Browse Source

代码暂存

dev
jianjun 5 years ago
parent
commit
180053a363
  1. 2
      epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/constant/IndexCalConstant.java
  2. 2
      epmet-module/data-statistical/data-statistical-server/pom.xml
  3. 2
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java
  4. 5
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/indexscore/CpcScoreDao.java
  5. 35
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/indexscore/CpcScoreEntity.java
  6. 158
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java
  7. 3
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/util/Pinyin4jUtil.java
  8. 15
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/indexscore/CpcScoreDao.xml
  9. 6
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/screen/IndexGroupDetailDao.xml

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

@ -12,6 +12,8 @@ public interface IndexCalConstant {
String GRID_ID="GRID_ID";
String AGENCY_ID="AGENCY_ID";
String CUSTOMER_ID="CUSTOMER_ID";
String MONTH_ID="MONTH_ID";

2
epmet-module/data-statistical/data-statistical-server/pom.xml

@ -195,7 +195,7 @@
<spring.redis.port>6379</spring.redis.port>
<spring.redis.password>123456</spring.redis.password>
<!-- nacos -->
<nacos.register-enabled>true</nacos.register-enabled>
<nacos.register-enabled>false</nacos.register-enabled>
<nacos.server-addr>192.168.1.130:8848</nacos.server-addr>
<nacos.discovery.namespace>6ceab336-d004-4acf-89c6-e121d06f4988</nacos.discovery.namespace>
<nacos.config.namespace></nacos.config.namespace>

2
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java

@ -44,7 +44,7 @@ public class IndexCalculateController {
}
@PostMapping("getMax")
public Result getMax(){
CalculateCommonFormDTO calculateCommonFormDTO = new CalculateCommonFormDTO("c1","202008");
CalculateCommonFormDTO calculateCommonFormDTO = new CalculateCommonFormDTO("b09527201c4409e19d1dbc5e3c3429a1","202008");
cpcIndexCalculateService.cpcIndexCalculate(calculateCommonFormDTO);
return new Result();
}

5
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/indexscore/CpcScoreDao.java

@ -25,6 +25,7 @@ import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
/**
* 党员相关分值
@ -76,4 +77,8 @@ public interface CpcScoreDao extends BaseDao<CpcScoreEntity> {
* @Date 2020/8/31 15:51
**/
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);
List<Map<String, Object>> getPartScoreByPage(@Param("customerId") String customerId, @Param("monthId") String monthId, @Param("offset") int offset, @Param("pageSize") int pageSize);
}

35
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/indexscore/CpcScoreEntity.java

@ -18,13 +18,11 @@
package com.epmet.entity.indexscore;
import com.baomidou.mybatisplus.annotation.TableName;
import com.epmet.commons.mybatis.entity.BaseEpmetEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
import java.util.Date;
/**
* 党员相关分值
@ -54,34 +52,29 @@ public class CpcScoreEntity extends BaseEpmetEntity {
*/
private String gridId;
/**
* 用户id
*/
private String userId;
/**
* 维度Id: yyyyMM
* 年维度Id: yyyy
*/
private String monthId;
private String yearId;
/**
* 党建能力分值
*/
private BigDecimal partyAblityScore;
/**
* 月维度Id: yyyyMM
*/
private String monthId;
/**
* 参与议事分值
*/
private BigDecimal joinIssueScore;
/**
* 用户id
*/
private String userId;
/**
* 党务活动分值
* 分值
*/
private BigDecimal partyWorkActScore;
private BigDecimal score;
/**
* 联系群众分值
* 指标code
*/
private BigDecimal contactMassesScore;
private String indexCode;
}

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

