| | |
| | | import cn.iocoder.yudao.module.aftersales.service.permission.bo.AfterSalePermissionCreateReqBO; |
| | | import cn.iocoder.yudao.module.mes.api.returnsales.MesWmReturnSalesApi; |
| | | import cn.iocoder.yudao.module.mes.api.returnsales.dto.MesWmReturnSalesCreateReqDTO; |
| | | import cn.iocoder.yudao.module.mes.api.returnsales.dto.MesWmReturnSalesLineRespDTO; |
| | | import jakarta.annotation.Resource; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | }).toList()); |
| | | Long mesReturnId = mesWmReturnSalesApi.createReturnSales(mesReqDTO); |
| | | |
| | | // 4. 更新退货申请状态 |
| | | // 4. 回写 MES 解析后的批次(原单未记录批次的商品由 MES 自动生成退货批次) |
| | | syncReturnItemBatch(id, mesReturnId); |
| | | |
| | | // 5. 更新退货申请状态 |
| | | returnMapper.updateById(new AfterSaleReturnDO().setId(id) |
| | | .setStatus(AfterSaleReturnStatusEnum.APPROVED.getStatus()) |
| | | .setMesReturnId(mesReturnId) |
| | |
| | | .setAuditTime(LocalDateTime.now())); |
| | | } |
| | | |
| | | /** |
| | | * 将 MES 退货单行上的批次回写到售后明细,便于页面展示与追溯 |
| | | */ |
| | | private void syncReturnItemBatch(Long returnId, Long mesReturnId) { |
| | | List<MesWmReturnSalesLineRespDTO> mesLines = mesWmReturnSalesApi.getReturnSalesLineList(mesReturnId); |
| | | if (CollUtil.isEmpty(mesLines)) { |
| | | return; |
| | | } |
| | | Map<Long, MesWmReturnSalesLineRespDTO> lineMap = mesLines.stream() |
| | | .filter(line -> line.getBatchId() != null) |
| | | .collect(Collectors.toMap(MesWmReturnSalesLineRespDTO::getItemId, line -> line, (a, b) -> a)); |
| | | if (lineMap.isEmpty()) { |
| | | return; |
| | | } |
| | | for (AfterSaleReturnItemDO item : returnItemMapper.selectListByReturnId(returnId)) { |
| | | MesWmReturnSalesLineRespDTO line = lineMap.get(item.getItemId()); |
| | | if (line == null || item.getBatchId() != null) { |
| | | continue; |
| | | } |
| | | returnItemMapper.updateById(new AfterSaleReturnItemDO().setId(item.getId()) |
| | | .setBatchId(line.getBatchId()).setBatchCode(line.getBatchCode())); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void cancelReturn(Long id) { |