diff --git a/src/main/java/cokr/xit/fims/stat/CompositeKey.java b/src/main/java/cokr/xit/fims/stat/CompositeKey.java new file mode 100644 index 00000000..7afeec12 --- /dev/null +++ b/src/main/java/cokr/xit/fims/stat/CompositeKey.java @@ -0,0 +1,47 @@ +package cokr.xit.fims.stat; + +import java.util.Objects; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class CompositeKey { + private String level1; + private String level2; + private String level3; + private String level4; + + public String[] toArray() { + + if(this.level2 == null) { + return new String[] { this.level1 }; + } + if(this.level3 == null) { + return new String[] { this.level1, this.level2 }; + } + if(this.level4 == null) { + return new String[] { this.level1, this.level2, this.level3 }; + } + + return new String[] { this.level1, this.level2, this.level3, this.level4 }; + } + + @Override + public boolean equals(Object o) { + if(this == o) return true; + if(o == null || getClass() != o.getClass()) return false; + CompositeKey k = (CompositeKey) o; + + return Objects.equals(level1, k.level1) + && Objects.equals(level2, k.level2) + && Objects.equals(level3, k.level3) + && Objects.equals(level4, k.level4); + } + + @Override + public int hashCode() { + return Objects.hash(level1,level2,level3,level4); + } +} diff --git a/src/main/java/cokr/xit/fims/stat/service/bean/StatBean.java b/src/main/java/cokr/xit/fims/stat/service/bean/StatBean.java index 57f381cd..0edd3864 100644 --- a/src/main/java/cokr/xit/fims/stat/service/bean/StatBean.java +++ b/src/main/java/cokr/xit/fims/stat/service/bean/StatBean.java @@ -20,6 +20,7 @@ import cokr.xit.fims.cmmn.CmmnUtil; import cokr.xit.fims.cmmn.CodeConverter; import cokr.xit.fims.crdn.service.bean.CrdnStngBean; import cokr.xit.fims.stat.CodeSubsetInfo; +import cokr.xit.fims.stat.CompositeKey; import cokr.xit.fims.stat.GroupInfo; import cokr.xit.fims.stat.NumberValueInfo; import cokr.xit.fims.stat.Stat; @@ -104,7 +105,7 @@ public class StatBean extends AbstractComponent { //통계 항목별 그룹핑 - Map> group = this.grouping(queryResult, statQuery); + Map> group = this.grouping(queryResult, statQuery); //고정 항목 설정 @@ -113,17 +114,17 @@ public class StatBean extends AbstractComponent { } //수치 값 추출 - Set keySet = group.keySet(); - Iterator it = keySet.iterator(); + Set keySet = group.keySet(); + Iterator it = keySet.iterator(); List statItems = new ArrayList<>(); while(it.hasNext()){ - String key = it.next(); + CompositeKey compositeKey = it.next(); StatItem statItem = new StatItem(); - statItem.setItemId(key.split(",", -1)); + statItem.setItemId(compositeKey.toArray()); - List listByKey = group.get(key); + List listByKey = group.get(compositeKey); int[] numberValues = this.extractNumberValue(listByKey, statQuery); @@ -145,29 +146,41 @@ public class StatBean extends AbstractComponent { * @param queryResult SQL쿼리 처리 결과, statQuery 통계 요청 * @return 통계 항목별로 그룹핑된 목록 */ - public Map> grouping(List queryResult, StatQuery statQuery){ + public Map> grouping(List queryResult, StatQuery statQuery){ List groupInfoList = statQuery.getGroupInfoList(); List subsetInfoList = statQuery.getCodeSubsetInfoList(); - Map> group = queryResult.stream() + Map> group = queryResult.stream() .collect( Collectors.groupingBy( (item) -> { - String result = ""; + + CompositeKey compositeKey = new CompositeKey(); + for(int i = 0; i < groupInfoList.size(); i++) { + String key = ""; GroupInfo groupInfo = groupInfoList.get(i); - if(i != 0) { - result += ","; - } - String refCol = groupInfo.getRefCol(); String colValue = item.string(refCol); if(ifEmpty(groupInfo.getCtgrType(), ()-> "").equals("")) { - result += colValue; + key = colValue; + if(i == 0) { + compositeKey.setLevel1(key); + } + if(i == 1) { + compositeKey.setLevel2(key); + } + if(i == 2) { + compositeKey.setLevel3(key); + } + if(i == 3) { + compositeKey.setLevel4(key); + } + continue; } @@ -177,21 +190,21 @@ public class StatBean extends AbstractComponent { if(ctgrType.equals("date")) { if(addOption.equals("YYYY")) { //연도별 - result += colValue.substring(0,4); + key = colValue.substring(0,4); } else if(addOption.equals("YYYYMM")) { //연월별 - result += colValue.substring(0,6); + key = colValue.substring(0,6); } else if(addOption.equals("YYYYMMDD")) { //일자별 - result += colValue.substring(0,8); + key = colValue.substring(0,8); } else if(addOption.equals("DAY_OF_WEEK")) { //요일별 - result += CmmnUtil.getDayOfWeek(colValue); + key = CmmnUtil.getDayOfWeek(colValue); } else if(addOption.equals("HH")) { //시간대별 if(colValue.length() == 14) { - result += colValue.substring(8,10); + key = colValue.substring(8,10); } else { - result += colValue.substring(0,2); + key = colValue.substring(0,2); } } else { - result += colValue; + key = colValue; } } else if(ctgrType.equals("code") || ctgrType.equals("otherCode")) { @@ -209,7 +222,7 @@ public class StatBean extends AbstractComponent { } } - result += colValue; + key = colValue; } else if(ctgrType.equals("method")) { @@ -217,19 +230,31 @@ public class StatBean extends AbstractComponent { String ffnlgCarmdlCd = item.string("FFNLG_CARMDL_CD"); String vhrno = item.string("VHRNO"); - result += crdnStngBean.getBusinessYnOfCar(ffnlgCarmdlCd, vhrno); + key = crdnStngBean.getBusinessYnOfCar(ffnlgCarmdlCd, vhrno); } else { - result += colValue; + key = colValue; } } else { - result += colValue; + key = colValue; } + if(i == 0) { + compositeKey.setLevel1(key); + } + if(i == 1) { + compositeKey.setLevel2(key); + } + if(i == 2) { + compositeKey.setLevel3(key); + } + if(i == 3) { + compositeKey.setLevel4(key); + } } - return result; + return compositeKey; } ) ); @@ -241,29 +266,37 @@ public class StatBean extends AbstractComponent { * @param group 그룹핑한 데이터 목록, statQuery 통계 요청; * @return */ - public void itemFix(Map> group, StatQuery statQuery) { + public void itemFix(Map> group, StatQuery statQuery) { String[] fixedItemId = statQuery.getFixedItemId(); + CompositeKey[] fixedItemKey = new CompositeKey[fixedItemId.length]; + for(int i=0; i < fixedItemId.length; i++) { - if(!group.containsKey(fixedItemId[i])) { - group.put(fixedItemId[i], null); + CompositeKey newObj = new CompositeKey(); + newObj.setLevel1(fixedItemId[i]); + fixedItemKey[i] = newObj; + } + + for(int i=0; i < fixedItemKey.length; i++) { + if(!group.containsKey(fixedItemKey[i])) { + group.put(fixedItemKey[i], null); } } - Set keySet = group.keySet(); - Iterator it = keySet.iterator(); + Set keySet = group.keySet(); + Iterator it = keySet.iterator(); - List deleteTargets = new ArrayList<>(); + List deleteTargets = new ArrayList<>(); while(it.hasNext()) { - String key = it.next(); - if(!Arrays.asList(fixedItemId).contains(key)) { - deleteTargets.add(key); + CompositeKey compositekey = it.next(); + if(!Arrays.asList(fixedItemKey).contains(compositekey)) { + deleteTargets.add(compositekey); } } - for(String deleteTarget : deleteTargets) { + for(CompositeKey deleteTarget : deleteTargets) { group.remove(deleteTarget); } } diff --git a/src/main/webapp/resources/js/fims/stat/crdnGroupSubset.js b/src/main/webapp/resources/js/fims/stat/crdnGroupSubset.js index dcc2f1ff..dc9c30a6 100644 --- a/src/main/webapp/resources/js/fims/stat/crdnGroupSubset.js +++ b/src/main/webapp/resources/js/fims/stat/crdnGroupSubset.js @@ -1,4 +1,4 @@ var ffnlgCarmdlCd_codeSubsetInfoList = [ { sourceGroup : "FIM009", sourceCodes : ["15","21"], - targetCode : "etc", targetCodeVal : "특수/건설기계" } + targetCode : "etc", targetCodeVal : "특수,건설기계" } ]; \ No newline at end of file