From 58b70d366307082871cf61c6c2b7f47050a527a6 Mon Sep 17 00:00:00 2001 From: leebeomjun Date: Thu, 2 Nov 2023 15:25:20 +0900 Subject: [PATCH] =?UTF-8?q?=ED=86=B5=EA=B3=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cokr/xit/fims/cmmn/CodeConverter.java | 219 ++++++++++++++++++ .../xit/fims/crdn/parsing/CodeConverter.java | 53 ----- .../xit/fims/crdn/parsing/LayoutParser.java | 1 + .../cokr/xit/fims/stat/dao/StatMapper.java | 19 ++ .../xit/fims/stat/service/bean/StatBean.java | 109 ++++++--- .../stat/service/bean/StatServiceBean.java | 2 +- .../xit/fims/stat/web/StatController.java | 11 + .../sql/mapper/fims/stat/stat-mapper.xml | 33 +++ 8 files changed, 366 insertions(+), 81 deletions(-) create mode 100644 src/main/java/cokr/xit/fims/cmmn/CodeConverter.java delete mode 100644 src/main/java/cokr/xit/fims/crdn/parsing/CodeConverter.java create mode 100644 src/main/java/cokr/xit/fims/stat/dao/StatMapper.java create mode 100644 src/main/resources/sql/mapper/fims/stat/stat-mapper.xml diff --git a/src/main/java/cokr/xit/fims/cmmn/CodeConverter.java b/src/main/java/cokr/xit/fims/cmmn/CodeConverter.java new file mode 100644 index 00000000..a9f78b33 --- /dev/null +++ b/src/main/java/cokr/xit/fims/cmmn/CodeConverter.java @@ -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> commonCodes = new HashMap>(); + + List sggList = new ArrayList(); + List deptList = new ArrayList(); + List vltnList = new ArrayList(); + List userList = new ArrayList(); + + @Resource(name = "statMapper") + private StatMapper statMapper; + + public CodeConverter(Map> commonCodes){ + this.commonCodes = commonCodes; + } + + /** 코드값으로 코드를 반환한다. + * @param codeGroupName 코드그룹명, value 코드값 + * @return 코드 + */ + public String valueToCode(String codeGroupName, String value){ + String result = ""; + + List 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 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 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; + } + + +} diff --git a/src/main/java/cokr/xit/fims/crdn/parsing/CodeConverter.java b/src/main/java/cokr/xit/fims/crdn/parsing/CodeConverter.java deleted file mode 100644 index e9d49da8..00000000 --- a/src/main/java/cokr/xit/fims/crdn/parsing/CodeConverter.java +++ /dev/null @@ -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> commonCodes = new HashMap>(); - - public CodeConverter(Map> commonCodes){ - this.commonCodes = commonCodes; - } - - public String valueToCode(String codeGroupName, String value){ - String result = ""; - - List 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 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))); - } - } -} diff --git a/src/main/java/cokr/xit/fims/crdn/parsing/LayoutParser.java b/src/main/java/cokr/xit/fims/crdn/parsing/LayoutParser.java index 67d7f180..be9e3fba 100644 --- a/src/main/java/cokr/xit/fims/crdn/parsing/LayoutParser.java +++ b/src/main/java/cokr/xit/fims/crdn/parsing/LayoutParser.java @@ -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; diff --git a/src/main/java/cokr/xit/fims/stat/dao/StatMapper.java b/src/main/java/cokr/xit/fims/stat/dao/StatMapper.java new file mode 100644 index 00000000..a1194422 --- /dev/null +++ b/src/main/java/cokr/xit/fims/stat/dao/StatMapper.java @@ -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); + +} 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 829ee686..d1ad74b2 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 @@ -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> 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> group = this.grouping(queryResult, statQuery); //고정 항목 설정 @@ -118,6 +102,32 @@ public class StatBean extends AbstractComponent { return stat; } + /**통계요청에 따라 데이터목록을 그룹핑한다. + * @param queryResult SQL쿼리 처리 결과, statQuery 통계 요청 + * @return 통계 항목별로 그룹핑된 목록 + */ + public Map> grouping(List queryResult, StatQuery statQuery){ + String[] categorizations = statQuery.getCategorization(); + + Map> 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 statItems, String[] categoryNameConverter, Map> allCode) { + public void attachItemName(List statItems, StatQuery statQuery, Map> 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); + } } /** 통계의 일부 항목을 합쳐 새 범주로 묶는다. 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 b5e2ad9f..217d082b 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 @@ -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()); diff --git a/src/main/java/cokr/xit/fims/stat/web/StatController.java b/src/main/java/cokr/xit/fims/stat/web/StatController.java index 6350316c..716fe94c 100644 --- a/src/main/java/cokr/xit/fims/stat/web/StatController.java +++ b/src/main/java/cokr/xit/fims/stat/web/StatController.java @@ -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"); + } + } } diff --git a/src/main/resources/sql/mapper/fims/stat/stat-mapper.xml b/src/main/resources/sql/mapper/fims/stat/stat-mapper.xml new file mode 100644 index 00000000..92a65791 --- /dev/null +++ b/src/main/resources/sql/mapper/fims/stat/stat-mapper.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + \ No newline at end of file