fix:修改能耗管理树状列表及仓储出库锁定库存回显问题

main
HuangHuiKang 1 day ago
parent 2782f664ae
commit 3b663ea96c

@ -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.ErpStockOutDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutItemDO; 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.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.enums.ErpStockOutStatusEnum;
import cn.iocoder.yudao.module.erp.service.mold.MoldBrandService; import cn.iocoder.yudao.module.erp.service.mold.MoldBrandService;
import cn.iocoder.yudao.module.erp.service.mold.MoldService; import cn.iocoder.yudao.module.erp.service.mold.MoldService;
@ -81,6 +82,8 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.
@Validated @Validated
public class ErpStockOutController { public class ErpStockOutController {
private static final List<Integer> LOCKED_STOCK_OUT_STATUSES = java.util.Arrays.asList(10, 0, 1);
@Resource @Resource
private ErpStockOutService stockOutService; private ErpStockOutService stockOutService;
@Resource @Resource
@ -97,6 +100,8 @@ public class ErpStockOutController {
private ErpPalletService palletService; private ErpPalletService palletService;
@Resource @Resource
private AdminUserApi adminUserApi; private AdminUserApi adminUserApi;
@Resource
private ErpStockOutItemMapper stockOutItemMapper;
@PostMapping("/create") @PostMapping("/create")
@Operation(summary = "创建其它出库单") @Operation(summary = "创建其它出库单")
@ -177,9 +182,11 @@ public class ErpStockOutController {
if (stockOut == null) { if (stockOut == null) {
return success(null); return success(null);
} }
return success(buildStockOutRespVO(stockOut, ErpStockOutRespVO stockOutVO = buildStockOutRespVO(stockOut,
stockOutService.getStockOutItemListByOutId(id), stockOutService.getStockOutItemListByOutId(id),
stockOutService.getStockOutApproveRecordList(id))); stockOutService.getStockOutApproveRecordList(id));
fillLockedStockCount(stockOutVO.getItems());
return success(stockOutVO);
} }
@GetMapping("/page") @GetMapping("/page")
@ -424,6 +431,22 @@ public class ErpStockOutController {
return value != null ? value : BigDecimal.ZERO; return value != null ? value : BigDecimal.ZERO;
} }
private void fillLockedStockCount(List<ErpStockOutRespVO.Item> 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) { private String buildStockKey(Long productId, Long warehouseId, Long areaId) {
return String.valueOf(productId) + "_" + String.valueOf(warehouseId) + "_" + String.valueOf(areaId); return String.valueOf(productId) + "_" + String.valueOf(warehouseId) + "_" + String.valueOf(areaId);
} }

@ -259,6 +259,9 @@ public class ErpStockOutRespVO {
@Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") @Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
private BigDecimal stockCount; private BigDecimal stockCount;
@Schema(description = "锁定库存数量", example = "10.00")
private BigDecimal lockedStockCount;
@Schema(description = "托盘列表") @Schema(description = "托盘列表")
private List<PalletItem> pallets; private List<PalletItem> pallets;

@ -153,8 +153,9 @@ public class DeviceLineController {
@PreAuthorize("@ss.hasPermission('iot:device:query')") @PreAuthorize("@ss.hasPermission('iot:device:query')")
public CommonResult<List<LineAnalysisTreeDTO.LineNode>> deviceParameterAnalysis( public CommonResult<List<LineAnalysisTreeDTO.LineNode>> deviceParameterAnalysis(
@RequestParam(value = "keyword", required = false) String keyword, @RequestParam(value = "keyword", required = false) String keyword,
@RequestParam(value = "showDevices") Integer showDevices) { @RequestParam(value = "showDevices") Integer showDevices,
return success(deviceLineService.deviceParameterAnalysis(keyword, showDevices)); @RequestParam(value = "filterNoDeviceLine", required = false) Integer filterNoDeviceLine) {
return success(deviceLineService.deviceParameterAnalysis(keyword, showDevices, filterNoDeviceLine));
} }
@GetMapping("/children") @GetMapping("/children")

@ -12,7 +12,7 @@ public enum PlanStatusEnum {
(2), (2),
(3), (3),
//旧完工- //旧完工-
// 完工(4), // 完工(4),
(5), (5),
(6), (6),

@ -36,7 +36,7 @@ public interface DeviceLineService {
List<DeviceLineDO> getAncestorDeviceLines(Long id); List<DeviceLineDO> getAncestorDeviceLines(Long id);
List<LineAnalysisTreeDTO.LineNode> deviceParameterAnalysis(String keyword, Integer showDevices); List<LineAnalysisTreeDTO.LineNode> deviceParameterAnalysis(String keyword, Integer showDevices, Integer filterNoDeviceLine);
void regenerateCode(Long id, String code) throws UnsupportedEncodingException; void regenerateCode(Long id, String code) throws UnsupportedEncodingException;

@ -229,11 +229,12 @@ public class DeviceLineServiceImpl implements DeviceLineService {
} }
@Override @Override
public List<LineAnalysisTreeDTO.LineNode> deviceParameterAnalysis(String keyword, Integer showDevices) { public List<LineAnalysisTreeDTO.LineNode> deviceParameterAnalysis(String keyword, Integer showDevices, Integer filterNoDeviceLine) {
if (showDevices == null || (showDevices != 1 && showDevices != 2)) { if (showDevices == null || (showDevices != 1 && showDevices != 2)) {
showDevices = 1; showDevices = 1;
} }
boolean needShowDevices = showDevices == 1; boolean needShowDevices = showDevices == 1;
boolean needFilterNoDeviceLine = filterNoDeviceLine != null && filterNoDeviceLine == 1;
boolean hasKeyword = StringUtils.isNotBlank(keyword); boolean hasKeyword = StringUtils.isNotBlank(keyword);
String lowerKeyword = hasKeyword ? keyword.toLowerCase() : null; String lowerKeyword = hasKeyword ? keyword.toLowerCase() : null;
@ -274,10 +275,21 @@ public class DeviceLineServiceImpl implements DeviceLineService {
.filter(item -> item.getDeviceLine() != null) .filter(item -> item.getDeviceLine() != null)
.collect(Collectors.groupingBy(item -> item.getDeviceLine().longValue())); .collect(Collectors.groupingBy(item -> item.getDeviceLine().longValue()));
Set<Long> validDeviceIds = deviceMap.keySet();
Set<Long> lineIdsWithDevice = ledgers.stream()
.filter(item -> item.getDeviceLine() != null)
.filter(item -> validDeviceIds.contains(item.getDvId()))
.map(item -> item.getDeviceLine().longValue())
.collect(Collectors.toSet());
Map<Long, List<DeviceLineDO>> childrenByParentId = deviceLines.stream() Map<Long, List<DeviceLineDO>> childrenByParentId = deviceLines.stream()
.filter(item -> item.getParentId() != null && item.getParentId() != 0L) .filter(item -> item.getParentId() != null && item.getParentId() != 0L)
.collect(Collectors.groupingBy(DeviceLineDO::getParentId)); .collect(Collectors.groupingBy(DeviceLineDO::getParentId));
Map<Long, DeviceLineDO> deviceLineMap = deviceLines.stream()
.collect(Collectors.toMap(DeviceLineDO::getId, Function.identity(), (a, b) -> a));
Set<Long> lineIdsWithDeviceOrAncestor = buildLineIdsWithDeviceOrAncestor(lineIdsWithDevice, deviceLineMap);
Set<Long> matchedNodeIds = new HashSet<>(); Set<Long> matchedNodeIds = new HashSet<>();
if (hasKeyword) { if (hasKeyword) {
for (DeviceLineDO line : deviceLines) { for (DeviceLineDO line : deviceLines) {
@ -294,8 +306,27 @@ public class DeviceLineServiceImpl implements DeviceLineService {
matchedNodeIds.addAll(deviceLines.stream().map(DeviceLineDO::getId).collect(Collectors.toSet())); matchedNodeIds.addAll(deviceLines.stream().map(DeviceLineDO::getId).collect(Collectors.toSet()));
} }
return buildDeviceLineAnalysisTree(deviceLines, matchedNodeIds, ledgersByLineId, deviceMap, return buildDeviceLineAnalysisTree(deviceLines, matchedNodeIds, lineIdsWithDeviceOrAncestor, ledgersByLineId, deviceMap,
paramsByDeviceId, needShowDevices, hasKeyword, lowerKeyword); paramsByDeviceId, needShowDevices, needFilterNoDeviceLine, hasKeyword, lowerKeyword);
}
private Set<Long> buildLineIdsWithDeviceOrAncestor(Set<Long> lineIdsWithDevice,
Map<Long, DeviceLineDO> deviceLineMap) {
Set<Long> result = new HashSet<>(lineIdsWithDevice);
for (Long lineId : lineIdsWithDevice) {
DeviceLineDO current = deviceLineMap.get(lineId);
Long parentId = current == null ? null : current.getParentId();
Set<Long> 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, private boolean isDeviceLineAnalysisMatched(DeviceLineDO line,
@ -365,10 +396,12 @@ public class DeviceLineServiceImpl implements DeviceLineService {
private List<LineAnalysisTreeDTO.LineNode> buildDeviceLineAnalysisTree( private List<LineAnalysisTreeDTO.LineNode> buildDeviceLineAnalysisTree(
List<DeviceLineDO> deviceLines, List<DeviceLineDO> deviceLines,
Set<Long> matchedNodeIds, Set<Long> matchedNodeIds,
Set<Long> lineIdsWithDeviceOrAncestor,
Map<Long, List<DeviceLedgerDO>> ledgersByLineId, Map<Long, List<DeviceLedgerDO>> ledgersByLineId,
Map<Long, DeviceDO> deviceMap, Map<Long, DeviceDO> deviceMap,
Map<Long, List<DeviceContactModelDO>> paramsByDeviceId, Map<Long, List<DeviceContactModelDO>> paramsByDeviceId,
boolean needShowDevices, boolean needShowDevices,
boolean needFilterNoDeviceLine,
boolean hasKeyword, boolean hasKeyword,
String lowerKeyword) { String lowerKeyword) {
@ -377,6 +410,9 @@ public class DeviceLineServiceImpl implements DeviceLineService {
if (!matchedNodeIds.contains(line.getId())) { if (!matchedNodeIds.contains(line.getId())) {
continue; continue;
} }
if (needFilterNoDeviceLine && !lineIdsWithDeviceOrAncestor.contains(line.getId())) {
continue;
}
nodeMap.put(line.getId(), LineAnalysisTreeDTO.LineNode.builder() nodeMap.put(line.getId(), LineAnalysisTreeDTO.LineNode.builder()
.id(line.getId()) .id(line.getId())
.name(line.getName()) .name(line.getName())

@ -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.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 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.iot.controller.admin.device.enums.JavaToTdengineTypeEnum;
import cn.iocoder.yudao.module.mes.controller.admin.energydevice.vo.HourEnergyValueVO; import cn.iocoder.yudao.module.mes.controller.admin.energydevice.vo.HourEnergyValueVO;
import cn.iocoder.yudao.module.iot.dal.dataobject.devicecontactmodel.DeviceContactModelDO; 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.dataobject.energydevice.EnergyDeviceDO;
import cn.iocoder.yudao.module.mes.dal.mysql.energydevice.EnergyDeviceCheckRecordMapper; 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.mysql.energydevice.EnergyDeviceMapper;
import cn.iocoder.yudao.module.mes.dal.redis.no.MesNoRedisDAO;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
@ -58,7 +58,7 @@ public class EnergyDeviceServiceImpl implements EnergyDeviceService {
@Resource @Resource
private EnergyDeviceCheckRecordMapper energyDeviceCheckRecordMapper; private EnergyDeviceCheckRecordMapper energyDeviceCheckRecordMapper;
@Resource @Resource
private MesNoRedisDAO noRedisDAO; private AutoCodeUtil autoCodeUtil;
@Resource @Resource
private TDengineService tDengineService; private TDengineService tDengineService;
@Resource @Resource
@ -68,15 +68,12 @@ public class EnergyDeviceServiceImpl implements EnergyDeviceService {
public Long createEnergyDevice(EnergyDeviceSaveReqVO createReqVO) { public Long createEnergyDevice(EnergyDeviceSaveReqVO createReqVO) {
// 插入 // 插入
EnergyDeviceDO energyDevice = BeanUtils.toBean(createReqVO, EnergyDeviceDO.class); EnergyDeviceDO energyDevice = BeanUtils.toBean(createReqVO, EnergyDeviceDO.class);
if (StringUtils.isEmpty(energyDevice.getCode())) { // 验证是否唯一编码;未填写时自动生成
// 1.4 生成编号 if (StringUtils.isBlank(createReqVO.getCode())) {
String no = noRedisDAO.generate2(MesNoRedisDAO.ENERGY_NO_PREFIX); energyDevice.setCode(autoCodeUtil.genSerialCode("ENERGY_CONSUMPTION_CODE", null));
energyDevice.setCode(no); } else {
}
// 校验编码是否唯一
if (StringUtils.isNotEmpty(energyDevice.getCode())) {
List<EnergyDeviceDO> existingDevice = energyDeviceMapper.selectList( List<EnergyDeviceDO> existingDevice = energyDeviceMapper.selectList(
Wrappers.<EnergyDeviceDO>lambdaQuery().eq(EnergyDeviceDO::getCode,createReqVO.getCode())); Wrappers.<EnergyDeviceDO>lambdaQuery().eq(EnergyDeviceDO::getCode, createReqVO.getCode()));
if (!existingDevice.isEmpty()) { if (!existingDevice.isEmpty()) {
throw exception(ENERGY_DEVICE_CODE_DUPLICATE); throw exception(ENERGY_DEVICE_CODE_DUPLICATE);
} }

Loading…
Cancel
Save