| | |
| | | import com.alibaba.excel.event.AnalysisEventListener; |
| | | import com.alibaba.excel.exception.ExcelAnalysisException; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.SnowflakeIdWorker; |
| | | import com.zy.asrs.entity.DocType; |
| | |
| | | |
| | | private long orderId; |
| | | |
| | | private long docTypeId; |
| | | |
| | | List<ImportOrderDto> list = new ArrayList<>(); |
| | | /** |
| | | * 假设这个是一个DAO,当然有业务逻辑这个也可以是一个service。当然如果不用存储这个对象没用。 |
| | |
| | | public void invoke(ImportOrderDto data, AnalysisContext context) { |
| | | log.info("解析到第 {} 条数据:{}", ++count, JSON.toJSONString(data)); |
| | | list.add(data); |
| | | if (context.getCurrentRowNum() == 3) { |
| | | if (context.getCurrentRowNum() == 5) { |
| | | String time = DateUtils.convert(new Date(),DateUtils.yyyyMMddHHmmss_F); |
| | | Order order2 = orderService.selectByNo(list.get(0).getColumn2()); |
| | | Order order2 = orderService.selectByNo(list.get(0).getColumn2()); // 订单号 |
| | | if(order2 != null) { |
| | | throw new ExcelAnalysisException("单据已存在!"); |
| | | } |
| | | DocType docType = docTypeService.selectOrAdd(list.get(1).getColumn2(), Boolean.FALSE); |
| | | DocType docType = docTypeService.selectOrAdd(list.get(1).getColumn2(), Boolean.FALSE); // 订单类型 |
| | | if (docType == null) { |
| | | throw new ExcelAnalysisException("单据类型错误:" + list.get(1).getColumn2()); |
| | | } |
| | | orderNo = list.get(0).getColumn2(); |
| | | docTypeId = docType.getDocId(); |
| | | Order order = new Order(); |
| | | order.setUuid(String.valueOf(snowflakeIdWorker.nextId())); |
| | | order.setOrderNo(orderNo); |
| | | order.setOrderTime(time); |
| | | order.setDocType(docType.getDocId()); |
| | | order.setCstmrName(Cools.isEmpty(list.get(2).getColumn2()) ? "" : list.get(2).getColumn2()); // 客户名称 |
| | | order.setMemo(Cools.isEmpty(list.get(3).getColumn2()) ? "" : list.get(3).getColumn2()); // 备注 |
| | | order.setSettle(1L); |
| | | order.setStatus(1); |
| | | order.setCreateBy(userId); |
| | |
| | | List<OrderDetl> orderDetlList = new ArrayList<>(); |
| | | list.forEach(importOrderDto -> { |
| | | OrderDetl orderDetl = new OrderDetl(); |
| | | orderDetl.setBrand(importOrderDto.getColumn1()); |
| | | if (docTypeId == 24) { |
| | | orderDetl.setSpecs(String.format("%07d",Integer.parseInt(importOrderDto.getColumn1()))); // 源库位 |
| | | if (importOrderDto.getColumn2() != null) { |
| | | orderDetl.setModel(String.format("%07d",Integer.parseInt(importOrderDto.getColumn2()))); // 目标库位 |
| | | } |
| | | if (importOrderDto.getColumn3() != null) { |
| | | orderDetl.setBeBatch(Integer.parseInt(importOrderDto.getColumn3())); //巷道 |
| | | } |
| | | } else { |
| | | orderDetl.setBrand(importOrderDto.getColumn1()); |
| | | } |
| | | orderDetl.setBatch(""); |
| | | orderDetl.setOrderId(orderId); |
| | | orderDetl.setOrderNo(orderNo); |