|
|
|
|
@ -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
|
|
|
|
|
|