Browse Source

区直部门暂存

master
yinzuomei 5 years ago
parent
commit
6b2730e4aa
  1. 2
      epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/constant/IndexCalConstant.java
  2. 4
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java
  3. 35
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcoll/FactIndexGovrnAblityDeptMonthlyDao.java
  4. 146
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/DeptScoreServiceImpl.java
  5. 61
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcoll/FactIndexGovrnAblityDeptMonthlyDao.xml

2
epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/constant/IndexCalConstant.java

@ -12,6 +12,8 @@ public interface IndexCalConstant {
String GRID_ID="GRID_ID";
String DEPT_ID="DEPT_ID";
String AGENCY_ID="AGENCY_ID";
String PARENT_AGENCY_ID = "parentAgencyId";

4
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java

@ -17,6 +17,7 @@ import com.epmet.entity.evaluationindex.indexcoll.FactIndexServiceAblityGridMont
import com.epmet.entity.evaluationindex.screen.ScreenCustomerGridEntity;
import com.epmet.entity.stats.DimAgencyEntity;
import com.epmet.service.StatsDemoService;
import com.epmet.service.evaluationindex.indexcal.DeptScoreService;
import com.epmet.service.evaluationindex.indexcal.GridCorreLationService;
import com.epmet.service.evaluationindex.indexcal.IndexCalculateCommunityService;
import com.epmet.service.evaluationindex.indexcal.IndexCalculateStreetService;
@ -53,6 +54,8 @@ public class DemoController {
private GridCorreLationService gridCorreLationService;
@Autowired
private IndexCalculateStreetService indexCalculateStreetService;
@Autowired
private DeptScoreService deptScoreService;
@GetMapping("testAlarm")
public void testAlarm() {
@ -162,6 +165,7 @@ public class DemoController {
// List<GridScoreDTO> gridScoreDTOList=gridScoreDao.selectList(formDTO);
// return new Result<List<GridScoreDTO>>().ok(gridScoreDTOList);
gridCorreLationService.calculateGridCorreLation(formDTO);
// deptScoreService.calculateDeptCorreLation(formDTO);
return new Result();
}

35
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcoll/FactIndexGovrnAblityDeptMonthlyDao.java

@ -17,12 +17,14 @@ package com.epmet.dao.evaluationindex.indexcoll; /**
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dto.indexcal.CalculateCommonFormDTO;
import com.epmet.dto.indexcollect.form.DeptGovrnAbilityFormDTO;
import com.epmet.entity.evaluationindex.indexcoll.FactIndexGovrnAblityDeptMonthlyEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* 治理能力-部门相关数据
@ -63,4 +65,37 @@ public interface FactIndexGovrnAblityDeptMonthlyDao extends BaseDao<FactIndexGov
* @Date 10:52 2020-08-20
**/
void batchInsertFactIndexGovrnAblityDeptMonthly(@Param("list") List<DeptGovrnAbilityFormDTO> list, @Param("customerId")String customerId);
/**
* @return java.lang.Integer
* @param calculateCommonFormDTO
* @author yinzuomei
* @description 查询fact_index_govrn_ablity_dept_monthly治理能力-区直部门相关数据 当前月共上传了多少条记录
* @Date 2020/9/3 9:31
**/
Integer selectCount(CalculateCommonFormDTO calculateCommonFormDTO);
/**
* @return java.util.Map<java.lang.String,java.lang.Object>
* @param calculateCommonFormDTO
* @author yinzuomei
* @description 计算最大最小值
* @Date 2020/9/3 9:36
**/
Map<String, Object> selectExtremeValue(CalculateCommonFormDTO calculateCommonFormDTO);
/**
* @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
* @param customerId 客户id
* @param monthId yyyyMM
* @param offset
* @param pageSize
* @author yinzuomei
* @description
* @Date 2020/9/3 11:00
**/
List<Map<String, Object>> selectListByMonthId(@Param("customerId") String customerId,
@Param("monthId") String monthId,
@Param("offset") Integer offset,
@Param("pageSize") Integer pageSize);
}

146
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/DeptScoreServiceImpl.java

@ -19,7 +19,10 @@ package com.epmet.service.evaluationindex.indexcal.impl;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.constant.IndexCalConstant;
import com.epmet.dao.evaluationindex.indexcal.DeptScoreDao;
import com.epmet.dao.evaluationindex.indexcoll.FactIndexGovrnAblityDeptMonthlyDao;
import com.epmet.dto.indexcal.CalculateCommonFormDTO;
@ -27,13 +30,26 @@ import com.epmet.entity.evaluationindex.indexcal.DeptScoreEntity;
import com.epmet.entity.evaluationindex.screen.IndexGroupDetailEntity;
import com.epmet.eum.IndexCodeEnum;
import com.epmet.service.evaluationindex.indexcal.DeptScoreService;
import com.epmet.service.evaluationindex.indexcal.IndexCodeFieldReService;
import com.epmet.service.evaluationindex.screen.IndexGroupDetailService;
import com.epmet.support.normalizing.BigDecimalScoreCalculator;
import com.epmet.support.normalizing.Correlation;
import com.epmet.support.normalizing.ScoreCalculator;
import com.epmet.support.normalizing.ScoreConstants;
import com.epmet.support.normalizing.batch.IndexInputVO;
import com.epmet.support.normalizing.batch.SampleValue;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
@ -49,6 +65,8 @@ public class DeptScoreServiceImpl extends BaseServiceImpl<DeptScoreDao, DeptScor
private IndexGroupDetailService getDetailListByParentCode;
@Autowired
private FactIndexGovrnAblityDeptMonthlyDao factIndexGovrnAblityDeptMonthlyDao;
@Autowired
private IndexCodeFieldReService indexCodeFieldReService;
/**
* @param formDTO
@ -60,15 +78,135 @@ public class DeptScoreServiceImpl extends BaseServiceImpl<DeptScoreDao, DeptScor
@Override
public Boolean calculateDeptCorreLation(CalculateCommonFormDTO formDTO) {
//获取指标权重
List<IndexGroupDetailEntity> parentIndexDetails = getDetailListByParentCode.getDetailListByParentCode(formDTO.getCustomerId(),
List<IndexGroupDetailEntity> indexGroupDetailEntityList = getDetailListByParentCode.getDetailListByParentCode(formDTO.getCustomerId(),
IndexCodeEnum.QU_ZHI_BU_MEN.getCode(),
IndexCodeEnum.ZHI_LI_NENG_LI.getCode());
if (CollectionUtils.isEmpty(parentIndexDetails)) {
if (CollectionUtils.isEmpty(indexGroupDetailEntityList)) {
log.warn("calculateDeptCorreLation customerId:{} have not any indexGroupDetail", formDTO.getCustomerId());
throw new RenException("客户【区直部门:治理能力】指标权重信息不存在");
}
log.info(JSON.toJSONString(parentIndexDetails));
return null;
log.info(JSON.toJSONString(indexGroupDetailEntityList));
//1、查询总记录数
int total = factIndexGovrnAblityDeptMonthlyDao.selectCount(formDTO);
if (NumConstant.ZERO == total) {
log.warn(String.format("customerId=%s,monthId=%s,fact_index_govrn_ablity_dept_monthly have not any fact record", formDTO.getCustomerId(), formDTO.getMonthId()));
return Boolean.FALSE;
} else if (NumConstant.ONE == total) {
//只有一个网格时
log.warn(String.format("customerId:%s,monthId:%s,only one fact_index_party_ablity_grid_monthly record", formDTO.getCustomerId(), formDTO.getMonthId()));
this.handleOneGridScene(formDTO);
return Boolean.TRUE;
}
//2、计算最大最小值
Map<String, Object> minAndMaxMap = factIndexGovrnAblityDeptMonthlyDao.selectExtremeValue(formDTO);
if (CollectionUtils.isEmpty(minAndMaxMap)) {
log.warn("calculateDeptCorreLation getExtremeValue customerId:{} fact_index_govrn_ablity_dept_monthly have not any fact record", formDTO.getCustomerId());
throw new RenException("【区直部门:治理能力】指标原始数据记录不存在");
}
//3、构造入参 指标集合
Map<String, IndexInputVO<BigDecimal>> indexMap = buildDeptCorrelationIndexInputVO(indexGroupDetailEntityList, minAndMaxMap);
//4、分批计算
int pageNo = NumConstant.ONE;
int pageSize = IndexCalConstant.PAGE_SIZE;
//分页查询 要计算的原始数据
List<Map<String, Object>> list = null;
do {
list = factIndexGovrnAblityDeptMonthlyDao.selectListByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), (pageNo - 1) * pageSize, pageSize);
if (!CollectionUtils.isEmpty(list)) {
//遍历指标分组 计算分数
List<Map<String, Object>> crrentFactRecordList = list;
calculateScore(formDTO,indexMap,crrentFactRecordList);
}
} while (!CollectionUtils.isEmpty(list) && pageNo++ > 0);
return true;
}
/**
* @return void
* @param formDTO
* @param indexMap
* @author yinzuomei
* @description 计算分值并保存结果
* @Date 2020/9/3 11:14
**/
private void calculateScore(CalculateCommonFormDTO formDTO, Map<String, IndexInputVO<BigDecimal>> indexMap,List<Map<String, Object>> recordList) {
//遍历每一个网格的记录
recordList.forEach(recordMap -> {
//遍历所有的指标
indexMap.forEach((key, indexInputVO) -> {
if (StringUtils.isNotBlank(indexCodeFieldReService.getFieldNameByIndexCode(key))) {
//对应的数值
String sampleValueStr = (String) recordMap.get(indexCodeFieldReService.getFieldNameByIndexCode(key));
//构造样本值对象
SampleValue<BigDecimal> currentGridIndexValue = new SampleValue((String) recordMap.get(IndexCalConstant.DEPT_ID), new BigDecimal(sampleValueStr));
indexInputVO.getIndexValueVOs().add(currentGridIndexValue);
}
});
});
//保存中间表记录 TODO
}
/**
* @param formDTO
* @return void
* @author yinzuomei
* @description TODO
* @Date 2020/9/3 9:35
**/
private void handleOneGridScene(CalculateCommonFormDTO formDTO) {
}
/**
* @param indexList
* @param minAndMaxMap
* @return java.util.Map<java.lang.String, com.epmet.support.normalizing.batch.IndexInputVO < java.math.BigDecimal>>
* @author yinzuomei
* @description
* @Date 2020/9/3 9:31
**/
private Map<String, IndexInputVO<BigDecimal>> buildDeptCorrelationIndexInputVO(List<IndexGroupDetailEntity> indexList,
Map<String, Object> minAndMaxMap) {
Map<String, IndexInputVO<BigDecimal>> map = new HashMap<>();
for (IndexGroupDetailEntity index : indexList) {
//获取指标对应的列名
String fieldName = indexCodeFieldReService.getFieldNameByIndexCode(index.getIndexCode());
if (StringUtils.isBlank(fieldName)) {
log.error("index_code:{} not find field_name", index.getIndexCode());
continue;
}
String minValueKey = fieldName.concat(StrConstant.UNDER_LINE).concat(StrConstant.MIN);
String maxValueKey = fieldName.concat(StrConstant.UNDER_LINE).concat(StrConstant.MAX);
BigDecimal minValue = new BigDecimal(String.valueOf(minAndMaxMap.get(minValueKey)));
BigDecimal maxValue = new BigDecimal(String.valueOf(minAndMaxMap.get(maxValueKey)));
//有阈值,且最大值>阈值,则最大值赋值为阈值
if (new BigDecimal(NumConstant.ONE_NEG_STR).compareTo(index.getThreshold()) != NumConstant.ZERO
&& maxValue.compareTo(index.getThreshold()) == NumConstant.ONE) {
maxValue = index.getThreshold();
}
//分值计算器
ScoreCalculator scoreCalculator = new BigDecimalScoreCalculator(minValue,
maxValue,
ScoreConstants.MIN_SCORE,
ScoreConstants.MAX_SCORE,
Correlation.getCorrelation(index.getCorrelation())
);
List<SampleValue<BigDecimal>> sampleValueList = new ArrayList<>();
IndexInputVO indexInputVO1 = new IndexInputVO(index.getIndexCode(),
sampleValueList,
index.getThreshold(),
// new BigDecimal("-1"), //FOR TEST
index.getWeight(),
scoreCalculator);
map.put(index.getIndexCode(), indexInputVO1);
}
return map;
}
}

61
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcoll/FactIndexGovrnAblityDeptMonthlyDao.xml

@ -79,4 +79,65 @@
</foreach>
</insert>
<!-- 查询(治理能力-区直部门相关数据 )当前月共上传了多少条记录 -->
<select id="selectCount" parameterType="com.epmet.dto.indexcal.CalculateCommonFormDTO" resultType="java.lang.Integer">
SELECT
count( 1 ) AS total
FROM
fact_index_govrn_ablity_dept_monthly m
WHERE
m.DEL_FLAG = '0'
AND m.CUSTOMER_ID =#{customerId}
AND m.MONTH_ID=#{monthId}
</select>
<!-- 计算最大最小值 -->
<select id="selectExtremeValue" parameterType="com.epmet.dto.indexcal.CalculateCommonFormDTO" resultType="java.util.Map">
SELECT
m.CUSTOMER_ID,
m.DEPT_ID,
m.MONTH_ID,
MIN(m.TRANSFERED_COUNT) as TRANSFERED_COUNT_MIN,
MAX(m.TRANSFERED_COUNT) as TRANSFERED_COUNT_MAX,
MIN(m.CLOSED_PROJECT_COUNT) as CLOSED_PROJECT_COUNT_MIN,
MAX(m.CLOSED_PROJECT_COUNT) as CLOSED_PROJECT_COUNT_MAX,
MIN(m.RESP_PROJECT_RATIO) as RESP_PROJECT_RATIO_MIN_MAX,
MAX(m.RESP_PROJECT_RATIO) as RESP_PROJECT_RATIO_MAX,
MIN(m.HANDLE_PROJECT_RATIO) as HANDLE_PROJECT_RATIO_MIN,
MAX(m.HANDLE_PROJECT_RATIO) as HANDLE_PROJECT_RATIO_MAX,
MIN(M.CLOSED_PROJECT_RATIO) as CLOSED_PROJECT_RATIO_MIN,
MAX(M.CLOSED_PROJECT_RATIO) as CLOSED_PROJECT_RATIO_MAX,
MIN(M.SATISFACTION_RATIO) as SATISFACTION_RATIO_MIN,
MAX(M.SATISFACTION_RATIO) as SATISFACTION_RATIO_MAX
FROM
fact_index_govrn_ablity_dept_monthly m
WHERE
m.DEL_FLAG = '0'
AND m.CUSTOMER_ID =#{customerId}
AND m.MONTH_ID =#{monthId}
</select>
<!-- 分页查询事实记录 -->
<select id="selectListByMonthId" parameterType="map" resultType="java.util.Map">
SELECT
m.CUSTOMER_ID,
m.AGENCY_ID,
m.DEPT_ID,
m.MONTH_ID,
m.TRANSFERED_COUNT,
m.CLOSED_PROJECT_COUNT,
m.RESP_PROJECT_RATIO,
m.HANDLE_PROJECT_RATIO,
m.CLOSED_PROJECT_RATIO,
SATISFACTION_RATIO
FROM
fact_index_govrn_ablity_dept_monthly m
WHERE
m.DEL_FLAG = '0'
AND m.CUSTOMER_ID =#{customerId}
AND m.MONTH_ID =#{monthId}
ORDER BY
m.DEPT_ID ASC
LIMIT #{offset},#{pageSize}
</select>
</mapper>

Loading…
Cancel
Save