Browse Source

修改:中止计算,停止计算,示例销毁都会清空redis的计算标记

停止计算和中止计算还要清空futureMap
master
wxz 5 years ago
parent
commit
dae03d771f
  1. 17
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java

17
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<String, Future> 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<Boolean> 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();
}

Loading…
Cancel
Save