|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.wms.asrs.timer; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.plugins.IgnoreStrategy; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper; | 
|---|
|  |  |  | import com.zy.asrs.framework.exception.CoolException; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.entity.*; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.entity.enums.OrderSettleType; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.service.*; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.scheduling.annotation.Scheduled; | 
|---|
|  |  |  | import org.springframework.stereotype.Component; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Component | 
|---|
|  |  |  | public class TaskLogTimer { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TaskService taskService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TaskDetlService taskDetlService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TaskDetlFieldService taskDetlFieldService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TaskLogService taskLogService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TaskDetlLogService taskDetlLogService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TaskDetlFieldLogService taskDetlFieldLogService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private OrderService orderService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private OrderDetlService orderDetlService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Scheduled(cron = "0/3 * * * * ? ") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public void inExecute() { | 
|---|
|  |  |  | InterceptorIgnoreHelper.handle(IgnoreStrategy.builder().tenantLine(true).build()); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | //获取入库完成任务 | 
|---|
|  |  |  | List<Task> list = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getTaskSts, 100)); | 
|---|
|  |  |  | if (list.isEmpty()) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (Task task : list) { | 
|---|
|  |  |  | Long hostId = task.getHostId(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //保存任务历史档 | 
|---|
|  |  |  | TaskLog taskLog = new TaskLog(); | 
|---|
|  |  |  | taskLog.sync(task); | 
|---|
|  |  |  | if (!taskLogService.save(taskLog)) { | 
|---|
|  |  |  | throw new CoolException("保存任务历史档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //删除任务历史档案 | 
|---|
|  |  |  | if (!taskService.removeById(task.getId())) { | 
|---|
|  |  |  | throw new CoolException("删除任务档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //保存任务明细历史档 | 
|---|
|  |  |  | List<TaskDetl> taskDetls = taskDetlService.getTaskDetlByTaskId(task.getId()); | 
|---|
|  |  |  | if(taskDetls.isEmpty()) { | 
|---|
|  |  |  | throw new CoolException("任务明细不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (TaskDetl taskDetl : taskDetls) { | 
|---|
|  |  |  | TaskDetlLog taskDetlLog = new TaskDetlLog(); | 
|---|
|  |  |  | taskDetlLog.sync(taskDetl); | 
|---|
|  |  |  | if (!taskDetlLogService.save(taskDetlLog)) { | 
|---|
|  |  |  | throw new CoolException("保存任务明细历史档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //保存明细扩展字段历史档 | 
|---|
|  |  |  | List<TaskDetlField> detlFields = taskDetlFieldService.list(new LambdaQueryWrapper<TaskDetlField>().eq(TaskDetlField::getDetlId, taskDetl.getId()).eq(TaskDetlField::getHostId, hostId)); | 
|---|
|  |  |  | for (TaskDetlField detlField : detlFields) { | 
|---|
|  |  |  | //明细扩展字段数据保存至历史档 | 
|---|
|  |  |  | TaskDetlFieldLog taskDetlFieldLog = new TaskDetlFieldLog(); | 
|---|
|  |  |  | taskDetlFieldLog.sync(detlField); | 
|---|
|  |  |  | if (!taskDetlFieldLogService.save(taskDetlFieldLog)) { | 
|---|
|  |  |  | throw new CoolException("明细扩展字段转历史档案失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //删除明细扩展 | 
|---|
|  |  |  | boolean removeField = taskDetlFieldService.removeById(detlField.getId()); | 
|---|
|  |  |  | if(!removeField){ | 
|---|
|  |  |  | throw new CoolException("删除明细扩展失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //删除明细 | 
|---|
|  |  |  | boolean removeDetl = taskDetlService.removeById(taskDetl.getId()); | 
|---|
|  |  |  | if(!removeDetl){ | 
|---|
|  |  |  | throw new CoolException("明细删除失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //更新订单信息 | 
|---|
|  |  |  | for (TaskDetl taskDetl : taskDetls) { | 
|---|
|  |  |  | OrderDetl orderDetl = orderDetlService.getById(taskDetl.getDetlId()); | 
|---|
|  |  |  | if (orderDetl == null) { | 
|---|
|  |  |  | throw new CoolException("订单明细不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | orderDetl.setWorkQty(orderDetl.getWorkQty() - taskDetl.getAnfme());//工作中数量减少 | 
|---|
|  |  |  | orderDetl.setQty(orderDetl.getQty() + taskDetl.getAnfme());//已完成数量增加 | 
|---|
|  |  |  | orderDetl.setUpdateTime(new Date()); | 
|---|
|  |  |  | if (!orderDetlService.updateById(orderDetl)) { | 
|---|
|  |  |  | throw new CoolException("更新订单明细失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //检测订单是否完成 | 
|---|
|  |  |  | boolean checkOrderComplete = orderService.checkOrderComplete(orderDetl.getOrderId()); | 
|---|
|  |  |  | if (checkOrderComplete) { | 
|---|
|  |  |  | //订单已经完成 | 
|---|
|  |  |  | Order order = orderService.getById(orderDetl.getOrderId()); | 
|---|
|  |  |  | if(order == null) { | 
|---|
|  |  |  | throw new CoolException("订单不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | order.setOrderSettle(OrderSettleType.COMPLETE.val()); | 
|---|
|  |  |  | order.setUpdateTime(new Date()); | 
|---|
|  |  |  | if (!orderService.save(order)) { | 
|---|
|  |  |  | throw new CoolException("订单更新失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | }finally { | 
|---|
|  |  |  | InterceptorIgnoreHelper.clearIgnoreStrategy(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Scheduled(cron = "0/3 * * * * ? ") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public void outExecute() { | 
|---|
|  |  |  | InterceptorIgnoreHelper.handle(IgnoreStrategy.builder().tenantLine(true).build()); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | }finally { | 
|---|
|  |  |  | InterceptorIgnoreHelper.clearIgnoreStrategy(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | package com.zy.asrs.wms.asrs.timer; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.plugins.IgnoreStrategy; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.DateUtils; | 
|---|
|  |  |  | import com.zy.asrs.framework.exception.CoolException; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.entity.*; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.entity.enums.OrderSettleType; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.entity.enums.TaskStsType; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.service.*; | 
|---|
|  |  |  | import com.zy.asrs.wms.system.entity.Dict; | 
|---|
|  |  |  | import com.zy.asrs.wms.system.service.DictService; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.scheduling.annotation.Scheduled; | 
|---|
|  |  |  | import org.springframework.stereotype.Component; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.transaction.interceptor.TransactionAspectSupport; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Collections; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Component | 
|---|
|  |  |  | public class TaskLogTimer { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TaskService taskService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TaskDetlService taskDetlService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TaskDetlFieldService taskDetlFieldService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TaskLogService taskLogService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TaskDetlLogService taskDetlLogService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TaskDetlFieldLogService taskDetlFieldLogService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private OrderService orderService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private OrderDetlService orderDetlService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private DictService dictService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WaveService waveService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @date 2025/6/20 | 
|---|
|  |  |  | * @description: 入库任务已完成 | 
|---|
|  |  |  | * @version 1.0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Scheduled(cron = "0/15 * * * * ? ") | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public void inExecute() { | 
|---|
|  |  |  | InterceptorIgnoreHelper.handle(IgnoreStrategy.builder().tenantLine(true).build()); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | //获取入库完成任务 | 
|---|
|  |  |  | List<Task> list = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getTaskSts, TaskStsType.UPDATED_IN.id)); | 
|---|
|  |  |  | if (list.isEmpty()) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (Task task : list) { | 
|---|
|  |  |  | Long hostId = task.getHostId(); | 
|---|
|  |  |  | //保存任务历史档 | 
|---|
|  |  |  | TaskLog taskLog = new TaskLog(); | 
|---|
|  |  |  | taskLog.sync(task); | 
|---|
|  |  |  | taskLog.setId(null); | 
|---|
|  |  |  | if (!taskLogService.save(taskLog)) { | 
|---|
|  |  |  | throw new CoolException("保存任务历史档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //保存任务明细历史档 | 
|---|
|  |  |  | List<TaskDetl> taskDetls = taskDetlService.getTaskDetlByTaskId(task.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (taskDetls.isEmpty()) { | 
|---|
|  |  |  | throw new CoolException("任务明细不存在"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | //任务类型为53,根据WaveId修改订单明细 | 
|---|
|  |  |  | for (TaskDetl taskDetl : taskDetls) { | 
|---|
|  |  |  | if (taskDetl.getDetlId() == null) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | OrderDetl orderDetl = orderDetlService.getById(taskDetl.getDetlId()); | 
|---|
|  |  |  | if (orderDetl == null) { | 
|---|
|  |  |  | throw new CoolException("订单明细不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | orderDetl.setWorkQty(orderDetl.getWorkQty() - taskDetl.getAnfme());//工作中数量减少 | 
|---|
|  |  |  | orderDetl.setQty(orderDetl.getQty() + taskDetl.getAnfme());//已完成数量增加 | 
|---|
|  |  |  | orderDetl.setUpdateTime(new Date()); | 
|---|
|  |  |  | if (!orderDetlService.updateById(orderDetl)) { | 
|---|
|  |  |  | throw new CoolException("更新订单明细失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //检测订单是否完成 | 
|---|
|  |  |  | boolean checkOrderComplete = orderService.checkOrderComplete(orderDetl.getOrderId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (checkOrderComplete) { | 
|---|
|  |  |  | //订单已经完成 | 
|---|
|  |  |  | Order order = orderService.getById(orderDetl.getOrderId()); | 
|---|
|  |  |  | if (order == null) { | 
|---|
|  |  |  | throw new CoolException("订单不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | order.setOrderSettle(OrderSettleType.COMPLETE.val()); | 
|---|
|  |  |  | order.setUpdateTime(new Date()); | 
|---|
|  |  |  | if (!orderService.updateById(order)) { | 
|---|
|  |  |  | throw new CoolException("订单更新失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //删除任务历史档案 | 
|---|
|  |  |  | if (!taskService.removeById(task.getId())) { | 
|---|
|  |  |  | throw new CoolException("删除任务档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (TaskDetl taskDetl : taskDetls) { | 
|---|
|  |  |  | TaskDetlLog taskDetlLog = new TaskDetlLog(); | 
|---|
|  |  |  | taskDetlLog.sync(taskDetl); | 
|---|
|  |  |  | taskDetlLog.setOrderId(taskDetl.getOrderId()); | 
|---|
|  |  |  | taskDetlLog.setId(null); | 
|---|
|  |  |  | taskDetlLog.setTaskId(taskLog.getId()); | 
|---|
|  |  |  | if (!taskDetlLogService.save(taskDetlLog)) { | 
|---|
|  |  |  | throw new CoolException("保存任务明细历史档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //保存明细扩展字段历史档 | 
|---|
|  |  |  | List<TaskDetlField> detlFields = taskDetlFieldService.list(new LambdaQueryWrapper<TaskDetlField>().eq(TaskDetlField::getDetlId, taskDetl.getId()).eq(TaskDetlField::getHostId, hostId)); | 
|---|
|  |  |  | for (TaskDetlField detlField : detlFields) { | 
|---|
|  |  |  | //明细扩展字段数据保存至历史档 | 
|---|
|  |  |  | TaskDetlFieldLog taskDetlFieldLog = new TaskDetlFieldLog(); | 
|---|
|  |  |  | taskDetlFieldLog.sync(detlField); | 
|---|
|  |  |  | taskDetlFieldLog.setId(null); | 
|---|
|  |  |  | taskDetlFieldLog.setDetlId(taskDetlLog.getId()); | 
|---|
|  |  |  | if (!taskDetlFieldLogService.save(taskDetlFieldLog)) { | 
|---|
|  |  |  | throw new CoolException("明细扩展字段转历史档案失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //删除明细扩展 | 
|---|
|  |  |  | boolean removeField = taskDetlFieldService.removeById(detlField.getId()); | 
|---|
|  |  |  | if (!removeField) { | 
|---|
|  |  |  | throw new CoolException("删除明细扩展失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //删除明细 | 
|---|
|  |  |  | boolean removeDetl = taskDetlService.removeById(taskDetl.getId()); | 
|---|
|  |  |  | if (!removeDetl) { | 
|---|
|  |  |  | throw new CoolException("明细删除失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); | 
|---|
|  |  |  | } finally { | 
|---|
|  |  |  | InterceptorIgnoreHelper.clearIgnoreStrategy(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @date 2025/6/20 | 
|---|
|  |  |  | * @description: 出库任务完成 | 
|---|
|  |  |  | * @version 1.0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Scheduled(cron = "0/35 * * * * ? ") | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public void outExecute() { | 
|---|
|  |  |  | InterceptorIgnoreHelper.handle(IgnoreStrategy.builder().tenantLine(true).build()); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | //获取出库完成任务 | 
|---|
|  |  |  | List<Task> list = taskService.list(new LambdaQueryWrapper<Task>() | 
|---|
|  |  |  | .eq(Task::getTaskSts, TaskStsType.UPDATED_OUT.id) | 
|---|
|  |  |  | .ge(Task::getTaskType, 101)); | 
|---|
|  |  |  | if (list.isEmpty()) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (Task task : list) { | 
|---|
|  |  |  | Long hostId = task.getHostId(); | 
|---|
|  |  |  | //保存任务明细历史档 | 
|---|
|  |  |  | List<TaskDetl> taskDetls = taskDetlService.getTaskDetlByTaskId(task.getId()); | 
|---|
|  |  |  | if (taskDetls.isEmpty()) { | 
|---|
|  |  |  | throw new CoolException("任务明细不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | boolean flag = false; | 
|---|
|  |  |  | for (TaskDetl taskDetl : taskDetls) { | 
|---|
|  |  |  | if (taskDetl.getWaveId() == null) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Wave wave = waveService.getById(taskDetl.getWaveId()); | 
|---|
|  |  |  | if (wave != null) { | 
|---|
|  |  |  | flag = true;//波次未完成 | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (flag) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //保存任务历史档 | 
|---|
|  |  |  | TaskLog taskLog = new TaskLog(); | 
|---|
|  |  |  | taskLog.sync(task); | 
|---|
|  |  |  | taskLog.setId(null); | 
|---|
|  |  |  | if (!taskLogService.save(taskLog)) { | 
|---|
|  |  |  | throw new CoolException("保存任务历史档失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | //更新订单信息 | 
|---|
|  |  |  | taskDetls.forEach(taskDetl -> { | 
|---|
|  |  |  | if (taskDetl.getDetlId() != null) { | 
|---|
|  |  |  | OrderDetl orderDetl = orderDetlService.getById(taskDetl.getDetlId()); | 
|---|
|  |  |  | if (orderDetl == null) { | 
|---|
|  |  |  | throw new CoolException("订单明细不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | orderDetl.setWorkQty(orderDetl.getWorkQty() - taskDetl.getAnfme());//工作中数量减少 | 
|---|
|  |  |  | orderDetl.setQty(orderDetl.getQty() + taskDetl.getAnfme());//已完成数量增加 | 
|---|
|  |  |  | orderDetl.setUpdateTime(new Date()); | 
|---|
|  |  |  | if (!orderDetlService.updateById(orderDetl)) { | 
|---|
|  |  |  | throw new CoolException("更新订单明细失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //检测订单是否完成 | 
|---|
|  |  |  | boolean checkOrderComplete = orderService.checkOrderComplete(orderDetl.getOrderId()); | 
|---|
|  |  |  | if (checkOrderComplete) { | 
|---|
|  |  |  | //订单已经完成 | 
|---|
|  |  |  | Order order = orderService.getById(orderDetl.getOrderId()); | 
|---|
|  |  |  | if (order == null) { | 
|---|
|  |  |  | throw new CoolException("订单不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | order.setOrderSettle(OrderSettleType.COMPLETE.val()); | 
|---|
|  |  |  | order.setUpdateTime(new Date()); | 
|---|
|  |  |  | if (!orderService.updateById(order)) { | 
|---|
|  |  |  | throw new CoolException("订单更新失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //删除任务历史档案 | 
|---|
|  |  |  | if (!taskService.removeById(task.getId())) { | 
|---|
|  |  |  | throw new CoolException("删除任务档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (TaskDetl taskDetl : taskDetls) { | 
|---|
|  |  |  | TaskDetlLog taskDetlLog = new TaskDetlLog(); | 
|---|
|  |  |  | taskDetlLog.sync(taskDetl); | 
|---|
|  |  |  | taskDetlLog.setId(null); | 
|---|
|  |  |  | taskDetlLog.setTaskId(taskLog.getId()); | 
|---|
|  |  |  | if (!taskDetlLogService.save(taskDetlLog)) { | 
|---|
|  |  |  | throw new CoolException("保存任务明细历史档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //保存明细扩展字段历史档 | 
|---|
|  |  |  | List<TaskDetlField> detlFields = taskDetlFieldService.list(new LambdaQueryWrapper<TaskDetlField>().eq(TaskDetlField::getDetlId, taskDetl.getId()).eq(TaskDetlField::getHostId, hostId)); | 
|---|
|  |  |  | for (TaskDetlField detlField : detlFields) { | 
|---|
|  |  |  | //明细扩展字段数据保存至历史档 | 
|---|
|  |  |  | TaskDetlFieldLog taskDetlFieldLog = new TaskDetlFieldLog(); | 
|---|
|  |  |  | taskDetlFieldLog.sync(detlField); | 
|---|
|  |  |  | taskDetlFieldLog.setId(null); | 
|---|
|  |  |  | taskDetlFieldLog.setDetlId(taskDetlLog.getId()); | 
|---|
|  |  |  | if (!taskDetlFieldLogService.save(taskDetlFieldLog)) { | 
|---|
|  |  |  | throw new CoolException("明细扩展字段转历史档案失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //删除明细扩展 | 
|---|
|  |  |  | boolean removeField = taskDetlFieldService.removeById(detlField.getId()); | 
|---|
|  |  |  | if (!removeField) { | 
|---|
|  |  |  | throw new CoolException("删除明细扩展失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //删除明细 | 
|---|
|  |  |  | boolean removeDetl = taskDetlService.removeById(taskDetl.getId()); | 
|---|
|  |  |  | if (!removeDetl) { | 
|---|
|  |  |  | throw new CoolException("明细删除失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); | 
|---|
|  |  |  | } finally { | 
|---|
|  |  |  | InterceptorIgnoreHelper.clearIgnoreStrategy(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|