Browse Source

[update] message:1.修改控制器注释;2.角色设置bug修改

kelei 6 months ago
parent
commit
88dc8e44d1

+ 1 - 3
admin/src/main/java/com/flyer/foster/controller/AppUserController.java

@@ -4,9 +4,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 /**
- * <p>
- * 小程序用户 前端控制器
- * </p>
+ * 小程序用户
  *
  * @author flyer
  * @since 2024-05-09

+ 1 - 3
admin/src/main/java/com/flyer/foster/controller/AreaController.java

@@ -4,9 +4,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 /**
- * <p>
- * 区域 前端控制器
- * </p>
+ * 区域
  *
  * @author flyer
  * @since 2024-05-09

+ 1 - 3
admin/src/main/java/com/flyer/foster/controller/FosterRecordController.java

@@ -4,9 +4,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 /**
- * <p>
- * 领养记录 前端控制器
- * </p>
+ * 领养记录
  *
  * @author flyer
  * @since 2024-05-09

+ 1 - 3
admin/src/main/java/com/flyer/foster/controller/GardenController.java

@@ -4,9 +4,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 /**
- * <p>
- * 果园 前端控制器
- * </p>
+ * 果园
  *
  * @author flyer
  * @since 2024-05-09

+ 1 - 3
admin/src/main/java/com/flyer/foster/controller/PosterLibController.java

@@ -4,9 +4,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 /**
- * <p>
- * 海报库 前端控制器
- * </p>
+ * 海报库
  *
  * @author flyer
  * @since 2024-05-09

+ 13 - 0
admin/src/main/java/com/flyer/foster/controller/RoleController.java

@@ -2,6 +2,7 @@ package com.flyer.foster.controller;
 
 import cn.dev33.satoken.annotation.SaCheckLogin;
 import com.flyer.foster.dto.RoleAddDTO;
+import com.flyer.foster.dto.RoleUpdateDTO;
 import com.flyer.foster.service.IRoleService;
 import com.flyer.util.R;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -42,6 +43,18 @@ public class RoleController {
     }
 
     /**
+     * 修改角色
+     *
+     * @param roleId
+     * @return
+     */
+    @PutMapping("/{roleId}")
+    public R updateRole(@PathVariable Integer roleId, @RequestBody RoleUpdateDTO updateDTO) {
+        updateDTO.setRoleId(roleId);
+        return R.ok().result(iRoleService.updateRole(updateDTO));
+    }
+
+    /**
      * 删除角色
      *
      * @param roleIdList

+ 1 - 3
admin/src/main/java/com/flyer/foster/controller/TreeController.java

@@ -4,9 +4,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 /**
- * <p>
- * 树 前端控制器
- * </p>
+ * 树
  *
  * @author flyer
  * @since 2024-05-09

+ 1 - 3
admin/src/main/java/com/flyer/foster/controller/TreeImageController.java

@@ -4,9 +4,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 /**
- * <p>
- * 树照片 前端控制器
- * </p>
+ * 树照片
  *
  * @author flyer
  * @since 2024-05-09

+ 1 - 3
admin/src/main/java/com/flyer/foster/controller/TreePosterContentController.java

@@ -4,9 +4,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 /**
- * <p>
- * 果树海报悄悄话 前端控制器
- * </p>
+ * 果树海报悄悄话
  *
  * @author flyer
  * @since 2024-05-09

+ 1 - 1
admin/src/main/java/com/flyer/foster/controller/UserRoleController.java

@@ -4,7 +4,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 /**
- * 用户角色表 前端控制器
+ * 用户角色
  *
  * @author flyer
  * @since 2024-05-06

+ 1 - 3
admin/src/main/java/com/flyer/foster/controller/WhisperController.java

@@ -4,9 +4,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 /**
- * <p>
- * 悄悄话 前端控制器
- * </p>
+ * 悄悄话
  *
  * @author flyer
  * @since 2024-05-09

+ 25 - 0
admin/src/main/java/com/flyer/foster/dto/RoleUpdateDTO.java

@@ -0,0 +1,25 @@
+package com.flyer.foster.dto;
+
+import lombok.Data;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * RoleUpdateDTO
+ *
+ * @author kelei
+ * @since 2023/3/24/14:28
+ */
+@Data
+public class RoleUpdateDTO {
+    private Integer roleId;
+
+    private String roleName;
+
+    private String roleCode;
+
+    private Integer tenantId;
+
+    private List<Integer> menuIdList = new ArrayList<>();
+}

