feat(gongfu): 添加测试控制器并完善设备组件功能
- 新增TestController用于初始化设备组件产品线数据 - 实现批量更新设备组件的产品线信息功能 - 添加设备机型字段到GongfuDeviceComponent实体类 - 在SolutionMeasuresSaveRequest中增加componentId非空验证 - 实现设备组件详情的批量创建和更新逻辑 - 添加多产品线设备组件的复制处理机制
This commit is contained in:
parent
381b9ec5f8
commit
2c678c27cb
|
|
@ -41,6 +41,7 @@ public class SolutionMeasuresSaveRequest {
|
|||
/**
|
||||
* 问题部件id
|
||||
*/
|
||||
@NotNull
|
||||
private Long componentId;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,139 @@
|
|||
package com.nflg.mobilebroken.gongfu.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.nflg.mobilebroken.common.pojo.ApiResult;
|
||||
import com.nflg.mobilebroken.common.util.AdminUserUtil;
|
||||
import com.nflg.mobilebroken.repository.entity.GongfuDevice;
|
||||
import com.nflg.mobilebroken.repository.entity.GongfuDeviceComponent;
|
||||
import com.nflg.mobilebroken.repository.entity.GongfuDeviceComponentDetail;
|
||||
import com.nflg.mobilebroken.repository.service.IGongfuDeviceComponentDetailService;
|
||||
import com.nflg.mobilebroken.repository.service.IGongfuDeviceComponentService;
|
||||
import com.nflg.mobilebroken.repository.service.IGongfuDeviceService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 测试
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/test")
|
||||
public class TestController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
private IGongfuDeviceService gongfuDeviceService;
|
||||
|
||||
@Resource
|
||||
private IGongfuDeviceComponentService gongfuDeviceComponentService;
|
||||
|
||||
@Resource
|
||||
private IGongfuDeviceComponentDetailService gongfuDeviceComponentDetailService;
|
||||
|
||||
/**
|
||||
* 初始化设备组件中的产品线数据
|
||||
*/
|
||||
@Transactional
|
||||
@GetMapping("initDeviceComponentProductLine")
|
||||
public ApiResult<Void> initDeviceComponentProductLine() {
|
||||
List<GongfuDeviceComponent> deviceComponents = gongfuDeviceComponentService
|
||||
.lambdaQuery()
|
||||
.isNull(GongfuDeviceComponent::getProductLine)
|
||||
.list();
|
||||
if (CollectionUtil.isEmpty(deviceComponents)) {
|
||||
return ApiResult.success();
|
||||
}
|
||||
List<GongfuDevice> devices = gongfuDeviceService.lambdaQuery()
|
||||
.select(GongfuDevice::getModelNo, GongfuDevice::getProductLine)
|
||||
.eq(GongfuDevice::getDataValidState, 1)
|
||||
.list();
|
||||
List<GongfuDeviceComponent> forUpdate = new ArrayList<>();
|
||||
List<GongfuDeviceComponent> forAdd = new ArrayList<>();
|
||||
List<GongfuDeviceComponentDetail> detailsForAdd = new ArrayList<>();
|
||||
deviceComponents.forEach(deviceComponent -> {
|
||||
List<GongfuDevice> ds = devices.stream()
|
||||
.filter(d -> d.getModelNo().equals(deviceComponent.getModelNo()))
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(ds)) {
|
||||
forUpdate.add(new GongfuDeviceComponent()
|
||||
.setId(deviceComponent.getId())
|
||||
.setProductLine(ds.get(0).getProductLine())
|
||||
);
|
||||
if (ds.size() > 1) {
|
||||
List<GongfuDeviceComponentDetail> details = gongfuDeviceComponentDetailService.lambdaQuery()
|
||||
.eq(GongfuDeviceComponentDetail::getDeviceComponentId, deviceComponent.getId())
|
||||
.list();
|
||||
for (int i = 1; i < ds.size(); i++) {
|
||||
String prodoctLine = ds.get(i).getProductLine();
|
||||
GongfuDeviceComponent component = deviceComponents.stream()
|
||||
.filter(dc -> StrUtil.equals(dc.getProductLine(), prodoctLine))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (Objects.isNull(component)) {
|
||||
component = forAdd.stream()
|
||||
.filter(dc -> StrUtil.equals(dc.getProductLine(), prodoctLine))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (Objects.isNull(component)) {
|
||||
component = new GongfuDeviceComponent()
|
||||
.setId(IdUtil.getSnowflakeNextId())
|
||||
.setProductLine(ds.get(i).getProductLine())
|
||||
.setComponent(deviceComponent.getComponent())
|
||||
.setEnable(deviceComponent.getEnable())
|
||||
.setCreateBy(deviceComponent.getCreateBy())
|
||||
.setCreateTime(deviceComponent.getCreateTime())
|
||||
.setUpdateBy(deviceComponent.getUpdateBy())
|
||||
.setUpdateTime(deviceComponent.getUpdateTime());
|
||||
forAdd.add(component);
|
||||
}
|
||||
}
|
||||
for (GongfuDeviceComponentDetail detail : details) {
|
||||
detailsForAdd.add(new GongfuDeviceComponentDetail()
|
||||
.setDeviceComponentId(component.getId())
|
||||
.setModelPartId(detail.getModelPartId())
|
||||
.setModelPartName(detail.getModelPartName())
|
||||
.setCreateBy(AdminUserUtil.getUserName())
|
||||
.setCreateTime(LocalDateTime.now())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
if (CollectionUtil.isNotEmpty(forUpdate)) {
|
||||
gongfuDeviceComponentService.updateBatchById(forUpdate);
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(forAdd)) {
|
||||
gongfuDeviceComponentService.saveBatch(forAdd);
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(detailsForAdd)) {
|
||||
gongfuDeviceComponentDetailService.saveBatch(detailsForAdd);
|
||||
}
|
||||
List<GongfuDeviceComponentDetail> allDetails = gongfuDeviceComponentDetailService
|
||||
.lambdaQuery()
|
||||
.select(GongfuDeviceComponentDetail::getDeviceComponentId, GongfuDeviceComponentDetail::getModelPartName)
|
||||
.list();
|
||||
List<GongfuDeviceComponent> allComponents = gongfuDeviceComponentService.lambdaQuery()
|
||||
.select(GongfuDeviceComponent::getId)
|
||||
.list();
|
||||
allComponents.forEach(component -> {
|
||||
component.setComponent(
|
||||
allDetails.stream()
|
||||
.filter(detail -> detail.getDeviceComponentId().equals(component.getId()))
|
||||
.map(GongfuDeviceComponentDetail::getModelPartName)
|
||||
.collect(Collectors.joining(","))
|
||||
);
|
||||
});
|
||||
gongfuDeviceComponentService.updateBatchById(allComponents);
|
||||
return ApiResult.success();
|
||||
}
|
||||
}
|
||||
|
|
@ -28,10 +28,10 @@ public class GongfuDeviceComponent implements Serializable {
|
|||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
|
||||
// /**
|
||||
// * 设备机型
|
||||
// */
|
||||
// private String modelNo;
|
||||
/**
|
||||
* 设备机型
|
||||
*/
|
||||
private String modelNo;
|
||||
|
||||
/**
|
||||
* 产品线
|
||||
|
|
|
|||
Loading…
Reference in New Issue