통계 수정

main
이범준 1 year ago
parent b4b6f8ce3f
commit 2a12a67278

@ -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);
}
}

@ -20,6 +20,7 @@ import cokr.xit.fims.cmmn.CmmnUtil;
import cokr.xit.fims.cmmn.CodeConverter; import cokr.xit.fims.cmmn.CodeConverter;
import cokr.xit.fims.crdn.service.bean.CrdnStngBean; import cokr.xit.fims.crdn.service.bean.CrdnStngBean;
import cokr.xit.fims.stat.CodeSubsetInfo; import cokr.xit.fims.stat.CodeSubsetInfo;
import cokr.xit.fims.stat.CompositeKey;
import cokr.xit.fims.stat.GroupInfo; import cokr.xit.fims.stat.GroupInfo;
import cokr.xit.fims.stat.NumberValueInfo; import cokr.xit.fims.stat.NumberValueInfo;
import cokr.xit.fims.stat.Stat; import cokr.xit.fims.stat.Stat;
@ -104,7 +105,7 @@ public class StatBean extends AbstractComponent {
//통계 항목별 그룹핑 //통계 항목별 그룹핑
Map<String, List<DataObject>> group = this.grouping(queryResult, statQuery); Map<CompositeKey, List<DataObject>> group = this.grouping(queryResult, statQuery);
//고정 항목 설정 //고정 항목 설정
@ -113,17 +114,17 @@ public class StatBean extends AbstractComponent {
} }
//수치 값 추출 //수치 값 추출
Set<String> keySet = group.keySet(); Set<CompositeKey> keySet = group.keySet();
Iterator<String> it = keySet.iterator(); Iterator<CompositeKey> it = keySet.iterator();
List<StatItem> statItems = new ArrayList<>(); List<StatItem> statItems = new ArrayList<>();
while(it.hasNext()){ while(it.hasNext()){
String key = it.next(); CompositeKey compositeKey = it.next();
StatItem statItem = new StatItem(); StatItem statItem = new StatItem();
statItem.setItemId(key.split(",", -1)); statItem.setItemId(compositeKey.toArray());
List<DataObject> listByKey = group.get(key); List<DataObject> listByKey = group.get(compositeKey);
int[] numberValues = this.extractNumberValue(listByKey, statQuery); int[] numberValues = this.extractNumberValue(listByKey, statQuery);
@ -145,29 +146,41 @@ public class StatBean extends AbstractComponent {
* @param queryResult SQL , statQuery * @param queryResult SQL , statQuery
* @return * @return
*/ */
public Map<String, List<DataObject>> grouping(List<DataObject> queryResult, StatQuery statQuery){ public Map<CompositeKey, List<DataObject>> grouping(List<DataObject> queryResult, StatQuery statQuery){
List<GroupInfo> groupInfoList = statQuery.getGroupInfoList(); List<GroupInfo> groupInfoList = statQuery.getGroupInfoList();
List<CodeSubsetInfo> subsetInfoList = statQuery.getCodeSubsetInfoList(); List<CodeSubsetInfo> subsetInfoList = statQuery.getCodeSubsetInfoList();
Map<String, List<DataObject>> group = queryResult.stream() Map<CompositeKey, List<DataObject>> group = queryResult.stream()
.collect( .collect(
Collectors.groupingBy( Collectors.groupingBy(
(item) -> { (item) -> {
String result = "";
CompositeKey compositeKey = new CompositeKey();
for(int i = 0; i < groupInfoList.size(); i++) { for(int i = 0; i < groupInfoList.size(); i++) {
String key = "";
GroupInfo groupInfo = groupInfoList.get(i); GroupInfo groupInfo = groupInfoList.get(i);
if(i != 0) {
result += ",";
}
String refCol = groupInfo.getRefCol(); String refCol = groupInfo.getRefCol();
String colValue = item.string(refCol); String colValue = item.string(refCol);
if(ifEmpty(groupInfo.getCtgrType(), ()-> "").equals("")) { 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; continue;
} }
@ -177,21 +190,21 @@ public class StatBean extends AbstractComponent {
if(ctgrType.equals("date")) { if(ctgrType.equals("date")) {
if(addOption.equals("YYYY")) { //연도별 if(addOption.equals("YYYY")) { //연도별
result += colValue.substring(0,4); key = colValue.substring(0,4);
} else if(addOption.equals("YYYYMM")) { //연월별 } else if(addOption.equals("YYYYMM")) { //연월별
result += colValue.substring(0,6); key = colValue.substring(0,6);
} else if(addOption.equals("YYYYMMDD")) { //일자별 } else if(addOption.equals("YYYYMMDD")) { //일자별
result += colValue.substring(0,8); key = colValue.substring(0,8);
} else if(addOption.equals("DAY_OF_WEEK")) { //요일별 } else if(addOption.equals("DAY_OF_WEEK")) { //요일별
result += CmmnUtil.getDayOfWeek(colValue); key = CmmnUtil.getDayOfWeek(colValue);
} else if(addOption.equals("HH")) { //시간대별 } else if(addOption.equals("HH")) { //시간대별
if(colValue.length() == 14) { if(colValue.length() == 14) {
result += colValue.substring(8,10); key = colValue.substring(8,10);
} else { } else {
result += colValue.substring(0,2); key = colValue.substring(0,2);
} }
} else { } else {
result += colValue; key = colValue;
} }
} else if(ctgrType.equals("code") || ctgrType.equals("otherCode")) { } 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")) { } else if(ctgrType.equals("method")) {
@ -217,19 +230,31 @@ public class StatBean extends AbstractComponent {
String ffnlgCarmdlCd = item.string("FFNLG_CARMDL_CD"); String ffnlgCarmdlCd = item.string("FFNLG_CARMDL_CD");
String vhrno = item.string("VHRNO"); String vhrno = item.string("VHRNO");
result += crdnStngBean.getBusinessYnOfCar(ffnlgCarmdlCd, vhrno); key = crdnStngBean.getBusinessYnOfCar(ffnlgCarmdlCd, vhrno);
} else { } else {
result += colValue; key = colValue;
} }
} else { } 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 ; * @param group , statQuery ;
* @return * @return
*/ */
public void itemFix(Map<String, List<DataObject>> group, StatQuery statQuery) { public void itemFix(Map<CompositeKey, List<DataObject>> group, StatQuery statQuery) {
String[] fixedItemId = statQuery.getFixedItemId(); String[] fixedItemId = statQuery.getFixedItemId();
CompositeKey[] fixedItemKey = new CompositeKey[fixedItemId.length];
for(int i=0; i < fixedItemId.length; i++) { for(int i=0; i < fixedItemId.length; i++) {
if(!group.containsKey(fixedItemId[i])) { CompositeKey newObj = new CompositeKey();
group.put(fixedItemId[i], null); 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<String> keySet = group.keySet(); Set<CompositeKey> keySet = group.keySet();
Iterator<String> it = keySet.iterator(); Iterator<CompositeKey> it = keySet.iterator();
List<String> deleteTargets = new ArrayList<>(); List<CompositeKey> deleteTargets = new ArrayList<>();
while(it.hasNext()) { while(it.hasNext()) {
String key = it.next(); CompositeKey compositekey = it.next();
if(!Arrays.asList(fixedItemId).contains(key)) { if(!Arrays.asList(fixedItemKey).contains(compositekey)) {
deleteTargets.add(key); deleteTargets.add(compositekey);
} }
} }
for(String deleteTarget : deleteTargets) { for(CompositeKey deleteTarget : deleteTargets) {
group.remove(deleteTarget); group.remove(deleteTarget);
} }
} }

@ -1,4 +1,4 @@
var ffnlgCarmdlCd_codeSubsetInfoList = [ var ffnlgCarmdlCd_codeSubsetInfoList = [
{ sourceGroup : "FIM009", sourceCodes : ["15","21"], { sourceGroup : "FIM009", sourceCodes : ["15","21"],
targetCode : "etc", targetCodeVal : "특수/건설기계" } targetCode : "etc", targetCodeVal : "특수,건설기계" }
]; ];
Loading…
Cancel
Save