refactor: 重构机型部件列表接口
This commit is contained in:
parent
b3552cf4e7
commit
def8dcbfe7
|
|
@ -4,7 +4,6 @@ package com.nflg.mobilebroken.admin.controller;
|
|||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.nflg.mobilebroken.admin.annotation.ApiMark;
|
||||
|
|
@ -17,17 +16,18 @@ import com.nflg.mobilebroken.common.pojo.PageData;
|
|||
import com.nflg.mobilebroken.common.pojo.dto.DevComponentExcel;
|
||||
import com.nflg.mobilebroken.common.pojo.dto.DevComponentImportExcel;
|
||||
import com.nflg.mobilebroken.common.pojo.query.DeviceComponentQuery;
|
||||
import com.nflg.mobilebroken.common.pojo.vo.DeviceComponentDetailVO;
|
||||
import com.nflg.mobilebroken.common.pojo.vo.DeviceComponentPartGroupVO;
|
||||
import com.nflg.mobilebroken.common.pojo.vo.DeviceComponentVO;
|
||||
import com.nflg.mobilebroken.common.pojo.vo.DeviceTypeVO;
|
||||
import com.nflg.mobilebroken.common.util.AdminUserUtil;
|
||||
import com.nflg.mobilebroken.common.util.EecExcelUtil;
|
||||
import com.nflg.mobilebroken.common.util.VUtils;
|
||||
import com.nflg.mobilebroken.repository.entity.Device;
|
||||
import com.nflg.mobilebroken.repository.entity.DeviceComponent;
|
||||
import com.nflg.mobilebroken.repository.entity.DeviceComponentDetail;
|
||||
import com.nflg.mobilebroken.repository.entity.TBasePart;
|
||||
import com.nflg.mobilebroken.repository.service.IDeviceComponentDetailService;
|
||||
import com.nflg.mobilebroken.repository.service.IDeviceComponentService;
|
||||
import com.nflg.mobilebroken.repository.service.IDeviceService;
|
||||
import com.nflg.mobilebroken.repository.service.ITBasePartService;
|
||||
import com.nflg.mobilebroken.starter.annotation.MethodInfoMark;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
|
@ -42,6 +42,7 @@ import javax.validation.Valid;
|
|||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
|
@ -60,6 +61,9 @@ public class DeviceComponentController extends ControllerBase {
|
|||
@Resource
|
||||
ITBasePartService basePartService;
|
||||
|
||||
@Resource
|
||||
private IDeviceService deviceService;
|
||||
|
||||
/**
|
||||
* 获取机型部件列表
|
||||
* @param query
|
||||
|
|
@ -67,18 +71,31 @@ public class DeviceComponentController extends ControllerBase {
|
|||
*/
|
||||
@PostMapping("getList")
|
||||
@ApiMark(moduleName = "机型部件管理", apiName = "获取设备机型列表")
|
||||
public ApiResult<PageData<DeviceComponentVO>> getList(@RequestBody DeviceComponentQuery query){
|
||||
Page<DeviceComponentVO> result = deviceComponentService.selectListByPage(query);
|
||||
result.getRecords().forEach(u->{
|
||||
List<DeviceComponentDetailVO> detail = deviceComponentDetailService.getDevicePartDetail(u.getId());
|
||||
Map<String, List<DeviceComponentDetailVO>> collect=detail.stream().collect(Collectors.groupingBy(DeviceComponentDetailVO::getTypeAttr));
|
||||
List<DeviceComponentPartGroupVO> vos=new ArrayList<>();
|
||||
collect.forEach((k,v)->{
|
||||
vos.add(new DeviceComponentPartGroupVO().setTypeAttr(k).setItems(v));
|
||||
});
|
||||
u.setPartList(vos);
|
||||
public ApiResult<PageData<DeviceTypeVO>> getList(@RequestBody DeviceComponentQuery query){
|
||||
List<Device> devices=deviceService.lambdaQuery().select(Device::getDeviceType,Device::getModelNo).eq(Device::getDataValidState,true).list();
|
||||
Map<String,List<Device>> mps=devices.stream().collect(Collectors.groupingBy(Device::getDeviceType));
|
||||
AtomicInteger index= new AtomicInteger();
|
||||
int first=(query.getPage()-1)*query.getPageSize();
|
||||
int last=query.getPage()*query.getPageSize();
|
||||
PageData<DeviceTypeVO> pageData=new PageData<>();
|
||||
List<DeviceTypeVO> items=new ArrayList<>();
|
||||
mps.forEach((k,v)->{
|
||||
if (index.get() >= first && index.get() < last) {
|
||||
DeviceTypeVO vo=new DeviceTypeVO();
|
||||
vo.setDeviceType(k);
|
||||
vo.setItems(v.stream().map(d -> new DeviceComponentVO()
|
||||
.setModelNo(d.getModelNo())
|
||||
.setPartList(deviceComponentDetailService.getByModelNo(d.getModelNo()))).collect(Collectors.toList())
|
||||
);
|
||||
items.add(vo);
|
||||
}
|
||||
index.getAndIncrement();
|
||||
});
|
||||
return ApiResult.success(result.getRecords(),query,result.getTotal());
|
||||
pageData.setItems(items);
|
||||
pageData.setPage(query.getPage());
|
||||
pageData.setPageSize(query.getPageSize());
|
||||
pageData.setTotal(mps.size());
|
||||
return ApiResult.success(pageData);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4,11 +4,13 @@ package com.nflg.mobilebroken.common.pojo.vo;
|
|||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class DeviceComponentVO {
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
|
|
@ -49,5 +51,5 @@ public class DeviceComponentVO {
|
|||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
private List<DeviceComponentPartGroupVO> partList;
|
||||
private List<DeviceComponentDetailVO> partList;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,15 +7,15 @@ import java.util.List;
|
|||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class DeviceComponentPartGroupVO {
|
||||
public class DeviceTypeVO {
|
||||
|
||||
/**
|
||||
* 类别属性
|
||||
* 设备类型
|
||||
*/
|
||||
private String typeAttr;
|
||||
private String deviceType;
|
||||
|
||||
/**
|
||||
* 部件列表
|
||||
* 机型列表
|
||||
*/
|
||||
private List<DeviceComponentDetailVO> items;
|
||||
private List<DeviceComponentVO> items;
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package com.nflg.mobilebroken.repository.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nflg.mobilebroken.common.pojo.vo.DeviceComponentDetailVO;
|
||||
import com.nflg.mobilebroken.repository.entity.DeviceComponentDetail;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -22,4 +22,6 @@ public interface DeviceComponentDetailMapper extends BaseMapper<DeviceComponentD
|
|||
void batchDelByComponentId(@Param("componentIds") List<Integer> componentIds);
|
||||
|
||||
List<DeviceComponentDetailVO> getDevicePartDetail(@Param("deviceComponentId") Integer deviceComponentId);
|
||||
|
||||
List<DeviceComponentDetailVO> getByModelNo(String modelNo);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package com.nflg.mobilebroken.repository.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.nflg.mobilebroken.common.pojo.vo.DeviceComponentDetailVO;
|
||||
import com.nflg.mobilebroken.repository.entity.DeviceComponentDetail;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -23,4 +23,6 @@ public interface IDeviceComponentDetailService extends IService<DeviceComponentD
|
|||
void batchDelByComponentId(@Param("componentIds") List<Integer> componentIds);
|
||||
|
||||
List<DeviceComponentDetailVO> getDevicePartDetail(@Param("deviceComponentId") Integer deviceComponentId);
|
||||
|
||||
List<DeviceComponentDetailVO> getByModelNo(String modelNo);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package com.nflg.mobilebroken.repository.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.nflg.mobilebroken.common.pojo.vo.DeviceComponentDetailVO;
|
||||
import com.nflg.mobilebroken.repository.entity.DeviceComponentDetail;
|
||||
import com.nflg.mobilebroken.repository.mapper.DeviceComponentDetailMapper;
|
||||
import com.nflg.mobilebroken.repository.service.IDeviceComponentDetailService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
|
@ -32,4 +32,9 @@ public class DeviceComponentDetailServiceImpl extends ServiceImpl<DeviceComponen
|
|||
public List<DeviceComponentDetailVO> getDevicePartDetail(@Param("deviceComponentId") Integer deviceComponentId){
|
||||
return this.getBaseMapper().getDevicePartDetail(deviceComponentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceComponentDetailVO> getByModelNo(String modelNo) {
|
||||
return baseMapper.getByModelNo(modelNo);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,4 +19,11 @@
|
|||
join t_base_part b on a.model_part_id=b.id
|
||||
where a.device_component_id=#{deviceComponentId}
|
||||
</select>
|
||||
|
||||
<select id="getByModelNo" resultType="com.nflg.mobilebroken.common.pojo.vo.DeviceComponentDetailVO">
|
||||
SELECT dct.*
|
||||
FROM device_component dc
|
||||
INNER JOIN device_component_detail dct ON dc.id=dct.device_component_id
|
||||
WHERE dc.model_no=#{modelNo}
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue