| | |
| | | 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.MatCode; |
| | | import com.zy.asrs.entity.Order; |
| | | import com.zy.asrs.entity.OrderDetl; |
| | | import com.zy.asrs.entity.WaitPakin; |
| | | 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.asrs.utils.VersionUtils; |
| | | import com.zy.asrs.task.core.ReturnT; |
| | | import com.zy.asrs.task.handler.WorkLogHandler; |
| | | import com.zy.asrs.utils.MatUtils; |
| | | 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.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 java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 移动端服务核心类 |
| | | * Created by vincent on 2020/6/28 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class MobileServiceImpl implements MobileService { |
| | | |
| | | @Autowired |
| | | private MatCodeService matCodeService; |
| | | private MatService matService; |
| | | @Autowired |
| | | private WaitPakinService waitPakinService; |
| | | @Autowired |
| | | private OrderService orderService; |
| | | @Autowired |
| | | 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; |
| | | @Autowired |
| | | private ApiLogService apiLogService; |
| | | @Autowired |
| | | private WorkLogHandler workLogHandler; |
| | | @Autowired |
| | | private CommonService commonService; |
| | | @Autowired |
| | | private LocMastService locMastService; |
| | | |
| | | @Override |
| | | @Transactional |
| | |
| | | // 判断是否有相同条码的数据 |
| | | if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>(). |
| | | eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) { |
| | | throw new CoolException("条码数据已存在"); |
| | | throw new CoolException(param.getBarcode() + "数据正在进行入库"); |
| | | } |
| | | |
| | | // todo: 不下线重新入库 |
| | | WrkMast wrkMast18 = wrkMastService.selectByBarcode(param.getBarcode()); |
| | | if (wrkMast18 != null && wrkMast18.getWrkSts() == 18) { |
| | | ReturnT<String> start = workLogHandler.start(wrkMast18); |
| | | if (!start.isSuccess()) { |
| | | log.error("工作档[workNo={}]历史档处理失败", wrkMast18.getWrkNo()); |
| | | } |
| | | } |
| | | |
| | | Date now = new Date(); |
| | | |
| | | // 无单组托 |
| | | if (Cools.isEmpty(param.getOrderNo())) { |
| | | |
| | | // 生成入库通知档 |
| | | List<DetlDto> detlDtos = new ArrayList<>(); |
| | | param.getCombMats().forEach(elem -> { |
| | | DetlDto detlDto = new DetlDto(elem.getMatNo(), elem.getBatch(), elem.getCount()); |
| | | 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) { |
| | | MatCode matCode = matCodeService.selectById(detlDto.getMatnr()); |
| | | if (Cools.isEmpty(matCode)) { |
| | | throw new CoolException("物料数据错误"); |
| | | } |
| | | WaitPakin waitPakin = new WaitPakin(); |
| | | 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); |
| | | VersionUtils.setWaitPakIn(waitPakin, matCode); |
| | | if (!waitPakinService.insert(waitPakin)) { |
| | | throw new CoolException("保存数据失败"); |
| | | } |
| | | } |
| | | // 关联组托 |
| | | } else { |
| | | Order order = orderService.selectByNo(param.getOrderNo()); |
| | |
| | | param.getCombMats().forEach(elem -> { |
| | | |
| | | // 订单明细数量校验 |
| | | OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), elem.getMatNo(), elem.getBatch()); |
| | | if (elem.getCount() > orderDetl.getEnableQty()) { |
| | | OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), elem.getMatnr(), elem.getBatch()); |
| | | if (elem.getAnfme() > orderDetl.getEnableQty()) { |
| | | throw new CoolException(orderDetl.getMatnr() + "入库数量不合法"); |
| | | } |
| | | // 修改订单明细数量 |
| | | if (!orderDetlService.increase(order.getId(), elem.getMatNo(), elem.getBatch(), elem.getCount())) { |
| | | if (!orderDetlService.increase(order.getId(), elem.getMatnr(), elem.getBatch(), elem.getAnfme())) { |
| | | throw new CoolException("修改单据明细数量失败"); |
| | | } |
| | | |
| | | DetlDto detlDto = new DetlDto(elem.getMatNo(), elem.getBatch(), elem.getCount()); |
| | | 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; |
| | |
| | | detlDtos.add(detlDto); |
| | | } |
| | | }); |
| | | |
| | | orderService.updateSettle(order.getId(), 2L, userId); |
| | | } |
| | | |
| | | LocMast locMast1 = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_sts", "O")); |
| | | if (Cools.isEmpty(locMast1)) { |
| | | throw new CoolException("未找到正确的库位信息"); |
| | | } |
| | | |
| | | int workNo = commonService.getWorkNo(0); |
| | | |
| | | // 生成工作档 |
| | | WrkMast wrkMast = new WrkMast(); |
| | | wrkMast.setWrkNo(workNo); |
| | | wrkMast.setIoTime(new Date()); |
| | | wrkMast.setWrkSts(9L); // 工作状态:生成入库ID |
| | | wrkMast.setIoType(1); // 入出库状态:1.入库 |
| | | Double ioPri = wrkMastService.getIoPri(1, locMast1.getLocNo()); |
| | | wrkMast.setIoPri(ioPri); // 优先级 |
| | | wrkMast.setCrnNo(locMast1.getCrnNo()); |
| | | wrkMast.setOutMost(locMastService.isOutMost(locMast1.getLocNo(), true)?1:0);; |
| | | wrkMast.setSourceStaNo(null); |
| | | wrkMast.setStaNo(null); |
| | | wrkMast.setLocNo(locMast1.getLocNo()); |
| | | wrkMast.setBarcode(param.getBarcode()); // 托盘码 |
| | | wrkMast.setFullPlt("Y"); // 满板:Y |
| | | wrkMast.setPicking("N"); // 拣料 |
| | | wrkMast.setExitMk("N"); // 退出 |
| | | wrkMast.setEmptyMk("N"); // 空板 |
| | | wrkMast.setLinkMis("Y"); |
| | | wrkMast.setCtnType(null); // 容器类型 |
| | | // 操作人员数据 |
| | | wrkMast.setAppeTime(now); |
| | | wrkMast.setModiTime(now); |
| | | boolean res = wrkMastService.insert(wrkMast); |
| | | if (!res) { |
| | | throw new CoolException("保存工作档失败"); |
| | | } |
| | | |
| | | |
| | | for (CombParam.CombMat paramMat : param.getCombMats() ) |
| | | { |
| | | Mat mat = matService.selectByMatnr(paramMat.getMatnr()); |
| | | if (Cools.isEmpty(mat)) { |
| | | throw new CoolException(paramMat.getMatnr() + "商品档案不存在"); |
| | | } |
| | | |
| | | // 生成工作档明细 |
| | | WrkDetl wrkDetl = new WrkDetl(); |
| | | wrkDetl.sync(mat); |
| | | wrkDetl.setAnfme(paramMat.getAnfme()); |
| | | wrkDetl.setZpallet(param.getBarcode()); |
| | | // wrkDetl.setAnfme(1.0D); |
| | | wrkDetl.setWrkNo(wrkMast.getWrkNo()); |
| | | wrkDetl.setIoTime(wrkMast.getIoTime()); |
| | | wrkDetl.setAppeTime(now); |
| | | wrkDetl.setModiTime(now); |
| | | if (!wrkDetlService.insert(wrkDetl)) { |
| | | throw new CoolException("保存工作明细失败"); |
| | | } |
| | | } |
| | | |
| | | // // 更新入库通知档 ioStatus ===>> Y |
| | | // Wrapper<WaitPakin> wrapper = new EntityWrapper<WaitPakin>() |
| | | // .eq("zpallet", barcode); |
| | | // WaitPakin setParam = new WaitPakin(); |
| | | // setParam.setIoStatus("Y"); |
| | | // setParam.setModiTime(now); |
| | | // if (!waitPakinService.update(setParam, wrapper)) { |
| | | // throw new CoolException("更新通知档失败"); |
| | | // } |
| | | |
| | | |
| | | // 更新目标库位状态 |
| | | |
| | | if (locMast1.getLocSts().equals("O")){ |
| | | locMast1.setLocSts("S"); // S.入库预约 |
| | | locMast1.setModiTime(now); |
| | | if (!locMastService.updateById(locMast1)){ |
| | | throw new CoolException("改变库位状态失败"); |
| | | } |
| | | } else { |
| | | throw new CoolException(locMast1.getLocNo()+"目标库位已被占用"); |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void adjust(MobileAdjustParam param, Long userId) { |
| | | BasDevp basDevp = basDevpService.selectById(param.getStaNo()); |
| | | if (null == basDevp || basDevp.getWrkNo() == null) { |
| | | throw new CoolException(param.getStaNo() + "盘点站无效"); |
| | | } |
| | | 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() + "条码已下线,请检查!"); |
| | | } |
| | | } |
| | | 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) { |
| | | MatCode matCode = matCodeService.selectById(detlDto.getMatnr()); |
| | | if (Cools.isEmpty(matCode)) { |
| | | throw new CoolException("物料数据错误"); |
| | | |
| | | // 修改作业数量 ---------------------------------------- |
| | | // 订单明细数量校验 |
| | | 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.setOrderNo(order.getOrderNo()); // 单据编号 |
| | | waitPakin.setBatch(detlDto.getBatch()); // 批号 |
| | | waitPakin.sync(mat); |
| | | waitPakin.setOrderNo(orderNo); |
| | | waitPakin.setBatch(detlDto.getBatch()); |
| | | waitPakin.setZpallet(param.getBarcode()); // 托盘码 |
| | | waitPakin.setIoStatus("N"); // 入出状态 |
| | | waitPakin.setAnfme(detlDto.getAnfme()); // 数量 |
| | |
| | | waitPakin.setAppeTime(now); |
| | | waitPakin.setModiUser(userId); |
| | | waitPakin.setModiTime(now); |
| | | VersionUtils.setWaitPakIn(waitPakin, matCode); |
| | | if (!waitPakinService.insert(waitPakin)) { |
| | | throw new CoolException("保存数据失败"); |
| | | 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("修改打包数据异常"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | } |