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 003813df2b..e1e2c85d78 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 @@ -8,6 +8,8 @@ import com.epmet.dto.indexcal.CalculateCommonFormDTO; import com.epmet.service.evaluationindex.indexcal.CpcIndexCalculateService; import com.epmet.service.evaluationindex.indexcal.IndexCalculateService; import com.epmet.util.DimIdGenerator; +import com.google.common.util.concurrent.ThreadFactoryBuilder; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; @@ -16,6 +18,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.Date; +import java.util.concurrent.*; /** * 指标计算controller @@ -23,9 +26,16 @@ import java.util.Date; * @author liujianjun@elink-cn.com * @date 2020/8/24 14:38 */ +@Slf4j @RestController @RequestMapping("indexcalculate") public class IndexCalculateController { + ThreadFactory namedThreadFactory = new ThreadFactoryBuilder() + .setNameFormat("indexcalculate-pool-%d").build(); + ExecutorService singleThreadPool = new ThreadPoolExecutor(1, 1, + 0L, TimeUnit.MILLISECONDS, + new LinkedBlockingQueue(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); + @Autowired private IndexCalculateService indexCalculateService; @@ -44,12 +54,15 @@ public class IndexCalculateController { @ExternalAppRequestAuth @PostMapping("all") public Result indexCalculate(ExternalAppRequestParam externalAppRequestParam, @RequestBody CalculateCommonFormDTO formDTO) { - formDTO.setCustomerId(externalAppRequestParam.getCustomerId()); - Boolean aBoolean = indexCalculateService.indexCalculate(formDTO); - if (aBoolean) { - return new Result().ok(true); - } - return new Result().error("指标计算失败"); + singleThreadPool.execute(() -> { + formDTO.setCustomerId(externalAppRequestParam.getCustomerId()); + long start = System.currentTimeMillis(); + Boolean aBoolean = indexCalculateService.indexCalculate(formDTO); + if (aBoolean) { + log.error("全部指标计算完成,总耗时:{}秒", (System.currentTimeMillis() - start) / 1000); + } + }); + return new Result().ok(true); } @PostMapping("reAll")