From b89e1a83acebe751596369457cedabf3a1236dd8 Mon Sep 17 00:00:00 2001 From: pang.jiabao <pang_jiabao@163.com> Date: 星期五, 12 七月 2024 16:36:12 +0800 Subject: [PATCH] 与gwcs相关接口交互 --- src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java | 400 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 390 insertions(+), 10 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 a33eb8b..8b629ee 100644 --- a/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java +++ b/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java @@ -1,7 +1,7 @@ package com.zy.asrs.service.impl; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.mapper.EntityWrapper; -import com.baomidou.mybatisplus.mapper.Wrapper; import com.core.common.Cools; import com.core.common.DateUtils; import com.core.common.R; @@ -13,25 +13,21 @@ import com.zy.asrs.entity.result.StockVo; import com.zy.asrs.mapper.TagMapper; import com.zy.asrs.service.*; -import com.zy.asrs.task.core.ReturnT; import com.zy.asrs.utils.MatUtils; -import com.zy.asrs.utils.PostMesDataUtils; +import com.zy.common.constant.MesConstant; import com.zy.common.model.DetlDto; import com.zy.common.model.LocTypeDto; import com.zy.common.model.StartupDto; import com.zy.common.model.enums.WorkNoType; import com.zy.common.service.CommonService; +import com.zy.common.utils.HttpHandler; import com.zy.common.utils.NodeUtils; -import com.zy.common.web.WcsController; -import com.zy.common.web.param.SearchLocParam; 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 @@ -728,9 +724,10 @@ throw new CoolException("瑙勬牸锛�"+matList.getMatnr()+"銆佸弬鏁帮細姣涢噸 roughWeight"); }else if (Cools.isEmpty(matList.getRollExtent()) || matList.getRollExtent().equals(0D)){ throw new CoolException("瑙勬牸锛�"+matList.getMatnr()+"銆佸弬鏁帮細鍗烽暱搴� rollExtent"); - }else if (Cools.isEmpty(matList.getJoint()) || matList.getJoint()==0){ - throw new CoolException("瑙勬牸锛�"+matList.getMatnr()+"銆佸弬鏁帮細鎺ュご鏁� joint"); } +// else if (Cools.isEmpty(matList.getJoint()) || matList.getJoint()==0){ +// throw new CoolException("瑙勬牸锛�"+matList.getMatnr()+"銆佸弬鏁帮細鎺ュご鏁� joint"); +// } if (matList.getPosition().equals("1")){//1銆佸乏 2銆佸彸 if (!matnrOne.equals("")){ @@ -980,6 +977,389 @@ } + @Override + @Transactional + public R gwmsGenerateInventory(GwmsGenerateInventoryDto param) { + + if (Cools.isEmpty(param)) { + throw new CoolException("璇锋眰鍙傛暟鏈夎锛�" + param); + } + int zpalletCount = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet", param.getBarcode())); + if (zpalletCount > 0) { + throw new CoolException("搴撳瓨鎵樼洏鐮佸凡瀛樺湪锛�" + param.getBarcode()); + } + + int barcodeCount = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("barcode", param.getBarcode())); + if (barcodeCount > 0) { + throw new CoolException("宸ヤ綔妗e凡瀛樺湪璇ユ墭鐩樼爜锛�" + param.getBarcode()); + } + + LocTypeDto locTypeDto = new LocTypeDto(); + locTypeDto.setLocType1((short)1); + + // 鏍规嵁婧愮珯鐐瑰鎵惧簱浣� +// StartupDto dto = commonService.getLocNo(1, 1, param.getPalletizingNo(), null,null,null, locTypeDto); + StartupDto dto = commonService.getLocNo(1, param.getPalletizingNo(), locTypeDto); + + // 杩斿洖GWCS鐩爣淇℃伅 + pushStaNoToGwcs(param.getPalletizingNo(),dto.getStaNo(),dto.getWorkNo()); + + int workNo = dto.getWorkNo(); + Date now = new Date(); + // 鐢熸垚宸ヤ綔妗� + WrkMast wrkMast = new WrkMast(); + wrkMast.setWrkNo(workNo); + wrkMast.setIoTime(new Date()); + wrkMast.setWrkSts(1L); // 宸ヤ綔鐘舵�侊細璁惧涓婅蛋 + wrkMast.setIoType(1); // 鍏ュ嚭搴撶姸鎬侊細1.鍏ュ簱 + wrkMast.setIoPri(13D); // 浼樺厛绾� + wrkMast.setCrnNo(dto.getCrnNo()); + wrkMast.setSourceStaNo(param.getPalletizingNo()); + wrkMast.setStaNo(dto.getStaNo()); + wrkMast.setLocNo(dto.getLocNo()); + wrkMast.setBarcode(param.getBarcode()); // 鎵樼洏鐮� + wrkMast.setFullPlt("Y"); // 婊℃澘锛歒 + wrkMast.setPicking("N"); // 鎷f枡 + wrkMast.setExitMk("N"); // 閫�鍑� + wrkMast.setEmptyMk("N"); // 绌烘澘 + wrkMast.setLinkMis("Y"); + wrkMast.setCtnType(1); // 瀹瑰櫒绫诲瀷 + // 鎿嶄綔浜哄憳鏁版嵁 + wrkMast.setAppeTime(now); + wrkMast.setModiTime(now); + boolean res = wrkMastService.insert(wrkMast); + if (!res) { + throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐�"); + } + + List<GwmsGenerateInventoryDto.MatList> matList = param.getMatList(); + for (GwmsGenerateInventoryDto.MatList obj :matList) { + WrkDetl wrkDetl = new WrkDetl(); + wrkDetl.setWrkNo(wrkMast.getWrkNo()); + obj.getRolls().forEach(roll -> { + Mat mat = matService.selectByMatnr(roll.getSpecs()); + if (mat == null) { + mat = new Mat(); + mat.setTagId(6L); + mat.setMatnr(roll.getSpecs()); + mat.setMaktx(roll.getSpecs()); + mat.setSpecs(roll.getSpecs()); + mat.setStatus(1); + mat.setCreateTime(now); + mat.setUpdateTime(now); + if (!matService.insert(mat)) { + throw new CoolException("鐗╂枡瀵煎叆澶辫触锛�"); + } + } + wrkDetl.setWrkNo(wrkMast.getWrkNo()); + wrkDetl.setMatnr(roll.getSpecs()); // 瑙勬牸 + wrkDetl.setMaktx(roll.getSpecs()); //瑙勬牸 + wrkDetl.setBatch(roll.getBoxNo()); // 绠卞彿 + wrkDetl.setModel(roll.getRollNo()); // 鍗峰彿 + wrkDetl.setBrand(""); // 鏈ㄧ绫诲瀷 + wrkDetl.setZpallet(param.getBarcode()); // 鎵樼洏鍚� + wrkDetl.setOrigin(obj.getBoxPos()); // 鏈ㄧ鍦ㄦ墭鐩樹綅缃� + wrkDetl.setWeight(roll.getNetWeight()); // 鍑�閲� + wrkDetl.setVolume(roll.getGrossWeight()); // 姣涢噸 + wrkDetl.setPrice(roll.getLength()); + wrkDetl.setSpecs(String.valueOf(roll.getSplices())); + wrkDetl.setAnfme(1.0); + wrkDetl.setIoTime(now); + wrkDetl.setAppeTime(now); + wrkDetl.setModiTime(now); + if (!wrkDetlService.insert(wrkDetl)) { + throw new CoolException("淇濆瓨宸ヤ綔鏄庣粏澶辫触"); + } + }); + } + + // 鏇存柊鐩爣搴撲綅鐘舵�� + LocMast locMast = locMastService.selectById(dto.getLocNo()); + if (locMast.getLocSts().equals("O")){ + locMast.setLocSts("S"); // S.鍏ュ簱棰勭害 + locMast.setModiTime(now); + if (!locMastService.updateById(locMast)){ + throw new CoolException("鏀瑰彉搴撲綅鐘舵�佸け璐�"); + } + } else { + throw new CoolException(dto.getLocNo()+"鐩爣搴撲綅宸茶鍗犵敤"); + } + return null; + } + + @Override + @Transactional + public String crnExecute(CrnExecuteParam param) { + if (Cools.isEmpty(param.getStaNo(),param.getWorkNo())){ + throw new CoolException("鍙傛暟涓嶈兘涓虹┖锛�" + param); + } + + WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", param.getWorkNo())); + if (wrkMast == null) { + throw new CoolException("涓嶅瓨鍦ㄨ宸ヤ綔鍙凤細" + param.getWorkNo()); + } + + wrkMast.setWrkSts(2L); + wrkMastService.updateById(wrkMast); + + return "璇锋眰鎴愬姛"; + } + + @Override + @Transactional + public String zwmsOutLocWork(ZwmsOutLocWorkDto param) { + + Order order = orderService.selectByNo(param.getOrderNo()); + if (!Cools.isEmpty(order)) { + throw new CoolException(param.getOrderNo() + "鍗曟嵁宸插瓨鍦紝璇峰嬁閲嶅鎻愪氦"); + } + + DocType docType = docTypeService.selectOrAdd(param.getOrderType(), Boolean.FALSE); + Date now = new Date(); + // 鍗曟嵁涓绘。 + order = new Order( + String.valueOf(snowflakeIdWorker.nextId()), // 缂栧彿[闈炵┖] + param.getOrderNo(), // 璁㈠崟缂栧彿 + DateUtils.convert(now), // 鍗曟嵁鏃ユ湡 + docType.getDocId(), // 鍗曟嵁绫诲瀷 + null, // 椤圭洰缂栧彿 + null, // + null, // 璋冩嫧椤圭洰缂栧彿 + null, // 鍒濆绁ㄦ嵁鍙� + null, // 绁ㄦ嵁鍙� + null, // 瀹㈡埛缂栧彿 + null, // 瀹㈡埛 + null, // 鑱旂郴鏂瑰紡 + null, // 鎿嶄綔浜哄憳 + null, // 鍚堣閲戦 + null, // 浼樻儬鐜� + null, // 浼樻儬閲戦 + null, // 閿�鍞垨閲囪喘璐圭敤鍚堣 + null, // 瀹炰粯閲戦 + null, // 浠樻绫诲瀷 + null, // 涓氬姟鍛� + null, // 缁撶畻澶╂暟 + null, // 閭垂鏀粯绫诲瀷 + null, // 閭垂 + null, // 浠樻鏃堕棿 + null, // 鍙戣揣鏃堕棿 + null, // 鐗╂祦鍚嶇О + null, // 鐗╂祦鍗曞彿 + 1L, // 璁㈠崟鐘舵�� + 1, // 鐘舵�� + 9527L, // 娣诲姞浜哄憳 + now, // 娣诲姞鏃堕棿 + 9527L, // 淇敼浜哄憳 + now, // 淇敼鏃堕棿 + null // 澶囨敞 + ); + if (!orderService.insert(order)) { + throw new CoolException("鐢熸垚鍗曟嵁涓绘。澶辫触锛岃鑱旂郴绠$悊鍛�"); + } + // 鍗曟嵁鏄庣粏妗� + List<DetlDto> list = new ArrayList<>(); + List<ZwmsOutLocWorkDto.Rolls> orderDetails = param.getMatDetails(); + for (ZwmsOutLocWorkDto.Rolls detail : orderDetails) { + DetlDto dto = new DetlDto(detail.getRollNo(), detail.getBoxNo(), 1.0); + dto.setOrderNo(detail.getSpecs()); + dto.setSplices(detail.getSplices()); + if (DetlDto.has(list, dto)) { + DetlDto detlDto = DetlDto.find(list, dto.getMatnr(), dto.getBatch()); + assert detlDto != null; + detlDto.setAnfme(detlDto.getAnfme() + 1); + } else { + list.add(dto); + } + } + for (DetlDto detlDto : list) { +// Mat mat = matService.selectByMatnr(detlDto.getMatnr()); + OrderDetl orderDetl = new OrderDetl(); +// if (Cools.isEmpty(mat)) { +// throw new CoolException(detlDto.getMatnr() + "缂栧彿鍟嗗搧妫�绱㈠け璐ワ紝璇峰厛娣诲姞鍟嗗搧"); +// } else { +// orderDetl.sync(mat); +// } + orderDetl.setSpecs(String.valueOf(detlDto.getSplices())); + orderDetl.setBatch(detlDto.getBatch() == null ? "" : detlDto.getBatch()); + orderDetl.setModel(detlDto.getMatnr()); + orderDetl.setMatnr(detlDto.getOrderNo()); + orderDetl.setMaktx(detlDto.getOrderNo()); + orderDetl.setAnfme(detlDto.getAnfme()); + orderDetl.setOrderId(order.getId()); + orderDetl.setOrderNo(order.getOrderNo()); + orderDetl.setCreateBy(9527L); + orderDetl.setCreateTime(now); + orderDetl.setUpdateBy(9527L); + orderDetl.setUpdateTime(now); + orderDetl.setStatus(1); + orderDetl.setQty(0.0D); + if (!orderDetlService.insert(orderDetl)) { + throw new CoolException("鐢熸垚鍗曟嵁鏄庣粏澶辫触锛岃鑱旂郴绠$悊鍛�"); + } + } + + return null; + } + + @Override + @Transactional + public String outLocResultReport(GhjtApiParam param) { + + if (Cools.isEmpty(param.getOutLocResult(),param.getWorkNo())) { + throw new CoolException("鍏ュ弬涓嶈兘涓虹┖锛�" + param); + } + + WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", param.getWorkNo())); + if (wrkMast == null) { + throw new CoolException("璇ュ伐浣滄。涓嶅瓨鍦紝浠诲姟鍙凤細" + param.getWorkNo()); + } else if(wrkMast.getWrkSts() != 2) { + throw new CoolException("宸ヤ綔妗e綋鍓嶇姸鎬佷笉绗﹀悎锛屼换鍔″彿锛�" + param.getWorkNo() + "锛屽伐浣滄。鐘舵�侊細" + wrkMast.getWrkSts()); + } + + // 鍒拌揪鍑哄簱鍙g‘璁や负1锛屾洿鏂板伐浣滄。鐘舵�佷负57.鍑哄簱瀹屾垚 + if (param.getOutLocResult() == 1) { + wrkMast.setWrkSts(20L); + // 绌烘墭鐩樺埌浣嶇洿鎺ユ洿鏂板伐浣滄。鐘舵�佷负14.宸插嚭搴撴湭纭锛岀┖鎵樻棤闇�澶嶆牳纭 + if (wrkMast.getIoType() == 110) { + wrkMast.setWrkSts(14L); + } + wrkMastService.updateById(wrkMast); + } + + return "鍑哄簱缁撴灉涓婃姤鎴愬姛"; + } + + @Override + @Transactional + public String emptyOutLoc(GhjtApiParam param) { +// 3102/3009/3008/3006/3003/3002鈫�3047/3112 + // 瀵绘壘绌烘墭鐩樺簱浣嶏紝鍏堟壘娴呭簱浣� + List<LocMast> locMasts; + locMasts = locMastService.selectList(new EntityWrapper<LocMast>().eq("loc_sts","D") + .orderAsc(Arrays.asList("row1","lev1","bay1")).in("row1",3,4,6,7,10,11,14,15,18,19,22,23)); + if (locMasts.isEmpty()) { + locMasts = locMastService.selectList(new EntityWrapper<LocMast>().eq("loc_sts","D") + .orderAsc(Arrays.asList("row1","lev1","bay1")).in("row1",1,4,5,8,9,12,13,16,17,20,21,24)); + } + + if (locMasts.isEmpty()) { + throw new CoolException("娌℃湁鎵惧埌绌烘墭鐩橈紝绔欑偣锛�" + param.getStaNo()); + } + + // 鍙栫涓�涓┖搴撲綅 + LocMast locMast = locMasts.get(0); + + // 鑾峰彇宸ヤ綔璺緞 + StaDesc staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>().eq("type_no", 110).eq("stn_no", + param.getStaNo()).eq("crn_no", locMast.getCrnNo())); + + if (staDesc == null) { + throw new CoolException("璺緞涓嶅瓨鍦�"); + } + + //2.鐢熸垚绌烘墭鐩樺嚭搴撳伐浣滄。 + Date now = new Date(); + WrkMast wrkMast = new WrkMast(); + wrkMast.setWrkNo(commonService.getWorkNo(WorkNoType.PAKOUT.type)); + wrkMast.setIoTime(now); + wrkMast.setWrkSts(11L); // 宸ヤ綔鐘舵�侊細11.鐢熸垚鍑哄簱ID + wrkMast.setIoType(110); // 鍏ュ嚭搴撶姸鎬侊細 110.绌烘澘鍑哄簱 + wrkMast.setIoPri(10D); + wrkMast.setSourceStaNo(staDesc.getCrnStn()); // 婧愮珯 + wrkMast.setStaNo(staDesc.getStnNo()); // 鐩爣绔� + wrkMast.setCrnNo(locMast.getCrnNo()); + wrkMast.setSourceLocNo(locMast.getLocNo()); // 婧愬簱浣� + wrkMast.setFullPlt("N"); // 婊℃澘锛歒 + wrkMast.setPicking("N"); // 鎷f枡 + wrkMast.setExitMk("N"); // 閫�鍑� + wrkMast.setEmptyMk("Y"); // 绌烘澘 + wrkMast.setLinkMis("N"); + wrkMast.setAppeUser(9999L); + wrkMast.setAppeTime(now); + wrkMast.setModiUser(9999L); + wrkMast.setModiTime(now); + if (!wrkMastService.insert(wrkMast)) { + throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐�"); + } + + // 3.鏇存柊搴撲綅鐘舵�� D.绌烘澘 -> R.鍑哄簱棰勭害 + if (locMast.getLocSts().equals("D")) { + locMast.setLocSts("R"); + locMast.setModiUser(9999L); + locMast.setModiTime(now); + if (!locMastService.updateById(locMast)) { + throw new CoolException("鏇存柊搴撲綅鐘舵�佸け璐�"); + } + } + + return "鍑哄簱鎴愬姛"; + } + + @Autowired + private ApiLogService apiLogService; + + private void pushStaNoToGwcs(Integer palletizingNo, Integer staNo, Integer workNo) { + boolean success = false; + // 鑾峰彇璇锋眰澶� + Map<String, Object> headers = getHeaders(); + + // 鏋勯�犺姹備綋 + JSONObject jsonObject = new JSONObject(); + jsonObject.put("workNo", workNo); + jsonObject.put("staNo", staNo); + jsonObject.put("sourceStaNo", palletizingNo); + String body = jsonObject.toJSONString(); + String response = ""; + try { + response = new HttpHandler.Builder() + .setUri(MesConstant.GWCS_IP_PORT) + .setPath(MesConstant.GWCS_FPKW_URL) + .setHeaders(headers) + .setJson(body) + .build() + .doPost(); + if (!Cools.isEmpty(response)) { + success = true; +// // 淇敼璁㈠崟鐘舵�� 4.瀹屾垚 ===>> 6.宸蹭笂鎶� +// if (!orderService.updateSettle(order.getId(), 6L, null)) { +// throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳"); +// } + } else { + log.error("zmws鎺ㄩ�佸叆搴撶爜澶寸珯鐐规帴鍙eけ璐ワ紒锛侊紒url锛歿}锛況equest锛歿}锛況esponse锛歿}", MesConstant.URL + MesConstant.PAKIN_URL, body, response); + throw new CoolException("涓婃姤mes绯荤粺澶辫触"); + } + } catch (Exception e) { + log.error("鍏ュ簱璇锋眰鎺ュ彛澶辫触锛歿}", e.getMessage()); +// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); +// return FAIL.setMsg(e.getMessage()); + } finally { + try { + // 淇濆瓨鎺ュ彛鏃ュ織 + apiLogService.save( + "鍏ュ簱", + MesConstant.URL + MesConstant.PAKIN_URL, + null, + "127.0.0.1", + jsonObject.toJSONString(), + response, + success + ); + } catch (Exception e) { + log.error("", e); + } + } + } + + Map<String, Object> getHeaders(){ + Map<String,Object> headers = new HashMap<>(); + headers.put("digi-type","sync "); + headers.put("digi-protocol","raw"); + headers.put("digi-datakey"," XCommon.ImportData"); + + return headers; + } + + private void descSta(Integer staNo,Integer crnNo){ // int[] typeNos =new int[]{1,10,53,101,103,110}; int[] typeNos =new int[]{10,110}; -- Gitblit v1.9.1