| | |
| | | package com.zy.asrs.service.impl; |
| | | |
| | | 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.OpenOrderCompleteParam; |
| | | import com.zy.asrs.entity.param.OpenOrderPakinParam; |
| | | import com.zy.asrs.entity.param.OpenOrderPakoutParam; |
| | | import com.zy.asrs.entity.param.PackParam; |
| | | import com.zy.asrs.entity.param.*; |
| | | import com.zy.asrs.entity.result.OpenOrderCompeteResult; |
| | | import com.zy.asrs.entity.result.StockVo; |
| | | import com.zy.asrs.mapper.ReportQueryMapper; |
| | | import com.zy.asrs.mapper.TagMapper; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.task.core.ReturnT; |
| | | import com.zy.asrs.task.handler.WorkLogHandler; |
| | | import com.zy.asrs.utils.MatUtils; |
| | | import com.zy.common.model.DetlDto; |
| | | import com.zy.common.utils.ListUtils; |
| | | import com.zy.common.utils.NodeUtils; |
| | | 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.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * Created by vincent on 2022/4/9 |
| | |
| | | private TagService tagService; |
| | | @Autowired |
| | | private TagMapper tagMapper; |
| | | @Autowired |
| | | private ApiLogService apiLogService; |
| | | @Autowired |
| | | private WaitPakinService waitPakinService; |
| | | @Autowired |
| | | private WrkDetlService wrkDetlService; |
| | | @Autowired |
| | | private ReportQueryMapper reportQueryMapper; |
| | | |
| | | @Override |
| | | @Transactional |
| | |
| | | Date now = new Date(); |
| | | pack = new Pack( |
| | | param.getBarcode(), // 条码[非空] |
| | | analyse.getMatnr(), // 单据号 |
| | | analyse.getMatnr(), // 物料号 |
| | | analyse.getBarcode(), // 序列码 |
| | | 1L, // 订单状态 |
| | | 1, // 状态 |
| | |
| | | if (!matService.insert(mat)) { |
| | | throw new CoolException("服务器内部错误,请联系管理员"); |
| | | } else { |
| | | log.info("打包上线添加新物料[单据号:{}]", mat.getMatnr()); |
| | | log.info("打包上线添加新物料[物料号:{}]", mat.getMatnr()); |
| | | } |
| | | } |
| | | } |
| | | @Override |
| | | @Transactional |
| | | public MatSyncParam syncMat(MatSyncParam param) { |
| | | if (Cools.isEmpty(param.getMats()) || param.getMats().size() <=0 ) { |
| | | throw new CoolException("商品数据为空"); |
| | | } |
| | | MatSyncParam matSyncParam = new MatSyncParam(); |
| | | ArrayList<MatSyncParam.Mats> matParams = new ArrayList<>(); |
| | | Tag tag = tagService.selectByName("全部", 1); |
| | | for (MatSyncParam.Mats matParam : param.getMats()){ |
| | | Date date = new Date(); |
| | | Mat mat = matService.selectByMatnr(matParam.getMatnr()); |
| | | if (Cools.isEmpty(mat)) { |
| | | Mat matNew = new Mat(); |
| | | matNew.setTagId(tag.getId()); |
| | | matNew.setMatnr(matParam.getMatnr());//物料编码 |
| | | matNew.setMaktx(matParam.getMaktx());//物料名称 |
| | | matNew.setSpecs(matParam.getSpecs());//规格 |
| | | matNew.setModel(matParam.getModel());//型号 |
| | | matNew.setColor(matParam.getColor());//颜色 |
| | | matNew.setUnit(matParam.getUnit());//单位 |
| | | matNew.setMemo(matParam.getMemo());//备注 |
| | | matNew.setCreateBy(9999L);//9999表示erp下发 |
| | | matNew.setCreateTime(date); |
| | | matNew.setUpdateBy(9999L);//9999表示erp下发 |
| | | matNew.setUpdateTime(date); |
| | | if (matService.insert(matNew)) { |
| | | callApiLogSave(matParam, "/open/asrs/mat/v1", "接收ERP下发商品信息成功!添加商品信息成功!", true); |
| | | matParam.setType(true); |
| | | } else { |
| | | callApiLogSave(matParam, "/open/asrs/mat/v1", "添加ERP下发商品信息失败!!!状态异常!!!", false); |
| | | matParam.setType(false); |
| | | matParam.setMemo("添加ERP下发商品信息失败!"); |
| | | } |
| | | } else { |
| | | callApiLogSave(matParam, "/open/asrs/mat/v1", "接收ERP下发商品信息失败!!!商品已存在!!!", false); |
| | | matParam.setType(false); |
| | | matParam.setMemo("商品已存在!"); |
| | | } |
| | | matParams.add(matParam); |
| | | } |
| | | matSyncParam.setMats(matParams); |
| | | return matSyncParam; |
| | | } |
| | | public void callApiLogSave(MatSyncParam.Mats matParam, String tableName, String response, Boolean bool) { |
| | | apiLogService.save("ERP下发商品信息", tableName, "null", "10.10.10.1", |
| | | "物料编码:" + matParam.getMatnr() + "、物料名称:" + matParam.getMaktx() + "、规格:" + matParam.getSpecs() + "、备注:" + matParam.getMemo(), |
| | | response, bool); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void combMes(CombParam param) { |
| | | Long userId=9999l; |
| | | if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) { |
| | | callApiLogSaveMES(null, null, BaseRes.PARAM, false); |
| | | throw new CoolException(BaseRes.PARAM); |
| | | } |
| | | if(param.getBarcode().length()!=8){ |
| | | callApiLogSaveMES(param, null, param.getBarcode() + ":条码长度不是8位", false); |
| | | throw new CoolException("条码长度不是8位===>>" + param.getBarcode()); |
| | | } |
| | | // 判断是否有相同条码的数据 |
| | | if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>(). |
| | | eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) { |
| | | callApiLogSaveMES(param, null, param.getBarcode() + "数据正在进行入库", false); |
| | | throw new CoolException(param.getBarcode() + "数据正在进行入库"); |
| | | } |
| | | |
| | | int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet",param.getBarcode())); |
| | | int countWrk = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet",param.getBarcode())); |
| | | if (countLoc > 0) { |
| | | callApiLogSaveMES(param, null, param.getBarcode() + ":库存条码数据已存在", false); |
| | | throw new CoolException("库存条码数据已存在===>>" + param.getBarcode()); |
| | | }else if (countWrk > 0){ |
| | | callApiLogSaveMES(param, null, param.getBarcode() + ":工作明细档已存在此数据", false); |
| | | throw new CoolException("工作明细档已存在此数据===>>" + param.getBarcode()); |
| | | } |
| | | |
| | | Date now = new Date(); |
| | | try{ |
| | | // 生成入库通知档 |
| | | 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)) { |
| | | callApiLogSaveMES(param, null,mat.getMatnr()+"商品档案不存在", false); |
| | | 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)) { |
| | | callApiLogSaveMES(param, null,mat.getMatnr()+"保存入库通知档失败", false); |
| | | throw new CoolException("保存入库通知档失败"); |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | | callApiLogSaveMES(null, null,""+e, false); |
| | | } |
| | | callApiLogSaveMES(param, param.getCombMats().get(0),"组托成功", true); |
| | | } |
| | | public void callApiLogSaveMES(CombParam combParam,CombParam.CombMat combMat, String response, Boolean bool) { |
| | | if (Cools.isEmpty(combParam)){ |
| | | apiLogService.save("MES下发入库通知单", "/open/asrs/comb/v1", "null", "10.10.10.1", |
| | | "", |
| | | response, bool); |
| | | }else if (Cools.isEmpty(combMat)){ |
| | | apiLogService.save("MES下发入库通知单", "/open/asrs/comb/v1", "null", "10.10.10.1", |
| | | "托盘码:" + combParam.getBarcode(), |
| | | response, bool); |
| | | }else { |
| | | apiLogService.save("MES下发入库通知单", "/open/asrs/comb/v1", "null", "10.10.10.1", |
| | | "托盘码:" + combParam.getBarcode() + "、物料编号:" + combMat.getMatnr() + "、数量:" + combMat.getAnfme(), |
| | | response, bool); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 入库记录获取 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public List<ViewWorkInBean> inlogERP() { |
| | | List<ViewWorkInBean> viewWorkInERP = reportQueryMapper.getViewWorkInERP(); |
| | | ArrayList<ViewWorkInBean> viewWorkInBeans = new ArrayList<>(); |
| | | for (ViewWorkInBean viewWorkInBean:viewWorkInERP){ |
| | | viewWorkInBean.sype(); |
| | | viewWorkInBeans.add(viewWorkInBean); |
| | | } |
| | | return viewWorkInBeans; |
| | | } |
| | | |
| | | /** |
| | | * 出库记录获取 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public List<ViewWorkInBean> outlogERP() { |
| | | List<ViewWorkInBean> viewWorkInERP = reportQueryMapper.getViewWorkOutERP(); |
| | | ArrayList<ViewWorkInBean> viewWorkInBeans = new ArrayList<>(); |
| | | for (ViewWorkInBean viewWorkInBean:viewWorkInERP){ |
| | | viewWorkInBean.sype(); |
| | | viewWorkInBeans.add(viewWorkInBean); |
| | | } |
| | | return viewWorkInBeans; |
| | | } |
| | | |
| | | } |