Browse Source

Merge remote-tracking branch 'remotes/origin/dev_screen_data_2.0' into dev_difficulty_data

dev_shibei_match
jianjun 5 years ago
parent
commit
c61ce8c7d6
  1. 78
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/distributedlock/DistributedLock.java
  2. 12
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/distributedlock/LockConstants.java
  3. 4
      epmet-module/data-report/data-report-client/src/main/java/com/epmet/evaluationindex/screen/dto/result/AblityListResultDTO.java
  4. 22
      epmet-module/data-report/data-report-client/src/main/java/com/epmet/evaluationindex/screen/dto/result/AnNingSubAgencyIndexRankResultDTO.java
  5. 8
      epmet-module/data-report/data-report-client/src/main/java/com/epmet/evaluationindex/screen/dto/result/ScoreListResultDTO.java
  6. 10
      epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/evaluationindex/screen/impl/AgencyServiceImpl.java
  7. 6
      epmet-module/data-report/data-report-server/src/main/resources/mapper/fact/FactIndexAgencyScoreDao.xml
  8. 1
      epmet-module/data-report/data-report-server/src/main/resources/mapper/fact/FactIndexAgencySubScoreDao.xml
  9. 6
      epmet-module/data-report/data-report-server/src/main/resources/mapper/fact/FactIndexCommunityScoreDao.xml
  10. 6
      epmet-module/data-report/data-report-server/src/main/resources/mapper/fact/FactIndexGridScoreDao.xml
  11. 3
      epmet-module/data-report/data-report-server/src/main/resources/mapper/screen/ScreenIndexDataMonthlyDao.xml
  12. 38
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcoll/impl/FactIndexCollectServiceImpl.java
  13. 48
      epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/RedissonTest.java
  14. 21
      epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/zxc/ZxcDTO.java

78
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/distributedlock/DistributedLock.java

