Browse Source

修改错误

dev_shibei_match
jianjun 5 years ago
parent
commit
81ac10db52
  1. 50
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/CpcIndexCalculateServiceImpl.java

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

@ -41,6 +41,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@Slf4j
@ -82,28 +83,18 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
int pageSize = IndexCalConstant.PAGE_SIZE;
List<CpcScoreEntity> list = null;
Map<String, CpcScoreEntity> preLastCpcScoreTotalMap = new HashMap<>();
//当前最后一条记录
//CpcScoreEntity currentLastCpcScore = null;
//当前第一条记录
//CpcScoreEntity currentFirstCpcScore = null;
Map<String, CpcScoreEntity> cpcScoreTotalMap = new HashMap<>();
Map<String, AtomicInteger> userTotalCount = new HashMap<>();
//删除总分 然后插入
cpcScoreDao.deleteByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(), IndexCalConstant.DELETE_SIZE, NumConstant.ONE_STR);
do {
Map<String, CpcScoreEntity> cpcScoreTotalMap = new HashMap<>();
List<CpcScoreEntity> result = new ArrayList<>();
//获取数据
list = cpcScoreDao.getPartScore(formDTO.getCustomerId(), formDTO.getMonthId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(), (pageNo - NumConstant.ONE) * pageSize, pageSize);
pageNo++;
if (CollectionUtils.isEmpty(list)) {
log.warn("calculateTotalScore cpcScoreDao.getPartScore return empty,customerId:{},monthId:{}", formDTO.getCustomerId(), formDTO.getMonthId());
} else {
//获取最后一条
//currentLastCpcScore = list.get(list.size() - 1);
//获取第一条
//currentFirstCpcScore = list.get(0);
/*if (preLastCpcScoreTotalMap.containsKey(currentFirstCpcScore.getUserId())) {
cpcScoreTotalMap.putAll(preLastCpcScoreTotalMap);
preLastCpcScoreTotalMap.clear();
preLastCpcScoreTotalMap.put(currentLastCpcScore.getUserId(), null);
}*/
Map<String, List<CpcScoreEntity>> userGroupMap = list.stream().collect(Collectors.groupingBy(CpcScoreEntity::getUserId));
userGroupMap.forEach((userId, partScoreList) -> {
CpcScoreEntity totalEntity = null;
@ -121,27 +112,26 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
totalEntity.setAllParentIndexCode(NumConstant.ZERO_STR);
totalEntity.setWeight(new BigDecimal(NumConstant.ONE_NEG));
cpcScoreTotalMap.put(userId, totalEntity);
/* if (preLastCpcScoreTotalMap.containsKey(part.getUserId())) {
preLastCpcScoreTotalMap.put(part.getUserId(), part);
} else {
}*/
}
//自建群活跃度——议题转项目率 有阈值 >60%按60%算
BigDecimal total = part.getScore().multiply(indexGroupDetailEntity.getWeight());
AtomicInteger atomicInteger = userTotalCount.get(part.getUserId());
if (atomicInteger == null) {
atomicInteger = new AtomicInteger(0);
userTotalCount.put(part.getUserId(), atomicInteger);
}
int totalCount = atomicInteger.addAndGet(1);
//todo 次代码限制了 党员的 4级指标的个数 看看是否还有更好的方式
if (totalCount == 3) {
result.add(totalEntity);
}
log.info("userId:{},分数:{},权重:{},total:{}", userId, part.getScore(), indexGroupDetailEntity.getWeight(), total);
totalEntity.setScore(totalEntity.getScore().add(total));
}
});
}
//没查询到数据 就把上次的放进去
if (list == null || list.size() < pageSize || !CollectionUtils.isEmpty(preLastCpcScoreTotalMap)) {
cpcScoreTotalMap.putAll(preLastCpcScoreTotalMap);
}
//删除总分 然后插入
cpcScoreDao.deleteByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(), IndexCalConstant.DELETE_SIZE, NumConstant.ONE_STR);
insertCpcScoreBatch(formDTO, cpcScoreTotalMap.values().stream().collect(Collectors.toList()), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode());
insertCpcScoreBatch(formDTO, result, IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode());
} while (!CollectionUtils.isEmpty(list));
}
@ -180,7 +170,7 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
*/
public void insertCpcScoreBatch(CalculateCommonFormDTO formDTO, List<CpcScoreEntity> values, String indexCode) {
if (CollectionUtils.isEmpty(values)) {
log.error("insertCpcScoreBatch要插入的数据为空,param:{},indexCode:{}", JSON.toJSONString(formDTO), indexCode);
log.warn("insertCpcScoreBatch要插入的数据为空,param:{},indexCode:{}", JSON.toJSONString(formDTO), indexCode);
return;
}
List<List<CpcScoreEntity>> partition = ListUtils.partition(values, IndexCalConstant.INSERT_SIZE);
@ -338,7 +328,7 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
*/
public void insertCpcSubScoreBatch(CalculateCommonFormDTO formDTO, List<CpcSubScoreEntity> subList, String parentIndexCode) {
if (CollectionUtils.isEmpty(subList)) {
log.error("insertCpcScoreBatch要插入的数据为空,param:{},indexCode:{}", JSON.toJSONString(formDTO), parentIndexCode);
log.warn("insertCpcScoreBatch要插入的数据为空,param:{},indexCode:{}", JSON.toJSONString(formDTO), parentIndexCode);
return;
}
List<List<CpcSubScoreEntity>> partition = ListUtils.partition(subList, IndexCalConstant.INSERT_SIZE);

Loading…
Cancel
Save