Browse Source

计算党员的

dev
jianjun 5 years ago
parent
commit
be6217395d
  1. 2
      epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/constant/IndexCalConstant.java
  2. 5
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/indexcoll/FactIndexPartyAblityCpcMonthlyDao.java
  3. 152
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java
  4. 2
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexCalculateServiceImpl.java
  5. 74
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/indexcoll/FactIndexPartyAblityCpcMonthlyDao.xml

2
epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/constant/IndexCalConstant.java

@ -15,4 +15,6 @@ public interface IndexCalConstant {
String CUSTOMER_ID="CUSTOMER_ID";
String MONTH_ID="MONTH_ID";
String USER_ID="USER_ID";
}

5
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/indexcoll/FactIndexPartyAblityCpcMonthlyDao.java

@ -23,7 +23,6 @@ import com.epmet.entity.indexcoll.FactIndexPartyAblityCpcMonthlyEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
@ -70,7 +69,7 @@ public interface FactIndexPartyAblityCpcMonthlyDao extends BaseDao<FactIndexPart
void batchInsertFactIndexPartyAblityCpcMonthly(@Param("list") List<GridPartyMemberDataFormDTO> list,
@Param("customerId") String customerId);
Map<String,BigDecimal> getCountByMonthId(@Param("customerId") String customerId, @Param("monthId") String monthId);
List<Map<String, Object>> getCountByMonthId(@Param("customerId") String customerId, @Param("monthId") String monthId, @Param("offset") Integer offset, @Param("pageSize") Integer pageSize);
Map<String, BigDecimal> getExtremeValue(@Param("customerId") String customerId);
Map<String, Object> getExtremeValue(@Param("customerId") String customerId);
}

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

