Jelajahi Sumber

feat: fta: 批量删除功能添加

张雨 4 bulan lalu
induk
melakukan
f865d076ef

+ 2 - 0
nationrel-module-fta-api/src/main/java/com/nationrel/modules/fta/entity/FtaProject.java

@@ -1,6 +1,7 @@
 package com.nationrel.modules.fta.entity;
 
 import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.v3.oas.annotations.media.Schema;
@@ -31,6 +32,7 @@ public class FtaProject {
     @Schema(description = "描述")
     private String description;
 
+    @TableLogic
     @Schema(description = "删除状态")
     private String delFlag;
 

+ 12 - 0
nationrel-module-fta-biz/src/main/java/com/nationrel/modules/fta/controller/FtaProjectController.java

@@ -14,7 +14,10 @@ import io.swagger.v3.oas.annotations.tags.Tag;
 import jakarta.servlet.http.HttpServletRequest;
 import lombok.RequiredArgsConstructor;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.aspect.annotation.AutoLog;
+import org.jeecg.config.i18n.MessageUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
@@ -89,4 +92,13 @@ public class FtaProjectController {
         return analysisService.deleteAnalysisInfo(userInfo, ftaId);
     }
 
+    @AutoLog(value = "项目信息-批量删除")
+    @Operation(summary = "项目信息-批量删除")
+    @RequiresPermissions("fta:fta_project:deleteBatch")
+    @DeleteMapping(value = "/deleteBatch")
+    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids, HttpServletRequest request) {
+        analysisService.deleteBatch(ids, GlobalExceptionHandler.parseUserInfo());
+        return Result.OK(MessageUtils.get("nationrel_delete_batch_success"));
+    }
+
 }

+ 22 - 0
nationrel-module-fta-biz/src/main/java/com/nationrel/modules/fta/service/FtaProjectService.java

@@ -1,6 +1,7 @@
 // Copyright(c) 2021 ReliaQube. All rights reserved.
 package com.nationrel.modules.fta.service;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -10,6 +11,7 @@ import com.nationrel.modules.fta.entity.FtaProject;
 import com.nationrel.modules.fta.general.domain.auth.HeaderUserInfo;
 import com.nationrel.modules.fta.general.domain.enums.fta.FtaParamDataExceptionEnum;
 import com.nationrel.modules.fta.general.util.common.BasicDataUtil;
+import com.nationrel.modules.fta.mapper.FtaAnalysisMapper;
 import com.nationrel.modules.fta.mapper.FtaProjectMapper;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -19,7 +21,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.Arrays;
 import java.util.Date;
+import java.util.List;
 import java.util.Objects;
 
 @Slf4j
@@ -29,6 +33,7 @@ public class FtaProjectService {
 
     private final FtaProjectMapper ftaProjectMapper;
     private final FtaAnalysisService analysisService;
+    private final FtaAnalysisMapper analysisMapper;
 
     /**
      * 分页查询
@@ -134,5 +139,22 @@ public class FtaProjectService {
         }
         return Result.ok();
     }
+
+    /**
+     * 批量逻辑删除逻辑
+     *
+     * @param ids
+     * @param userInfo
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public void deleteBatch(String ids, HeaderUserInfo userInfo) {
+        List<String> idList = Arrays.asList(ids.split(","));
+
+        // 逻辑删除子表
+        List<FtaAnalysis> analysisList = analysisMapper.selectList(new LambdaQueryWrapper<FtaAnalysis>().in(FtaAnalysis::getProjectId, idList));
+        analysisList.forEach(analysis -> analysisService.deleteAnalysis(analysis.getAnalysisId(), userInfo));
+        // 逻辑删除主表
+        ftaProjectMapper.deleteBatchIds(idList);
+    }
 }