@ -0,0 +1,78 @@
package com.epmet.commons.tools.distributedlock;
import com.epmet.commons.tools.exception.RenException;
import org.apache.commons.lang3.StringUtils;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.concurrent.TimeUnit;
/**
* @Author zxc
* @DateTime 2020/10/28 9:05 上午
*/
@Component
public class DistributedLock {
@Autowired
private RedissonClient redissonClient;
/**
* @Description 抢锁🔒 每个锁持有十分钟
* watchDog模式每隔10s自动更改持锁时间,假设宕机持锁时间达到时会自动释放锁
* @Param name
* @author zxc
* @date 2020/10/28 2:52 下午
*/
public RLock getLock(String name){
RLock lock = null;
if (StringUtils.isNotBlank(name)) {
lock = redissonClient.getLock(name);
// 持续时间为 -1 时,直到其明确释放锁才会释放【宕机就完蛋了】,
lock.lock(10,TimeUnit.MINUTES);
}
return lock;
}
/**
* @Description
* @Param name 锁名
* @Param leaseTime 持锁时间 单位min
* @Param waitTime 获取锁最长等待时间 单位min
* @author zxc
* @date 2020/10/29 9:04 上午
*/
public RLock getLock(String name,Long leaseTime,Long waitTime){
RLock lock = null;
if (StringUtils.isNotBlank(name) && leaseTime > 0 && waitTime > 0 ){
lock = redissonClient.getLock(name);
Boolean lockStatus;
try {
lockStatus = lock.tryLock(waitTime,leaseTime,TimeUnit.MINUTES);
if (!lockStatus){
throw new RenException("获取锁🔒失败了......");
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return lock;
}
/**
* @Description 释放锁🔒
* @Param rLock
* @author zxc
* @date 2020/10/28 2:52 下午
*/
public void unLock(RLock rLock){
if (null != rLock){
if (rLock.isHeldByCurrentThread()){
rLock.unlock();
}
}
}
}

12
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/distributedlock/LockConstants.java

@ -0,0 +1,12 @@
package com.epmet.commons.tools.distributedlock;
/**
* @Author zxc
* @DateTime 2020/10/28 9:23 上午
*/
public interface LockConstants {
String TEST_LOCK_NAME = "testLock";
String STATS_LOCK_NAME = "stats";
}

4
epmet-module/data-report/data-report-client/src/main/java/com/epmet/evaluationindex/screen/dto/result/AblityListResultDTO.java

@ -19,7 +19,7 @@ public class AblityListResultDTO implements Serializable {
*/
private String name;
/**
* 指标对应值数值或百分比
* 指标对应值数值或百分比原始值
*/
private String value = "0";
/**
@ -36,4 +36,6 @@ public class AblityListResultDTO implements Serializable {
*/
private BigDecimal weight;
private Double score;
}

22
epmet-module/data-report/data-report-client/src/main/java/com/epmet/evaluationindex/screen/dto/result/AnNingSubAgencyIndexRankResultDTO.java

@ -1,5 +1,6 @@
package com.epmet.evaluationindex.screen.dto.result;
import com.epmet.commons.tools.constant.NumConstant;
import lombok.Data;
import java.io.Serializable;
@ -38,6 +39,21 @@ public class AnNingSubAgencyIndexRankResultDTO implements Serializable {
*/
private Double serviceAbility = 0.0;
/**
* 党建能力权重
*/
private Double partyWeight;
/**
* 治理能力权重
*/
private Double governWeight;
/**
* 服务能力权重
*/
private Double serviceWeight;
/**
* 组织id或者网格id
*/
@ -47,4 +63,10 @@ public class AnNingSubAgencyIndexRankResultDTO implements Serializable {
* 组织类型
*/
private String orgType = "";
public AnNingSubAgencyIndexRankResultDTO() {
this.partyWeight = NumConstant.ZERO_DOT_ZERO;
this.governWeight = NumConstant.ZERO_DOT_ZERO;
this.serviceWeight = NumConstant.ZERO_DOT_ZERO;
}
}

8
epmet-module/data-report/data-report-client/src/main/java/com/epmet/evaluationindex/screen/dto/result/ScoreListResultDTO.java

@ -25,9 +25,17 @@ public class ScoreListResultDTO implements Serializable {
* 本级分数(保留一位小数)
*/
private Double agencyScore;
private Double selfOriginScore;
private Double agencyWeight;
/**
* 下级分数(保留一位小数)
*/
private Double subAgencyScore;
private Double subAgencyWeight;
private Double subOriginScore;
}

10
epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/evaluationindex/screen/impl/AgencyServiceImpl.java

@ -138,12 +138,7 @@ public class AgencyServiceImpl implements AgencyService {
});
sub.setChildren(treeResultDTOS);
}else {
List<TreeResultDTO> subAgency = new ArrayList<>();
if (sub.getPids().contains(ScreenConstant.COMMA)){
subAgency = getDepartmentList(sub.getPids() + ScreenConstant.COMMA + sub.getValue());
}else {
subAgency = getDepartmentList(sub.getPids() + ScreenConstant.COLON + sub.getValue());
}
List<TreeResultDTO> subAgency = getDepartmentList(sub.getPids() + ScreenConstant.COMMA + sub.getValue());
sub.setChildren(subAgency);
}
});
@ -176,6 +171,9 @@ public class AgencyServiceImpl implements AgencyService {
subAgency = getDepartmentListByBiz(sub.getPids() + ScreenConstant.COMMA + sub.getValue());
}else {
subAgency = getDepartmentListByBiz(sub.getPids() + ScreenConstant.COLON + sub.getValue());
if (null == subAgency){
subAgency = getDepartmentListByBiz(sub.getPids() + ScreenConstant.COMMA + sub.getValue());
}
}
sub.setChildren(subAgency);
}

6
epmet-module/data-report/data-report-server/src/main/resources/mapper/fact/FactIndexAgencyScoreDao.xml

@ -26,7 +26,11 @@
fact.index_code AS "indexCode",
ROUND(fact.score*fact.WEIGHT, 1) AS "indexTotal",
ROUND(self.self_score*fact.WEIGHT, 1) AS "agencyScore",
ROUND(self.sub_score*fact.WEIGHT, 1) AS "subAgencyScore"
self.self_score AS selfOriginScore,
self.SELF_WEIGHT AS agencyWeight,
ROUND(self.sub_score*fact.WEIGHT, 1) AS "subAgencyScore",
self.sub_score AS subOriginScore,
self.SUB_WEIGHT AS subAgencyWeight
FROM
fact_index_agency_score fact
INNER JOIN fact_index_agency_self_sub_score self ON fact.agency_id = self.agency_id

1
epmet-module/data-report/data-report-server/src/main/resources/mapper/fact/FactIndexAgencySubScoreDao.xml

