Skip to content

Commit bf0699c

Browse files
committed
repair search logic
1 parent 26c7eaf commit bf0699c

File tree

6 files changed

+42
-13
lines changed

6 files changed

+42
-13
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public String loadPage(@Valid SkillSearchInfo skillSearchInfo, Model model) {
4848
}
4949

5050
try {
51-
List<Long> conditionList = new ArrayList<Long>();
51+
List<Integer> conditionList = new ArrayList<Integer>();
5252
for (String skillIdStr : skillSearchInfo.getLsSkill()) {
53-
conditionList.add(Long.parseLong(skillIdStr));
53+
conditionList.add(Integer.parseInt(skillIdStr));
5454
}
5555
List<IndexViewInfo> indexViewInfos = searchImpl.getSearchResultBySkill(conditionList);
5656
// 結果を出す

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public List<SkillTitleMst> getSkillNameList() {
2929
return skillTitleMstRepository.findAll();
3030
}
3131

32-
public List<IndexViewInfo> getSearchResultBySkill(List<Long> titleIds) {
32+
public List<IndexViewInfo> getSearchResultBySkill(List<Integer> titleIds) {
3333
List<StuffMeta> stuffMetas = skillSearchJdbcTemplate.findByIds(titleIds);
3434
List<IndexViewInfo> indexViewInfos = new ArrayList<>();
3535
for (StuffMeta stuffMeta : stuffMetas) {

skill_db/src/main/java/jp/wicresoft/domain/SkillTitleMst.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
public class SkillTitleMst {
1111

1212
@Id
13-
private Long skillTitleId;
13+
private int skillTitleId;
1414

1515
private String titleName;
1616

17-
private Long skillCategory;
17+
private int skillCategory;
1818
}
Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package jp.wicresoft.jdbc;
22

3+
import java.util.ArrayList;
34
import java.util.List;
45
import java.util.Map;
5-
66
import org.springframework.beans.factory.annotation.Autowired;
77
import org.springframework.jdbc.core.JdbcTemplate;
88
import org.springframework.stereotype.Component;
@@ -15,11 +15,40 @@ public class SkillSearchJdbcTemplate extends BasicJdbc{
1515
@Autowired
1616
JdbcTemplate jdbcTemplate;
1717

18-
public List<StuffMeta> findByIds(List<Long> titleIds) {
19-
String queryStr = "select meta.* "
20-
+ "from skill_version_mst v inner join stuff_skill s inner join stuff_meta meta "
21-
+ "on v.skill_title in (1) and v.skill_id = s.skill_id and s.stuff_id = meta.id;";
22-
List<Map<String, Object>> mapList = jdbcTemplate.queryForList(queryStr);
18+
final private int INDEX_START = 1;
19+
20+
public List<StuffMeta> findByIds(List<Integer> titleIds) {
21+
if (titleIds.isEmpty()) {
22+
return new ArrayList<StuffMeta>();
23+
}
24+
25+
StringBuffer joinBuffer = new StringBuffer();
26+
StringBuffer andBuffer = new StringBuffer();
27+
StringBuffer paramBuffer = new StringBuffer();
28+
for (int currentIndex = INDEX_START; currentIndex <= titleIds.size(); currentIndex++) {
29+
joinBuffer.append(" inner join stuff_skill s");
30+
joinBuffer.append(currentIndex);
31+
32+
if (currentIndex > INDEX_START) {
33+
andBuffer.append(" and s");
34+
andBuffer.append(currentIndex - 1);
35+
andBuffer.append(".stuff_id = s");
36+
andBuffer.append(currentIndex);
37+
andBuffer.append(".stuff_id");
38+
}
39+
40+
paramBuffer.append(" and s");
41+
paramBuffer.append(currentIndex);
42+
paramBuffer.append(".skill_id = ?");
43+
}
44+
String queryStr = "select meta.* from stuff_meta meta "
45+
+ joinBuffer.toString()
46+
+ " on meta.id = s"
47+
+ INDEX_START
48+
+ ".stuff_id "
49+
+ andBuffer.toString()
50+
+ paramBuffer.toString();
51+
List<Map<String, Object>> mapList = jdbcTemplate.queryForList(queryStr, titleIds.toArray());
2352
return convertJdbcMapToBean(mapList, StuffMeta.class);
2453
}
2554
}

skill_db/src/main/java/jp/wicresoft/repository/SkillTitleMstRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import jp.wicresoft.domain.SkillTitleMst;
88

9-
public interface SkillTitleMstRepository extends Repository<SkillTitleMst, Long> {
9+
public interface SkillTitleMstRepository extends Repository<SkillTitleMst, Integer> {
1010

1111
public List<SkillTitleMst> findAll();
1212
}

skill_db/src/main/java/jp/wicresoft/repository/StuffMetaRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import jp.wicresoft.domain.StuffMeta;
99

10-
public interface StuffMetaRepository extends Repository<StuffMeta, Long>{
10+
public interface StuffMetaRepository extends Repository<StuffMeta, Integer>{
1111

1212
public List<StuffMeta> findAll();
1313

0 commit comments

Comments
 (0)