|
|
@ -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(); |
|
|
|