瀏覽代碼

机型机号 导入

wanggaokun 11 月之前
父節點
當前提交
45028f1ebd

+ 14 - 4
als-modules/agile-assurance/src/main/java/org/eco/als/domain/vo/AircraftImportVo.java

@@ -1,5 +1,6 @@
 package org.eco.als.domain.vo;
 
+import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
 import com.alibaba.excel.annotation.ExcelProperty;
 import lombok.Data;
 import lombok.NoArgsConstructor;
@@ -16,6 +17,7 @@ import java.io.Serializable;
 
 @Data
 @NoArgsConstructor
+@ExcelIgnoreUnannotated
 public class AircraftImportVo implements Serializable {
 
     @Serial
@@ -26,15 +28,23 @@ public class AircraftImportVo implements Serializable {
     /**
      * 机型Id
      */
-    @ExcelProperty(value = "机型Id")
     private String parentId;
 
+    /**
+     * 机型Id
+     */
+    @ExcelProperty(value = "父级名称" )
+    private String parentName;
+
     /**
      * 机型/机号
      */
-    @ExcelProperty(value = "机型/机号")
+    @ExcelProperty(value = "机型/机号" )
     private String name;
 
-
-
+    /**
+     * 显示顺序
+     */
+    @ExcelProperty(value = "显示顺序")
+    private Integer orderNum;
 }

+ 0 - 6
als-modules/agile-assurance/src/main/java/org/eco/als/domain/vo/AircraftVo.java

@@ -28,18 +28,12 @@ public class AircraftVo extends TreeEntity implements Serializable {
     private static final long serialVersionUID = 1L;
 
     /** 编号 */
-    @ExcelProperty(value = "编号")
     private Long id;
 
     /** 机型/机号 */
     @ExcelProperty(value = "机型/机号")
     private String name;
 
-    /** 删除标识(1删除 0未删除) */
-    @ExcelProperty(value = "删除标识(1删除 0未删除)")
-    private Integer delFlag;
-
-
     /**
      * 创建人名称
      */

+ 15 - 11
als-modules/agile-assurance/src/main/java/org/eco/als/listener/AircraftImportListener.java

@@ -1,9 +1,12 @@
 package org.eco.als.listener;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.excel.context.AnalysisContext;
 import com.alibaba.excel.event.AnalysisEventListener;
+import com.mybatisflex.core.query.QueryWrapper;
+import com.mybatisflex.core.util.LambdaGetter;
 import lombok.extern.slf4j.Slf4j;
 import org.eco.als.domain.bo.AircraftBo;
 import org.eco.als.domain.vo.AircraftImportVo;
@@ -18,6 +21,8 @@ import org.eco.common.excel.entity.ExcelResultRes;
 
 import java.util.List;
 
+import static org.eco.als.domain.table.AircraftTableDef.AIRCRAFT;
+
 /**
  * 机型机号自定义导入
  *
@@ -43,41 +48,40 @@ public class AircraftImportListener extends AnalysisEventListener<AircraftImport
     @Override
     public void invoke(AircraftImportVo aircraftVo, AnalysisContext context) {
         try {
-
             AircraftBo aircraftBo = BeanUtil.toBean(aircraftVo, AircraftBo.class);
-
             //TODO:根据某个字段,查询数据库表中是否存在记录,不存在就新增,存在就更新
             AircraftVo aircraftVo1 = null;
-
             aircraftVo1 = aircraftService.selectById(aircraftVo.getId());
-            if (ObjectUtil.isNull(aircraftVo1)) {
+            QueryWrapper queryWrapper = QueryWrapper.create();
+            queryWrapper.where("name = ?", aircraftBo.getName());
+            queryWrapper.and("parent_name = ?", aircraftBo.getParentName());
+            AircraftVo aircraftVo2 =  aircraftService.getOneAs(queryWrapper ,AircraftVo.class);
+            AircraftVo pAircraftVo = aircraftService.selectByName(aircraftBo.getParentName());
+            if (ObjectUtil.isNull(aircraftVo2)) {
                 //不存在就新增
                 aircraftBo.setVersion(0);
+                aircraftBo.setTenantId(loginUser.getTenantId());
+                aircraftBo.setParentId(ObjectUtil.isNull(pAircraftVo) ? 0 : pAircraftVo.getId());
+                aircraftBo.setParentName(ObjectUtil.isNull(pAircraftVo) ? "" : pAircraftVo.getName());
                 ValidatorUtils.validate(aircraftBo);
-                boolean inserted = aircraftService.insertWithPk(aircraftBo);//树表需要前台传来主键值
-
+                boolean inserted = aircraftService.insert(aircraftBo);//树表需要前台传来主键值
                 if (inserted) {
                     successNum++;
                     successMsg.append("<br/>").append(successNum).append("、机型机号 记录导入成功");
-                    return;
                 } else {
                     failureNum++;
                     failureMsg.append("<br/>").append(failureNum).append("、机型机号 记录导入失败");
-                    return;
                 }
             } else if (isUpdateSupport) {
                 //存在就更新
-                aircraftBo.setId(aircraftVo1.getId());//主键
                 aircraftBo.setVersion(aircraftVo1.getVersion());
                 boolean updated = aircraftService.update(aircraftBo);
                 if (updated) {
                     successNum++;
                     successMsg.append("<br/>").append(successNum).append("、机型机号 记录更新成功");
-                    return;
                 } else {
                     failureNum++;
                     failureMsg.append("<br/>").append(failureNum).append("、机型机号 记录更新失败");
-                    return;
                 }
             }
         } catch (Exception e) {

+ 8 - 0
als-modules/agile-assurance/src/main/java/org/eco/als/service/IAircraftService.java

@@ -25,6 +25,14 @@ public interface IAircraftService extends IBaseService<Aircraft> {
      */
     AircraftVo selectById(Long id);
 
+    /**
+     * 查询机型机号
+     *
+     * @param name 机型机号
+     * @return 机型机号
+     */
+    AircraftVo selectByName(String name);
+
     /**
      * 查询机型机号列表
      *

+ 6 - 0
als-modules/agile-assurance/src/main/java/org/eco/als/service/impl/AircraftServiceImpl.java

@@ -73,6 +73,11 @@ public class AircraftServiceImpl extends BaseServiceImpl<AircraftMapper, Aircraf
 
     }
 
+    @Override
+    public AircraftVo selectByName(String name) {
+        return this.getOneAs(query().where(AIRCRAFT.NAME.eq(name)), AircraftVo.class);
+    }
+
     /**
      * 查询机型机号列表
      *
@@ -110,6 +115,7 @@ public class AircraftServiceImpl extends BaseServiceImpl<AircraftMapper, Aircraf
         Aircraft aircraft = MapstructUtils.convert(aircraftBo, Aircraft.class);
 
         //获取祖级列表字段
+        assert aircraft != null;
         Long parentId = aircraft.getParentId();
         if (parentId == 0) {
             aircraft.setAncestors("0");