diff --git a/epmet-module/data-report/data-report-client/src/main/java/com/epmet/evaluationindex/screen/dto/result/IndexDictResultDTO.java b/epmet-module/data-report/data-report-client/src/main/java/com/epmet/evaluationindex/screen/dto/result/IndexDictResultDTO.java new file mode 100644 index 0000000000..196837f220 --- /dev/null +++ b/epmet-module/data-report/data-report-client/src/main/java/com/epmet/evaluationindex/screen/dto/result/IndexDictResultDTO.java @@ -0,0 +1,30 @@ +package com.epmet.evaluationindex.screen.dto.result; + +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * 评价指标字典表数据--接口返参 + * @Author sun + */ +@Data +public class IndexDictResultDTO implements Serializable { + + private static final long serialVersionUID = 3860268744336541373L; + + /** + * 指标名 + */ + private String indexName; + /** + * 指标code + */ + private String indexCode; + /** + * 指标值类型 百分比:percent + */ + private String valueType; + +} diff --git a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/constant/FactConstant.java b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/constant/FactConstant.java index 70c5614f65..4e2449c81c 100644 --- a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/constant/FactConstant.java +++ b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/constant/FactConstant.java @@ -45,4 +45,20 @@ public interface FactConstant { * 网格相关 */ String WANG_GE_XIANG_GUAN = "wanggexiangguan"; + /** + * 评价指标类型-无 + */ + String NONE = "none"; + /** + * 评价指标类型-整数 + */ + String INTEGER = "integer"; + /** + * 评价指标类型-小数 + */ + String DECIMAL = "decimal"; + /** + * 评价指标类型-百分比 + */ + String PERCENT = "percent"; } diff --git a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/dao/fact/IndexDictDao.java b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/dao/fact/IndexDictDao.java new file mode 100644 index 0000000000..893820cf1c --- /dev/null +++ b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/dao/fact/IndexDictDao.java @@ -0,0 +1,49 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.datareport.dao.fact; + +import com.epmet.evaluationindex.screen.dto.result.IndexDictResultDTO; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +/** + * 评价指标字典 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-09-02 + */ +@Mapper +public interface IndexDictDao { + + /** + * @param + * @Description 查询指标字典表是百分比类型的数据 + * @author sun + */ + List selectList(); + + /** + * @param + * @Description 根据indexCode查询指标字典表具体数据 + * @author sun + */ + IndexDictResultDTO selectIndexDict(@Param("indexCode") String indexCode); +} diff --git a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/fact/impl/FactIndexServiceImpl.java b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/fact/impl/FactIndexServiceImpl.java index 523bf3a7e5..68b3fd1f60 100644 --- a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/fact/impl/FactIndexServiceImpl.java +++ b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/fact/impl/FactIndexServiceImpl.java @@ -15,12 +15,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; +import java.text.NumberFormat; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.LinkedList; -import java.util.List; +import java.util.*; /** * 数据改版api @@ -47,6 +45,8 @@ public class FactIndexServiceImpl implements FactIndexService { private FactIndexGridScoreDao factIndexGridScoreDao; @Autowired private FactIndexGridSubScoreDao factIndexGridSubScoreDao; + @Autowired + private IndexDictDao indexDictDao; /** * @param formDTO @@ -125,19 +125,27 @@ public class FactIndexServiceImpl implements FactIndexService { AblityIndexResultDTO nl = new AblityIndexResultDTO(); nl.setIndexCode(FactConstant.NLZB); nl.setScoreList(nlList); - if(null != nlList){resultList.add(nl);} + if (null != nlList) { + resultList.add(nl); + } AblityIndexResultDTO dj = new AblityIndexResultDTO(); dj.setIndexCode(FactConstant.DJNL); dj.setScoreList(djList); - if(null != djList){resultList.add(dj);} + if (null != djList) { + resultList.add(dj); + } AblityIndexResultDTO zl = new AblityIndexResultDTO(); zl.setIndexCode(FactConstant.ZLNL); zl.setScoreList(zlList); - if(null != zlList){resultList.add(zl);} + if (null != zlList) { + resultList.add(zl); + } AblityIndexResultDTO fw = new AblityIndexResultDTO(); fw.setIndexCode(FactConstant.FWNL); fw.setScoreList(fwList); - if(null != fwList){resultList.add(fw);} + if (null != fwList) { + resultList.add(fw); + } return resultList; } @@ -203,9 +211,15 @@ public class FactIndexServiceImpl implements FactIndexService { throw new RenException(String.format("按月份查询各项能力分数,orgType类型错误,组织Id:%s,类型Type:%s", formDTO.getOrgId(), formDTO.getOrgType())); } //5.封装数据并返回 - if(null != dj){resultList.add(dj);} - if(null != zl){resultList.add(zl);} - if(null != fw){resultList.add(fw);} + if (null != dj) { + resultList.add(dj); + } + if (null != zl) { + resultList.add(zl); + } + if (null != fw) { + resultList.add(fw); + } return resultList; } @@ -278,15 +292,21 @@ public class FactIndexServiceImpl implements FactIndexService { MonthScoreListResultDTO dj = new MonthScoreListResultDTO(); dj.setIndexCode(FactConstant.DJNL); dj.setScoreList(djList); - if(null != djList){resultList.add(dj);} + if (null != djList) { + resultList.add(dj); + } MonthScoreListResultDTO zl = new MonthScoreListResultDTO(); zl.setIndexCode(FactConstant.ZLNL); zl.setScoreList(zlList); - if(null != zlList){resultList.add(zl);} + if (null != zlList) { + resultList.add(zl); + } MonthScoreListResultDTO fw = new MonthScoreListResultDTO(); fw.setIndexCode(FactConstant.FWNL); fw.setScoreList(fwList); - if(null != fwList){resultList.add(fw);} + if (null != fwList) { + resultList.add(fw); + } return resultList; } @@ -333,7 +353,28 @@ public class FactIndexServiceImpl implements FactIndexService { throw new RenException(String.format("按月查询各项指标数据,orgType类型错误,组织Id:%s,类型Type:%s", formDTO.getOrgId(), formDTO.getOrgType())); } - //4.调用方法判断各项指标是数字指标还是百分比指标 //TODO 记得value值保留一位小数 是数的保留零位小数 是百分比的保留一位小数 + //4.查询指标字典表数据 + List list = indexDictDao.selectList(); + //5.遍历数据,判断数据类型并处理 + /*NumberFormat nf = NumberFormat.getPercentInstance(); + nf.setMaximumFractionDigits(1);*/ + resultList.forEach(result -> { + list.forEach(l -> { + if (result.getKey().equals(l.getIndexCode())) { + //小数类型,四舍五入保留小数点后一位 + if (FactConstant.DECIMAL.equals(l.getValueType())) { + BigDecimal num = new BigDecimal(result.getValue()).setScale(1, BigDecimal.ROUND_HALF_UP); + result.setValue(num.toString()); + } + //百分数类型,四舍五入保留小数点后一位并转成百分比 + if (FactConstant.PERCENT.equals(l.getValueType())) { + BigDecimal num = new BigDecimal(result.getValue()).setScale(1, BigDecimal.ROUND_HALF_UP); + result.setValue(num+"%"); + } + } + }); + }); + return resultList; } @@ -373,7 +414,30 @@ public class FactIndexServiceImpl implements FactIndexService { throw new RenException(String.format("按月查询各项指标最近12个月数据,orgType类型错误,组织Id:%s,类型Type:%s", formDTO.getOrgId(), formDTO.getOrgType())); } - //6.调用方法判断各项指标是数字指标还是百分比指标//TODO 记得value值保留一位小数 是数的保留零位小数 是百分比的保留一位小数 + //6.查询指标字典表具体数据 + IndexDictResultDTO dictDTO = indexDictDao.selectIndexDict(formDTO.getKey()); + if (null == dictDTO) { + throw new RenException(String.format("根据评价指标indexCode未查询到字典表数据,indexCode值:%s", formDTO.getKey())); + } + + //7.遍历数据,判断数据类型并处理 + /*NumberFormat nf = NumberFormat.getPercentInstance(); + nf.setMaximumFractionDigits(1);*/ + //小数类型,四舍五入保留小数点后一位 + if (FactConstant.DECIMAL.equals(dictDTO.getValueType())) { + resultList.forEach(result -> { + BigDecimal num = new BigDecimal(result.getAblity()).setScale(1, BigDecimal.ROUND_HALF_UP); + result.setAblity(num.toString()); + }); + } + //百分数类型,四舍五入保留小数点后一位并转成百分比 + if (FactConstant.PERCENT.equals(dictDTO.getValueType())) { + resultList.forEach(result -> { + BigDecimal num = new BigDecimal(result.getAblity()).setScale(1, BigDecimal.ROUND_HALF_UP); + result.setAblity(num+"%"); + }); + } + return resultList; } diff --git a/epmet-module/data-report/data-report-server/src/main/resources/mapper/fact/FactIndexAgencySubScoreDao.xml b/epmet-module/data-report/data-report-server/src/main/resources/mapper/fact/FactIndexAgencySubScoreDao.xml index 879d8b521e..9744157016 100644 --- a/epmet-module/data-report/data-report-server/src/main/resources/mapper/fact/FactIndexAgencySubScoreDao.xml +++ b/epmet-module/data-report/data-report-server/src/main/resources/mapper/fact/FactIndexAgencySubScoreDao.xml @@ -6,7 +6,7 @@ SELECT fact.month_id AS "monthId", - IF(fact.origin_value='',0,IFNULL(ROUND(fact.origin_value,1),0)) AS "ablity" + IF(fact.origin_value='',0,IFNULL(fact.origin_value,0)) AS "ablity" FROM fact_index_agency_sub_score fact LEFT JOIN index_dict dict ON fact.index_code = dict.index_code diff --git a/epmet-module/data-report/data-report-server/src/main/resources/mapper/fact/FactIndexCommunitySubScoreDao.xml b/epmet-module/data-report/data-report-server/src/main/resources/mapper/fact/FactIndexCommunitySubScoreDao.xml index 8c8e780259..197b6f9bf9 100644 --- a/epmet-module/data-report/data-report-server/src/main/resources/mapper/fact/FactIndexCommunitySubScoreDao.xml +++ b/epmet-module/data-report/data-report-server/src/main/resources/mapper/fact/FactIndexCommunitySubScoreDao.xml @@ -6,7 +6,7 @@ SELECT fact.month_id AS "monthId", - IF(fact.origin_value='',0,IFNULL(ROUND(fact.origin_value,1),0)) AS "ablity" + IF(fact.origin_value='',0,IFNULL(fact.origin_value,0)) AS "ablity" FROM fact_index_community_sub_score fact LEFT JOIN index_dict dict ON fact.index_code = dict.index_code diff --git a/epmet-module/data-report/data-report-server/src/main/resources/mapper/fact/FactIndexGridSubScoreDao.xml b/epmet-module/data-report/data-report-server/src/main/resources/mapper/fact/FactIndexGridSubScoreDao.xml index d48f24966e..1b317e2791 100644 --- a/epmet-module/data-report/data-report-server/src/main/resources/mapper/fact/FactIndexGridSubScoreDao.xml +++ b/epmet-module/data-report/data-report-server/src/main/resources/mapper/fact/FactIndexGridSubScoreDao.xml @@ -6,7 +6,7 @@ SELECT fact.month_id AS "monthId", - IF(fact.origin_value='',0,IFNULL(ROUND(fact.origin_value,1),0)) AS "ablity" + IF(fact.origin_value='',0,IFNULL(fact.origin_value,0)) AS "ablity" FROM fact_index_grid_sub_score fact LEFT JOIN index_dict dict ON fact.index_code = dict.index_code diff --git a/epmet-module/data-report/data-report-server/src/main/resources/mapper/fact/IndexDictDao.xml b/epmet-module/data-report/data-report-server/src/main/resources/mapper/fact/IndexDictDao.xml new file mode 100644 index 0000000000..0784877dda --- /dev/null +++ b/epmet-module/data-report/data-report-server/src/main/resources/mapper/fact/IndexDictDao.xml @@ -0,0 +1,31 @@ + + + + + + + + + +