통계 수정

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

@ -0,0 +1,219 @@
package cokr.xit.fims.cmmn;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import javax.annotation.Resource;
import cokr.xit.base.code.CommonCode;
import cokr.xit.fims.stat.dao.StatMapper;
import cokr.xit.foundation.data.DataObject;
public class CodeConverter {
Map<String, List<CommonCode>> commonCodes = new HashMap<String, List<CommonCode>>();
List<DataObject> sggList = new ArrayList<DataObject>();
List<DataObject> deptList = new ArrayList<DataObject>();
List<DataObject> vltnList = new ArrayList<DataObject>();
List<DataObject> userList = new ArrayList<DataObject>();
@Resource(name = "statMapper")
private StatMapper statMapper;
public CodeConverter(Map<String, List<CommonCode>> commonCodes){
this.commonCodes = commonCodes;
}
/** .
* @param codeGroupName , value
* @return
*/
public String valueToCode(String codeGroupName, String value){
String result = "";
List<CommonCode> commonCodeList = commonCodes.get(codeGroupName);
for(int i = 0; i < commonCodeList.size(); i++) {
if(value.replaceAll(Matcher.quoteReplacement(" "), "").equals(commonCodeList.get(i).getValue().replaceAll(Matcher.quoteReplacement(" "), ""))) {
result = commonCodeList.get(i).getCode();
}
}
return result;
}
/** .
* @param codeGroupName , code
* @return
*/
public String codeToValue(String codeGroupName, String code){
String result = "";
List<CommonCode> commonCodeList = commonCodes.get(codeGroupName);
for(int i = 0; i < commonCodeList.size(); i++) {
if(code.equals(commonCodeList.get(i).getCode())) {
result = commonCodeList.get(i).getValue();
}
}
return result;
}
/** .
* @param dataObject , codeGroupName , codeName , valueName
* @return
*/
public void fillIfEmpty(DataObject dataObject, String codeGroupName, String codeName, String valueName) {
if(!dataObject.string(valueName).equals("") && dataObject.string(codeName).equals("")) {
dataObject.put(codeName, this.valueToCode(codeGroupName, dataObject.string(valueName)));
} else if(dataObject.string(valueName).equals("") && !dataObject.string(codeName).equals("")) {
dataObject.put(valueName, this.codeToValue(codeGroupName, dataObject.string(codeName)));
}
}
/** .
* @param taskSeCd , vltnCd
* @return
*/
public String vltnCdToValue(String taskSeCd, String vltnCd) {
String result = "";
String codeGroup = "";
switch(taskSeCd){
case "PVS" :
codeGroup = "FIM004";
break;
case "BPV" :
codeGroup = "FIM005";
break;
case "DPV" :
codeGroup = "FIM006";
break;
case "ECA" :
codeGroup = "FIM061";
break;
case "TPV" :
codeGroup = "FIM064";
break;
default :
throw new RuntimeException("위반코드 변환 오류");
}
List<CommonCode> commonCodeList = commonCodes.get(codeGroup);
for(int i = 0; i < commonCodeList.size(); i++) {
if(vltnCd.equals(commonCodeList.get(i).getCode())) {
result = commonCodeList.get(i).getValue();
}
}
return result;
}
/** ID .
* @param vltnId ID
* @return
*/
public String vltnIdToValue(String vltnId){
String result = "";
for(int i = 0; i < vltnList.size(); i++) {
if(vltnId.equals(vltnList.get(i).string("VLTN_ID"))) {
result = vltnList.get(i).string("VLTN_NM");
}
}
if(result.equals("")) {
DataObject findRow = statMapper.selectVltnById(vltnId);
if(findRow != null){
vltnList.add(findRow);
result = findRow.string("VLTN_NM");
}
}
return result;
}
/** .
* @param sggCd
* @return
*/
public String sggCodeToValue(String sggCd){
String result = "";
for(int i = 0; i < sggList.size(); i++) {
if(sggCd.equals(sggList.get(i).string("SGG_CD"))) {
result = sggList.get(i).string("SGG_NM");
}
}
if(result.equals("")) {
DataObject findRow = statMapper.selectSggByCode(sggCd);
if(findRow != null){
vltnList.add(findRow);
result = findRow.string("SGG_NM");
}
}
return result;
}
/** .
* @param deptCd
* @return
*/
public String deptCodeToValue(String deptCd){
String result = "";
for(int i = 0; i < deptList.size(); i++) {
if(deptCd.equals(deptList.get(i).string("DEPT_CD"))) {
result = deptList.get(i).string("DEPT_NM");
}
}
if(result.equals("")) {
DataObject findRow = statMapper.selectDeptByCode(deptCd);
if(findRow != null){
vltnList.add(findRow);
result = findRow.string("DEPT_NM");
}
}
return result;
}
/** ID .
* @param userId ID
* @return
*/
public String userIdToUserName(String userId){
String result = "";
for(int i = 0; i < userList.size(); i++) {
if(userId.equals(userList.get(i).string("USER_ID"))) {
result = userList.get(i).string("USER_NM");
}
}
if(result.equals("")) {
DataObject findRow = statMapper.selectUserById(userId);
if(findRow != null){
vltnList.add(findRow);
result = findRow.string("USER_NM");
}
}
return result;
}
}

