fix:添加设备台账顶级分类

main
HuangHuiKang 1 week ago
parent 75889f05cd
commit 623c14fd99

@ -47,6 +47,12 @@ public class DeviceLedgerRespVO extends BaseDO {
@Schema(description = "设备产线")
private Integer deviceLine;
@Schema(description = "顶级分类 id")
private Long topCategoryId;
@Schema(description = "顶级分类名称")
private String topCategoryName;
@Schema(description = "设备类型名称", example = "1")
@ExcelProperty("类型")
private String typeName;

@ -73,6 +73,18 @@ public class DeviceLedgerDO extends BaseDO {
* 线
*/
private Integer deviceLine;
/**
* id
*/
@TableField(exist = false)
private Long topCategoryId;
/**
*
*/
@TableField(exist = false)
private String topCategoryName;
/**
*
*/

@ -449,6 +449,8 @@ public class DeviceLedgerServiceImpl implements DeviceLedgerService {
}
List<DeviceLineDO> deviceLineList = deviceLineService.getDeviceLineList(new DeviceLineListReqVO());
Map<Long, List<DeviceLineDO>> collect = deviceLineList.stream().collect(Collectors.groupingBy(DeviceLineDO::getId));
Map<Long, DeviceLineDO> deviceLineMap = deviceLineList.stream()
.collect(Collectors.toMap(DeviceLineDO::getId, Function.identity(), (a, b) -> a));
PageResult<DeviceLedgerDO> deviceLedgerDOPageResult = deviceLedgerMapper.selectPage(pageReqVO);
for (DeviceLedgerDO deviceLedgerDO : deviceLedgerDOPageResult.getList()) {
if (deviceLedgerDO.getDeviceType()!=null){
@ -458,6 +460,7 @@ public class DeviceLedgerServiceImpl implements DeviceLedgerService {
if(deviceLedgerDO.getDeviceLine()!=null&&CollUtil.isNotEmpty(collect.get(deviceLedgerDO.getDeviceLine().longValue()))){
deviceLedgerDO.setWorkshopName(collect.get(deviceLedgerDO.getDeviceLine().longValue()).get(0).getName());
}
fillTopCategoryInfo(deviceLedgerDO, deviceLineMap);
}
return deviceLedgerDOPageResult;
}
@ -647,7 +650,69 @@ public class DeviceLedgerServiceImpl implements DeviceLedgerService {
@Override
public List<DeviceLedgerDO> getDeviceLedgerList() {
return deviceLedgerMapper.selectList();
List<DeviceLedgerDO> list = deviceLedgerMapper.selectList();
fillTopCategoryInfo(list);
return list;
}
private void fillTopCategoryInfo(List<DeviceLedgerDO> list) {
if (CollUtil.isEmpty(list)) {
return;
}
List<DeviceLineDO> deviceLineList = deviceLineService.getDeviceLineList(new DeviceLineListReqVO());
Map<Long, DeviceLineDO> deviceLineMap = deviceLineList.stream()
.collect(Collectors.toMap(DeviceLineDO::getId, Function.identity(), (a, b) -> a));
list.forEach(item -> fillTopCategoryInfo(item, deviceLineMap));
}
private void fillTopCategoryInfo(DeviceLedgerDO deviceLedgerDO, Map<Long, DeviceLineDO> deviceLineMap) {
if (deviceLedgerDO == null || deviceLedgerDO.getDeviceLine() == null || deviceLineMap == null || deviceLineMap.isEmpty()) {
return;
}
DeviceLineDO currentLine = deviceLineMap.get(deviceLedgerDO.getDeviceLine().longValue());
if (currentLine == null) {
return;
}
DeviceLineDO topLine = getTopDeviceLine(currentLine, deviceLineMap);
if (topLine == null) {
return;
}
deviceLedgerDO.setTopCategoryId(topLine.getId());
deviceLedgerDO.setTopCategoryName(topLine.getName());
}
private DeviceLineDO getTopDeviceLine(DeviceLineDO currentLine, Map<Long, DeviceLineDO> deviceLineMap) {
Long topLineId = parseTopDeviceLineId(currentLine.getParentChain());
if (topLineId != null && deviceLineMap.containsKey(topLineId)) {
return deviceLineMap.get(topLineId);
}
DeviceLineDO topLine = currentLine;
Set<Long> visitedIds = new HashSet<>();
while (topLine.getParentId() != null && topLine.getParentId() > 0 && visitedIds.add(topLine.getId())) {
DeviceLineDO parentLine = deviceLineMap.get(topLine.getParentId());
if (parentLine == null) {
break;
}
topLine = parentLine;
}
return topLine;
}
private Long parseTopDeviceLineId(String parentChain) {
if (StringUtils.isBlank(parentChain)) {
return null;
}
String[] ids = parentChain.split(",");
for (String id : ids) {
if (StringUtils.isBlank(id)) {
continue;
}
try {
return Long.valueOf(id.trim());
} catch (NumberFormatException ignored) {
}
}
return null;
}
@Override

Loading…
Cancel
Save