Skip to content

Commit ec59ee3

Browse files
committed
Add skill select to new page
1 parent bf0699c commit ec59ee3

File tree

12 files changed

+170
-42
lines changed

12 files changed

+170
-42
lines changed
Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package jp.wicresoft.controller;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
5+
36
import javax.validation.Valid;
47

58
import org.slf4j.Logger;
@@ -12,33 +15,59 @@
1215
import org.springframework.web.bind.annotation.RequestMethod;
1316

1417
import jp.wicresoft.impl.NewImpl;
18+
import jp.wicresoft.impl.SkillSelectImpl;
1519
import jp.wicresoft.info.IndexViewInfo;
20+
import jp.wicresoft.info.SkillSelectInfo;
1621

1722
@Controller
1823
public class NewController {
1924

2025
@Autowired
2126
NewImpl newImpl;
2227

28+
@Autowired
29+
SkillSelectImpl skillSelectImpl;
30+
2331
Logger logger = LoggerFactory.getLogger(NewController.class);
2432

2533
@RequestMapping(value={"/new"})
2634
public String loadPage(Model model) {
2735
IndexViewInfo indexViewInfo = new IndexViewInfo();
2836
model.addAttribute("indexViewInfo", indexViewInfo);
2937
model.addAttribute("page", "new");
38+
// add skill select
39+
SkillSelectInfo skill = new SkillSelectInfo();
40+
skill.setLsSkill(new ArrayList<String>());
41+
skill.getLsSkill().add("0");
42+
model.addAttribute("skillSelectInfo", skill);
43+
model.addAttribute("skillOptions", skillSelectImpl.getSkillNameList());
3044
return "new";
3145
}
3246

3347
@RequestMapping(value = {"/new_add"}, method = RequestMethod.POST)
34-
public String addInfo(@Valid IndexViewInfo indexViewInfo, BindingResult bindingResult, Model model) {
35-
if (bindingResult.hasErrors()) {
36-
model.addAttribute("indexViewInfo", indexViewInfo);
37-
model.addAttribute("page", "new");
38-
return "new";
48+
public String addInfo(@Valid IndexViewInfo indexViewInfo, BindingResult bindingResult, @Valid SkillSelectInfo skillSelectInfo, Model model) {
49+
if (!bindingResult.hasErrors()) {
50+
logger.info("Add skill : " + skillSelectInfo.getLsSkill());
51+
try {
52+
// convert skill id to integer
53+
List<Integer> skillIdList = new ArrayList<Integer>();
54+
for (String skillIdStr : skillSelectInfo.getLsSkill()) {
55+
skillIdList.add(Integer.parseInt(skillIdStr));
56+
}
57+
logger.info("Add stuff: " + indexViewInfo.getName());
58+
newImpl.addOneStuff(indexViewInfo, skillIdList);
59+
return "redirect:all_stuff";
60+
} catch (Exception e) {
61+
logger.info(e.getLocalizedMessage());
62+
}
63+
3964
}
40-
logger.info("Add stuff: " + indexViewInfo.getName());
41-
newImpl.addOneStuff(indexViewInfo);
42-
return "redirect:all_stuff";
65+
66+
model.addAttribute("indexViewInfo", indexViewInfo);
67+
model.addAttribute("page", "new");
68+
// add skill select
69+
model.addAttribute("skillSelectInfo", skillSelectInfo);
70+
model.addAttribute("skillOptions", skillSelectImpl.getSkillNameList());
71+
return "new";
4372
}
4473
}

skill/src/main/java/jp/wicresoft/controller/SearchController.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,46 @@
1414
import org.springframework.web.bind.annotation.RequestMethod;
1515
import org.springframework.web.bind.annotation.RequestParam;
1616
import jp.wicresoft.impl.SearchImpl;
17+
import jp.wicresoft.impl.SkillSelectImpl;
1718
import jp.wicresoft.info.IndexViewInfo;
18-
import jp.wicresoft.info.SkillSearchInfo;
19+
import jp.wicresoft.info.SkillSelectInfo;
1920

2021
@Controller
2122
public class SearchController {
2223

2324
@Autowired
2425
SearchImpl searchImpl;
2526

27+
@Autowired
28+
SkillSelectImpl skillSelectImpl;
29+
2630
Logger logger = LoggerFactory.getLogger(NewController.class);
2731

2832
@RequestMapping(value={"/search"}, method=RequestMethod.GET)
2933
public String loadPage(Model model) {
3034
model.addAttribute("page", "search");
31-
SkillSearchInfo skill = new SkillSearchInfo();
35+
SkillSelectInfo skill = new SkillSelectInfo();
3236
skill.setLsSkill(new ArrayList<String>());
3337
skill.getLsSkill().add("0");
34-
model.addAttribute("skillSearchInfo", skill);
35-
model.addAttribute("skillOptions", searchImpl.getSkillNameList());
38+
model.addAttribute("skillSelectInfo", skill);
39+
model.addAttribute("skillOptions", skillSelectImpl.getSkillNameList());
3640
return "search";
3741
}
3842

3943
@RequestMapping(value={"/search"}, method=RequestMethod.POST)
40-
public String loadPage(@Valid SkillSearchInfo skillSearchInfo, Model model) {
41-
logger.info("Search for: " + skillSearchInfo.getLsSkill());
44+
public String loadPage(@Valid SkillSelectInfo skillSelectInfo, Model model) {
45+
logger.info("Search for: " + skillSelectInfo.getLsSkill());
4246
model.addAttribute("page", "search");
43-
if (skillSearchInfo.getLsSkill().isEmpty()) {
47+
if (skillSelectInfo.getLsSkill().isEmpty()) {
4448
// 検索条件がない場合
45-
model.addAttribute("skillSearchInfo", skillSearchInfo);
46-
model.addAttribute("skillOptions", searchImpl.getSkillNameList());
49+
model.addAttribute("skillSelectInfo", skillSelectInfo);
50+
model.addAttribute("skillOptions", skillSelectImpl.getSkillNameList());
4751
return "search";
4852
}
4953

5054
try {
5155
List<Integer> conditionList = new ArrayList<Integer>();
52-
for (String skillIdStr : skillSearchInfo.getLsSkill()) {
56+
for (String skillIdStr : skillSelectInfo.getLsSkill()) {
5357
conditionList.add(Integer.parseInt(skillIdStr));
5458
}
5559
List<IndexViewInfo> indexViewInfos = searchImpl.getSearchResultBySkill(conditionList);
@@ -60,23 +64,23 @@ public String loadPage(@Valid SkillSearchInfo skillSearchInfo, Model model) {
6064
} catch (Exception e) {
6165
logger.info(e.getLocalizedMessage());
6266
}
63-
model.addAttribute("skillSearchInfo", skillSearchInfo);
64-
model.addAttribute("skillOptions", searchImpl.getSkillNameList());
67+
model.addAttribute("skillSelectInfo", skillSelectInfo);
68+
model.addAttribute("skillOptions", skillSelectImpl.getSkillNameList());
6569

6670
return "search";
6771
}
6872

6973
@RequestMapping(value={"/search_addSelect"}, method=RequestMethod.POST)
7074
public String addSelect(@RequestParam(value = "index", required = false) int index, Model model) {
7175
logger.info("Selector have now: " + String.valueOf(index));
72-
SkillSearchInfo skill = new SkillSearchInfo();
76+
SkillSelectInfo skill = new SkillSelectInfo();
7377

7478
skill.setLsSkill(new ArrayList<String>());
7579
skill.getLsSkill().add("0");
76-
model.addAttribute("skillSearchInfo", skill);
80+
model.addAttribute("skillSelectInfo", skill);
7781
// set dynamic index
7882
model.addAttribute("index", index);
79-
model.addAttribute("skillOptions", searchImpl.getSkillNameList());
80-
return "search_subrow";
83+
model.addAttribute("skillOptions", skillSelectImpl.getSkillNameList());
84+
return "skill_select";
8185
}
8286
}
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
11
package jp.wicresoft.impl;
22

3+
import java.util.List;
4+
5+
import javax.transaction.Transactional;
6+
37
import org.springframework.beans.factory.annotation.Autowired;
48
import org.springframework.stereotype.Component;
59

610
import jp.wicresoft.domain.StuffMeta;
11+
import jp.wicresoft.domain.StuffSkill;
712
import jp.wicresoft.info.IndexViewInfo;
813
import jp.wicresoft.repository.StuffMetaRepository;
14+
import jp.wicresoft.repository.StuffSkillRepository;
915

1016
@Component
1117
public class NewImpl {
1218

1319
@Autowired
1420
StuffMetaRepository stuffMetaRepository;
1521

16-
public void addOneStuff(IndexViewInfo indexViewInfo) {
22+
@Autowired
23+
StuffSkillRepository stuffSkillRepository;
24+
25+
@Transactional
26+
public void addOneStuff(IndexViewInfo indexViewInfo, List<Integer> skillIdList) {
1727
StuffMeta stuffMeta = indexViewInfo.toStuffMeta();
18-
stuffMetaRepository.saveAndFlush(stuffMeta);
28+
StuffMeta result = stuffMetaRepository.saveAndFlush(stuffMeta);
29+
int stuffId = result.getId();
30+
for (Integer skillId : skillIdList) {
31+
stuffSkillRepository.saveAndFlush(new StuffSkill(stuffId, skillId));
32+
}
1933
}
2034
}

skill/src/main/java/jp/wicresoft/impl/SearchImpl.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,20 @@
66
import org.springframework.beans.factory.annotation.Autowired;
77
import org.springframework.stereotype.Component;
88

9-
import jp.wicresoft.domain.SkillTitleMst;
109
import jp.wicresoft.domain.StuffMeta;
1110
import jp.wicresoft.info.IndexViewInfo;
1211
import jp.wicresoft.jdbc.SkillSearchJdbcTemplate;
13-
import jp.wicresoft.repository.SkillTitleMstRepository;
1412
import jp.wicresoft.repository.StuffMetaRepository;
1513

1614
@Component
1715
public class SearchImpl {
1816

19-
@Autowired
20-
SkillTitleMstRepository skillTitleMstRepository;
21-
2217
@Autowired
2318
StuffMetaRepository stuffMetaRepository;
2419

2520
@Autowired
2621
SkillSearchJdbcTemplate skillSearchJdbcTemplate;
2722

28-
public List<SkillTitleMst> getSkillNameList() {
29-
return skillTitleMstRepository.findAll();
30-
}
31-
3223
public List<IndexViewInfo> getSearchResultBySkill(List<Integer> titleIds) {
3324
List<StuffMeta> stuffMetas = skillSearchJdbcTemplate.findByIds(titleIds);
3425
List<IndexViewInfo> indexViewInfos = new ArrayList<>();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package jp.wicresoft.impl;
2+
3+
import java.util.List;
4+
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.stereotype.Component;
7+
8+
import jp.wicresoft.domain.SkillTitleMst;
9+
import jp.wicresoft.repository.SkillTitleMstRepository;
10+
11+
@Component
12+
public class SkillSelectImpl {
13+
14+
@Autowired
15+
SkillTitleMstRepository skillTitleMstRepository;
16+
17+
public List<SkillTitleMst> getSkillNameList() {
18+
return skillTitleMstRepository.findAll();
19+
}
20+
}

skill/src/main/java/jp/wicresoft/info/SkillSearchInfo.java renamed to skill/src/main/java/jp/wicresoft/info/SkillSelectInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import lombok.Data;
66

77
@Data
8-
public class SkillSearchInfo {
8+
public class SkillSelectInfo {
99

1010
List<String> lsSkill;
1111
}

skill/src/main/resources/templates/new.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,35 @@ <h2 class="col-sm-offset-4 col-sm-8">スキル情報新規</h2>
7373
</div>
7474
</div>
7575
</div>
76+
<div class="selectList">
77+
<div class="form-group" th:each="row,rowStat : ${skillSelectInfo.lsSkill}">
78+
<label for="inputName" class="col-sm-4 control-label">スキル</label>
79+
<select id="" th:field="${skillSelectInfo.lsSkill[__${rowStat.index}__]}"
80+
class="selectpicker dynamic-select" data-live-search="true"
81+
title="下記のスキルを選択してください">
82+
<optgroup label="資格">
83+
<option th:each="skill : ${skillOptions}"
84+
th:if="${skill.skillCategory==1}"
85+
th:value="${skill.skillTitleId}" th:text="${skill.titleName}"></option>
86+
</optgroup>
87+
<optgroup label="環境(OS)">
88+
<option th:each="skill : ${skillOptions}"
89+
th:if="${skill.skillCategory==2}"
90+
th:value="${skill.skillTitleId}" th:text="${skill.titleName}"></option>
91+
</optgroup>
92+
<optgroup label="DB">
93+
<option th:each="skill : ${skillOptions}"
94+
th:if="${skill.skillCategory==3}"
95+
th:value="${skill.skillTitleId}" th:text="${skill.titleName}"></option>
96+
</optgroup>
97+
<optgroup label="言語">
98+
<option th:each="skill : ${skillOptions}"
99+
th:if="${skill.skillCategory==4}"
100+
th:value="${skill.skillTitleId}" th:text="${skill.titleName}"></option>
101+
</optgroup>
102+
</select>
103+
</div>
104+
</div>
76105
<div class="form-group">
77106
<div class="col-sm-offset-4 col-sm-4">
78107
<button type="submit" class="btn btn-success">新規</button>

skill/src/main/resources/templates/search.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
<div class="container">
2525
<h2 class="col-sm-offset-4 col-sm-8">スキル情報検索</h2>
2626

27-
<form class="form-horizontal" method="post" action="/search" th:object="${skillSearchInfo}">
27+
<form class="form-horizontal" method="post" action="/search" th:object="${skillSelectInfo}">
2828
<div class="selectList">
29-
<div class="form-group" th:each="row,rowStat : ${skillSearchInfo.lsSkill}">
29+
<div class="form-group" th:each="row,rowStat : ${skillSelectInfo.lsSkill}">
3030
<label for="inputName" class="col-sm-4 control-label">スキル</label>
31-
<select id="" th:field="${skillSearchInfo.lsSkill[__${rowStat.index}__]}"
31+
<select id="" th:field="${skillSelectInfo.lsSkill[__${rowStat.index}__]}"
3232
class="selectpicker dynamic-select" data-live-search="true"
3333
title="下記のスキルを選択してください">
3434
<optgroup label="資格">

skill/src/main/resources/templates/search_subrow.html renamed to skill/src/main/resources/templates/skill_select.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
<body>
77
<div class="selectList">
88
<div class="form-group"
9-
th:each="row,rowStat : ${skillSearchInfo.lsSkill}">
9+
th:each="row,rowStat : ${skillSelectInfo.lsSkill}">
1010
<label for="inputName" class="col-sm-4 control-label">スキル</label> <select
11-
th:field="${skillSearchInfo.lsSkill[__${index}__]}"
11+
th:field="${skillSelectInfo.lsSkill[__${index}__]}"
1212
class="selectpicker dynamic-select" data-live-search="true" title="下記のスキルを選択してください">
1313
<optgroup label="資格">
1414
<option th:each="skill : ${skillOptions}"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package jp.wicresoft.domain;
2+
3+
import javax.persistence.Entity;
4+
import javax.persistence.Id;
5+
import javax.persistence.IdClass;
6+
7+
import lombok.AllArgsConstructor;
8+
import lombok.Data;
9+
import lombok.NoArgsConstructor;
10+
11+
@Data
12+
@NoArgsConstructor
13+
@AllArgsConstructor
14+
@Entity
15+
@IdClass(StuffSkill.StuffId.class)
16+
public class StuffSkill {
17+
18+
@Id
19+
int stuffId;
20+
21+
@Id
22+
int skillId;
23+
24+
static class StuffId {
25+
26+
int stuffId;
27+
28+
int skillId;
29+
30+
}
31+
}

0 commit comments

Comments
 (0)