Browse Source

代码调整

dev_shibei_match
jianjun 5 years ago
parent
commit
cbf7212c68
  1. 1
      epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/constant/IndexCalConstant.java
  2. 184
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java
  3. 3
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/indexcoll/FactIndexPartyAblityCpcMonthlyDao.xml

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

@ -19,4 +19,5 @@ public interface IndexCalConstant {
String MONTH_ID="MONTH_ID"; String MONTH_ID="MONTH_ID";
String USER_ID="USER_ID"; String USER_ID="USER_ID";
String YEAR_ID = "YEAR_ID";
} }

184
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java

@ -2,8 +2,8 @@ package com.epmet.service.indexcal.impl;
import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.StrConstant; import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.constant.IndexCalConstant; import com.epmet.constant.IndexCalConstant;
import com.epmet.dao.indexcoll.FactIndexPartyAblityCpcMonthlyDao; import com.epmet.dao.indexcoll.FactIndexPartyAblityCpcMonthlyDao;
import com.epmet.dao.indexscore.CpcScoreDao; import com.epmet.dao.indexscore.CpcScoreDao;
@ -22,7 +22,6 @@ import com.epmet.support.normalizing.ScoreConstants;
import com.epmet.support.normalizing.batch.BatchScoreCalculator; import com.epmet.support.normalizing.batch.BatchScoreCalculator;
import com.epmet.support.normalizing.batch.IndexInputVO; import com.epmet.support.normalizing.batch.IndexInputVO;
import com.epmet.support.normalizing.batch.SampleValue; import com.epmet.support.normalizing.batch.SampleValue;
import com.epmet.util.DimIdGenerator;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -50,11 +49,8 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
@Override @Override
public Boolean cpcIndexCalculate(CalculateCommonFormDTO formDTO) { public Boolean cpcIndexCalculate(CalculateCommonFormDTO formDTO) {
calculatePartScore(formDTO); calculatePartScore(formDTO);
calculateTotalScore(formDTO); calculateTotalScore(formDTO);
return true; return true;
} }
@ -68,36 +64,35 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
List<IndexGroupDetailEntity> parentIndexDetails = getDetailListByParentCode.getDetailListByParentCode(formDTO.getCustomerId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode()); List<IndexGroupDetailEntity> parentIndexDetails = getDetailListByParentCode.getDetailListByParentCode(formDTO.getCustomerId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode());
if (CollectionUtils.isEmpty(parentIndexDetails)) { if (CollectionUtils.isEmpty(parentIndexDetails)) {
log.warn("cpcIndexCalculate customerId:{} have not any indexGroupDetail", formDTO.getCustomerId()); log.warn("cpcIndexCalculate customerId:{} have not any indexGroupDetail", formDTO.getCustomerId());
return; throw new RenException("客户【党员相关】指标权重信息不存在");
} }
//获取数据
List<CpcScoreEntity> list = null;
Map<String, CpcScoreEntity> cpcScoreTotalMap = new HashMap<>(); Map<String, CpcScoreEntity> cpcScoreTotalMap = new HashMap<>();
Map<String, IndexGroupDetailEntity> indexWeightMap = parentIndexDetails.stream().collect(Collectors.toMap(IndexGroupDetailEntity::getIndexCode, o -> o)); Map<String, IndexGroupDetailEntity> indexWeightMap = parentIndexDetails.stream().collect(Collectors.toMap(IndexGroupDetailEntity::getIndexCode, o -> o));
list = cpcScoreDao.getPartScore(formDTO.getCustomerId(), formDTO.getMonthId()); //获取数据
if (!CollectionUtils.isEmpty(list)) { List<CpcScoreEntity> list = cpcScoreDao.getPartScore(formDTO.getCustomerId(), formDTO.getMonthId());
Map<String, List<CpcScoreEntity>> userGroupMap = list.stream().collect(Collectors.groupingBy(CpcScoreEntity::getUserId)); if (CollectionUtils.isEmpty(list)) {
userGroupMap.forEach((userId, partScoreList) -> { log.error("calculateTotalScore cpcScoreDao.getPartScore return empty,customerId:{},monthId:{}", formDTO.getCustomerId(), formDTO.getMonthId());
CpcScoreEntity totalEntity = null; throw new RenException("客户四级指标分值记录不存在");
for (CpcScoreEntity part : partScoreList) {
IndexGroupDetailEntity indexGroupDetailEntity = indexWeightMap.get(part.getIndexCode());
if (totalEntity == null) {
totalEntity = ConvertUtils.sourceToTarget(part, CpcScoreEntity.class);
totalEntity.setIsTotal(NumConstant.ONE_STR);
totalEntity.setIndexCode(indexGroupDetailEntity.getIndexCode());
cpcScoreTotalMap.put(userId, totalEntity);
}
BigDecimal total = part.getScore().multiply(indexGroupDetailEntity.getWeight());
log.warn("userId:{},分数:{},权重:{},total:{}", userId, part.getScore(), indexGroupDetailEntity.getWeight(), total);
totalEntity.setScore(totalEntity.getScore().add(total));
}
});
} }
Map<String, List<CpcScoreEntity>> userGroupMap = list.stream().collect(Collectors.groupingBy(CpcScoreEntity::getUserId));
userGroupMap.forEach((userId, partScoreList) -> {
CpcScoreEntity totalEntity = null;
for (CpcScoreEntity part : partScoreList) {
IndexGroupDetailEntity indexGroupDetailEntity = indexWeightMap.get(part.getIndexCode());
if (totalEntity == null) {
totalEntity = ConvertUtils.sourceToTarget(part, CpcScoreEntity.class);
totalEntity.setIsTotal(NumConstant.ONE_STR);
totalEntity.setIndexCode(indexGroupDetailEntity.getIndexCode());
cpcScoreTotalMap.put(userId, totalEntity);
}
//todo 自建群活跃度——议题转项目率 有阈值 >60%按60%算
BigDecimal total = part.getScore().multiply(indexGroupDetailEntity.getWeight());
log.debug("userId:{},分数:{},权重:{},total:{}", userId, part.getScore(), indexGroupDetailEntity.getWeight(), total);
totalEntity.setScore(totalEntity.getScore().add(total));
}
});
insertBatch(cpcScoreTotalMap.values().stream().collect(Collectors.toList())); insertBatch(cpcScoreTotalMap.values().stream().collect(Collectors.toList()));
} }
private void insertBatch(Collection<CpcScoreEntity> values) { private void insertBatch(Collection<CpcScoreEntity> values) {
@ -113,56 +108,44 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
//计算最大最小值 //计算最大最小值
Map<String, Object> minAndMaxMap = factIndexPartyAblityCpcMonthlyDao.getExtremeValue(formDTO.getCustomerId()); Map<String, Object> minAndMaxMap = factIndexPartyAblityCpcMonthlyDao.getExtremeValue(formDTO.getCustomerId());
if (CollectionUtils.isEmpty(minAndMaxMap)) { if (CollectionUtils.isEmpty(minAndMaxMap)) {
log.warn("cpcIndexCalculate getExtremeValue customerId:{} have not any fact record", formDTO.getCustomerId()); log.error("cpcIndexCalculate getExtremeValue customerId:{} have not any fact record", formDTO.getCustomerId());
return; return;
} }
//指标集合 //指标集合
//对指标进行分组 Map<String, List<IndexGroupDetailEntity>> groupIndexDetailsMap = getIndexDetailMap(formDTO);
//Map<String, List<IndexGroupDetailEntity>> groupIndexDetailsMap = indexDetails.stream().collect(Collectors.groupingBy(IndexGroupDetailEntity::getAllParentIndexCode)); if (groupIndexDetailsMap == null) {
//获取指标权重信息 -参与议事
List<IndexGroupDetailEntity> canyuyishiIndexDetails = getDetailListByParentCode.getDetailListByParentCode(formDTO.getCustomerId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(), IndexCodeEnum.CAN_YU_YI_SHI.getCode());
if (CollectionUtils.isEmpty(canyuyishiIndexDetails)) {
log.warn("cpcIndexCalculate customerId:{} have not any indexGroupDetail", formDTO.getCustomerId());
return;
}
List<IndexGroupDetailEntity> dangwuhongdongIndexDetails = getDetailListByParentCode.getDetailListByParentCode(formDTO.getCustomerId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(), IndexCodeEnum.DANG_WU_HUO_DONG.getCode());
if (CollectionUtils.isEmpty(canyuyishiIndexDetails)) {
log.warn("cpcIndexCalculate customerId:{} have not any indexGroupDetail", formDTO.getCustomerId());
return;
}
List<IndexGroupDetailEntity> lianxiqunzhongIndexDetails = getDetailListByParentCode.getDetailListByParentCode(formDTO.getCustomerId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(), IndexCodeEnum.LIAN_XI_QUN_ZHONG.getCode());
if (CollectionUtils.isEmpty(canyuyishiIndexDetails)) {
log.warn("cpcIndexCalculate customerId:{} have not any indexGroupDetail", formDTO.getCustomerId());
return; return;
} }
Map<String, List<IndexGroupDetailEntity>> groupIndexDetailsMap = new HashMap<>();
groupIndexDetailsMap.put(IndexCodeEnum.CAN_YU_YI_SHI.getCode(), canyuyishiIndexDetails);
groupIndexDetailsMap.put(IndexCodeEnum.DANG_WU_HUO_DONG.getCode(), dangwuhongdongIndexDetails);
groupIndexDetailsMap.put(IndexCodeEnum.LIAN_XI_QUN_ZHONG.getCode(), lianxiqunzhongIndexDetails);
List<Map<String, Object>> list = null;
int pageNo = 1; int pageNo = 1;
int pageSize = 10; int pageSize = 10;
//分页查询 要计算的原始数据
List<Map<String, Object>> list = null;
do { do {
list = factIndexPartyAblityCpcMonthlyDao.getCountByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), (pageNo - 1) * pageSize, pageSize); list = factIndexPartyAblityCpcMonthlyDao.getCountByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), (pageNo - 1) * pageSize, pageSize);
if (!CollectionUtils.isEmpty(list)) { if (!CollectionUtils.isEmpty(list)) {
//遍历指标分组 计算分数 //遍历指标分组 计算分数
List<Map<String, Object>> finalList = list; List<Map<String, Object>> finalList = list;
groupIndexDetailsMap.forEach((parentIndexCode, details) -> { groupIndexDetailsMap.forEach((parentIndexCode, details) -> {
calculate(formDTO, details, finalList, minAndMaxMap, parentIndexCode); calculateScore(formDTO, details, finalList, minAndMaxMap, parentIndexCode);
}); });
} }
} while (!CollectionUtils.isEmpty(list) && pageNo++ > 0); } while (!CollectionUtils.isEmpty(list) && pageNo++ > 0);
} }
private void calculate(CalculateCommonFormDTO formDTO, List<IndexGroupDetailEntity> indexDetailList, List<Map<String, Object>> finalList, Map<String, Object> minAndMaxMap, String parentIndexCode) { /**
Map<String, IndexInputVO<BigDecimal>> indexMap = getIndexInputVO(indexDetailList, minAndMaxMap); * desc计算并保存中间结果
*
* @param formDTO
* @param indexDetailList
* @param finalList
* @param minAndMaxMap
* @param parentIndexCode remark1.遍历指标和原始数据2.构建指标归一算法计算器计算分值3.将分值保存到中间表
*/
private void calculateScore(CalculateCommonFormDTO formDTO, List<IndexGroupDetailEntity> indexDetailList, List<Map<String, Object>> finalList, Map<String, Object> minAndMaxMap, String parentIndexCode) {
Map<String, IndexInputVO<BigDecimal>> indexMap = buildIndexInputVO(indexDetailList, minAndMaxMap);
Map<String, CpcScoreEntity> scoreEntityMap = new HashMap<>(); Map<String, CpcScoreEntity> scoreEntityMap = new HashMap<>();
//遍历指标 进行计算 //遍历指标 进行计算
for (Map.Entry<String, IndexInputVO<BigDecimal>> entry : indexMap.entrySet()) { for (Map.Entry<String, IndexInputVO<BigDecimal>> entry : indexMap.entrySet()) {
String indexCode = entry.getKey(); String indexCode = entry.getKey();
IndexInputVO<BigDecimal> value = entry.getValue(); IndexInputVO<BigDecimal> value = entry.getValue();
@ -175,10 +158,10 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
for (Map<String, Object> cpcCount : finalList) { for (Map<String, Object> cpcCount : finalList) {
//对应的数值 //对应的数值
String userId = String.valueOf(cpcCount.get(IndexCalConstant.USER_ID)); String userId = String.valueOf(cpcCount.get(IndexCalConstant.USER_ID));
String sampleValueStr = String.valueOf(cpcCount.get(fieldName)); BigDecimal sampleValue = new BigDecimal(String.valueOf(cpcCount.get(fieldName)));
CpcScoreEntity cpcScoreEntity = new CpcScoreEntity(); CpcScoreEntity cpcScoreEntity = new CpcScoreEntity();
cpcScoreEntity.setYearId(DimIdGenerator.getYearDimId(DateUtils.addDateMonths(new Date(), -1))); cpcScoreEntity.setYearId(String.valueOf(cpcCount.get(IndexCalConstant.YEAR_ID)));
cpcScoreEntity.setCustomerId(formDTO.getCustomerId()); cpcScoreEntity.setCustomerId(formDTO.getCustomerId());
cpcScoreEntity.setAgencyId(String.valueOf(cpcCount.get(IndexCalConstant.AGENCY_ID))); cpcScoreEntity.setAgencyId(String.valueOf(cpcCount.get(IndexCalConstant.AGENCY_ID)));
cpcScoreEntity.setGridId(String.valueOf(cpcCount.get(IndexCalConstant.GRID_ID))); cpcScoreEntity.setGridId(String.valueOf(cpcCount.get(IndexCalConstant.GRID_ID)));
@ -187,22 +170,30 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
cpcScoreEntity.setMonthId(formDTO.getMonthId()); cpcScoreEntity.setMonthId(formDTO.getMonthId());
cpcScoreEntity.setScore(new BigDecimal(0)); cpcScoreEntity.setScore(new BigDecimal(0));
cpcScoreEntity.setIndexCode(parentIndexCode); cpcScoreEntity.setIndexCode(parentIndexCode);
scoreEntityMap.put(userId, cpcScoreEntity); scoreEntityMap.put(userId, cpcScoreEntity);
//构造样本值对象 //构造样本值对象
SampleValue<BigDecimal> currentGridIndexValue = new SampleValue((String) cpcCount.get(IndexCalConstant.USER_ID), new BigDecimal(sampleValueStr)); SampleValue<BigDecimal> currentUserIndexValue = new SampleValue(userId, sampleValue);
value.getIndexValueVOs().add(currentGridIndexValue); value.getIndexValueVOs().add(currentUserIndexValue);
} }
} }
log.warn("计算的参数:{}", indexMap); log.warn("计算的参数:{}", indexMap);
HashMap<String, BigDecimal> result = calculate(indexMap); HashMap<String, BigDecimal> result = calculateScore(indexMap);
log.warn("计算的结果:{}", result); log.warn("计算的结果:{}", result);
//处理结果 //处理结果
saveCpcScore(formDTO, scoreEntityMap, parentIndexCode, result); saveCpcScore(formDTO, scoreEntityMap, parentIndexCode, result);
} }
/**
* desc:保存分值 到中间表
*
* @param formDTO
* @param indexDetails
* @param parentIndexCode
* @param result
*/
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void saveCpcScore(CalculateCommonFormDTO formDTO, Map<String, CpcScoreEntity> indexDetails, String parentIndexCode, HashMap<String, BigDecimal> result) { public void saveCpcScore(CalculateCommonFormDTO formDTO, Map<String, CpcScoreEntity> indexDetails, String parentIndexCode, HashMap<String, BigDecimal> result) {
cpcScoreDao.deleteByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), parentIndexCode); cpcScoreDao.deleteByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), parentIndexCode);
@ -215,21 +206,10 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
this.insertBatch(list); this.insertBatch(list);
} }
/**
* @param indexMap
* @return java.util.List<com.epmet.support.normalizing.batch.IndexOutputVO>
* @author yinzuomei
* @description
* @Date 2020/8/30 21:40
**/
private HashMap<String, BigDecimal> calculate(Map<String, IndexInputVO<BigDecimal>> indexMap) {
//构造入参
List<IndexInputVO> indexInputVOS = indexMap.values().stream().collect(Collectors.toList());
BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator();
return batchScoreCalculator.getScoreCountOfSampleId(indexInputVOS);
}
/** /**
* desc构建分值计算器
*
* @param indexList 指标集合 * @param indexList 指标集合
* @param minAndMaxMap 最大值最小值集合 * @param minAndMaxMap 最大值最小值集合
* @return java.util.Map<java.lang.String, com.epmet.support.normalizing.batch.IndexInputVO> * @return java.util.Map<java.lang.String, com.epmet.support.normalizing.batch.IndexInputVO>
@ -237,10 +217,9 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
* @description * @description
* @Date 2020/8/30 15:56 * @Date 2020/8/30 15:56
**/ **/
private Map<String, IndexInputVO<BigDecimal>> getIndexInputVO(List<IndexGroupDetailEntity> indexList, Map<String, Object> minAndMaxMap) { private Map<String, IndexInputVO<BigDecimal>> buildIndexInputVO(List<IndexGroupDetailEntity> indexList, Map<String, Object> minAndMaxMap) {
Map<String, IndexInputVO<BigDecimal>> map = new HashMap<>(); Map<String, IndexInputVO<BigDecimal>> map = new HashMap<>();
for (int indexNum = 0; indexNum < indexList.size(); indexNum++) { for (IndexGroupDetailEntity index : indexList) {
IndexGroupDetailEntity index = indexList.get(indexNum);
IndexInputVO indexInputVO = new IndexInputVO(); IndexInputVO indexInputVO = new IndexInputVO();
// 指标code // 指标code
indexInputVO.setIndexId(index.getIndexCode()); indexInputVO.setIndexId(index.getIndexCode());
@ -273,4 +252,49 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
} }
return map; return map;
} }
/**
* desc:调用计算器计算每个人的分数值
*
* @param indexMap
* @return
*/
private HashMap<String, BigDecimal> calculateScore(Map<String, IndexInputVO<BigDecimal>> indexMap) {
//构造入参
List<IndexInputVO> indexInputVOS = indexMap.values().stream().collect(Collectors.toList());
BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator();
return batchScoreCalculator.getScoreCountOfSampleId(indexInputVOS);
}
/**
* desc构建党员相关4级指标明细map
*
* @param formDTO
* @return
*/
private Map<String, List<IndexGroupDetailEntity>> getIndexDetailMap(CalculateCommonFormDTO formDTO) {
//获取指标权重信息 -参与议事
List<IndexGroupDetailEntity> canyuyishiIndexDetails = getDetailListByParentCode.getDetailListByParentCode(formDTO.getCustomerId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(), IndexCodeEnum.CAN_YU_YI_SHI.getCode());
if (CollectionUtils.isEmpty(canyuyishiIndexDetails)) {
log.error("cpcIndexCalculate customerId:{} have not any indexGroupDetail", formDTO.getCustomerId());
return null;
}
List<IndexGroupDetailEntity> dangwuhongdongIndexDetails = getDetailListByParentCode.getDetailListByParentCode(formDTO.getCustomerId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(), IndexCodeEnum.DANG_WU_HUO_DONG.getCode());
if (CollectionUtils.isEmpty(canyuyishiIndexDetails)) {
log.error("cpcIndexCalculate customerId:{} have not any indexGroupDetail", formDTO.getCustomerId());
return null;
}
List<IndexGroupDetailEntity> lianxiqunzhongIndexDetails = getDetailListByParentCode.getDetailListByParentCode(formDTO.getCustomerId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(), IndexCodeEnum.LIAN_XI_QUN_ZHONG.getCode());
if (CollectionUtils.isEmpty(canyuyishiIndexDetails)) {
log.error("cpcIndexCalculate customerId:{} have not any indexGroupDetail", formDTO.getCustomerId());
return null;
}
Map<String, List<IndexGroupDetailEntity>> groupIndexDetailsMap = new HashMap<>();
groupIndexDetailsMap.put(IndexCodeEnum.CAN_YU_YI_SHI.getCode(), canyuyishiIndexDetails);
groupIndexDetailsMap.put(IndexCodeEnum.DANG_WU_HUO_DONG.getCode(), dangwuhongdongIndexDetails);
groupIndexDetailsMap.put(IndexCodeEnum.LIAN_XI_QUN_ZHONG.getCode(), lianxiqunzhongIndexDetails);
return groupIndexDetailsMap;
}
} }

3
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/indexcoll/FactIndexPartyAblityCpcMonthlyDao.xml

@ -101,6 +101,9 @@
AGENCY_ID, AGENCY_ID,
PARENT_ID, PARENT_ID,
GRID_ID, GRID_ID,
MONTH_ID,
QUARTER_ID,
YEAR_ID,
USER_ID, USER_ID,
CREATE_TOPIC_COUNT, CREATE_TOPIC_COUNT,
JOIN_TOPIC_COUNT, JOIN_TOPIC_COUNT,

Loading…
Cancel
Save