Browse Source

增加终止计算方法

dev_shibei_match
wxz 5 years ago
parent
commit
6acf962060
  1. 6
      epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/indexcal/CalculateCommonFormDTO.java
  2. 26
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java

6
epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/indexcal/CalculateCommonFormDTO.java

@ -1,7 +1,9 @@
package com.epmet.dto.indexcal;
import com.epmet.commons.tools.validator.group.CustomerClientShowGroup;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
@ -13,6 +15,9 @@ import java.io.Serializable;
@Data
public class CalculateCommonFormDTO implements Serializable {
private static final long serialVersionUID = -5689788391963427717L;
public interface CancelCalculateGroup extends CustomerClientShowGroup {}
/**
* 月份id: yyyyMM
*/
@ -21,6 +26,7 @@ public class CalculateCommonFormDTO implements Serializable {
/**
* 客户id
*/
@NotBlank(message = "客户id不能为空", groups = { CancelCalculateGroup.class })
private String customerId;
public CalculateCommonFormDTO() {

26
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java

@ -7,6 +7,7 @@ import com.epmet.commons.tools.redis.RedisUtils;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.commons.tools.utils.HttpClientManager;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.dto.indexcal.CalculateCommonFormDTO;
import com.epmet.service.evaluationindex.indexcal.CpcIndexCalculateService;
import com.epmet.service.evaluationindex.indexcal.IndexCalculateService;
@ -21,6 +22,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.*;
/**
@ -52,6 +55,8 @@ public class IndexCalculateController {
// 计算同步锁
private Object statsCalLock = new Object();
private Map<String, Future> futureMap = new HashMap<>();
/**
* 按照客户计算所有指标(按照月份)
*
@ -72,7 +77,7 @@ public class IndexCalculateController {
log.error(String.format("该客户正在执行计算,请勿重复提交计算请求。", customerId));
return new Result<Boolean>().ok(false);
}
singleThreadPool.execute(() -> {
Future<?> future = singleThreadPool.submit(() -> {
formDTO.setCustomerId(customerId);
long start = System.currentTimeMillis();
Boolean aBoolean = indexCalculateService.indexCalculate(formDTO);
@ -80,7 +85,9 @@ public class IndexCalculateController {
log.error("客户Id:{},全部指标计算完成,总耗时:{}秒", customerId, (System.currentTimeMillis() - start) / 1000);
}
redisUtils.set(RedisKeys.getCustomerStatsCalFlag(customerId), false);
futureMap.remove(customerId);
});
futureMap.put(customerId, future);
redisUtils.set(RedisKeys.getCustomerStatsCalFlag(customerId), true);
}
} else {
@ -92,6 +99,23 @@ public class IndexCalculateController {
return new Result<Boolean>().ok(true);
}
/**
* 终止计算
* @param form
* @return
*/
@PostMapping("stopcalculate")
public Result stopcalculate(@RequestBody CalculateCommonFormDTO form) {
ValidatorUtils.validateEntity(form);
String customerId = form.getCustomerId();
Future future = this.futureMap.get(customerId);
if (future != null && !future.isCancelled()) {
future.cancel(true);
}
return new Result();
}
@PostMapping("reAll")
public Result<Boolean> calculateAll(@RequestBody CalculateCommonFormDTO formDTO) {
long start = System.currentTimeMillis();

Loading…
Cancel
Save