@ -7,6 +7,7 @@
SELECT
fact.index_code AS "key",
IF(fact.origin_value='',0,IFNULL(fact.origin_value,0)) AS "value",
fact.score,
dict.index_name AS "name",
round(fact.WEIGHT,2) AS weight
FROM

6
epmet-module/data-report/data-report-server/src/main/resources/mapper/fact/FactIndexCommunityScoreDao.xml

@ -26,7 +26,11 @@
fact.index_code AS "indexCode",
ROUND(fact.score*fact.WEIGHT, 1) AS "indexTotal",
ROUND(self.self_score*fact.WEIGHT, 1) AS "agencyScore",
ROUND(self.sub_score*fact.WEIGHT, 1) AS "subAgencyScore"
self.self_score AS selfOriginScore,
self.SELF_WEIGHT AS agencyWeight,
ROUND(self.sub_score*fact.WEIGHT, 1) AS "subAgencyScore",
self.sub_score AS subOriginScore,
self.SUB_WEIGHT AS subAgencyWeight
FROM
fact_index_community_score fact
INNER JOIN fact_index_community_self_sub_score self ON fact.agency_id = self.agency_id

6
epmet-module/data-report/data-report-server/src/main/resources/mapper/fact/FactIndexGridScoreDao.xml

@ -26,7 +26,11 @@
fact.index_code AS "indexCode",
ROUND(fact.score*fact.WEIGHT, 1) AS "indexTotal",
ROUND(self.self_score*fact.WEIGHT, 1) AS "agencyScore",
ROUND(self.sub_score*fact.WEIGHT, 1) AS "subAgencyScore"
self.self_score AS selfOriginScore,
self.SELF_WEIGHT AS agencyWeight,
ROUND(self.sub_score*fact.WEIGHT, 1) AS "subAgencyScore",
self.sub_score AS subOriginScore,
self.SUB_WEIGHT AS subAgencyWeight
FROM
fact_index_grid_score fact
INNER JOIN fact_index_grid_self_sub_score self ON fact.grid_id = self.grid_id

3
epmet-module/data-report/data-report-server/src/main/resources/mapper/screen/ScreenIndexDataMonthlyDao.xml

@ -69,6 +69,9 @@
service_ablity * SERVICE_ABLITY_WEIGHT AS serviceAbility,
party_dev_ablity * PARTY_DEV_WEIGHT AS partyDevAbility,
govern_ablity * GOVERN_ABLITY_WEIGHT AS governAbility,
PARTY_DEV_WEIGHT AS partyWeight,
GOVERN_ABLITY_WEIGHT AS governWeight,
SERVICE_ABLITY_WEIGHT AS serviceWeight,
ORG_ID orgId,
ORG_TYPE orgType
FROM

38
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcoll/impl/FactIndexCollectServiceImpl.java

