| | |
| | | package com.zy.asrs.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.core.common.*; |
| | | import com.core.common.BaseRes; |
| | | import com.core.common.Cools; |
| | | import com.core.common.R; |
| | | import com.core.common.SnowflakeIdWorker; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.entity.param.CombParam; |
| | | import com.zy.asrs.entity.param.MobileAdjustParam; |
| | | import com.zy.asrs.entity.param.OffSaleParam; |
| | | import com.zy.asrs.entity.param.OpenOrderPakinParam; |
| | | import com.zy.asrs.entity.param.*; |
| | | import com.zy.asrs.mapper.ManLocDetlMapper; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.utils.MatUtils; |
| | | import com.zy.common.CodeRes; |
| | | import com.zy.common.constant.MesConstant; |
| | | import com.zy.common.entity.Parameter; |
| | | import com.zy.asrs.utils.MatCompareUtils; |
| | | import com.zy.common.model.DetlDto; |
| | | import com.zy.common.model.MesCombParam; |
| | | import com.zy.common.model.LocDto; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 移动端服务核心类 |
| | |
| | | private ManLocDetlService manLocDetlService; |
| | | @Autowired |
| | | private ManLocDetlMapper manLocDetlMapper; |
| | | @Autowired |
| | | private AdjDetlService adjDetlService; |
| | | |
| | | |
| | | @Override |
| | |
| | | Date now = new Date(); |
| | | |
| | | // 无单组托 |
| | | if (Cools.isEmpty(param.getOrderNo())) { |
| | | // if (Cools.isEmpty(param.getOrderNo())) { |
| | | // |
| | | // // 生成入库通知档 |
| | | // List<DetlDto> detlDtos = new ArrayList<>(); |
| | | // param.getCombMats().forEach(elem -> { |
| | | // DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme()); |
| | | // if (DetlDto.has(detlDtos, detlDto)) { |
| | | // DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch()); |
| | | // assert one != null; |
| | | // one.setAnfme(one.getAnfme() + detlDto.getAnfme()); |
| | | // } else { |
| | | // detlDtos.add(detlDto); |
| | | // } |
| | | // }); |
| | | // |
| | | // |
| | | // for (DetlDto detlDto : detlDtos) { |
| | | // Mat mat = matService.selectByMatnr(detlDto.getMatnr()); |
| | | // if (Cools.isEmpty(mat)) { |
| | | // throw new CoolException(detlDto.getMatnr() + "商品档案不存在"); |
| | | // } |
| | | // WaitPakin waitPakin = new WaitPakin(); |
| | | // waitPakin.sync(mat); |
| | | // waitPakin.setBatch(detlDto.getBatch()); |
| | | // waitPakin.setZpallet(param.getBarcode()); // 托盘码 |
| | | // waitPakin.setIoStatus("N"); // 入出状态 |
| | | // waitPakin.setAnfme(detlDto.getAnfme()); // 数量 |
| | | // waitPakin.setStatus("Y"); // 状态 |
| | | // waitPakin.setAppeUser(userId); |
| | | // waitPakin.setAppeTime(now); |
| | | // waitPakin.setModiUser(userId); |
| | | // waitPakin.setModiTime(now); |
| | | // if (!waitPakinService.insert(waitPakin)) { |
| | | // throw new CoolException("保存入库通知档失败"); |
| | | // } |
| | | // } |
| | | // // 关联组托 |
| | | // } else { |
| | | |
| | | // 生成入库通知档 |
| | | List<DetlDto> detlDtos = new ArrayList<>(); |
| | | param.getCombMats().forEach(elem -> { |
| | | DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme()); |
| | | if (DetlDto.has(detlDtos, detlDto)) { |
| | | DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch()); |
| | | assert one != null; |
| | | one.setAnfme(one.getAnfme() + detlDto.getAnfme()); |
| | | } else { |
| | | detlDtos.add(detlDto); |
| | | } |
| | | }); |
| | | |
| | | |
| | | for (DetlDto detlDto : detlDtos) { |
| | | Mat mat = matService.selectByMatnr(detlDto.getMatnr()); |
| | | if (Cools.isEmpty(mat)) { |
| | | throw new CoolException(detlDto.getMatnr() + "商品档案不存在"); |
| | | } |
| | | WaitPakin waitPakin = new WaitPakin(); |
| | | waitPakin.sync(mat); |
| | | waitPakin.setBatch(detlDto.getBatch()); |
| | | waitPakin.setZpallet(param.getBarcode()); // 托盘码 |
| | | waitPakin.setIoStatus("N"); // 入出状态 |
| | | waitPakin.setAnfme(detlDto.getAnfme()); // 数量 |
| | | waitPakin.setStatus("Y"); // 状态 |
| | | waitPakin.setAppeUser(userId); |
| | | waitPakin.setAppeTime(now); |
| | | waitPakin.setModiUser(userId); |
| | | waitPakin.setModiTime(now); |
| | | if (!waitPakinService.insert(waitPakin)) { |
| | | throw new CoolException("保存入库通知档失败"); |
| | | } |
| | | } |
| | | // 关联组托 |
| | | } else { |
| | | |
| | | Order order = orderService.selectOne(new EntityWrapper<Order>().eq("temp1", param.getOrderNo())); |
| | | if (Cools.isEmpty(order) || order.getSettle() > 2) { |
| | | throw new CoolException("单据编号已过期"); |
| | | } |
| | | // 生成入库通知档 |
| | | List<DetlDto> detlDtos = new ArrayList<>(); |
| | | param.getCombMats().forEach(elem -> { |
| | | |
| | | // 订单明细数量校验 |
| | | OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), elem.getMatnr(), elem.getBatch(),elem.getAnfme() ); |
| | | if (elem.getAnfme() > orderDetl.getEnableQty()) { |
| | | throw new CoolException(orderDetl.getMatnr() + "入库数量不合法"); |
| | | } |
| | | // 修改订单作业数量 |
| | | if (!orderDetlService.increaseWorkQty(order.getId(), elem.getMatnr(), elem.getBatch(), elem.getAnfme())) { |
| | | throw new CoolException("修改单据作业数量失败"); |
| | | } |
| | | |
| | | DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme()); |
| | | if (DetlDto.has(detlDtos, detlDto)) { |
| | | DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch()); |
| | | assert one != null; |
| | | one.setAnfme(one.getAnfme() + detlDto.getAnfme()); |
| | | } else { |
| | | detlDtos.add(detlDto); |
| | | } |
| | | }); |
| | | for (DetlDto detlDto : detlDtos) { |
| | | Mat mat = matService.selectByMatnr(detlDto.getMatnr()); |
| | | if (Cools.isEmpty(mat)) { |
| | | throw new CoolException(detlDto.getMatnr() + "商品档案不存在"); |
| | | } |
| | | WaitPakin waitPakin = new WaitPakin(); |
| | | waitPakin.sync(mat); |
| | | waitPakin.setOrderNo(order.getOrderNo()); // 单据编号 |
| | | waitPakin.setBatch(detlDto.getBatch()); // 序列码 |
| | | waitPakin.setZpallet(param.getBarcode()); // 托盘码 |
| | | waitPakin.setIoStatus("N"); // 入出状态 |
| | | waitPakin.setAnfme(detlDto.getAnfme()); // 数量 |
| | | waitPakin.setStatus("Y"); // 状态 |
| | | waitPakin.setAppeUser(userId); |
| | | waitPakin.setAppeTime(now); |
| | | waitPakin.setModiUser(userId); |
| | | waitPakin.setModiTime(now); |
| | | OrderDetl orderDetl = orderDetlService.selectItem(order.getOrderNo(), waitPakin.getMatnr(), waitPakin.getBatch(),detlDto.getAnfme()); |
| | | if (orderDetl == null) { |
| | | orderDetl = orderDetlService.selectItem(order.getOrderNo(), waitPakin.getMatnr(), null,detlDto.getAnfme()); |
| | | } |
| | | if (orderDetl!=null){ |
| | | waitPakin.setSPgNO(orderDetl.getSPgNO()); |
| | | waitPakin.setOutOrderNo(orderDetl.getOutOrderNo()); |
| | | } |
| | | if (!waitPakinService.insert(waitPakin)) { |
| | | throw new CoolException("保存入库通知档失败"); |
| | | } |
| | | } |
| | | orderService.updateSettle(order.getId(), 2L, userId); |
| | | Order order = orderService.selectOne(new EntityWrapper<Order>().eq("temp1", param.getOrderNo())); |
| | | if (Cools.isEmpty(order) || order.getSettle() > 2) { |
| | | throw new CoolException("单据编号已过期"); |
| | | } |
| | | // 生成入库通知档 |
| | | List<DetlDto> detlDtos = new ArrayList<>(); |
| | | param.getCombMats().forEach(elem -> { |
| | | |
| | | // 订单明细数量校验 |
| | | //OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), elem.getMatnr(), elem.getBatch(),elem.getAnfme() ); |
| | | OrderDetl orderDetl = orderDetlService.selectById(elem.getDetlId()); |
| | | if (elem.getAnfme() > orderDetl.getEnableQty()) { |
| | | throw new CoolException(orderDetl.getMatnr() + "入库数量不合法"); |
| | | } |
| | | // 修改订单作业数量 |
| | | if (!orderDetlService.increaseWorkQty(orderDetl, elem.getAnfme())) { |
| | | throw new CoolException("修改单据作业数量失败"); |
| | | } |
| | | |
| | | Mat mat = matService.selectByMatnr(orderDetl.getMatnr()); |
| | | if (Cools.isEmpty(mat)) { |
| | | throw new CoolException(orderDetl.getMatnr() + "商品档案不存在"); |
| | | } |
| | | WaitPakin waitPakin = new WaitPakin(); |
| | | waitPakin.sync(mat); |
| | | waitPakin.setOrderNo(order.getOrderNo()); // 单据编号 |
| | | waitPakin.setBatch(orderDetl.getBatch()); // 序列码 |
| | | waitPakin.setZpallet(param.getBarcode()); // 托盘码 |
| | | waitPakin.setIoStatus("N"); // 入出状态 |
| | | waitPakin.setAnfme(elem.getAnfme()); // 数量 |
| | | waitPakin.setStatus("Y"); // 状态 |
| | | waitPakin.setAppeUser(userId); |
| | | waitPakin.setAppeTime(now); |
| | | waitPakin.setModiUser(userId); |
| | | waitPakin.setModiTime(now); |
| | | |
| | | waitPakin.setBatch(orderDetl.getBatch()); |
| | | waitPakin.setSPgNO(orderDetl.getSPgNO()); |
| | | waitPakin.setOutOrderNo(orderDetl.getOutOrderNo()); |
| | | waitPakin.setProType(orderDetl.getProType()); |
| | | waitPakin.setLuHao(orderDetl.getLuHao()); |
| | | waitPakin.setPacking(orderDetl.getPacking()); |
| | | if (!waitPakinService.insert(waitPakin)) { |
| | | throw new CoolException("保存入库通知档失败"); |
| | | } |
| | | }); |
| | | |
| | | orderService.updateSettle(order.getId(), 2L, userId); |
| | | // } |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void packComb(CombParam param, Long userId) { |
| | | if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) { |
| | | throw new CoolException(BaseRes.PARAM); |
| | | } |
| | | // 判断是否有相同条码的数据 |
| | | if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>(). |
| | | eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) { |
| | | throw new CoolException(param.getBarcode() + "数据正在进行入库"); |
| | | } |
| | | Date now = new Date(); |
| | | |
| | | boolean packDown = Parameter.get().getPackDown().equals("true"); |
| | | |
| | | // 无单组托 |
| | | if (Cools.isEmpty(param.getOrderNo())) { |
| | | |
| | | // 生成入库通知档 |
| | | List<DetlDto> detlDtos = new ArrayList<>(); |
| | | param.getCombMats().forEach(elem -> { |
| | | // 打包上线数据校验 |
| | | if (packDown) { |
| | | Pack pack = packService.selectByBarcode(elem.getMatnr()); |
| | | if (pack == null) { |
| | | throw new CoolException(elem.getMatnr() + "条码冗余,请检查!"); |
| | | } |
| | | if (pack.getSettle() != 1) { |
| | | throw new CoolException(elem.getMatnr() + "条码已下线,请检查!"); |
| | | } |
| | | } |
| | | Mat analyse = MatUtils.analyseMat(elem.getMatnr()); |
| | | // 条码、物料代码、序列号、数量 |
| | | DetlDto detlDto = new DetlDto(elem.getMatnr(), analyse.getMatnr(), analyse.getBarcode(), elem.getAnfme()); |
| | | // DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme()); |
| | | if (DetlDto.has(detlDtos, detlDto)) { |
| | | DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch()); |
| | | assert one != null; |
| | | one.setAnfme(one.getAnfme() + detlDto.getAnfme()); |
| | | } else { |
| | | detlDtos.add(detlDto); |
| | | } |
| | | }); |
| | | |
| | | if (packDown) { |
| | | MesCombParam mesCombParam = new MesCombParam(); |
| | | mesCombParam.setZpallet(param.getBarcode()); |
| | | mesCombParam.setPakinTime(DateUtils.convert(now)); |
| | | mesCombParam.setLgort("5008"); |
| | | mesCombParam.setPlantCode("5000"); |
| | | mesCombParam.setFromCode("5012-20"); |
| | | mesCombParam.setStationCode("JJQ-PFZPDB-XX"); |
| | | for (DetlDto detlDto : detlDtos) { |
| | | mesCombParam.getList().add(new MesCombParam.Detl(detlDto.getOrderNo(), detlDto.getAnfme())); |
| | | } |
| | | String response = ""; |
| | | boolean success = false; |
| | | try { |
| | | response = new HttpHandler.Builder() |
| | | .setUri(MesConstant.URL) |
| | | .setPath(MesConstant.PACK_DOWN_URL) |
| | | .setJson(JSON.toJSONString(mesCombParam)) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (jsonObject.getInteger("code").equals(200)) { |
| | | success = true; |
| | | } else if (jsonObject.getInteger("code").equals(500)) { |
| | | log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL + MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response); |
| | | throw new CoolException(jsonObject.getString("msg")); |
| | | } else { |
| | | log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL + MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response); |
| | | throw new CoolException("上报mes系统失败"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("fail", e); |
| | | throw new CoolException(e.getMessage()); |
| | | } finally { |
| | | try { |
| | | // 保存接口日志 |
| | | apiLogService.save( |
| | | "打包下线帮托上报", |
| | | MesConstant.URL + MesConstant.PACK_DOWN_URL, |
| | | null, |
| | | "127.0.0.1", |
| | | JSON.toJSONString(mesCombParam), |
| | | response, |
| | | success |
| | | ); |
| | | } catch (Exception e) { |
| | | log.error("", e); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | // 生成入库单据 |
| | | String orderNo = "PACK" + snowflakeIdWorker.nextId(); |
| | | OpenOrderPakinParam openParam = new OpenOrderPakinParam(); |
| | | openParam.setOrderNo(orderNo); |
| | | openParam.setOrderTime(DateUtils.convert(now)); |
| | | openParam.setOrderType("打包入库单"); |
| | | openParam.setOrderDetails(detlDtos); |
| | | openService.pakinOrderCreate(openParam); |
| | | Order order = orderService.selectByNo(orderNo); |
| | | if (null == order) { |
| | | throw new CoolException("生成单据失败"); |
| | | } |
| | | if (!orderService.updateSettle(order.getId(), 2L, userId)) { |
| | | throw new CoolException("修改单据状态失败"); |
| | | } |
| | | |
| | | // 生成入库通知档 |
| | | for (DetlDto detlDto : detlDtos) { |
| | | |
| | | // 修改作业数量 ---------------------------------------- |
| | | // 订单明细数量校验 |
| | | OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), detlDto.getMatnr(), detlDto.getBatch(),detlDto.getAnfme()); |
| | | if (detlDto.getAnfme() > orderDetl.getEnableQty()) { |
| | | throw new CoolException(orderDetl.getMatnr() + "入库数量不合法"); |
| | | } |
| | | // 修改订单作业数量 |
| | | if (!orderDetlService.increaseWorkQty(order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getAnfme())) { |
| | | throw new CoolException("修改单据作业数量失败"); |
| | | } |
| | | |
| | | // 保存入库通知档 |
| | | Mat mat = matService.selectByMatnr(detlDto.getMatnr()); |
| | | if (Cools.isEmpty(mat)) { |
| | | throw new CoolException(detlDto.getMatnr() + "商品档案不存在"); |
| | | } |
| | | WaitPakin waitPakin = new WaitPakin(); |
| | | waitPakin.sync(mat); |
| | | waitPakin.setOrderNo(orderNo); |
| | | waitPakin.setBatch(detlDto.getBatch()); |
| | | waitPakin.setZpallet(param.getBarcode()); // 托盘码 |
| | | waitPakin.setIoStatus("N"); // 入出状态 |
| | | waitPakin.setAnfme(detlDto.getAnfme()); // 数量 |
| | | waitPakin.setStatus("Y"); // 状态 |
| | | waitPakin.setAppeUser(userId); |
| | | waitPakin.setAppeTime(now); |
| | | waitPakin.setModiUser(userId); |
| | | waitPakin.setModiTime(now); |
| | | if (!waitPakinService.insert(waitPakin)) { |
| | | throw new CoolException("保存入库通知档失败"); |
| | | } |
| | | // 修改打包数据状态 |
| | | Pack pack = packService.selectByBarcode(detlDto.getOrderNo()); |
| | | pack.setSettle(2L); |
| | | pack.setUpdateTime(now); |
| | | pack.setUpdateBy(userId); |
| | | if (!packService.updateById(pack)) { |
| | | throw new CoolException("修改打包数据异常"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | // @Override |
| | | // @Transactional |
| | | // public void packComb(CombParam param, Long userId) { |
| | | // if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) { |
| | | // throw new CoolException(BaseRes.PARAM); |
| | | // } |
| | | // // 判断是否有相同条码的数据 |
| | | // if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>(). |
| | | // eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) { |
| | | // throw new CoolException(param.getBarcode() + "数据正在进行入库"); |
| | | // } |
| | | // Date now = new Date(); |
| | | // |
| | | // boolean packDown = Parameter.get().getPackDown().equals("true"); |
| | | // |
| | | // // 无单组托 |
| | | // if (Cools.isEmpty(param.getOrderNo())) { |
| | | // |
| | | // // 生成入库通知档 |
| | | // List<DetlDto> detlDtos = new ArrayList<>(); |
| | | // param.getCombMats().forEach(elem -> { |
| | | // // 打包上线数据校验 |
| | | // if (packDown) { |
| | | // Pack pack = packService.selectByBarcode(elem.getMatnr()); |
| | | // if (pack == null) { |
| | | // throw new CoolException(elem.getMatnr() + "条码冗余,请检查!"); |
| | | // } |
| | | // if (pack.getSettle() != 1) { |
| | | // throw new CoolException(elem.getMatnr() + "条码已下线,请检查!"); |
| | | // } |
| | | // } |
| | | // Mat analyse = MatUtils.analyseMat(elem.getMatnr()); |
| | | // // 条码、物料代码、序列号、数量 |
| | | // DetlDto detlDto = new DetlDto(elem.getMatnr(), analyse.getMatnr(), analyse.getBarcode(), elem.getAnfme()); |
| | | //// DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme()); |
| | | // if (DetlDto.has(detlDtos, detlDto)) { |
| | | // DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch()); |
| | | // assert one != null; |
| | | // one.setAnfme(one.getAnfme() + detlDto.getAnfme()); |
| | | // } else { |
| | | // detlDtos.add(detlDto); |
| | | // } |
| | | // }); |
| | | // |
| | | // if (packDown) { |
| | | // MesCombParam mesCombParam = new MesCombParam(); |
| | | // mesCombParam.setZpallet(param.getBarcode()); |
| | | // mesCombParam.setPakinTime(DateUtils.convert(now)); |
| | | // mesCombParam.setLgort("5008"); |
| | | // mesCombParam.setPlantCode("5000"); |
| | | // mesCombParam.setFromCode("5012-20"); |
| | | // mesCombParam.setStationCode("JJQ-PFZPDB-XX"); |
| | | // for (DetlDto detlDto : detlDtos) { |
| | | // mesCombParam.getList().add(new MesCombParam.Detl(detlDto.getOrderNo(), detlDto.getAnfme())); |
| | | // } |
| | | // String response = ""; |
| | | // boolean success = false; |
| | | // try { |
| | | // response = new HttpHandler.Builder() |
| | | // .setUri(MesConstant.URL) |
| | | // .setPath(MesConstant.PACK_DOWN_URL) |
| | | // .setJson(JSON.toJSONString(mesCombParam)) |
| | | // .build() |
| | | // .doPost(); |
| | | // JSONObject jsonObject = JSON.parseObject(response); |
| | | // if (jsonObject.getInteger("code").equals(200)) { |
| | | // success = true; |
| | | // } else if (jsonObject.getInteger("code").equals(500)) { |
| | | // log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL + MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response); |
| | | // throw new CoolException(jsonObject.getString("msg")); |
| | | // } else { |
| | | // log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL + MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response); |
| | | // throw new CoolException("上报mes系统失败"); |
| | | // } |
| | | // } catch (Exception e) { |
| | | // log.error("fail", e); |
| | | // throw new CoolException(e.getMessage()); |
| | | // } finally { |
| | | // try { |
| | | // // 保存接口日志 |
| | | // apiLogService.save( |
| | | // "打包下线帮托上报", |
| | | // MesConstant.URL + MesConstant.PACK_DOWN_URL, |
| | | // null, |
| | | // "127.0.0.1", |
| | | // JSON.toJSONString(mesCombParam), |
| | | // response, |
| | | // success |
| | | // ); |
| | | // } catch (Exception e) { |
| | | // log.error("", e); |
| | | // } |
| | | // } |
| | | // |
| | | // } |
| | | // |
| | | // // 生成入库单据 |
| | | // String orderNo = "PACK" + snowflakeIdWorker.nextId(); |
| | | // OpenOrderPakinParam openParam = new OpenOrderPakinParam(); |
| | | // openParam.setOrderNo(orderNo); |
| | | // openParam.setOrderTime(DateUtils.convert(now)); |
| | | // openParam.setOrderType("打包入库单"); |
| | | // openParam.setOrderDetails(detlDtos); |
| | | // openService.pakinOrderCreate(openParam); |
| | | // Order order = orderService.selectByNo(orderNo); |
| | | // if (null == order) { |
| | | // throw new CoolException("生成单据失败"); |
| | | // } |
| | | // if (!orderService.updateSettle(order.getId(), 2L, userId)) { |
| | | // throw new CoolException("修改单据状态失败"); |
| | | // } |
| | | // |
| | | // // 生成入库通知档 |
| | | // for (DetlDto detlDto : detlDtos) { |
| | | // |
| | | // // 修改作业数量 ---------------------------------------- |
| | | // // 订单明细数量校验 |
| | | // OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), detlDto.getMatnr(), detlDto.getBatch(),detlDto.getAnfme()); |
| | | // |
| | | // if (detlDto.getAnfme() > orderDetl.getEnableQty()) { |
| | | // throw new CoolException(orderDetl.getMatnr() + "入库数量不合法"); |
| | | // } |
| | | // // 修改订单作业数量 |
| | | // if (!orderDetlService.increaseWorkQty(orderDetl, detlDto.getAnfme())) { |
| | | // throw new CoolException("修改单据作业数量失败"); |
| | | // } |
| | | // |
| | | // // 保存入库通知档 |
| | | // Mat mat = matService.selectByMatnr(detlDto.getMatnr()); |
| | | // if (Cools.isEmpty(mat)) { |
| | | // throw new CoolException(detlDto.getMatnr() + "商品档案不存在"); |
| | | // } |
| | | // WaitPakin waitPakin = new WaitPakin(); |
| | | // waitPakin.sync(mat); |
| | | // waitPakin.setOrderNo(orderNo); |
| | | // waitPakin.setBatch(detlDto.getBatch()); |
| | | // waitPakin.setZpallet(param.getBarcode()); // 托盘码 |
| | | // waitPakin.setIoStatus("N"); // 入出状态 |
| | | // waitPakin.setAnfme(detlDto.getAnfme()); // 数量 |
| | | // waitPakin.setStatus("Y"); // 状态 |
| | | // waitPakin.setAppeUser(userId); |
| | | // waitPakin.setAppeTime(now); |
| | | // waitPakin.setModiUser(userId); |
| | | // waitPakin.setModiTime(now); |
| | | // if (!waitPakinService.insert(waitPakin)) { |
| | | // throw new CoolException("保存入库通知档失败"); |
| | | // } |
| | | // // 修改打包数据状态 |
| | | // Pack pack = packService.selectByBarcode(detlDto.getOrderNo()); |
| | | // pack.setSettle(2L); |
| | | // pack.setUpdateTime(now); |
| | | // pack.setUpdateBy(userId); |
| | | // if (!packService.updateById(pack)) { |
| | | // throw new CoolException("修改打包数据异常"); |
| | | // } |
| | | // } |
| | | // |
| | | // } |
| | | // } |
| | | |
| | | @Override |
| | | @Transactional |
| | |
| | | |
| | | BasDevp sta = basDevpService.checkSiteStatus(staNo); |
| | | //根据订单号生成出库任务工作档 |
| | | List<OrderDetl> pg_no = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("pg_no",orderNo)); |
| | | List<OrderDetl> pg_no = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("pg_no", orderNo)); |
| | | Order order = orderService.selectOne(new EntityWrapper<Order>().eq("order_no", pg_no.get(0).getOrderNo())); |
| | | if (order.getSettle() != 1 && order.getSettle() != 2) { |
| | | throw new CoolException("该订单已处理"); |
| | |
| | | Date now = new Date(); |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | //查询所有库位状态为F的库位信息 |
| | | List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(), orderDetl.getBatch(), null, null); |
| | | List<LocDetl> locDetls = locDetlService.queryStock(orderDetl); |
| | | if (locDetls.size() == 0) { |
| | | throw new CoolException("库存中没有该物料"); |
| | | } |
| | |
| | | throw new CoolException(locDetl.getLocNo() + "库位不是在库状态"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 拣料途中并板直接加到库存中 |
| | | * @param param |
| | | * @param userId |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public R WarehouseOutPickMergeV1(WarehouseOutPickMergeParam param, Long userId) { |
| | | //判断库位状态 |
| | | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", param.getLocNo())); |
| | | if (Cools.isEmpty(locMast)){ |
| | | return R.error("该库位不存在"); |
| | | } |
| | | if (!locMast.getLocSts().equals("P")){ |
| | | return R.error("该库位状态为:"+locMast.getLocSts()+",不满足拣料途中并板条件!!!"); |
| | | } |
| | | |
| | | HashMap<String, OrderDetl> mapData = new HashMap<>(); |
| | | for (OrderDetl orderDetl : param.getCombMats()) { |
| | | String key = orderDetl.getMatnr(); |
| | | // private static final String[] sameFields = {"matnr", "batch", "outOrderNo", "luHao", "packing", "sPgNO", "proType","color"}; |
| | | if (!Cools.isEmpty(orderDetl.getBatch())) { |
| | | key += "_" + orderDetl.getBatch(); |
| | | } |
| | | if (!Cools.isEmpty(orderDetl.getOutOrderNo())) { |
| | | key += "_" + orderDetl.getOutOrderNo(); |
| | | } |
| | | if (!Cools.isEmpty(orderDetl.getLuHao())) { |
| | | key += "_" + orderDetl.getLuHao(); |
| | | } |
| | | if (!Cools.isEmpty(orderDetl.getPacking())) { |
| | | key += "_" + orderDetl.getPacking(); |
| | | } |
| | | if (!Cools.isEmpty(orderDetl.getSPgNO())) { |
| | | key += "_" + orderDetl.getSPgNO(); |
| | | } |
| | | if (!Cools.isEmpty(orderDetl.getProType())) { |
| | | key += "_" + orderDetl.getProType(); |
| | | } |
| | | if (!Cools.isEmpty(orderDetl.getColor())) { |
| | | key += "_" + orderDetl.getColor(); |
| | | } |
| | | |
| | | OrderDetl value = mapData.get(key); |
| | | if(value == null){ |
| | | mapData.put(key, orderDetl); |
| | | }else { |
| | | value.setAnfme(value.getAnfme() + orderDetl.getAnfme()); |
| | | mapData.put(key, value); |
| | | } |
| | | } |
| | | |
| | | List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", locMast.getLocNo())); |
| | | |
| | | HashMap<String, PickMergeDto> locData = new HashMap<>(); |
| | | for (LocDetl locDetl : locDetls) { |
| | | String matKey = locDetl.getMatnr(); |
| | | if (!Cools.isEmpty(locDetl.getBatch())) { |
| | | matKey += "_" + locDetl.getBatch(); |
| | | } |
| | | if (!Cools.isEmpty(locDetl.getOutOrderNo())) { |
| | | matKey += "_" + locDetl.getOutOrderNo(); |
| | | } |
| | | if (!Cools.isEmpty(locDetl.getLuHao())) { |
| | | matKey += "_" + locDetl.getLuHao(); |
| | | } |
| | | if (!Cools.isEmpty(locDetl.getPacking())) { |
| | | matKey += "_" + locDetl.getPacking(); |
| | | } |
| | | if (!Cools.isEmpty(locDetl.getSPgNO())) { |
| | | matKey += "_" + locDetl.getSPgNO(); |
| | | } |
| | | if (!Cools.isEmpty(locDetl.getProType())) { |
| | | matKey += "_" + locDetl.getProType(); |
| | | } |
| | | if (!Cools.isEmpty(locDetl.getColor())) { |
| | | matKey += "_" + locDetl.getColor(); |
| | | } |
| | | |
| | | PickMergeDto dto = new PickMergeDto(); |
| | | dto.setOriginAnfme(locDetl.getAnfme()); |
| | | dto.setLocDetl(locDetl); |
| | | dto.setOrders(new ArrayList<>()); |
| | | locData.put(matKey, dto); |
| | | } |
| | | |
| | | for (Map.Entry<String, OrderDetl> entry : mapData.entrySet()) { |
| | | OrderDetl orderDetl = entry.getValue(); |
| | | LocDetl locDetl = new LocDetl(); |
| | | locDetl.sync(orderDetl); |
| | | locDetl.setLocNo(param.getLocNo()); |
| | | locDetl.setBarcode(locMast.getBarcode()); |
| | | Mat mat = matService.selectOne(new EntityWrapper<Mat>().eq("matnr",locDetl.getMatnr())); |
| | | locDetl.setMaktx(mat.getMaktx()); |
| | | |
| | | String matKey = locDetl.getMatnr(); |
| | | if (!Cools.isEmpty(locDetl.getBatch())) { |
| | | matKey += "_" + locDetl.getBatch(); |
| | | } |
| | | if (!Cools.isEmpty(locDetl.getOutOrderNo())) { |
| | | matKey += "_" + locDetl.getOutOrderNo(); |
| | | } |
| | | if (!Cools.isEmpty(locDetl.getLuHao())) { |
| | | matKey += "_" + locDetl.getLuHao(); |
| | | } |
| | | if (!Cools.isEmpty(locDetl.getPacking())) { |
| | | matKey += "_" + locDetl.getPacking(); |
| | | } |
| | | if (!Cools.isEmpty(locDetl.getSPgNO())) { |
| | | matKey += "_" + locDetl.getSPgNO(); |
| | | } |
| | | if (!Cools.isEmpty(locDetl.getProType())) { |
| | | matKey += "_" + locDetl.getProType(); |
| | | } |
| | | if (!Cools.isEmpty(locDetl.getColor())) { |
| | | matKey += "_" + locDetl.getColor(); |
| | | } |
| | | |
| | | |
| | | PickMergeDto dto = locData.get(matKey); |
| | | if (dto == null) { |
| | | ArrayList<PickMergeOrderDto> orders = new ArrayList<>(); |
| | | orders.add(new PickMergeOrderDto(locDetl.getOrderNo(), locDetl.getAnfme())); |
| | | |
| | | dto = new PickMergeDto(); |
| | | dto.setOriginAnfme(0.0); |
| | | dto.setLocDetl(locDetl); |
| | | dto.setOrders(orders); |
| | | |
| | | locData.put(matKey, dto); |
| | | }else { |
| | | LocDetl detl = dto.getLocDetl(); |
| | | List<PickMergeOrderDto> orders = dto.getOrders(); |
| | | |
| | | detl.setAnfme(detl.getAnfme() + locDetl.getAnfme()); |
| | | orders.add(new PickMergeOrderDto(locDetl.getOrderNo(), locDetl.getAnfme())); |
| | | |
| | | dto.setLocDetl(detl); |
| | | dto.setOrders(orders); |
| | | |
| | | locData.put(matKey, dto); |
| | | } |
| | | } |
| | | |
| | | |
| | | for (Map.Entry<String, PickMergeDto> entry : locData.entrySet()) { |
| | | PickMergeDto dto = entry.getValue(); |
| | | |
| | | Double originAnfme = dto.getOriginAnfme(); |
| | | LocDetl locDetl = dto.getLocDetl(); |
| | | List<PickMergeOrderDto> orders = dto.getOrders(); |
| | | |
| | | Boolean b=false; |
| | | for (LocDetl detl : locDetls) { |
| | | b= MatCompareUtils.compare(detl, locDetl); |
| | | if (b) break; |
| | | } |
| | | |
| | | if (b){ |
| | | if (!locDetlService.updateAnfmeAdd(locDetl.getAnfme(),locDetl.getLocNo(),locDetl)) { |
| | | throw new CoolException("并板库存更新失败"); |
| | | } |
| | | }else { |
| | | locDetl.setZpallet(locDetl.getBarcode()); |
| | | if (!locDetlService.insert(locDetl)) { |
| | | throw new CoolException("并板库存插入失败"); |
| | | } |
| | | } |
| | | |
| | | if (!orders.isEmpty()){ |
| | | for (PickMergeOrderDto orderDto : orders) { |
| | | Order order = orderService.selectByNo(orderDto.getOrderNo()); |
| | | if (Cools.isEmpty(order)){ |
| | | continue; |
| | | } |
| | | if (order.getSettle() == 1){ |
| | | orderService.updateSettle(order.getId(), 2L, 9527L); |
| | | } |
| | | |
| | | |
| | | LocDto locDto = new LocDto(locDetl.getOrderNo(),locDetl.getMatnr(),locDetl.getBatch(),locDetl.getOutOrderNo(),locDetl.getLuHao(),locDetl.getPacking(),locDetl.getSPgNO(),locDetl.getProType(),locDetl.getColor()); |
| | | OrderDetl orderDetl = orderDetlService.selectItem(locDto); |
| | | if (Cools.isEmpty(orderDetl)){ |
| | | continue; |
| | | } |
| | | if (orderDetl.getAnfme() < (orderDetl.getWorkQty() + orderDto.getAnfme())) { |
| | | throw new CoolException("并板数量出错,订单剩余出库数量小于已出库数量与将并板数量之和!!!"); |
| | | } |
| | | // 修改订单明细作业数量 |
| | | if (!orderDetlService.increaseWorkQtyByOrderNo(orderDto.getOrderNo(), orderDetl, orderDto.getAnfme())) { |
| | | throw new CoolException("修改单据明细工作数量失败"); |
| | | } |
| | | // 修改订单明细完成数量 |
| | | if (!orderDetlService.increaseQtyByOrderNo1(orderDto.getOrderNo(), orderDetl, orderDto.getAnfme())) { |
| | | throw new CoolException("修改单据明细完成数量失败"); |
| | | } |
| | | // 修改订单状态 作业中 ===>> 已完成 |
| | | orderService.checkComplete(orderDto.getOrderNo()); |
| | | |
| | | try { |
| | | //处理库存信息 |
| | | AdjDetl adjDetl = new AdjDetl(); |
| | | adjDetl.setLocNo(locDetl.getLocNo()); |
| | | adjDetl.setMatnr(locDetl.getMatnr()); |
| | | adjDetl.setBatch(locDetl.getBatch()); |
| | | adjDetl.setOriQty(originAnfme); |
| | | adjDetl.setAdjQty(locDetl.getAnfme()); |
| | | adjDetl.setMemo("拣料途中并板"); |
| | | adjDetl.setModiUser(userId); |
| | | adjDetl.setAppeUser(userId); |
| | | adjDetl.setAppeTime(new Date()); |
| | | adjDetl.setModiTime(new Date()); |
| | | adjDetl.setExpand(locDetl);//对扩充进行拼接 |
| | | adjDetl.setOrderNo(order.getOrderNo()); |
| | | |
| | | if (!adjDetlService.save(adjDetl,userId)) { |
| | | throw new CoolException("保存库存调整记录失败"); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | throw new CoolException("更新库存数据出错" + e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | return R.ok(); |
| | | } |
| | | } |