@ -1,6 +1,7 @@
package com.epmet.service.indexcal.impl;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.constant.IndexCalConstant;
import com.epmet.dao.indexcoll.FactIndexPartyAblityCpcMonthlyDao;
import com.epmet.dao.screen.IndexCodeFieldReDao;
import com.epmet.dto.indexcal.CalculateCommonFormDTO;
@ -9,14 +10,24 @@ import com.epmet.eum.IndexCodeEnum;
import com.epmet.service.indexcal.CpcIndexCalculateService;
import com.epmet.service.indexcal.IndexCodeFieldReService;
import com.epmet.service.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.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
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.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@Service
@ -29,35 +40,144 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
private IndexGroupDetailService getDetailListByParentCode;
@Autowired
private IndexCodeFieldReService indexCodeFieldReService;
@Override
public Boolean cpcIndexCalculate(CalculateCommonFormDTO formDTO) {
//计算最大最小值
Map<String, BigDecimal> minAndMaxList = factIndexPartyAblityCpcMonthlyDao.getExtremeValue(formDTO.getCustomerId());
if (CollectionUtils.isEmpty(minAndMaxList)){
log.warn("cpcIndexCalculate customerId:{} have not any fact record",formDTO.getCustomerId());
return false;
}
//获取指标权重信息
//获取指标权重信息 -参与议事
List<IndexGroupDetailEntity> indexDetails = getDetailListByParentCode.getDetailListByParentCode(formDTO.getCustomerId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(), IndexCodeEnum.CAN_YU_YI_SHI.getCode());
if (CollectionUtils.isEmpty(indexDetails)) {
log.warn("cpcIndexCalculate customerId:{} have not any indexGroupDetail", formDTO.getCustomerId());
return false;
}
canyuyishi(formDTO, indexDetails);
//log.info(JSON.toJSONString(minAndMaxList));
return null;
}
private void canyuyishi(CalculateCommonFormDTO formDTO, List<IndexGroupDetailEntity> indexDetails) {
Map<String, String> indexCodeFieldReList = indexCodeFieldReService.getIndexCodeFieldReMap();
if (CollectionUtils.isEmpty(indexCodeFieldReList)) {
log.warn("cpcIndexCalculate have any indexcodefieldre");
return false;
log.error("cpcIndexCalculate have any indexcodefieldre");
return;
}
//计算最大最小值
Map<String, Object> minAndMaxMap = factIndexPartyAblityCpcMonthlyDao.getExtremeValue(formDTO.getCustomerId());
if (CollectionUtils.isEmpty(minAndMaxMap)) {
log.warn("cpcIndexCalculate getExtremeValue customerId:{} have not any fact record", formDTO.getCustomerId());
return;
}
String indexCode = null;
//指标集合
Map<String, IndexInputVO<BigDecimal>> indexMap = getIndexInputVO(indexDetails, minAndMaxMap);
List<Map<String, Object>> list = null;
int pageNo = 1;
int pageSize = 10;
do {
String fieldName = null;
for (IndexGroupDetailEntity indexDetail : indexDetails) {
indexCode = indexDetail.getIndexCode();
list = factIndexPartyAblityCpcMonthlyDao.getCountByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), (pageNo - 1) * pageSize, pageSize);
if (!CollectionUtils.isEmpty(list)) {
//遍历指标 进行计算
for (Map.Entry<String, IndexInputVO<BigDecimal>> entry : indexMap.entrySet()) {
String indexCode = entry.getKey();
IndexInputVO<BigDecimal> value = entry.getValue();
fieldName = indexCodeFieldReService.getFieldNameByIndexCode(indexCode);
if (StringUtils.isBlank(fieldName)) {
log.error("cpcIndexCalculate fieldName error");
continue;
}
for (Map<String, Object> cpcIndex : list) {
//对应的数值
String sampleValueStr = String.valueOf(cpcIndex.get(indexCodeFieldReService.getFieldNameByIndexCode(fieldName)));
//构造样本值对象
SampleValue<BigDecimal> currentGridIndexValue = new SampleValue((String) cpcIndex.get(IndexCalConstant.USER_ID), new BigDecimal(sampleValueStr));
value.getIndexValueVOs().add(currentGridIndexValue);
}
}
}
log.info(JSON.toJSONString(minAndMaxList));
Map<String, BigDecimal> list = factIndexPartyAblityCpcMonthlyDao.getCountByMonthId(formDTO.getCustomerId(), formDTO.getMonthId());
return null;
List<IndexOutputVO> result = calculate(indexMap);
// TODO 处理结果
saveGridCorreLationDangJian(formDTO, indexDetails, result);
try {
for (IndexOutputVO m : result) {
log.info("indexId=" + m.getIndexId());
for (SampleScore sampleScore : m.getIndexScoreVOs()) {
log.info(String.format("网格id:%s,得分:%s", sampleScore.getSampleId(), sampleScore.getSampleScore()));
}
}
} catch (Exception e) {
}
} while (!CollectionUtils.isEmpty(list) && pageNo++ > 0);
}
@Transactional(rollbackFor = Exception.class)
public void saveGridCorreLationDangJian(CalculateCommonFormDTO formDTO, List<IndexGroupDetailEntity> indexDetails, List<IndexOutputVO> result) {
}
/**
* @param indexMap
* @return java.util.List<com.epmet.support.normalizing.batch.IndexOutputVO>
* @author yinzuomei
* @description
* @Date 2020/8/30 21:40
**/
private List<IndexOutputVO> calculate(Map<String, IndexInputVO<BigDecimal>> indexMap) {
//构造入参
List<IndexInputVO> indexInputVOS = indexMap.values().stream().collect(Collectors.toList());
BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator();
return batchScoreCalculator.getScoreDetailOfIndexId(indexInputVOS);
}
/**
* @param indexList 指标集合
* @param minAndMaxMap 最大值最小值集合
* @return java.util.Map<java.lang.String, com.epmet.support.normalizing.batch.IndexInputVO>
* @author yinzuomei
* @description
* @Date 2020/8/30 15:56
**/
private Map<String, IndexInputVO<BigDecimal>> getIndexInputVO(List<IndexGroupDetailEntity> indexList, Map<String, Object> minAndMaxMap) {
Map<String, IndexInputVO<BigDecimal>> map = new HashMap<>();
for (int indexNum = 0; indexNum < indexList.size(); indexNum++) {
IndexGroupDetailEntity index = indexList.get(indexNum);
IndexInputVO indexInputVO = new IndexInputVO();
// 指标code
indexInputVO.setIndexId(index.getIndexCode());
//权重
indexInputVO.setWeight(index.getWeight());
BigDecimal minValue = null;
BigDecimal maxValue = null;
//获取指标对应的列名
String fieldName = indexCodeFieldReService.getFieldNameByIndexCode(index.getIndexCode());
//最小值key
String minValueKey = fieldName.concat(StrConstant.UNDER_LINE).concat(StrConstant.MIN);
//最大值key
String maxValueKey = fieldName.concat(StrConstant.UNDER_LINE).concat(StrConstant.MAX);
minValue = new BigDecimal(String.valueOf(minAndMaxMap.get(minValueKey)));
maxValue = new BigDecimal(String.valueOf(minAndMaxMap.get(maxValueKey)));
//分值计算器
ScoreCalculator<Integer> scoreCalculator = new BigDecimalScoreCalculator(minValue,
maxValue,
ScoreConstants.MIN_SCORE,
ScoreConstants.MAX_SCORE,
Correlation.getCorrelation(index.getCorrelation())
);
indexInputVO.setScoreCalculator(scoreCalculator);
List<SampleValue<BigDecimal>> sampleValueList = new ArrayList<>();
indexInputVO.setIndexValueVOs(sampleValueList);
map.put(index.getIndexCode(), indexInputVO);
}
return map;
}
}

2
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexCalculateServiceImpl.java