@ -1,9 +1,12 @@
package com.epmet.service.evaluationindex.indexcoll.impl;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.dynamic.datasource.annotation.DataSource;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.redis.RedisKeys;
import com.epmet.commons.tools.distributedlock.DistributedLock;
import com.epmet.commons.tools.distributedlock.LockConstants;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.constant.DataSourceConstant;
import com.epmet.constant.OrgTypeConstant;
@ -28,8 +31,8 @@ import com.epmet.service.evaluationindex.indexcoll.FactIndexCollectService;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.ListUtils;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -89,7 +92,7 @@ public class FactIndexCollectServiceImpl implements FactIndexCollectService {
@Autowired
private ScreenCustomerAgencyDao screenCustomerAgencyDao;
@Autowired
private RedissonClient redissonClient;
private DistributedLock distributedLock;
@Override
@Transactional(rollbackFor = Exception.class)
@ -200,7 +203,17 @@ public class FactIndexCollectServiceImpl implements FactIndexCollectService {
} while (deleteNum > NumConstant.ZERO);
}
if (!CollectionUtils.isEmpty(formDTO.getDataList())) {
factIndexGovrnAblityDeptMonthlyDao.batchInsertFactIndexGovrnAblityDeptMonthly(formDTO.getDataList(), customerId);
List<DeptGovrnAbilityFormDTO> dataList = formDTO.getDataList();
// 有 deptId字段为空时,报错提示
List<DeptGovrnAbilityFormDTO> deptIsNull = dataList.stream().filter(d -> null == d.getDeptId() || d.getDeptId().equals("")).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(deptIsNull)){
throw new RenException("治理能力-部门相关指标计算【deptId为空】的客户ID为:"+customerId+",具体信息信息为:"+ JSON.toJSONString(deptIsNull));
}
// 改成分批插入
List<List<DeptGovrnAbilityFormDTO>> partition = ListUtils.partition(dataList, NumConstant.ONE_HUNDRED);
partition.forEach(p -> {
factIndexGovrnAblityDeptMonthlyDao.batchInsertFactIndexGovrnAblityDeptMonthly(p, customerId);
});
}
}
@ -216,15 +229,9 @@ public class FactIndexCollectServiceImpl implements FactIndexCollectService {
if (NumConstant.SIX != monthId.length()) {
throw new RuntimeException("入参monthId格式不正确:monthId =" + monthId);
}
RLock lock = redissonClient.getLock(RedisKeys.getScreenIndexDataLockKey());
RLock lock = distributedLock.getLock(LockConstants.STATS_LOCK_NAME);
try {
AtomicInteger tryTimes = new AtomicInteger(0);
boolean lockFlag = false;
do {
lockFlag = lock.tryLock(1, 10, TimeUnit.MINUTES);
} while (!lockFlag && tryTimes.addAndGet(1) < 3);
if (!lockFlag) {
log.error("插入大屏指数方法获取锁失败");
if (null==lock) {
return;
}
allParentIds.cleanUp();
@ -250,13 +257,8 @@ public class FactIndexCollectServiceImpl implements FactIndexCollectService {
// 根据年,汇总今年各项得到,计算平均值后 插入年表 screen_index_data_yearly
this.insertIndexDataYear(monthId, customerId);
allParentIds.invalidateAll();
} catch (InterruptedException inter) {
log.error("插入计算指标数据异常", inter);
} finally {
//判断是否是当前线程 持有锁
if (lock.isHeldByCurrentThread()) {
lock.unlock();
}
distributedLock.unLock(lock);
}
}

48
epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/RedissonTest.java

@ -1,6 +1,10 @@
package com.epmet.stats.test;
import com.alibaba.fastjson.JSON;
import com.epmet.DataStatsApplication;
import com.epmet.commons.tools.distributedlock.DistributedLock;
import com.epmet.commons.tools.distributedlock.LockConstants;
import com.epmet.stats.test.zxc.ZxcDTO;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -10,6 +14,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
/**
@ -22,8 +29,43 @@ public class RedissonTest {
@Autowired
private RedissonClient redissonClient;
@Autowired
private DistributedLock distributedLock;
@Test
public void lock(){
long start = System.currentTimeMillis();
RLock lock = distributedLock.getLock(LockConstants.TEST_LOCK_NAME);
if (null==lock){
System.out.println("shibai");
}
try {
List<ZxcDTO> list = new ArrayList<>();
for (int i = 0; i < 50000; i++) {
ZxcDTO zxcDTO = new ZxcDTO();
zxcDTO.setA(UUID.randomUUID().toString());
zxcDTO.setB(UUID.randomUUID().toString());
zxcDTO.setC(UUID.randomUUID().toString());
zxcDTO.setD(UUID.randomUUID().toString());
zxcDTO.setE(UUID.randomUUID().toString());
zxcDTO.setF(i);
zxcDTO.setG(i+1);
zxcDTO.setH(i+2);
list.add(zxcDTO);
}
// log.info(JSON.toJSONString(list));
}finally {
// distributedLock.unLock(lock);
}
long end = System.currentTimeMillis();
log.info((end-start)+"hs");
}
/*@Test
public void lockTest() {
//获取一个名为 lockName 的锁实例
RLock lock = redissonClient.getLock("lockName");
@ -38,10 +80,10 @@ public class RedissonTest {
//lock.lock();
//异步方式
/* RFuture<Void> future = lock.lockAsync();
*//* RFuture<Void> future = lock.lockAsync();
if (future.isSuccess()){
//todo something
}*/
}*//*
if (bs) {
// 业务代码
System.out.println("进入业务代码: " + 123);
@ -56,6 +98,6 @@ public class RedissonTest {
lock.unlock();
}
}
}
}*/
}

21
epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/zxc/ZxcDTO.java

@ -0,0 +1,21 @@
package com.epmet.stats.test.zxc;
import lombok.Data;
/**
* @Author zxc
* @DateTime 2020/10/28 3:15 下午
*/
@Data
public class ZxcDTO {
private String a;
private String b;
private String c;
private String d;
private String e;
private Integer f;
private Integer g;
private Integer h;
}
Loading…
Cancel
Save