|
@@ -5,10 +5,12 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.haha.common.exception.BusinessException;
|
|
import com.haha.common.exception.BusinessException;
|
|
|
|
|
+import com.haha.entity.Device;
|
|
|
import com.haha.entity.DeviceInventory;
|
|
import com.haha.entity.DeviceInventory;
|
|
|
import com.haha.entity.InventoryLog;
|
|
import com.haha.entity.InventoryLog;
|
|
|
import com.haha.entity.dto.InventoryQueryDTO;
|
|
import com.haha.entity.dto.InventoryQueryDTO;
|
|
|
import com.haha.mapper.DeviceInventoryMapper;
|
|
import com.haha.mapper.DeviceInventoryMapper;
|
|
|
|
|
+import com.haha.mapper.DeviceMapper;
|
|
|
import com.haha.service.DeviceInventoryService;
|
|
import com.haha.service.DeviceInventoryService;
|
|
|
import com.haha.service.InventoryLogService;
|
|
import com.haha.service.InventoryLogService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
@@ -35,6 +37,8 @@ public class DeviceInventoryServiceImpl extends ServiceImpl<DeviceInventoryMappe
|
|
|
|
|
|
|
|
private final InventoryLogService inventoryLogService;
|
|
private final InventoryLogService inventoryLogService;
|
|
|
|
|
|
|
|
|
|
+ private final DeviceMapper deviceMapper;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public IPage<DeviceInventory> getPage(int page, int pageSize, InventoryQueryDTO queryDTO) {
|
|
public IPage<DeviceInventory> getPage(int page, int pageSize, InventoryQueryDTO queryDTO) {
|
|
|
LambdaQueryWrapper<DeviceInventory> wrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<DeviceInventory> wrapper = new LambdaQueryWrapper<>();
|
|
@@ -57,7 +61,27 @@ public class DeviceInventoryServiceImpl extends ServiceImpl<DeviceInventoryMappe
|
|
|
// 按更新时间倒序
|
|
// 按更新时间倒序
|
|
|
wrapper.orderByDesc(DeviceInventory::getUpdateTime);
|
|
wrapper.orderByDesc(DeviceInventory::getUpdateTime);
|
|
|
|
|
|
|
|
- return page(new Page<>(page, pageSize), wrapper);
|
|
|
|
|
|
|
+ IPage<DeviceInventory> result = page(new Page<>(page, pageSize), wrapper);
|
|
|
|
|
+ fillDeviceNames(result.getRecords());
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void fillDeviceNames(List<DeviceInventory> records) {
|
|
|
|
|
+ if (records == null || records.isEmpty()) return;
|
|
|
|
|
+ List<String> ids = records.stream()
|
|
|
|
|
+ .map(DeviceInventory::getDeviceId)
|
|
|
|
|
+ .filter(id -> id != null && !id.isEmpty())
|
|
|
|
|
+ .distinct()
|
|
|
|
|
+ .collect(java.util.stream.Collectors.toList());
|
|
|
|
|
+ if (ids.isEmpty()) return;
|
|
|
|
|
+ List<Device> devices = deviceMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<Device>().in(Device::getDeviceId, ids));
|
|
|
|
|
+ if (devices == null) return;
|
|
|
|
|
+ java.util.Map<String, String> nameMap = devices.stream()
|
|
|
|
|
+ .collect(java.util.stream.Collectors.toMap(Device::getDeviceId, d -> d.getName() != null ? d.getName() : "", (a, b) -> a));
|
|
|
|
|
+ for (DeviceInventory r : records) {
|
|
|
|
|
+ r.setDeviceName(nameMap.getOrDefault(r.getDeviceId(), ""));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|