+ 7 - 0
admin/src/main/java/com/flyer/foster/service/IRoleMenuService.java

@@ -18,4 +18,11 @@ public interface IRoleMenuService extends IService<RoleMenu> {
     boolean addRoleMenu(RoleMenuAddDTO addDTO);
 
     List<Integer> getRoleMenuIdList(Integer roleId);
+
+    /**
+     * 物理删除
+     * @param roleIdList
+     * @return
+     */
+    boolean deleteByRoleIdList(List<Integer> roleIdList);
 }

+ 3 - 0
admin/src/main/java/com/flyer/foster/service/IRoleService.java

@@ -2,6 +2,7 @@ package com.flyer.foster.service;
 
 import com.flyer.foster.dto.RoleAddDTO;
 import com.flyer.foster.dto.RoleRespDTO;
+import com.flyer.foster.dto.RoleUpdateDTO;
 import com.flyer.foster.entity.Role;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.flyer.foster.pojo.Dropdown;
@@ -21,6 +22,8 @@ public interface IRoleService extends IService<Role> {
 
     boolean addRole(RoleAddDTO addDTO);
 
+    boolean updateRole(RoleUpdateDTO updateDTO);
+
     /**
      * 删除角色
      *

+ 8 - 0
admin/src/main/java/com/flyer/foster/service/IUserRoleService.java

@@ -2,6 +2,7 @@ package com.flyer.foster.service;
 
 import com.flyer.foster.entity.UserRole;
 import com.baomidou.mybatisplus.extension.service.IService;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -20,4 +21,11 @@ public interface IUserRoleService extends IService<UserRole> {
      * @return
      */
     boolean deleteByUserIdList(List<Integer> userIdList);
+
+    /**
+     * 物理删除
+     * @param roleIdList
+     * @return
+     */
+    boolean deleteByRoleIdList(List<Integer> roleIdList);
 }

+ 9 - 2
admin/src/main/java/com/flyer/foster/service/impl/RoleMenuServiceImpl.java

@@ -9,6 +9,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -31,8 +33,8 @@ public class RoleMenuServiceImpl extends ServiceImpl<IRoleMenuMapper, RoleMenu>
         if (addDTO.getMenuIdList().size() == 0) {
             throw new BusinessException("请选择菜单");
         }
-        // 删除角色菜单
-        this.removeBatchByIds(addDTO.getMenuIdList());
+        // 物理删除菜单
+        baseMapper.deleteByRoleIdList(Collections.singletonList(addDTO.getRoleId()));
         // 添加角色菜单
         RoleMenu roleMenu;
         for (Integer menuId : addDTO.getMenuIdList()) {
@@ -48,4 +50,9 @@ public class RoleMenuServiceImpl extends ServiceImpl<IRoleMenuMapper, RoleMenu>
     public List<Integer> getRoleMenuIdList(Integer roleId) {
         return this.lambdaQuery().eq(RoleMenu::getRoleId, roleId).list().stream().map(RoleMenu::getMenuId).collect(Collectors.toList());
     }
+
+    @Override
+    public boolean deleteByRoleIdList(List<Integer> roleIdList) {
+        return baseMapper.deleteByRoleIdList(roleIdList);
+    }
 }

+ 51 - 14
admin/src/main/java/com/flyer/foster/service/impl/RoleServiceImpl.java

@@ -3,23 +3,22 @@ package com.flyer.foster.service.impl;
 import cn.dev33.satoken.stp.StpUtil;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.bean.copier.CopyOptions;
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.flyer.exception.BusinessException;
 import com.flyer.foster.dto.RoleAddDTO;
 import com.flyer.foster.dto.RoleMenuAddDTO;
 import com.flyer.foster.dto.RoleRespDTO;
+import com.flyer.foster.dto.RoleUpdateDTO;
 import com.flyer.foster.entity.Role;
 import com.flyer.foster.entity.RoleMenu;
-import com.flyer.foster.entity.UserRole;
 import com.flyer.foster.enums.IsAdminEnum;
 import com.flyer.foster.enums.StatusEnum;
 import com.flyer.foster.enums.TFEnum;
 import com.flyer.foster.mapper.IRoleMapper;
