|
|
@ -1,5 +1,6 @@ |
|
|
|
package com.epmet.service.indexcal.impl; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
|
import com.epmet.constant.IndexCalConstant; |
|
|
|
import com.epmet.dao.indexcoll.FactIndexPartyAblityCpcMonthlyDao; |
|
|
@ -14,7 +15,9 @@ 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.*; |
|
|
|
import com.epmet.support.normalizing.batch.BatchScoreCalculator; |
|
|
|
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; |
|
|
@ -45,7 +48,7 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { |
|
|
|
public Boolean cpcIndexCalculate(CalculateCommonFormDTO formDTO) { |
|
|
|
|
|
|
|
//获取指标权重信息 -参与议事
|
|
|
|
List<IndexGroupDetailEntity> indexDetails = getDetailListByParentCode.getDetailListByParentCode(formDTO.getCustomerId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(), IndexCodeEnum.CAN_YU_YI_SHI.getCode()); |
|
|
|
List<IndexGroupDetailEntity> indexDetails = getDetailListByParentCode.getDetailListLikeParentCode(formDTO.getCustomerId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode()); |
|
|
|
if (CollectionUtils.isEmpty(indexDetails)) { |
|
|
|
log.warn("cpcIndexCalculate customerId:{} have not any indexGroupDetail", formDTO.getCustomerId()); |
|
|
|
return false; |
|
|
@ -53,7 +56,6 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { |
|
|
|
|
|
|
|
canyuyishi(formDTO, indexDetails); |
|
|
|
|
|
|
|
|
|
|
|
//log.info(JSON.toJSONString(minAndMaxList));
|
|
|
|
return null; |
|
|
|
} |
|
|
@ -71,54 +73,55 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { |
|
|
|
return; |
|
|
|
} |
|
|
|
//指标集合
|
|
|
|
Map<String, IndexInputVO<BigDecimal>> indexMap = getIndexInputVO(indexDetails, minAndMaxMap); |
|
|
|
//对指标进行分组
|
|
|
|
Map<String, List<IndexGroupDetailEntity>> groupIndexDetailsMap = indexDetails.stream().collect(Collectors.groupingBy(IndexGroupDetailEntity::getAllParentIndexCode)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Map<String, Object>> list = null; |
|
|
|
int pageNo = 1; |
|
|
|
int pageSize = 10; |
|
|
|
do { |
|
|
|
String fieldName = null; |
|
|
|
list = factIndexPartyAblityCpcMonthlyDao.getCountByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), (pageNo - 1) * pageSize, pageSize); |
|
|
|
if (!CollectionUtils.isEmpty(list)) { |
|
|
|
//遍历指标 进行计算
|
|
|
|
for (Map.Entry<String, IndexInputVO<BigDecimal>> entry : indexMap.entrySet()) { |
|
|
|
String indexCode = entry.getKey(); |
|
|
|
IndexInputVO<BigDecimal> value = entry.getValue(); |
|
|
|
fieldName = indexCodeFieldReService.getFieldNameByIndexCode(indexCode); |
|
|
|
if (StringUtils.isBlank(fieldName)) { |
|
|
|
log.error("cpcIndexCalculate fieldName error"); |
|
|
|
continue; |
|
|
|
} |
|
|
|
for (Map<String, Object> cpcIndex : list) { |
|
|
|
//对应的数值
|
|
|
|
String sampleValueStr = String.valueOf(cpcIndex.get(indexCodeFieldReService.getFieldNameByIndexCode(fieldName))); |
|
|
|
//构造样本值对象
|
|
|
|
SampleValue<BigDecimal> currentGridIndexValue = new SampleValue((String) cpcIndex.get(IndexCalConstant.USER_ID), new BigDecimal(sampleValueStr)); |
|
|
|
value.getIndexValueVOs().add(currentGridIndexValue); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
List<IndexOutputVO> result = calculate(indexMap); |
|
|
|
// TODO 处理结果
|
|
|
|
saveGridCorreLationDangJian(formDTO, indexDetails, result); |
|
|
|
//遍历指标分组 计算分数
|
|
|
|
List<Map<String, Object>> finalList = list; |
|
|
|
groupIndexDetailsMap.forEach((parentIndex, indexDetailList)->{ |
|
|
|
Map<String, IndexInputVO<BigDecimal>> indexMap = getIndexInputVO(indexDetailList, minAndMaxMap); |
|
|
|
//遍历指标 进行计算
|
|
|
|
for (Map.Entry<String, IndexInputVO<BigDecimal>> entry : indexMap.entrySet()) { |
|
|
|
String indexCode = entry.getKey(); |
|
|
|
IndexInputVO<BigDecimal> value = entry.getValue(); |
|
|
|
String fieldName = indexCodeFieldReService.getFieldNameByIndexCode(indexCode); |
|
|
|
if (StringUtils.isBlank(fieldName)) { |
|
|
|
log.error("cpcIndexCalculate fieldName error"); |
|
|
|
continue; |
|
|
|
} |
|
|
|
for (Map<String, Object> cpcIndex : finalList) { |
|
|
|
//对应的数值
|
|
|
|
String sampleValueStr = String.valueOf(cpcIndex.get(indexCodeFieldReService.getFieldNameByIndexCode(fieldName))); |
|
|
|
//构造样本值对象
|
|
|
|
SampleValue<BigDecimal> currentGridIndexValue = new SampleValue((String) cpcIndex.get(IndexCalConstant.USER_ID), new BigDecimal(sampleValueStr)); |
|
|
|
value.getIndexValueVOs().add(currentGridIndexValue); |
|
|
|
} |
|
|
|
} |
|
|
|
HashMap<String, BigDecimal> result = calculate(indexMap); |
|
|
|
// TODO 处理结果
|
|
|
|
saveGridCorreLationDangJian(formDTO, indexDetails, result); |
|
|
|
|
|
|
|
try { |
|
|
|
for (IndexOutputVO m : result) { |
|
|
|
log.info("indexId=" + m.getIndexId()); |
|
|
|
for (SampleScore sampleScore : m.getIndexScoreVOs()) { |
|
|
|
log.info(String.format("网格id:%s,得分:%s", sampleScore.getSampleId(), sampleScore.getSampleScore())); |
|
|
|
try { |
|
|
|
System.out.println( JSON.toJSONString(result)); |
|
|
|
} catch (Exception e) { |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
} while (!CollectionUtils.isEmpty(list) && pageNo++ > 0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void saveGridCorreLationDangJian(CalculateCommonFormDTO formDTO, List<IndexGroupDetailEntity> indexDetails, List<IndexOutputVO> result) { |
|
|
|
public void saveGridCorreLationDangJian(CalculateCommonFormDTO formDTO, List<IndexGroupDetailEntity> indexDetails, HashMap<String, BigDecimal> result) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@ -129,11 +132,11 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { |
|
|
|
* @description |
|
|
|
* @Date 2020/8/30 21:40 |
|
|
|
**/ |
|
|
|
private List<IndexOutputVO> calculate(Map<String, IndexInputVO<BigDecimal>> indexMap) { |
|
|
|
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.getScoreDetailOfIndexId(indexInputVOS); |
|
|
|
return batchScoreCalculator.getScoreCountOfSampleId(indexInputVOS); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|