Browse Source

计算党员总分

dev_shibei_match
jianjun 5 years ago
parent
commit
4ef2e4a0bd
  1. 13
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/indexscore/CpcScoreDao.java
  2. 5
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/indexscore/CpcScoreEntity.java
  3. 45
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java
  4. 46
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/indexscore/CpcScoreDao.xml

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

@ -24,6 +24,7 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
@ -36,10 +37,10 @@ import java.util.List;
public interface CpcScoreDao extends BaseDao<CpcScoreEntity> { public interface CpcScoreDao extends BaseDao<CpcScoreEntity> {
/** /**
* @return java.math.BigDecimal
* @param customerId * @param customerId
* @param monthId * @param monthId
* @param gridId * @param gridId
* @return java.math.BigDecimal
* @author yinzuomei * @author yinzuomei
* @description 获取网格内党员的联系群众能力考评分平均值 * @description 获取网格内党员的联系群众能力考评分平均值
* @Date 2020/8/31 10:56 * @Date 2020/8/31 10:56
@ -49,17 +50,17 @@ public interface CpcScoreDao extends BaseDao<CpcScoreEntity> {
@Param("gridId") String gridId); @Param("gridId") String gridId);
/** /**
* @return java.util.List<java.math.BigDecimal>
* @param formDTO * @param formDTO
* @return java.util.List<java.math.BigDecimal>
* @author yinzuomei * @author yinzuomei
* @description 获取网格内党员的联系群众能力考评分平均值的最大值最小值 * @description 获取网格内党员的联系群众能力考评分平均值的最大值最小值
* @Date 2020/8/31 12:10 * @Date 2020/8/31 12:10
**/ **/
List<BigDecimal> selectListGridContactMassesAvgValue(CalculateCommonFormDTO formDTO); List<BigDecimal> selectListGridContactMassesAvgValue(CalculateCommonFormDTO formDTO);
/** /**
* @return java.util.List<java.math.BigDecimal>
* @param calculateCommonFormDTO * @param calculateCommonFormDTO
* @return java.util.List<java.math.BigDecimal>
* @author yinzuomei * @author yinzuomei
* @description 网格内党员的参与议事能力考评分平均值 最大值最小值 * @description 网格内党员的参与议事能力考评分平均值 最大值最小值
* @Date 2020/8/31 14:42 * @Date 2020/8/31 14:42
@ -79,5 +80,7 @@ public interface CpcScoreDao extends BaseDao<CpcScoreEntity> {
int deleteByMonthId(@Param("customerId") String customerId, @Param("monthId") String monthId, @Param("indexCode") String indexCode); int deleteByMonthId(@Param("customerId") String customerId, @Param("monthId") String monthId, @Param("indexCode") String indexCode);
List<CpcScoreEntity> getPartScoreByPage(@Param("customerId") String customerId, @Param("monthId") String monthId, @Param("offset") int offset, @Param("pageSize") int pageSize); List<CpcScoreEntity> getPartScore(@Param("customerId") String customerId, @Param("monthId") String monthId);
int insertBatch(@Param("list") Collection<CpcScoreEntity> values);
} }

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

@ -77,4 +77,9 @@ public class CpcScoreEntity extends BaseEpmetEntity {
* 指标code * 指标code
*/ */
private String indexCode; private String indexCode;
/**
* 是否是总分 1是0不是
*/
private String isTotal;
} }

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

