Browse Source

错误调整

master
jianjun 5 years ago
parent
commit
00324ad1c7
  1. 2
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/screen/IndexGroupDetailDao.java
  2. 79
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java
  3. 8
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/IndexGroupDetailService.java
  4. 4
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexCalculateServiceImpl.java
  5. 5
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexGroupDetailServiceImpl.java
  6. 9
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/screen/IndexGroupDetailDao.xml

2
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/screen/IndexGroupDetailDao.java

@ -34,4 +34,6 @@ import java.util.List;
public interface IndexGroupDetailDao extends BaseDao<IndexGroupDetailEntity> {
List<IndexGroupDetailEntity> getDetailListByParentCode(@Param("customerId") String customerId, @Param("indexCode") String indexCode);
List<IndexGroupDetailEntity> getDetailListLikeParentCode(@Param("customerId") String customerId, @Param("parentIndexCode") String parentIndexCode);
}

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

@ -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);
}
/**

8
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/IndexGroupDetailService.java

@ -35,4 +35,12 @@ public interface IndexGroupDetailService extends BaseService<IndexGroupDetailEnt
* @param indexCode
*/
List<IndexGroupDetailEntity> getDetailListByParentCode(String customerId,String... indexCode);
/**
* desc获取所有 包含该指标code的
* @param customerId
* @param parentIndexCode
* @return
*/
List<IndexGroupDetailEntity> getDetailListLikeParentCode(String customerId, String parentIndexCode);
}

4
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexCalculateServiceImpl.java

@ -17,10 +17,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @author liujianjun
@ -58,7 +56,7 @@ public class IndexCalculateServiceImpl implements IndexCalculateService {
CalculateCommonFormDTO calculateCommonFormDTO=new CalculateCommonFormDTO(customerId, formDTO.getMonthId());
//计算党员
try {
Map<String, BigDecimal> list = factIndexPartyAblityCpcMonthlyDao.getCountByMonthId(customerId, formDTO.getMonthId(), (pageNo - 1) * pageSize, pageSize);
//Map<String, BigDecimal> list = factIndexPartyAblityCpcMonthlyDao.getCountByMonthId(customerId, formDTO.getMonthId(), (pageNo - 1) * pageSize, pageSize);
} catch (Exception e) {
}

5
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexGroupDetailServiceImpl.java

@ -48,4 +48,9 @@ public class IndexGroupDetailServiceImpl extends BaseServiceImpl<IndexGroupDetai
}
return baseDao.getDetailListByParentCode(customerId,sb.deleteCharAt(sb.length()-1).toString());
}
@Override
public List<IndexGroupDetailEntity> getDetailListLikeParentCode(String customerId, String parentIndexCode) {
return baseDao.getDetailListLikeParentCode(customerId,parentIndexCode);
}
}

9
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/screen/IndexGroupDetailDao.xml

@ -12,4 +12,13 @@
CUSTOMER_ID = #{customerId,jdbcType=VARCHAR} and STATUS = 'enable' and DEL_FLAG = '0'
and ALL_PARENT_INDEX_CODE = #{indexCode,jdbcType=VARCHAR}
</select>
<select id="getDetailListLikeParentCode" resultType="com.epmet.entity.screen.IndexGroupDetailEntity">
select
ID, INDEX_GROUP_ID, INDEX_ID, INDEX_CODE, WEIGHT, THRESHOLD
FROM index_group_detail
WHERE
CUSTOMER_ID = #{customerId,jdbcType=VARCHAR} and STATUS = 'enable' and DEL_FLAG = '0'
and ALL_PARENT_INDEX_CODE like concat(#{indexCode,jdbcType=VARCHAR},'%')
</select>
</mapper>
Loading…
Cancel
Save