Browse Source

组织自身和下级分数

master
jianjun 5 years ago
parent
commit
5857c6cb58
  1. 2
      epmet-commons/epmet-commons-dynamic-datasource/src/main/java/com/epmet/commons/dynamic/datasource/config/DynamicDataSource.java
  2. 4
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java
  3. 8
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/AgencySelfSubScoreDao.java
  4. 2
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/CommunitySelfSubScoreDao.java
  5. 8
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/GridSelfSubScoreDao.java
  6. 52
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/GridCorreLationServiceImpl.java
  7. 8
      epmet-module/data-statistical/data-statistical-server/src/main/resources/bootstrap.yml
  8. 40
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/AgencySelfSubScoreDao.xml
  9. 2
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/CommunitySelfSubScoreDao.xml
  10. 29
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/FactIndexGridSelfSubScoreDao.xml
  11. 58
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/GridSelfSubScoreDao.xml
  12. 2
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/GridSubScoreDao.xml

2
epmet-commons/epmet-commons-dynamic-datasource/src/main/java/com/epmet/commons/dynamic/datasource/config/DynamicDataSource.java

@ -25,7 +25,7 @@ public class DynamicDataSource extends AbstractRoutingDataSource {
@Override @Override
protected Object determineCurrentLookupKey() { protected Object determineCurrentLookupKey() {
String ds = DynamicContextHolder.peek(); String ds = DynamicContextHolder.peek();
logger.info("动态数据源:{}" + ds); logger.debug("动态数据源:{}", ds);
return ds; return ds;
} }

4
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java

@ -178,13 +178,13 @@ public class DemoController {
@PostMapping("zxc2") @PostMapping("zxc2")
public Result getZxc2(){ public Result getZxc2(){
indexCalculateCommunityService.calCommunityAll("b09527201c4409e19d1dbc5e3c3429a1","202008"); indexCalculateCommunityService.calCommunityAll("epmettest", "202008");
return new Result(); return new Result();
} }
@PostMapping("testcalculategridcorrelation") @PostMapping("testcalculategridcorrelation")
public Result testcalculateGridCorreLation(){ public Result testcalculateGridCorreLation(){
CalculateCommonFormDTO formDTO=new CalculateCommonFormDTO("b09527201c4409e19d1dbc5e3c3429a1","202008"); CalculateCommonFormDTO formDTO = new CalculateCommonFormDTO("epmettest", "202008");
gridCorreLationService.calculateGridCorreLation(formDTO); gridCorreLationService.calculateGridCorreLation(formDTO);
return new Result(); return new Result();
} }

8
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/FactIndexAgencySelfSubScoreDao.java → epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/AgencySelfSubScoreDao.java

@ -20,6 +20,9 @@ package com.epmet.dao.evaluationindex.indexcal;
import com.epmet.commons.mybatis.dao.BaseDao; import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.entity.evaluationindex.indexcal.AgencySelfSubScoreEntity; import com.epmet.entity.evaluationindex.indexcal.AgencySelfSubScoreEntity;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* /街道相关 自身和下级分数表 * /街道相关 自身和下级分数表
@ -28,6 +31,9 @@ import org.apache.ibatis.annotations.Mapper;
* @since v1.0.0 2020-09-21 * @since v1.0.0 2020-09-21
*/ */
@Mapper @Mapper
public interface FactIndexAgencySelfSubScoreDao extends BaseDao<AgencySelfSubScoreEntity> { public interface AgencySelfSubScoreDao extends BaseDao<AgencySelfSubScoreEntity> {
int deleteByMonthId(@Param("customerId") String customerId, @Param("monthId") String monthId);
int insertBatch(@Param("list") List<AgencySelfSubScoreEntity> list);
} }

2
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/FactIndexCommunitySelfSubScoreDao.java → epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/CommunitySelfSubScoreDao.java

@ -28,6 +28,6 @@ import org.apache.ibatis.annotations.Mapper;
* @since v1.0.0 2020-09-21 * @since v1.0.0 2020-09-21
*/ */
@Mapper @Mapper
public interface FactIndexCommunitySelfSubScoreDao extends BaseDao<CommunitySelfSubScoreEntity> { public interface CommunitySelfSubScoreDao extends BaseDao<CommunitySelfSubScoreEntity> {
} }

8
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/FactIndexGridSelfSubScoreDao.java → epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/indexcal/GridSelfSubScoreDao.java

@ -20,6 +20,9 @@ package com.epmet.dao.evaluationindex.indexcal;
import com.epmet.commons.mybatis.dao.BaseDao; import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.entity.evaluationindex.indexcal.GridSelfSubScoreEntity; import com.epmet.entity.evaluationindex.indexcal.GridSelfSubScoreEntity;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* 网格相关自身/下级分值记录表 * 网格相关自身/下级分值记录表
@ -28,6 +31,9 @@ import org.apache.ibatis.annotations.Mapper;
* @since v1.0.0 2020-09-21 * @since v1.0.0 2020-09-21
*/ */
@Mapper @Mapper
public interface FactIndexGridSelfSubScoreDao extends BaseDao<GridSelfSubScoreEntity> { public interface GridSelfSubScoreDao extends BaseDao<GridSelfSubScoreEntity> {
int deleteByMonthId(@Param("customerId") String customerId, @Param("monthId") String monthId, @Param("parentIndexCode") String parentIndexCode);
int insertBatch(@Param("list") List<GridSelfSubScoreEntity> list);
} }

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

@ -11,6 +11,7 @@ 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.indexcal.GridScoreDao; import com.epmet.dao.evaluationindex.indexcal.GridScoreDao;
import com.epmet.dao.evaluationindex.indexcal.GridSelfSubScoreDao;
import com.epmet.dao.evaluationindex.indexcal.GridSubScoreDao; import com.epmet.dao.evaluationindex.indexcal.GridSubScoreDao;
import com.epmet.dao.evaluationindex.indexcoll.FactIndexGovrnAblityGridMonthlyDao; import com.epmet.dao.evaluationindex.indexcoll.FactIndexGovrnAblityGridMonthlyDao;
import com.epmet.dao.evaluationindex.indexcoll.FactIndexPartyAblityGridMonthlyDao; import com.epmet.dao.evaluationindex.indexcoll.FactIndexPartyAblityGridMonthlyDao;
@ -19,8 +20,8 @@ import com.epmet.dao.evaluationindex.screen.IndexGroupDetailDao;
import com.epmet.dao.evaluationindex.screen.ScreenCustomerGridDao; import com.epmet.dao.evaluationindex.screen.ScreenCustomerGridDao;
import com.epmet.dto.ScreenCustomerGridDTO; import com.epmet.dto.ScreenCustomerGridDTO;
import com.epmet.dto.indexcal.*; import com.epmet.dto.indexcal.*;
import com.epmet.entity.evaluationindex.indexcal.AgencySelfSubScoreEntity;
import com.epmet.entity.evaluationindex.indexcal.GridScoreEntity; import com.epmet.entity.evaluationindex.indexcal.GridScoreEntity;
import com.epmet.entity.evaluationindex.indexcal.GridSelfSubScoreEntity;
import com.epmet.entity.evaluationindex.indexcal.GridSubScoreEntity; import com.epmet.entity.evaluationindex.indexcal.GridSubScoreEntity;
import com.epmet.entity.evaluationindex.screen.IndexGroupDetailEntity; import com.epmet.entity.evaluationindex.screen.IndexGroupDetailEntity;
import com.epmet.eum.IndexCodeEnum; import com.epmet.eum.IndexCodeEnum;
@ -75,6 +76,8 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
private GridSubScoreDao gridSubScoreDao; private GridSubScoreDao gridSubScoreDao;
@Autowired @Autowired
private IndexGroupDetailDao indexGroupDetailDao; private IndexGroupDetailDao indexGroupDetailDao;
@Autowired
private GridSelfSubScoreDao gridSelfSubScoreDao;
/** /**
@ -122,22 +125,57 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
log.error("calculateSelfSubScore gridSubScoreDao.selectSubListByPath return empty,customerId:{} ", formDTO.getCustomerId()); log.error("calculateSelfSubScore gridSubScoreDao.selectSubListByPath return empty,customerId:{} ", formDTO.getCustomerId());
return; return;
} }
Map<String, String> selfSubParentMap = new HashMap<>(); Map<String, Set<String>> selfSubParentMap = new HashMap<>();
selfSubParentMap.put("zishen", new HashSet<>());
selfSubParentMap.put("xiaji", new HashSet<>());
selfSubIndexList.forEach(o -> { selfSubIndexList.forEach(o -> {
//找出自身 和下级的指标 //找出自身 和下级的指标
if (o.getAllParentIndexCode().contains("xiaji")) { if (o.getAllIndexCodePath().indexOf("xiaji") > -1) {
selfSubParentMap.put(o.getAllParentIndexCode(), "xiaji"); selfSubParentMap.get("xiaji").add(o.getIndexCode());
} else { } else {
selfSubParentMap.put(o.getAllParentIndexCode(), "zishen"); selfSubParentMap.get("zishen").add(o.getIndexCode());
} }
}); });
Map<String, AgencySelfSubScoreEntity> insertList = new HashMap<>(); Map<String, GridSelfSubScoreEntity> insertMap = new HashMap<>();
subScore.forEach(score -> { subScore.forEach(score -> {
insertList.get(score.getAllParentIndexCode());
String key = score.getGridId().concat(index.getIndexCode());
GridSelfSubScoreEntity scoreEntity = insertMap.get(key);
if (scoreEntity == null) {
scoreEntity = ConvertUtils.sourceToTarget(score, GridSelfSubScoreEntity.class);
insertMap.put(key, scoreEntity);
scoreEntity.setSelfScore(new BigDecimal(0));
scoreEntity.setSubScore(new BigDecimal(0));
scoreEntity.setParentIndexCode(index.getIndexCode());
scoreEntity.setSelfWeight(new BigDecimal(0));
scoreEntity.setSubWeight(new BigDecimal(0));
}
BigDecimal partScore = score.getScore().multiply(score.getWeight());
BigDecimal partWeight = score.getScore().multiply(score.getWeight());
if (selfSubParentMap.get("xiaji").contains(score.getIndexCode())) {
scoreEntity.setSubScore(scoreEntity.getSubScore().add(partScore));
scoreEntity.setSubWeight(scoreEntity.getSubWeight().add(score.getWeight()));
} else {
scoreEntity.setSelfScore(scoreEntity.getSelfScore().add(partScore));
scoreEntity.setSelfWeight(scoreEntity.getSelfWeight().add(score.getWeight()));
}
log.debug("=====key" + key + ",grid:{},originScore:{},weight:{},finalScore:{},total", score.getGridId(), score.getScore(), score.getWeight(), partScore);
System.out.println("=====grid:" + score.getGridId() + ",originScore:" + score.getScore() + ",weight:" + score.getWeight() + ",finalScore:" + partScore + " ,selftotal:" + scoreEntity.getSelfScore() + ",subScore:" + scoreEntity.getSubScore());
}); });
deleteAndInsertSelfSubScore(formDTO, index.getIndexCode(), insertMap);
}); });
} }
@Transactional(rollbackFor = Exception.class)
public void deleteAndInsertSelfSubScore(CalculateCommonFormDTO formDTO, String indexCode, Map<String, GridSelfSubScoreEntity> insertMap) {
int effectRow = 0;
do {
gridSelfSubScoreDao.deleteByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), indexCode);
} while (effectRow > 0);
gridSelfSubScoreDao.insertBatch(new ArrayList<>(insertMap.values()));
}
/** /**
* @param formDTO * @param formDTO
* @return void * @return void

8
epmet-module/data-statistical/data-statistical-server/src/main/resources/bootstrap.yml

@ -189,7 +189,7 @@ thread:
queueCapacity: @thread.pool.queue-capacity@ queueCapacity: @thread.pool.queue-capacity@
keepAlive: @thread.pool.keep-alive@ keepAlive: @thread.pool.keep-alive@
dingTalk: #dingTalk:
robot: # robot:
webHook: @dingTalk.robot.webHook@ # webHook: @dingTalk.robot.webHook@
secret: @dingTalk.robot.secret@ # secret: @dingTalk.robot.secret@

40
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/AgencySelfSubScoreDao.xml

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.epmet.dao.evaluationindex.indexcal.AgencySelfSubScoreDao">
<delete id="deleteByMonthId">
delete from fact_index_agency_self_sub_score limit 1000
</delete>
<insert id="insertBatch">
INSERT INTO fact_index_agency_self_sub_score (ID, CUSTOMER_ID, AGENCY_ID, PARENT_AGENCY_ID, YEAR_ID, QUARTER_ID, MONTH_ID,
DATA_TYPE, SELF_SCORE, SUB_SCORE, PARENT_INDEX_CODE,ALL_PARENT_INDEX_CODE,
SELF_WEIGHT,SUB_WEIGHT,DEL_FLAG, REVISION, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME )
VALUES
<foreach collection="list" item="item" separator=",">
(
REPLACE ( UUID(), '-', '' ),
#{item.customerId},
#{item.agencyId},
#{item.parentAgencyId},
#{item.yearId},
#{item.quarterId},
#{item.monthId},
#{item.dataType},
#{item.selfScore},
#{item.subScore},
#{item.parentIndexCode},
#{item.allParentIndexCode},
#{item.selfWeight},
#{item.subWeight},
#{item.delFlag},
#{item.revision},
#{item.createdBy},
NOW(),
#{item.updatedBy},
NOW()
)
</foreach>
</insert>
</mapper>

2
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/FactIndexCommunitySelfSubScoreDao.xml → epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/CommunitySelfSubScoreDao.xml

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.epmet.dao.evaluationindex.indexcal.FactIndexCommunitySelfSubScoreDao"> <mapper namespace="com.epmet.dao.evaluationindex.indexcal.CommunitySelfSubScoreDao">
<resultMap type="com.epmet.entity.evaluationindex.indexcal.CommunitySelfSubScoreEntity" id="factIndexCommunitySelfSubScoreMap"> <resultMap type="com.epmet.entity.evaluationindex.indexcal.CommunitySelfSubScoreEntity" id="factIndexCommunitySelfSubScoreMap">
<result property="id" column="ID"/> <result property="id" column="ID"/>

29
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/FactIndexGridSelfSubScoreDao.xml

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.epmet.dao.evaluationindex.indexcal.FactIndexGridSelfSubScoreDao">
<resultMap type="com.epmet.entity.evaluationindex.indexcal.GridSelfSubScoreEntity" id="factIndexGridSelfSubScoreMap">
<result property="id" column="ID"/>
<result property="customerId" column="CUSTOMER_ID"/>
<result property="gridId" column="GRID_ID"/>
<result property="agencyId" column="AGENCY_ID"/>
<result property="allParentIds" column="ALL_PARENT_IDS"/>
<result property="quarterId" column="QUARTER_ID"/>
<result property="yearId" column="YEAR_ID"/>
<result property="monthId" column="MONTH_ID"/>
<result property="scoreType" column="SCORE_TYPE"/>
<result property="score" column="SCORE"/>
<result property="indexCode" column="INDEX_CODE"/>
<result property="allParentIndexCode" column="ALL_PARENT_INDEX_CODE"/>
<result property="weight" column="WEIGHT"/>
<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"/>
</resultMap>
</mapper>

58
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/GridSelfSubScoreDao.xml

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.epmet.dao.evaluationindex.indexcal.GridSelfSubScoreDao">
<delete id="deleteByMonthId">
delete from fact_index_grid_self_sub_score where CUSTOMER_ID = #{customerId,jdbcType=VARCHAR} AND MONTH_ID = #{monthId,jdbcType=VARCHAR} AND PARENT_INDEX_CODE = #{parentIndexCode,jdbcType=VARCHAR} limit 1000
</delete>
<!-- 批量插入计算结果 -->
<insert id="insertBatch">
INSERT INTO `fact_index_grid_self_sub_score` (
`ID`,
`CUSTOMER_ID`,
`GRID_ID`,
`AGENCY_ID`,
`ALL_PARENT_IDS`,
`QUARTER_ID`,
`YEAR_ID`,
`MONTH_ID`,
`SELF_SCORE`,
`SUB_SCORE`,
`PARENT_INDEX_CODE`,
`ALL_PARENT_INDEX_CODE`,
`SELF_WEIGHT`,
`SUB_WEIGHT`,
`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.allParentIds},
#{item.quarterId},
#{item.yearId},
#{item.monthId},
#{item.selfScore},
#{item.subScore},
#{item.parentIndexCode},
#{item.allParentIndexCode},
#{item.selfWeight},
#{item.subWeight},
0,
0,
'APP_USER',
now(),
'APP_USER',
now()
)
</foreach>
</insert>
</mapper>

2
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/indexcal/GridSubScoreDao.xml

@ -82,7 +82,7 @@
`ALL_PARENT_INDEX_CODE`, `ALL_PARENT_INDEX_CODE`,
WEIGHT WEIGHT
FROM FROM
fact_index_grid_score fact_index_grid_sub_score
WHERE WHERE
DEL_FLAG = '0' DEL_FLAG = '0'
AND CUSTOMER_ID = #{customerId} AND CUSTOMER_ID = #{customerId}

Loading…
Cancel
Save