diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/redis/IndexCodeFieldReRedis.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/redis/IndexCodeFieldReRedis.java index 2863952420..8a99d62890 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/redis/IndexCodeFieldReRedis.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/redis/IndexCodeFieldReRedis.java @@ -51,4 +51,12 @@ public class IndexCodeFieldReRedis { hashOperations.putAll(RedisKeys.getIndexCodeFieldReKey(), records); redisTemplate.expire(RedisKeys.getIndexCodeFieldReKey(), 1, TimeUnit.DAYS); } + + /** + * desc:删除指标字段关系缓存 + * @return + */ + public Boolean deleteIndexCodeFromRedis() { + return redisTemplate.delete(RedisKeys.getIndexCodeFieldReKey()); + } } \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java index b7370217ed..dabeade3f1 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java @@ -1,5 +1,6 @@ package com.epmet.service.indexcal.impl; +import com.alibaba.fastjson.JSON; import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.constant.StrConstant; import com.epmet.commons.tools.exception.RenException; @@ -104,17 +105,18 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { Map indexCodeFieldReList = indexCodeFieldReService.getIndexCodeFieldReMap(); if (CollectionUtils.isEmpty(indexCodeFieldReList)) { log.error("cpcIndexCalculate have any indexcodefieldre"); - return; + throw new RenException("指标code与字段关系记录不存在"); } //计算最大最小值 Map minAndMaxMap = factIndexPartyAblityCpcMonthlyDao.getExtremeValue(formDTO.getCustomerId()); if (CollectionUtils.isEmpty(minAndMaxMap)) { log.error("cpcIndexCalculate getExtremeValue customerId:{} have not any fact record", formDTO.getCustomerId()); - return; + throw new RenException("指标原始数据记录不存在"); } //指标集合 Map> groupIndexDetailsMap = getIndexDetailMap(formDTO); if (groupIndexDetailsMap == null) { + log.error("calculatePartScore"); return; } @@ -152,7 +154,7 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { IndexInputVO value = entry.getValue(); String fieldName = indexCodeFieldReService.getFieldNameByIndexCode(indexCode); if (StringUtils.isBlank(fieldName)) { - log.error("cpcIndexCalculate fieldName error"); + log.error("calculateScore indexCode:{} get fieldName return blank", indexCode); continue; } @@ -179,9 +181,9 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { value.getIndexValueVOs().add(currentUserIndexValue); } } - log.warn("计算的参数:{}", indexMap); + log.info("计算的参数:{}", JSON.toJSONString(indexMap)); HashMap result = calculateScore(indexMap); - log.warn("计算的结果:{}", result); + log.info("计算的结果:{}", result); //处理结果 saveCpcScore(formDTO, scoreEntityMap, parentIndexCode, result); diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexCalculateServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexCalculateServiceImpl.java index 611ad18f4e..12bbbbad27 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexCalculateServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexCalculateServiceImpl.java @@ -1,14 +1,15 @@ package com.epmet.service.screen.impl; +import com.alibaba.fastjson.JSON; import com.epmet.commons.tools.utils.DateUtils; import com.epmet.commons.tools.utils.Result; -import com.epmet.dao.indexcoll.FactIndexPartyAblityCpcMonthlyDao; -import com.epmet.dao.screen.IndexGroupDao; -import com.epmet.dao.screen.IndexGroupDetailDao; import com.epmet.dto.indexcal.CalculateCommonFormDTO; import com.epmet.dto.screen.form.IndexCalculateForm; import com.epmet.feign.EpmetCommonServiceOpenFeignClient; +import com.epmet.redis.IndexCodeFieldReRedis; +import com.epmet.service.indexcal.CpcIndexCalculateService; import com.epmet.service.indexcal.GridCorreLationService; +import com.epmet.service.screen.IndexCalculateCommunityService; import com.epmet.service.screen.IndexCalculateService; import com.epmet.util.DimIdGenerator; import lombok.extern.slf4j.Slf4j; @@ -29,45 +30,65 @@ public class IndexCalculateServiceImpl implements IndexCalculateService { @Autowired private EpmetCommonServiceOpenFeignClient epmetCommonServiceOpenFeignClient; @Autowired - private FactIndexPartyAblityCpcMonthlyDao factIndexPartyAblityCpcMonthlyDao; - @Autowired private GridCorreLationService gridCorreLationService; @Autowired - private IndexGroupDao indexGroupDao; + private CpcIndexCalculateService cpcIndexCalculateService; + @Autowired + private IndexCodeFieldReRedis indexCodeFieldReRedis; @Autowired - private IndexGroupDetailDao indexGroupDetailDao; + private IndexCalculateCommunityService indexCalculateCommunityService; @Override public Boolean indexCalculate(IndexCalculateForm formDTO) { - if (StringUtils.isBlank(formDTO.getMonthId())) { - //默认 当前月份-1 - formDTO.setMonthId(DimIdGenerator.getMonthDimId(DateUtils.addDateMonths(new Date(), -1))); - } - //按照客户分组 - if (CollectionUtils.isEmpty(formDTO.getCustomerIds())) { - Result> externalCustomerIdsResult = epmetCommonServiceOpenFeignClient.getExternalCustomerIds(); - if (!externalCustomerIdsResult.success()) { - log.error("cpcIndexCalculate epmetCommonServiceOpenFeignClient.getExternalCustomerIds return fail"); - return false; + try { + if (StringUtils.isBlank(formDTO.getMonthId())) { + //默认 当前月份-1 + formDTO.setMonthId(DimIdGenerator.getMonthDimId(DateUtils.addDateMonths(new Date(), -1))); } - formDTO.setCustomerIds(externalCustomerIdsResult.getData()); - } - formDTO.getCustomerIds().forEach(customerId -> { - CalculateCommonFormDTO calculateCommonFormDTO=new CalculateCommonFormDTO(customerId, formDTO.getMonthId()); - //计算党员 - try { - //Map list = factIndexPartyAblityCpcMonthlyDao.getCountByMonthId(customerId, formDTO.getMonthId(), (pageNo - 1) * pageSize, pageSize); - } catch (Exception e) { - + //按照客户分组 + if (CollectionUtils.isEmpty(formDTO.getCustomerIds())) { + Result> externalCustomerIdsResult = epmetCommonServiceOpenFeignClient.getExternalCustomerIds(); + if (!externalCustomerIdsResult.success()) { + log.error("indexCalculate epmetCommonServiceOpenFeignClient.getExternalCustomerIds return fail"); + return false; + } + formDTO.setCustomerIds(externalCustomerIdsResult.getData()); } + formDTO.getCustomerIds().forEach(customerId -> { + CalculateCommonFormDTO calculateCommonFormDTO = new CalculateCommonFormDTO(customerId, formDTO.getMonthId()); + //计算党员相关的 + Boolean flag = false; + try { + CalculateCommonFormDTO param = new CalculateCommonFormDTO(customerId, formDTO.getMonthId()); + flag = cpcIndexCalculateService.cpcIndexCalculate(param); + log.info("indexCalculate cpcIndexCalculate return result:{}", flag); + } catch (Exception e) { + log.error("indexCalculate cpcIndexCalculate exception", e); + } - //计算网格 - //TODO - gridCorreLationService.calculateGridCorreLation(calculateCommonFormDTO); - //计算社区 - //TODO + //计算网格 + try { + flag = gridCorreLationService.calculateGridCorreLation(calculateCommonFormDTO); + log.info("indexCalculate calculateGridCorreLation return result:{}", flag); + } catch (Exception e) { + log.error("indexCalculate calculateGridCorreLation exception", e); + } + //计算社区 + try { + indexCalculateCommunityService.calAll(customerId, formDTO.getMonthId()); + log.info("indexCalculate calAll return result:{}", flag); + } catch (Exception e) { + log.error("indexCalculate calAll exception", e); + } - }); + }); + indexCodeFieldReRedis.deleteIndexCodeFromRedis(); + } catch (Exception e) { + log.error("indexCalculate exception,param:{}", JSON.toJSONString(formDTO)); + } finally { + //清除缓存 + indexCodeFieldReRedis.deleteIndexCodeFromRedis(); + } return true; } } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/BigDecimalScoreCalculator.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/BigDecimalScoreCalculator.java index fe0412ba3f..b86c347d24 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/BigDecimalScoreCalculator.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/BigDecimalScoreCalculator.java @@ -66,12 +66,18 @@ public class BigDecimalScoreCalculator extends ScoreCalculator { @Override public BigDecimal getMaxFromSourceArray() { + if (this.sourceArrary == null){ + return null; + } BigDecimal[] intSourceArrary = (BigDecimal[]) this.sourceArrary; return intSourceArrary[intSourceArrary.length - 1]; } @Override public BigDecimal getMinFromSourceArray() { + if (this.sourceArrary == null){ + return null; + } BigDecimal[] intSourceArrary = (BigDecimal[]) this.sourceArrary; return intSourceArrary[0]; }