|
@ -21,6 +21,7 @@ import org.springframework.web.bind.annotation.RequestBody; |
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.PreDestroy; |
|
|
import java.util.Date; |
|
|
import java.util.Date; |
|
|
import java.util.HashMap; |
|
|
import java.util.HashMap; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
@ -57,6 +58,15 @@ public class IndexCalculateController { |
|
|
|
|
|
|
|
|
private Map<String, Future> futureMap = new HashMap<>(); |
|
|
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") |
|
|
@PostMapping("all") |
|
|
public Result<Boolean> indexCalculate(ExternalAppRequestParam externalAppRequestParam, @RequestBody CalculateCommonFormDTO formDTO) { |
|
|
public Result<Boolean> indexCalculate(ExternalAppRequestParam externalAppRequestParam, @RequestBody CalculateCommonFormDTO formDTO) { |
|
|
String customerId = externalAppRequestParam.getCustomerId(); |
|
|
String customerId = externalAppRequestParam.getCustomerId(); |
|
|
|
|
|
//String customerId = "epmettest";
|
|
|
Boolean executing = (Boolean) redisUtils.get(RedisKeys.getCustomerStatsCalFlag(customerId)); |
|
|
Boolean executing = (Boolean) redisUtils.get(RedisKeys.getCustomerStatsCalFlag(customerId)); |
|
|
if (executing == null || !executing) { |
|
|
if (executing == null || !executing) { |
|
|
synchronized (statsCalLock) { |
|
|
synchronized (statsCalLock) { |
|
@ -84,7 +95,7 @@ public class IndexCalculateController { |
|
|
if (aBoolean) { |
|
|
if (aBoolean) { |
|
|
log.error("客户Id:{},全部指标计算完成,总耗时:{}秒", customerId, (System.currentTimeMillis() - start) / 1000); |
|
|
log.error("客户Id:{},全部指标计算完成,总耗时:{}秒", customerId, (System.currentTimeMillis() - start) / 1000); |
|
|
} |
|
|
} |
|
|
redisUtils.set(RedisKeys.getCustomerStatsCalFlag(customerId), false); |
|
|
redisUtils.delete(RedisKeys.getCustomerStatsCalFlag(customerId)); |
|
|
futureMap.remove(customerId); |
|
|
futureMap.remove(customerId); |
|
|
}); |
|
|
}); |
|
|
futureMap.put(customerId, future); |
|
|
futureMap.put(customerId, future); |
|
@ -104,6 +115,7 @@ public class IndexCalculateController { |
|
|
* @param form |
|
|
* @param form |
|
|
* @return |
|
|
* @return |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
@ExternalAppRequestAuth |
|
|
@PostMapping("stopcalculate") |
|
|
@PostMapping("stopcalculate") |
|
|
public Result stopcalculate(@RequestBody CalculateCommonFormDTO form) { |
|
|
public Result stopcalculate(@RequestBody CalculateCommonFormDTO form) { |
|
|
ValidatorUtils.validateEntity(form); |
|
|
ValidatorUtils.validateEntity(form); |
|
@ -112,6 +124,9 @@ public class IndexCalculateController { |
|
|
Future future = this.futureMap.get(customerId); |
|
|
Future future = this.futureMap.get(customerId); |
|
|
if (future != null && !future.isCancelled()) { |
|
|
if (future != null && !future.isCancelled()) { |
|
|
future.cancel(true); |
|
|
future.cancel(true); |
|
|
|
|
|
redisUtils.delete(RedisKeys.getCustomerStatsCalFlag(customerId)); |
|
|
|
|
|
futureMap.remove(customerId); |
|
|
|
|
|
HttpClientManager.getInstance().sendAlarmMsg(String.format("数据统计服务-中止计算成功,customerId:%s", customerId)); |
|
|
} |
|
|
} |
|
|
return new Result(); |
|
|
return new Result(); |
|
|
} |
|
|
} |
|
|