Browse Source

用户编辑-删除某个项目下的全部角色

liuyc 3 năm trước cách đây
mục cha
commit
6240d9e4e5

+ 28 - 7
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/ContractInfoController.java

@@ -22,7 +22,9 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import io.swagger.annotations.*;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import lombok.AllArgsConstructor;
+
 import javax.validation.Valid;
+
 import org.apache.commons.lang.StringUtils;
 import org.springblade.common.utils.SnowFlakeUtil;
 import org.springblade.core.log.exception.ServiceException;
@@ -350,11 +352,11 @@ public class ContractInfoController extends BladeController {
     @ApiOperationSupport(order = 14)
     @ApiOperation(value = "逻辑删除", notes = "传入当前列表用户的记录ids")
     @Transactional(rollbackFor = Exception.class)
-    public R removeUsersByIds(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
+    public R removeUsersByIds(@ApiParam(value = "主键id集合", required = true) @RequestParam String ids) {
         if (StringUtils.isEmpty(ids)) {
             throw new ServiceException("请选择要删除的用户");
         }
-        if (Func.toLongList(ids).size() > 1) {//批量删除
+        if (Func.toLongList(ids).size() > 1) {//批量删除-合同段分配人员的全部删除按钮
             List<Long> idsList = Func.toLongList(ids);
             return R.status(saveUserInfoByProjectService.deleteBatchByIdsList(idsList));
         } else {//单删除
@@ -367,11 +369,29 @@ public class ContractInfoController extends BladeController {
         }
     }
 
+    /**
+     * 项目分配用户逻辑删除当前项目下所有合同段角色信息
+     */
+    @PostMapping("/removeUserProjectInfoAndRoleById")
+    @ApiOperationSupport(order = 14)
+    @ApiOperation(value = "逻辑删除当前项目下所有合同段角色信息", notes = "传入dataInfo内的id")
+    public R removeUserProjectInfoAndRoleById(@ApiParam(value = "主键id", required = true) @RequestParam String id) {
+        if (StringUtils.isEmpty(id)) {
+            throw new ServiceException("请选择要删除的数据");
+        }
+        boolean b = saveUserInfoByProjectService.removeUserProjectInfoAndRoleById(id);
+        if (b) {
+            return R.success("删除成功");
+        }
+        return R.fail(200, "删除失败");
+    }
+
+
     /**
      * 重置密码
      */
     @PostMapping("/resetPasswordByUserId")
-    @ApiOperationSupport(order = 15)
+    @ApiOperationSupport(order = 16)
     @ApiOperation(value = "重置密码", notes = "传入当前用户的userId,默认重置密码123456")
     public R updatePasswordByUserId(@ApiParam(value = "用户userId", required = true) @RequestParam String userId) {
         if (StringUtils.isNotEmpty(userId)) {
@@ -385,7 +405,7 @@ public class ContractInfoController extends BladeController {
      * 分配合同段wbs节点树保存或者修改
      */
     @PostMapping("/submitWbsTreeInContract")
-    @ApiOperationSupport(order = 16)
+    @ApiOperationSupport(order = 17)
     @ApiOperation(value = "分配合同段wbs节点树保存或修改", notes = "传入ids,wbsId,项目id,合同段id")
     public R submitWbsTreeInContract(@RequestBody WbsTreeContractDTO wbsTreeContractDTO) {
         boolean b = wbsTreeContractService.submitWbsTreeInContract(wbsTreeContractDTO);
@@ -399,7 +419,7 @@ public class ContractInfoController extends BladeController {
      * 查询合同段私有Wbs节点树形结构
      */
     @GetMapping("/tree")
-    @ApiOperationSupport(order = 17)
+    @ApiOperationSupport(order = 18)
     @ApiOperation(value = "查询合同段私有Wbs节点树形结构", notes = "传入wbsId,项目id,合同段id")
     @ApiImplicitParams(value = {
             @ApiImplicitParam(name = "wbsId", value = "wbsId", required = true),
@@ -419,7 +439,7 @@ public class ContractInfoController extends BladeController {
      * 查询所有施工合同wbs树根节点(新建监理或业主合同段时,加载当前项目下的施工WBS树,分配时使用)
      */
     @GetMapping("/treeAllConstruction")
-    @ApiOperationSupport(order = 18)
+    @ApiOperationSupport(order = 19)
     @ApiOperation(value = "查询所有施工合同wbs树根节点", notes = "传入wbsId,项目id")
     @ApiImplicitParams(value = {
             @ApiImplicitParam(name = "项目id", value = "projectId", required = true)
@@ -437,7 +457,7 @@ public class ContractInfoController extends BladeController {
      * 懒加载合同wbs节点树形结构
      */
     @GetMapping("/lazy-tree")
-    @ApiOperationSupport(order = 19)
+    @ApiOperationSupport(order = 20)
     @ApiOperation(value = "懒加载合同段wbs节点树形结构", notes = "传入wbsId,parentId,请求头token")
     @ApiImplicitParams(value = {
             @ApiImplicitParam(name = "parentId", value = "父级parentId = primaryKeyId , 根节点=0", required = true),
@@ -456,4 +476,5 @@ public class ContractInfoController extends BladeController {
         return R.fail(200, "未查询到信息");
     }
 
+
 }

+ 2 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/SaveUserInfoByProjectMapper.java

@@ -18,4 +18,6 @@ public interface SaveUserInfoByProjectMapper extends BaseMapper<SaveUserInfoByPr
     List<SaveUserInfoByProjectDTO> selectByIds(@Param("idsList") List<Long> idsList);
 
     int deleteByIds(@Param("idsList") List<Long> idsList);
+
+    int updateUserRoleIdById(String roleIds, String userId);
 }

+ 4 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/SaveUserInfoByProjectMapper.xml

@@ -34,6 +34,10 @@
         </foreach>
     </update>
 
+    <update id="updateUserRoleIdById">
+        UPDATE blade_user SET role_id = #{roleIds} WHERE id = #{userId}
+    </update>
+
     <select id="findMaintenanceUser" resultMap="queryUserMap">
         select
           bu.id,

+ 1 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/service/SaveUserInfoByProjectService.java

@@ -19,4 +19,5 @@ public interface SaveUserInfoByProjectService extends BaseService<SaveUserInfoBy
 
     boolean deleteBatchByIdsList(List<Long> idsList);
 
+    boolean removeUserProjectInfoAndRoleById(String id);
 }

+ 61 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/SaveUserInfoByProjectServiceImpl.java

@@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import lombok.AllArgsConstructor;
 import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.mp.base.BaseServiceImpl;
+import org.springblade.core.tool.utils.Func;
 import org.springblade.manager.dto.SaveUserInfoByProjectDTO;
+import org.springblade.manager.entity.SaveUserInfoByProject;
 import org.springblade.manager.mapper.SaveUserInfoByProjectMapper;
 import org.springblade.manager.service.SaveUserInfoByProjectService;
 import org.springblade.system.user.entity.User;
@@ -12,6 +14,8 @@ import org.springblade.system.user.feign.IUserClient;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.lang.reflect.Array;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -70,4 +74,61 @@ public class SaveUserInfoByProjectServiceImpl
         }
         return true;
     }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean removeUserProjectInfoAndRoleById(String id) {
+        //获取当前项目id
+        SaveUserInfoByProjectDTO saveUserInfoByProjectDTO = baseMapper.selectById(id);
+        String projectId = saveUserInfoByProjectDTO.getProjectId();
+        String userId = saveUserInfoByProjectDTO.getUserId();
+
+        //获取当前用户所绑定的所有项目角色信息
+        List<SaveUserInfoByProjectDTO> list1 = baseMapper.selectList(Wrappers.<SaveUserInfoByProjectDTO>query().lambda()
+                .eq(SaveUserInfoByProjectDTO::getUserId, userId)
+        );
+
+        //获取当前用户其他项目信息List
+        List<SaveUserInfoByProjectDTO> list2 = list1.stream().filter(f -> !f.getProjectId().equals(projectId) && f.getUserId().equals(userId)).collect(Collectors.toList());
+        List<String> roleIdListAllOther = list2.stream().map(SaveUserInfoByProjectDTO::getRoleId).collect(Collectors.toList());
+
+        //获取当前用户选择删除的项目下所有信息List
+        List<SaveUserInfoByProjectDTO> list3 = list1.stream().filter(f -> f.getProjectId().equals(projectId) && f.getUserId().equals(userId)).collect(Collectors.toList());
+        List<String> roleIdListCurrent = list3.stream().map(SaveUserInfoByProjectDTO::getRoleId).collect(Collectors.toList());
+
+        //需要保存的roleId
+        List<String> saveRoleIdListReally = new ArrayList<>();
+        for (String s : roleIdListAllOther) {
+            for (String s1 : roleIdListCurrent) {
+                if (s1.equals(s)) { //需要保留
+                    saveRoleIdListReally.add(s);
+                }
+            }
+        }
+        roleIdListAllOther.addAll(saveRoleIdListReally);
+        //去重
+        List<String> resultRoleIds = roleIdListAllOther.stream().distinct().collect(Collectors.toList());
+
+        //删除关系表中对应的项目信息数据
+        int row = baseMapper.delete(Wrappers.<SaveUserInfoByProjectDTO>update().lambda()
+                .eq(SaveUserInfoByProjectDTO::getProjectId, projectId)
+                .eq(SaveUserInfoByProjectDTO::getUserId, userId)
+        );
+
+        //删除用户roleId
+        boolean result = this.updateUserRoleIdFour(resultRoleIds, userId);
+        return row > 0 && result;
+
+    }
+
+    private boolean updateUserRoleIdFour(List<String> saveRoleIdListReally, String userId) {
+        StringBuilder stringBuilder = new StringBuilder();
+        for (String s : saveRoleIdListReally) {
+            stringBuilder.append(s).append(",");
+        }
+        String roleIds = stringBuilder.substring(0, stringBuilder.length() - 1);
+        int row = baseMapper.updateUserRoleIdById(roleIds, userId);
+        return row > 0;
+    }
+
 }