@ -58,7 +58,7 @@ public class IndexCalculateServiceImpl implements IndexCalculateService {
CalculateCommonFormDTO calculateCommonFormDTO=new CalculateCommonFormDTO(customerId, formDTO.getMonthId());
//计算党员
try {
Map<String, BigDecimal> list = factIndexPartyAblityCpcMonthlyDao.getCountByMonthId(customerId, formDTO.getMonthId());
Map<String, BigDecimal> list = factIndexPartyAblityCpcMonthlyDao.getCountByMonthId(customerId, formDTO.getMonthId(), (pageNo - 1) * pageSize, pageSize);
} catch (Exception e) {
}

74
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/indexcoll/FactIndexPartyAblityCpcMonthlyDao.xml

@ -3,33 +3,6 @@
<mapper namespace="com.epmet.dao.indexcoll.FactIndexPartyAblityCpcMonthlyDao">
<resultMap type="com.epmet.entity.indexcoll.FactIndexPartyAblityCpcMonthlyEntity" id="factIndexPartyAblityCpcMonthlyMap">
<result property="id" column="ID"/>
<result property="customerId" column="CUSTOMER_ID"/>
<result property="agencyId" column="AGENCY_ID"/>
<result property="parentId" column="PARENT_ID"/>
<result property="gridId" column="GRID_ID"/>
<result property="monthId" column="MONTH_ID"/>
<result property="quarterId" column="QUARTER_ID"/>
<result property="yearId" column="YEAR_ID"/>
<result property="createTopicCount" column="CREATE_TOPIC_COUNT"/>
<result property="joinTopicCount" column="JOIN_TOPIC_COUNT"/>
<result property="shiftIssueCount" column="SHIFT_ISSUE_COUNT"/>
<result property="shiftProjectCount" column="SHIFT_PROJECT_COUNT"/>
<result property="joinThreeMeetsCount" column="JOIN_THREE_MEETS_COUNT"/>
<result property="groupUserCount" column="GROUP_USER_COUNT"/>
<result property="groupTopicCount" column="GROUP_TOPIC_COUNT"/>
<result property="topicToIssueRatio" column="TOPIC_TO_ISSUE_RATIO"/>
<result property="groupActiveUserCount" column="GROUP_ACTIVE_USER_COUNT"/>
<result property="delFlag" column="DEL_FLAG"/>
<result property="revision" column="REVISION"/>
<result property="createdBy" column="CREATED_BY"/>
<result property="createdTime" column="CREATED_TIME"/>
<result property="updatedBy" column="UPDATED_BY"/>
<result property="updatedTime" column="UPDATED_TIME"/>
<result property="userId" column="USER_ID"/>
</resultMap>
<delete id="deleteFactIndexPartyAblityCpcMonthly">
delete from fact_index_party_ablity_cpc_monthly
where CUSTOMER_ID = #{customerId} AND AGENCY_ID = #{agencyId} AND GRID_ID = #{gridId} AND USER_ID = #{userId}
@ -94,27 +67,7 @@
</foreach>
</insert>
<select id="getCountByMonthId" resultType="java.util.Map">
SELECT
CUSTOMER_ID,
AGENCY_ID,
PARENT_ID,
GRID_ID,
CREATE_TOPIC_COUNT,
JOIN_TOPIC_COUNT,
SHIFT_ISSUE_COUNT,
SHIFT_PROJECT_COUNT,
JOIN_THREE_MEETS_COUNT,
GROUP_USER_COUNT,
GROUP_TOPIC_COUNT,
TOPIC_TO_ISSUE_RATIO,
GROUP_ACTIVE_USER_COUNT
FROM
fact_index_party_ablity_cpc_monthly
WHERE
CUSTOMER_ID = #{customerId,jdbcType=VARCHAR}
AND MONTH_ID = #{monthId,jdbcType=VARCHAR}
</select>
<select id="getExtremeValue" resultType="java.util.Map">
SELECT
@ -142,4 +95,29 @@
CUSTOMER_ID = #{customerId,jdbcType=VARCHAR} AND DEL_FLAG = '0'
</select>
<select id="getCountByMonthId" resultType="java.util.Map">
SELECT
CUSTOMER_ID,
AGENCY_ID,
PARENT_ID,
GRID_ID,
USER_ID,
CREATE_TOPIC_COUNT,
JOIN_TOPIC_COUNT,
SHIFT_ISSUE_COUNT,
SHIFT_PROJECT_COUNT,
JOIN_THREE_MEETS_COUNT,
GROUP_USER_COUNT,
GROUP_TOPIC_COUNT,
TOPIC_TO_ISSUE_RATIO,
GROUP_ACTIVE_USER_COUNT
FROM
fact_index_party_ablity_cpc_monthly
WHERE
CUSTOMER_ID = #{customerId,jdbcType=VARCHAR}
AND MONTH_ID = #{monthId,jdbcType=VARCHAR}
LIMIT #{offset},#{pageSize}
</select>
</mapper>

Loading…
Cancel
Save