Browse Source

党员相关 如果只有一条记录则给50分;处理导入指标的正负相关及阈值

dev_shibei_match
jianjun 5 years ago
parent
commit
9fbb8136e4
  1. 28
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/IndexExcelDataListener.java
  2. 1
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/IndexModel.java
  3. 77
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/CpcIndexCalculateServiceImpl.java
  4. 18
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/CpcScoreDao.xml

28
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/IndexExcelDataListener.java

@ -11,6 +11,7 @@ import com.epmet.entity.evaluationindex.screen.IndexGroupTemplateEntity;
import com.epmet.service.evaluationindex.screen.IndexDictService; import com.epmet.service.evaluationindex.screen.IndexDictService;
import com.epmet.service.evaluationindex.screen.IndexGroupDetailTemplateService; import com.epmet.service.evaluationindex.screen.IndexGroupDetailTemplateService;
import com.epmet.service.evaluationindex.screen.IndexGroupTemplateService; import com.epmet.service.evaluationindex.screen.IndexGroupTemplateService;
import com.epmet.support.normalizing.Correlation;
import com.epmet.util.Pinyin4jUtil; import com.epmet.util.Pinyin4jUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -29,7 +30,6 @@ import java.util.stream.Collectors;
*/ */
public class IndexExcelDataListener extends AnalysisEventListener<IndexModel> { public class IndexExcelDataListener extends AnalysisEventListener<IndexModel> {
private static final Logger LOGGER = LoggerFactory.getLogger(IndexExcelDataListener.class); private static final Logger LOGGER = LoggerFactory.getLogger(IndexExcelDataListener.class);
private String POSITIVE = "positive";
/** /**
* 每隔5条存储数据库实际使用中可以3000条然后清理list 方便内存回收 * 每隔5条存储数据库实际使用中可以3000条然后清理list 方便内存回收
*/ */
@ -86,8 +86,23 @@ public class IndexExcelDataListener extends AnalysisEventListener<IndexModel> {
data.setWeight(preWheight); data.setWeight(preWheight);
} }
LOGGER.info("解析到一条数据:{}", JSON.toJSONString(data)); LOGGER.info("解析到一条数据:{}", JSON.toJSONString(data));
//TODO 默认正相关 if (StringUtils.isNotBlank(data.getThreshold())) {
data.setCorrelation(POSITIVE); String threshold = data.getThreshold();
if ("无".equals(data.getThreshold())) {
threshold = "-1";
} else if (data.getThreshold().contains("%")) {
String thresholdStr = data.getThreshold().replace("%", "");
threshold = new BigDecimal(thresholdStr).divide(new BigDecimal(100), 4, RoundingMode.HALF_UP).toString();
}
data.setThreshold(threshold);
}
if (StringUtils.isNotBlank(data.getCorrelation())) {
if (Correlation.NEGATIVE.getDesc().equals(data.getCorrelation())) {
data.setCorrelation(Correlation.NEGATIVE.getCode());
} else {
data.setCorrelation(Correlation.POSITIVE.getCode());
}
}
IndexDictEntity entity = new IndexDictEntity(); IndexDictEntity entity = new IndexDictEntity();
IndexDictEntity entity2 = new IndexDictEntity(); IndexDictEntity entity2 = new IndexDictEntity();
@ -240,11 +255,8 @@ public class IndexExcelDataListener extends AnalysisEventListener<IndexModel> {
templateEntity.setIndexCode(Pinyin4jUtil.getSpellPinYin(indexDictEntity.getIndexName(), false, 4)); templateEntity.setIndexCode(Pinyin4jUtil.getSpellPinYin(indexDictEntity.getIndexName(), false, 4));
templateEntity.setWeight(new BigDecimal(index.getWeight()).divide(new BigDecimal(100), 4, RoundingMode.HALF_UP)); templateEntity.setWeight(new BigDecimal(index.getWeight()).divide(new BigDecimal(100), 4, RoundingMode.HALF_UP));
} }
templateEntity.setThreshold(new BigDecimal(index.getThreshold()));
if (StringUtils.isNotBlank(index.getThreshold())) { templateEntity.setCorrelation(index.getCorrelation());
String thresholdStr = index.getThreshold().replace("%", "");
templateEntity.setThreshold(new BigDecimal(thresholdStr).divide(new BigDecimal(100), 4, RoundingMode.HALF_UP));
}
} }
private void buildIndexDicEntity(IndexModel data, IndexDictEntity entity, IndexDictEntity entity2, IndexDictEntity entity3, IndexDictEntity entity4, IndexDictEntity entity5) { private void buildIndexDicEntity(IndexModel data, IndexDictEntity entity, IndexDictEntity entity2, IndexDictEntity entity3, IndexDictEntity entity4, IndexDictEntity entity5) {

1
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/IndexModel.java

@ -21,6 +21,7 @@ public class IndexModel {
private String weight; private String weight;
@ExcelProperty(value = "五级权重") @ExcelProperty(value = "五级权重")
private String level5Weight; private String level5Weight;
//没有阈值:无,有就是百分数
@ExcelProperty(value = "阈值") @ExcelProperty(value = "阈值")
private String threshold; private String threshold;
/** /**

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

@ -10,9 +10,9 @@ import com.epmet.constant.DataSourceConstant;
import com.epmet.constant.IndexCalConstant; import com.epmet.constant.IndexCalConstant;
import com.epmet.dao.evaluationindex.indexcal.CpcScoreDao; import com.epmet.dao.evaluationindex.indexcal.CpcScoreDao;
import com.epmet.dao.evaluationindex.indexcoll.FactIndexPartyAblityCpcMonthlyDao; import com.epmet.dao.evaluationindex.indexcoll.FactIndexPartyAblityCpcMonthlyDao;
import com.epmet.dao.evaluationindex.screen.IndexCodeFieldReDao;
import com.epmet.dto.indexcal.CalculateCommonFormDTO; import com.epmet.dto.indexcal.CalculateCommonFormDTO;
import com.epmet.entity.evaluationindex.indexcal.CpcScoreEntity; import com.epmet.entity.evaluationindex.indexcal.CpcScoreEntity;
import com.epmet.entity.evaluationindex.indexcoll.FactIndexPartyAblityCpcMonthlyEntity;
import com.epmet.entity.evaluationindex.screen.IndexGroupDetailEntity; import com.epmet.entity.evaluationindex.screen.IndexGroupDetailEntity;
import com.epmet.eum.IndexCodeEnum; import com.epmet.eum.IndexCodeEnum;
import com.epmet.service.evaluationindex.indexcal.CpcIndexCalculateService; import com.epmet.service.evaluationindex.indexcal.CpcIndexCalculateService;
@ -43,8 +43,6 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
@Autowired @Autowired
private FactIndexPartyAblityCpcMonthlyDao factIndexPartyAblityCpcMonthlyDao; private FactIndexPartyAblityCpcMonthlyDao factIndexPartyAblityCpcMonthlyDao;
@Autowired @Autowired
private IndexCodeFieldReDao indexCodeFieldReDao;
@Autowired
private IndexGroupDetailService getDetailListByParentCode; private IndexGroupDetailService getDetailListByParentCode;
@Autowired @Autowired
private IndexCodeFieldReService indexCodeFieldReService; private IndexCodeFieldReService indexCodeFieldReService;
@ -97,11 +95,43 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
totalEntity.setScore(totalEntity.getScore().add(total)); totalEntity.setScore(totalEntity.getScore().add(total));
} }
}); });
deleteAndInsertBatch(formDTO.getCustomerId(),formDTO.getMonthId(),IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(),cpcScoreTotalMap.values().stream().collect(Collectors.toList())); deleteAndInsertBatch(formDTO, cpcScoreTotalMap.values().stream().collect(Collectors.toList()), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode());
}
/**
* @param formDTO
* @param indexCode
* @param stringObjectMap
* @return void
* @author yinzuomei
* @description 只有一条事实记录时分值默认赋50
* @Date 2020/9/2 14:35
**/
private CpcScoreEntity handleOneGridScene(CalculateCommonFormDTO formDTO, String indexCode, Map<String, Object> stringObjectMap) {
FactIndexPartyAblityCpcMonthlyEntity factCpc = JSON.parseObject(JSON.toJSONString(stringObjectMap), FactIndexPartyAblityCpcMonthlyEntity.class);
// 保存中间表
CpcScoreEntity cpcScoreEntity = new CpcScoreEntity();
cpcScoreEntity.setCustomerId(factCpc.getCustomerId());
cpcScoreEntity.setAgencyId(factCpc.getAgencyId());
cpcScoreEntity.setGridId(factCpc.getGridId());
cpcScoreEntity.setYearId(factCpc.getYearId());
cpcScoreEntity.setMonthId(factCpc.getMonthId());
cpcScoreEntity.setUserId(factCpc.getUserId());
cpcScoreEntity.setScore(new BigDecimal(NumConstant.FIFTY_STR));
cpcScoreEntity.setIndexCode(indexCode);
cpcScoreEntity.setIsTotal(NumConstant.ZERO_STR);
return cpcScoreEntity;
} }
private void deleteAndInsertBatch(String customerId, String monthId, String indexCode, Collection<CpcScoreEntity> values) { /**
cpcScoreDao.deleteByMonthId(customerId, monthId, indexCode); * desc:根据客户id和月份Id 指标code 非必填 删除数据
*
* @param formDTO
* @param indexCode 指标code 非必填
* @param values
*/
private void deleteAndInsertBatch(CalculateCommonFormDTO formDTO, Collection<CpcScoreEntity> values, String indexCode) {
cpcScoreDao.deleteByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), indexCode);
cpcScoreDao.insertBatch(values); cpcScoreDao.insertBatch(values);
} }
@ -119,20 +149,33 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
return; return;
} }
int pageNo = 1; int pageNo = NumConstant.ONE;
int pageSize = 10; int pageSize = NumConstant.ONE_THOUSAND;
//分页查询 要计算的原始数据 //分页查询 要计算的原始数据
List<Map<String, Object>> list = null; List<Map<String, Object>> list = null;
do { do {
list = factIndexPartyAblityCpcMonthlyDao.getCountByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), (pageNo - 1) * pageSize, pageSize); list = factIndexPartyAblityCpcMonthlyDao.getCountByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), (pageNo - 1) * pageSize, pageSize);
if (!CollectionUtils.isEmpty(list)) { if (!CollectionUtils.isEmpty(list)) {
//遍历指标分组 计算分数 //如果是第一页且仅有一条数据 则直接给50分
List<Map<String, Object>> finalList = list; if (pageNo == NumConstant.ONE && list.size() == NumConstant.ONE) {
groupIndexDetailsMap.forEach((parentIndexCode, details) -> { List<CpcScoreEntity> insertList = new ArrayList<>();
calculateScore(formDTO, details, finalList, minAndMaxMap, parentIndexCode); for (String parentIndexCode : groupIndexDetailsMap.keySet()) {
}); insertList.add(handleOneGridScene(formDTO, parentIndexCode, list.get(0)));
}
if (CollectionUtils.isEmpty(insertList)) {
deleteAndInsertBatch(formDTO, insertList, null);
}
} else {
//遍历指标分组 计算分数
for (Map.Entry<String, List<IndexGroupDetailEntity>> entry : groupIndexDetailsMap.entrySet()) {
String parentIndexCode = entry.getKey();
List<IndexGroupDetailEntity> details = entry.getValue();
calculateScore(formDTO, details, list, minAndMaxMap, parentIndexCode);
}
}
} }
} while (!CollectionUtils.isEmpty(list) && pageNo++ > 0); pageNo++;
} while (!CollectionUtils.isEmpty(list) && list.size() == pageSize);
} }
/** /**
@ -185,7 +228,7 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
log.info("计算的结果:{}", result); log.info("计算的结果:{}", result);
//处理结果 //处理结果
if (CollectionUtils.isEmpty(result)){ if (CollectionUtils.isEmpty(result)) {
log.error("calculateScore calculateScore return empty"); log.error("calculateScore calculateScore return empty");
return; return;
} }
@ -209,7 +252,7 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
cpcScoreEntity.setScore(score); cpcScoreEntity.setScore(score);
list.add(cpcScoreEntity); list.add(cpcScoreEntity);
}); });
this.deleteAndInsertBatch(formDTO.getCustomerId(),formDTO.getMonthId(),parentIndexCode,list); this.deleteAndInsertBatch(formDTO, list, parentIndexCode);
} }
@ -242,7 +285,7 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
minValue = new BigDecimal(String.valueOf(minAndMaxMap.get(minValueKey))); minValue = new BigDecimal(String.valueOf(minAndMaxMap.get(minValueKey)));
//如果最大值超过阈值 则最大值为阈值 //如果最大值超过阈值 则最大值为阈值
if (new BigDecimal(NumConstant.ONE_NEG).compareTo(index.getThreshold()) != NumConstant.ZERO if (new BigDecimal(NumConstant.ONE_NEG).compareTo(index.getThreshold()) != NumConstant.ZERO
&& maxValue.compareTo(new BigDecimal(NumConstant.ONE_NEG)) == NumConstant.ONE){ && maxValue.compareTo(new BigDecimal(NumConstant.ONE_NEG)) == NumConstant.ONE) {
maxValue = index.getThreshold(); maxValue = index.getThreshold();
} }
//分值计算器 //分值计算器

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

@ -3,6 +3,16 @@
<mapper namespace="com.epmet.dao.evaluationindex.indexcal.CpcScoreDao"> <mapper namespace="com.epmet.dao.evaluationindex.indexcal.CpcScoreDao">
<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>
</delete>
<resultMap type="com.epmet.entity.evaluationindex.indexcal.CpcScoreEntity" id="cpcScoreMap"> <resultMap type="com.epmet.entity.evaluationindex.indexcal.CpcScoreEntity" id="cpcScoreMap">
<result property="id" column="ID"/> <result property="id" column="ID"/>
<result property="customerId" column="CUSTOMER_ID"/> <result property="customerId" column="CUSTOMER_ID"/>
@ -18,14 +28,6 @@
<result property="updatedTime" column="UPDATED_TIME"/> <result property="updatedTime" column="UPDATED_TIME"/>
</resultMap> </resultMap>
<delete id="deleteByMonthId">
delete from fact_index_cpc_score
where
CUSTOMER_ID = #{customerId,jdbcType=VARCHAR}
and MONTH_ID = #{monthId,jdbcType=VARCHAR}
and INDEX_CODE = #{indexCode,jdbcType=VARCHAR}
</delete>
<select id="getPartScore" resultType="com.epmet.entity.evaluationindex.indexcal.CpcScoreEntity"> <select id="getPartScore" resultType="com.epmet.entity.evaluationindex.indexcal.CpcScoreEntity">
select select
CUSTOMER_ID,AGENCY_ID,GRID_ID,YEAR_ID,MONTH_ID,USER_ID,SCORE,INDEX_CODE FROM fact_index_cpc_score CUSTOMER_ID,AGENCY_ID,GRID_ID,YEAR_ID,MONTH_ID,USER_ID,SCORE,INDEX_CODE FROM fact_index_cpc_score

Loading…
Cancel
Save