|
|
|
@ -21,6 +21,7 @@ import java.math.BigDecimal; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.IntStream; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@Service |
|
|
|
public class WcsIntegrationServiceImpl implements WcsIntegrationService { |
|
|
|
@ -262,4 +263,109 @@ public class WcsIntegrationServiceImpl implements WcsIntegrationService { |
|
|
|
|
|
|
|
wcsIntegrationMapper.deletePalletDetail(site, palletId, serialNo); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<Integer> getLayersForEdit(Map<String, Object> params) throws Exception { |
|
|
|
String site = (String) params.get("site"); |
|
|
|
String palletId = (String) params.get("palletId"); |
|
|
|
String position = (String) params.get("position"); |
|
|
|
String excludeSerialNo = (String) params.get("excludeSerialNo"); |
|
|
|
|
|
|
|
if (!StringUtils.hasText(site) || !StringUtils.hasText(palletId) || |
|
|
|
!StringUtils.hasText(position) || !StringUtils.hasText(excludeSerialNo)) { |
|
|
|
throw new Exception("参数不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
// 获取当前位置的已占用层数(排除指定标签) |
|
|
|
List<Integer> occupiedLayers = wcsIntegrationMapper.getOccupiedLayersExcludeSerial(site, palletId, position, excludeSerialNo); |
|
|
|
|
|
|
|
// 获取栈板类型信息以确定最大层数 |
|
|
|
Map<String, Object> palletInfo = wcsIntegrationMapper.getPalletInfo(site, palletId); |
|
|
|
if (palletInfo == null) { |
|
|
|
throw new Exception("栈板不存在"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 生成可选层数:已占用层数 + 下一层 |
|
|
|
List<Integer> availableLayers = new ArrayList<>(); |
|
|
|
|
|
|
|
// 添加下一层(如果不超过最大层数) |
|
|
|
if (occupiedLayers.isEmpty()) { |
|
|
|
availableLayers.add(1); // 如果没有占用层,可以选择第1层 |
|
|
|
} else { |
|
|
|
int maxOccupied = occupiedLayers.stream().mapToInt(Integer::intValue).max().orElse(0); |
|
|
|
for (int i = 0; i <maxOccupied ; i++) { |
|
|
|
availableLayers.add(i+1); |
|
|
|
} |
|
|
|
|
|
|
|
availableLayers.add(maxOccupied + 1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 去重并排序 |
|
|
|
return availableLayers.stream().distinct().sorted().collect(Collectors.toList()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public void updatePalletDetailPosition(Map<String, Object> params) throws Exception { |
|
|
|
String site = (String) params.get("site"); |
|
|
|
String palletId = (String) params.get("palletId"); |
|
|
|
String serialNo = (String) params.get("serialNo"); |
|
|
|
String newPosition = (String) params.get("newPosition"); |
|
|
|
Integer newLayer = null; |
|
|
|
|
|
|
|
if (params.get("newLayer") != null) { |
|
|
|
newLayer = Integer.valueOf(params.get("newLayer").toString()); |
|
|
|
} |
|
|
|
|
|
|
|
if (!StringUtils.hasText(site) || !StringUtils.hasText(palletId) || |
|
|
|
!StringUtils.hasText(serialNo) || !StringUtils.hasText(newPosition) || newLayer == null) { |
|
|
|
throw new Exception("参数不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
// 验证标签是否在当前栈板中 |
|
|
|
Map<String, Object> currentDetail = wcsIntegrationMapper.findPalletByLabel(site, serialNo); |
|
|
|
if (currentDetail == null || !palletId.equals(currentDetail.get("palletId"))) { |
|
|
|
throw new Exception("标签不在当前栈板中"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 层级校验:如果目标层数 > 1,检查前一层是否完整 |
|
|
|
if (newLayer > 1) { |
|
|
|
// 获取栈板类型信息 |
|
|
|
Map<String, Object> palletInfo = wcsIntegrationMapper.getPalletInfo(site, palletId); |
|
|
|
String palletType = (String) palletInfo.get("pallet_type"); |
|
|
|
|
|
|
|
List<Map<String, Object>> areaInfo = wcsIntegrationMapper.getPalletTypeAreaInfo(site, palletType); |
|
|
|
int totalPositions = areaInfo.size(); |
|
|
|
|
|
|
|
// 检查前一层是否所有位置都有数据(排除当前移动的标签) |
|
|
|
List<Map<String, Object>> layerStatistics = wcsIntegrationMapper.getPalletLayerStatistics(site, palletId, newLayer - 1); |
|
|
|
|
|
|
|
// 排除当前标签后,检查前一层各位置是否都有数据 |
|
|
|
int currentLayer = (Integer) currentDetail.get("layer"); |
|
|
|
String currentPosition = (String) currentDetail.get("position"); |
|
|
|
|
|
|
|
int expectedCount = totalPositions; |
|
|
|
if (currentLayer == newLayer - 1) { |
|
|
|
expectedCount--; // 如果当前标签在前一层,需要减1 |
|
|
|
} |
|
|
|
|
|
|
|
int actualCount = layerStatistics.size(); |
|
|
|
if (currentLayer == newLayer - 1) { |
|
|
|
actualCount--; // 排除当前标签 |
|
|
|
} |
|
|
|
|
|
|
|
if (actualCount < expectedCount) { |
|
|
|
throw new Exception("第" + (newLayer - 1) + "层未满,无法移动到第" + newLayer + "层"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 执行位置更新 |
|
|
|
String username = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername(); |
|
|
|
wcsIntegrationMapper.updatePalletDetailPosition(site, palletId, serialNo, newPosition, newLayer, username); |
|
|
|
} |
|
|
|
} |