From dae03d771fab3a074582f777fdb196871735b9f1 Mon Sep 17 00:00:00 2001 From: wxz Date: Fri, 11 Sep 2020 16:20:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=E4=B8=AD=E6=AD=A2?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=EF=BC=8C=E5=81=9C=E6=AD=A2=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=EF=BC=8C=E7=A4=BA=E4=BE=8B=E9=94=80=E6=AF=81=E9=83=BD=E4=BC=9A?= =?UTF-8?q?=E6=B8=85=E7=A9=BAredis=E7=9A=84=E8=AE=A1=E7=AE=97=E6=A0=87?= =?UTF-8?q?=E8=AE=B0=20=E5=81=9C=E6=AD=A2=E8=AE=A1=E7=AE=97=E5=92=8C?= =?UTF-8?q?=E4=B8=AD=E6=AD=A2=E8=AE=A1=E7=AE=97=E8=BF=98=E8=A6=81=E6=B8=85?= =?UTF-8?q?=E7=A9=BAfutureMap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/IndexCalculateController.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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(); }