From 907e117c441d409fab5922e655039138a4715126 Mon Sep 17 00:00:00 2001
From: zc <zc>
Date: 星期一, 29 七月 2024 10:57:08 +0800
Subject: [PATCH] 订单组托代码
---
src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java | 298 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 276 insertions(+), 22 deletions(-)
diff --git a/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
index 6c3b9f9..52b1e21 100644
--- a/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
@@ -3,20 +3,23 @@
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.baomidou.mybatisplus.mapper.Wrapper;
+import com.core.common.*;
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.OffSaleParam;
import com.zy.asrs.entity.param.OpenOrderPakinParam;
+import com.zy.asrs.mapper.ManLocDetlMapper;
import com.zy.asrs.service.*;
+import com.zy.asrs.utils.MatUtils;
+import com.zy.common.CodeRes;
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;
@@ -56,6 +59,25 @@
private OpenService openService;
@Autowired
private SnowflakeIdWorker snowflakeIdWorker;
+ @Autowired
+ private ApiLogService apiLogService;
+ @Autowired
+ private BasCrnpService basCrnpService;
+ @Autowired
+ private LocMastService locMastService;
+ @Autowired
+ private LocDetlService locDetlService;
+ @Autowired
+ private StaDescService staDescService;
+ @Autowired
+ private CommonService commonService;
+ @Autowired
+ private NodeService nodeService;
+ @Autowired
+ private ManLocDetlService manLocDetlService;
+ @Autowired
+ private ManLocDetlMapper manLocDetlMapper;
+
@Override
@Transactional
@@ -63,11 +85,29 @@
if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) {
throw new CoolException(BaseRes.PARAM);
}
+// if(param.getCombMats().size()>1){
+// throw new CoolException("璇锋彁鍙栦竴涓晢鍝侊紝鎴栬�呭埛鏂伴噸鏂扮粍鎵橈紒");
+// }
// 鍒ゆ柇鏄惁鏈夌浉鍚屾潯鐮佺殑鏁版嵁
if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().
eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) {
throw new CoolException(param.getBarcode() + "鏁版嵁姝e湪杩涜鍏ュ簱");
}
+
+ if(param.getBarcode().length()!=8){
+ throw new CoolException("鏉$爜闀垮害涓嶆槸8浣�===>>" + param.getBarcode());
+ }
+// if (param.getCombMats().size()>1){
+// 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()));
+ int countwait = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet",param.getBarcode()));
+ if (countLoc > 0 || countWrk > 0 || countwait > 0) {
+ throw new CoolException("缁勬墭妗�/宸ヤ綔妗�/搴撳瓨鏉$爜鏁版嵁宸插瓨鍦�===>>" + param.getBarcode());
+ }
+
Date now = new Date();
// 鏃犲崟缁勬墭
@@ -110,7 +150,7 @@
// 鍏宠仈缁勬墭
} else {
Order order = orderService.selectByNo(param.getOrderNo());
- if (order.getSettle() > 2) {
+ if (Cools.isEmpty(order) || order.getSettle() > 2) {
throw new CoolException("鍗曟嵁缂栧彿宸茶繃鏈�");
}
// 鐢熸垚鍏ュ簱閫氱煡妗�
@@ -122,9 +162,9 @@
if (elem.getAnfme() > orderDetl.getEnableQty()) {
throw new CoolException(orderDetl.getMatnr() + "鍏ュ簱鏁伴噺涓嶅悎娉�");
}
- // 淇敼璁㈠崟鏄庣粏鏁伴噺
- if (!orderDetlService.increase(order.getId(), elem.getMatnr(), elem.getBatch(), elem.getAnfme())) {
- throw new CoolException("淇敼鍗曟嵁鏄庣粏鏁伴噺澶辫触");
+ // 淇敼璁㈠崟浣滀笟鏁伴噺
+ if (!orderDetlService.increaseWorkQty(order.getId(), elem.getMatnr(), elem.getBatch(), elem.getAnfme())) {
+ throw new CoolException("淇敼鍗曟嵁浣滀笟鏁伴噺澶辫触");
}
DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme());
@@ -144,7 +184,7 @@
WaitPakin waitPakin = new WaitPakin();
waitPakin.sync(mat);
waitPakin.setOrderNo(order.getOrderNo()); // 鍗曟嵁缂栧彿
- waitPakin.setBatch(detlDto.getBatch()); // 鎵瑰彿
+ waitPakin.setBatch(detlDto.getBatch()); // 搴忓垪鐮�
waitPakin.setZpallet(param.getBarcode()); // 鎵樼洏鐮�
waitPakin.setIoStatus("N"); // 鍏ュ嚭鐘舵��
waitPakin.setAnfme(detlDto.getAnfme()); // 鏁伴噺
@@ -161,6 +201,62 @@
}
}
+
+ // 鍟嗗搧涓婃灦
+ @Override
+ public void onSale(CombParam param) {
+ Date now = new Date();
+ // 鑾峰彇搴撲綅鍙�
+ String locno = param.getLocno();
+ Node node = nodeService.selectByUuid(locno);
+ if (Cools.isEmpty(node)) {
+ throw new CoolException(param.getLocno() + ":搴撲綅涓嶅瓨鍦�");
+ }
+
+ // 鑾峰彇鍟嗗搧鍒楄〃
+ for(CombParam.CombMat combMat : param.getCombMats()){
+ Mat mat = matService.selectByMatnr(combMat.getMatnr());
+ if (Cools.isEmpty(mat)){
+ throw new CoolException(combMat.getMatnr() + ":鍟嗗搧妗f涓嶅瓨鍦紒");
+ }
+ if (Cools.isEmpty(combMat.getAnfme()) || combMat.getAnfme()==0){
+ throw new CoolException(combMat.getMatnr() + ":鍟嗗搧鏁伴噺鏈夎锛�");
+ }
+ if (Cools.isEmpty(combMat.getBatch())){
+// throw new CoolException(combMat.getMatnr() + ":鍟嗗搧鎵瑰彿鏈夎锛�");
+ }
+ ManLocDetl manLocDetl = new ManLocDetl();
+ manLocDetl.setLocNo(locno);
+ manLocDetl.setNodeId(node.getId());
+ manLocDetl.setMaktx(mat.getMaktx());
+ manLocDetl.setMatnr(mat.getMatnr());
+ manLocDetl.setBatch(Cools.isEmpty(combMat.getBatch()) ? "" : combMat.getBatch());
+ manLocDetl.setAnfme(combMat.getAnfme());
+ manLocDetl.setModiTime(now);
+ if (!manLocDetlService.insert(manLocDetl)) {
+ throw new CoolException("鍟嗗搧涓婃灦澶辫触锛�");
+ }
+ }
+ }
+
+ // 鍟嗗搧涓嬫灦
+ @Override
+ public void offSale(OffSaleParam offSaleParam) {
+ ManLocDetl manLocDetl = manLocDetlMapper.selectLocNo0(offSaleParam.getLocNo(), offSaleParam.getMatnr());
+ if (Cools.isEmpty(manLocDetl)){
+ throw new CoolException("鏃犳鍟嗗搧锛�");
+ }
+ double anfme = manLocDetl.getAnfme() - offSaleParam.getAnfme();
+ if (anfme < 0) {
+ throw new CoolException("鍟嗗搧搴撳瓨涓嶈冻锛�");
+ } else if (anfme == 0){
+ manLocDetlMapper.deleteLocNo0(offSaleParam.getLocNo(), offSaleParam.getMatnr());
+ }
+ manLocDetlMapper.updateAnfme0(anfme,manLocDetl.getNodeId());
+ }
+
+ // 鏌ユ壘鍟嗗搧
+
@Override
@Transactional
@@ -271,7 +367,10 @@
throw new CoolException(elem.getMatnr() + "鏉$爜宸蹭笅绾匡紝璇锋鏌ワ紒");
}
}
- DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme());
+ 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;
@@ -284,14 +383,18 @@
if (packDown) {
MesCombParam mesCombParam = new MesCombParam();
mesCombParam.setZpallet(param.getBarcode());
- mesCombParam.setCombTime(DateUtils.convert(now));
+ 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.getMatnr(), detlDto.getAnfme()));
+ mesCombParam.getList().add(new MesCombParam.Detl(detlDto.getOrderNo(), detlDto.getAnfme()));
}
- String response;
+ String response = "";
+ boolean success = false;
try {
- response = new HttpHandler.Builder()
+ response = new HttpHandler.Builder()
.setUri(MesConstant.URL)
.setPath(MesConstant.PACK_DOWN_URL)
.setJson(JSON.toJSONString(mesCombParam))
@@ -299,16 +402,30 @@
.doPost();
JSONObject jsonObject = JSON.parseObject(response);
if (jsonObject.getInteger("code").equals(200)) {
- log.info("璇锋眰鎺ュ彛鎴愬姛锛侊紒锛�");
-// log.info("璇锋眰鎺ュ彛鎴愬姛锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", MesConstant.URL+MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response);
+ success = true;
+ } else if (jsonObject.getInteger("code").equals(500)) {
+ log.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", MesConstant.URL+MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response);
+ throw new CoolException(jsonObject.getString("msg"));
} else {
log.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", MesConstant.URL+MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response);
throw new CoolException("涓婃姤mes绯荤粺澶辫触");
}
} catch (Exception e) {
log.error("fail", e);
- e.printStackTrace();
- throw new CoolException("涓婃姤mes绯荤粺澶辫触");
+ 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); }
}
}
@@ -338,9 +455,9 @@
if (detlDto.getAnfme() > orderDetl.getEnableQty()) {
throw new CoolException(orderDetl.getMatnr() + "鍏ュ簱鏁伴噺涓嶅悎娉�");
}
- // 淇敼璁㈠崟鏄庣粏鏁伴噺
- if (!orderDetlService.increase(order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getAnfme())) {
- throw new CoolException("淇敼鍗曟嵁鏄庣粏鏁伴噺澶辫触");
+ // 淇敼璁㈠崟浣滀笟鏁伴噺
+ if (!orderDetlService.increaseWorkQty(order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getAnfme())) {
+ throw new CoolException("淇敼鍗曟嵁浣滀笟鏁伴噺澶辫触");
}
// 淇濆瓨鍏ュ簱閫氱煡妗�
@@ -364,7 +481,7 @@
throw new CoolException("淇濆瓨鍏ュ簱閫氱煡妗eけ璐�");
}
// 淇敼鎵撳寘鏁版嵁鐘舵��
- Pack pack = packService.selectByBarcode(detlDto.getMatnr());
+ Pack pack = packService.selectByBarcode(detlDto.getOrderNo());
pack.setSettle(2L);
pack.setUpdateTime(now);
pack.setUpdateBy(userId);
@@ -376,4 +493,141 @@
}
}
+ @Override
+ @Transactional
+ public void pakoutByOrder(JSONObject param, Long userId) {
+ Integer staNo = param.containsKey("staNo") ? Integer.parseInt(param.get("staNo").toString()) : 0;
+ String orderNo = param.containsKey("orderNo") ? param.get("orderNo").toString() : "";
+
+ BasDevp sta = basDevpService.checkSiteStatus(staNo);
+ //鏍规嵁璁㈠崟鍙风敓鎴愬嚭搴撲换鍔″伐浣滄。
+ Order order = orderService.selectOne(new EntityWrapper<Order>().eq("order_no", orderNo));
+ if (order.getSettle() != 1 && order.getSettle() != 2){
+ throw new CoolException("璇ヨ鍗曞凡澶勭悊");
+ }
+
+ List<OrderDetl> orderDetls = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no", orderNo));
+ Date now = new Date();
+ for(OrderDetl orderDetl : orderDetls){
+ //鏌ヨ鎵�鏈夊簱浣嶇姸鎬佷负F鐨勫簱浣嶄俊鎭�
+ List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(),orderDetl.getBatch(),null,null);
+ if (locDetls.size() == 0) {
+ throw new CoolException("搴撳瓨涓病鏈夎鐗╂枡");
+ }
+ for(LocDetl locDetl : locDetls){
+ //濡傛灉璇ュ簱浣嶅嚭搴撹矾绾挎墍鐢ㄧ殑鍫嗗灈鏈簅ut_enable涓嶄负Y,璺宠繃璇ュ惊鐜�
+ LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
+ .eq("loc_no", locDetl.getLocNo()));
+ if (Cools.isEmpty(locMast)) {
+ continue;
+ }
+ BasCrnp crn_no = basCrnpService.selectOne(new EntityWrapper<BasCrnp>()
+ .eq("crn_no", locMast.getCrnNo()));
+ if (Cools.isEmpty(crn_no) || !crn_no.getOutEnable().equals("Y")){
+ continue;
+ }
+
+ //鍙嚭搴撴暟閲� = 璁㈠崟鏁伴噺 - 浣滀笟涓暟閲�
+ Double outQty = orderDetl.getAnfme() - orderDetl.getWorkQty();
+ if(outQty <= 0){
+ break;
+ }
+ // 鍒ゆ柇鍏ュ嚭搴撶被鍨嬶細101.鍏ㄦ澘鍑哄簱 or 103.鎷f枡鍑哄簱
+ Double sumCount = locDetlService.getLocDetlSumQty(locDetl.getLocNo());
+ Double curOutQty = outQty >= locDetl.getAnfme() ? locDetl.getAnfme() : outQty; //鏈鍑哄簱閲�
+ int ioType = sumCount <= curOutQty ? 101 : 103;
+
+ stockOut(orderDetl, sta, locDetl, curOutQty, ioType, userId, now);
+ order.setSettle(2L);
+ order.setUpdateBy(userId);
+ order.setUpdateTime(now);
+ if(!orderService.update(order, new EntityWrapper<Order>().eq("order_no", orderNo))){
+ throw new CoolException("鏇存柊璁㈠崟鐘舵�佸け璐�");
+ }
+ orderDetl.setWorkQty(orderDetl.getWorkQty() + curOutQty);
+ orderDetl.setUpdateBy(userId);
+ orderDetl.setUpdateTime(now);
+ Wrapper wrapper = new EntityWrapper<OrderDetl>().eq("order_no", orderNo)
+ .eq("matnr",orderDetl.getMatnr());
+ if(!Cools.isEmpty(orderDetl.getBatch())){
+ wrapper.eq("batch", orderDetl.getBatch());
+ }
+ if(!orderDetlService.update(orderDetl, wrapper)){
+ throw new CoolException("鏇存柊璁㈠崟鏄庣粏澶辫触");
+ }
+ }
+
+ }
+ }
+
+ @Override
+ @Transactional
+ public void stockOut(OrderDetl orderDetl, BasDevp staNo, LocDetl locDetl,
+ Double curOutQty, Integer ioType, Long userId, Date now) {
+ // 鑾峰彇搴撲綅
+ LocMast locMast = locMastService.selectById(locDetl.getLocNo());
+ // 鑾峰彇璺緞
+ Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
+ .eq("type_no", ioType)
+ .eq("stn_no", staNo.getDevNo())
+ .eq("crn_no", locMast.getCrnNo());
+
+ StaDesc staDesc = staDescService.selectOne(wrapper);
+ if (Cools.isEmpty(staDesc)) {
+ throw new CoolException("鍑哄簱璺緞涓嶅瓨鍦�");
+ }
+ // 鐢熸垚宸ヤ綔鍙�
+ int workNo = commonService.getWorkNo(2);
+ // 鐢熸垚宸ヤ綔妗�
+ WrkMast wrkMast = new WrkMast();
+ wrkMast.setWrkNo(workNo);
+ wrkMast.setIoTime(now);
+ wrkMast.setWrkSts(11L); // 宸ヤ綔鐘舵�侊細11.鐢熸垚鍑哄簱ID
+ wrkMast.setIoType(ioType); // 鍏ュ嚭搴撶姸鎬�
+ wrkMast.setIoPri(13D); // 浼樺厛绾э細13
+ wrkMast.setCrnNo(locMast.getCrnNo());
+ wrkMast.setSourceStaNo(staDesc.getCrnStn()); // 婧愮珯
+ wrkMast.setStaNo(staDesc.getStnNo()); // 鐩爣绔�
+ wrkMast.setSourceLocNo(locDetl.getLocNo()); // 婧愬簱浣�
+ wrkMast.setFullPlt("Y"); // 婊℃澘锛歒
+ wrkMast.setPicking("N"); // 鎷f枡
+ wrkMast.setExitMk("N"); // 閫�鍑�
+ wrkMast.setEmptyMk("N"); // 绌烘澘
+ wrkMast.setLinkMis("N");
+ wrkMast.setAppeUser(userId); // 鎿嶄綔浜哄憳鏁版嵁
+ wrkMast.setAppeTime(now);
+ wrkMast.setModiUser(userId);
+ wrkMast.setModiTime(now);
+ wrkMast.setBarcode(locMast.getBarcode());
+ if (!wrkMastService.insert(wrkMast)) {
+ throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐ワ紝鍑哄簱搴撲綅鍙凤細" + locDetl.getLocNo());
+ }
+
+ WrkDetl wrkDetl = new WrkDetl();
+ wrkDetl.sync(locDetl);
+ wrkDetl.setWrkNo(workNo);
+ wrkDetl.setIoTime(now);
+ wrkDetl.setAnfme(curOutQty); // 鏁伴噺
+ wrkDetl.setOrderNo(orderDetl.getOrderNo());
+ wrkDetl.setAppeTime(now);
+ wrkDetl.setAppeUser(userId);
+ wrkDetl.setModiTime(now);
+ wrkDetl.setModiUser(userId);
+ if (!wrkDetlService.insert(wrkDetl)) {
+ throw new CoolException("淇濆瓨宸ヤ綔妗f槑缁嗗け璐�");
+ }
+
+ // 淇敼搴撲綅鐘舵��: F.鍦ㄥ簱 ====>>> R.鍑哄簱棰勭害/P.鎷f枡/鐩樼偣/骞舵澘鍑哄簱涓�
+ locMast = locMastService.selectById(locDetl.getLocNo());
+ if (locMast.getLocSts().equals("F")) {
+ locMast.setLocSts(ioType == 101 ? "R" : "P");
+ locMast.setModiUser(userId);
+ locMast.setModiTime(new Date());
+ if (!locMastService.updateById(locMast)) {
+ throw new CoolException("棰勭害搴撲綅鐘舵�佸け璐ワ紝搴撲綅鍙凤細" + locDetl.getLocNo());
+ }
+ } else {
+ throw new CoolException(locDetl.getLocNo() + "搴撲綅涓嶆槸鍦ㄥ簱鐘舵��");
+ }
+ }
}
--
Gitblit v1.9.1