打印日志

This commit is contained in:
Guoqs
2024-09-10 11:42:06 +08:00
parent 6a2bfe75c5
commit 409307db85
2 changed files with 48 additions and 3 deletions

View File

@@ -9,6 +9,7 @@ import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.response.RestApiResponse;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.spring.SpringUtils;
import com.jsowell.pile.dto.QueryConnectorListDTO;
import com.jsowell.pile.dto.QueryStationDTO;
import com.jsowell.pile.dto.RemoteGroundLockDTO;
@@ -17,10 +18,11 @@ import com.jsowell.pile.vo.base.ConnectorInfoVO;
import com.jsowell.pile.vo.base.MerchantInfoVO;
import com.jsowell.pile.vo.uniapp.customer.BillingPriceVO;
import com.jsowell.pile.vo.web.ThirdPartySnRelationVO;
import com.jsowell.web.controller.pile.PileConnectorInfoController;
import com.jsowell.thirdparty.common.CommonService;
import com.jsowell.web.controller.pile.PileConnectorInfoController;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.util.StopWatch;
import org.springframework.web.bind.annotation.*;
@@ -61,6 +63,9 @@ public class PileController extends BaseController {
@Autowired
private CommonService commonService;
// 引入线程池
private ThreadPoolTaskExecutor executor = SpringUtils.getBean("threadPoolTaskExecutor");
/**
* 查询充电站信息列表(主页)
@@ -222,8 +227,6 @@ public class PileController extends BaseController {
}
}
@PostMapping("/selectConnectorInfoList")
public RestApiResponse<?> selectConnectorInfoList(@RequestBody QueryConnectorListDTO dto) {
RestApiResponse<?> response = null;
@@ -260,6 +263,42 @@ public class PileController extends BaseController {
return response;
}
@PostMapping("/selectConnectorInfoListV2")
public RestApiResponse<?> selectConnectorInfoListV2(@RequestBody QueryConnectorListDTO dto) {
RestApiResponse<?> response = null;
try {
// List<ConnectorInfoVO> connectorInfoVOS = pileConnectorInfoService.selectConnectorInfoList(pileSn);
CompletableFuture<List<ConnectorInfoVO>> connectorInfoListFuture = CompletableFuture.supplyAsync(() -> pileConnectorInfoService.selectConnectorInfoList(dto.getPileSn()), executor);
logger.info("查询充电枪口详情-supplyAsync-selectConnectorInfoList:{}", connectorInfoListFuture);
// 查计费模板信息
CompletableFuture<List<BillingPriceVO>> billingPriceFuture = CompletableFuture.supplyAsync(() -> pileBillingTemplateService.queryBillingPrice(dto.getStationId()), executor);
logger.info("查询充电枪口详情-supplyAsync-queryBillingPrice:{}", billingPriceFuture);
// 查询运营商信息
CompletableFuture<MerchantInfoVO> merchantInfoVOFuture = CompletableFuture.supplyAsync(() -> pileMerchantInfoService.getMerchantInfoVO(dto.getMerchantId()), executor);
logger.info("查询充电枪口详情-supplyAsync-getMerchantInfoVO:{}", merchantInfoVOFuture);
CompletableFuture<Void> all = CompletableFuture.allOf(connectorInfoListFuture, merchantInfoVOFuture, billingPriceFuture);
// .join()和.get()都会阻塞并获取线程的执行情况
// .join()会抛出未经检查的异常,不会强制开发者处理异常 .get()会抛出检查异常,需要开发者处理
all.join();
all.get();
Map<String, Object> map = Maps.newHashMap();
map.put("connectorInfoList", connectorInfoListFuture.get());
map.put("billingPriceList", billingPriceFuture.get());
map.put("merchantInfoVO", merchantInfoVOFuture.get());
response = new RestApiResponse<>(map);
}catch (Exception e) {
logger.error("查询充电枪口详情 error", e);
response = new RestApiResponse<>(e);
}
logger.info("查询充电枪口详情 response:{}", response);
return response;
}
@PostMapping("/selectConnectorInfoListNo")
public RestApiResponse<?> selectConnectorInfoListNo(@RequestBody QueryConnectorListDTO dto) {
RestApiResponse<?> response = null;

View File

@@ -2,6 +2,8 @@ package com.jsowell.framework.config;
import com.jsowell.common.util.Threads;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
@@ -17,6 +19,8 @@ import java.util.concurrent.ThreadPoolExecutor;
**/
@Configuration
public class ThreadPoolConfig {
Logger log = LoggerFactory.getLogger(ThreadPoolConfig.class);
// 核心线程池大小
private final int corePoolSize = 50;
@@ -41,6 +45,7 @@ public class ThreadPoolConfig {
executor.setKeepAliveSeconds(keepAliveSeconds);
// 线程池对拒绝任务(无线程可用)的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
log.info("threadPoolTaskExecutor创建成功");
return executor;
}
@@ -49,6 +54,7 @@ public class ThreadPoolConfig {
*/
@Bean(name = "scheduledExecutorService")
protected ScheduledExecutorService scheduledExecutorService() {
log.info("scheduledExecutorService创建成功");
return new ScheduledThreadPoolExecutor(corePoolSize,
new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build(),
new ThreadPoolExecutor.CallerRunsPolicy()) {