From 2c678c27cbb52b46ae37a6cf01d73935313869e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E9=B9=8F=E9=A3=9E?= Date: Thu, 29 Jan 2026 16:09:01 +0800 Subject: [PATCH] =?UTF-8?q?feat(gongfu):=20=E6=B7=BB=E5=8A=A0=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=8E=A7=E5=88=B6=E5=99=A8=E5=B9=B6=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=BB=84=E4=BB=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增TestController用于初始化设备组件产品线数据 - 实现批量更新设备组件的产品线信息功能 - 添加设备机型字段到GongfuDeviceComponent实体类 - 在SolutionMeasuresSaveRequest中增加componentId非空验证 - 实现设备组件详情的批量创建和更新逻辑 - 添加多产品线设备组件的复制处理机制 --- .../request/SolutionMeasuresSaveRequest.java | 1 + .../gongfu/controller/TestController.java | 139 ++++++++++++++++++ .../entity/GongfuDeviceComponent.java | 8 +- 3 files changed, 144 insertions(+), 4 deletions(-) create mode 100644 nflg-mobilebroken-gongfu/src/main/java/com/nflg/mobilebroken/gongfu/controller/TestController.java diff --git a/nflg-mobilebroken-common/src/main/java/com/nflg/mobilebroken/common/pojo/request/SolutionMeasuresSaveRequest.java b/nflg-mobilebroken-common/src/main/java/com/nflg/mobilebroken/common/pojo/request/SolutionMeasuresSaveRequest.java index ff937fc3..753eb457 100644 --- a/nflg-mobilebroken-common/src/main/java/com/nflg/mobilebroken/common/pojo/request/SolutionMeasuresSaveRequest.java +++ b/nflg-mobilebroken-common/src/main/java/com/nflg/mobilebroken/common/pojo/request/SolutionMeasuresSaveRequest.java @@ -41,6 +41,7 @@ public class SolutionMeasuresSaveRequest { /** * 问题部件id */ + @NotNull private Long componentId; /** diff --git a/nflg-mobilebroken-gongfu/src/main/java/com/nflg/mobilebroken/gongfu/controller/TestController.java b/nflg-mobilebroken-gongfu/src/main/java/com/nflg/mobilebroken/gongfu/controller/TestController.java new file mode 100644 index 00000000..e7512c6c --- /dev/null +++ b/nflg-mobilebroken-gongfu/src/main/java/com/nflg/mobilebroken/gongfu/controller/TestController.java @@ -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 initDeviceComponentProductLine() { + List deviceComponents = gongfuDeviceComponentService + .lambdaQuery() + .isNull(GongfuDeviceComponent::getProductLine) + .list(); + if (CollectionUtil.isEmpty(deviceComponents)) { + return ApiResult.success(); + } + List devices = gongfuDeviceService.lambdaQuery() + .select(GongfuDevice::getModelNo, GongfuDevice::getProductLine) + .eq(GongfuDevice::getDataValidState, 1) + .list(); + List forUpdate = new ArrayList<>(); + List forAdd = new ArrayList<>(); + List detailsForAdd = new ArrayList<>(); + deviceComponents.forEach(deviceComponent -> { + List 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 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 allDetails = gongfuDeviceComponentDetailService + .lambdaQuery() + .select(GongfuDeviceComponentDetail::getDeviceComponentId, GongfuDeviceComponentDetail::getModelPartName) + .list(); + List 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(); + } +} diff --git a/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/entity/GongfuDeviceComponent.java b/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/entity/GongfuDeviceComponent.java index 4e5c3cc0..c0ed6c5d 100644 --- a/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/entity/GongfuDeviceComponent.java +++ b/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/entity/GongfuDeviceComponent.java @@ -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; /** * 产品线