package com.zy.asrs.utils; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.core.common.Cools; import com.core.common.DateUtils; import com.core.common.R; import com.core.common.SpringUtils; import com.zy.asrs.entity.LocDetl; import com.zy.asrs.entity.LocMast; import com.zy.asrs.entity.param.StockOutParam; import com.zy.asrs.service.LocDetlService; import com.zy.asrs.service.LocMastService; import com.zy.asrs.service.WorkService; import com.zy.common.model.LocDto; import com.zy.common.properties.SlaveProperties; import com.zy.system.entity.OperateLog; import com.zy.system.service.OperateLogService; import java.util.ArrayList; import java.util.Date; import java.util.List; import static org.reflections.Reflections.log; public class OrderOutBatchUtil { private String errorMsgOrderLoc = ""; private boolean sign = true; private String orderOneNo = null; private String cstmrName = null; private String ip = ""; private String action = ""; private String orderName = ""; private Long userId = 9999L; private boolean signDanger = true; public OrderOutBatchUtil() { this.sign = true; this.errorMsgOrderLoc = ""; } public OrderOutBatchUtil(String orderOneNo, String cstmrName) { this.errorMsgOrderLoc = ""; this.sign = true; this.orderOneNo = orderOneNo; this.cstmrName = cstmrName; } public OrderOutBatchUtil(String orderOneNo, String cstmrName, String ip, String action,String orderName,boolean signDanger) { this.errorMsgOrderLoc = ""; this.sign = true; this.orderOneNo = orderOneNo; this.cstmrName = cstmrName; this.ip = ip; this.action = action; this.orderName = orderName; this.userId = 9999L; this.signDanger = signDanger; } public R setOrderOutBatch() { return R.ok(); } public R setOrderOutBatch(List OutLocBoxCs) { int total = OutLocBoxCs.size(); if (!Cools.isEmpty(OutLocBoxCs) && !OutLocBoxCs.isEmpty()) { LocDetlService locDetlService = SpringUtils.getBean(LocDetlService.class); LocMastService locMastService = SpringUtils.getBean(LocMastService.class); SlaveProperties slaveProperties = SpringUtils.getBean(SlaveProperties.class); WorkService workService = SpringUtils.getBean(WorkService.class); List locDtos = new ArrayList<>(); List outLocBoxCList = new ArrayList<>(); List outLocBoxCNew = new ArrayList<>(); for (String[] outLocBoxC : OutLocBoxCs) { total--; if (!outLocBoxCNew.contains(outLocBoxC[0])) { LocDetl locDetlSou = locDetlService.selectOne(new EntityWrapper().eq("batch", outLocBoxC[0])); if (Cools.isEmpty(locDetlSou)) { sign = false; errorMsgOrderLoc = errorMsgOrderLoc + "[===》" + "箱号:" + outLocBoxC[0] + " 未查询到数据!!!《===]"; continue; // throw new CoolException("箱号:"+outLocBoxC[0]+" 未查询到数据!!!"); } if (signDanger){ if (!locDetlSou.getDanger$().equals(outLocBoxC[4])) { sign = false; errorMsgOrderLoc = errorMsgOrderLoc + "[===》" + "箱号:" + outLocBoxC[0] + " ==》出库输入待判状态:" + outLocBoxC[4] + "、库存状态:" + locDetlSou.getDanger$() + "。状态不匹配《===]"; continue; } } LocMast locMast = locMastService.selectOne(new EntityWrapper().eq("loc_no", locDetlSou.getLocNo())); if (Cools.isEmpty(locMast)) { sign = false; errorMsgOrderLoc = errorMsgOrderLoc + "[===》" + "箱号:" + outLocBoxC[0] + " 所在库位不满足出库条件!!!未查询到此箱号所在库位" + "《===]"; continue; } if (!locMast.getLocSts().equals("F")) { sign = false; errorMsgOrderLoc = errorMsgOrderLoc + "[===》" + "箱号:" + outLocBoxC[0] + " 所在库位不满足出库条件!!!库位状态不为F!!!库位状态:" + locMast.getLocSts$() + "《===]"; continue; } // 目标库位 ===>> 浅库位 if (Utils.isShallowLoc(slaveProperties, locMast.getLocNo())) { String shallowLoc = Utils.getDeepLoc(slaveProperties, locMast.getLocNo()); LocMast locMast2 = locMastService.selectOne(new EntityWrapper().eq("loc_no", shallowLoc)); if (!Cools.isEmpty(locMast2)) { if (locMast2.getLocSts().equals("P") || locMast2.getLocSts().equals("R")) { errorMsgOrderLoc = errorMsgOrderLoc + "[===》" + "箱号:" + outLocBoxC[0] + " 所在库位满足出库条件!!!但是深库位在出库中!!!因此会夹杂在前边订单执行!!!" + "《===]"; } } } if (sign) { List locDetls = locDetlService.selectList(new EntityWrapper() .eq("loc_no", locDetlSou.getLocNo()).eq("origin", locDetlSou.getOrigin())); for (LocDetl locDetl : locDetls) { total++; String[] locDetlNow = new String[5]; locDetlNow[0] = locDetl.getBatch(); locDetlNow[1] = outLocBoxC[1]; locDetlNow[2] = outLocBoxC[2]; locDetlNow[3] = outLocBoxC[3]; locDetlNow[4] = outLocBoxC[4]; outLocBoxCList.add(locDetlNow); outLocBoxCNew.add(outLocBoxC[0]); } } } } for (String[] outLocBoxC : outLocBoxCList) { LocDetl locDetl = locDetlService.selectOne(new EntityWrapper().eq("batch", outLocBoxC[0])); if (Cools.isEmpty(locDetl)) { total--; continue; } if (!Cools.isEmpty(outLocBoxC[3])) { String memo = Cools.isEmpty(locDetl.getMemo()) ? "" : locDetl.getMemo() + ","; locDetl.setMemo(memo + DateUtils.convert(new Date(), DateUtils.yyyyMMdd_C) + "备注:" + outLocBoxC[3]); } else if (Cools.isEmpty(locDetl.getMemo())) { locDetl.setMemo(outLocBoxC[3]); } LocDto locDto = new LocDto(locDetl); locDtos.add(locDto); } StockOutParam param = new StockOutParam(); ArrayList locDetls = new ArrayList<>(); List locDtosList = new ArrayList<>(); List batchList = new ArrayList<>(); for (LocDto locDto : locDtos) { if (!batchList.contains(locDto.getBatch())) { batchList.add(locDto.getBatch()); locDtosList.add(locDto); } } for (LocDto locDto : locDtosList) { StockOutParam.LocDetl locDetl = new StockOutParam.LocDetl(); locDetl.setBrand(locDto.getBrand()); locDetl.setLocNo(locDto.getLocNo()); locDetl.setAnfme(locDto.getAnfme()); locDetl.setMatnr(locDto.getMatnr()); locDetl.setBatch(locDto.getBatch()); locDetl.setModel(locDto.getModel()); locDetl.setSpecs(locDto.getSpecs()); locDetl.setZpallet(locDto.getZpallet()); locDetl.setOrigin(locDto.getOrigin()); locDetl.setWeight(locDto.getWeight()); locDetl.setMemo(locDto.getMemo()); locDetl.setDanger(locDto.getDanger()); locDetls.add(locDetl); } param.setLocDetls(locDetls); param.setOrderNo(orderOneNo); param.setCstmrName(cstmrName); param.setOrderName(orderName); if (sign && total > 0) { workService.startupFullTakeStoreOrder(param, 9999L); } try { OperateLogService operateLogService = SpringUtils.getBean(OperateLogService.class); // 记录操作日志 OperateLog operateLog = new OperateLog(); operateLog.setAction(action); operateLog.setIp(ip); operateLog.setUserId(9999L); operateLog.setRequest("单号:" + orderOneNo + "、客户名:" + cstmrName); operateLog.setResponse(errorMsgOrderLoc.equals("") ? "正常" : (sign && total > 0) ? "成功:" + errorMsgOrderLoc : "失败:" + errorMsgOrderLoc); operateLogService.insert(operateLog); } catch (Exception e) { log.error("记录操作日志失败!" + e.getMessage()); } } log.info("出库{}条箱号!", total); String requert = errorMsgOrderLoc.equals("") ? "正常" : (sign && total > 0) ? "成功:" + errorMsgOrderLoc : "失败:" + errorMsgOrderLoc; if (sign && total > 0) { return R.ok(requert.equals("正常")? "成功":requert); } return R.error(requert); } }