-import com.flyer.foster.mapper.IRoleMenuMapper;
-import com.flyer.foster.mapper.IUserRoleMapper;
 import com.flyer.foster.pojo.Dropdown;
 import com.flyer.foster.service.IRoleMenuService;
 import com.flyer.foster.service.IRoleService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.flyer.foster.service.IUserRoleService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -44,10 +43,7 @@ public class RoleServiceImpl extends ServiceImpl<IRoleMapper, Role> implements I
     private IRoleMenuService iRoleMenuService;
 
     @Autowired
-    private IRoleMenuMapper iRoleMenuMapper;
-
-    @Autowired
-    private IUserRoleMapper iUserRoleMapper;
+    private IUserRoleService iUserRoleService;
 
     @Override
     public List<RoleRespDTO> getRoleList() {
@@ -88,13 +84,54 @@ public class RoleServiceImpl extends ServiceImpl<IRoleMapper, Role> implements I
         role.setTenantId(tenantId);
         // 新增角色
         this.save(role);
+        // 保存角色菜单
+        RoleMenu roleMenu;
+        for (Integer menuId : addDTO.getMenuIdList()) {
+            roleMenu = new RoleMenu();
+            roleMenu.setRoleId(role.getId());
+            roleMenu.setMenuId(menuId);
+            iRoleMenuService.save(roleMenu);
+        }
+        return true;
+    }
+
+    @Transactional
+    @Override
+    public boolean updateRole(RoleUpdateDTO updateDTO) {
+        int tenantId = StpUtil.getTokenSession().getInt("tenantId");
+        Role role = this.lambdaQuery()
+                .eq(Role::getId, updateDTO.getRoleId())
+                .eq(Role::getTenantId, tenantId)
+                .one();
+        if (role == null) {
+            throw new BusinessException(StrUtil.format("无效的角色id:{}", updateDTO.getRoleId()));
+        }
 
+        // 删除菜单后新增
         RoleMenuAddDTO roleMenuAddDTO = new RoleMenuAddDTO();
-        roleMenuAddDTO.setRoleId(role.getId());
-        roleMenuAddDTO.setMenuIdList(addDTO.getMenuIdList());
-        // 保存角色菜单
+        roleMenuAddDTO.setRoleId(updateDTO.getRoleId());
+        roleMenuAddDTO.setMenuIdList(updateDTO.getMenuIdList());
         iRoleMenuService.addRoleMenu(roleMenuAddDTO);
-        return true;
+
+        // 没有修改则不作修改
+        if (role.getRoleName().equals(updateDTO.getRoleName()) && role.getRoleCode().equals(updateDTO.getRoleCode())) {
+            return true;
+        } else if (StrUtil.isBlank(updateDTO.getRoleName()) && StrUtil.isBlank(updateDTO.getRoleCode())) {
+            return true;
+        } else {
+            Role one = this.lambdaQuery()
+                    .eq(Role::getRoleName, updateDTO.getRoleName())
+                    .eq(Role::getRoleCode, updateDTO.getRoleCode())
+                    .eq(Role::getTenantId, tenantId)
+                    .ne(Role::getId, updateDTO.getRoleId())
+                    .one();
+            if (one != null) {
+                throw new BusinessException(StrUtil.format("角色名称:{}+角色编码:{}已存在", role.getRoleName(), role.getRoleCode()));
+            }
+            role.setRoleName(updateDTO.getRoleName());
+            role.setRoleCode(updateDTO.getRoleCode());
+            return this.updateById(role);
+        }
     }
 
     @Transactional
@@ -104,9 +141,9 @@ public class RoleServiceImpl extends ServiceImpl<IRoleMapper, Role> implements I
         // 物理删除角色
         baseMapper.deleteByIdList(roleIdList);
         // 物理删除角色菜单
-        iRoleMenuMapper.deleteByRoleIdList(roleIdList);
+        iRoleMenuService.deleteByRoleIdList(roleIdList);
         // 物理删除用户角色
-        iUserRoleMapper.deleteByRoleIdList(roleIdList);
+        iUserRoleService.deleteByRoleIdList(roleIdList);
         return true;
     }
 

+ 5 - 0
admin/src/main/java/com/flyer/foster/service/impl/UserRoleServiceImpl.java

@@ -23,4 +23,9 @@ public class UserRoleServiceImpl extends ServiceImpl<IUserRoleMapper, UserRole>
     public boolean deleteByUserIdList(List<Integer> userIdList) {
         return baseMapper.deleteByUserIdList(userIdList);
     }
+
+    @Override
+    public boolean deleteByRoleIdList(List<Integer> roleIdList) {
+        return baseMapper.deleteByRoleIdList(roleIdList);
+    }
 }