통계 수정

main
이범준 1 year ago
parent 58b70d3663
commit f2df91c63c

@ -26,6 +26,11 @@ public class StatQuery extends CmmnQuery {
*/ */
private String[] categorization; private String[] categorization;
/**
*
*/
private String[] categorizationAddOption;
/** /**
* (ID) * (ID)
*/ */
@ -93,6 +98,15 @@ public class StatQuery extends CmmnQuery {
return self(); return self();
} }
public String[] getCategorizationAddOption() {
return ifEmpty(categorizationAddOption, () -> null);
}
public <T extends StatQuery> T setCategorizationAddOption(String... categorizationAddOption) {
this.categorizationAddOption = categorizationAddOption;
return self();
}
public String[] getCategoryNameConverter() { public String[] getCategoryNameConverter() {
return ifEmpty(categoryNameConverter, () -> null); return ifEmpty(categoryNameConverter, () -> null);
} }

@ -1,10 +1,14 @@
package cokr.xit.fims.stat.service.bean; package cokr.xit.fims.stat.service.bean;
import java.lang.reflect.Method; 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.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -24,6 +28,35 @@ import cokr.xit.foundation.data.DataObject;
@Component("statBean") @Component("statBean")
public class StatBean extends AbstractComponent { public class StatBean extends AbstractComponent {
/** .
* @param sql query, dayCol , from , to
* @return
*/
public void daySetting(CmmnQuery someQuery, String dayCol, String from, String to) {
try {
if(dayCol.equals("REG_DT")) {
Method m0 = CmmnQuery.class.getDeclaredMethod("setSchDateOpt", String.class);
m0.invoke(someQuery, "regDt");
Method m1 = CmmnQuery.class.getDeclaredMethod("setSchDateFrom", String.class);
m1.invoke(someQuery, from);
Method m2 = CmmnQuery.class.getDeclaredMethod("setSchDateTo", String.class);
m2.invoke(someQuery, to);
} else {
if(dayCol.equals("CRDN_YMD")) {
Method m1 = someQuery.getClass().getDeclaredMethod("setSchCrdnYmdFrom", String.class);
m1.invoke(someQuery, from);
Method m2 = someQuery.getClass().getDeclaredMethod("setSchCrdnYmdTo", String.class);
m2.invoke(someQuery, to);
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/** . /** .
* @param queryResult SQL , statQuery * @param queryResult SQL , statQuery
* @return * @return
@ -109,6 +142,9 @@ public class StatBean extends AbstractComponent {
public Map<String, List<DataObject>> grouping(List<DataObject> queryResult, StatQuery statQuery){ public Map<String, List<DataObject>> grouping(List<DataObject> queryResult, StatQuery statQuery){
String[] categorizations = statQuery.getCategorization(); String[] categorizations = statQuery.getCategorization();
String[] addOptions = statQuery.getCategorizationAddOption();
Map<String, List<DataObject>> group = queryResult.stream() Map<String, List<DataObject>> group = queryResult.stream()
.collect( .collect(
Collectors.groupingBy( Collectors.groupingBy(
@ -118,7 +154,33 @@ public class StatBean extends AbstractComponent {
if(i != 0) { if(i != 0) {
result += ","; result += ",";
} }
result += item.string(categorizations[i]); String colValue = item.string(categorizations[i]);
if(addOptions != null) {
if(addOptions[i].equals("YYYY")) { //연도별
result += colValue.substring(0,4);
} else if(addOptions[i].equals("YYYYMM")) { //연월별
result += colValue.substring(0,6);
} else if(addOptions[i].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;
} else if(addOptions[i].equals("HH")) { //시간대별
if(colValue.length() == 14) {
result += colValue.substring(8,10);
} else {
result += colValue.substring(0,2);
}
} else {
result += colValue;
}
} else {
result += colValue;
}
} }
return result; return result;
} }
@ -325,33 +387,35 @@ public class StatBean extends AbstractComponent {
} }
} }
/** . /** (%) .
* @param sql query, dayCol , from , to * @param statItems , statQuery
* @return * @return
*/ */
public void daySetting(CmmnQuery someQuery, String dayCol, String from, String to) { public void attachRatioValue(List<StatItem> statItems, StatQuery statQuery) {
try {
if(dayCol.equals("REG_DT")) {
Method m0 = CmmnQuery.class.getDeclaredMethod("setSchDateOpt", String.class); String[] aggregateTypes = statQuery.getAggregateType();
m0.invoke(someQuery, "regDt");
Method m1 = CmmnQuery.class.getDeclaredMethod("setSchDateFrom", String.class); for(StatItem statItem : statItems) {
m1.invoke(someQuery, from);
Method m2 = CmmnQuery.class.getDeclaredMethod("setSchDateTo", String.class); for(int i = 0; i < aggregateTypes.length ; i++) {
m2.invoke(someQuery, to);
} else { if(aggregateTypes[i].startsWith("ratioRef=")) {
int refIndex = Integer.parseInt(aggregateTypes[i].split("=")[1]);
int totValue = statItem.getNumberValue()[refIndex];
if(totValue == 0) {
statItem.getNumberValue()[i] = 0;
} else {
statItem.getNumberValue()[i] = statItem.getNumberValue()[i] * 100 / totValue;
}
if(dayCol.equals("CRDN_YMD")) {
Method m1 = someQuery.getClass().getDeclaredMethod("setSchCrdnYmdFrom", String.class);
m1.invoke(someQuery, from);
Method m2 = someQuery.getClass().getDeclaredMethod("setSchCrdnYmdTo", String.class);
m2.invoke(someQuery, to);
} }
} }
} catch (Exception e) {
throw new RuntimeException(e);
} }
} }
} }

@ -2,6 +2,7 @@ package cokr.xit.fims.stat.service.bean;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -119,9 +120,6 @@ public class StatServiceBean extends AbstractServiceBean implements StatService
} }
String domain = ""; String domain = "";
String[] categorizations = statQuery.getCategorization(); String[] categorizations = statQuery.getCategorization();
@ -191,14 +189,28 @@ public class StatServiceBean extends AbstractServiceBean implements StatService
} }
//통계 생성
stat = statBean.groupByCartegory(queryResult, statQuery); stat = statBean.groupByCartegory(queryResult, statQuery);
//통계 항목명 변환
statBean.attachItemName(stat.getStatItems(), statQuery, commonCodes); statBean.attachItemName(stat.getStatItems(), statQuery, commonCodes);
//통계 항목 재그룹화
if(statQuery.getRegroupInfos() != null){ if(statQuery.getRegroupInfos() != null){
statBean.regroupItem(stat.getStatItems(), statQuery.getRegroupInfos()); statBean.regroupItem(stat.getStatItems(), statQuery.getRegroupInfos());
} }
//비율 계산
boolean exsistRatioValue = false;
for(String aggregateType : Arrays.asList(statQuery.getAggregateType())) {
if(aggregateType.startsWith("ratioRef=")) {
exsistRatioValue = true;
}
}
if(exsistRatioValue){
statBean.attachRatioValue(stat.getStatItems(), statQuery);
}
if(numberValueLabel != null) { if(numberValueLabel != null) {
stat.setNumberValueLabel(numberValueLabel); stat.setNumberValueLabel(numberValueLabel);
} }

Loading…
Cancel
Save