| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.DocType; |
| | | import com.zy.asrs.entity.Order; |
| | | import com.zy.asrs.entity.OrderDetl; |
| | | import com.zy.asrs.mapper.OrderMapper; |
| | | import com.zy.asrs.service.DocTypeService; |
| | | import com.zy.asrs.service.MatService; |
| | | import com.zy.asrs.service.OrderDetlService; |
| | |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | | |
| | | /** |
| | | * 入库更新完成回报 |
| | |
| | | @Autowired |
| | | private ErpSqlServer erpSqlServer; |
| | | |
| | | private final ReentrantLock lock = new ReentrantLock(); |
| | | |
| | | @Resource |
| | | private OrderMapper orderMapper; |
| | | |
| | | @Transactional(rollbackFor = Throwable.class) |
| | | @Scheduled(cron = "${erp.refreshtime}") |
| | | @Scheduled(cron = "0/10 * * * * ?") |
| | | public void pakinOrderComplete() { |
| | | //log.info("开始入库更新完成回报"); |
| | | // 所有订单 |
| | | List<Order> orders = orderService.selectList(new EntityWrapper<Order>().eq("settle", 4L)); |
| | | DocType docType; |
| | | for (Order order : orders) { |
| | | // 拿不到锁直接跳过(关键) |
| | | if (!lock.tryLock()) { |
| | | System.out.println("上一次任务未执行完,跳过本次"); |
| | | return; |
| | | } |
| | | |
| | | docType = docTypeService.selectById(order.getDocType()); |
| | | if (docType == null) { |
| | | log.error("该订单类型不存在:" + order.getDocType()); |
| | | throw new CoolException("服务器内部错误,请联系管理员"); |
| | | } |
| | | List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(order.getId()); |
| | | if (docType.getPakin() == 1) { |
| | | //入库单 |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | log.info("该入库单对象:" + orderDetl); |
| | | insertInDet(orderDetl); |
| | | // 所有订单 |
| | | try { |
| | | // List<Order> orders = orderService.selectList(new EntityWrapper<Order>().eq("settle", 4L)); |
| | | // 创建分页对象:页码 1,每页 2 条 |
| | | Page<Order> page = new Page<>(1, 10); // 一次10条,避免处理不过来 |
| | | // 使用 selectPage 获取前 2 条记录 |
| | | Page<Order> result = orderService.selectPage( |
| | | page, |
| | | new EntityWrapper<Order>().eq("settle", 4L) |
| | | ); |
| | | |
| | | List<Order> orders = result.getRecords(); // 这就是前 2 条 |
| | | DocType docType; |
| | | for (Order order : orders) { |
| | | |
| | | docType = docTypeService.selectById(order.getDocType()); |
| | | if (docType == null) { |
| | | log.error("该订单类型不存在:" + order.getDocType()); |
| | | throw new CoolException("服务器内部错误,请联系管理员"); |
| | | } |
| | | insertInHed(order); |
| | | } else { |
| | | //出库单 |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | log.info("该出库单对象:" + orderDetl); |
| | | insertOutDet(orderDetl); |
| | | List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(order.getId()); |
| | | if (docType.getPakin() == 1) { |
| | | //入库单 |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | log.info("该入库单对象:" + orderDetl); |
| | | insertInDet(orderDetl); |
| | | } |
| | | insertInHed(order); |
| | | } else { |
| | | //出库单 |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | log.info("该出库单对象:" + orderDetl); |
| | | insertOutDet(orderDetl); |
| | | } |
| | | insertOutHed(order); |
| | | } |
| | | insertOutHed(order); |
| | | // 修改订单状态 4.完成 ===>> 6.已上报 |
| | | if (!orderService.updateSettle(order.getId(), 6L, null)) { |
| | | throw new CoolException("服务器内部错误,请联系管理员"); |
| | | } |
| | | } |
| | | // 修改订单状态 4.完成 ===>> 6.已上报 |
| | | if (!orderService.updateSettle(order.getId(), 6L, null)) { |
| | | throw new CoolException("服务器内部错误,请联系管理员"); |
| | | } |
| | | } finally { |
| | | lock.unlock(); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | @Transactional(rollbackFor = Throwable.class) |
| | | public boolean insertInDet(OrderDetl orderDetl) { |
| | | String sqlInDetTb = "select * from lk_InDetTB where BillNo='" + orderDetl.getOrderNo() + "' and " + " ItemId='" + orderDetl.getMatnr() + "' and ItemBatch='" + orderDetl.getBatch() + "' and proType='" + orderDetl.getSpecs() + "'"; |
| | | String sqlInDetTb = "select * from lk_InDetTB where BillNo='" + orderDetl.getOrderNo() + "' and " + " ItemId='" + orderDetl.getMatnr() + "' and ItemBatch='" + orderDetl.getBatch() + "'"; |
| | | List<InDetTB> inDets = erpSqlServer.select(sqlInDetTb, InDetTB.class); |
| | | String sqlInDetTbBak = "select * from lk_InDetTB_Bak where BillNo='" + orderDetl.getOrderNo() + "' and " + " ItemId='" + orderDetl.getMatnr() + "' and ItemBatch='" + orderDetl.getBatch() + "' and proType='" + orderDetl.getSpecs() + "'"; |
| | | String sqlInDetTbBak = "select * from lk_InDetTB_Bak where BillNo='" + orderDetl.getOrderNo() + "' and " + " ItemId='" + orderDetl.getMatnr() + "' and ItemBatch='" + orderDetl.getBatch() + "'"; |
| | | List<InDetTBBak> inDetBaks = erpSqlServer.select(sqlInDetTbBak, InDetTBBak.class); |
| | | if (!inDets.isEmpty() || !inDetBaks.isEmpty()) { |
| | | log.error("该单号料号中间表表身已存在:" + orderDetl.getOrderNo() + "==>>" + orderDetl.getOrderNo()); |
| | |
| | | if (orderDetl.getQty() > orderDetl.getAnfme() && orderDetl.getQty() > orderDetl.getWorkQty()) { |
| | | log.info("修正错误数量:{}", JSON.toJSON(orderDetl)); |
| | | content.put("MainNum", orderDetl.getWorkQty()); |
| | | } else if (orderDetl.getAnfme() == orderDetl.getWorkQty() && orderDetl.getQty() <= 0) { |
| | | content.put("MainNum", orderDetl.getWorkQty()); |
| | | } else { |
| | | content.put("MainNum", orderDetl.getQty()); |
| | | } |