|  |  |  | 
|---|
|  |  |  | package com.vincent.rsf.server.manager.schedules; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | 
|---|
|  |  |  | import com.vincent.rsf.framework.common.R; | 
|---|
|  |  |  | import com.vincent.rsf.framework.exception.CoolException; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.AsnOrder; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.AsnOrderItem; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.AsnOrderItemLog; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.AsnOrderLog; | 
|---|
|  |  |  | import com.vincent.rsf.server.api.controller.erp.params.ReportDataParam; | 
|---|
|  |  |  | import com.vincent.rsf.server.api.controller.erp.params.ReportParams; | 
|---|
|  |  |  | import com.vincent.rsf.server.api.service.ReportMsgService; | 
|---|
|  |  |  | import com.vincent.rsf.server.common.utils.FieldsUtils; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.*; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.enums.AsnExceStatus; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.enums.OrderType; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.AsnOrderItemLogService; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.AsnOrderItemService; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.AsnOrderLogService; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.AsnOrderService; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.enums.OrderWorkType; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.enums.POExceStatus; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.*; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.impl.TransferOrderServiceImpl; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.entity.User; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.service.UserService; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.service.impl.UserServiceImpl; | 
|---|
|  |  |  | import org.springframework.beans.BeanUtils; | 
|---|
|  |  |  | 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.ArrayList; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Set; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | public class AsnOrderLogSchedule { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private PurchaseService purchaseService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private DeliveryService deliveryService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AsnOrderService asnOrderService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AsnOrderItemService asnOrderItemService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AsnOrderLogService asnOrderLogService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AsnOrderItemLogService asnOrderItemLogService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TransferOrderService transferOrderService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TransferService transferService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private UserService userService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ReportMsgService reportMsgService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @description 删除已完成订单加入Log表 | 
|---|
|  |  |  | * @param | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @description 删除已完成订单加入Log表 | 
|---|
|  |  |  | * @time 2025/3/19 19:09 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Scheduled(cron = "0 0/05 * * * ?  ") | 
|---|
|  |  |  | @Scheduled(cron = "0/35 * * * * ?  ") | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public void moveOrderToLog() { | 
|---|
|  |  |  | List<AsnOrder> asnOrders = asnOrderService.list(new LambdaQueryWrapper<AsnOrder>() | 
|---|
|  |  |  | .eq(AsnOrder::getType, OrderType.ORDER_IN.type) | 
|---|
|  |  |  | .eq(AsnOrder::getExceStatus, AsnExceStatus.ASN_EXCE_STATUS_TASK_DONE.val)); | 
|---|
|  |  |  | if (asnOrders.isEmpty()) { | 
|---|
|  |  |  | public void InStockToLog() { | 
|---|
|  |  |  | List<WkOrder> wkOrders = asnOrderService.list(new LambdaQueryWrapper<WkOrder>() | 
|---|
|  |  |  | .eq(WkOrder::getType, OrderType.ORDER_IN.type) | 
|---|
|  |  |  | .eq(WkOrder::getExceStatus, AsnExceStatus.ASN_EXCE_STATUS_TASK_EXCE.val)); | 
|---|
|  |  |  | if (wkOrders.isEmpty()) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | moveOrderToLog(asnOrders, OrderType.ORDER_IN.type); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | moveOrderToLog(wkOrders, OrderType.ORDER_IN.type); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | throw new CoolException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @description 出库单完成后,状态修改 | 
|---|
|  |  |  | * @param | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | * @time 2025/6/16 08:35 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | * @param | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @description 出库单完成后,状态修改 | 
|---|
|  |  |  | * @time 2025/6/16 08:35 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Scheduled(cron = "0/30 * * * * ?  ") | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public void outStockComplete() { | 
|---|
|  |  |  | List<AsnOrder> asnOrders = asnOrderService.list(new LambdaQueryWrapper<AsnOrder>() | 
|---|
|  |  |  | .eq(AsnOrder::getType, OrderType.ORDER_OUT.type) | 
|---|
|  |  |  | .apply("anfme=work_qty") | 
|---|
|  |  |  | List<WkOrder> wkOrders = asnOrderService.list(new LambdaQueryWrapper<WkOrder>() | 
|---|
|  |  |  | .eq(WkOrder::getType, OrderType.ORDER_OUT.type) | 
|---|
|  |  |  | .eq(WkOrder::getExceStatus, AsnExceStatus.OUT_STOCK_STATUS_TASK_WORKING.val) | 
|---|
|  |  |  | .apply("anfme = qty") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if (asnOrders.isEmpty()) { | 
|---|
|  |  |  | if (wkOrders.isEmpty()) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | moveOrderToLog(asnOrders, OrderType.ORDER_OUT.type); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | moveOrderToLog(wkOrders, OrderType.ORDER_OUT.type); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | throw new CoolException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @date 2025/10/28 | 
|---|
|  |  |  | * @description: 上传已完成订单至ERP平台 | 
|---|
|  |  |  | * @version 1.0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public void reportOrders(List<WkOrder> orders) { | 
|---|
|  |  |  | orders.forEach(order -> { | 
|---|
|  |  |  | ReportParams params = new ReportParams(); | 
|---|
|  |  |  | List<WkOrderItem> orderItems = asnOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>().eq(WkOrderItem::getOrderId, order.getId())); | 
|---|
|  |  |  | if (orderItems.isEmpty()) { | 
|---|
|  |  |  | throw new CoolException("订据明细不存在!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<ReportDataParam> reportData = new ArrayList<>(); | 
|---|
|  |  |  | orderItems.forEach(orderItem -> { | 
|---|
|  |  |  | ReportDataParam param = new ReportDataParam(); | 
|---|
|  |  |  | User user = userService.getById(order.getUpdateBy()); | 
|---|
|  |  |  | String nickName = null; | 
|---|
|  |  |  | if (!Objects.isNull(user)) { | 
|---|
|  |  |  | nickName = user.getNickname(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, String> fields = FieldsUtils.getFields(orderItem.getFieldsIndex()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //设置通用参数 | 
|---|
|  |  |  | param.setWMSNO(order.getCode()) | 
|---|
|  |  |  | .setPONO(order.getPoCode()) | 
|---|
|  |  |  | .setOrderDate(order.getCreateTime()) | 
|---|
|  |  |  | .setItemCode(orderItem.getMatnrCode()) | 
|---|
|  |  |  | .setEditUser(nickName) | 
|---|
|  |  |  | .setEditDate(order.getUpdateTime()) | 
|---|
|  |  |  | .setGoodsNO(fields.get("crushNo")) | 
|---|
|  |  |  | .setMemoDtl(order.getMemo()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (order.getWkType().equals(OrderWorkType.ORDER_WORK_TYPE_DONE_IN.type)) { | 
|---|
|  |  |  | //采购入库单 | 
|---|
|  |  |  | params.setOrderType("PO_Instock").setAction("Update"); | 
|---|
|  |  |  | //获取指定查询字段CrushNo 票号 | 
|---|
|  |  |  | param.setInQty(orderItem.getQty()); | 
|---|
|  |  |  | } else if (order.getWkType().equals(OrderWorkType.ORDER_WORK_TYPE_PURCHASE_RETURN.type)) { | 
|---|
|  |  |  | //采购退货 | 
|---|
|  |  |  | params.setOrderType("PR_Outstock").setAction("Update"); | 
|---|
|  |  |  | param.setOutQty(orderItem.getQty()); | 
|---|
|  |  |  | } else if (order.getWkType().equals(OrderWorkType.ORDER_WORK_TYPE_PROD.type)) { | 
|---|
|  |  |  | //生产入库单 | 
|---|
|  |  |  | //                params.setOrderType("WO_Outstock").setAction("Update"); | 
|---|
|  |  |  | } else if (order.getWkType().equals(OrderWorkType.ORDER_WORK_TYPE_PURCHASE.type)) { | 
|---|
|  |  |  | //生产退料 | 
|---|
|  |  |  | params.setOrderType("WR_Instock").setAction("Update"); | 
|---|
|  |  |  | param.setInQty(orderItem.getQty()); | 
|---|
|  |  |  | } else if (order.getWkType().equals(OrderWorkType.ORDER_WORK_TYPE_RETURN_ORDER.type)) { | 
|---|
|  |  |  | //生产领料 | 
|---|
|  |  |  | params.setOrderType("WO_Outstock").setAction("Update"); | 
|---|
|  |  |  | param.setOutQty(orderItem.getQty()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } else if (order.getWkType().equals(OrderWorkType.ORDER_WORK_TYPE_PROD_ADDITION.type)) { | 
|---|
|  |  |  | //生产补料 | 
|---|
|  |  |  | params.setOrderType("WR_Instock_BL").setAction("Update"); | 
|---|
|  |  |  | param.setOutQty(orderItem.getQty()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } else if (order.getWkType().equals(OrderWorkType.ORDER_WORK_TYPE_OTHER_IN.type)) { | 
|---|
|  |  |  | //其它入库单/手动入库单 | 
|---|
|  |  |  | params.setOrderType("In_Instock").setAction("Update"); | 
|---|
|  |  |  | param.setInQty(orderItem.getQty()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } else if (order.getWkType().equals(OrderWorkType.ORDER_WORK_TYPE_OTHER.type)) { | 
|---|
|  |  |  | //其它出库单/手动出库单 | 
|---|
|  |  |  | params.setOrderType("Io_Outstock").setAction("Update"); | 
|---|
|  |  |  | param.setOutQty(orderItem.getQty()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | reportData.add(param); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | params.setData(reportData); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | R reported = reportMsgService.reportOrders(params); | 
|---|
|  |  |  | if (reported.get("code").equals(200)) { | 
|---|
|  |  |  | order.setNtyStatus(1); | 
|---|
|  |  |  | if (!asnOrderService.updateById(order)) { | 
|---|
|  |  |  | throw new CoolException("上报状态修改失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | //休眠3秒 | 
|---|
|  |  |  | Thread.sleep(3000); | 
|---|
|  |  |  | } catch (InterruptedException e) { | 
|---|
|  |  |  | throw new RuntimeException(e); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @param | 
|---|
|  |  |  | 
|---|
|  |  |  | * @description 添加历史单据 | 
|---|
|  |  |  | * @time 2025/6/16 08:56 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void moveOrderToLog(List<AsnOrder> asnOrders, String type) { | 
|---|
|  |  |  | Set<Long> longSet = asnOrders.stream().map(AsnOrder::getId).collect(Collectors.toSet()); | 
|---|
|  |  |  | List<AsnOrderItem> orderItems = asnOrderItemService.list(new LambdaQueryWrapper<AsnOrderItem>().in(AsnOrderItem::getAsnId, longSet)); | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public void moveOrderToLog(List<WkOrder> wkOrders, String type) { | 
|---|
|  |  |  | //上报已完成订单至ERP、MES等三方系统 | 
|---|
|  |  |  | reportOrders(wkOrders); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | Set<Long> longSet = wkOrders.stream().map(WkOrder::getId).collect(Collectors.toSet()); | 
|---|
|  |  |  | List<WkOrderItem> orderItems = asnOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>() | 
|---|
|  |  |  | .in(WkOrderItem::getOrderId, longSet)); | 
|---|
|  |  |  | if (orderItems.isEmpty()) { | 
|---|
|  |  |  | throw new CoolException("收货明细为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (AsnOrder order : asnOrders) { | 
|---|
|  |  |  | AsnOrderLog orderLog = new AsnOrderLog(); | 
|---|
|  |  |  | if (type.equals(OrderType.ORDER_OUT.type)) { | 
|---|
|  |  |  | order.setExceStatus(AsnExceStatus.ASN_EXCE_STATUS_TASK_DONE.val); | 
|---|
|  |  |  | order.setQty(order.getWorkQty()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BeanUtils.copyProperties(order, orderLog); | 
|---|
|  |  |  | orderLog.setId(null); | 
|---|
|  |  |  | orderLog.setAsnId(order.getId()); | 
|---|
|  |  |  | for (WkOrder order : wkOrders) { | 
|---|
|  |  |  | AsnOrderLog one = asnOrderLogService.getOne(new LambdaQueryWrapper<AsnOrderLog>().eq(AsnOrderLog::getCode, order.getCode()), false); | 
|---|
|  |  |  | if (Objects.isNull(one)) { | 
|---|
|  |  |  | AsnOrderLog orderLog = new AsnOrderLog(); | 
|---|
|  |  |  | if (type.equals(OrderType.ORDER_OUT.type)) { | 
|---|
|  |  |  | order.setExceStatus(AsnExceStatus.ASN_EXCE_STATUS_TASK_DONE.val); | 
|---|
|  |  |  | order.setQty(order.getWorkQty()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BeanUtils.copyProperties(order, orderLog); | 
|---|
|  |  |  | orderLog.setId(null); | 
|---|
|  |  |  | orderLog.setAsnId(order.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!asnOrderLogService.save(orderLog)) { | 
|---|
|  |  |  | throw new CoolException("主单历史档添加失败!!"); | 
|---|
|  |  |  | if (!asnOrderLogService.save(orderLog)) { | 
|---|
|  |  |  | throw new CoolException("主单历史档添加失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<AsnOrderItemLog> logs = new ArrayList<>(); | 
|---|
|  |  |  | List<WkOrderItem> items = asnOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>() | 
|---|
|  |  |  | .eq(WkOrderItem::getOrderId, order.getId())); | 
|---|
|  |  |  | items.forEach(item -> { | 
|---|
|  |  |  | AsnOrderItemLog itemLog = new AsnOrderItemLog(); | 
|---|
|  |  |  | BeanUtils.copyProperties(item, itemLog); | 
|---|
|  |  |  | itemLog.setAsnItemId(itemLog.getId()) | 
|---|
|  |  |  | .setId(null) | 
|---|
|  |  |  | .setMatnrId(item.getMatnrId()) | 
|---|
|  |  |  | .setLogId(orderLog.getId()) | 
|---|
|  |  |  | .setAsnId(item.getOrderId()); | 
|---|
|  |  |  | logs.add(itemLog); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!asnOrderItemLogService.saveBatch(logs)) { | 
|---|
|  |  |  | throw new CoolException("单据明细历史档保存失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //更新PO/DO单执行状态 | 
|---|
|  |  |  | if (type.equals(OrderType.ORDER_IN.type)) { | 
|---|
|  |  |  | if (order.getWkType().equals(OrderWorkType.ORDER_WORK_TYPE_OTHER_TERANSFER.type)) { | 
|---|
|  |  |  | order.setExceStatus(AsnExceStatus.ASN_EXCE_STATUS_TASK_DONE.val); | 
|---|
|  |  |  | if (!asnOrderService.updateById(order)) { | 
|---|
|  |  |  | throw new CoolException("单据状态更新失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //                        List<TransferOrder> orders = transferOrderService.list(new LambdaQueryWrapper<TransferOrder>().eq(TransferOrder::getTransferId, order.getPoId())); | 
|---|
|  |  |  | //                        if (orders.isEmpty()) { | 
|---|
|  |  |  | //                            throw new CoolException("数据错误:关联表信息不存在!!"); | 
|---|
|  |  |  | //                        } | 
|---|
|  |  |  | //                        Set<Long> orderIds = orders.stream().map(TransferOrder::getOrderId).collect(Collectors.toSet()); | 
|---|
|  |  |  | //                        if (!asnOrderItemService.remove(new LambdaQueryWrapper<WkOrderItem>() | 
|---|
|  |  |  | //                                .in(WkOrderItem::getOrderId, orderIds))) { | 
|---|
|  |  |  | //                            throw new CoolException("原单据明细删除失败!!"); | 
|---|
|  |  |  | //                        } | 
|---|
|  |  |  | //                        if (!this.asnOrderService.removeByIds(orderIds)) { | 
|---|
|  |  |  | //                            throw new CoolException("原单据删除失败!!"); | 
|---|
|  |  |  | //                        } | 
|---|
|  |  |  | if (!transferService.update(new LambdaUpdateWrapper<Transfer>() | 
|---|
|  |  |  | .eq(Transfer::getId, order.getPoId()) | 
|---|
|  |  |  | .set(Transfer::getExceStatus, AsnExceStatus.ASN_EXCE_STATUS_TASK_DONE.val))) { | 
|---|
|  |  |  | throw new CoolException("调拔单状态修改失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | if (!Objects.isNull(order.getPoId())) { | 
|---|
|  |  |  | purchaseService.update(new LambdaUpdateWrapper<Purchase>() | 
|---|
|  |  |  | .set(Purchase::getExceStatus, POExceStatus.PO_EXCE_STATUS_ALL_DONE.val) | 
|---|
|  |  |  | .eq(Purchase::getId, order.getPoId())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | if (order.getWkType().equals(OrderWorkType.ORDER_WORK_TYPE_STOCK_TERANSFER.type)) { | 
|---|
|  |  |  | order.setExceStatus(AsnExceStatus.OUT_STOCK_STATUS_TASK_DONE.val); | 
|---|
|  |  |  | if (!asnOrderService.updateById(order)) { | 
|---|
|  |  |  | throw new CoolException("单据状态更新失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //如果为调拔单据保留 | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | if (!Objects.isNull(order.getPoId())) { | 
|---|
|  |  |  | deliveryService.update(new LambdaUpdateWrapper<Delivery>() | 
|---|
|  |  |  | .eq(Delivery::getId, order.getPoId()) | 
|---|
|  |  |  | .set(Delivery::getExceStatus, POExceStatus.PO_EXCE_STATUS_ALL_DONE.val)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<AsnOrderItemLog> logs = new ArrayList<>(); | 
|---|
|  |  |  | List<AsnOrderItem> items = asnOrderItemService.list(new LambdaQueryWrapper<AsnOrderItem>().eq(AsnOrderItem::getAsnId, order.getId())); | 
|---|
|  |  |  | items.forEach(item -> { | 
|---|
|  |  |  | AsnOrderItemLog itemLog = new AsnOrderItemLog(); | 
|---|
|  |  |  | BeanUtils.copyProperties(item, itemLog); | 
|---|
|  |  |  | itemLog.setAsnItemId(itemLog.getId()) | 
|---|
|  |  |  | .setLogId(orderLog.getId()) | 
|---|
|  |  |  | .setAsnId(item.getAsnId()); | 
|---|
|  |  |  | logs.add(itemLog); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!asnOrderItemLogService.saveBatch(logs)) { | 
|---|
|  |  |  | throw new CoolException("单据明细历史档保存失败!!"); | 
|---|
|  |  |  | if (!asnOrderItemService.remove(new LambdaQueryWrapper<WkOrderItem>() | 
|---|
|  |  |  | .eq(WkOrderItem::getOrderId, order.getId()))) { | 
|---|
|  |  |  | throw new CoolException("原单据明细删除失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!asnOrderItemService.remove(new LambdaQueryWrapper<AsnOrderItem>().in(AsnOrderItem::getAsnId, longSet))) { | 
|---|
|  |  |  | throw new CoolException("原单据明细删除失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!this.asnOrderService.removeByIds(longSet)) { | 
|---|
|  |  |  | throw new CoolException("原单据删除失败!!"); | 
|---|
|  |  |  | if (!this.asnOrderService.removeById(order.getId())) { | 
|---|
|  |  |  | throw new CoolException("原单据删除失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|