ソースを参照

feat(sparepart): 完善备件信息导入的数据校验和类别处理

- 新增备件名称、规格型号、计量单位的必填校验
- 将备件类别编码校验改为必填并完善类别存在性检查
- 在新增和编辑操作中统一写入 parent_type_id 避免类别显示为空
- 优化类别匹配逻辑并保持与新增表单的一致性
dazhaxie 2 日 前
コミット
6d9572e3aa

BIN
platform-rest/src/main/resources/templates/备件导入模板.xlsx


+ 28 - 13
platform-service/src/main/java/com/platform/service/sqarepartmanage/impl/SparePartInfoServiceImpl.java

@@ -1200,6 +1200,16 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
                     if (StringUtils.isBlank(item.getNo())) {
                         throw new BusinessException("第" + lineNum + "行,备件编码不可为空");
                     }
+                    // 必填校验:与新增表单、导入模板保持一致(备件名称、规格型号、计量单位、备件类别编码)
+                    if (StringUtils.isBlank(item.getName())) {
+                        throw new BusinessException("第" + lineNum + "行,备件名称不可为空");
+                    }
+                    if (StringUtils.isBlank(item.getGgxh())) {
+                        throw new BusinessException("第" + lineNum + "行,规格型号不可为空");
+                    }
+                    if (StringUtils.isBlank(item.getUnit())) {
+                        throw new BusinessException("第" + lineNum + "行,计量单位不可为空");
+                    }
                     boolean itemExist = false;
                     for (SparePartInfo oldItem : oldList) {
                         if (item.getNo().trim().equals(oldItem.getNo())) {
@@ -1233,21 +1243,24 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
                         }
                         sparePartInfo.setLevel(level);
                     }
-                    // 判断类别
-                    if (StringUtils.isNotBlank(item.getTypeId())) {
-                        boolean isExist = false;
-                        for (SpareType spareType : spareTypeList) {
-                            if (spareType.getNo() != null && spareType.getNo().equals(item.getTypeId().trim())) {
-                                isExist = true;
-                                sparePartInfo.setTypeId(spareType.getId());
-                                break;
-                            }
-                        }
-                        if (!isExist) {
-                            throw new BusinessException(
-                                    "第" + lineNum + "行的备件类别编码【" + item.getTypeId() + "】,系统中不存在,请检查");
+                    // 判断类别(必填)
+                    if (StringUtils.isBlank(item.getTypeId())) {
+                        throw new BusinessException("第" + lineNum + "行,备件类别编码不可为空");
+                    }
+                    boolean typeExist = false;
+                    for (SpareType spareType : spareTypeList) {
+                        if (spareType.getNo() != null && spareType.getNo().equals(item.getTypeId().trim())) {
+                            typeExist = true;
+                            sparePartInfo.setTypeId(spareType.getId());
+                            // 与新增保持一致:同时写入 parent_type_id,避免编辑时类别显示为空
+                            sparePartInfo.setParentTypeId(spareType.getId());
+                            break;
                         }
                     }
+                    if (!typeExist) {
+                        throw new BusinessException(
+                                "第" + lineNum + "行的备件类别编码【" + item.getTypeId() + "】,系统中不存在,请检查");
+                    }
                     // 生产厂商
                     if (StringUtils.isNotBlank(item.getProducerName())) {
                         boolean isExist = false;
@@ -1453,6 +1466,8 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
                             if (spareType.getNo() != null && spareType.getNo().equals(item.getTypeId().trim())) {
                                 isExist = true;
                                 updInfo.setTypeId(spareType.getId());
+                                // 与新增保持一致:同时写入 parent_type_id,避免编辑时类别显示为空
+                                updInfo.setParentTypeId(spareType.getId());
                                 break;
                             }
                         }