diff --git a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/ErpStockOutController.java b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/ErpStockOutController.java index 6d7104710..db9dd4e5c 100644 --- a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/ErpStockOutController.java +++ b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/ErpStockOutController.java @@ -26,6 +26,7 @@ import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutApproveRecord import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutDO; import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutItemDO; import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutItemPalletDO; +import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockOutItemMapper; import cn.iocoder.yudao.module.erp.enums.ErpStockOutStatusEnum; import cn.iocoder.yudao.module.erp.service.mold.MoldBrandService; import cn.iocoder.yudao.module.erp.service.mold.MoldService; @@ -81,6 +82,8 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. @Validated public class ErpStockOutController { + private static final List LOCKED_STOCK_OUT_STATUSES = java.util.Arrays.asList(10, 0, 1); + @Resource private ErpStockOutService stockOutService; @Resource @@ -97,6 +100,8 @@ public class ErpStockOutController { private ErpPalletService palletService; @Resource private AdminUserApi adminUserApi; + @Resource + private ErpStockOutItemMapper stockOutItemMapper; @PostMapping("/create") @Operation(summary = "创建其它出库单") @@ -177,9 +182,11 @@ public class ErpStockOutController { if (stockOut == null) { return success(null); } - return success(buildStockOutRespVO(stockOut, + ErpStockOutRespVO stockOutVO = buildStockOutRespVO(stockOut, stockOutService.getStockOutItemListByOutId(id), - stockOutService.getStockOutApproveRecordList(id))); + stockOutService.getStockOutApproveRecordList(id)); + fillLockedStockCount(stockOutVO.getItems()); + return success(stockOutVO); } @GetMapping("/page") @@ -424,6 +431,22 @@ public class ErpStockOutController { return value != null ? value : BigDecimal.ZERO; } + private void fillLockedStockCount(List items) { + if (CollUtil.isEmpty(items)) { + return; + } + items.forEach(item -> item.setLockedStockCount(getLockedStockCount(item))); + } + + private BigDecimal getLockedStockCount(ErpStockOutRespVO.Item item) { + if (item.getProductId() == null) { + return BigDecimal.ZERO; + } + BigDecimal lockedStockCount = stockOutItemMapper.selectLockedStockCount( + item.getProductId(), item.getWarehouseId(), item.getAreaId(), LOCKED_STOCK_OUT_STATUSES); + return lockedStockCount != null ? lockedStockCount : BigDecimal.ZERO; + } + private String buildStockKey(Long productId, Long warehouseId, Long areaId) { return String.valueOf(productId) + "_" + String.valueOf(warehouseId) + "_" + String.valueOf(areaId); } diff --git a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/out/ErpStockOutRespVO.java b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/out/ErpStockOutRespVO.java index bc46f3eb6..7bd3b79e9 100644 --- a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/out/ErpStockOutRespVO.java +++ b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/out/ErpStockOutRespVO.java @@ -259,6 +259,9 @@ public class ErpStockOutRespVO { @Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") private BigDecimal stockCount; + @Schema(description = "锁定库存数量", example = "10.00") + private BigDecimal lockedStockCount; + @Schema(description = "托盘列表") private List pallets; diff --git a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockOutServiceImpl.java b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockOutServiceImpl.java index 051e1936e..0cb3a6aa7 100644 --- a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockOutServiceImpl.java +++ b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockOutServiceImpl.java @@ -422,7 +422,7 @@ public class ErpStockOutServiceImpl implements ErpStockOutService { item -> copyStockOutItem(sourceItem, warehouseId, areaId)); BigDecimal palletCount = resolvePalletCount(pallet, sourceItem); if (palletCount.compareTo(BigDecimal.ZERO) <= 0) { - throw exception(STOCK_OUT_PRODUCT_PALLET_COUNT_EMPTY, pallet.getPalletId()); + throw exception(STOCK_OUT_PRODUCT_PALLET_COUNT_EMPTY, getPalletCodeOrId(pallet.getPalletId())); } palletTotalCount = palletTotalCount.add(palletCount); targetItem.setCount(defaultZero(targetItem.getCount()).add(palletCount)); @@ -440,6 +440,14 @@ public class ErpStockOutServiceImpl implements ErpStockOutService { reqVO.setItems(normalizedItems); } + private Object getPalletCodeOrId(Long palletId) { + if (palletId == null) { + return null; + } + ErpPalletDO pallet = palletMapper.selectById(palletId); + return pallet != null && pallet.getCode() != null ? pallet.getCode() : palletId; + } + private ErpStockOutSaveReqVOItem copyStockOutItem(ErpStockOutSaveReqVOItem sourceItem, Long warehouseId, Long areaId) { ErpStockOutSaveReqVOItem targetItem = BeanUtils.toBean(sourceItem, ErpStockOutSaveReqVOItem.class); targetItem.setId(null); diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/deviceline/DeviceLineController.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/deviceline/DeviceLineController.java index 5ab1b73e5..5426bc04d 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/deviceline/DeviceLineController.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/deviceline/DeviceLineController.java @@ -153,8 +153,9 @@ public class DeviceLineController { @PreAuthorize("@ss.hasPermission('iot:device:query')") public CommonResult> deviceParameterAnalysis( @RequestParam(value = "keyword", required = false) String keyword, - @RequestParam(value = "showDevices") Integer showDevices) { - return success(deviceLineService.deviceParameterAnalysis(keyword, showDevices)); + @RequestParam(value = "showDevices") Integer showDevices, + @RequestParam(value = "filterNoDeviceLine", required = false) Integer filterNoDeviceLine) { + return success(deviceLineService.deviceParameterAnalysis(keyword, showDevices, filterNoDeviceLine)); } @GetMapping("/children") diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/plan/vo/PlanStatusEnum.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/plan/vo/PlanStatusEnum.java index b16643deb..84067ade7 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/plan/vo/PlanStatusEnum.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/plan/vo/PlanStatusEnum.java @@ -12,7 +12,7 @@ public enum PlanStatusEnum { 量产(2), 暂停(3), - //旧完工-启用 + //旧完工-弃用 // 完工(4), 已入库(5), 试产 (6), diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/deviceledger/DeviceLedgerServiceImpl.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/deviceledger/DeviceLedgerServiceImpl.java index d81f972e1..2eee9f026 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/deviceledger/DeviceLedgerServiceImpl.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/deviceledger/DeviceLedgerServiceImpl.java @@ -255,6 +255,9 @@ public class DeviceLedgerServiceImpl implements DeviceLedgerService { updateObj.setComponentId(updateObj.getComponentId()==null?"":updateObj.getComponentId()); updateObj.setBeijianId(updateObj.getBeijianId()==null?"":updateObj.getBeijianId()); deviceLedgerMapper.updateById(updateObj); + deviceLedgerMapper.update(null, Wrappers.lambdaUpdate() + .eq(DeviceLedgerDO::getId, updateObj.getId()) + .set(DeviceLedgerDO::getDvId, updateReqVO.getDvId())); deviceLedgerComponentRelService.replaceByDeviceLedgerId(updateObj.getId(), updateReqVO.getComponentId()); deviceLedgerSpareRelService.replaceByDeviceLedgerId(updateObj.getId(), updateReqVO.getBeijianId()); } diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/deviceline/DeviceLineService.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/deviceline/DeviceLineService.java index 6a5d6b375..9fb1f970c 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/deviceline/DeviceLineService.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/deviceline/DeviceLineService.java @@ -36,7 +36,7 @@ public interface DeviceLineService { List getAncestorDeviceLines(Long id); - List deviceParameterAnalysis(String keyword, Integer showDevices); + List deviceParameterAnalysis(String keyword, Integer showDevices, Integer filterNoDeviceLine); void regenerateCode(Long id, String code) throws UnsupportedEncodingException; diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/deviceline/DeviceLineServiceImpl.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/deviceline/DeviceLineServiceImpl.java index 6edf4e0d7..7ee11d0ee 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/deviceline/DeviceLineServiceImpl.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/deviceline/DeviceLineServiceImpl.java @@ -229,11 +229,12 @@ public class DeviceLineServiceImpl implements DeviceLineService { } @Override - public List deviceParameterAnalysis(String keyword, Integer showDevices) { + public List deviceParameterAnalysis(String keyword, Integer showDevices, Integer filterNoDeviceLine) { if (showDevices == null || (showDevices != 1 && showDevices != 2)) { showDevices = 1; } boolean needShowDevices = showDevices == 1; + boolean needFilterNoDeviceLine = filterNoDeviceLine != null && filterNoDeviceLine == 1; boolean hasKeyword = StringUtils.isNotBlank(keyword); String lowerKeyword = hasKeyword ? keyword.toLowerCase() : null; @@ -274,10 +275,21 @@ public class DeviceLineServiceImpl implements DeviceLineService { .filter(item -> item.getDeviceLine() != null) .collect(Collectors.groupingBy(item -> item.getDeviceLine().longValue())); + Set validDeviceIds = deviceMap.keySet(); + Set lineIdsWithDevice = ledgers.stream() + .filter(item -> item.getDeviceLine() != null) + .filter(item -> validDeviceIds.contains(item.getDvId())) + .map(item -> item.getDeviceLine().longValue()) + .collect(Collectors.toSet()); + Map> childrenByParentId = deviceLines.stream() .filter(item -> item.getParentId() != null && item.getParentId() != 0L) .collect(Collectors.groupingBy(DeviceLineDO::getParentId)); + Map deviceLineMap = deviceLines.stream() + .collect(Collectors.toMap(DeviceLineDO::getId, Function.identity(), (a, b) -> a)); + Set lineIdsWithDeviceOrAncestor = buildLineIdsWithDeviceOrAncestor(lineIdsWithDevice, deviceLineMap); + Set matchedNodeIds = new HashSet<>(); if (hasKeyword) { for (DeviceLineDO line : deviceLines) { @@ -294,8 +306,27 @@ public class DeviceLineServiceImpl implements DeviceLineService { matchedNodeIds.addAll(deviceLines.stream().map(DeviceLineDO::getId).collect(Collectors.toSet())); } - return buildDeviceLineAnalysisTree(deviceLines, matchedNodeIds, ledgersByLineId, deviceMap, - paramsByDeviceId, needShowDevices, hasKeyword, lowerKeyword); + return buildDeviceLineAnalysisTree(deviceLines, matchedNodeIds, lineIdsWithDeviceOrAncestor, ledgersByLineId, deviceMap, + paramsByDeviceId, needShowDevices, needFilterNoDeviceLine, hasKeyword, lowerKeyword); + } + + private Set buildLineIdsWithDeviceOrAncestor(Set lineIdsWithDevice, + Map deviceLineMap) { + Set result = new HashSet<>(lineIdsWithDevice); + for (Long lineId : lineIdsWithDevice) { + DeviceLineDO current = deviceLineMap.get(lineId); + Long parentId = current == null ? null : current.getParentId(); + Set visitedParentIds = new HashSet<>(); + while (parentId != null && parentId > 0 && visitedParentIds.add(parentId)) { + result.add(parentId); + DeviceLineDO parent = deviceLineMap.get(parentId); + if (parent == null) { + break; + } + parentId = parent.getParentId(); + } + } + return result; } private boolean isDeviceLineAnalysisMatched(DeviceLineDO line, @@ -365,10 +396,12 @@ public class DeviceLineServiceImpl implements DeviceLineService { private List buildDeviceLineAnalysisTree( List deviceLines, Set matchedNodeIds, + Set lineIdsWithDeviceOrAncestor, Map> ledgersByLineId, Map deviceMap, Map> paramsByDeviceId, boolean needShowDevices, + boolean needFilterNoDeviceLine, boolean hasKeyword, String lowerKeyword) { @@ -377,6 +410,9 @@ public class DeviceLineServiceImpl implements DeviceLineService { if (!matchedNodeIds.contains(line.getId())) { continue; } + if (needFilterNoDeviceLine && !lineIdsWithDeviceOrAncestor.contains(line.getId())) { + continue; + } nodeMap.put(line.getId(), LineAnalysisTreeDTO.LineNode.builder() .id(line.getId()) .name(line.getName()) diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/energydevice/EnergyDeviceServiceImpl.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/energydevice/EnergyDeviceServiceImpl.java index 34a763374..209b799df 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/energydevice/EnergyDeviceServiceImpl.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/energydevice/EnergyDeviceServiceImpl.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.erp.controller.admin.autocode.util.AutoCodeUtil; import cn.iocoder.yudao.module.iot.controller.admin.device.enums.JavaToTdengineTypeEnum; import cn.iocoder.yudao.module.mes.controller.admin.energydevice.vo.HourEnergyValueVO; import cn.iocoder.yudao.module.iot.dal.dataobject.devicecontactmodel.DeviceContactModelDO; @@ -15,7 +16,6 @@ import cn.iocoder.yudao.module.mes.dal.dataobject.energydevice.EnergyDeviceCheck import cn.iocoder.yudao.module.mes.dal.dataobject.energydevice.EnergyDeviceDO; import cn.iocoder.yudao.module.mes.dal.mysql.energydevice.EnergyDeviceCheckRecordMapper; import cn.iocoder.yudao.module.mes.dal.mysql.energydevice.EnergyDeviceMapper; -import cn.iocoder.yudao.module.mes.dal.redis.no.MesNoRedisDAO; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -58,7 +58,7 @@ public class EnergyDeviceServiceImpl implements EnergyDeviceService { @Resource private EnergyDeviceCheckRecordMapper energyDeviceCheckRecordMapper; @Resource - private MesNoRedisDAO noRedisDAO; + private AutoCodeUtil autoCodeUtil; @Resource private TDengineService tDengineService; @Resource @@ -68,15 +68,12 @@ public class EnergyDeviceServiceImpl implements EnergyDeviceService { public Long createEnergyDevice(EnergyDeviceSaveReqVO createReqVO) { // 插入 EnergyDeviceDO energyDevice = BeanUtils.toBean(createReqVO, EnergyDeviceDO.class); - if (StringUtils.isEmpty(energyDevice.getCode())) { - // 1.4 生成编号 - String no = noRedisDAO.generate2(MesNoRedisDAO.ENERGY_NO_PREFIX); - energyDevice.setCode(no); - } - // 校验编码是否唯一 - if (StringUtils.isNotEmpty(energyDevice.getCode())) { + // 验证是否唯一编码;未填写时自动生成 + if (StringUtils.isBlank(createReqVO.getCode())) { + energyDevice.setCode(autoCodeUtil.genSerialCode("ENERGY_CONSUMPTION_CODE", null)); + } else { List existingDevice = energyDeviceMapper.selectList( - Wrappers.lambdaQuery().eq(EnergyDeviceDO::getCode,createReqVO.getCode())); + Wrappers.lambdaQuery().eq(EnergyDeviceDO::getCode, createReqVO.getCode())); if (!existingDevice.isEmpty()) { throw exception(ENERGY_DEVICE_CODE_DUPLICATE); }