工单优化

This commit is contained in:
guoshengxiong 2025-09-29 17:54:58 +08:00
parent 98791b9d6c
commit 7fc738861f
2 changed files with 55 additions and 12 deletions

View File

@ -27,12 +27,11 @@ import com.zhgd.xmgl.modules.quality.service.IQualityRegionService;
import com.zhgd.xmgl.modules.worker.entity.EnterpriseInfo; import com.zhgd.xmgl.modules.worker.entity.EnterpriseInfo;
import com.zhgd.xmgl.modules.worker.service.impl.EnterpriseInfoServiceImpl; import com.zhgd.xmgl.modules.worker.service.impl.EnterpriseInfoServiceImpl;
import com.zhgd.xmgl.modules.worker.service.impl.WorkerInfoServiceImpl; import com.zhgd.xmgl.modules.worker.service.impl.WorkerInfoServiceImpl;
import com.zhgd.xmgl.util.EntityUtils; import com.zhgd.xmgl.util.*;
import com.zhgd.xmgl.util.MapBuilder;
import com.zhgd.xmgl.util.PageUtil;
import com.zhgd.xmgl.util.RefUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -86,6 +85,9 @@ public class WorkTicketServiceImpl extends ServiceImpl<WorkTicketMapper, WorkTic
@Lazy @Lazy
@Autowired @Autowired
private IWorkTicketOrderService workTicketOrderService; private IWorkTicketOrderService workTicketOrderService;
@Autowired
@Qualifier("doubleCarbonExecutor")
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
@Override @Override
public IPage<WorkTicketVo> queryPageList(HashMap<String, Object> param) { public IPage<WorkTicketVo> queryPageList(HashMap<String, Object> param) {
@ -254,14 +256,6 @@ public class WorkTicketServiceImpl extends ServiceImpl<WorkTicketMapper, WorkTic
workTicketHistoryService.completeEndTimeByTicketId(ticketId); workTicketHistoryService.completeEndTimeByTicketId(ticketId);
} }
if (workTicketService.enableBindCamera(ticket.getProjectSn())) { if (workTicketService.enableBindCamera(ticket.getProjectSn())) {
PoliceCameraManufacturer manufacturer = policeCameraManufacturerFactory.getPoliceCameraManufacturer(ticket.getProjectSn());
if (manufacturer != null) {
if (workTicketDto.getOperateStatus() == 1 || workTicketDto.getOperateStatus() == 3) {
manufacturer.beginWork(ticket, his.getId() + "", his.getNo());
} else if (workTicketDto.getOperateStatus() == 2 || workTicketDto.getOperateStatus() == 4) {
manufacturer.endWork(ticket, his.getId() + "");
}
}
if (workTicketDto.getOperateStatus() == 1 || workTicketDto.getOperateStatus() == 3) { if (workTicketDto.getOperateStatus() == 1 || workTicketDto.getOperateStatus() == 3) {
for (PoliceCameraItem item : ticket.getItemList()) { for (PoliceCameraItem item : ticket.getItemList()) {
WorkTicketOrder order = new WorkTicketOrder(); WorkTicketOrder order = new WorkTicketOrder();
@ -284,6 +278,17 @@ public class WorkTicketServiceImpl extends ServiceImpl<WorkTicketMapper, WorkTic
.eq(WorkTicketOrder::getHistoryId, his.getId()) .eq(WorkTicketOrder::getHistoryId, his.getId())
); );
} }
WorkTicketHistory finalHis = his;
AsyncTaskUtil.runAsync(() -> {
PoliceCameraManufacturer manufacturer = policeCameraManufacturerFactory.getPoliceCameraManufacturer(ticket.getProjectSn());
if (manufacturer != null) {
if (workTicketDto.getOperateStatus() == 1 || workTicketDto.getOperateStatus() == 3) {
manufacturer.beginWork(ticket, finalHis.getId() + "", finalHis.getNo());
} else if (workTicketDto.getOperateStatus() == 2 || workTicketDto.getOperateStatus() == 4) {
manufacturer.endWork(ticket, finalHis.getId() + "");
}
}
});
} }
} }

View File

@ -0,0 +1,38 @@
package com.zhgd.xmgl.util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
@Component
public class AsyncTaskUtil {
private static ThreadPoolTaskExecutor doubleCarbonExecutor;
/**
* 执行异步任务
*/
public static CompletableFuture<Void> runAsync(Runnable task) {
return CompletableFuture.runAsync(task, doubleCarbonExecutor);
}
/**
* 执行异步任务并支持异常处理
*/
public static CompletableFuture<Void> runAsync(Runnable task, Consumer<Throwable> exceptionHandler) {
return CompletableFuture.runAsync(task, doubleCarbonExecutor)
.exceptionally(throwable -> {
exceptionHandler.accept(throwable);
return null;
});
}
@Autowired
public void setDoubleCarbonExecutor(@Qualifier("doubleCarbonExecutor") ThreadPoolTaskExecutor executor) {
AsyncTaskUtil.doubleCarbonExecutor = executor;
}
}