Browse Source

修改计算错误;先全部删除 在插入

dev_shibei_match
jianjun 5 years ago
parent
commit
6f5f48b8ac
  1. 2
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/CpcScoreDao.java
  2. 2
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/CpcSubScoreDao.java
  3. 65
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/CpcIndexCalculateServiceImpl.java
  4. 14
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/CpcScoreDao.xml
  5. 10
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/CpcSubScoreDao.xml

2
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/CpcScoreDao.java

@ -78,7 +78,7 @@ public interface CpcScoreDao extends BaseDao<CpcScoreEntity> {
**/
BigDecimal selectGridJoinIssueAvgValue(@Param("customerId") String customerId, @Param("monthId") String monthId, @Param("gridId") String gridId);
int deleteByMonthId(@Param("customerId") String customerId, @Param("monthId") String monthId, @Param("indexCode") String indexCode);
int deleteByMonthId(@Param("customerId") String customerId, @Param("monthId") String monthId, @Param("indexCode") String indexCode, @Param("deleteSize") Integer deleteSize, @Param("isTotal") String isTotal);
List<CpcScoreEntity> getPartScore(@Param("customerId") String customerId, @Param("monthId") String monthId, @Param("allParentCode") String allParentCode);

2
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/CpcSubScoreDao.java

@ -79,7 +79,7 @@ public interface CpcSubScoreDao extends BaseDao<CpcScoreEntity> {
**/
BigDecimal selectGridJoinIssueAvgValue(@Param("customerId") String customerId, @Param("monthId") String monthId, @Param("gridId") String gridId);
int deleteByMonthId(@Param("customerId") String customerId, @Param("monthId") String monthId, @Param("allParentCode") String allParentCode);
int deleteByMonthId(@Param("customerId") String customerId, @Param("monthId") String monthId, @Param("allParentCode") String allParentCode, @Param("deleteSize") Integer deleteSize);
List<CpcScoreEntity> getPartScore(@Param("customerId") String customerId, @Param("monthId") String monthId, @Param("allParentCode") String allParentCode);

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

@ -29,6 +29,7 @@ import com.epmet.support.normalizing.batch.CalculateResult;
import com.epmet.support.normalizing.batch.IndexInputVO;
import com.epmet.support.normalizing.batch.SampleValue;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -36,7 +37,10 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@ -95,7 +99,7 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
totalEntity = ConvertUtils.sourceToTarget(part, CpcScoreEntity.class);
totalEntity.setIsTotal(NumConstant.ONE_STR);
totalEntity.setIndexCode(IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode());
totalEntity.setScore(new BigDecimal(0));
totalEntity.setScore(new BigDecimal(NumConstant.ZERO));
totalEntity.setAllParentIndexCode(indexGroupDetailEntity.getAllParentIndexCode());
cpcScoreTotalMap.put(userId, totalEntity);
}
@ -105,7 +109,9 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
totalEntity.setScore(totalEntity.getScore().add(total));
}
});
deleteAndInsertBatch(formDTO, cpcScoreTotalMap.values().stream().collect(Collectors.toList()), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode());
//删除总分 然后插入
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());
}
/**
@ -140,10 +146,13 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
* @param indexCode 指标code 非必填
* @param values
*/
@Transactional(rollbackFor = Exception.class)
private void deleteAndInsertBatch(CalculateCommonFormDTO formDTO, Collection<CpcScoreEntity> values, String indexCode) {
cpcScoreDao.deleteByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), indexCode);
cpcScoreDao.insertBatch(values);
public void insertCpcScoreBatch(CalculateCommonFormDTO formDTO, List<CpcScoreEntity> values, String indexCode) {
if (CollectionUtils.isEmpty(values)) {
log.error("insertCpcScoreBatch要插入的数据为空,param:{},indexCode:{}", JSON.toJSONString(formDTO), indexCode);
return;
}
List<List<CpcScoreEntity>> partition = ListUtils.partition(values, IndexCalConstant.INSERT_SIZE);
partition.forEach(list -> cpcScoreDao.insertBatch(list));
}
private void calculatePartScore(CalculateCommonFormDTO formDTO) {
@ -161,9 +170,12 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
}
int pageNo = NumConstant.ONE;
int pageSize = NumConstant.ONE_THOUSAND;
int pageSize = IndexCalConstant.PAGE_SIZE;
//分页查询 要计算的原始数据
List<Map<String, Object>> list = null;
groupIndexDetailsMap.keySet().forEach(indexCode -> {
deleteOldData(formDTO, indexCode);
});
do {
list = factIndexPartyAblityCpcMonthlyDao.getCountByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), (pageNo - 1) * pageSize, pageSize);
if (!CollectionUtils.isEmpty(list)) {
@ -178,6 +190,20 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
} while (!CollectionUtils.isEmpty(list) && list.size() == pageSize);
}
@Transactional(rollbackFor = Exception.class)
public void deleteOldData(CalculateCommonFormDTO formDTO, String indexCode) {
int effectRow;
do {
effectRow = cpcScoreDao.deleteByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), indexCode, IndexCalConstant.DELETE_SIZE, NumConstant.ZERO_STR);
} while (effectRow > NumConstant.ZERO);
effectRow = NumConstant.ZERO;
do {
//删除 党员相关:(参与议事等4级指标的 明细数据)
String allParentCode = IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode().concat(StrConstant.COLON).concat(indexCode);
effectRow = cpcSubScoreDao.deleteByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), allParentCode, IndexCalConstant.DELETE_SIZE);
} while (effectRow > NumConstant.ZERO);
}
/**
* desc计算并保存中间结果
*
@ -213,7 +239,7 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
cpcScoreEntity.setUserId(userId);
cpcScoreEntity.setIsTotal(NumConstant.ZERO_STR);
cpcScoreEntity.setMonthId(formDTO.getMonthId());
cpcScoreEntity.setScore(new BigDecimal(0));
cpcScoreEntity.setScore(new BigDecimal(NumConstant.ZERO));
cpcScoreEntity.setIndexCode(parentIndexCode);
cpcScoreEntity.setAllParentIndexCode(value.getAllParentIndexCode());
scoreEntityMap.put(userId, cpcScoreEntity);
@ -243,7 +269,6 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
* @param parentIndexCode
* @param result
*/
@Transactional(rollbackFor = Exception.class)
public void saveCpcScore(CalculateCommonFormDTO formDTO, Map<String, CpcScoreEntity> indexDetails, String parentIndexCode, HashMap<String, CalculateResult> result) {
List<CpcScoreEntity> list = new ArrayList<>();
@ -254,8 +279,8 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
CalculateResult score = entry.getValue();
CpcScoreEntity cpcScoreEntity = indexDetails.get(userId);
cpcScoreEntity.setScore(score.getTotalScore());
allParentIndexCode = score.getDetails().get(0).getAllParentIndexCode();
cpcScoreEntity.setAllParentIndexCode(allParentIndexCode.substring(0, allParentIndexCode.lastIndexOf(StrConstant.COLON)));
allParentIndexCode = score.getDetails().get(NumConstant.ZERO).getAllParentIndexCode();
cpcScoreEntity.setAllParentIndexCode(allParentIndexCode.substring(NumConstant.ZERO, allParentIndexCode.lastIndexOf(StrConstant.COLON)));
list.add(cpcScoreEntity);
CpcScoreEntity parent = ConvertUtils.sourceToTarget(cpcScoreEntity, CpcScoreEntity.class);
score.getDetails().forEach(o -> {
@ -267,9 +292,8 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
});
}
System.out.println("value:" + JSON.toJSONString(list));
this.deleteAndInsertBatch(formDTO, list, parentIndexCode);
this.deleteAndInsertSubBatch(formDTO, subList, allParentIndexCode);
this.insertCpcScoreBatch(formDTO, list, parentIndexCode);
this.insertCpcSubScoreBatch(formDTO, subList, allParentIndexCode);
}
/**
@ -279,10 +303,13 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
* @param subList
* @param parentIndexCode 指标code 非必填
*/
@Transactional(rollbackFor = Exception.class)
public void deleteAndInsertSubBatch(CalculateCommonFormDTO formDTO, List<CpcSubScoreEntity> subList, String parentIndexCode) {
cpcSubScoreDao.deleteByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), parentIndexCode);
cpcSubScoreDao.insertBatch(subList);
public void insertCpcSubScoreBatch(CalculateCommonFormDTO formDTO, List<CpcSubScoreEntity> subList, String parentIndexCode) {
if (CollectionUtils.isEmpty(subList)) {
log.error("insertCpcScoreBatch要插入的数据为空,param:{},indexCode:{}", JSON.toJSONString(formDTO), parentIndexCode);
return;
}
List<List<CpcSubScoreEntity>> partition = ListUtils.partition(subList, IndexCalConstant.INSERT_SIZE);
partition.forEach(list -> cpcSubScoreDao.insertBatch(list));
}