@ -1,11 +1,13 @@
package com.epmet.service.indexcal.impl;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.constant.IndexCalConstant;
import com.epmet.dao.indexcoll.FactIndexPartyAblityCpcMonthlyDao;
import com.epmet.dao.indexscore.CpcScoreDao;
import com.epmet.dao.screen.IndexCodeFieldReDao;
import com.epmet.dto.indexcal.CalculateCommonFormDTO;
import com.epmet.entity.indexscore.CpcScoreEntity;
import com.epmet.entity.screen.IndexGroupDetailEntity;
import com.epmet.eum.IndexCodeEnum;
import com.epmet.service.indexcal.CpcIndexCalculateService;
@ -18,6 +20,7 @@ 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 com.epmet.util.DimIdGenerator;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -26,10 +29,7 @@ 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.*;
import java.util.stream.Collectors;
@Slf4j
@ -43,24 +43,53 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
private IndexGroupDetailService getDetailListByParentCode;
@Autowired
private IndexCodeFieldReService indexCodeFieldReService;
@Autowired
private CpcScoreDao cpcScoreDao;
@Override
public Boolean cpcIndexCalculate(CalculateCommonFormDTO formDTO) {
//获取指标权重信息 -参与议事
List<IndexGroupDetailEntity> indexDetails = getDetailListByParentCode.getDetailListLikeParentCode(formDTO.getCustomerId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode());
if (CollectionUtils.isEmpty(indexDetails)) {
calculatePartScore(formDTO);
calculateTotalScore(formDTO);
return null;
}
/**
* desc: 计算总分
* @param formDTO
*/
private void calculateTotalScore(CalculateCommonFormDTO formDTO) {
//获取指标权重
List<IndexGroupDetailEntity> parentIndexDetails = getDetailListByParentCode.getDetailListByParentCode(formDTO.getCustomerId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode());
if (CollectionUtils.isEmpty(parentIndexDetails)) {
log.warn("cpcIndexCalculate customerId:{} have not any indexGroupDetail", formDTO.getCustomerId());
return false;
return;
}
//获取数据
List<Map<String, Object>> list = null;
int pageNo = 1;
int pageSize = 10;
do {
canyuyishi(formDTO, indexDetails);
list = cpcScoreDao.getPartScoreByPage(formDTO.getCustomerId(), formDTO.getMonthId(), (pageNo - 1) * pageSize, pageSize);
if (!CollectionUtils.isEmpty(list)) {
list.forEach(partScore->{
partScore.get(IndexCalConstant.USER_ID)
});
//遍历指标分组 计算分数
List<Map<String, Object>> finalList = list;
groupIndexDetailsMap.forEach((parentIndexCode, details) -> {
calculate(formDTO, details, finalList, minAndMaxMap, parentIndexCode);
});
}
} while (!CollectionUtils.isEmpty(list) && pageNo++ > 0);
//log.info(JSON.toJSONString(minAndMaxList));
return null;
}
private void canyuyishi(CalculateCommonFormDTO formDTO, List<IndexGroupDetailEntity> indexDetails) {
private void calculatePartScore(CalculateCommonFormDTO formDTO) {
Map<String, String> indexCodeFieldReList = indexCodeFieldReService.getIndexCodeFieldReMap();
if (CollectionUtils.isEmpty(indexCodeFieldReList)) {
log.error("cpcIndexCalculate have any indexcodefieldre");
@ -74,9 +103,29 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
}
//指标集合
//对指标进行分组
Map<String, List<IndexGroupDetailEntity>> groupIndexDetailsMap = indexDetails.stream().collect(Collectors.groupingBy(IndexGroupDetailEntity::getAllParentIndexCode));
//Map<String, List<IndexGroupDetailEntity>> groupIndexDetailsMap = indexDetails.stream().collect(Collectors.groupingBy(IndexGroupDetailEntity::getAllParentIndexCode));
//获取指标权重信息 -参与议事
List<IndexGroupDetailEntity> canyuyishiIndexDetails = getDetailListByParentCode.getDetailListByParentCode(formDTO.getCustomerId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(), IndexCodeEnum.CAN_YU_YI_SHI.getCode());
if (CollectionUtils.isEmpty(canyuyishiIndexDetails)) {
log.warn("cpcIndexCalculate customerId:{} have not any indexGroupDetail", formDTO.getCustomerId());
return;
}
List<IndexGroupDetailEntity> dangwuhongdongIndexDetails = getDetailListByParentCode.getDetailListByParentCode(formDTO.getCustomerId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(), IndexCodeEnum.DANG_WU_HUO_DONG.getCode());
if (CollectionUtils.isEmpty(canyuyishiIndexDetails)) {
log.warn("cpcIndexCalculate customerId:{} have not any indexGroupDetail", formDTO.getCustomerId());
return;
}
List<IndexGroupDetailEntity> lianxiqunzhongIndexDetails = getDetailListByParentCode.getDetailListByParentCode(formDTO.getCustomerId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(), IndexCodeEnum.LIAN_XI_QUN_ZHONG.getCode());
if (CollectionUtils.isEmpty(canyuyishiIndexDetails)) {
log.warn("cpcIndexCalculate customerId:{} have not any indexGroupDetail", formDTO.getCustomerId());
return;
}
Map<String, List<IndexGroupDetailEntity>> groupIndexDetailsMap = new HashMap<>();
groupIndexDetailsMap.put(IndexCodeEnum.CAN_YU_YI_SHI.getCode(), canyuyishiIndexDetails);
groupIndexDetailsMap.put(IndexCodeEnum.DANG_WU_HUO_DONG.getCode(), dangwuhongdongIndexDetails);
groupIndexDetailsMap.put(IndexCodeEnum.LIAN_XI_QUN_ZHONG.getCode(), lianxiqunzhongIndexDetails);
List<Map<String, Object>> list = null;
int pageNo = 1;
@ -87,42 +136,65 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
//遍历指标分组 计算分数
List<Map<String, Object>> finalList = list;
groupIndexDetailsMap.forEach((parentIndex, indexDetailList)->{
Map<String, IndexInputVO<BigDecimal>> indexMap = getIndexInputVO(indexDetailList, minAndMaxMap);
//遍历指标 进行计算
for (Map.Entry<String, IndexInputVO<BigDecimal>> entry : indexMap.entrySet()) {
String indexCode = entry.getKey();
IndexInputVO<BigDecimal> value = entry.getValue();
String fieldName = indexCodeFieldReService.getFieldNameByIndexCode(indexCode);
if (StringUtils.isBlank(fieldName)) {
log.error("cpcIndexCalculate fieldName error");
continue;
}
for (Map<String, Object> cpcIndex : finalList) {
//对应的数值
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);
}
}
HashMap<String, BigDecimal> result = calculate(indexMap);
// TODO 处理结果
saveGridCorreLationDangJian(formDTO, indexDetails, result);
try {
System.out.println( JSON.toJSONString(result));
} catch (Exception e) {
}
groupIndexDetailsMap.forEach((parentIndexCode, details) -> {
calculate(formDTO, details, finalList, minAndMaxMap, parentIndexCode);
});
}
} while (!CollectionUtils.isEmpty(list) && pageNo++ > 0);
}
@Transactional(rollbackFor = Exception.class)
public void saveGridCorreLationDangJian(CalculateCommonFormDTO formDTO, List<IndexGroupDetailEntity> indexDetails, HashMap<String, BigDecimal> result) {
private void calculate(CalculateCommonFormDTO formDTO, List<IndexGroupDetailEntity> indexDetailList, List<Map<String, Object>> finalList, Map<String, Object> minAndMaxMap, String parentIndexCode) {
Map<String, IndexInputVO<BigDecimal>> indexMap = getIndexInputVO(indexDetailList, minAndMaxMap);
Map<String, CpcScoreEntity> scoreEntityMap = new HashMap<>();
//遍历指标 进行计算
for (Map.Entry<String, IndexInputVO<BigDecimal>> entry : indexMap.entrySet()) {
String indexCode = entry.getKey();
IndexInputVO<BigDecimal> value = entry.getValue();
String fieldName = indexCodeFieldReService.getFieldNameByIndexCode(indexCode);
if (StringUtils.isBlank(fieldName)) {
log.error("cpcIndexCalculate fieldName error");
continue;
}
for (Map<String, Object> cpcCount : finalList) {
//对应的数值
String userId = String.valueOf(cpcCount.get(IndexCalConstant.USER_ID));
String sampleValueStr = String.valueOf(cpcCount.get(fieldName));
CpcScoreEntity cpcScoreEntity = new CpcScoreEntity();
cpcScoreEntity.setYearId(DimIdGenerator.getYearDimId(DateUtils.addDateMonths(new Date(), -1)));
cpcScoreEntity.setCustomerId(formDTO.getCustomerId());
cpcScoreEntity.setAgencyId(String.valueOf(cpcCount.get(IndexCalConstant.AGENCY_ID)));
cpcScoreEntity.setGridId(String.valueOf(cpcCount.get(IndexCalConstant.GRID_ID)));
cpcScoreEntity.setUserId(userId);
cpcScoreEntity.setMonthId(formDTO.getMonthId());
cpcScoreEntity.setScore(new BigDecimal(0));
cpcScoreEntity.setIndexCode(parentIndexCode);
scoreEntityMap.put(userId, cpcScoreEntity);
//构造样本值对象
SampleValue<BigDecimal> currentGridIndexValue = new SampleValue((String) cpcCount.get(IndexCalConstant.USER_ID), new BigDecimal(sampleValueStr));
value.getIndexValueVOs().add(currentGridIndexValue);
}
}
log.warn("计算的参数:{}", indexMap);
HashMap<String, BigDecimal> result = calculate(indexMap);
//处理结果
saveCpcScore(formDTO, scoreEntityMap, parentIndexCode, result);
}
@Transactional(rollbackFor = Exception.class)
public void saveCpcScore(CalculateCommonFormDTO formDTO, Map<String, CpcScoreEntity> indexDetails, String parentIndexCode, HashMap<String, BigDecimal> result) {
cpcScoreDao.deleteByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), parentIndexCode);
result.forEach((userId, score) -> {
CpcScoreEntity cpcScoreEntity = indexDetails.get(userId);
cpcScoreEntity.setScore(score);
cpcScoreDao.insert(cpcScoreEntity);
});
}
/**

3
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/util/Pinyin4jUtil.java

@ -25,6 +25,8 @@ public class Pinyin4jUtil {
duoyinMap.put('率',new String[]{"lv"});
duoyinMap.put('员',new String[]{"yuan"});
duoyinMap.put('提',new String[]{"ti"});
duoyinMap.put('被',new String[]{"bei"});
duoyinMap.put('期',new String[]{"qi"});
}
/**
@ -192,5 +194,6 @@ public class Pinyin4jUtil {
public static void main(String[] args) {
System.out.println(getFirstSpellPinYin("区直部门",false));
System.out.println(getSpellPinYin("党员提出话题数",false,4));
System.out.println(getSpellPinYin("社区超期项目数",false,4));
}
}

15
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/indexscore/CpcScoreDao.xml

@ -10,10 +10,6 @@
<result property="gridId" column="GRID_ID"/>
<result property="userId" column="USER_ID"/>
<result property="monthId" column="MONTH_ID"/>
<result property="partyAblityScore" column="PARTY_ABLITY_SCORE"/>
<result property="joinIssueScore" column="JOIN_ISSUE_SCORE"/>
<result property="partyWorkActScore" column="PARTY_WORK_ACT_SCORE"/>
<result property="contactMassesScore" column="CONTACT_MASSES_SCORE"/>
<result property="delFlag" column="DEL_FLAG"/>
<result property="revision" column="REVISION"/>
<result property="createdBy" column="CREATED_BY"/>
@ -22,6 +18,17 @@
<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="getPartScoreByPage" resultType="java.util.Map">
select
CUSTOMER_ID,AGENCY_ID,GRID_ID,USER_ID,SCORE,INDEX_CODE FROM fact_index_cpc_score
WHERE
CUSTOMER_ID = #{customerId,jdbcType=VARCHAR} and MONTH_ID = #{monthId,jdbcType=VARCHAR} AND IS_TOTAL = '0'
</select>
<!-- 获取网格内党员的联系群众能力考评分(平均值) -->
<select id="selectGridContactMassesAvgValue" parameterType="map" resultType="java.math.BigDecimal">

6
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/screen/IndexGroupDetailDao.xml

@ -6,7 +6,7 @@
<select id="getDetailListByParentCode" resultType="com.epmet.entity.screen.IndexGroupDetailEntity">
select
ID, INDEX_GROUP_ID, INDEX_ID, INDEX_CODE, WEIGHT, THRESHOLD
ID,CUSTOMER_ID, INDEX_GROUP_ID, INDEX_ID, INDEX_CODE, WEIGHT, THRESHOLD, ALL_PARENT_INDEX_CODE
FROM index_group_detail
WHERE
CUSTOMER_ID = #{customerId,jdbcType=VARCHAR} and STATUS = 'enable' and DEL_FLAG = '0'
@ -15,10 +15,10 @@
<select id="getDetailListLikeParentCode" resultType="com.epmet.entity.screen.IndexGroupDetailEntity">
select
ID, INDEX_GROUP_ID, INDEX_ID, INDEX_CODE, WEIGHT, THRESHOLD
ID, CUSTOMER_ID, INDEX_GROUP_ID, INDEX_ID, INDEX_CODE, WEIGHT, THRESHOLD, ALL_PARENT_INDEX_CODE
FROM index_group_detail
WHERE
CUSTOMER_ID = #{customerId,jdbcType=VARCHAR} and STATUS = 'enable' and DEL_FLAG = '0'
and ALL_PARENT_INDEX_CODE like concat(#{indexCode,jdbcType=VARCHAR},'%')
and ALL_PARENT_INDEX_CODE like concat(#{parentIndexCode,jdbcType=VARCHAR},'%')
</select>
</mapper>
Loading…
Cancel
Save