diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java index 4d44af0d47..c6e24b6893 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java @@ -115,6 +115,7 @@ public class IndexCalculateController { /** * 指标计算 + * * @param formDTO */ private void indexCalculate(CalculateCommonFormDTO formDTO) { @@ -137,29 +138,34 @@ public class IndexCalculateController { /** * 提交异步计算 + * * @param formDTO * @return */ private void submitCalculate(CalculateCommonFormDTO formDTO) { Future future = singleThreadPool.submit(() -> { - long start = System.currentTimeMillis(); - Boolean aBoolean = indexCalculateService.indexCalculate(formDTO); - if (aBoolean) { - log.error("客户Id:{},全部指标计算完成,总耗时:{}秒", formDTO.getCustomerId(), (System.currentTimeMillis() - start) / 1000); - } + try { + long start = System.currentTimeMillis(); + Boolean aBoolean = indexCalculateService.indexCalculate(formDTO); + if (aBoolean) { + log.error("客户Id:{},全部指标计算完成,总耗时:{}秒", formDTO.getCustomerId(), (System.currentTimeMillis() - start) / 1000); + } - redisUtils.delete(RedisKeys.getCustomerStatsCalFlag(formDTO.getCustomerId())); - futureMap.remove(formDTO.getCustomerId()); + redisUtils.delete(RedisKeys.getCustomerStatsCalFlag(formDTO.getCustomerId())); + futureMap.remove(formDTO.getCustomerId()); - //测试代码 - //try { - // Thread.sleep(20000l); - // System.out.println(System.currentTimeMillis()); - //} catch (InterruptedException e) { - // e.printStackTrace(); - //} - //redisUtils.delete(RedisKeys.getCustomerStatsCalFlag(formDTO.getCustomerId())); - //futureMap.remove(formDTO.getCustomerId()); + //测试代码 + //try { + // Thread.sleep(20000l); + // System.out.println(System.currentTimeMillis()); + //} catch (InterruptedException e) { + // e.printStackTrace(); + //} + //redisUtils.delete(RedisKeys.getCustomerStatsCalFlag(formDTO.getCustomerId())); + //futureMap.remove(formDTO.getCustomerId()); + } catch (Exception e) { + log.warn("submitCalculate exception", e); + } }); futureMap.put(formDTO.getCustomerId(), future); @@ -172,6 +178,7 @@ public class IndexCalculateController { /** * 终止计算 + * * @param form * @return */ @@ -194,10 +201,14 @@ public class IndexCalculateController { @PostMapping("reAll") public Result calculateAll(@RequestBody CalculateCommonFormDTO formDTO) { long start = System.currentTimeMillis(); - Boolean aBoolean = indexCalculateService.indexCalculate(formDTO); - HttpClientManager.getInstance().sendAlarmMsg(EnvEnum.getCurrentEnv().getName() + "客户Id:" + formDTO.getCustomerId() + ",calculateAll全部指标计算完成,是否成功:" + aBoolean + ",总耗时:" + (System.currentTimeMillis() - start) / 1000 + "秒"); - if (aBoolean) { - return new Result().ok(true); + try { + Boolean aBoolean = indexCalculateService.indexCalculate(formDTO); + HttpClientManager.getInstance().sendAlarmMsg(EnvEnum.getCurrentEnv().getName() + "客户Id:" + formDTO.getCustomerId() + ",calculateAll全部指标计算完成,是否成功:" + aBoolean + ",总耗时:" + (System.currentTimeMillis() - start) / 1000 + "秒"); + if (aBoolean) { + return new Result().ok(true); + } + } catch (Exception e) { + return new Result().error(e.getMessage()); } return new Result().error("指标计算失败"); } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/ScreenCustomerAgencyDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/ScreenCustomerAgencyDao.java index 56f6c9d5b4..04e5a0027d 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/ScreenCustomerAgencyDao.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/ScreenCustomerAgencyDao.java @@ -34,8 +34,8 @@ import java.util.List; @Mapper public interface ScreenCustomerAgencyDao extends BaseDao { /** - *14、组织层级 - * 1) 根据CUSTOMER_ID 进行查询,如果有数据,则先进行物理删除, 一次删除1000条 + * 14、组织层级 + * 1) 根据CUSTOMER_ID 进行查询,如果有数据,则先进行物理删除, 一次删除1000条 * * @param customerId * @return java.util.Integer @@ -46,24 +46,25 @@ public interface ScreenCustomerAgencyDao extends BaseDao list, @Param("customerId")String customerId); + void batchInsertCustomerAgency(@Param("list") List list, @Param("customerId") String customerId); /** * 返回当前客户下,未匹配到的 【社区级】 组织信息 - * @param customerId 客户id - * @param agencyIds 组织id集合 + * + * @param customerId 客户id + * @param agencyIds 组织id集合 * @return java.util.List * @Author zhangyong * @Date 14:38 2020-09-04 **/ - List selectListMismatcCommunityAgencyInfo(@Param("customerId")String customerId, @Param("agencyIds") String[] agencyIds); + List selectListMismatcCommunityAgencyInfo(@Param("customerId") String customerId, @Param("agencyIds") String[] agencyIds); /** * 根据客户id,查询区/街道 组织名称、id @@ -73,24 +74,32 @@ public interface ScreenCustomerAgencyDao extends BaseDao selectListAgencyInfo(@Param("customerId")String customerId); + List selectListAgencyInfo(@Param("customerId") String customerId); /** - * @Description 根据agencyId查询上级组织Id * @param agencyId + * @Description 根据agencyId查询上级组织Id * @author zxc * @date 2020/9/8 3:36 下午 */ - String selectPid(@Param("agencyId")String agencyId); + String selectPid(@Param("agencyId") String agencyId); /** * 返回当前客户下,未匹配到的 【乡(镇、街道)级、区县级】 组织信息 - * @param customerId 客户id - * @param agencyIds 组织id集合 + * + * @param customerId 客户id + * @param agencyIds 组织id集合 * @return java.util.List * @Author zhangyong * @Date 14:38 2020-09-04 **/ - List selectListMismatcStreetAndDistrictAgencyInfo(@Param("customerId")String customerId, @Param("agencyIds") String[] agencyIds); + List selectListMismatcStreetAndDistrictAgencyInfo(@Param("customerId") String customerId, @Param("agencyIds") String[] agencyIds); + /** + * desc:获取客户的组织条数 + * + * @param customerId + * @return + */ + int selectCountByCustomerId(@Param("customerId") String customerId); } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/CpcIndexCalculateServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/CpcIndexCalculateServiceImpl.java index 9d9cfe5739..71359d8b32 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/CpcIndexCalculateServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/CpcIndexCalculateServiceImpl.java @@ -75,8 +75,8 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { //获取指标权重 List parentIndexDetails = indexGroupDetailService.getDetailListByParentCode(formDTO.getCustomerId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode()); if (CollectionUtils.isEmpty(parentIndexDetails)) { - log.warn("cpcIndexCalculate customerId:{} have not any indexGroupDetail", formDTO.getCustomerId()); - throw new RenException("客户【党员相关】指标权重信息不存在"); + log.error("cpcIndexCalculate customerId:{} have not init index", formDTO.getCustomerId()); + throw new RenException("客户Id:" + formDTO.getCustomerId() + "【党员相关】指标权重信息不存在"); } Map indexWeightMap = parentIndexDetails.stream().collect(Collectors.toMap(IndexGroupDetailEntity::getIndexCode, o -> o)); int pageNo = NumConstant.ONE; diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateServiceImpl.java index c4fef95f7b..a2703968ec 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateServiceImpl.java @@ -6,6 +6,7 @@ import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.utils.DateUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.constant.DataSourceConstant; +import com.epmet.dao.evaluationindex.screen.ScreenCustomerAgencyDao; import com.epmet.dto.indexcal.CalculateCommonFormDTO; import com.epmet.feign.EpmetCommonServiceOpenFeignClient; import com.epmet.redis.IndexCalRedis; @@ -47,6 +48,8 @@ public class IndexCalculateServiceImpl implements IndexCalculateService { private DeptScoreService deptScoreService; @Autowired private FactIndexCollectService factIndexCollectService; + @Autowired + private ScreenCustomerAgencyDao screenCustomerAgencyDao; @Override @@ -91,6 +94,12 @@ public class IndexCalculateServiceImpl implements IndexCalculateService { Boolean flag; long start = System.currentTimeMillis(); try { + //校验是否含有组织数据 + int agencyCount = screenCustomerAgencyDao.selectCountByCustomerId(formDTO.getCustomerId()); + if (agencyCount < 1) { + log.info("客户id:{},组织结构数据缺失,请先上传后再计算", formDTO.getCustomerId()); + throw new RenException("组织结构数据缺失,请先上传后再计算"); + } //计算党员相关的 try { diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/BatchScoreCalculator.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/BatchScoreCalculator.java index b8efe2a1ff..786ec50233 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/BatchScoreCalculator.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/BatchScoreCalculator.java @@ -64,6 +64,10 @@ public class BatchScoreCalculator { } else { normalizeValue = scoreCalculator.normalize(getFinalSampleValue(vo.getSampleValue(), threshold)); } + //反正切函数 [-pi/2,pi/2] + if (idx.getScoreCalculator().getMaxValue().compareTo(idx.getScoreCalculator().getMinValue()) == 0) { + normalizeValue = new BigDecimal(Math.atan(new Double(vo.getSampleValue().toString())) / Math.PI * 100).setScale(6, RoundingMode.HALF_UP); + } BigDecimal score = normalizeValue.multiply(weight).setScale(6, RoundingMode.HALF_UP); CalculateResult result = scoreCountOfSamples.get(sampleId); diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenCustomerAgencyDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenCustomerAgencyDao.xml index 7963aefd4c..49ce41b17c 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenCustomerAgencyDao.xml +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenCustomerAgencyDao.xml @@ -128,4 +128,9 @@ + + diff --git a/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/normalizing/DemoScoreCal.java b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/normalizing/DemoScoreCal.java index 05a9360b47..556e4a6029 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/normalizing/DemoScoreCal.java +++ b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/normalizing/DemoScoreCal.java @@ -257,5 +257,33 @@ public class DemoScoreCal { System.err.println("-----------------2222222222---------------"); } + @Test + public void testMath() { + // 每个指标需要单独的分支计算器,因为每个指标的最大最小值是不同的 + ScoreCalculator sc1 = new BigDecimalScoreCalculator(new BigDecimal(8), new BigDecimal(8), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE); + ScoreCalculator sc2 = new BigDecimalScoreCalculator(new BigDecimal(10), new BigDecimal(10), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE); + + List> index1SampleValues = Arrays.asList(new SampleValue<>("id1", 4), new SampleValue<>("id2", 1), new SampleValue<>("id3", 8)); + List> index2SampleValues = Arrays.asList(new SampleValue<>("id1", 1), new SampleValue<>("id2", 8), new SampleValue<>("id3", 3)); + + // 每个指标的信息,包括样本列表,权重,指标标记 + IndexInputVO index1VO = new IndexInputVO<>("aaa", "a:bbb2", index1SampleValues, new BigDecimal(10), new BigDecimal(1), false, sc1); + IndexInputVO index2VO = new IndexInputVO<>("bbb", "a:bbb2", index2SampleValues, new BigDecimal(10), new BigDecimal(1), false, sc2); + + List indexInputVOS = Arrays.asList(index1VO, index2VO); + + BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator(); + HashMap result = batchScoreCalculator.getScoreTotalOfSampleId(indexInputVOS); + + System.err.println("--------------------------------"); + result.forEach((key, value) -> { + System.out.println(key.concat("的总得分为:") + value.getTotalScore()); + //System.out.println(JSON.toJSONString(indexInputVOS)); + value.getDetails().forEach(o -> System.out.println(JSON.toJSONString(o))); + }); + + System.err.println("--------------------------------"); + } + } diff --git a/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/normalizing/MathUtilTest.java b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/normalizing/MathUtilTest.java new file mode 100644 index 0000000000..bed5fc95b7 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/normalizing/MathUtilTest.java @@ -0,0 +1,17 @@ +package com.epmet.stats.test.normalizing; + +public class MathUtilTest { + public static void main(String[] args) { + double tan = Math.atan(4); + double tan2 = Math.atan(1); + double tan3 = Math.atan(8); + double tan4 = Math.atan(3); + + + System.out.println((tan / Math.PI)); + System.out.println((tan2 / Math.PI)); + System.out.println((tan3 / Math.PI)); + System.out.println((tan4 / Math.PI * 200)); + } + +}