Browse Source

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

master
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. 71
      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.IndexGroupDetailTemplateService;
import com.epmet.service.evaluationindex.screen.IndexGroupTemplateService;
import com.epmet.support.normalizing.Correlation;
import com.epmet.util.Pinyin4jUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@ -29,7 +30,6 @@ import java.util.stream.Collectors;
*/
public class IndexExcelDataListener extends AnalysisEventListener<IndexModel> {
private static final Logger LOGGER = LoggerFactory.getLogger(IndexExcelDataListener.class);
private String POSITIVE = "positive";
/**
* 每隔5条存储数据库实际使用中可以3000条然后清理list 方便内存回收
*/
@ -86,8 +86,23 @@ public class IndexExcelDataListener extends AnalysisEventListener<IndexModel> {
data.setWeight(preWheight);
}
LOGGER.info("解析到一条数据:{}", JSON.toJSONString(data));
//TODO 默认正相关
data.setCorrelation(POSITIVE);
if (StringUtils.isNotBlank(data.getThreshold())) {
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 entity2 = new IndexDictEntity();
@ -240,11 +255,8 @@ public class IndexExcelDataListener extends AnalysisEventListener<IndexModel> {
templateEntity.setIndexCode(Pinyin4jUtil.getSpellPinYin(indexDictEntity.getIndexName(), false, 4));
templateEntity.setWeight(new BigDecimal(index.getWeight()).divide(new BigDecimal(100), 4, RoundingMode.HALF_UP));
}
if (StringUtils.isNotBlank(index.getThreshold())) {
String thresholdStr = index.getThreshold().replace("%", "");
templateEntity.setThreshold(new BigDecimal(thresholdStr).divide(new BigDecimal(100), 4, RoundingMode.HALF_UP));
}
templateEntity.setThreshold(new BigDecimal(index.getThreshold()));
templateEntity.setCorrelation(index.getCorrelation());
}
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;
@ExcelProperty(value = "五级权重")
private String level5Weight;
//没有阈值:无,有就是百分数
@ExcelProperty(value = "阈值")
private String threshold;
/**

71
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.dao.evaluationindex.indexcal.CpcScoreDao;
import com.epmet.dao.evaluationindex.indexcoll.FactIndexPartyAblityCpcMonthlyDao;
import com.epmet.dao.evaluationindex.screen.IndexCodeFieldReDao;
import com.epmet.dto.indexcal.CalculateCommonFormDTO;
import com.epmet.entity.evaluationindex.indexcal.CpcScoreEntity;
import com.epmet.entity.evaluationindex.indexcoll.FactIndexPartyAblityCpcMonthlyEntity;
import com.epmet.entity.evaluationindex.screen.IndexGroupDetailEntity;
import com.epmet.eum.IndexCodeEnum;
import com.epmet.service.evaluationindex.indexcal.CpcIndexCalculateService;
@ -43,8 +43,6 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
@Autowired
private FactIndexPartyAblityCpcMonthlyDao factIndexPartyAblityCpcMonthlyDao;
@Autowired
private IndexCodeFieldReDao indexCodeFieldReDao;
@Autowired
private IndexGroupDetailService getDetailListByParentCode;
@Autowired
private IndexCodeFieldReService indexCodeFieldReService;
@ -97,11 +95,43 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
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);
}
@ -119,20 +149,33 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
return;
}
int pageNo = 1;
int pageSize = 10;
int pageNo = NumConstant.ONE;
int pageSize = NumConstant.ONE_THOUSAND;
//分页查询 要计算的原始数据
List<Map<String, Object>> list = null;
do {
list = factIndexPartyAblityCpcMonthlyDao.getCountByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), (pageNo - 1) * pageSize, pageSize);
if (!CollectionUtils.isEmpty(list)) {
//如果是第一页且仅有一条数据 则直接给50分
if (pageNo == NumConstant.ONE && list.size() == NumConstant.ONE) {
List<CpcScoreEntity> insertList = new ArrayList<>();
for (String parentIndexCode : groupIndexDetailsMap.keySet()) {
insertList.add(handleOneGridScene(formDTO, parentIndexCode, list.get(0)));
}
if (CollectionUtils.isEmpty(insertList)) {
deleteAndInsertBatch(formDTO, insertList, null);
}
} else {
//遍历指标分组 计算分数
List<Map<String, Object>> finalList = list;
groupIndexDetailsMap.forEach((parentIndexCode, details) -> {
calculateScore(formDTO, details, finalList, minAndMaxMap, parentIndexCode);
});
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);
}
/**
@ -209,7 +252,7 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
cpcScoreEntity.setScore(score);
list.add(cpcScoreEntity);
});
this.deleteAndInsertBatch(formDTO.getCustomerId(),formDTO.getMonthId(),parentIndexCode,list);
this.deleteAndInsertBatch(formDTO, list, parentIndexCode);
}

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">
<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">
<result property="id" column="ID"/>
<result property="customerId" column="CUSTOMER_ID"/>
@ -18,14 +28,6 @@
<result property="updatedTime" column="UPDATED_TIME"/>
</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
CUSTOMER_ID,AGENCY_ID,GRID_ID,YEAR_ID,MONTH_ID,USER_ID,SCORE,INDEX_CODE FROM fact_index_cpc_score

Loading…
Cancel
Save