| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | @Slf4j |
| | | public class OrderExcelListener extends AnalysisEventListener<OrderExcel> { |
| | | public class OrderExcelListener extends AnalysisEventListener<OrderExcel> { |
| | | |
| | | private int total = 0; |
| | | private Long userId; |
| | |
| | | |
| | | /** |
| | | * 单据导入实现 |
| | | * |
| | | * @param data |
| | | * @param context |
| | | * @author Ryan |
| | | * @date 2026/1/8 17:25 |
| | | * @param data |
| | | * @param context |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void invoke(OrderExcel data, AnalysisContext context) { |
| | | OrderService orderService = (OrderService) SpringUtils.getBean(OrderService.class); |
| | | OrderDetlService detlService = (OrderDetlService) SpringUtils.getBean(OrderDetlService.class); |
| | | OrderService orderService = SpringUtils.getBean(OrderService.class); |
| | | OrderDetlService detlService = SpringUtils.getBean(OrderDetlService.class); |
| | | MatService matService = SpringUtils.getBean(MatService.class); |
| | | DocTypeService docTypeService = SpringUtils.getBean(DocTypeService.class); |
| | | Date now = new Date(); |
| | |
| | | |
| | | Order order = new Order(); |
| | | order.setOrderNo(data.getOrderNo()); |
| | | order.setDocType(docType.getDocId()); |
| | | order.setUuid(UUID.randomUUID().toString()); |
| | | order.setCreateTime(now); |
| | | order.setUpdateTime(now); |
| | | order.setSettle(1L); |
| | | order.setStatus(1); |
| | | order.setCreateBy(userId); |
| | | order.setUpdateBy(userId); |
| | | order.setPakinPakoutStatus(docType.getPakin() == 1 ? 1 : 2); |
| | | if (!orderService.insert(order)) { |
| | | throw new CoolException("订单创建失败!!"); |
| | | if (Objects.isNull(data.getOrderNo())) { |
| | | throw new CoolException("单据编码不能为空!!"); |
| | | } |
| | | order = orderService.selectOne(new EntityWrapper<Order>().eq("order_no", data.getOrderNo())); |
| | | if (!Objects.isNull(order)) { |
| | | //订单已存在,只添加明细 |
| | | } else { |
| | | order = new Order(); |
| | | order.setOrderNo(data.getOrderNo()); |
| | | order.setDocType(docType.getDocId()); |
| | | order.setUuid(UUID.randomUUID().toString()); |
| | | order.setCreateTime(now); |
| | | order.setUpdateTime(now); |
| | | order.setSettle(1L); |
| | | order.setStatus(1); |
| | | order.setCreateBy(userId); |
| | | order.setUpdateBy(userId); |
| | | order.setPakinPakoutStatus(docType.getPakin() == 1 ? 1 : 2); |
| | | if (!orderService.insert(order)) { |
| | | throw new CoolException("订单创建失败!!"); |
| | | } |
| | | } |
| | | if (Objects.isNull(data.getMatnr())) { |
| | | throw new CoolException("物料编码不能为空!"); |
| | |
| | | if (Objects.isNull(mat)) { |
| | | throw new CoolException("物料[" + data.getMatnr() + "]不存在!!"); |
| | | } |
| | | |
| | | OrderDetl orderDetl = detlService.selectOne(new EntityWrapper<OrderDetl>() |
| | | .eq("matnr", data.getMatnr()) |
| | | .eq("batch", data.getBatch()) |
| | | .eq("barcode", data.getBarcode()) |
| | | .eq("order_no", order.getOrderNo())); |
| | | if (!Objects.isNull(orderDetl)) { |
| | | return; |
| | | } |
| | | OrderDetl detl = new OrderDetl(); |
| | | detl.setOrderNo(data.getOrderNo()); |
| | | detl.setOrderId(order.getId()); |
| | | detl.setMatnr(data.getMatnr()); |
| | | detl.setMaktx(mat.getMaktx()); |
| | | detl.setQty(data.getQty()); |
| | | detl.setUnit(data.getUnit()); |
| | | detl.setModel(data.getModel()); |
| | | detl.setBrand(data.getBrand()); |
| | | detl.setSpecs(data.getSpecs()); |
| | | detl.setBatch(Objects.isNull(data.getBatch()) ? "1" : data.getBatch()); |
| | | detl.setVolume(data.getVolume()); |
| | | detl.setSafeQty(data.getSafeQty()); |
| | | detl.setVolume(mat.getVolume()); |
| | | detl.setSafeQty(mat.getSafeQty()); |
| | | detl.setAnfme(data.getAnfme()); |
| | | detl.setBarcode(data.getBarcode()); |
| | | detl.setUpdateTime(now); |
| | |
| | | if (!detlService.insert(detl)) { |
| | | throw new CoolException("订单详情创建失败!!"); |
| | | } |
| | | total ++ ; |
| | | total++; |
| | | } |
| | | |
| | | @Override |