diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/external/IndexCalculateController.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/external/IndexCalculateController.java index 29267ca44e..247dc31d7f 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/external/IndexCalculateController.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/external/IndexCalculateController.java @@ -1,5 +1,6 @@ package com.epmet.controller.external; +import com.alibaba.fastjson.JSON; import com.epmet.commons.tools.enums.EnvEnum; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.redis.RedisKeys; @@ -40,7 +41,7 @@ import java.util.concurrent.*; @RequestMapping("indexcalculate") public class IndexCalculateController { ThreadFactory namedThreadFactory = new ThreadFactoryBuilder() - .setNameFormat("indexcalculate-pool-%d").build(); + .setNameFormat("manual_execute_indexcal-pool-%d").build(); ExecutorService singleThreadPool = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); @@ -68,7 +69,7 @@ public class IndexCalculateController { CalculateFlagModel flag = (CalculateFlagModel) redisUtils.get(RedisKeys.getCustomerStatsCalFlag(customerId)); flag.setStatus(CalculateStatus.PENDDING); redisUtils.set(RedisKeys.getCustomerStatsCalFlag(customerId), flag); - log.info("客户【%s】正在执行计算,实例发生重启,修改计算状态为:calculation->pendding", customerId); + log.error("客户【%s】正在执行计算,实例发生重启,修改计算状态为:calculation->pendding", customerId); }); } @@ -97,7 +98,7 @@ public class IndexCalculateController { } /** - * 按照客户计算所有指标(按照月份) + * 这个是外部客户主动调用的方法入口 按照客户计算所有指标(按照月份) * * @param formDTO * @return com.epmet.commons.tools.utils.Result @@ -112,6 +113,35 @@ public class IndexCalculateController { return new Result().ok(true); } + @PostMapping("calSingle") + public Result calculateSingle(@RequestBody CalculateCommonFormDTO formDTO) { + long start = System.currentTimeMillis(); + try { + ValidatorUtils.validateEntity(formDTO); + Boolean aBoolean = indexCalculateService.indexCalculate(formDTO); + HttpClientManager.getInstance().sendAlarmMsg(EnvEnum.getCurrentEnv().getName() + "客户Id:" + formDTO.getCustomerId() + ";monthId:" + formDTO.getMonthId() + ",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("指标计算失败"); + } + + /** + * desc:异步 连续计算[指定或所有内部客户][多个月份]的指标得分入口 适用于公式调整后或之前计算错误 统一计算 + * @param formDTO + * @return + * @remark:不要轻易调用 因为异步 怕有冲突 + */ + @PostMapping("warn/moreStats") + public Result indexStatistics(@RequestBody IndexStatisticsFormDTO formDTO){ + log.error("moreStats 不要轻易调用 因为异步 怕有冲突,参数:{}", JSON.toJSONString(formDTO)); + indexCalculateService.indexStatistics(formDTO); + return new Result(); + } + /** * 指标计算 * @@ -202,21 +232,6 @@ public class IndexCalculateController { return new Result(); } - @PostMapping("reAll") - public Result calculateAll(@RequestBody CalculateCommonFormDTO formDTO) { - long start = System.currentTimeMillis(); - try { - Boolean aBoolean = indexCalculateService.indexCalculate(formDTO); - HttpClientManager.getInstance().sendAlarmMsg(EnvEnum.getCurrentEnv().getName() + "客户Id:" + formDTO.getCustomerId() + ";monthId:" + formDTO.getMonthId() + ",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("指标计算失败"); - } - /** * desc:计算党员指标分数 * @@ -343,12 +358,6 @@ public class IndexCalculateController { return new Result(); }*/ - @PostMapping("indexstatistics") - public Result indexStatistics(@RequestBody IndexStatisticsFormDTO formDTO){ - indexCalculateService.indexStatistics(formDTO); - return new Result(); - } - /** * @return com.epmet.commons.tools.utils.Result * @param formDTO diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/IndexCalculateService.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/IndexCalculateService.java index d5d41e48a3..cabc852377 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/IndexCalculateService.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/IndexCalculateService.java @@ -19,6 +19,11 @@ public interface IndexCalculateService { */ Boolean indexCalculate(CalculateCommonFormDTO formDTO); + /** + * desc:异步 连续计算[指定或所有内部客户][多个月份]的指标得分入口 + * @param formDTO + * @return + */ Boolean indexStatistics(IndexStatisticsFormDTO formDTO); /** 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 d1e449b4a0..b2d3c0b9d7 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 @@ -1,7 +1,9 @@ package com.epmet.service.evaluationindex.indexcal.impl; +import cn.hutool.core.collection.CollectionUtil; 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.enums.EnvEnum; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.utils.DateUtils; @@ -17,16 +19,16 @@ import com.epmet.redis.IndexCalRedis; import com.epmet.service.crm.CustomerRelationService; import com.epmet.service.evaluationindex.indexcal.*; import com.epmet.service.evaluationindex.indexcoll.FactIndexCollectService; +import com.epmet.service.stats.DimCustomerService; import com.epmet.util.DimIdGenerator; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.util.*; /** * @author liujianjun @@ -58,6 +60,8 @@ public class IndexCalculateServiceImpl implements IndexCalculateService { private ScreenCustomerAgencyDao screenCustomerAgencyDao; @Autowired private CustomerRelationService customerRelationService; + @Autowired + private DimCustomerService dimCustomerService; @Override public Boolean indexCalculate(CalculateCommonFormDTO formDTO) { @@ -67,14 +71,15 @@ public class IndexCalculateServiceImpl implements IndexCalculateService { formDTO.setMonthId(DimIdGenerator.getMonthDimId(DateUtils.addDateMonths(new Date(), -1))); } //按照客户分组 - List customerIds = new ArrayList<>(); + Set customerIds = new HashSet<>(); if (StringUtils.isBlank(formDTO.getCustomerId())) { + log.error("什么情况下走的这个方法,应该干掉他,因为...=====param:{}",JSON.toJSONString(formDTO)); Result> externalCustomerIdsResult = epmetCommonServiceOpenFeignClient.getExternalCustomerIds(); if (!externalCustomerIdsResult.success()) { log.error("indexCalculate epmetCommonServiceOpenFeignClient.getExternalCustomerIds return fail"); return false; } - customerIds = externalCustomerIdsResult.getData(); + customerIds.addAll(externalCustomerIdsResult.getData()); } else { customerIds.add(formDTO.getCustomerId()); } @@ -95,8 +100,7 @@ public class IndexCalculateServiceImpl implements IndexCalculateService { } return flag; } catch (Exception e) { - e.printStackTrace(); - log.warn("indexCalculate exception:{}",e); + log.warn("indexCalculate late exception",e); log.error("indexCalculate exception,param:{}", JSON.toJSONString(formDTO)); } finally { //清除缓存 @@ -212,12 +216,15 @@ public class IndexCalculateServiceImpl implements IndexCalculateService { public Boolean indexStatistics(IndexStatisticsFormDTO formDTO) { List customerIds = new ArrayList<>(); if (StringUtils.isEmpty(formDTO.getCustomerId())){ - Result> externalCustomerIds = epmetCommonServiceOpenFeignClient.getExternalCustomerIds(); - if (!externalCustomerIds.success()){ - log.error("indexCalculate epmetCommonServiceOpenFeignClient.getExternalCustomerIds return fail"); - return false; - } - customerIds = externalCustomerIds.getData(); + int pageNo = NumConstant.ONE; + int pageSize = NumConstant.ONE_HUNDRED; + List customerIdList = null; + do { + customerIdList = dimCustomerService.selectCustomerIdPage(pageNo++, pageSize); + if (!CollectionUtils.isEmpty(customerIdList)){ + customerIds.addAll(customerIdList); + } + } while (!CollectionUtil.isEmpty(customerIdList) && customerIdList.size() == pageSize); }else { customerIds.add(formDTO.getCustomerId()); } diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppServiceImpl.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppServiceImpl.java index 12f84f3456..b6dcf98dcf 100644 --- a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppServiceImpl.java +++ b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppServiceImpl.java @@ -187,7 +187,6 @@ public class ExternalAppServiceImpl implements ExternalAppService { @Override public List getCustomerIds() { - return externalAppDao.getCustomerIds(); } @@ -224,4 +223,4 @@ public class ExternalAppServiceImpl implements ExternalAppService { return appIdInfoResultDTO; } -} \ No newline at end of file +} diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalAppDao.xml b/epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalAppDao.xml index fbc74db7ff..8f401cb0f5 100644 --- a/epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalAppDao.xml +++ b/epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalAppDao.xml @@ -66,7 +66,7 @@ @@ -84,4 +84,4 @@ - \ No newline at end of file + diff --git a/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueServiceImpl.java b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueServiceImpl.java index 379eaf6444..70e8528491 100644 --- a/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueServiceImpl.java +++ b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueServiceImpl.java @@ -969,13 +969,13 @@ public class IssueServiceImpl extends BaseServiceImpl imp //1:查询议题数据 IssueEntity entity = baseDao.selectById(formDTO.getIssueId()); if (null == entity) { - throw new EpmetException(9999,IssueConstant.SELECT_EXCEPTION,IssueConstant.SELECT_EXCEPTION); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),IssueConstant.SELECT_EXCEPTION,IssueConstant.SELECT_EXCEPTION); } if (IssueConstant.ISSUE_SHIFT_PROJECT.equals(entity.getIssueStatus())) { - throw new EpmetException(9999,IssueConstant.ISSUE_SHIFT_PROJECT_EXCEPTION,IssueConstant.ISSUE_SHIFT_PROJECT_EXCEPTION); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),IssueConstant.ISSUE_SHIFT_PROJECT_EXCEPTION,IssueConstant.ISSUE_SHIFT_PROJECT_EXCEPTION); } if (!IssueConstant.ISSUE_VOTING.equals(entity.getIssueStatus())) { - throw new EpmetException(9999,IssueConstant.ISSUE_VOTING_EXCEPTION,IssueConstant.ISSUE_VOTING_EXCEPTION); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),IssueConstant.ISSUE_VOTING_EXCEPTION,IssueConstant.ISSUE_VOTING_EXCEPTION); } formDTO.setIssueDTO(ConvertUtils.sourceToTarget(entity, IssueDTO.class)); @@ -1007,7 +1007,7 @@ public class IssueServiceImpl extends BaseServiceImpl imp //2:调用resi-group查询话题创建人数据(目前议题来源只有来自话题),为了到项目服务初始数据以及发送消息使用 Result resultTopicDTO = resiGroupFeignClient.getTopicById(entity.getSourceId()); if (!resultTopicDTO.success() || null == resultTopicDTO.getData()) { - throw new EpmetException(9999,IssueConstant.SELECT_TOPIC_EXCEPTION,IssueConstant.SELECT_TOPIC_EXCEPTION); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),IssueConstant.SELECT_TOPIC_EXCEPTION,IssueConstant.SELECT_TOPIC_EXCEPTION); } ResiTopicDTO topicDTO = resultTopicDTO.getData(); formDTO.setTopicDTO(topicDTO); @@ -1019,7 +1019,7 @@ public class IssueServiceImpl extends BaseServiceImpl imp Result resultDTO = govProjectFeignClient.issueShiftProject(formDTO); if (!resultDTO.success() || null == resultDTO.getData()) { logger.error(resultDTO.getInternalMsg()); - throw new EpmetException(9999,IssueConstant.GOV_PRJECT_EXCEPTION,IssueConstant.GOV_PRJECT_EXCEPTION); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),IssueConstant.GOV_PRJECT_EXCEPTION,IssueConstant.GOV_PRJECT_EXCEPTION); } IssueProjectResultDTO issueProjectResultDTO = resultDTO.getData(); //更新项目对标签的引用次数 @@ -1054,7 +1054,7 @@ public class IssueServiceImpl extends BaseServiceImpl imp //5:调用epmet-message服务,给居民端话题创建人、议题发起人以及政府端工作人员发送消息 if (!shiftProjectMessage(issueProjectResultDTO, formDTO, entity).success()) { - throw new EpmetException(9999,IssueConstant.SAVE_MSG_EXCEPTION,IssueConstant.SAVE_MSG_EXCEPTION); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),IssueConstant.SAVE_MSG_EXCEPTION,IssueConstant.SAVE_MSG_EXCEPTION); } //5-1:2020.10.26 添加给居民端话题创建人、议题发起人以及政府端工作人员推送微信订阅消息功能 sun if (!wxmpShiftProjectMessage(issueProjectResultDTO, formDTO, entity).success()) {