package com.zy.asrs.task; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.zy.asrs.entity.*; import com.zy.asrs.entity.param.OrderToLine; import com.zy.asrs.service.*; import com.zy.asrs.service.impl.OrderDetlServiceImpl; import com.zy.asrs.task.core.ReturnT; import com.zy.asrs.task.handler.OrderToLineHandler; import com.zy.asrs.utils.GroupedLockerOptimizerUtils; import com.zy.asrs.utils.OptimizedLockerPackingUtils; import com.zy.asrs.utils.OrderInAndOutUtil; import com.zy.asrs.utils.ToSortLineUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.List; @Slf4j @Component //订单下发至分拣线 public class OrderToSortLineScheduler { @Autowired private OrderPakinService orderPakinService; @Autowired private OrderDetlPakinService orderDetlPakinService; @Autowired private BasArmRulesService basArmRulesService; @Autowired private OrderToLineHandler orderToLineHandler; @Autowired private BasArmMastSignService basArmMastSignService; @Scheduled(cron = "0/3 * * * * ? ") private void orderToSortLine() { //获取未下发单据 List orderNos = orderPakinService.AllStatusSatisfyOrder(0); if(orderNos == null || orderNos.isEmpty()) { // log.info("未有新订单"); return; } //遍历单据 for (String orderNo : orderNos) { try{ List orderDetlPakinList = orderDetlPakinService.selectList(new EntityWrapper().eq("order_no",orderNo)); // List items = new ArrayList<>(); if (orderDetlPakinList.size()<1){ continue; } List items = new ArrayList<>(); for (OrderDetlPakin orderDetl:orderDetlPakinList){ Integer number = basArmRulesService.getNumber(orderDetl.getWeight(),orderDetl.getVolume(),orderDetl.getManLength(),orderDetl.getWidth(),orderDetl.getHeight()); if (number == null) { BasArmRules basArmRules = new BasArmRules(); basArmRules.setMaterialHeight(orderDetl.getHeight()); basArmRules.setMaterialWeight(orderDetl.getWeight()); basArmRules.setMaterialLength(orderDetl.getManLength()); basArmRules.setMaterialWidth(orderDetl.getWidth()); basArmRulesService.insert(basArmRules); return; } else if (number == 0){ return; } String name = ToSortLineUtils.MergerParameter(orderDetl.getMatnr(),orderDetl.getStandby1(),orderDetl.getStandby2()); int maxCapacity = number; int stock = orderDetl.getAnfme().intValue(); // items.add(new GroupedLockerOptimizerUtils.Item(name, maxCapacity, stock)); items.add(new OptimizedLockerPackingUtils.Item(name, maxCapacity, stock)); } OrderToLine orderToLine = new OrderToLine(); orderToLine.setOrderNo(orderNo); //单据编号 orderToLine.setCreateTime(System.currentTimeMillis()); //创建时间 // OrderToLine orderToLineR = ToSortLineUtils.GetOrderToLineGro(items, orderToLine); OrderToLine orderToLineR = ToSortLineUtils.GetOrderToLineOpt(items, orderToLine); try{ ReturnT returnT = orderToLineHandler.start(orderToLineR); if (!returnT.isSuccess()) { log.error("下发单据失败===>"+ JSON.toJSON(orderToLineR)); } else { try{ for (OrderToLine.MatList matList:orderToLineR.getMatList()){ BasArmMastSign basArmMastSign = new BasArmMastSign(); basArmMastSign.setMatnr(matList.getSku()); basArmMastSign.setOrderNo(orderNo); basArmMastSign.setSku(matList.getSku()); basArmMastSign.setPo(matList.getPo()); basArmMastSign.setUpc(matList.getUpc()); basArmMastSign.setSupplier(matList.getSupplier()); basArmMastSign.setStatus(0); basArmMastSign.setAnfme(matList.getCtns()); basArmMastSign.setCreateTime(matList.getBindingTags()); basArmMastSignService.insert(basArmMastSign); } }catch (Exception e){} } } catch (Exception e){ log.error("下发单据异常===>"+e.getMessage()); } } catch (Exception e){ log.error("下发单据异常,跳转下一个订单===>"+e.getMessage()); } } } }