From 78a59eda850857e1bfeb48541f0c64d442877a4d Mon Sep 17 00:00:00 2001 From: lty <876263681@qq.com> Date: 星期二, 08 四月 2025 11:17:10 +0800 Subject: [PATCH] #实现pda简单入库出库操作 --- src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java | 324 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 313 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java index bc4b8f7..6a7aeae 100644 --- a/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java +++ b/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java @@ -1,29 +1,30 @@ 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.DocType; -import com.zy.asrs.entity.Mat; -import com.zy.asrs.entity.Order; -import com.zy.asrs.entity.OrderDetl; -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.*; +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 @@ -44,6 +45,20 @@ private MatService matService; @Autowired private LocDetlService locDetlService; + @Autowired + private PackService packService; + @Autowired + 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 @@ -177,10 +192,15 @@ } @Override + @Transactional public void pakoutOrderCreate(OpenOrderPakoutParam param) { Order order = orderService.selectByNo(param.getOrderNo()); + // 濡傛灉鍗曟嵁涓嶅瓨鍦ㄥ垯娣诲姞锛涘鏋滃崟鎹瓨鍦紝浣滀笟涓棤娉曚慨鏀癸紝鍙嶄箣鍒欎慨鏀瑰崟鎹� if (!Cools.isEmpty(order)) { - throw new CoolException(param.getOrderNo() + "鍗曟嵁宸插瓨鍦紝璇峰嬁閲嶅鎻愪氦"); + if (order.getSettle() > 1L) { + throw new CoolException(param.getOrderNo() + "姝e湪鍑哄簱锛屾棤娉曚慨鏀瑰崟鎹�"); + } + orderService.remove(order.getId()); } DocType docType = docTypeService.selectOrAdd(param.getOrderType(), Boolean.FALSE); Date now = new Date(); @@ -311,4 +331,286 @@ return locDetlService.queryStockTotal(); } + @Override + @Transactional + public void packageUp(PackParam param) { + if (Cools.isEmpty(param.getBarcode())) { + throw new CoolException("barcode涓嶈兘涓虹┖"); + } + Mat analyse = MatUtils.analyseMat(param.getBarcode()); + Pack pack = packService.selectByBarcode(param.getBarcode()); + if (null != pack) { + throw new CoolException(param.getBarcode() + "閲嶅鎻愪氦"); + } + Date now = new Date(); + pack = new Pack( + param.getBarcode(), // 鏉$爜[闈炵┖] + analyse.getMatnr(), // 鐗╂枡鍙� + analyse.getBarcode(), // 搴忓垪鐮� + 1L, // 璁㈠崟鐘舵�� + 1, // 鐘舵�� + now, // 娣诲姞鏃堕棿 + null, // 娣诲姞浜哄憳 + now, // 淇敼鏃堕棿 + null, // 淇敼浜哄憳 + null // 澶囨敞 + ); + if (!packService.insert(pack)) { + throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳"); + } + + Mat mat = matService.selectByMatnr(analyse.getMatnr()); + if (mat == null) { + mat = new Mat(); + // 鍒嗙被 + Long tagId; + // 涓�绾у垎绫� + if (!Cools.isEmpty(param.getGroupCode()) && !Cools.isEmpty(param.getGroupName())) { + Tag priTag = tagService.selectByName(param.getGroupCode(), 2); + if (priTag == null) { + Tag top = tagService.getTop(); + NodeUtils nodeUtils = new NodeUtils(); + nodeUtils.executePath(top.getId()); + priTag = new Tag( + null, // 缂栧彿 + param.getGroupCode(), // 鍚嶇О + top.getId(), // 鐖剁骇 + top.getName(), // 鐖剁骇鍚嶇О + nodeUtils.path.toString(), // 鍏宠仈璺緞 + nodeUtils.pathName.toString(), // 鍏宠仈璺緞鍚� + 0, // 绫诲瀷 + null, // 璐熻矗浜� + null, // 鍥剧墖 + null, // 绠�瑕佹弿杩� + null, // 鏁伴噺 + 2, // 绛夌骇 + null, // 鎺掑簭 + 1, // 鐘舵�� + now, // 娣诲姞鏃堕棿 + null, // 娣诲姞浜哄憳 + now, // 淇敼鏃堕棿 + null, // 淇敼浜哄憳 + null // 澶囨敞 + ); + if (tagMapper.insert(priTag) == 0) { + throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳"); + } + } + // 浜岀骇鍒嗙被 + Tag secTag = tagService.selectByName(param.getGroupName(), 3); + if (secTag == null) { + NodeUtils nodeUtils = new NodeUtils(); + nodeUtils.executePath(priTag.getId()); + secTag = new Tag( + null, // 缂栧彿 + param.getGroupName(), // 鍚嶇О + priTag.getId(), // 鐖剁骇 + priTag.getName(), // 鐖剁骇鍚嶇О + nodeUtils.path.toString(), // 鍏宠仈璺緞 + nodeUtils.pathName.toString(), // 鍏宠仈璺緞鍚� + 0, // 绫诲瀷 + null, // 璐熻矗浜� + null, // 鍥剧墖 + null, // 绠�瑕佹弿杩� + null, // 鏁伴噺 + 3, // 绛夌骇 + null, // 鎺掑簭 + 1, // 鐘舵�� + now, // 娣诲姞鏃堕棿 + null, // 娣诲姞浜哄憳 + now, // 淇敼鏃堕棿 + null, // 淇敼浜哄憳 + null // 澶囨敞 + ); + if (tagMapper.insert(secTag) == 0) { + throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳"); + } + } + tagId = secTag.getId(); + } else { + tagId = tagService.getTop().getId(); + } + mat.setTagId(tagId); + mat.setMatnr(analyse.getMatnr()); + mat.setMaktx(param.getMaterialName()); + mat.setSpecs(param.getConfigureDesc()); + mat.setModel(analyse.getModel()); + mat.setStatus(1); + mat.setCreateTime(now); + mat.setUpdateTime(now); + if (!matService.insert(mat)) { + throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳"); + } else { + 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() + "鏁版嵁姝e湪杩涜鍏ュ簱", false); + throw new CoolException(param.getBarcode() + "鏁版嵁姝e湪杩涜鍏ュ簱"); + } + + 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("宸ヤ綔鏄庣粏妗e凡瀛樺湪姝ゆ暟鎹�===>>" + 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()+"鍟嗗搧妗f涓嶅瓨鍦�", false); + throw new CoolException(detlDto.getMatnr() + "鍟嗗搧妗f涓嶅瓨鍦�"); + } + 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()+"淇濆瓨鍏ュ簱閫氱煡妗eけ璐�", false); + throw new CoolException("淇濆瓨鍏ュ簱閫氱煡妗eけ璐�"); + } + } + }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; + } + } -- Gitblit v1.9.1