| | |
| | | |
| | | import com.alibaba.excel.context.AnalysisContext; |
| | | import com.alibaba.excel.event.AnalysisEventListener; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.BaseRes; |
| | | import com.core.common.Cools; |
| | |
| | | import com.core.common.SpringUtils; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.LocDetl; |
| | | import com.zy.asrs.entity.LocMast; |
| | | import com.zy.asrs.entity.OrderDetl; |
| | | import com.zy.asrs.entity.param.StockOutParam; |
| | | import com.zy.asrs.service.LocDetlService; |
| | | import com.zy.asrs.service.OrderDetlService; |
| | | import com.zy.asrs.service.TagService; |
| | | import com.zy.asrs.service.WorkService; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.common.entity.OutLocBoxExcel; |
| | | 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 lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.util.ArrayList; |
| | |
| | | public class OutLocBoxExcelListener extends AnalysisEventListener<OutLocBoxExcel> { |
| | | |
| | | private int total = 0; |
| | | private String errorMsgOrderLoc = ""; |
| | | private String orderOneNo = null; |
| | | private String cstmrName = null; |
| | | private Long userId; |
| | | private String remoteAddr; |
| | | private boolean sign = true; |
| | | |
| | | List<String[]> OutLocBoxCs = new ArrayList<>(); |
| | | |
| | | public OutLocBoxExcelListener() { |
| | | } |
| | | |
| | | public OutLocBoxExcelListener(Long userId) { |
| | | this.userId = userId; |
| | | } |
| | | |
| | | public OutLocBoxExcelListener(String remoteAddr,Long userId) { |
| | | this.remoteAddr = remoteAddr; |
| | | this.userId = userId; |
| | | } |
| | | |
| | |
| | | public void invoke(OutLocBoxExcel excel, AnalysisContext ctx) { |
| | | String batch = excel.getBatch(); |
| | | String orderNo = excel.getOrderNo(); |
| | | String[] s=new String[2]; |
| | | // String cstmrName = excel.getCstmrName(); |
| | | String memo = excel.getMemo(); |
| | | if (Cools.isEmpty(orderOneNo)){ |
| | | if (!Cools.isEmpty(excel.getOrderNo())){ |
| | | orderOneNo = excel.getOrderNo(); |
| | | } else { |
| | | throw new CoolException("订单号参数为空"); |
| | | } |
| | | } |
| | | if (Cools.isEmpty(cstmrName)){ |
| | | if (!Cools.isEmpty(excel.getCstmrName())){ |
| | | cstmrName = excel.getCstmrName(); |
| | | } else { |
| | | throw new CoolException("客户名称参数为空"); |
| | | } |
| | | } |
| | | String[] s=new String[4]; |
| | | s[0] = batch; |
| | | s[1] = orderNo; |
| | | s[1] = orderOneNo; |
| | | s[2] = cstmrName; |
| | | s[3] = memo; |
| | | OutLocBoxCs.add(s); |
| | | total++; |
| | | } |
| | |
| | | public void doAfterAllAnalysed(AnalysisContext ctx) { |
| | | if (!Cools.isEmpty(OutLocBoxCs) && OutLocBoxCs.size() != 0) { |
| | | 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<LocDto> locDtos = new ArrayList<>(); |
| | | List<String[]> outLocBoxCList = new ArrayList<>(); |
| | | List<String> outLocBoxCNew = new ArrayList<>(); |
| | | for (String[] outLocBoxC:OutLocBoxCs){ |
| | | total--; |
| | | if (!outLocBoxCNew.contains(outLocBoxC[0])){ |
| | | LocDetl locDetlSou = locDetlService.selectOne(new EntityWrapper<LocDetl>().eq("batch", outLocBoxC[0])); |
| | | if (Cools.isEmpty(locDetlSou)){ |
| | | sign = false; |
| | | errorMsgOrderLoc = errorMsgOrderLoc + "[===》" +"箱号:"+outLocBoxC[0]+" 未查询到数据!!!《===]"; |
| | | continue; |
| | | // throw new CoolException("箱号:"+outLocBoxC[0]+" 未查询到数据!!!"); |
| | | } |
| | | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", locDetlSou.getLocNo())); |
| | | if (Cools.isEmpty(locMast)){ |
| | | sign = false; |
| | | errorMsgOrderLoc = errorMsgOrderLoc + "[===》" +"箱号:"+outLocBoxC[0]+" 所在库位不满足出库条件!!!未查询到此箱号所在库位"+"《===]"; |
| | | continue; |
| | | // throw new CoolException("箱号:"+outLocBoxC[0]+" 所在库位不满足出库条件!!!未查询到此箱号所在库位"); |
| | | } |
| | | if (!locMast.getLocSts().equals("F")){ |
| | | sign = false; |
| | | errorMsgOrderLoc = errorMsgOrderLoc + "[===》" +"箱号:"+outLocBoxC[0]+" 所在库位不满足出库条件!!!库位状态不为F!!!库位状态:"+locMast.getLocSts$()+"《===]"; |
| | | continue; |
| | | // throw new CoolException("箱号:"+outLocBoxC[0]+" 所在库位不满足出库条件!!!库位状态不为F!!!库位状态:"+locMast.getLocSts$()); |
| | | } |
| | | |
| | | // 目标库位 ===>> 浅库位 |
| | | if (Utils.isShallowLoc(slaveProperties, locMast.getLocNo())) { |
| | | String shallowLoc = Utils.getDeepLoc(slaveProperties, locMast.getLocNo()); |
| | | LocMast locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", shallowLoc)); |
| | | if (!Cools.isEmpty(locMast2)) { |
| | | if (locMast2.getLocSts().equals("P") || locMast2.getLocSts().equals("R")){ |
| | | errorMsgOrderLoc = errorMsgOrderLoc + "[===》" +"箱号:"+outLocBoxC[0]+" 所在库位满足出库条件!!!但是深库位在出库中!!!因此会夹杂在前边订单执行!!!"+"《===]"; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (sign){ |
| | | List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>() |
| | | .eq("loc_no", locDetlSou.getLocNo()).eq("origin", locDetlSou.getOrigin())); |
| | | for (LocDetl locDetl:locDetls){ |
| | | total++; |
| | | String[] locDetlNow=new String[4]; |
| | | locDetlNow[0] = locDetl.getBatch(); |
| | | locDetlNow[1] = outLocBoxC[1]; |
| | | locDetlNow[2] = outLocBoxC[2]; |
| | | locDetlNow[3] = outLocBoxC[3]; |
| | | outLocBoxCList.add(locDetlNow); |
| | | outLocBoxCNew.add(outLocBoxC[0]); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | for (String[] outLocBoxC:outLocBoxCList){ |
| | | LocDetl locDetl = locDetlService.selectOne(new EntityWrapper<LocDetl>().eq("batch", outLocBoxC[0])); |
| | | if (Cools.isEmpty(locDetl)){ |
| | | total--; |
| | | continue; |
| | | } |
| | | LocDto locDto = new LocDto(locDetl.getManu(), locDetl.getMatnr(), locDetl.getMaktx(),locDetl.getModel(),locDetl.getSpecs(), |
| | | locDetl.getBatch(),locDetl.getBrand(),locDetl.getBarcode(), outLocBoxC[1],locDetl.getAnfme()); |
| | | // LocDto locDto = new LocDto(locDetl.getManu(), locDetl.getMatnr(), locDetl.getMaktx(),locDetl.getModel(),locDetl.getSpecs(), |
| | | // locDetl.getBatch(),locDetl.getBrand(),locDetl.getBarcode(), outLocBoxC[1],locDetl.getAnfme()); |
| | | // locDto.setOrigin(locDetl.getOrigin()); |
| | | // locDto.setWeight(locDetl.getWeight()); |
| | | locDetl.setMemo(outLocBoxC[3]); |
| | | LocDto locDto = new LocDto(locDetl); |
| | | locDtos.add(locDto); |
| | | } |
| | | |
| | | StockOutParam param = new StockOutParam(); |
| | | ArrayList<StockOutParam.LocDetl> locDetls = new ArrayList<>(); |
| | | for (LocDto locDto:locDtos){ |
| | | List<LocDto> locDtosList = new ArrayList<>(); |
| | | List<String> 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.setModel(locDto.getModel()); |
| | | locDetl.setSpecs(locDto.getSpecs()); |
| | | locDetl.setZpallet(locDto.getZpallet()); |
| | | |
| | | param.setOrderNo(locDto.getOrderNo()); |
| | | locDetl.setOrigin(locDto.getOrigin()); |
| | | locDetl.setWeight(locDto.getWeight()); |
| | | locDetl.setMemo(locDto.getMemo()); |
| | | |
| | | locDetls.add(locDetl); |
| | | } |
| | | param.setLocDetls(locDetls); |
| | | param.setOrderNo(orderOneNo); |
| | | param.setCstmrName(cstmrName); |
| | | |
| | | if (total>0){ |
| | | if (sign && total>0){ |
| | | workService.startupFullTakeStoreOrder(param,9999L); |
| | | } |
| | | |
| | | try { |
| | | OperateLogService operateLogService = SpringUtils.getBean(OperateLogService.class); |
| | | // 记录操作日志 |
| | | OperateLog operateLog = new OperateLog(); |
| | | operateLog.setAction("导入订单批量出库"); |
| | | operateLog.setIp(remoteAddr); |
| | | operateLog.setUserId(userId); |
| | | operateLog.setRequest("单号:"+orderOneNo+"、客户名:"+cstmrName); |
| | | operateLog.setResponse(errorMsgOrderLoc.equals("")? "正常" : (sign && total>0)? "成功:"+errorMsgOrderLoc : "失败:"+errorMsgOrderLoc); |
| | | operateLogService.insert(operateLog); |
| | | } catch (Exception e){ |
| | | log.error("记录操作日志失败!"+e.getMessage()); |
| | | } |
| | | |
| | | // if (!sign || total<1){ |
| | | // throw new CoolException("失败:"+errorMsgOrderLoc); |
| | | // } |
| | | |
| | | } |
| | | |
| | | |
| | | log.info("导入{}条箱号!", total); |
| | | log.info("出库{}条箱号!", total); |
| | | } |
| | | |
| | | public int getTotal() { |
| | | return total; |
| | | } |
| | | |
| | | public boolean getSign() { |
| | | return sign; |
| | | } |
| | | |
| | | public String getErrorMsgOrderLoc() { |
| | | return errorMsgOrderLoc; |
| | | } |
| | | } |