12 changed files with 562 additions and 9 deletions
@ -0,0 +1,51 @@ |
|||||
|
package com.epmet.dto.indexcal; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
import java.math.BigDecimal; |
||||
|
|
||||
|
/** |
||||
|
* @Author zxc |
||||
|
* @DateTime 2020/9/4 9:32 上午 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class SubAgencyScoreAvgResultDTO implements Serializable { |
||||
|
|
||||
|
private static final long serialVersionUID = 6913351504675726385L; |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
*/ |
||||
|
private String customerId; |
||||
|
|
||||
|
/** |
||||
|
* 机关ID |
||||
|
*/ |
||||
|
private String agencyId; |
||||
|
|
||||
|
/** |
||||
|
* 上级组织ID |
||||
|
*/ |
||||
|
private String parentId; |
||||
|
|
||||
|
/** |
||||
|
* 月度ID |
||||
|
*/ |
||||
|
private String monthId; |
||||
|
|
||||
|
/** |
||||
|
* 季度ID |
||||
|
*/ |
||||
|
private String quarterId; |
||||
|
|
||||
|
/** |
||||
|
* 年度ID |
||||
|
*/ |
||||
|
private String yearId; |
||||
|
|
||||
|
/** |
||||
|
* 分数 |
||||
|
*/ |
||||
|
private BigDecimal score; |
||||
|
} |
@ -0,0 +1,18 @@ |
|||||
|
package com.epmet.service.evaluationindex.indexcal; |
||||
|
|
||||
|
/** |
||||
|
* @Author zxc |
||||
|
* @DateTime 2020/9/4 9:03 上午 |
||||
|
*/ |
||||
|
public interface IndexCalculateDistrictService { |
||||
|
|
||||
|
/** |
||||
|
* @Description 计算全区相关总分 |
||||
|
* @param customerId |
||||
|
* @param monthId |
||||
|
* @author zxc |
||||
|
* @date 2020/9/2 3:12 下午 |
||||
|
*/ |
||||
|
Boolean calDistrictAll(String customerId, String monthId); |
||||
|
|
||||
|
} |
@ -0,0 +1,406 @@ |
|||||
|
package com.epmet.service.evaluationindex.indexcal.impl; |
||||
|
|
||||
|
import com.alibaba.druid.util.StringUtils; |
||||
|
import com.epmet.commons.dynamic.datasource.annotation.DataSource; |
||||
|
import com.epmet.commons.tools.constant.NumConstant; |
||||
|
import com.epmet.commons.tools.exception.RenException; |
||||
|
import com.epmet.commons.tools.utils.DateUtils; |
||||
|
import com.epmet.constant.DataSourceConstant; |
||||
|
import com.epmet.constant.IndexCalConstant; |
||||
|
import com.epmet.dao.evaluationindex.indexcal.AgencyScoreDao; |
||||
|
import com.epmet.dao.evaluationindex.indexcal.DeptScoreDao; |
||||
|
import com.epmet.dao.evaluationindex.indexcoll.FactIndexGovrnAblityDeptMonthlyDao; |
||||
|
import com.epmet.dao.evaluationindex.indexcoll.FactIndexPartyAblityOrgMonthlyDao; |
||||
|
import com.epmet.dto.indexcal.AgencyScoreDTO; |
||||
|
import com.epmet.dto.indexcal.SubAgencyScoreAvgResultDTO; |
||||
|
import com.epmet.dto.screen.result.MaxAndMinBigDecimalResultDTO; |
||||
|
import com.epmet.entity.evaluationindex.screen.IndexGroupDetailEntity; |
||||
|
import com.epmet.eum.IndexCodeEnum; |
||||
|
import com.epmet.service.evaluationindex.indexcal.IndexCalculateDistrictService; |
||||
|
import com.epmet.service.evaluationindex.indexcal.IndexCodeFieldReService; |
||||
|
import com.epmet.service.evaluationindex.screen.IndexGroupDetailService; |
||||
|
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.BatchScoreCalculator; |
||||
|
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.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
import org.springframework.util.CollectionUtils; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
import java.util.*; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
/** |
||||
|
* @Author zxc |
||||
|
* @DateTime 2020/9/4 9:03 上午 |
||||
|
*/ |
||||
|
@Service |
||||
|
@Slf4j |
||||
|
@DataSource(DataSourceConstant.EVALUATION_INDEX) |
||||
|
public class IndexCalculateDistrictServiceImpl implements IndexCalculateDistrictService { |
||||
|
|
||||
|
@Autowired |
||||
|
private FactIndexPartyAblityOrgMonthlyDao factIndexPartyAblityOrgMonthlyDao; |
||||
|
@Autowired |
||||
|
private IndexCodeFieldReService indexCodeFieldReService; |
||||
|
@Autowired |
||||
|
private IndexGroupDetailService indexGroupDetailService; |
||||
|
@Autowired |
||||
|
private AgencyScoreDao agencyScoreDao; |
||||
|
@Autowired |
||||
|
private DeptScoreDao deptScoreDao; |
||||
|
|
||||
|
/** |
||||
|
* @Description 计算全区相关总分 |
||||
|
* @param customerId |
||||
|
* @param monthId |
||||
|
* @author zxc |
||||
|
* @date 2020/9/2 3:12 下午 |
||||
|
*/ |
||||
|
@Override |
||||
|
public Boolean calDistrictAll(String customerId, String monthId) { |
||||
|
Boolean aBoolean = districtPartyCalculate(customerId, monthId);//党建能力
|
||||
|
if (!aBoolean.equals(true)) { |
||||
|
throw new RenException("calculate district-party-ability failure ......"); |
||||
|
} |
||||
|
Boolean bBoolean = districtGovernAbilityCalculate(customerId, monthId);// 治理能力
|
||||
|
if (!bBoolean.equals(true)) { |
||||
|
throw new RenException("calculate district-govern-ability failure ......"); |
||||
|
} |
||||
|
Boolean cBoolean = districtServiceAbilityCalculate(customerId, monthId);// 服务能力
|
||||
|
if (!cBoolean.equals(true)) { |
||||
|
throw new RenException("calculate district-service-ability failure ......"); |
||||
|
} |
||||
|
Boolean dBoolean = districtRelate(customerId, monthId); |
||||
|
if (!dBoolean.equals(true)) { |
||||
|
throw new RenException("calculate district-all insert failure ......"); |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param customerId |
||||
|
* @Description 全区名义发文数量计算【党建能力】 |
||||
|
* @author zxc |
||||
|
* @date 2020/8/26 10:46 上午 |
||||
|
*/ |
||||
|
public Boolean districtPartyCalculate(String customerId, String monthId) { |
||||
|
// 党建能力
|
||||
|
// 根据all_parent_index_code 获取指标明细
|
||||
|
List<IndexGroupDetailEntity> indexDetailList = indexGroupDetailService.getDetailListByParentCode(customerId, IndexCodeEnum.QUAN_QU_XIANG_GUAN.getCode(), IndexCodeEnum.DANG_JIAN_NENG_LI.getCode()); |
||||
|
if (CollectionUtils.isEmpty(indexDetailList)) { |
||||
|
log.error(IndexCalConstant.INDEX_DETAIL_LIST_NULL); |
||||
|
return false; |
||||
|
} |
||||
|
List<IndexInputVO> indexInputVOS = new ArrayList<>(); |
||||
|
Map<String,String> pid = new HashMap<>(); |
||||
|
//党建能力平均值
|
||||
|
indexDetailList.forEach(detail -> { |
||||
|
if (IndexCodeEnum.QU_XIA_JI_JIE_DDJNLHZPJZ.getCode().equals(detail.getIndexCode())) { |
||||
|
List<SubAgencyScoreAvgResultDTO> subGridPartyAvgScore = agencyScoreDao.selectAgencyScoreAvg(customerId, monthId,IndexCodeEnum.DANG_JIAN_NENG_LI.getCode()); |
||||
|
if (CollectionUtils.isEmpty(subGridPartyAvgScore)) { |
||||
|
log.error(IndexCalConstant.DISTRICT_PARTY_AVG_NULL); |
||||
|
return; |
||||
|
}else if (subGridPartyAvgScore.size() == NumConstant.ONE){ |
||||
|
pid.put(subGridPartyAvgScore.get(NumConstant.ZERO).getAgencyId(),subGridPartyAvgScore.get(NumConstant.ZERO).getParentId()); |
||||
|
sizeOne(subGridPartyAvgScore.get(NumConstant.ZERO).getAgencyId(),customerId,monthId,IndexCodeEnum.DANG_JIAN_NENG_LI.getCode(),pid); |
||||
|
return; |
||||
|
}else if (subGridPartyAvgScore.size() > NumConstant.ONE) { |
||||
|
MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(subGridPartyAvgScore.stream().map(o -> o.getScore()).collect(Collectors.toList())); |
||||
|
List<List<SubAgencyScoreAvgResultDTO>> subPartyAvgList = ListUtils.partition(subGridPartyAvgScore, IndexCalConstant.PAGE_SIZE); |
||||
|
subPartyAvgList.forEach( party -> { |
||||
|
List<SampleValue> index1SampleValues = new ArrayList<>(); |
||||
|
party.forEach(c -> { |
||||
|
pid.put(c.getAgencyId(),c.getParentId()); |
||||
|
SampleValue s = new SampleValue(c.getAgencyId(), c.getScore()); |
||||
|
index1SampleValues.add(s); |
||||
|
}); |
||||
|
BigDecimalScoreCalculator sc = new BigDecimalScoreCalculator(maxAndMinBigDecimal.getMin(), maxAndMinBigDecimal.getMax(), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.getCorrelation(detail.getCorrelation())); |
||||
|
IndexInputVO index1VO = new IndexInputVO(detail.getIndexId(), index1SampleValues, detail.getThreshold(), detail.getWeight(), sc); |
||||
|
indexInputVOS.add(index1VO); |
||||
|
}); |
||||
|
} |
||||
|
} else { |
||||
|
// 区名义发文数量
|
||||
|
List<Map<String, Object>> publishArticleCountList = factIndexPartyAblityOrgMonthlyDao.selectPublishArticleCountMap(customerId, monthId,IndexCalConstant.DISTRICT_LEVEL); |
||||
|
if (CollectionUtils.isEmpty(publishArticleCountList)) { |
||||
|
log.error(IndexCalConstant.DISTRICT_PUBLISH_ARTICLE_LIST_NULL); |
||||
|
return; |
||||
|
} |
||||
|
String fieldNameByIndexCode = indexCodeFieldReService.getFieldNameByIndexCode(detail.getIndexCode()); |
||||
|
if (StringUtils.isEmpty(fieldNameByIndexCode)) { |
||||
|
log.error(String.format(IndexCalConstant.INDEX_CODE_NULL,detail.getIndexCode())); |
||||
|
return; |
||||
|
}else if (publishArticleCountList.size() == NumConstant.ONE){ |
||||
|
pid.put(publishArticleCountList.get(NumConstant.ZERO).get(IndexCalConstant.AGENCY_ID).toString(),publishArticleCountList.get(NumConstant.ZERO).get(IndexCalConstant.PARENT_ID).toString()); |
||||
|
sizeOne(publishArticleCountList.get(NumConstant.ZERO).get(IndexCalConstant.AGENCY_ID).toString(),customerId,monthId,IndexCodeEnum.DANG_JIAN_NENG_LI.getCode(),pid); |
||||
|
return; |
||||
|
}else if (publishArticleCountList.size() > NumConstant.ONE) { |
||||
|
List<BigDecimal> decimalList = publishArticleCountList.stream().map(m -> new BigDecimal(m.get(fieldNameByIndexCode).toString())).collect(Collectors.toList()); |
||||
|
MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(decimalList); |
||||
|
List<List<Map<String, Object>>> publishArticleList = ListUtils.partition(publishArticleCountList, IndexCalConstant.PAGE_SIZE); |
||||
|
publishArticleList.forEach( publish -> { |
||||
|
ScoreCalculator sc1 = new BigDecimalScoreCalculator(maxAndMinBigDecimal.getMin(), maxAndMinBigDecimal.getMax(), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE); |
||||
|
List<SampleValue> index1SampleValues = new ArrayList<>(); |
||||
|
publish.forEach(c -> { |
||||
|
pid.put(c.get(IndexCalConstant.AGENCY_ID).toString(),c.get(IndexCalConstant.PARENT_ID).toString()); |
||||
|
SampleValue s = new SampleValue((String) c.get(IndexCalConstant.AGENCY_ID), new BigDecimal(String.valueOf(c.get(fieldNameByIndexCode)))); |
||||
|
index1SampleValues.add(s); |
||||
|
}); |
||||
|
IndexInputVO index1VO = new IndexInputVO(detail.getIndexId(), index1SampleValues, detail.getThreshold(), detail.getWeight(), sc1); |
||||
|
indexInputVOS.add(index1VO); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator(); |
||||
|
HashMap<String, BigDecimal> scoreCountOfSampleId = batchScoreCalculator.getScoreCountOfSampleId(indexInputVOS); |
||||
|
List<AgencyScoreDTO> result = getResult(scoreCountOfSampleId, customerId, monthId, NumConstant.ZERO_STR, IndexCodeEnum.DANG_JIAN_NENG_LI.getCode(), pid); |
||||
|
deleteAndInsert(customerId, monthId, IndexCodeEnum.DANG_JIAN_NENG_LI.getCode(), result); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param customerId |
||||
|
* @param monthId |
||||
|
* @Description 全区治理能力 |
||||
|
* @author zxc |
||||
|
* @date 2020/8/26 1:40 下午 |
||||
|
*/ |
||||
|
public Boolean districtGovernAbilityCalculate(String customerId, String monthId) { |
||||
|
List<IndexGroupDetailEntity> detailListByParentCode = indexGroupDetailService.getDetailListByParentCode(customerId, IndexCodeEnum.QUAN_QU_XIANG_GUAN.getCode(), IndexCodeEnum.ZHI_LI_NENG_LI.getCode()); |
||||
|
if (CollectionUtils.isEmpty(detailListByParentCode)) { |
||||
|
log.error(IndexCalConstant.INDEX_DETAIL_LIST_NULL); |
||||
|
return false; |
||||
|
} |
||||
|
List<IndexInputVO> indexInputVOS = new ArrayList<>(); |
||||
|
Map<String,String> pid = new HashMap<>(); |
||||
|
detailListByParentCode.forEach(detail -> { |
||||
|
if (IndexCodeEnum.SUO_YOU_JIE_DAO_ZLNLPJZ.getCode().equals(detail.getIndexCode())) { |
||||
|
List<SubAgencyScoreAvgResultDTO> districtGovernAvgList = agencyScoreDao.selectAgencyScoreAvg(customerId, monthId, IndexCodeEnum.ZHI_LI_NENG_LI.getCode()); |
||||
|
if (districtGovernAvgList.size() == NumConstant.ONE) { |
||||
|
pid.put(districtGovernAvgList.get(NumConstant.ZERO).getAgencyId(),districtGovernAvgList.get(NumConstant.ZERO).getParentId()); |
||||
|
sizeOne(districtGovernAvgList.get(NumConstant.ZERO).getAgencyId(),customerId,monthId,IndexCodeEnum.ZHI_LI_NENG_LI.getCode(),pid); |
||||
|
return; |
||||
|
} else if (districtGovernAvgList.size() > NumConstant.ONE) { |
||||
|
MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(districtGovernAvgList.stream().map(o -> o.getScore()).collect(Collectors.toList())); |
||||
|
List<List<SubAgencyScoreAvgResultDTO>> governAvg = ListUtils.partition(districtGovernAvgList, IndexCalConstant.PAGE_SIZE); |
||||
|
governAvg.forEach(avg -> { |
||||
|
List<SampleValue> index1SampleValues = new ArrayList<>(); |
||||
|
avg.forEach(c -> { |
||||
|
pid.put(c.getAgencyId(),c.getParentId()); |
||||
|
SampleValue s = new SampleValue(c.getAgencyId(), c.getScore()); |
||||
|
index1SampleValues.add(s); |
||||
|
}); |
||||
|
BigDecimalScoreCalculator sc = new BigDecimalScoreCalculator(maxAndMinBigDecimal.getMin(), maxAndMinBigDecimal.getMax(), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.getCorrelation(detail.getCorrelation())); |
||||
|
IndexInputVO index1VO = new IndexInputVO(detail.getIndexId(), index1SampleValues, detail.getThreshold(), detail.getWeight(), sc); |
||||
|
indexInputVOS.add(index1VO); |
||||
|
}); |
||||
|
} |
||||
|
} else if (IndexCodeEnum.SUO_YOU_ZHI_SHU_BMZLNLPJZ.getCode().equals(detail.getIndexCode())){ |
||||
|
List<SubAgencyScoreAvgResultDTO> deptScoreAvgList = deptScoreDao.selectGovernDeptScoreAvg(customerId, monthId, IndexCodeEnum.ZHI_LI_NENG_LI.getCode()); |
||||
|
if (deptScoreAvgList.size() == NumConstant.ONE) { |
||||
|
pid.put(deptScoreAvgList.get(NumConstant.ZERO).getAgencyId(),deptScoreAvgList.get(NumConstant.ZERO).getParentId()); |
||||
|
sizeOne(deptScoreAvgList.get(NumConstant.ZERO).getAgencyId(),customerId,monthId,IndexCodeEnum.ZHI_LI_NENG_LI.getCode(),pid); |
||||
|
return; |
||||
|
} else if (deptScoreAvgList.size() > NumConstant.ONE) { |
||||
|
MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(deptScoreAvgList.stream().map(o -> o.getScore()).collect(Collectors.toList())); |
||||
|
List<List<SubAgencyScoreAvgResultDTO>> governAvg = ListUtils.partition(deptScoreAvgList, IndexCalConstant.PAGE_SIZE); |
||||
|
governAvg.forEach(avg -> { |
||||
|
List<SampleValue> index1SampleValues = new ArrayList<>(); |
||||
|
avg.forEach(c -> { |
||||
|
pid.put(c.getAgencyId(),c.getParentId()); |
||||
|
SampleValue s = new SampleValue(c.getAgencyId(), c.getScore()); |
||||
|
index1SampleValues.add(s); |
||||
|
}); |
||||
|
BigDecimalScoreCalculator sc = new BigDecimalScoreCalculator(maxAndMinBigDecimal.getMin(), maxAndMinBigDecimal.getMax(), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.getCorrelation(detail.getCorrelation())); |
||||
|
IndexInputVO index1VO = new IndexInputVO(detail.getIndexId(), index1SampleValues, detail.getThreshold(), detail.getWeight(), sc); |
||||
|
indexInputVOS.add(index1VO); |
||||
|
}); |
||||
|
} |
||||
|
}else{ |
||||
|
// TODO 治理能力暂无自身级别
|
||||
|
} |
||||
|
}); |
||||
|
BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator(); |
||||
|
HashMap<String, BigDecimal> scoreCountOfSampleId = batchScoreCalculator.getScoreCountOfSampleId(indexInputVOS); |
||||
|
List<AgencyScoreDTO> result = getResult(scoreCountOfSampleId, customerId, monthId, NumConstant.ZERO_STR, IndexCodeEnum.ZHI_LI_NENG_LI.getCode(), pid); |
||||
|
deleteAndInsert(customerId, monthId, IndexCodeEnum.ZHI_LI_NENG_LI.getCode(), result); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param customerId |
||||
|
* @param monthId |
||||
|
* @Description 全区服务能力 |
||||
|
* @author zxc |
||||
|
* @date 2020/8/31 1:38 下午 |
||||
|
*/ |
||||
|
public Boolean districtServiceAbilityCalculate(String customerId, String monthId) { |
||||
|
List<IndexGroupDetailEntity> detailListByParentCode = indexGroupDetailService.getDetailListByParentCode(customerId, IndexCodeEnum.QUAN_QU_XIANG_GUAN.getCode(), IndexCodeEnum.FU_WU_NENG_LI.getCode()); |
||||
|
if (CollectionUtils.isEmpty(detailListByParentCode)) { |
||||
|
log.error(IndexCalConstant.INDEX_DETAIL_LIST_NULL); |
||||
|
return false; |
||||
|
} |
||||
|
List<IndexInputVO> indexInputVOS = new ArrayList<>(); |
||||
|
Map<String,String> pid = new HashMap<>(); |
||||
|
detailListByParentCode.forEach(detail -> { |
||||
|
String indexCode = detail.getIndexCode(); |
||||
|
if (IndexCodeEnum.QU_XIA_SHU_JIE_DFWNLHZPJZ.getCode().equals(indexCode)) { |
||||
|
List<SubAgencyScoreAvgResultDTO> subStreetAvgList = agencyScoreDao.selectAgencyScoreAvg(customerId, monthId,IndexCodeEnum.FU_WU_NENG_LI.getCode()); |
||||
|
if (subStreetAvgList.size() == NumConstant.ONE) { |
||||
|
pid.put(subStreetAvgList.get(NumConstant.ZERO).getAgencyId(),subStreetAvgList.get(NumConstant.ZERO).getParentId()); |
||||
|
sizeOne(subStreetAvgList.get(NumConstant.ZERO).getAgencyId(),customerId,monthId,IndexCodeEnum.FU_WU_NENG_LI.getCode(),pid); |
||||
|
return; |
||||
|
} else if (subStreetAvgList.size() > NumConstant.ONE) { |
||||
|
MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(subStreetAvgList.stream().map(o -> o.getScore()).collect(Collectors.toList())); |
||||
|
List<List<SubAgencyScoreAvgResultDTO>> serviceAvgList = ListUtils.partition(subStreetAvgList, IndexCalConstant.PAGE_SIZE); |
||||
|
serviceAvgList.forEach(serviceAvg -> { |
||||
|
BigDecimalScoreCalculator sc1 = new BigDecimalScoreCalculator(maxAndMinBigDecimal.getMin(), maxAndMinBigDecimal.getMax(), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE); |
||||
|
List<SampleValue> index1SampleValues = new ArrayList<>(); |
||||
|
serviceAvg.forEach(c -> { |
||||
|
pid.put(c.getAgencyId(),c.getParentId()); |
||||
|
SampleValue s = new SampleValue(c.getAgencyId(), c.getScore()); |
||||
|
index1SampleValues.add(s); |
||||
|
}); |
||||
|
IndexInputVO index1VO = new IndexInputVO(detail.getIndexId(), index1SampleValues, detail.getThreshold(), detail.getWeight(), sc1); |
||||
|
indexInputVOS.add(index1VO); |
||||
|
}); |
||||
|
} |
||||
|
} else { |
||||
|
// todo 暂时没有自身级别
|
||||
|
} |
||||
|
}); |
||||
|
BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator(); |
||||
|
HashMap<String, BigDecimal> scoreCountOfSampleId = batchScoreCalculator.getScoreCountOfSampleId(indexInputVOS); |
||||
|
List<AgencyScoreDTO> result = getResult(scoreCountOfSampleId, customerId, monthId, NumConstant.ZERO_STR, IndexCodeEnum.FU_WU_NENG_LI.getCode(),pid); |
||||
|
deleteAndInsert(customerId, monthId, IndexCodeEnum.FU_WU_NENG_LI.getCode(), result); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param customerId |
||||
|
* @param monthId |
||||
|
* @Description 区相关计算 |
||||
|
* @author zxc |
||||
|
* @date 2020/9/1 9:21 上午 |
||||
|
*/ |
||||
|
public Boolean districtRelate(String customerId, String monthId) { |
||||
|
List<IndexGroupDetailEntity> detailListByParentCode = indexGroupDetailService.getDetailListByParentCode(customerId, IndexCodeEnum.SHE_QU_XIANG_GUAN.getCode()); |
||||
|
List<AgencyScoreDTO> agencyScoreList = agencyScoreDao.selectAgencyScoreInfo(customerId, monthId, IndexCalConstant.DISTRICT_LEVEL); |
||||
|
detailListByParentCode.forEach(detail -> { |
||||
|
agencyScoreList.forEach(community -> { |
||||
|
if (detail.getIndexCode().equals(community.getIndexCode())) { |
||||
|
community.setScore(community.getScore().multiply(detail.getWeight())); |
||||
|
} |
||||
|
}); |
||||
|
}); |
||||
|
Map<String, List<AgencyScoreDTO>> collect = agencyScoreList.stream().collect(Collectors.groupingBy(AgencyScoreDTO::getAgencyId)); |
||||
|
List<AgencyScoreDTO> result = new ArrayList<>(); |
||||
|
collect.forEach((key, value) -> { |
||||
|
AgencyScoreDTO score = new AgencyScoreDTO(); |
||||
|
score.setIsTotal(NumConstant.ONE_STR); |
||||
|
score.setCustomerId(customerId); |
||||
|
score.setAgencyId(key); |
||||
|
score.setMonthId(monthId); |
||||
|
score.setYearId(DateUtils.getYearId(monthId)); |
||||
|
score.setQuarterId(DateUtils.getQuarterId(monthId)); |
||||
|
score.setIndexCode(IndexCodeEnum.QUAN_QU_XIANG_GUAN.getCode()); |
||||
|
value.forEach(community -> { |
||||
|
score.setScore(score.getScore().add(community.getScore())); |
||||
|
score.setParentAgencyId(community.getParentAgencyId()); |
||||
|
}); |
||||
|
result.add(score); |
||||
|
}); |
||||
|
deleteAndInsert(customerId, monthId, IndexCodeEnum.QUAN_QU_XIANG_GUAN.getCode(), result); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param list |
||||
|
* @Description BigDecimal类型获取最大数和最小数 |
||||
|
* @author zxc |
||||
|
* @date 2020/8/27 1:30 下午 |
||||
|
*/ |
||||
|
public MaxAndMinBigDecimalResultDTO getMaxAndMinBigDecimal(List<BigDecimal> list) { |
||||
|
BigDecimal max = Collections.max(list); |
||||
|
BigDecimal min = Collections.min(list); |
||||
|
MaxAndMinBigDecimalResultDTO result = new MaxAndMinBigDecimalResultDTO(); |
||||
|
result.setMax(max); |
||||
|
result.setMin(min); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param customerId |
||||
|
* @param monthId |
||||
|
* @param indexCode |
||||
|
* @param subAllDistrict |
||||
|
* @Description 先删除记录,在插入 |
||||
|
* @author zxc |
||||
|
* @date 2020/9/1 4:24 下午 |
||||
|
*/ |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void deleteAndInsert(String customerId, String monthId, String indexCode, List<AgencyScoreDTO> subAllDistrict) { |
||||
|
if (!CollectionUtils.isEmpty(subAllDistrict)) { |
||||
|
agencyScoreDao.deleteOldRecord(customerId, monthId, indexCode,IndexCalConstant.DISTRICT_LEVEL); |
||||
|
System.err.println(subAllDistrict.size()); |
||||
|
agencyScoreDao.insertStreetRecord(subAllDistrict); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @Description |
||||
|
* @param scoreCountOfSampleId 指标计算结果 |
||||
|
* @param customerId 客户ID |
||||
|
* @param monthId 月份ID |
||||
|
* @param isTotal 是否 总分【党建+治理+服务】 |
||||
|
* @param indexCode 党建能力:dangjiannengli,治理能力:zhilinengli,服务能力:fuwunengli,xx相关:xx相关 |
||||
|
* @author zxc |
||||
|
* @date 2020/9/2 2:37 下午 |
||||
|
*/ |
||||
|
public List<AgencyScoreDTO> getResult(HashMap<String, BigDecimal> scoreCountOfSampleId, String customerId, String monthId, String isTotal, String indexCode,Map<String,String> pid) { |
||||
|
List<AgencyScoreDTO> result = new ArrayList<>(); |
||||
|
scoreCountOfSampleId.forEach((k, v) -> { |
||||
|
AgencyScoreDTO score = new AgencyScoreDTO(); |
||||
|
score.setCustomerId(customerId); |
||||
|
score.setAgencyId(k); |
||||
|
score.setMonthId(monthId); |
||||
|
score.setQuarterId(DateUtils.getQuarterId(monthId)); |
||||
|
score.setYearId(DateUtils.getYearId(monthId)); |
||||
|
score.setIsTotal(isTotal); |
||||
|
score.setIndexCode(indexCode); |
||||
|
score.setScore(v); |
||||
|
score.setDataType(IndexCalConstant.DISTRICT_LEVEL); |
||||
|
pid.forEach((agency,parentAgency) -> { |
||||
|
if (k.equals(agency)){ |
||||
|
score.setParentAgencyId(parentAgency); |
||||
|
} |
||||
|
}); |
||||
|
result.add(score); |
||||
|
}); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @Description 当查询结果为一条时,调用此方法 |
||||
|
* @param agencyId |
||||
|
* @param customerId |
||||
|
* @param monthId |
||||
|
* @author zxc |
||||
|
* @date 2020/9/2 2:40 下午 |
||||
|
*/ |
||||
|
public void sizeOne(String agencyId,String customerId,String monthId,String indexCode,Map<String,String> pid){ |
||||
|
HashMap<String, BigDecimal> scoreCountOfSampleId = new HashMap<>(); |
||||
|
scoreCountOfSampleId.put(agencyId,new BigDecimal(NumConstant.FIFTY)); |
||||
|
List<AgencyScoreDTO> result = getResult(scoreCountOfSampleId, customerId, monthId, NumConstant.ZERO_STR, indexCode,pid); |
||||
|
deleteAndInsert(customerId, monthId, indexCode, result); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue