diff --git a/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java b/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java index d4a5f28e..e019af1a 100644 --- a/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java +++ b/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java @@ -6,11 +6,15 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.text.SimpleDateFormat; +import java.time.DayOfWeek; +import java.time.LocalDate; +import java.time.format.TextStyle; import java.util.Calendar; import java.util.Comparator; import java.util.Date; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.stream.Collectors; @@ -218,4 +222,14 @@ public class CmmnUtil { return yyyyMMddFormat.format(cal.getTime()); } + + public static String getDayOfWeek(String dateStr) { + int y = Integer.parseInt(dateStr.substring(0,4)); + int m = Integer.parseInt(dateStr.substring(4,6)); + int d = Integer.parseInt(dateStr.substring(6,8)); + LocalDate date = LocalDate.of(y, m, d); + DayOfWeek dayOfWeek = date.getDayOfWeek(); + String dow = dayOfWeek.getDisplayName(TextStyle.SHORT, Locale.KOREAN); + return dow; + } } diff --git a/src/main/java/cokr/xit/fims/stat/GroupInfo.java b/src/main/java/cokr/xit/fims/stat/GroupInfo.java index 70516ef8..c7812c0f 100644 --- a/src/main/java/cokr/xit/fims/stat/GroupInfo.java +++ b/src/main/java/cokr/xit/fims/stat/GroupInfo.java @@ -2,33 +2,43 @@ package cokr.xit.fims.stat; public class GroupInfo { - private String groupColName; + /** + * 기준 컬럼 + */ + private String refCol; - private String categoryNameConverter; + /** + * 분류 유형 + */ + private String ctgrType; - private String categorizationAddOption; + /** + * 상세 분류 + */ + private String dtlCtgr; - public String getGroupColName(){ - return this.groupColName; + + public String getRefCol(){ + return this.refCol; } - public void setGroupColName(String groupColName){ - this.groupColName = groupColName; + public void setRefCol(String refCol){ + this.refCol = refCol; } - public String getCategoryNameConverter(){ - return this.categoryNameConverter; + public String getCtgrType(){ + return this.ctgrType; } - public void setCategoryNameConverter(String categoryNameConverter){ - this.categoryNameConverter = categoryNameConverter; + public void setCtgrType(String ctgrType){ + this.ctgrType = ctgrType; } - public String getCategorizationAddOption(){ - return this.categorizationAddOption; + public String getDtlCtgr(){ + return this.dtlCtgr; } - public void setCategorizationAddOption(String categorizationAddOption){ - this.categorizationAddOption = categorizationAddOption; + public void setDtlCtgr(String dtlCtgr){ + this.dtlCtgr = dtlCtgr; } } diff --git a/src/main/java/cokr/xit/fims/stat/NumberValueInfo.java b/src/main/java/cokr/xit/fims/stat/NumberValueInfo.java index a18cd369..39194619 100644 --- a/src/main/java/cokr/xit/fims/stat/NumberValueInfo.java +++ b/src/main/java/cokr/xit/fims/stat/NumberValueInfo.java @@ -3,21 +3,71 @@ package cokr.xit.fims.stat; public class NumberValueInfo { /** - * 복합 수치 값 구분자 + * 구분자 기준 컬럼 */ - private String numberValueSeperator; + private String seperatorRefCol; + + /** + * 조건 값 + */ + private String conditionValue; + + /** + * 구분자 분류 유형 + */ + private String seperatorCtgrType; + + /** + * 구분자 상세분류 + */ + private String seperatorDtlCtgr; /** * 수치값 집계 유형(count 건수, sum 합계, ratio 비율) */ private String aggregateType; - public String getNumberValueSeperator(){ - return this.numberValueSeperator; + /** + * 합계 기준 컬럼 + */ + private String sumRefCol; + + /** + * 비율 전체 참조 인덱스 + */ + private int ratioRefIndex; + + + public String getSeperatorRefCol(){ + return this.seperatorRefCol; + } + + public void setSeperatorRefCol(String seperatorRefCol){ + this.seperatorRefCol = seperatorRefCol; } - public void setNumberValueSeperator(String numberValueSeperator){ - this.numberValueSeperator = numberValueSeperator; + public String getConditionValue(){ + return this.conditionValue; + } + + public void setConditionValue(String conditionValue){ + this.conditionValue = conditionValue; + } + + public String getSeperatorCtgrType(){ + return this.seperatorCtgrType; + } + + public void setSeperatorCtgrType(String seperatorCtgrType){ + this.seperatorCtgrType = seperatorCtgrType; + } + + public String getSeperatorDtlCtgr(){ + return this.seperatorDtlCtgr; + } + + public void setSeperatorDtlCtgr(String seperatorDtlCtgr){ + this.seperatorDtlCtgr = seperatorDtlCtgr; } public String getAggregateType(){ @@ -28,4 +78,19 @@ public class NumberValueInfo { this.aggregateType = aggregateType; } + public String getSumRefCol(){ + return this.sumRefCol; + } + + public void setSumRefCol(String sumRefCol){ + this.sumRefCol = sumRefCol; + } + + public int getRatioRefIndex(){ + return this.ratioRefIndex; + } + + public void setRatioRefIndex(int ratioRefIndex){ + this.ratioRefIndex = ratioRefIndex; + } } diff --git a/src/main/java/cokr/xit/fims/stat/StatQuery.java b/src/main/java/cokr/xit/fims/stat/StatQuery.java index 5fbd028d..32ee6f61 100644 --- a/src/main/java/cokr/xit/fims/stat/StatQuery.java +++ b/src/main/java/cokr/xit/fims/stat/StatQuery.java @@ -53,6 +53,11 @@ public class StatQuery extends CmmnQuery { */ private String globalAggregate; + /** + * 전역 합계 기준 컬럼 + */ + private String globalSumRefCol; + /** * 표기할 소수점 자릿수 */ @@ -128,6 +133,15 @@ public class StatQuery extends CmmnQuery { return self(); } + public String getGlobalSumRefCol() { + return ifEmpty(globalSumRefCol, () -> null); + } + + public T setGlobalSumRefCol(String globalSumRefCol) { + this.globalSumRefCol = globalSumRefCol; + return self(); + } + public int getDecimalPoint() { return ifEmpty(decimalPoint, () -> null); } 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 da0ff664..605ac79e 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 @@ -1,14 +1,10 @@ package cokr.xit.fims.stat.service.bean; import java.lang.reflect.Method; -import java.time.DayOfWeek; -import java.time.LocalDate; -import java.time.format.TextStyle; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -17,6 +13,7 @@ import org.springframework.stereotype.Component; import cokr.xit.base.code.CommonCode; import cokr.xit.fims.cmmn.CmmnQuery; +import cokr.xit.fims.cmmn.CmmnUtil; import cokr.xit.fims.cmmn.CodeConverter; import cokr.xit.fims.stat.CodeSubsetInfo; import cokr.xit.fims.stat.GroupInfo; @@ -128,23 +125,28 @@ public class StatBean extends AbstractComponent { if(i != 0) { result += ","; } - String colValue = item.string(groupInfo.getGroupColName()); - if(!ifEmpty(groupInfo.getCategorizationAddOption(), ()-> "").equals("")) { - String addOption = groupInfo.getCategorizationAddOption(); + String refCol = groupInfo.getRefCol(); + String colValue = item.string(refCol); + + if(ifEmpty(groupInfo.getCtgrType(), ()-> "").equals("")) { + result += colValue; + continue; + } + + String ctgrType = groupInfo.getCtgrType(); + String addOption = groupInfo.getDtlCtgr(); + + if(ctgrType.equals("date")) { if(addOption.equals("YYYY")) { //연도별 result += colValue.substring(0,4); } else if(addOption.equals("YYYYMM")) { //연월별 result += colValue.substring(0,6); + } else if(addOption.equals("YYYYMMDD")) { //일자별 + result += colValue.substring(0,8); } else if(addOption.equals("DAY_OF_WEEK")) { //요일별 - int y = Integer.parseInt(colValue.substring(0,4)); - int m = Integer.parseInt(colValue.substring(4,6)); - int d = Integer.parseInt(colValue.substring(6,8)); - LocalDate date = LocalDate.of(y, m, d); - DayOfWeek dayOfWeek = date.getDayOfWeek(); - String dow = dayOfWeek.getDisplayName(TextStyle.SHORT, Locale.KOREAN); - result += dow; + result += CmmnUtil.getDayOfWeek(colValue); } else if(addOption.equals("HH")) { //시간대별 if(colValue.length() == 14) { result += colValue.substring(8,10); @@ -154,16 +156,15 @@ public class StatBean extends AbstractComponent { } else { result += colValue; } - } else { + } else if(ctgrType.equals("code") || ctgrType.equals("otherCode")) { - if(groupInfo.getGroupColName().endsWith("_CD") - && groupInfo.getCategoryNameConverter() != null - && groupInfo.getCategoryNameConverter().startsWith("code=") - && subsetInfoList != null && !subsetInfoList.isEmpty() + if(ctgrType.equals("code") + && subsetInfoList != null + && !subsetInfoList.isEmpty() ) { for(CodeSubsetInfo subsetInfo : subsetInfoList) { - if(subsetInfo.getSourceGroup().equals(groupInfo.getCategoryNameConverter().split("=")[1])) { + if(subsetInfo.getSourceGroup().equals(addOption)) { if(Arrays.asList(subsetInfo.getSourceCodes()).contains(colValue)) { colValue = subsetInfo.getTargetCode(); } @@ -171,8 +172,11 @@ public class StatBean extends AbstractComponent { } } + result += colValue; + } else { result += colValue; } + } return result; } @@ -219,6 +223,8 @@ public class StatBean extends AbstractComponent { List numberValueInfoList = statQuery.getNumberValueInfoList(); + List subsetInfoList = statQuery.getCodeSubsetInfoList(); + int[] aggregateArr = new int[numberValueInfoList.size()]; for(int i=0; i < numberValueInfoList.size(); i++) { aggregateArr[i] = 0; @@ -230,32 +236,65 @@ public class StatBean extends AbstractComponent { DataObject dataObject = listByKey.get(i); for(int j=0; j < aggregateArr.length; j++) { + NumberValueInfo numverValueInfo = numberValueInfoList.get(j); + + String seperatorRefCol = ifEmpty(numverValueInfo.getSeperatorRefCol(), ()-> ""); + String conditionValue = ifEmpty(numverValueInfo.getConditionValue(), ()-> ""); + + String seperatorCtgrType = ifEmpty(numverValueInfo.getSeperatorCtgrType(), ()-> ""); + String seperatorDtlCtgr = ifEmpty(numverValueInfo.getSeperatorDtlCtgr(), ()-> ""); + + String aggregateType = ifEmpty(numverValueInfo.getAggregateType(), ()-> ""); + String sumRefCol = ifEmpty(numverValueInfo.getSumRefCol(), ()-> ""); + + if(!seperatorRefCol.equals("")) { + + String dataColumnValue = dataObject.string(seperatorRefCol); + + if(seperatorCtgrType.equals("date")) { + if(seperatorDtlCtgr.equals("YYYY")) { //연도별 + dataColumnValue = dataColumnValue.substring(0,4); + } else if(seperatorDtlCtgr.equals("YYYYMM")) { //연월별 + dataColumnValue = dataColumnValue.substring(0,6); + } else if(seperatorDtlCtgr.equals("YYYYMMDD")) { //일자별 + dataColumnValue = dataColumnValue.substring(0,8); + } else if(seperatorDtlCtgr.equals("DAY_OF_WEEK")) { //요일별 + dataColumnValue = CmmnUtil.getDayOfWeek(dataColumnValue); + } else if(seperatorDtlCtgr.equals("HH")) { //시간대별 + if(dataColumnValue.length() == 14) { + dataColumnValue = dataColumnValue.substring(8,10); + } else { + dataColumnValue = dataColumnValue.substring(0,2); + } + } - String condition = numberValueInfoList.get(j).getNumberValueSeperator(); - String aggregateType = numberValueInfoList.get(j).getAggregateType(); - - if(!condition.equals("")) { - - if(condition.contains("=")) { + } else if(seperatorCtgrType.equals("code") || seperatorCtgrType.equals("otherCode")) { - String conditionColumn = condition.split("=")[0]; - String conditionColumnValue = dataObject.string(conditionColumn); - String conditionValue = condition.split("=")[1]; + if(seperatorCtgrType.equals("code") + && subsetInfoList != null + && !subsetInfoList.isEmpty() + ) { - if(conditionColumn.endsWith("_DT") && conditionValue.length() == 8) { - conditionColumnValue = conditionColumnValue.substring(0,8); + for(CodeSubsetInfo subsetInfo : subsetInfoList) { + if(subsetInfo.getSourceGroup().equals(seperatorDtlCtgr)) { + if(Arrays.asList(subsetInfo.getSourceCodes()).contains(dataColumnValue)) { + dataColumnValue = subsetInfo.getTargetCode(); + } + } + } } - if(!conditionColumnValue.equals(conditionValue)) { - continue; - } + } + + if(!dataColumnValue.equals(conditionValue)) { + continue; } } - if(aggregateType.startsWith("sum=")) { - aggregateArr[j] += dataObject.number(aggregateType.split("=")[1]).intValue(); + if(aggregateType.equals("sum")) { + aggregateArr[j] += dataObject.number(sumRefCol).intValue(); } else { aggregateArr[j] += 1; } @@ -281,7 +320,8 @@ public class StatBean extends AbstractComponent { int taskSeCdIndex = -1; for(int i=0; i < groupInfoList.size(); i++) { - if(groupInfoList.get(i).getCategoryNameConverter().equals("code=FIM054")) { + if(groupInfoList.get(i).getCtgrType().equals("code") + && groupInfoList.get(i).getDtlCtgr().equals("FIM054")) { taskSeCdIndex = i; } } @@ -294,9 +334,12 @@ public class StatBean extends AbstractComponent { for(int i=0; i < compositeItemId.length ;i++) { GroupInfo groupInfo = groupInfoList.get(i); - String converter = groupInfo.getCategoryNameConverter(); - if(converter.equals("") || converter.equals("plain")) { //일반텍스트 + String ctgrType = groupInfo.getCtgrType(); + String dtlCtgr = groupInfo.getDtlCtgr(); + + + if(ctgrType.equals("") || ctgrType.equals("plain")) { //일반텍스트 compositeItemName[i] = compositeItemId[i]; continue; } @@ -304,13 +347,13 @@ public class StatBean extends AbstractComponent { String itemName = ""; - if(converter.startsWith("code=")){ //공통코드 + if(ctgrType.equals("code")){ //공통코드 - itemName = codeConverter.codeToValue(converter.split("=")[1], compositeItemId[i]); + itemName = codeConverter.codeToValue(dtlCtgr, compositeItemId[i]); - } else if(converter.startsWith("otherCode=")) { //비공통코드 + } else if(ctgrType.equals("otherCode")) { //비공통코드 - if(converter.equals("otherCode=VLTN_CD")) { + if(dtlCtgr.equals("VLTN_CD")) { String taskSeCd = ""; if(taskSeCdIndex != -1) { @@ -324,13 +367,13 @@ public class StatBean extends AbstractComponent { } itemName = codeConverter.vltnCdToValue(taskSeCd, compositeItemId[i]); - } else if(converter.equals("otherCode=VLTN_ID")) { + } else if(dtlCtgr.equals("VLTN_ID")) { itemName = codeConverter.vltnIdToValue(compositeItemId[i]); - } else if(converter.equals("otherCode=SGG_CD")) { + } else if(dtlCtgr.equals("SGG_CD")) { itemName = codeConverter.sggCodeToValue(compositeItemId[i]); - } else if(converter.equals("otherCode=DEPT_CD")) { + } else if(dtlCtgr.equals("DEPT_CD")) { itemName = codeConverter.deptCodeToValue(compositeItemId[i]); - } else if(converter.equals("otherCode=USER_ID")) { + } else if(dtlCtgr.equals("USER_ID")) { itemName = codeConverter.userIdToUserName(compositeItemId[i]); } @@ -365,9 +408,9 @@ public class StatBean extends AbstractComponent { String aggregateType = numberValueInfo.getAggregateType(); - if(aggregateType.startsWith("ratio=")) { + if(aggregateType.equals("ratio")) { - int refIndex = Integer.parseInt(aggregateType.split("=")[1]); + int refIndex = numberValueInfo.getRatioRefIndex(); int totValue = statItem.getNumberValue()[refIndex]; if(totValue == 0) { diff --git a/src/main/java/cokr/xit/fims/stat/service/bean/StatServiceBean.java b/src/main/java/cokr/xit/fims/stat/service/bean/StatServiceBean.java index e7716f99..683a1c50 100644 --- a/src/main/java/cokr/xit/fims/stat/service/bean/StatServiceBean.java +++ b/src/main/java/cokr/xit/fims/stat/service/bean/StatServiceBean.java @@ -66,21 +66,19 @@ public class StatServiceBean extends AbstractServiceBean implements StatService if(statQuery.getNamedNumberValueSeperator().equals("completeAndTotal")) { //완료자료 및 전체자료 - String seperator1 = "COMPLETE_YN=Y"; - String seperator2 = ""; - String globalAggregate = statQuery.getGlobalAggregate(); - String aggregate1 = globalAggregate; - String aggregate2 = globalAggregate; + String globalSumRefCol = ifEmpty(statQuery.getGlobalSumRefCol(), () -> "") ; List numberValueInfoList = new ArrayList(); NumberValueInfo col1 = new NumberValueInfo(); - col1.setNumberValueSeperator(seperator1); - col1.setAggregateType(aggregate1); + col1.setSeperatorRefCol("COMPLETE_YN"); + col1.setConditionValue("Y"); + col1.setAggregateType(globalAggregate); + col1.setSumRefCol(globalSumRefCol); numberValueInfoList.add(col1); NumberValueInfo col2 = new NumberValueInfo(); - col2.setNumberValueSeperator(seperator2); - col2.setAggregateType(aggregate2); + col2.setAggregateType(globalAggregate); + col2.setSumRefCol(globalSumRefCol); numberValueInfoList.add(col2); statQuery.setNumberValueInfoList(numberValueInfoList); @@ -96,7 +94,10 @@ public class StatServiceBean extends AbstractServiceBean implements StatService for(int i=0; i