14
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/CpcScoreDao.xml

@ -6,11 +6,15 @@
<delete id="deleteByMonthId">
delete from fact_index_cpc_score
where
CUSTOMER_ID = #{customerId,jdbcType=VARCHAR}
and MONTH_ID = #{monthId,jdbcType=VARCHAR}
<if test="indexCode != null and indexCode !=''">
and INDEX_CODE = #{indexCode,jdbcType=VARCHAR}
</if>
CUSTOMER_ID = #{customerId,jdbcType=VARCHAR}
AND MONTH_ID = #{monthId,jdbcType=VARCHAR}
AND IS_TOTAL = #{isTotal,jdbcType=VARCHAR}
<if test="indexCode != null and indexCode !=''">
and INDEX_CODE = #{indexCode,jdbcType=VARCHAR}
</if>
<if test="deleteSize != null">
limit #{deleteSize,jdbcType=INTEGER}
</if>
</delete>
<resultMap type="com.epmet.entity.evaluationindex.indexcal.CpcScoreEntity" id="cpcScoreMap">

10
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/CpcSubScoreDao.xml

@ -6,10 +6,12 @@
<delete id="deleteByMonthId">
delete from fact_index_cpc_sub_score
where
CUSTOMER_ID = #{customerId,jdbcType=VARCHAR}
and MONTH_ID = #{monthId,jdbcType=VARCHAR}
and ALL_PARENT_INDEX_CODE = #{allParentCode,jdbcType=VARCHAR}
CUSTOMER_ID = #{customerId,jdbcType=VARCHAR}
and MONTH_ID = #{monthId,jdbcType=VARCHAR}
and ALL_PARENT_INDEX_CODE = #{allParentCode,jdbcType=VARCHAR}
<if test="deleteSize != null">
limit #{deleteSize,jdbcType=INTEGER}
</if>
</delete>
<resultMap type="com.epmet.entity.evaluationindex.indexcal.CpcScoreEntity" id="cpcScoreMap">

Loading…
Cancel
Save