From 6c3cc6842009f3897c3fb18bef8a6634fe653818 Mon Sep 17 00:00:00 2001
From: 1 <1@123>
Date: 星期三, 04 三月 2026 19:59:11 +0800
Subject: [PATCH] lsh#
---
rsf-server/src/main/java/com/vincent/rsf/server/manager/utils/LocManageUtil.java | 253 ++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 231 insertions(+), 22 deletions(-)
diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/utils/LocManageUtil.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/utils/LocManageUtil.java
index a016244..da7af21 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/manager/utils/LocManageUtil.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/utils/LocManageUtil.java
@@ -1,40 +1,88 @@
package com.vincent.rsf.server.manager.utils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.vincent.rsf.framework.common.Cools;
import com.vincent.rsf.framework.common.SpringUtils;
+import com.vincent.rsf.framework.exception.CoolException;
import com.vincent.rsf.server.api.utils.LocUtils;
-import com.vincent.rsf.server.manager.entity.DeviceSite;
-import com.vincent.rsf.server.manager.entity.Loc;
-import com.vincent.rsf.server.manager.entity.LocItem;
-import com.vincent.rsf.server.manager.service.DeviceSiteService;
-import com.vincent.rsf.server.manager.service.LocItemService;
-import com.vincent.rsf.server.manager.service.LocService;
+import com.vincent.rsf.server.manager.controller.dto.ExistDto;
+import com.vincent.rsf.server.manager.controller.dto.OrderOutItemDto;
+import com.vincent.rsf.server.manager.controller.params.WaveToLocParams;
+import com.vincent.rsf.server.manager.entity.*;
+import com.vincent.rsf.server.manager.enums.TaskType;
+import com.vincent.rsf.server.manager.enums.WaveRuleType;
+import com.vincent.rsf.server.manager.service.*;
import com.vincent.rsf.server.manager.enums.LocStsType;
+import org.apache.commons.lang3.StringUtils;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Objects;
+import java.math.BigDecimal;
+import java.util.*;
import java.util.stream.Collectors;
public class LocManageUtil {
/**
- * @author Ryan
- * @description 鑾峰彇鐩爣搴撲綅, 鍖呭惈搴撲綅鑾峰彇绛栫暐
* @param
* @return
+ * @author Ryan
+ * @description 鑾峰彇鐩爣搴撲綅, 鍖呭惈搴撲綅鑾峰彇绛栫暐
* @time 2025/3/31 08:50
*/
public static String getTargetLoc(Long areaId) {
//TODO 搴撲綅绛栫暐鍚庣画鎺掓湡
- LocService locService = SpringUtils.getBean(LocService.class);
+ return getTargetLoc(areaId, null);
+ }
+
+ public static String getTargetLoc(Long areaId, Long containerType,List<Integer> rowList) {
+
+ Long locType = containerType;
+ //TODO 搴撲綅绛栫暐鍚庣画鎺掓湡
+ LocService locService = SpringUtils.getBean(LocService.class);
Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>()
+ .eq(!Objects.isNull(locType), Loc::getType, locType)
.eq(Loc::getAreaId, areaId)
+ .eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
+ .in(Objects.nonNull(rowList) && !rowList.isEmpty(), Loc::getRow, rowList)
.orderByAsc(Loc::getLev)
.orderByAsc(Loc::getCol)
.orderByAsc(Loc::getRow)
- .eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type), false
+ .last("LIMIT 1")
+ );
+
+ return !Objects.isNull(loc) ? loc.getCode() : null;
+ }
+
+ public static String getTargetLoc(Long areaId, Long containerType) {
+ Long locType = containerType;
+// if (!Objects.isNull(containerType)) {
+// LocTypeService locService = SpringUtils.getBean(LocTypeService.class);
+// if (containerType.equals(ContainerType.CONTAINER_TYPE_NORMAL.val)) {
+// LocType low = locService.getOne(new LambdaQueryWrapper<LocType>()
+// .eq(LocType::getCode, "L"));
+// if (Objects.isNull(low)) {
+// throw new CoolException("搴綅椤炲瀷涓嶅瓨鍦紒锛�");
+// }
+// locType = low.getId();
+// } else {
+// LocType low = locService.getOne(new LambdaQueryWrapper<LocType>()
+// .eq(LocType::getCode, "H"));
+// if (Objects.isNull(low)) {
+// throw new CoolException("搴綅椤炲瀷涓嶅瓨鍦紒锛�");
+// }
+// locType = low.getId();
+// }
+// }
+ //TODO 搴撲綅绛栫暐鍚庣画鎺掓湡
+ LocService locService = SpringUtils.getBean(LocService.class);
+ Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>()
+ .eq(!Objects.isNull(locType), Loc::getType, locType)
+ .eq(Loc::getAreaId, areaId)
+ .eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
+ .orderByAsc(Loc::getLev)
+ .orderByAsc(Loc::getCol)
+ .orderByAsc(Loc::getRow)
+ .last("LIMIT 1")
);
return !Objects.isNull(loc) ? loc.getCode() : null;
@@ -42,12 +90,12 @@
/**
- * @author Ryan
- * @description 鑾峰彇鐩爣绔欑偣
- * @param
- * @return
- * @time 2025/3/31 09:49
- */
+ * @param
+ * @return
+ * @author Ryan
+ * @description 鑾峰彇鐩爣绔欑偣
+ * @time 2025/3/31 09:49
+ */
public static String getTargetSite() {
//TODO 绔欑偣绛栫暐鍚庣画鎺掓湡
DeviceSiteService deviceSite = SpringUtils.getBean(DeviceSiteService.class);
@@ -57,6 +105,7 @@
/**
* 鍑哄簱绛栫暐锛�--銆堟晥鐜囦紭鍖栥��
+ *
* @param matnrCode
* @param splrBatch
* @param anfme
@@ -65,7 +114,7 @@
public static List<LocItem> getEfficiencyFirstItemList(String matnrCode, String splrBatch, Double anfme) {
LambdaQueryWrapper<LocItem> locItemQueryWrapper = new LambdaQueryWrapper<>();
locItemQueryWrapper.eq(LocItem::getMatnrCode, matnrCode);
- locItemQueryWrapper.eq(LocItem::getBatch, splrBatch);
+ locItemQueryWrapper.eq(StringUtils.isNotBlank(splrBatch), LocItem::getBatch, splrBatch);
String applySql = String.format(
"EXISTS (SELECT 1 FROM man_loc ml " +
"WHERE ml.use_status = '%s'" +
@@ -87,6 +136,7 @@
/**
* 鍑哄簱绛栫暐锛�--<鍏堣繘鍏堝嚭>
+ *
* @param matnrCode
* @param splrBatch
* @param anfme
@@ -95,8 +145,13 @@
public static List<LocItem> getFirstInFirstOutItemList(String matnrCode, String splrBatch, Double anfme) {
LambdaQueryWrapper<LocItem> locItemQueryWrapper = new LambdaQueryWrapper<>();
locItemQueryWrapper.eq(LocItem::getMatnrCode, matnrCode);
- locItemQueryWrapper.eq(LocItem::getBatch, splrBatch);
- locItemQueryWrapper.orderByAsc(LocItem::getCreateTime);
+ locItemQueryWrapper.eq(StringUtils.isNotEmpty(splrBatch), LocItem::getBatch, splrBatch);
+ //濡傛灉鎵规涓嶄负绌猴紝鎸夋壒娆″厛鍚庡嚭搴�
+ if (StringUtils.isNotBlank(splrBatch)) {
+ locItemQueryWrapper.orderByAsc(LocItem::getBatch);
+ } else {
+ locItemQueryWrapper.orderByAsc(LocItem::getCreateTime);
+ }
String applySql = String.format(
"EXISTS (SELECT 1 FROM man_loc ml " +
"WHERE ml.use_status = '%s'" +
@@ -110,6 +165,160 @@
return locItems;
}
+ /**
+ * 鑾峰彇鍑哄簱搴撲綅淇℃伅
+ *
+ * @param params
+ * @param waveRule
+ * @return
+ */
+ public static List<OrderOutItemDto> getOutOrderList(List<WaveToLocParams> params, WaveRule waveRule) {
+ LocService locService = SpringUtils.getBean(LocService.class);
+ LocItemService locItemService = SpringUtils.getBean(LocItemService.class);
+ DeviceSiteService deviceSiteService = SpringUtils.getBean(DeviceSiteService.class);
+ BasStationAreaService basStationAreaService = SpringUtils.getBean(BasStationAreaService.class);
+// List<BasStationArea> basStationAreas = basStationAreaService.list(new LambdaQueryWrapper<>());//
+ List<Loc> locList = new ArrayList<>();
+ List<OrderOutItemDto> list = new ArrayList<>();
+ //涓嶈绔欑偣閲嶅浣跨敤闂
+ List<BasStation> stations = new ArrayList<>();
+ Set<ExistDto> existDtos = new HashSet<>();
+ for (WaveToLocParams item : params) {
+ BigDecimal issued = new BigDecimal(item.getAnfme().toString())
+ .subtract(new BigDecimal(item.getWorkQty().toString()));
+ if (issued.doubleValue() <= 0) {
+ continue;
+ }
+ List<LocItem> locItems;
+ if (Objects.isNull(waveRule)) {
+ locItems = LocManageUtil.getFirstInFirstOutItemList(item.getMatnrCode(), item.getBatch(), item.getAnfme());
+ } else {
+ if (WaveRuleType.Efficiency_First.type.equals(waveRule.getType())) {
+ locItems = LocManageUtil.getEfficiencyFirstItemList(item.getMatnrCode(), item.getBatch(), item.getAnfme());
+ } else if (WaveRuleType.First_In_First_Out.type.equals(waveRule.getType())) {
+ locItems = LocManageUtil.getFirstInFirstOutItemList(item.getMatnrCode(), item.getBatch(), item.getAnfme());
+ } else {
+ locItems = LocManageUtil.getFirstInFirstOutItemList(item.getMatnrCode(), item.getBatch(), item.getAnfme());
+ }
+ }
+ for (LocItem locItem : locItems) {
+ Loc loc = locService.getById(locItem.getLocId());
+ List<LocItem> itemList = locItemService.list(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocId, loc.getId()));
+
+ if (issued.doubleValue() > 0 && locList.contains(loc)) {
+ for (OrderOutItemDto itemDto : list) {
+ if (itemDto.getLoc().equals(loc)) {
+ ExistDto existDto = new ExistDto().setBatch(locItem.getBatch()).setMatnr(locItem.getMatnrCode()).setLocNo(locItem.getLocCode());
+ if (existDtos.add(existDto)) {
+ locItem.setOutQty(issued.doubleValue() >= locItem.getAnfme() ? locItem.getAnfme() : issued.doubleValue());
+ locItem.setBarcode(loc.getBarcode())
+ .setSourceId(item.getWaveId())//娉㈡ID
+ .setSource(item.getItemId());//娉㈡鏄庣粏ID
+ itemDto.getLocItemList().add(locItem);
+ issued = issued.subtract(new BigDecimal(locItem.getAnfme().toString()));
+ }
+ break;
+ }
+ }
+ } else if (issued.doubleValue() > 0) {
+ ExistDto existDto = new ExistDto().setBatch(locItem.getBatch()).setMatnr(locItem.getMatnrCode()).setLocNo(locItem.getLocCode());
+ if (existDtos.add(existDto)) {
+ locItem.setOutQty(issued.doubleValue() >= locItem.getAnfme() ? locItem.getAnfme() : issued.doubleValue());
+ locItem.setBarcode(loc.getBarcode())
+ .setSourceId(item.getWaveId())//娉㈡ID
+ .setSource(item.getItemId());//娉㈡鏄庣粏ID
+ OrderOutItemDto orderOutItemDto = new OrderOutItemDto();
+// orderOutItemDto.setLocItem(locItem);
+ orderOutItemDto.setLoc(loc);
+ orderOutItemDto.getLocItemList().add(locItem);
+ BasContainer containerType = getContainerType(loc.getBarcode());
+ List<BasStationArea> basStationAreas = basStationAreaService.list(new LambdaQueryWrapper<BasStationArea>()
+ .apply("JSON_CONTAINS(cross_zone_area, '{0}') = 1", loc.getAreaId())//鍙墽琛屽簱鍖哄尯鍖哄煙id
+ .apply("JSON_CONTAINS(container_type, '{0}') = 1", containerType)//瀹瑰櫒绫诲瀷
+// .apply("JSON_CONTAINS(station_alias, '\"{0}\"') = 1", null)//鍖哄煙鍖呭惈绔欑偣闆�
+ .eq(BasStationArea::getDeleted, 0));// 閫氬父闇�瑕佸姞涓婃湭鍒犻櫎鏉′欢
+ List<String> targSiteAreaList = new ArrayList<>();
+ for (BasStationArea basStationArea : basStationAreas) {
+ targSiteAreaList.add(basStationArea.getStationAreaId());
+ }
+ int count = 0;
+ for (BasStationArea basStationArea : basStationAreas) {
+ count++;
+ if (!basStationArea.getStationAlias().isEmpty()) {
+ List<OrderOutItemDto.staListDto> maps = new ArrayList<>();
+ for (String site : basStationArea.getStationAlias()) {
+ OrderOutItemDto.staListDto staListDto = new OrderOutItemDto.staListDto();
+ staListDto.setStaNo(site);
+ staListDto.setStaName(site);
+ maps.add(staListDto);
+ }
+ orderOutItemDto.setStaNos(maps);
+ //鑾峰彇婊¤冻鏉′欢绔欑偣
+ Set<String> stationSet = new HashSet<>(basStationArea.getStationAlias());
+// Set<String> stationSet = basStationArea.getStationAlias().stream().collect(Collectors.toSet());
+// Set<String> stationSet = deviceSites.stream().map(DeviceSite::getSite).collect(Collectors.toSet());
+ //宸蹭娇鐢ㄧ珯鐐�
+ Set<String> stas = stations.stream().map(BasStation::getStationName).collect(Collectors.toSet());
+ BasStationService basStationService = SpringUtils.getBean(BasStationService.class);
+ BasStation basStation = basStationService.getOne(new LambdaQueryWrapper<BasStation>()
+ .eq(BasStation::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
+ .in(BasStation::getStationName, stationSet)
+ .notIn(!stas.isEmpty(), BasStation::getStationName, stas)
+ .last("LIMIT 1"));
+ if (!Objects.isNull(basStation)) {
+ stations.add(basStation);
+ }
+
+ if (count == basStationAreas.size()) {
+ if (!Objects.isNull(basStation)) {
+ orderOutItemDto.setSiteNo(basStation.getStationName());
+// throw new CoolException("绔欓粸涓嶅瓨鍦紒锛�");
+ }
+ } else {
+ if (Objects.isNull(basStation)) {
+ continue;
+// throw new CoolException("绔欓粸涓嶅瓨鍦紒锛�");
+ }
+ orderOutItemDto.setSiteNo(basStation.getStationName());
+ }
+
+ }
+
+ orderOutItemDto.setSource(item.getItemId().toString())
+ .setTargSiteAreaList(targSiteAreaList)
+ .setSourceId(item.getWaveId().toString());
+ list.add(orderOutItemDto);
+ locList.add(loc);
+
+ issued = issued.subtract(new BigDecimal(locItem.getAnfme().toString()));
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ return list;
+ }
+
+
+
+
+ //鏍规嵁鏉$爜鑾峰彇瑙勫垯
+ private static BasContainer getContainerType(String barcode) {
+ BasContainerService basContainerService = SpringUtils.getBean(BasContainerService.class);
+ if (Cools.isEmpty(barcode)) {
+ throw new CoolException("瀹瑰櫒鐮佷笉鑳戒负绌�");
+ }
+ List<BasContainer> containers = basContainerService.list(new LambdaQueryWrapper<>());
+ for (BasContainer container : containers) {
+ String codeType = container.getCodeType(); // 鑾峰彇姝e垯琛ㄨ揪寮�
+ if (barcode.matches(codeType)) { // 鍒ゆ柇鏉$爜鏄惁绗﹀悎杩欎釜姝e垯
+ return container;
+ }
+ }
+ return null;
+ }
}
--
Gitblit v1.9.1