| package com.vincent.rsf.server.manager.service.impl; | 
|   | 
| import com.alibaba.fastjson.JSONArray; | 
| import com.alibaba.fastjson.JSONObject; | 
| 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.api.entity.dto.PoItemsDto; | 
| import com.vincent.rsf.server.api.service.ReceiveMsgService; | 
| import com.vincent.rsf.server.api.service.ReportMsgService; | 
| import com.vincent.rsf.server.common.utils.DateUtils; | 
| import com.vincent.rsf.server.manager.controller.dto.DashboardDto; | 
| import com.vincent.rsf.server.manager.controller.dto.StockTrandDto; | 
| import com.vincent.rsf.server.manager.controller.dto.StockTransItemDto; | 
| import com.vincent.rsf.server.manager.controller.params.AsnOrderAndItemsParams; | 
| import com.vincent.rsf.server.manager.controller.params.BatchUpdateParam; | 
| import com.vincent.rsf.server.manager.entity.*; | 
| import com.vincent.rsf.server.manager.enums.*; | 
| import com.vincent.rsf.server.manager.mapper.AsnOrderMapper; | 
| import com.vincent.rsf.server.manager.service.*; | 
| import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
| import com.vincent.rsf.server.system.constant.SerialRuleCode; | 
| import com.vincent.rsf.server.system.mapper.SerialRuleMapper; | 
| import com.vincent.rsf.server.system.utils.SerialRuleUtils; | 
| import org.apache.commons.lang3.StringUtils; | 
| import org.springframework.beans.BeanUtils; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.transaction.annotation.Transactional; | 
|   | 
| import javax.annotation.Resource; | 
| import java.text.DateFormat; | 
| import java.text.ParsePosition; | 
| import java.text.SimpleDateFormat; | 
| import java.util.*; | 
| import java.util.stream.Collectors; | 
|   | 
| /** | 
|  * @author Ryan | 
|  * @description | 
|  * @throws | 
|  * @return | 
|  * @time 2025/3/7 08:02 | 
|  */ | 
| @Service("asnOrderService") | 
| public class AsnOrderServiceImpl extends ServiceImpl<AsnOrderMapper, WkOrder> implements AsnOrderService { | 
|   | 
|     @Autowired | 
|     private ReceiveMsgService receiveMsgService; | 
|     @Autowired | 
|     private ReportMsgService reportMsgService; | 
|   | 
|     @Autowired | 
|     private AsnOrderItemService asnOrderItemService; | 
|     @Autowired | 
|     private AsnOrderLogService asnOrderLogService; | 
|     @Autowired | 
|     private AsnOrderItemLogService asnOrderItemLogService; | 
|     @Resource | 
|     private SerialRuleMapper serialRuleMapper; | 
|     @Autowired | 
|     private MatnrService matnrService; | 
|     @Autowired | 
|     private PurchaseService purchaseService; | 
|     @Autowired | 
|     private PurchaseItemService purchaseItemService; | 
|     @Autowired | 
|     private AsnOrderService asnOrderService; | 
|     @Autowired | 
|     private TaskService taskService; | 
|   | 
|     @Override | 
|     public boolean notifyInspect(List<WkOrder> orders) { | 
|         if (orders.isEmpty()) { | 
|             throw new CoolException("上报参数不能为空!!"); | 
|         } | 
|         Set<Long> asnIds = orders.stream().map(WkOrder::getId).collect(Collectors.toSet()); | 
|         if (asnIds.isEmpty()) { | 
|             throw new CoolException("ASN单据不能为空!!"); | 
|         } | 
|         List<PoItemsDto> items = purchaseService.poList(asnIds); | 
|         if (items.isEmpty()) { | 
|             throw new CoolException("物料所属采购单据不存在!!"); | 
|         } | 
|         if (reportMsgService.reportInspectNotify(items)) { | 
|             return true; | 
|         } else { | 
|             return false; | 
|         } | 
|     } | 
|   | 
|     @Override | 
|     public List<WkOrder> getListByMatnr(Map<String, String> params) { | 
|         if (Objects.isNull(params)) { | 
|             throw new CoolException("查询条件不能为空!!"); | 
|         } | 
|         List<WkOrderItem> orderItems = asnOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>() | 
|                 .like(!Objects.isNull(params.get("maktx")), WkOrderItem::getMaktx, params.get("maktx")) | 
|                 .eq(!Objects.isNull(params.get("matnrCode")), WkOrderItem::getMatnrCode, params.get("matnrCode"))); | 
|         if (orderItems.isEmpty()) { | 
|             return new ArrayList<>(); | 
|         } | 
|         List<Long> longList = orderItems.stream().map(WkOrderItem::getOrderId).collect(Collectors.toList()); | 
|   | 
|         return this.listByIds(longList); | 
|     } | 
|   | 
|     @Override | 
|     @Transactional(rollbackFor = Exception.class) | 
|     public R saveOrderAndItems(AsnOrderAndItemsParams params, Long loginUserId) throws Exception { | 
|         if (Objects.isNull(params.getOrders())) { | 
|             throw new CoolException("主单信息不能为空"); | 
|         } | 
|         WkOrder orders = params.getOrders(); | 
|         if (Objects.isNull(orders)) { | 
|             throw new CoolException("单据不能为空!!"); | 
|         } | 
|         String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_ASN_ORDER, orders); | 
|         if (Objects.isNull(ruleCode)) { | 
|             throw new CoolException("收货通知单编码生成失败!!"); | 
|         } | 
|         orders.setCode(ruleCode) | 
|                 .setUpdateBy(loginUserId) | 
|                 .setCreateBy(loginUserId); | 
|         if (!this.save(orders)) { | 
|             throw new CoolException("主单保存失败!!"); | 
|         } | 
|         if (params.getItems().isEmpty()) { | 
|             throw new CoolException("收货通知单明细不能为空!!"); | 
|         } | 
|         params.setOrders(orders); | 
|   | 
|         svaeOrUpdateOrderItem(params, loginUserId); | 
|   | 
|         return R.ok("保存成功!!"); | 
|     } | 
|   | 
|     /** | 
|      * 表单明细修改 | 
|      * | 
|      * @param params | 
|      * @param loginUserId | 
|      * @return | 
|      */ | 
|     @Override | 
|     @Transactional(rollbackFor = Exception.class) | 
|     public R updateOrderItem(AsnOrderAndItemsParams params, Long loginUserId) throws Exception { | 
|         WkOrder orders = params.getOrders(); | 
|         if (Objects.isNull(orders)) { | 
|             throw new CoolException("主单信息不能为空!!"); | 
|         } | 
|         if (Objects.isNull(orders.getId())) { | 
|             throw new CoolException("数据错误:单据ID不能为空!!"); | 
|         } | 
|         if (!this.updateById(orders)) { | 
|             throw new CoolException("主单修改失败!!"); | 
|         } | 
|         if (Objects.isNull(params.getItems()) || params.getItems().isEmpty()) { | 
|             return R.ok("明细参数不能为空!!"); | 
|         } | 
|   | 
|         svaeOrUpdateOrderItem(params, loginUserId); | 
|   | 
|         return R.ok("修改完成!!"); | 
|     } | 
|   | 
|     /** | 
|      * @param | 
|      * @return | 
|      * @author Ryan | 
|      * @description 更新或保存明细 | 
|      * @time 2025/4/7 13:28 | 
|      */ | 
|     @Transactional(rollbackFor = Exception.class) | 
|     public void svaeOrUpdateOrderItem(AsnOrderAndItemsParams params, Long loginUserId) throws Exception { | 
|         WkOrder orders = params.getOrders(); | 
|         params.getItems().forEach(item -> { | 
|             item.put("orderId", orders.getId()); | 
|             item.put("orderCode", orders.getCode()); | 
|             item.put("poCode", orders.getPoCode()); | 
|             item.put("createBy", loginUserId); | 
|             item.put("updateBy", loginUserId); | 
|             if (!asnOrderItemService.fieldsSave(item, loginUserId)) { | 
|                 throw new CoolException("明细保存失败!!"); | 
|             } | 
|         }); | 
|         List<WkOrderItem> orderItems = asnOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>() | 
|                 .eq(WkOrderItem::getOrderId, params.getOrders().getId())); | 
|         double sum = orderItems.stream().mapToDouble(WkOrderItem::getAnfme).sum(); | 
|         orders.setAnfme(sum); | 
|         if (!this.updateById(orders)) { | 
|             throw new CoolException("计划收货数量修改失败!!"); | 
|         } | 
|     } | 
|   | 
|     /** | 
|      * @param | 
|      * @return | 
|      * @author Ryan | 
|      * @description 批量修改 | 
|      * @time 2025/4/1 07:58 | 
|      */ | 
|     @Override | 
|     public boolean batchUpdate(BatchUpdateParam params, Long userId) { | 
|         WkOrder order = params.getOrder(); | 
|         if (Objects.isNull(order)) { | 
|             throw new CoolException("修改参数不能为空!!"); | 
|         } | 
|         return this.update(new LambdaUpdateWrapper<WkOrder>() | 
|                 .in(WkOrder::getId, params.getIds()) | 
|                 .set(!Objects.isNull(order.getRleStatus()), WkOrder::getRleStatus, order.getRleStatus()) | 
|                 .set(!Objects.isNull(order.getNtyStatus()), WkOrder::getNtyStatus, order.getNtyStatus()) | 
|                 .set(!Objects.isNull(order.getStatus()), WkOrder::getStatus, order.getStatus()) | 
|                 .set(!Objects.isNull(order.getWkType()), WkOrder::getWkType, order.getWkType()) | 
|                 .set(!Objects.isNull(order.getExceStatus()), WkOrder::getExceStatus, order.getExceStatus()) | 
|                 .set(WkOrder::getUpdateBy, userId)); | 
|     } | 
|   | 
|     /** | 
|      * @param id | 
|      * @param loginUserId | 
|      * @return | 
|      * @author Ryan | 
|      * @description 一键收货 | 
|      * @time 2025/4/3 15:45 | 
|      */ | 
|     @Override | 
|     @Transactional(rollbackFor = Exception.class) | 
|     public R completeOrder(Long id, Long loginUserId) { | 
|         WkOrder wkOrder = this.getById(id); | 
|         if (Objects.isNull(wkOrder)) { | 
|             throw new CoolException("单据不存在!!"); | 
|         } | 
|         //一键加入历史档 | 
|         try { | 
|             operateOrderLogs(wkOrder); | 
|         } catch (Exception e) { | 
|             throw new CoolException("收货完成失败!!"); | 
|         } | 
|         return R.ok("收货成功!!"); | 
|     } | 
|   | 
|     @Override | 
|     @Transactional(rollbackFor = Exception.class) | 
|     public R closeOrder(Long id) { | 
|         WkOrder order = this.getById(id); | 
|         if (Objects.isNull(order)) { | 
|             throw new CoolException("单据不存在!!"); | 
|         } | 
|         try { | 
|             operateOrderLogs(order); | 
|         } catch (Exception e) { | 
|             throw new CoolException("单据关闭失败!!"); | 
|         } | 
|         return null; | 
|     } | 
|   | 
|     /** | 
|      * @author Ryan | 
|      * @date 2025/5/13 | 
|      * @description: 根据PO单创建ASN单 | 
|      * @version 1.0 | 
|      */ | 
|     @Override | 
|     @Transactional(rollbackFor = Exception.class) | 
|     public R createByPo(Map<String, Object> params) { | 
|         Long purchaseId = Long.parseLong(params.get("purchaseId").toString()); | 
|         List<PurchaseItem> itemList = JSONArray.parseArray(JSONObject.toJSONString(params.get("items")), PurchaseItem.class); | 
|         if (itemList.isEmpty()) { | 
|             throw new CoolException("PO单明细不能为空!!"); | 
|         } | 
|         Purchase purchase = purchaseService.getOne(new LambdaQueryWrapper<Purchase>().eq(Purchase::getId, purchaseId)); | 
|         if (Objects.isNull(purchase)) { | 
|             throw new CoolException("PO单据不存在!!"); | 
|         } | 
|         WkOrder order = new WkOrder(); | 
|         //根据编码规则生成ASN单号 | 
|         String code = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_ASN_ORDER, purchase); | 
|         order.setCode(code) | 
|                 .setArrTime(purchase.getPreArr()) | 
|                 .setType(purchase.getType()) | 
|                 .setWkType(purchase.getWkType()) | 
|                 .setPoId(purchase.getId()) | 
|                 .setPoCode(purchase.getCode()); | 
|         if (!this.save(order)) { | 
|             throw new CoolException("ASN单据保存失败!!"); | 
|         } | 
|         List<WkOrderItem> orderItems = new ArrayList<>(); | 
|         for (PurchaseItem item : itemList) { | 
|             WkOrderItem orderItem = new WkOrderItem(); | 
|             Matnr matnr = matnrService.getOne(new LambdaQueryWrapper<Matnr>().eq(Matnr::getCode, item.getMatnrCode())); | 
|             if (Objects.isNull(matnr)) { | 
|                 throw new CoolException("数据错误:当前物料不存在!!"); | 
|             } | 
|             String trackCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_LABEL_CODE, item); | 
|             if (StringUtils.isBlank(trackCode)) { | 
|                 throw new CoolException("单据跟踪码生成失败:请检查「sys_asn_mantr_label」是否配置完成!!"); | 
|             } | 
|   | 
|             PurchaseItem service = purchaseItemService.getById(item.getId()); | 
|             Double qty = Math.round((service.getQty() + item.getAnfme()) * 10000) / 10000.0; | 
|             if (qty.compareTo(service.getAnfme()) > 0) { | 
|                 throw new CoolException("新建单据数量不能大于计划数量!!"); | 
|             } | 
|             orderItem.setAnfme(item.getAnfme()) | 
|                     .setOrderId(order.getId()) | 
|                     .setSplrName(item.getSplrName()) | 
|                     .setOrderCode(code) | 
|                     .setSplrBatch(item.getSplrBatch()) | 
|                     .setSplrCode(item.getSplrCode()) | 
|                     .setPoDetlId(item.getId()) | 
|                     .setPlatItemId(item.getPlatItemId()) | 
|                     .setTrackCode(trackCode) | 
|                     .setPoCode(purchase.getCode()) | 
|                     .setPurQty(item.getAnfme()) | 
|                     .setStockUnit(item.getUnit()) | 
|                     .setPurUnit(item.getUnit()) | 
|                     .setMatnrCode(matnr.getCode()) | 
|                     .setMaktx(matnr.getName()) | 
|                     .setMatnrId(matnr.getId()); | 
|             orderItems.add(orderItem); | 
|   | 
|             PurchaseItem purchaseItem = purchaseItemService.getOne(new LambdaQueryWrapper<PurchaseItem>().eq(PurchaseItem::getId, item.getId())); | 
|             if (Objects.isNull(purchaseItem)) { | 
|                 throw new CoolException("单据不存在!!"); | 
|             } | 
|   | 
|             Double toQty = Math.round((purchaseItem.getQty() + item.getAnfme()) * 10000) / 10000.0; | 
|             purchaseItem.setQty(toQty); | 
|             if (!purchaseItemService.updateById(purchaseItem)) { | 
|                 throw new CoolException("PO单明细修改失败!!"); | 
|             } | 
|         } | 
|   | 
|         double sum = orderItems.stream().mapToDouble(WkOrderItem::getAnfme).sum(); | 
|   | 
|         if (!asnOrderItemService.saveBatch(orderItems)) { | 
|             throw new CoolException(("Asn单据明细保存失败!!")); | 
|         } | 
|         //任务执行完成,修改已完成数量和PO单执行状态 | 
|         Double qty = Math.round((sum + purchase.getQty()) * 10000) / 10000.0; | 
|         purchase.setQty(qty) | 
|                 .setExceStatus(POExceStatus.PO_EXCE_STATUS_EXCE_ING.val); | 
|   | 
|         if (!purchaseService.saveOrUpdate(purchase)) { | 
|             throw new CoolException("PO单执行完成后,保存失败!!"); | 
|         } | 
|         order.setAnfme(sum); | 
|         if (!this.updateById(order)) { | 
|             throw new CoolException("单据更新失败!!"); | 
|         } | 
|   | 
|         return R.ok("操作成功!!"); | 
|     } | 
|   | 
|     /** | 
|      * @author Ryan | 
|      * @date 2025/5/14 | 
|      * @description: 移除收货单 | 
|      * @version 1.0 | 
|      */ | 
|     @Override | 
|     @Transactional(rollbackFor = Exception.class) | 
|     public R removeOrders(List<Long> ids) { | 
|         for (Long id : ids) { | 
|             List<WkOrderItem> list = asnOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>() | 
|                     .eq(WkOrderItem::getOrderId, id)); | 
|             if (list.isEmpty()) { | 
|                 continue; | 
|             } | 
|   | 
|             list.forEach(item -> { | 
|                 PurchaseItem purchaseItem = purchaseItemService.getById(item.getPoDetlId()); | 
|                 if (!Objects.isNull(purchaseItem)) { | 
|                     Double minusQty = Math.round((purchaseItem.getQty() - item.getAnfme()) * 10000) / 10000.0; | 
|                     purchaseItem.setQty(minusQty); | 
|                     if (!purchaseItemService.updateById(purchaseItem)) { | 
|                         throw new CoolException("PO单明细更新失败!!"); | 
|                     } | 
|                 } | 
|             }); | 
|   | 
|             double sum = list.stream().mapToDouble(WkOrderItem::getAnfme).sum(); | 
|   | 
|             Purchase purchase = purchaseService.getOne(new LambdaQueryWrapper<Purchase>() | 
|                     .eq(Purchase::getCode, list.stream().findFirst().get().getPoCode())); | 
|             if (!Objects.isNull(purchase)) { | 
|                 Double qty = Math.round((purchase.getQty() - sum) * 10000) / 10000.0; | 
|                 purchase.setQty(qty) | 
|                         .setExceStatus(POExceStatus.PO_EXCE_STATUS_EXCE_ING.val); | 
|   | 
|                 if (!purchaseService.updateById(purchase)) { | 
|                     throw new CoolException("PO单据更新失败!!"); | 
|                 } | 
|             } | 
|         } | 
|   | 
|         if (!this.remove(new LambdaQueryWrapper<WkOrder>() | 
|                 .in(WkOrder::getId, ids) | 
|                 .eq(WkOrder::getExceStatus, AsnExceStatus.ASN_EXCE_STATUS_UN_EXCE.val))) { | 
|             throw new CoolException("任务中单据不可删除!!"); | 
|         } | 
|   | 
|         if (!asnOrderItemService.remove(new LambdaQueryWrapper<WkOrderItem>() | 
|                 .in(WkOrderItem::getOrderId, ids))) { | 
| //            throw new CoolException("Details Delete Fail"); | 
|         } | 
|   | 
|         return R.ok("操作成功!!"); | 
|     } | 
|   | 
|     /** | 
|      * 获取首页表头数据 | 
|      * @return | 
|      */ | 
|     @Override | 
|     public R getDashbord() { | 
|         DashboardDto dto = new DashboardDto(); | 
|         //获取入库数量 | 
|         DashboardDto trandDto = this.baseMapper.getDashbord(OrderType.ORDER_IN.type, TaskType.TASK_TYPE_IN.type + ""); | 
|         dto.setInAnf(trandDto.getAnfme()).setTaskIn(trandDto.getRealAnfme()).setTotalIn(trandDto.getAnfme() + trandDto.getRealAnfme()); | 
|   | 
|         //获取出库单数量 | 
|         DashboardDto outTrand = this.baseMapper.getDashbord(OrderType.ORDER_OUT.type, TaskType.TASK_TYPE_OUT.type + ""); | 
|         dto.setOutAnf(outTrand.getAnfme()).setTaskOut(outTrand.getRealAnfme()).setTotalOut(outTrand.getAnfme() + outTrand.getRealAnfme()); | 
|   | 
|         //获取执行中任务数量 | 
|         List<Task> tasks = taskService.list(new LambdaQueryWrapper<>()); | 
|         if (!tasks.isEmpty()) { | 
|             dto.setTaskQty(tasks.size()); | 
|         } | 
|         return R.ok().add(dto); | 
|     } | 
|   | 
|     /** | 
|      * 获取出入库趋势 | 
|      * @return | 
|      */ | 
|     @Override | 
|     public R getStockTrand() { | 
|         List<String> days = DateUtils.getLastMonthDays("yyyy-MM-dd"); | 
|         LambdaQueryWrapper<StockStatistic> queryWrapper = new LambdaQueryWrapper<StockStatistic>() | 
|                 .in(StockStatistic::getTaskType, Arrays.asList(TaskType.TASK_TYPE_IN.type, TaskType.TASK_TYPE_OUT.type)); | 
|        List<StockTransItemDto> items = this.baseMapper.getStockTrand(queryWrapper); | 
|        if (items.isEmpty()) { | 
|            return R.ok(); | 
|        } | 
|        List<StockTransItemDto> stockDtos = new ArrayList<>(); | 
|        days.forEach(day -> { | 
|            StockTransItemDto itemDto = new StockTransItemDto(); | 
|            itemDto.setInQty(0).setOutQty(0).setOutAnfme(0).setOutAnfme(0); | 
|            items.forEach(item -> { | 
|                if (item.getOrderTime().equals(day)) { | 
|                    BeanUtils.copyProperties(item, itemDto); | 
|                } | 
|            }); | 
|            itemDto.setOrderTime(day); | 
|            stockDtos.add(itemDto); | 
|        }); | 
|   | 
|        //获取最大值 | 
|         Optional<Integer> max = stockDtos.stream().map(StockTransItemDto::getInQty).filter(Objects::nonNull).max(Comparator.naturalOrder()); | 
|         Optional<Integer> maxOut = stockDtos.stream().map(StockTransItemDto::getOutQty).filter(Objects::nonNull).max(Comparator.naturalOrder()); | 
|         int maxed = Math.max(max.orElse(Integer.MIN_VALUE), maxOut.orElse(Integer.MIN_VALUE)); | 
|   | 
|         StockTrandDto trandDto = new StockTrandDto(); | 
|         trandDto.setMaxQty(maxed).setTrandItem(stockDtos); | 
|         return R.ok().add(trandDto); | 
|     } | 
|   | 
|     /** | 
|      * @param | 
|      * @return | 
|      * @author Ryan | 
|      * @description 删除原主单及明细,加入历史档 | 
|      * @time 2025/3/19 19:53 | 
|      */ | 
|     @Transactional(rollbackFor = Exception.class) | 
|     public synchronized void operateOrderLogs(WkOrder asrder) throws Exception { | 
|         if (Objects.isNull(asrder) || Objects.isNull(asrder.getId())) { | 
|             throw new CoolException("参数不能为空!!"); | 
|         } | 
|         asrder.setExceStatus(AsnExceStatus.ASN_EXCE_STATUS_TASK_CLOSE.val); | 
|   | 
|         if (!this.updateById(asrder)) { | 
|             throw new CoolException("单据关闭失败!!"); | 
|         } | 
|         List<WkOrderItem> orderItems = asnOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>().eq(WkOrderItem::getOrderId, asrder.getId())); | 
|         if (orderItems.isEmpty()) { | 
|             throw new CoolException("收货明细为空!!"); | 
|         } | 
| //        if (Objects.isNull(asrder.getAnfme()) || asrder.getAnfme().compareTo(0.00) == 0) { | 
| //            throw new CoolException("收货数量不能为零!!"); | 
| //        } | 
|         WkOrder order = this.getById(asrder.getId()); | 
|         AsnOrderLog orderLog = new AsnOrderLog(); | 
| //        order.setExceStatus(AsnExceStatus.ASN_EXCE_STATUS_TASK_DONE.val); | 
|         BeanUtils.copyProperties(order, orderLog); | 
|         orderLog.setId(null); | 
|         orderLog.setAsnId(order.getId()); | 
|   | 
| //        if (!this.saveOrUpdate(order)) { | 
| //            throw new CoolException("状态修改失败!!"); | 
| //        } | 
| //        orderLog.setExceStatus(AsnExceStatus.ASN_EXCE_STATUS_TASK_CLOSE.val); | 
|         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()) | 
|                     .setLogId(orderLog.getId()) | 
|                     .setAsnId(item.getOrderId()); | 
|             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 (!this.removeById(asrder.getId())) { | 
|             throw new CoolException("原单据删除失败!!"); | 
|         } | 
|     } | 
| } |