From 144d50c5ba277ba9df9613d3510655db314358f7 Mon Sep 17 00:00:00 2001
From: zhang <zc857179121@qq.com>
Date: 星期五, 31 十月 2025 16:26:44 +0800
Subject: [PATCH] 1
---
src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java | 302 ++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 242 insertions(+), 60 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 c48df3a..2c9a489 100644
--- a/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
@@ -8,6 +8,7 @@
import com.core.exception.CoolException;
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.param.*;
+import com.zy.asrs.enums.CommonEnum;
import com.zy.asrs.enums.LocStsType;
import com.zy.asrs.mapper.LocMastMapper;
import com.zy.asrs.mapper.ManLocDetlMapper;
@@ -28,7 +29,10 @@
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
import java.util.*;
+import java.util.stream.Collectors;
/**
* 绉诲姩绔湇鍔℃牳蹇冪被
@@ -97,8 +101,19 @@
@Resource
private OrderDetlPakoutService orderDetlPakoutService;
+
@Autowired
private LocCacheService locCacheService;
+
+ @Autowired
+ private TaskService taskService;
+
+ @Autowired
+ private TaskDetlService taskDetlService;
+ @Autowired
+ private BasStationService basStationService;
+ @Autowired
+ private BasContainerService basContainerService;
@Override
@Transactional
@@ -553,7 +568,8 @@
}
// 鍒ゆ柇鏄惁鏈夌浉鍚屾潯鐮佺殑鏁版嵁
if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().
- eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) {
+ eq("zpallet", param.getBarcode())
+ .eq("io_status", "N")) > 0) {
throw new CoolException(param.getBarcode() + "鏁版嵁姝e湪杩涜鍏ュ簱");
}
@@ -569,7 +585,6 @@
}
Date now = new Date();
-
// 鏃犲崟缁勬墭
if (Cools.isEmpty(param.getOrderNo())) {
// 鐢熸垚鍏ュ簱閫氱煡妗�
@@ -586,19 +601,21 @@
}
});
-
for (DetlDto detlDto : detlDtos) {
Mat mat = matService.selectByMatnr(detlDto.getMatnr());
if (Cools.isEmpty(mat)) {
throw new CoolException(detlDto.getMatnr() + "鍟嗗搧妗f涓嶅瓨鍦�");
}
+ if (mat.getUpQty().compareTo(detlDto.getAnfme()) < 0) {
+ throw new CoolException("鐗╂枡锛�" + detlDto.getMatnr() + "鍗曟鏈�澶х粍鎵樹笂闄愪负锛�" + mat.getUpQty());
+ }
WaitPakin waitPakin = new WaitPakin();
BeanUtils.copyProperties(mat, waitPakin);
waitPakin.setBatch(detlDto.getBatch());
- waitPakin.setZpallet(param.getBarcode()); // 鎵樼洏鐮�
- waitPakin.setIoStatus("N"); // 鍏ュ嚭鐘舵��
- waitPakin.setAnfme(detlDto.getAnfme()); // 鏁伴噺
- waitPakin.setStatus("Y"); // 鐘舵��
+ waitPakin.setZpallet(param.getBarcode());
+ waitPakin.setIoStatus("N");
+ waitPakin.setAnfme(detlDto.getAnfme());
+ waitPakin.setStatus("Y");
waitPakin.setAppeUser(userId);
waitPakin.setAppeTime(now);
waitPakin.setModiUser(userId);
@@ -610,13 +627,13 @@
// 鍏宠仈缁勬墭
} else {
// Order order = orderService.selectByNo(param.getOrderNo());
- Order order = OrderInAndOutUtil.selectByNo(Boolean.TRUE, param.getOrderNo());
- if (Cools.isEmpty(order) || order.getSettle() > 2) {
- throw new CoolException("鍗曟嵁缂栧彿宸茶繃鏈�");
- }
// 鐢熸垚鍏ュ簱閫氱煡妗�
List<DetlDto> detlDtos = new ArrayList<>();
param.getCombMats().forEach(elem -> {
+ Order order = OrderInAndOutUtil.selectByNo(Boolean.TRUE, elem.getOrderNo());
+ if (Cools.isEmpty(order) || order.getSettle() > 2) {
+ throw new CoolException("鍗曟嵁缂栧彿宸茶繃鏈�");
+ }
// 璁㈠崟鏄庣粏鏁伴噺鏍¢獙
// OrderDetl orderDetl = OrderInAndOutUtil.selectItem(Boolean.TRUE, order.getId(), elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(),
// elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3());
@@ -635,6 +652,8 @@
elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme());
DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(),
elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme());
+ detlDto.setOrderId(order.getId());
+ detlDto.setOrderNo(order.getOrderNo());
if (DetlDto.has(detlDtos, detlDto)) {
DetlDto one = DetlDto.findDto(detlDtos, detlDto);
assert one != null;
@@ -643,16 +662,45 @@
detlDtos.add(detlDto);
}
});
+
+ BasContainer container = basContainerService.selectOne(new EntityWrapper<BasContainer>().eq("barcode", param.getBarcode()));
+ if (Objects.isNull(container)) {
+ throw new CoolException("鏁版嵁閿欒锛氬鍣ㄧ爜涓嶅瓨鍦紒锛�");
+ }
+ if (container.getMixMax() < detlDtos.size()) {
+ throw new CoolException("瓒呭嚭瀹瑰櫒鏈�澶ф贩瑁呮暟閲忥紝褰撳墠瀹瑰櫒鏈�澶ф暟閲忎负锛�" + container.getMixMax() + "!!");
+ }
+ Set<String> matnrs = detlDtos.stream().map(DetlDto::getMatnr).collect(Collectors.toSet());
+ List<Mat> mats = matService.selectList(new EntityWrapper<Mat>().in("matnr", matnrs));
+ Set<Long> tagIds = mats.stream().map(Mat::getTagId).collect(Collectors.toSet());
+ if (tagIds.size() > 1) {
+ throw new CoolException("缁勬墭鐗╂枡绫诲瀷涓嶄竴鑷达紝鍙湁鐩稿悓鐨勭墿鏂欏垎绫绘墠鍙互缁勬墭锛侊紒");
+ }
+ //杩樺彲浠ユ斁鍏ュ灏戠鐗╂枡
+ Integer suplus = container.getMixMax();
for (DetlDto detlDto : detlDtos) {
Mat mat = matService.selectByMatnr(detlDto.getMatnr());
if (Cools.isEmpty(mat)) {
throw new CoolException(detlDto.getMatnr() + "鍟嗗搧妗f涓嶅瓨鍦�");
}
+ //鏈�澶氬彲鏀炬暟閲�
+ Double singleMax = mat.getUpQty() * suplus;
+ if (singleMax.compareTo(detlDto.getAnfme()) < 0) {
+ throw new CoolException("鐗╂枡锛�" + detlDto.getMatnr() + "鍗曟缁勬墭涓婇檺涓猴細" + mat.getUpQty() + ",褰撳墠鎬婚噺瓒呭嚭鎵樼洏瑁呰浇涓婇檺!!");
+ }
+ BigDecimal decimal = new BigDecimal(detlDto.getAnfme() / mat.getUpQty());
+ //褰撳墠鐗╂枡闇�瑕佸崰鐢ㄦ枡绠辨牸鏁�
+ Integer curr = decimal.setScale(0, RoundingMode.CEILING).intValue();
+ suplus = suplus - curr;
+ if (suplus < 0) {
+ throw new CoolException("鐗╂枡锛�" + detlDto.getMatnr() + ", 瓒呭嚭褰撳墠鎵樼洏瑁呰浇涓婇檺锛侊紒");
+ }
+
WaitPakin waitPakin = new WaitPakin();
BeanUtils.copyProperties(mat, waitPakin);
// waitPakin.sync(mat);
- waitPakin.setOrderNo(order.getOrderNo()); // 鍗曟嵁缂栧彿
- waitPakin.setOrderId(order.getId());
+ waitPakin.setOrderNo(detlDto.getOrderNo()); // 鍗曟嵁缂栧彿
+ waitPakin.setOrderId(detlDto.getOrderId());
waitPakin.setBatch(detlDto.getBatch()); // 搴忓垪鐮�
waitPakin.setZpallet(param.getBarcode()); // 鎵樼洏鐮�
waitPakin.setIoStatus("N"); // 鍏ュ嚭鐘舵��
@@ -666,8 +714,12 @@
throw new CoolException("淇濆瓨鍏ュ簱閫氱煡妗eけ璐�");
}
}
-// orderService.updateSettle(order.getId(), 2L, userId);
- OrderInAndOutUtil.updateOrder(Boolean.TRUE, order.getId(), 2L, userId);
+
+ Set<String> stringSet = param.getCombMats().stream().map(CombParam.CombMat::getOrderNo).collect(Collectors.toSet());
+ stringSet.forEach(orderNo -> {
+ Order order = OrderInAndOutUtil.selectByNo(Boolean.TRUE, orderNo);
+ OrderInAndOutUtil.updateOrder(Boolean.TRUE, order.getId(), 2L, userId);
+ });
}
}
@@ -1166,79 +1218,209 @@
/**
* @author Ryan
+ * @date 2025/9/24
+ * @description: 鑾峰彇璁㈠崟鐗╂枡淇℃伅
+ * @version 1.0
+ */
+ @Override
+ public R getMatsByQRcode(PakinMatsByQRParams params) {
+ if (Objects.isNull(params)) {
+ throw new CoolException("鍙傛暟涓嶈兘涓虹┖锛侊紒");
+ }
+ if (Objects.isNull(params.getOrderNo())) {
+ throw new CoolException("鍗曞彿涓嶈兘涓虹┖锛侊紒");
+ }
+ OrderPakin orderPakin = orderPakinService.selectOne(new EntityWrapper<OrderPakin>().eq("order_no", params.getOrderNo()));
+ if (Objects.isNull(orderPakin)) {
+ throw new CoolException("鏁版嵁閿欒锛氬崟鎹笉瀛樺湪锛侊紒");
+ }
+ List<OrderDetlPakin> detlPakins = orderDetlPakinService.selectList(new EntityWrapper<OrderDetlPakin>()
+ .eq(!Cools.isEmpty(params.getMatnr()), "matnr", params.getMatnr())
+ .eq("order_id", orderPakin.getId()));
+ if (Objects.isNull(detlPakins) || detlPakins.isEmpty()) {
+ throw new CoolException("鏁版嵁閿欒锛� 鍗曟嵁鏄庣粏涓嶅瓨鍦紒锛�");
+ }
+
+ return R.ok().add(detlPakins);
+ }
+
+ /**
+ * @author Ryan
+ * @date 2025/9/24
+ * @description: AGV鍛煎彨鎼繍
+ * @version 1.0
+ */
+ @Override
+ public R OutCallAgv(AgvCallParams params, Long userId) {
+ LocCache locCaches = locCacheService.selectOne(new EntityWrapper<LocCache>()
+ .eq("loc_sts", LocStsType.LOC_STS_TYPE_F.type)
+ .eq("frozen", 0)
+ .orderDesc(Arrays.asList("sort", "first_time"))
+ .last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY"));
+ if (Objects.isNull(locCaches)) {
+ throw new CoolException("鏆傛棤婊¤冻闇�姹傚簱浣嶏紒");
+ }
+ BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>()
+ .eq("loc_sts", LocStsType.LOC_STS_TYPE_O.type)
+ .eq("dev_no", params.getTarSite()));
+ if (Objects.isNull(station)) {
+ throw new CoolException("绔欑偣姝e湪鎵ц浠诲姟锛侊紒");
+ }
+
+ generateOutTask(station, locCaches, userId);
+
+ return R.ok();
+ }
+
+ /**
+ * @author Ryan
+ * @date 2025/9/25
+ * @description: 鍛煎彨AGV鐢熸垚鍑哄簱浠诲姟
+ * @version 1.0
+ */
+ @Transactional(rollbackFor = Exception.class)
+ public void generateOutTask(BasStation station, LocCache loc, Long userId) {
+ // 鑾峰彇宸ヤ綔鍙�
+ int workNo = commonService.getWorkNo(WorkNoType.PICK.type);
+ // 淇濆瓨宸ヤ綔妗�
+ Task task = new Task();
+ task.setWrkNo(workNo)
+ .setIoTime(new Date())
+ .setWrkSts(11L) // 宸ヤ綔鐘舵�侊細11.鐢熸垚鍑哄簱ID
+ .setIoType(101) // 鍏ュ嚭搴撶姸鎬侊細 11.搴撴牸绉昏浇
+ .setTaskType("agv")
+ .setIoPri(10D)
+ .setFullPlt("Y") // 婊℃澘锛歒
+ .setPicking("N") // 鎷f枡
+ .setExitMk("N")// 閫�鍑�
+ .setStaNo(station.getDevNo())
+ .setSourceLocNo(loc.getLocNo())
+ .setEmptyMk(loc.getLocSts().equals("D") ? "Y" : "N")// 绌烘澘
+ .setBarcode(loc.getBarcode())// 鎵樼洏鐮�
+ .setLinkMis("N")
+ .setAppeUser(userId)
+ .setAppeTime(new Date())
+ .setModiUser(userId)
+ .setModiTime(new Date());
+ if (!taskService.insert(task)) {
+ throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐�");
+ }
+ List<LocDetl> detls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_id", loc.getId()));
+ if (Objects.isNull(detls) || detls.isEmpty()) {
+ throw new CoolException("鏁版嵁閿欒锛氬簱浣嶆槑缁嗕负绌猴紒锛�");
+ }
+ List<TaskDetl> taskDetls = new ArrayList<>();
+ detls.forEach(pakin -> {
+ TaskDetl wrkDetl = new TaskDetl();
+ BeanUtils.copyProperties(pakin, wrkDetl);
+ wrkDetl.setWrkNo(workNo)
+ .setIoTime(new Date())
+ .setOrderNo(pakin.getOrderNo())
+ .setAnfme(pakin.getAnfme())
+ .setZpallet(pakin.getZpallet())
+ .setBatch(pakin.getBatch())
+ .setMatnr(pakin.getMatnr())
+ .setMaktx(pakin.getMaktx())
+ .setAppeUser(userId)
+ .setUnit(pakin.getUnit())
+ .setModel(pakin.getModel())
+ .setAppeTime(new Date())
+ .setModiUser(userId);
+ taskDetls.add(wrkDetl);
+ });
+
+ //淇濆瓨宸ヤ綔妗f槑缁�
+ if (!taskDetlService.insertBatch(taskDetls)) {
+ throw new CoolException("淇濆瓨宸ヤ綔妗f槑缁嗗け璐�");
+ }
+
+ loc.setLocSts(LocStsType.LOC_STS_TYPE_R.type);
+ loc.setModiUser(userId);
+ loc.setModiTime(new Date());
+
+ if (!locCacheService.updateById(loc)) {
+ throw new CoolException("鏇存柊搴撲綅鐘舵�佷俊鎭紒锛�");
+ }
+
+ // 淇敼鐩爣绔欑偣淇℃伅
+ if (station.getLocSts().equals("O")) {
+ station.setLocSts("S"); // S.鍏ュ簱棰勭害
+ station.setModiTime(new Date());
+ station.setModiUser(userId);
+ if (!basStationService.updateById(station)) {
+ throw new CoolException("鏇存柊鐩爣搴撲綅鐘舵�佸け璐�");
+ }
+ } else {
+ throw new CoolException("绉昏浆澶辫触锛岀洰鏍囧簱浣嶇姸鎬侊細" + station.getLocSts());
+ }
+ }
+
+ /**
+ * @author Ryan
* @date 2025/9/22
* @description: 鐢熸垚AGV鎼繍浠诲姟
* @version 1.0
*/
@Transactional(rollbackFor = Exception.class)
public void generateAgvTask(String type, LocCache loc, String orgSite, String barcode, Long userId) {
- WaitPakin pakin = waitPakinService.selectOne(new EntityWrapper<WaitPakin>().eq("zpallet", barcode));
- if (Objects.isNull(pakin)) {
+ List<WaitPakin> pakins = waitPakinService.selectList(new EntityWrapper<WaitPakin>().eq("zpallet", barcode));
+ if (Objects.isNull(pakins) || pakins.isEmpty()) {
throw new CoolException("缁勬墭淇℃伅涓嶅瓨鍦紒锛�");
}
- OrderPakin orderPakin = orderPakinService.selectById(pakin.getOrderId());
- if (Objects.isNull(orderPakin)) {
- throw new CoolException("鍗曟嵁涓嶈兘涓虹┖锛侊紒");
- }
-
- List<OrderDetlPakin> detls = orderDetlPakinService.selectList(new EntityWrapper<OrderDetlPakin>().eq("order_id", pakin.getOrderId()));
- if (Objects.isNull(detls) || detls.isEmpty()) {
- throw new CoolException("鏁版嵁閿欒锛氬崟鎹槑缁嗕笉瀛樺湪锛侊紒");
- }
-
- Date now = new Date();
// 鑾峰彇宸ヤ綔鍙�
int workNo = commonService.getWorkNo(WorkNoType.PICK.type);
// 淇濆瓨宸ヤ綔妗�
- WrkMast wrkMast = new WrkMast();
- wrkMast.setWrkNo(workNo);
- wrkMast.setIoTime(now);
- wrkMast.setWrkSts(11L); // 宸ヤ綔鐘舵�侊細11.鐢熸垚鍑哄簱ID
- wrkMast.setIoType(11); // 鍏ュ嚭搴撶姸鎬侊細 11.搴撴牸绉昏浇
- wrkMast.setTaskType("agv");
- wrkMast.setIoPri(10D);
- wrkMast.setLocNo(loc.getLocNo()); // 鐩爣搴撲綅
- wrkMast.setFullPlt("Y"); // 婊℃澘锛歒
- wrkMast.setPicking("N"); // 鎷f枡
- wrkMast.setExitMk("N"); // 閫�鍑�
- wrkMast.setSourceLocNo(orgSite);
- wrkMast.setEmptyMk(loc.getLocSts().equals("D") ? "Y" : "N"); // 绌烘澘
- wrkMast.setBarcode(barcode); // 鎵樼洏鐮�
- wrkMast.setLinkMis("N");
- wrkMast.setAppeUser(userId);
- wrkMast.setAppeTime(now);
- wrkMast.setModiUser(userId);
- wrkMast.setModiTime(now);
- if (!wrkMastService.insert(wrkMast)) {
+ Task task = new Task();
+ task.setWrkNo(workNo)
+ .setIoTime(new Date())
+ .setWrkSts(1L) // 宸ヤ綔鐘舵�侊細11.鐢熸垚鍑哄簱ID
+ .setIoType(1) // 鍏ュ嚭搴撶姸鎬侊細 11.搴撴牸绉昏浇
+ .setTaskType("agv")
+ .setIoPri(10D)
+ .setLocNo(loc.getLocNo()) // 鐩爣搴撲綅
+ .setFullPlt("Y") // 婊℃澘锛歒
+ .setPicking("N") // 鎷f枡
+ .setExitMk("N")// 閫�鍑�
+ .setSourceStaNo(orgSite)
+ .setEmptyMk(loc.getLocSts().equals("D") ? "Y" : "N")// 绌烘澘
+ .setBarcode(barcode)// 鎵樼洏鐮�
+ .setLinkMis("N")
+ .setAppeUser(userId)
+ .setAppeTime(new Date())
+ .setModiUser(userId)
+ .setModiTime(new Date());
+ if (!taskService.insert(task)) {
throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐�");
}
- List<WrkDetl> taskDetls = new ArrayList<>();
- detls.forEach(detl -> {
- WrkDetl wrkDetl = new WrkDetl();
- BeanUtils.copyProperties(detl, wrkDetl);
+ List<TaskDetl> taskDetls = new ArrayList<>();
+ pakins.forEach(pakin -> {
+ TaskDetl wrkDetl = new TaskDetl();
+ BeanUtils.copyProperties(pakin, wrkDetl);
wrkDetl.setWrkNo(workNo)
.setIoTime(new Date())
- .setAnfme(detl.getAnfme())
+ .setOrderNo(pakin.getOrderNo())
+ .setAnfme(pakin.getAnfme())
.setZpallet(pakin.getZpallet())
- .setBatch(detl.getBatch())
- .setMatnr(detl.getMatnr())
- .setMaktx(detl.getMaktx())
+ .setBatch(pakin.getBatch())
+ .setMatnr(pakin.getMatnr())
+ .setMaktx(pakin.getMaktx())
.setAppeUser(userId)
- .setUnit(detl.getUnit())
- .setModel(detl.getModel())
+ .setUnit(pakin.getUnit())
+ .setModel(pakin.getModel())
.setAppeTime(new Date())
.setModiUser(userId);
taskDetls.add(wrkDetl);
});
+
//淇濆瓨宸ヤ綔妗f槑缁�
- if (!wrkDetlService.insertBatch(taskDetls)) {
+ if (!taskDetlService.insertBatch(taskDetls)) {
throw new CoolException("淇濆瓨宸ヤ綔妗f槑缁嗗け璐�");
}
// 淇敼鐩爣搴撲綅鐘舵��
if (loc.getLocSts().equals("O")) {
loc.setLocSts("S"); // S.鍏ュ簱棰勭害
- loc.setModiTime(now);
+ loc.setModiTime(new Date());
loc.setModiUser(userId);
if (!locCacheService.updateById(loc)) {
throw new CoolException("鏇存柊鐩爣搴撲綅鐘舵�佸け璐�");
--
Gitblit v1.9.1