@ -1,53 +0,0 @@
package cokr.xit.fims.crdn.parsing;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import cokr.xit.base.code.CommonCode;
import cokr.xit.foundation.data.DataObject;
public class CodeConverter {
Map<String, List<CommonCode>> commonCodes = new HashMap<String, List<CommonCode>>();
public CodeConverter(Map<String, List<CommonCode>> commonCodes){
this.commonCodes = commonCodes;
}
public String valueToCode(String codeGroupName, String value){
String result = "";
List<CommonCode> commonCodeList = commonCodes.get(codeGroupName);
for(int i = 0; i < commonCodeList.size(); i++) {
if(value.replaceAll(Matcher.quoteReplacement(" "), "").equals(commonCodeList.get(i).getValue().replaceAll(Matcher.quoteReplacement(" "), ""))) {
result = commonCodeList.get(i).getCode();
}
}
return result;
}
public String codeToValue(String codeGroupName, String code){
String result = "";
List<CommonCode> commonCodeList = commonCodes.get(codeGroupName);
for(int i = 0; i < commonCodeList.size(); i++) {
if(code.equals(commonCodeList.get(i).getCode())) {
result = commonCodeList.get(i).getValue();
}
}
return result;
}
public void fillIfEmpty(DataObject dataObject, String codeGroupName, String codeName, String valueName) {
if(!dataObject.string(valueName).equals("") && dataObject.string(codeName).equals("")) {
dataObject.put(codeName, this.valueToCode(codeGroupName, dataObject.string(valueName)));
} else if(dataObject.string(valueName).equals("") && !dataObject.string(codeName).equals("")) {
dataObject.put(valueName, this.codeToValue(codeGroupName, dataObject.string(codeName)));
}
}
}

@ -15,6 +15,7 @@ import org.apache.commons.io.FilenameUtils;
import cokr.xit.base.code.CommonCode;
import cokr.xit.fims.cmmn.CmmnUtil;
import cokr.xit.fims.cmmn.CodeConverter;
import cokr.xit.foundation.data.DataObject;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;

@ -0,0 +1,19 @@
package cokr.xit.fims.stat.dao;
import org.egovframe.rte.psl.dataaccess.mapper.Mapper;
import cokr.xit.foundation.component.AbstractMapper;
import cokr.xit.foundation.data.DataObject;
@Mapper("statMapper")
public interface StatMapper extends AbstractMapper {
DataObject selectVltnById(String vltnId);
DataObject selectSggByCode(String sggCd);
DataObject selectDeptByCode(String deptCd);
DataObject selectUserById(String userId);
}

