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