@ -1,6 +1,8 @@
package com.epmet.service.indexcal.impl; package com.epmet.service.indexcal.impl;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.StrConstant; import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.DateUtils; import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.constant.IndexCalConstant; import com.epmet.constant.IndexCalConstant;
import com.epmet.dao.indexcoll.FactIndexPartyAblityCpcMonthlyDao; import com.epmet.dao.indexcoll.FactIndexPartyAblityCpcMonthlyDao;
@ -53,12 +55,12 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
calculatePartScore(formDTO); calculatePartScore(formDTO);
calculateTotalScore(formDTO); calculateTotalScore(formDTO);
return true;
return null;
} }
/** /**
* desc: 计算总分 * desc: 计算总分
*
* @param formDTO * @param formDTO
*/ */
private void calculateTotalScore(CalculateCommonFormDTO formDTO) { private void calculateTotalScore(CalculateCommonFormDTO formDTO) {
@ -70,19 +72,35 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
} }
//获取数据 //获取数据
List<CpcScoreEntity> list = null; List<CpcScoreEntity> list = null;
int pageNo = 1; Map<String, CpcScoreEntity> cpcScoreTotalMap = new HashMap<>();
int pageSize = 10; Map<String, IndexGroupDetailEntity> indexWeightMap = parentIndexDetails.stream().collect(Collectors.toMap(IndexGroupDetailEntity::getIndexCode, o -> o));
do {
list = cpcScoreDao.getPartScore(formDTO.getCustomerId(), formDTO.getMonthId());
if (!CollectionUtils.isEmpty(list)) {
Map<String, List<CpcScoreEntity>> userGroupMap = list.stream().collect(Collectors.groupingBy(CpcScoreEntity::getUserId));
userGroupMap.forEach((userId, partScoreList) -> {
CpcScoreEntity totalEntity = null;
for (CpcScoreEntity part : partScoreList) {
IndexGroupDetailEntity indexGroupDetailEntity = indexWeightMap.get(part.getIndexCode());
if (totalEntity == null) {
totalEntity = ConvertUtils.sourceToTarget(part, CpcScoreEntity.class);
totalEntity.setIsTotal(NumConstant.ONE_STR);
totalEntity.setIndexCode(indexGroupDetailEntity.getIndexCode());
cpcScoreTotalMap.put(userId, totalEntity);
}
BigDecimal total = part.getScore().multiply(indexGroupDetailEntity.getWeight());
totalEntity.setScore(totalEntity.getScore().add(total));
}
});
}
list = cpcScoreDao.getPartScoreByPage(formDTO.getCustomerId(), formDTO.getMonthId(), (pageNo - 1) * pageSize, pageSize); insertBatch(cpcScoreTotalMap.values().stream().collect(Collectors.toList()));
if (!CollectionUtils.isEmpty(list)) {
list.forEach(partScore->{
});
} }
} while (!CollectionUtils.isEmpty(list) && pageNo++ > 0);
private void insertBatch(Collection<CpcScoreEntity> values) {
cpcScoreDao.insertBatch(values);
} }
private void calculatePartScore(CalculateCommonFormDTO formDTO) { private void calculatePartScore(CalculateCommonFormDTO formDTO) {
@ -165,6 +183,7 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
cpcScoreEntity.setAgencyId(String.valueOf(cpcCount.get(IndexCalConstant.AGENCY_ID))); cpcScoreEntity.setAgencyId(String.valueOf(cpcCount.get(IndexCalConstant.AGENCY_ID)));
cpcScoreEntity.setGridId(String.valueOf(cpcCount.get(IndexCalConstant.GRID_ID))); cpcScoreEntity.setGridId(String.valueOf(cpcCount.get(IndexCalConstant.GRID_ID)));
cpcScoreEntity.setUserId(userId); cpcScoreEntity.setUserId(userId);
cpcScoreEntity.setIsTotal(NumConstant.ZERO_STR);
cpcScoreEntity.setMonthId(formDTO.getMonthId()); cpcScoreEntity.setMonthId(formDTO.getMonthId());
cpcScoreEntity.setScore(new BigDecimal(0)); cpcScoreEntity.setScore(new BigDecimal(0));
cpcScoreEntity.setIndexCode(parentIndexCode); cpcScoreEntity.setIndexCode(parentIndexCode);
@ -186,11 +205,13 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void saveCpcScore(CalculateCommonFormDTO formDTO, Map<String, CpcScoreEntity> indexDetails, String parentIndexCode, HashMap<String, BigDecimal> result) { public void saveCpcScore(CalculateCommonFormDTO formDTO, Map<String, CpcScoreEntity> indexDetails, String parentIndexCode, HashMap<String, BigDecimal> result) {
cpcScoreDao.deleteByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), parentIndexCode); cpcScoreDao.deleteByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), parentIndexCode);
List<CpcScoreEntity> list = new ArrayList<>();
result.forEach((userId, score) -> { result.forEach((userId, score) -> {
CpcScoreEntity cpcScoreEntity = indexDetails.get(userId); CpcScoreEntity cpcScoreEntity = indexDetails.get(userId);
cpcScoreEntity.setScore(score); cpcScoreEntity.setScore(score);
cpcScoreDao.insert(cpcScoreEntity); list.add(cpcScoreEntity);
}); });
this.insertBatch(list);
} }
/** /**

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

@ -22,9 +22,9 @@
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 from fact_index_cpc_score where CUSTOMER_ID = #{customerId,jdbcType=VARCHAR} and MONTH_ID = #{monthId,jdbcType=VARCHAR} and INDEX_CODE = #{indexCode,jdbcType=VARCHAR}
</delete> </delete>
<select id="getPartScoreByPage" resultType="com.epmet.entity.indexscore.CpcScoreEntity"> <select id="getPartScore" resultType="com.epmet.entity.indexscore.CpcScoreEntity">
select select
CUSTOMER_ID,AGENCY_ID,GRID_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
WHERE WHERE
CUSTOMER_ID = #{customerId,jdbcType=VARCHAR} and MONTH_ID = #{monthId,jdbcType=VARCHAR} AND IS_TOTAL = '0' CUSTOMER_ID = #{customerId,jdbcType=VARCHAR} and MONTH_ID = #{monthId,jdbcType=VARCHAR} AND IS_TOTAL = '0'
</select> </select>
@ -91,4 +91,46 @@
GROUP BY GROUP BY
m.GRID_ID m.GRID_ID
</select> </select>
<insert id="insertBatch">
INSERT INTO `fact_index_cpc_score` (
`ID`,
`CUSTOMER_ID`,
`GRID_ID`,
`AGENCY_ID`,
`YEAR_ID`,
`MONTH_ID`,
`USER_ID`,
`IS_TOTAL`,
`SCORE`,
`INDEX_CODE`,
`DEL_FLAG`,
`REVISION`,
`CREATED_BY`,
`CREATED_TIME`,
`UPDATED_BY`,
`UPDATED_TIME`
)
VALUES
<foreach collection="list" item="item" index="index" separator=",">
(
(SELECT REPLACE(UUID(), '-', '') AS id),
#{item.customerId},
#{item.gridId},
#{item.agencyId},
#{item.yearId},
#{item.monthId},
#{item.userId},
#{item.isTotal},
#{item.score},
#{item.indexCode},
'0',
0,
'APP_USER',
now(),
'APP_USER',
now()
)
</foreach>
</insert>
</mapper> </mapper>
Loading…
Cancel
Save