@ -13,7 +13,7 @@ import org.springframework.stereotype.Component;
import cokr.xit.base.code.CommonCode;
import cokr.xit.fims.cmmn.CmmnQuery;
import cokr.xit.fims.crdn.parsing.CodeConverter;
import cokr.xit.fims.cmmn.CodeConverter;
import cokr.xit.fims.stat.Stat;
import cokr.xit.fims.stat.StatItem;
import cokr.xit.fims.stat.StatQuery;
@ -69,23 +69,7 @@ public class StatBean extends AbstractComponent {
statQuery.setCompositeNumberValueSeperator(compositeNumberValueSeperator);
//통계 항목별 그룹핑
String[] categorizations = statQuery.getCategorization();
Map<String, List<DataObject>> group = queryResult.stream()
.collect(
Collectors.groupingBy(
(item) -> {
String result = "";
for(int i = 0; i < categorizations.length; i++) {
if(i != 0) {
result += ",";
}
result += item.string(categorizations[i]);
}
return result;
}
)
);
Map<String, List<DataObject>> group = this.grouping(queryResult, statQuery);
//고정 항목 설정
@ -118,6 +102,32 @@ public class StatBean extends AbstractComponent {
return stat;
}
/** .
* @param queryResult SQL , statQuery
* @return
*/
public Map<String, List<DataObject>> grouping(List<DataObject> queryResult, StatQuery statQuery){
String[] categorizations = statQuery.getCategorization();
Map<String, List<DataObject>> group = queryResult.stream()
.collect(
Collectors.groupingBy(
(item) -> {
String result = "";
for(int i = 0; i < categorizations.length; i++) {
if(i != 0) {
result += ",";
}
result += item.string(categorizations[i]);
}
return result;
}
)
);
return group;
}
/** .
* @param group , fixedItemId ID;
* @return
@ -205,30 +215,75 @@ public class StatBean extends AbstractComponent {
}
/** .
* @param statItems , categoryNameConverter , allCode
* @param statItems , statQuery , allCode
* @return
*/
public void attachItemName(List<StatItem> statItems, String[] categoryNameConverter, Map<String, List<CommonCode>> allCode) {
public void attachItemName(List<StatItem> statItems, StatQuery statQuery, Map<String, List<CommonCode>> allCode) {
CodeConverter codeConverter = new CodeConverter(allCode);
String[] nameConverters = categoryNameConverter;
String[] nameConverters = statQuery.getCategoryNameConverter();
int taskSeCdIndex = -1;
for(int i=0; i < nameConverters.length; i++) {
if(nameConverters[i].equals("code=FIM054")) {
taskSeCdIndex = i;
}
}
for(StatItem statItem : statItems) {
String[] compositeItemId = statItem.getItemId();
String[] compositeItemName = new String[compositeItemId.length];
for(int i=0; i < compositeItemId.length ;i++) {
if(nameConverters[i].equals("") || nameConverters[i].equals("plain")) {
if(nameConverters[i].equals("") || nameConverters[i].equals("plain")) { //일반텍스트
compositeItemName[i] = compositeItemId[i];
} else if(nameConverters[i].startsWith("code=")){
String itemName = codeConverter.codeToValue(nameConverters[i].split("=")[1], compositeItemId[i]);
compositeItemName[i] = itemName;
continue;
}
String itemName = "";
if(nameConverters[i].startsWith("code=")){ //공통코드
itemName = codeConverter.codeToValue(nameConverters[i].split("=")[1], compositeItemId[i]);
} else if(nameConverters[i].startsWith("otherCode=")) { //비공통코드
if(nameConverters[i].equals("otherCode=VLTN_CD")) {
String taskSeCd = "";
if(taskSeCdIndex != -1) {
taskSeCd = compositeItemId[taskSeCdIndex];
} else if(!statQuery.getTaskSeCd().equals("")) {
taskSeCd = statQuery.getTaskSeCd();
}
if(taskSeCd.equals("")) {
throw new RuntimeException("위반코드 변환 오류");
}
itemName = codeConverter.vltnCdToValue(taskSeCd, compositeItemId[i]);
} else if(nameConverters[i].equals("otherCode=VLTN_ID")) {
itemName = codeConverter.vltnIdToValue(compositeItemId[i]);
} else if(nameConverters[i].equals("otherCode=SGG_CD")) {
itemName = codeConverter.sggCodeToValue(compositeItemId[i]);
} else if(nameConverters[i].equals("otherCode=DEPT_CD")) {
itemName = codeConverter.deptCodeToValue(compositeItemId[i]);
} else if(nameConverters[i].equals("otherCode=USER_ID")) {
itemName = codeConverter.userIdToUserName(compositeItemId[i]);
}
}
compositeItemName[i] = itemName;
}
statItem.setItemName(compositeItemName);
}
statItem.setItemName(compositeItemName);
}
}
/** .

@ -193,7 +193,7 @@ public class StatServiceBean extends AbstractServiceBean implements StatService
stat = statBean.groupByCartegory(queryResult, statQuery);
statBean.attachItemName(stat.getStatItems(), statQuery.getCategoryNameConverter(), commonCodes);
statBean.attachItemName(stat.getStatItems(), statQuery, commonCodes);
if(statQuery.getRegroupInfos() != null){
statBean.regroupItem(stat.getStatItems(), statQuery.getRegroupInfos());

@ -47,6 +47,17 @@ public class StatController extends ApplicationController {
for(int i=0; i < categoryNameConverter.length; i++) {
if(categoryNameConverter[i].startsWith("code=")) {
codeGroup.add(categoryNameConverter[i].split("=")[1]);
} else if(categoryNameConverter[i].startsWith("otherCode=")) {
if(categoryNameConverter[i].equals("otherCode=VLTN_CD")) {
codeGroup.add("FIM054");
codeGroup.add("FIM004");
codeGroup.add("FIM005");
codeGroup.add("FIM006");
codeGroup.add("FIM061");
codeGroup.add("FIM064");
}
}
}

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cokr.xit.fims.stat.dao.StatMapper">
<select id="selectVltnById" parameterType="string" resultType="dataobject">
SELECT VLTN_ID
, VLTN_NM
FROM TB_VLTN_INFO
WHERE VLTN_ID = #{vltnId}
</select>
<select id="selectSggByCode" parameterType="string" resultType="dataobject">
SELECT SGG_CD
, SGG_NM
FROM TB_SGG_INFO
WHERE SGG_CD = #{sggCd}
</select>
<select id="selectDeptByCode" parameterType="string" resultType="dataobject">
SELECT DEPT_CD
, DEPT_NM
FROM TB_DEPT_INFO
WHERE DEPT_CD = #{deptCd}
</select>
<select id="selectUserById" parameterType="string" resultType="dataobject">
SELECT USER_ID
, USER_NM
FROM TB_USER
WHERE USER_ID = #{userId}
</select>
</mapper>
Loading…
Cancel
Save