获取设备列表
This commit is contained in:
parent
efef85c89b
commit
0187c28a91
|
|
@ -3,6 +3,7 @@ package com.nflg.mobilebroken.admin.controller;
|
|||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.nflg.mobilebroken.admin.pojo.dto.DeviceDTO;
|
||||
import com.nflg.mobilebroken.admin.pojo.query.DeviceQuery;
|
||||
import com.nflg.mobilebroken.admin.pojo.vo.DeviceDetailResultVO;
|
||||
|
|
@ -29,7 +30,10 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 设备管理
|
||||
|
|
@ -50,17 +54,48 @@ public class DeviceController extends ControllerBase {
|
|||
IDictionaryItemService dictionaryItemService;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备列表
|
||||
* @param query
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("getList")
|
||||
@MethodInfoMark(value = "获取设备列表", menuName = "设备管理")
|
||||
public ApiResult<PageData<Device>> getList(@RequestBody DeviceQuery query) {
|
||||
public ApiResult<PageData<DeviceDetailResultVO>> getList(@RequestBody DeviceQuery query) {
|
||||
Page<Device> result = deviceService.getList(new Page<>(query.getPage(), query.getPageSize()), query);
|
||||
return ApiResult.success(result.getRecords(), query, result.getTotal());
|
||||
List<DeviceDetailResultVO> resultData = Convert.toList(DeviceDetailResultVO.class, result.getRecords());
|
||||
//初始化单位名称
|
||||
if(CollUtil.isNotEmpty(result.getRecords())){
|
||||
Set<Integer> deviceStateIds = result.getRecords().stream().map(u -> u.getDeviceState()).collect(Collectors.toSet());
|
||||
Set<Integer> warrantyStateIds = result.getRecords().stream().map(u -> u.getWarrantyState()).collect(Collectors.toSet());
|
||||
Sets.SetView<Integer> stateIds = Sets.union(deviceStateIds, warrantyStateIds);
|
||||
if(CollUtil.isNotEmpty(stateIds)) {
|
||||
List<DictionaryItem> dictionaryItems = dictionaryItemService.getBaseMapper().selectByIds(stateIds);
|
||||
Map<Integer, String> stateMap = dictionaryItems.stream().collect(Collectors.toMap(DictionaryItem::getId, DictionaryItem::getName));
|
||||
resultData.forEach(u->{
|
||||
if(stateMap.containsKey(u.getDeviceState())){
|
||||
u.setDeviceStateName(stateMap.get(u.getDeviceState()));
|
||||
}
|
||||
if(stateMap.containsKey(u.getWarrantyState())){
|
||||
u.setWarrantyStateName(stateMap.get(u.getWarrantyState()));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return ApiResult.success(resultData, query, result.getTotal());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备详情
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("getDetail")
|
||||
@MethodInfoMark(value = "获取设备详情", menuName = "设备管理")
|
||||
|
||||
public ApiResult<DeviceDetailResultVO> getDetail(@RequestParam("id") Integer id) {
|
||||
Device data = deviceService.getById(id);
|
||||
DeviceDetailResultVO result = Convert.convert(DeviceDetailResultVO.class, data);
|
||||
|
|
|
|||
Loading…
Reference in New Issue