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 596a1f17ad..1a48df14d5 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 @@ -21,6 +21,7 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.annotation.PreDestroy; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -57,6 +58,15 @@ public class IndexCalculateController { private Map futureMap = new HashMap<>(); + @PreDestroy + public void clearDataCalFlag() { + // 实例销毁之前,将正在本实例中执行计算的客户列表的计算状态清空 + futureMap.forEach((customerId, future) -> { + redisUtils.delete(RedisKeys.getCustomerStatsCalFlag(customerId)); + }); + } + + /** * 按照客户计算所有指标(按照月份) * @@ -69,6 +79,7 @@ public class IndexCalculateController { @PostMapping("all") public Result indexCalculate(ExternalAppRequestParam externalAppRequestParam, @RequestBody CalculateCommonFormDTO formDTO) { String customerId = externalAppRequestParam.getCustomerId(); + //String customerId = "epmettest"; Boolean executing = (Boolean) redisUtils.get(RedisKeys.getCustomerStatsCalFlag(customerId)); if (executing == null || !executing) { synchronized (statsCalLock) { @@ -84,7 +95,7 @@ public class IndexCalculateController { if (aBoolean) { log.error("客户Id:{},全部指标计算完成,总耗时:{}秒", customerId, (System.currentTimeMillis() - start) / 1000); } - redisUtils.set(RedisKeys.getCustomerStatsCalFlag(customerId), false); + redisUtils.delete(RedisKeys.getCustomerStatsCalFlag(customerId)); futureMap.remove(customerId); }); futureMap.put(customerId, future); @@ -104,6 +115,7 @@ public class IndexCalculateController { * @param form * @return */ + @ExternalAppRequestAuth @PostMapping("stopcalculate") public Result stopcalculate(@RequestBody CalculateCommonFormDTO form) { ValidatorUtils.validateEntity(form); @@ -112,6 +124,9 @@ public class IndexCalculateController { Future future = this.futureMap.get(customerId); if (future != null && !future.isCancelled()) { future.cancel(true); + redisUtils.delete(RedisKeys.getCustomerStatsCalFlag(customerId)); + futureMap.remove(customerId); + HttpClientManager.getInstance().sendAlarmMsg(String.format("数据统计服务-中止计算成功,customerId:%s", customerId)); } return new Result(); }