|  |  | 
 |  |  | package com.zy.asrs.task; | 
 |  |  |  | 
 |  |  | import com.alibaba.fastjson.JSON; | 
 |  |  | import com.zy.asrs.entity.BasArmRules; | 
 |  |  | import com.zy.asrs.entity.OrderDetl; | 
 |  |  | import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
 |  |  | import com.zy.asrs.entity.*; | 
 |  |  | import com.zy.asrs.entity.param.OrderToLine; | 
 |  |  | import com.zy.asrs.service.BasArmRulesService; | 
 |  |  | import com.zy.asrs.service.OrderDetlService; | 
 |  |  | import com.zy.asrs.service.OrderService; | 
 |  |  | import com.zy.asrs.service.impl.OrderDetlServiceImpl; | 
 |  |  | import com.zy.asrs.service.*; | 
 |  |  | import com.zy.asrs.task.core.ReturnT; | 
 |  |  | import com.zy.asrs.task.handler.OrderToLineHandler; | 
 |  |  | import com.zy.asrs.utils.ToSortLineUtils; | 
 |  |  | import com.zy.asrs.utils.param.ItemUtilParam; | 
 |  |  | import lombok.extern.slf4j.Slf4j; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.scheduling.annotation.Scheduled; | 
 |  |  | 
 |  |  | //订单下发至分拣线 | 
 |  |  | public class OrderToSortLineScheduler { | 
 |  |  |     @Autowired | 
 |  |  |     private OrderService orderService; | 
 |  |  |     private OrderPakinService orderPakinService; | 
 |  |  |     @Autowired | 
 |  |  |     private OrderDetlService orderDetlService; | 
 |  |  |     private OrderDetlPakinService orderDetlPakinService; | 
 |  |  |     @Autowired | 
 |  |  |     private BasArmRulesService basArmRulesService; | 
 |  |  |     @Autowired | 
 |  |  |     private OrderToLineHandler orderToLineHandler; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private BasArmMastSignService basArmMastSignService; | 
 |  |  |  | 
 |  |  |     @Scheduled(cron = "0/3 * * * * ? ") | 
 |  |  |     private void orderToSortLine() { | 
 |  |  |         //获取未下发单据 | 
 |  |  |         List<String> orderNos = orderService.AllStatusSatisfyOrder(0); | 
 |  |  |         List<String> orderNos = orderPakinService.AllStatusSatisfyOrder(0); | 
 |  |  |         if(orderNos == null || orderNos.isEmpty()) { | 
 |  |  |             log.info("未有新订单"); | 
 |  |  | //            log.info("未有新订单"); | 
 |  |  |             return; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         //遍历单据 | 
 |  |  |         for (String orderNo : orderNos) { | 
 |  |  |             List<OrderDetl> orderDetls = orderDetlService.selectByOrderNo(orderNo); | 
 |  |  |             OrderToLine orderToLine = new OrderToLine(); | 
 |  |  |             orderToLine.setOrderNo(orderNo);  //单据编号 | 
 |  |  |             orderToLine.setCreateTime(System.currentTimeMillis());  //创建时间 | 
 |  |  |  | 
 |  |  |             Long bindingTag = System.currentTimeMillis();//混搭标记 | 
 |  |  |  | 
 |  |  |             List<OrderToLine.MatList> matLists = new ArrayList<>(); | 
 |  |  |             for (OrderDetl orderDetl : orderDetls) { | 
 |  |  |                 Integer number =  basArmRulesService.getNumber(orderDetl.getWeight(),orderDetl.getVolume(),orderDetl.getManLength(),orderDetl.getWidth(),orderDetl.getHeight()); | 
 |  |  |                 Double anfme = orderDetl.getAnfme(); | 
 |  |  |                 Double remainder = anfme % number;  //取余   余数混搭 | 
 |  |  |                 if(remainder != 0){ | 
 |  |  |                     // 组装物料信息 | 
 |  |  |                     OrderToLine.MatList matMix = new OrderToLine.MatList( | 
 |  |  |                             orderDetl.getMatnr(),  // matnr -> sku | 
 |  |  |                             orderDetl.getSupp(),  //  supp -> po | 
 |  |  |                             remainder,          //    余料 -> 剩余余料统一时间戳标记 | 
 |  |  |                             orderDetl.getBarcode(),   //barcode -> upc 条码 | 
 |  |  |                             1, | 
 |  |  |                             orderDetl.getOrigin(),   //origin -> supplier 货源 | 
 |  |  |                             bindingTag        //余料标记相同 | 
 |  |  |                     ); | 
 |  |  |                     matLists.add(matMix); | 
 |  |  |                 } | 
 |  |  |                 Double ctns = anfme - remainder; | 
 |  |  |                 // 组装物料信息 | 
 |  |  |                 OrderToLine.MatList mat = new OrderToLine.MatList( | 
 |  |  |                         orderDetl.getMatnr(),  // matnr -> sku | 
 |  |  |                         orderDetl.getSupp(),  //  supp -> po | 
 |  |  |                         ctns,          //整料 | 
 |  |  |                         orderDetl.getBarcode(),   //barcode -> upc | 
 |  |  |                         1, | 
 |  |  |                         orderDetl.getOrigin(),   //origin -> supplier 货源 | 
 |  |  |                         System.currentTimeMillis() | 
 |  |  |                 ); | 
 |  |  |                 matLists.add(mat); | 
 |  |  |             } | 
 |  |  |             orderToLine.setMatList(matLists); | 
 |  |  |             try{ | 
 |  |  |                 ReturnT<String> returnT = orderToLineHandler.start(orderToLine); | 
 |  |  |                 if (!returnT.isSuccess()) { | 
 |  |  |                     log.error("下发单据失败===>"+ JSON.toJSON(orderToLine)); | 
 |  |  |                 List<OrderDetlPakin> orderDetlPakinList = orderDetlPakinService.selectList(new EntityWrapper<OrderDetlPakin>().eq("order_no",orderNo)); | 
 |  |  |                 if (orderDetlPakinList.size()<1){ | 
 |  |  |                     continue; | 
 |  |  |                 } | 
 |  |  |                 List<ItemUtilParam.Item> 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 ItemUtilParam.Item(name, maxCapacity, stock)); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 OrderToLine orderToLine = new OrderToLine(); | 
 |  |  |                 orderToLine.setOrderNo(orderNo);  //单据编号 | 
 |  |  |                 orderToLine.setCreateTime(System.currentTimeMillis());  //创建时间 | 
 |  |  |                 OrderToLine orderToLineR = ToSortLineUtils.GetOrderToLine(items, orderToLine,"Opt3"); | 
 |  |  |  | 
 |  |  |                 try{ | 
 |  |  |                     ReturnT<String> 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()); | 
 |  |  |                 log.error("下发单据异常,跳转下一个订单===>"+e.getMessage()); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | } |