| | |
| | | package com.zy.asrs.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.BaseRes; |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | | 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.OpenOrderPakinParam; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.common.constant.MesConstant; |
| | | import com.zy.common.entity.Parameter; |
| | | import com.zy.common.model.DetlDto; |
| | | import com.zy.common.model.MesCombParam; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | private OrderDetlService orderDetlService; |
| | | @Autowired |
| | | private BasDevpService basDevpService; |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | | private WrkDetlService wrkDetlService; |
| | | @Autowired |
| | | private PackService packService; |
| | | @Autowired |
| | | private OpenService openService; |
| | | @Autowired |
| | | private SnowflakeIdWorker snowflakeIdWorker; |
| | | |
| | | @Override |
| | | @Transactional |
| | |
| | | detlDtos.add(detlDto); |
| | | } |
| | | }); |
| | | |
| | | |
| | | for (DetlDto detlDto : detlDtos) { |
| | | Mat mat = matService.selectByMatnr(detlDto.getMatnr()); |
| | |
| | | throw new CoolException("保存入库通知档失败"); |
| | | } |
| | | } |
| | | |
| | | orderService.updateSettle(order.getId(), 2L, userId); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void adjust(MobileAdjustParam param, Long userId) { |
| | | BasDevp basDevp = basDevpService.selectById(param.getStaNo()); |
| | | if (null == basDevp || basDevp.getWrkNo() == null) { |
| | |
| | | if (!param.getWrkNo().equals(basDevp.getWrkNo())) { |
| | | throw new CoolException(param.getStaNo() + "盘点站更新,请重新检索"); |
| | | } |
| | | WrkMast wrkMast = wrkMastService.selectById(param.getWrkNo()); |
| | | if (wrkMast.getWrkSts() < 10) { |
| | | throw new CoolException("盘点无效,任务已盘点再入库"); |
| | | } |
| | | Date now = new Date(); |
| | | List<WrkDetl> wrkDetls = wrkDetlService.selectByWrkNo(wrkMast.getWrkNo()); |
| | | |
| | | List<WrkDetl> list = param.getWrkDetls(); |
| | | |
| | | // 修改数量 |
| | | Iterator<WrkDetl> iterator = wrkDetls.iterator(); |
| | | while (iterator.hasNext()) { |
| | | WrkDetl wrkDetl = iterator.next(); |
| | | Iterator<WrkDetl> iterator1 = list.iterator(); |
| | | while (iterator1.hasNext()) { |
| | | WrkDetl wrkDetl1 = iterator1.next(); |
| | | if (wrkDetl1.getAnfme() == 0) { |
| | | iterator1.remove(); |
| | | } |
| | | if (wrkDetl.getMatnr().equals(wrkDetl1.getMatnr()) && Cools.eq(wrkDetl.getBatch(), wrkDetl1.getBatch())) { |
| | | if (!wrkDetl.getAnfme().equals(wrkDetl1.getAnfme())) { |
| | | // todo 盘点记录、保存调整记录 |
| | | // 修改明细 |
| | | if (!wrkDetlService.updateAnfme(wrkDetl1.getAnfme(), wrkMast.getWrkNo(), wrkDetl.getMatnr(), wrkDetl.getBatch())) { |
| | | throw new CoolException(wrkMast.getWrkNo() + "盘点任务," + wrkDetl.getMatnr() + "商品," + wrkDetl.getBatch() + "批号修改数量失败"); |
| | | } |
| | | } |
| | | iterator.remove(); |
| | | iterator1.remove(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 删除明细 |
| | | for (WrkDetl wrkDetl : wrkDetls) { |
| | | // todo 盘点记录、保存调整记录 |
| | | if (!wrkDetlService.updateAnfme(-1.0D, wrkMast.getWrkNo(), wrkDetl.getMatnr(), wrkDetl.getBatch())) { |
| | | throw new CoolException("删除" + wrkMast.getWrkNo() + "盘点任务," + wrkDetl.getMatnr() + "商品," + wrkDetl.getBatch() + "批号任务明细失败"); |
| | | } |
| | | } |
| | | |
| | | // 添加明细 |
| | | for (WrkDetl wrkDetl : list) { |
| | | if (wrkDetl.getAnfme() == 0.0D) { continue; } |
| | | // todo 盘点记录、保存调整记录 |
| | | String orderNo = wrkDetl.getOrderNo(); |
| | | Mat mat = matService.selectByMatnr(wrkDetl.getMatnr()); |
| | | wrkDetl.sync(mat); |
| | | wrkDetl.setOrderNo(orderNo); |
| | | wrkDetl.setModiTime(now); |
| | | wrkDetl.setModiUser(userId); |
| | | wrkDetl.setAppeTime(now); |
| | | wrkDetl.setAppeUser(userId); |
| | | if (!wrkDetlService.insert(wrkDetl)) { |
| | | throw new CoolException("添加" + wrkMast.getWrkNo() + "盘点任务," + wrkDetl.getMatnr() + "商品," + wrkDetl.getBatch() + "批号任务明细失败"); |
| | | } |
| | | } |
| | | |
| | | // 修改盘点任务主档状态 |
| | | wrkMast.setFullPlt(wrkDetlService.selectByWrkNo(wrkMast.getWrkNo()).size() != 0?"Y":"N"); |
| | | wrkMast.setModiTime(now); |
| | | wrkMast.setModiUser(userId); |
| | | if (!wrkMastService.updateById(wrkMast)) { |
| | | 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() + "条码已下线,请检查!"); |
| | | } |
| | | } |
| | | 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.setCombTime(DateUtils.convert(now)); |
| | | mesCombParam.setLgort("5008"); |
| | | for (DetlDto detlDto : detlDtos) { |
| | | mesCombParam.getList().add(new MesCombParam.Detl(detlDto.getMatnr(), detlDto.getAnfme())); |
| | | } |
| | | String response; |
| | | 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)) { |
| | | log.info("请求接口成功!!!"); |
| | | } 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()); |
| | | } |
| | | |
| | | } |
| | | |
| | | // 生成入库单据 |
| | | 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()); |
| | | if (detlDto.getAnfme() > orderDetl.getEnableQty()) { |
| | | throw new CoolException(orderDetl.getMatnr() + "入库数量不合法"); |
| | | } |
| | | // 修改订单明细数量 |
| | | if (!orderDetlService.increase(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.getMatnr()); |
| | | pack.setSettle(2L); |
| | | pack.setUpdateTime(now); |
| | | pack.setUpdateBy(userId); |
| | | if (!packService.updateById(pack)) { |
| | | throw new CoolException("修改打包数据异常"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | } |