فهرست منبع

[update] message:1.添加用户;2.添加角色

kelei 11 ماه پیش
والد
کامیت
f1093acb56
30فایلهای تغییر یافته به همراه308 افزوده شده و 94 حذف شده
  1. 1 3
      admin/src/main/java/com/flyer/foster/controller/MenuController.java
  2. 23 3
      admin/src/main/java/com/flyer/foster/controller/RoleController.java
  3. 12 3
      admin/src/main/java/com/flyer/foster/controller/RoleMenuController.java
  4. 1 3
      admin/src/main/java/com/flyer/foster/controller/TenantController.java
  5. 10 8
      admin/src/main/java/com/flyer/foster/controller/UserController.java
  6. 0 2
      admin/src/main/java/com/flyer/foster/controller/UserRoleController.java
  7. 24 0
      admin/src/main/java/com/flyer/foster/dto/UserAddDto.java
  8. 3 5
      admin/src/main/java/com/flyer/foster/entity/Menu.java
  9. 3 5
      admin/src/main/java/com/flyer/foster/entity/Role.java
  10. 3 5
      admin/src/main/java/com/flyer/foster/entity/RoleMenu.java
  11. 3 5
      admin/src/main/java/com/flyer/foster/entity/Tenant.java
  12. 3 5
      admin/src/main/java/com/flyer/foster/entity/User.java
  13. 3 5
      admin/src/main/java/com/flyer/foster/entity/UserRole.java
  14. 4 1
      admin/src/main/java/com/flyer/foster/mapper/IRoleMapper.java
  15. 4 0
      admin/src/main/java/com/flyer/foster/mapper/IRoleMenuMapper.java
  16. 8 0
      admin/src/main/java/com/flyer/foster/mapper/IUserMapper.java
  17. 6 0
      admin/src/main/java/com/flyer/foster/mapper/IUserRoleMapper.java
  18. 24 0
      admin/src/main/java/com/flyer/foster/pojo/Dropdown.java
  19. 4 0
      admin/src/main/java/com/flyer/foster/service/IRoleMenuService.java
  20. 16 0
      admin/src/main/java/com/flyer/foster/service/IRoleService.java
  21. 8 1
      admin/src/main/java/com/flyer/foster/service/IUserRoleService.java
  22. 8 5
      admin/src/main/java/com/flyer/foster/service/IUserService.java
  23. 8 0
      admin/src/main/java/com/flyer/foster/service/impl/RoleMenuServiceImpl.java
  24. 52 2
      admin/src/main/java/com/flyer/foster/service/impl/RoleServiceImpl.java
  25. 6 0
      admin/src/main/java/com/flyer/foster/service/impl/UserRoleServiceImpl.java
  26. 40 33
      admin/src/main/java/com/flyer/foster/service/impl/UserServiceImpl.java
  27. 6 0
      admin/src/main/resources/mapper/RoleMapper.xml
  28. 6 0
      admin/src/main/resources/mapper/RoleMenuMapper.xml
  29. 6 0
      admin/src/main/resources/mapper/UserMapper.xml
  30. 13 0
      admin/src/main/resources/mapper/UserRoleMapper.xml

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

@@ -11,9 +11,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 /**
- * <p>
- * 菜单表 前端控制器
- * </p>
+ * 菜单
  *
  * @author flyer
  * @since 2024-05-06

+ 23 - 3
admin/src/main/java/com/flyer/foster/controller/RoleController.java

@@ -8,11 +8,10 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
+import java.util.List;
 
 /**
- * <p>
- * 角色表 前端控制器
- * </p>
+ * 角色
  *
  * @author flyer
  * @since 2024-05-06
@@ -41,4 +40,25 @@ public class RoleController {
     public R addRole(@Valid @RequestBody RoleAddDTO addDTO) {
         return R.ok().result(iRoleService.addRole(addDTO));
     }
+
+    /**
+     * 删除角色
+     *
+     * @param roleIdList
+     * @return
+     */
+    @PostMapping("/delete")
+    public R deleteRole(@RequestBody List<Integer> roleIdList) {
+        return R.ok().result(iRoleService.deleteRole(roleIdList));
+    }
+
+    /**
+     * 角色下拉框
+     *
+     * @return
+     */
+    @GetMapping("/dropdown-list")
+    public R getDropdownList() {
+        return R.ok().result(iRoleService.getDropdownList());
+    }
 }

+ 12 - 3
admin/src/main/java/com/flyer/foster/controller/RoleMenuController.java

@@ -1,12 +1,15 @@
 package com.flyer.foster.controller;
 
+import com.flyer.foster.service.IRoleMenuService;
+import com.flyer.util.R;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 /**
- * <p>
- * 角色菜单关系表 前端控制器
- * </p>
+ * 角色菜单
  *
  * @author flyer
  * @since 2024-05-06
@@ -14,5 +17,11 @@ import org.springframework.web.bind.annotation.RestController;
 @RestController
 @RequestMapping("/role-menu")
 public class RoleMenuController {
+    @Autowired
+    private IRoleMenuService iRoleMenuService;
 
+    @GetMapping("/{roleId}")
+    public R getRoleMenuIdList(@PathVariable Integer roleId){
+        return R.ok().result(iRoleMenuService.getRoleMenuIdList(roleId));
+    }
 }

+ 1 - 3
admin/src/main/java/com/flyer/foster/controller/TenantController.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-06

+ 10 - 8
admin/src/main/java/com/flyer/foster/controller/UserController.java

@@ -7,9 +7,8 @@ import cn.hutool.core.bean.BeanUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.flyer.foster.dto.LoginDTO;
-import com.flyer.foster.dto.UserAddOrUpdateDTO;
+import com.flyer.foster.dto.UserAddDto;
 import com.flyer.foster.dto.UserSearchDTO;
-import com.flyer.foster.entity.Tenant;
 import com.flyer.foster.entity.User;
 import com.flyer.foster.pojo.UserRespPOJO;
 import com.flyer.foster.service.IUserService;
@@ -22,9 +21,7 @@ import javax.validation.Valid;
 import java.util.List;
 
 /**
- * <p>
- * 用户表 前端控制器
- * </p>
+ * 用户
  *
  * @author flyer
  * @since 2024-05-06
@@ -37,6 +34,11 @@ public class UserController {
     @Autowired
     private IUserService iUserService;
 
+    /**
+     * 登录
+     * @param loginDto
+     * @return
+     */
     @SaIgnore
     @PostMapping("/login")
     public R login(@RequestBody LoginDTO loginDto) {
@@ -72,8 +74,8 @@ public class UserController {
      * @return
      */
     @PostMapping("")
-    public R addUser(@Valid @RequestBody UserAddOrUpdateDTO addDTO) {
-        return R.ok().result(iUserService.addUserAndRole(addDTO));
+    public R addUser(@Valid @RequestBody UserAddDto addDTO) {
+        return R.ok().result(iUserService.addUser(addDTO));
     }
 
     /**
@@ -97,6 +99,6 @@ public class UserController {
      */
     @PostMapping("/delete")
     public R deleteUser(@RequestBody List<Integer> idList) {
-        return R.ok().result(iUserService.removeBatchByIds(idList));
+        return R.ok().result(iUserService.removeByIdList(idList));
     }
 }

+ 0 - 2
admin/src/main/java/com/flyer/foster/controller/UserRoleController.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-06

+ 24 - 0
admin/src/main/java/com/flyer/foster/dto/UserAddDto.java

@@ -0,0 +1,24 @@
+package com.flyer.foster.dto;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+
+/**
+ * UserAddDto
+ *
+ * @author kelei
+ * @since 2023/3/24/15:18
+ */
+@Data
+public class UserAddDto {
+    @NotBlank(message = "用户名不能为空")
+    private String username;
+
+    @NotBlank(message = "密码不能为空")
+    private String password;
+
+    private Integer tenantId;
+
+    private Integer roleId;
+}

+ 3 - 5
admin/src/main/java/com/flyer/foster/entity/Menu.java

@@ -1,10 +1,7 @@
 package com.flyer.foster.entity;
 
-import com.baomidou.mybatisplus.annotation.FieldFill;
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableLogic;
-import com.baomidou.mybatisplus.annotation.TableName;
-import com.baomidou.mybatisplus.annotation.Version;
+import com.baomidou.mybatisplus.annotation.*;
+
 import java.io.Serializable;
 import java.time.LocalDateTime;
 import lombok.Getter;
@@ -25,6 +22,7 @@ public class Menu implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
+    @TableId(value = "id", type = IdType.AUTO)
     private Integer id;
 
     private String menuName;

+ 3 - 5
admin/src/main/java/com/flyer/foster/entity/Role.java

@@ -1,10 +1,7 @@
 package com.flyer.foster.entity;
 
-import com.baomidou.mybatisplus.annotation.FieldFill;
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableLogic;
-import com.baomidou.mybatisplus.annotation.TableName;
-import com.baomidou.mybatisplus.annotation.Version;
+import com.baomidou.mybatisplus.annotation.*;
+
 import java.io.Serializable;
 import java.time.LocalDateTime;
 import lombok.Getter;
@@ -25,6 +22,7 @@ public class Role implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
+    @TableId(value = "id", type = IdType.AUTO)
     private Integer id;
 
     private String roleName;

+ 3 - 5
admin/src/main/java/com/flyer/foster/entity/RoleMenu.java

@@ -1,10 +1,7 @@
 package com.flyer.foster.entity;
 
-import com.baomidou.mybatisplus.annotation.FieldFill;
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableLogic;
-import com.baomidou.mybatisplus.annotation.TableName;
-import com.baomidou.mybatisplus.annotation.Version;
+import com.baomidou.mybatisplus.annotation.*;
+
 import java.io.Serializable;
 import java.time.LocalDateTime;
 import lombok.Getter;
@@ -25,6 +22,7 @@ public class RoleMenu implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
+    @TableId(value = "id", type = IdType.AUTO)
     private Integer id;
 
     private Integer roleId;

+ 3 - 5
admin/src/main/java/com/flyer/foster/entity/Tenant.java

@@ -1,10 +1,7 @@
 package com.flyer.foster.entity;
 
-import com.baomidou.mybatisplus.annotation.FieldFill;
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableLogic;
-import com.baomidou.mybatisplus.annotation.TableName;
-import com.baomidou.mybatisplus.annotation.Version;
+import com.baomidou.mybatisplus.annotation.*;
+
 import java.io.Serializable;
 import java.time.LocalDateTime;
 import lombok.Getter;
@@ -25,6 +22,7 @@ public class Tenant implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
+    @TableId(value = "id", type = IdType.AUTO)
     private Integer id;
 
     private String tenantName;

+ 3 - 5
admin/src/main/java/com/flyer/foster/entity/User.java

@@ -1,10 +1,7 @@
 package com.flyer.foster.entity;
 
-import com.baomidou.mybatisplus.annotation.FieldFill;
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableLogic;
-import com.baomidou.mybatisplus.annotation.TableName;
-import com.baomidou.mybatisplus.annotation.Version;
+import com.baomidou.mybatisplus.annotation.*;
+
 import java.io.Serializable;
 import java.time.LocalDateTime;
 import lombok.Getter;
@@ -25,6 +22,7 @@ public class User implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
+    @TableId(value = "id", type = IdType.AUTO)
     private Integer id;
 
     private String username;

+ 3 - 5
admin/src/main/java/com/flyer/foster/entity/UserRole.java

@@ -1,10 +1,7 @@
 package com.flyer.foster.entity;
 
-import com.baomidou.mybatisplus.annotation.FieldFill;
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableLogic;
-import com.baomidou.mybatisplus.annotation.TableName;
-import com.baomidou.mybatisplus.annotation.Version;
+import com.baomidou.mybatisplus.annotation.*;
+
 import java.io.Serializable;
 import java.time.LocalDateTime;
 import lombok.Getter;
@@ -25,6 +22,7 @@ public class UserRole implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
+    @TableId(value = "id", type = IdType.AUTO)
     private Integer id;
 
     private Integer userId;

+ 4 - 1
admin/src/main/java/com/flyer/foster/mapper/IRoleMapper.java

@@ -2,6 +2,9 @@ package com.flyer.foster.mapper;
 
 import com.flyer.foster.entity.Role;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 /**
  * <p>
@@ -12,5 +15,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * @since 2024-05-06
  */
 public interface IRoleMapper extends BaseMapper<Role> {
-
+    boolean deleteByIdList(@Param("idList") List<Integer> idList);
 }

+ 4 - 0
admin/src/main/java/com/flyer/foster/mapper/IRoleMenuMapper.java

@@ -2,6 +2,9 @@ package com.flyer.foster.mapper;
 
 import com.flyer.foster.entity.RoleMenu;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 /**
  * <p>
@@ -13,4 +16,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface IRoleMenuMapper extends BaseMapper<RoleMenu> {
 
+    boolean deleteByRoleIdList(@Param("roleIdList") List<Integer> roleIdList);
 }

+ 8 - 0
admin/src/main/java/com/flyer/foster/mapper/IUserMapper.java

@@ -37,4 +37,12 @@ public interface IUserMapper extends BaseMapper<User> {
     IPage<UserSearchDTO> adminListByPage(@Param("page") IPage<UserSearchDTO> page,
                                          @Param("searchDTO") UserSearchDTO searchDTO,
                                          @Param("userIdList") List<Integer> userIdList);
+
+    /**
+     * 物理删除
+     *
+     * @param idList
+     * @return
+     */
+    boolean deleteByIdList(@Param("idList") List<Integer> idList, @Param("tenantId") Integer tenantId);
 }

+ 6 - 0
admin/src/main/java/com/flyer/foster/mapper/IUserRoleMapper.java

@@ -2,6 +2,9 @@ package com.flyer.foster.mapper;
 
 import com.flyer.foster.entity.UserRole;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 /**
  * <p>
@@ -13,4 +16,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface IUserRoleMapper extends BaseMapper<UserRole> {
 
+    boolean deleteByUserIdList(@Param("userIdList") List<Integer> userIdList);
+
+    boolean deleteByRoleIdList(@Param("roleIdList") List<Integer> roleIdList);
 }

+ 24 - 0
admin/src/main/java/com/flyer/foster/pojo/Dropdown.java

@@ -0,0 +1,24 @@
+package com.flyer.foster.pojo;
+
+import lombok.Data;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 下拉框对象
+ *
+ * @author kelei
+ * @since 2023/3/21/20:59
+ */
+@Data
+public class Dropdown {
+    private Integer id;
+
+    private String name;
+
+    /**
+     * 级联下拉集合
+     */
+    private List<Dropdown> children = new ArrayList<>();
+}

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

@@ -4,6 +4,8 @@ import com.flyer.foster.dto.RoleMenuAddDTO;
 import com.flyer.foster.entity.RoleMenu;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.List;
+
 /**
  * <p>
  * 角色菜单关系表 服务类
@@ -14,4 +16,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IRoleMenuService extends IService<RoleMenu> {
     boolean addRoleMenu(RoleMenuAddDTO addDTO);
+
+    List<Integer> getRoleMenuIdList(Integer roleId);
 }

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

@@ -4,6 +4,7 @@ import com.flyer.foster.dto.RoleAddDTO;
 import com.flyer.foster.dto.RoleRespDTO;
 import com.flyer.foster.entity.Role;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.flyer.foster.pojo.Dropdown;
 
 import java.util.List;
 
@@ -19,4 +20,19 @@ public interface IRoleService extends IService<Role> {
     List<RoleRespDTO> getRoleList();
 
     boolean addRole(RoleAddDTO addDTO);
+
+    /**
+     * 删除角色
+     *
+     * @param roleIdList
+     * @return
+     */
+    boolean deleteRole(List<Integer> roleIdList);
+
+    /**
+     * 角色下拉框数据
+     *
+     * @return
+     */
+    List<Dropdown> getDropdownList();
 }

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

@@ -3,6 +3,8 @@ package com.flyer.foster.service;
 import com.flyer.foster.entity.UserRole;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.List;
+
 /**
  * <p>
  * 用户角色表 服务类
@@ -12,5 +14,10 @@ import com.baomidou.mybatisplus.extension.service.IService;
  * @since 2024-05-06
  */
 public interface IUserRoleService extends IService<UserRole> {
-
+    /**
+     * 物理删除
+     * @param userIdList
+     * @return
+     */
+    boolean deleteByUserIdList(List<Integer> userIdList);
 }

+ 8 - 5
admin/src/main/java/com/flyer/foster/service/IUserService.java

@@ -3,11 +3,13 @@ package com.flyer.foster.service;
 import cn.hutool.crypto.asymmetric.RSA;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.flyer.foster.dto.LoginDTO;
+import com.flyer.foster.dto.UserAddDto;
 import com.flyer.foster.dto.UserAddOrUpdateDTO;
 import com.flyer.foster.dto.UserSearchDTO;
 import com.flyer.foster.entity.User;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -43,10 +45,11 @@ public interface IUserService extends IService<User> {
     IPage<UserSearchDTO> selectByPage(IPage<User> page, UserSearchDTO queryDTO);
 
     /**
-     * 添加用户和权限
-     *
-     * @param addDTO 新增用户对象
-     * @return true:成功,false:失败
+     * 物理删除
+     * @param idList
+     * @return
      */
-    boolean addUserAndRole(UserAddOrUpdateDTO addDTO);
+    boolean removeByIdList(List<Integer> idList);
+
+    boolean addUser(UserAddDto addDTO);
 }

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

@@ -9,6 +9,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.List;
+import java.util.stream.Collectors;
+
 /**
  * <p>
  * 角色菜单关系表 服务实现类
@@ -40,4 +43,9 @@ public class RoleMenuServiceImpl extends ServiceImpl<IRoleMenuMapper, RoleMenu>
         }
         return true;
     }
+
+    @Override
+    public List<Integer> getRoleMenuIdList(Integer roleId) {
+        return this.lambdaQuery().eq(RoleMenu::getRoleId, roleId).list().stream().map(RoleMenu::getMenuId).collect(Collectors.toList());
+    }
 }

+ 52 - 2
admin/src/main/java/com/flyer/foster/service/impl/RoleServiceImpl.java

@@ -2,22 +2,33 @@ 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 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.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;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * <p>
@@ -32,9 +43,15 @@ public class RoleServiceImpl extends ServiceImpl<IRoleMapper, Role> implements I
     @Autowired
     private IRoleMenuService iRoleMenuService;
 
+    @Autowired
+    private IRoleMenuMapper iRoleMenuMapper;
+
+    @Autowired
+    private IUserRoleMapper iUserRoleMapper;
+
     @Override
     public List<RoleRespDTO> getRoleList() {
-        int tenantId = StpUtil.getSession().getInt("tenantId");
+        int tenantId = StpUtil.getTokenSession().getInt("tenantId");
         List<RoleRespDTO> list = new ArrayList<>();
         List<Role> roleList = this.lambdaQuery()
                 .eq(Role::getTenantId, tenantId)
@@ -52,7 +69,7 @@ public class RoleServiceImpl extends ServiceImpl<IRoleMapper, Role> implements I
     @Transactional
     @Override
     public boolean addRole(RoleAddDTO addDTO) {
-        int tenantId = StpUtil.getSession().getInt("tenantId");
+        int tenantId = StpUtil.getTokenSession().getInt("tenantId");
         addDTO.setRoleName(addDTO.getRoleName().trim());
         addDTO.setRoleCode(addDTO.getRoleCode().trim());
         if (addDTO.getMenuIdList().size() == 0) {
@@ -79,4 +96,37 @@ public class RoleServiceImpl extends ServiceImpl<IRoleMapper, Role> implements I
         iRoleMenuService.addRoleMenu(roleMenuAddDTO);
         return true;
     }
+
+    @Transactional
+    @Override
+    public boolean deleteRole(List<Integer> roleIdList) {
+        int tenantId = StpUtil.getTokenSession().getInt("tenantId");
+        // 物理删除角色
+        baseMapper.deleteByIdList(roleIdList);
+        // 物理删除角色菜单
+        iRoleMenuMapper.deleteByRoleIdList(roleIdList);
+        // 物理删除用户角色
+        iUserRoleMapper.deleteByRoleIdList(roleIdList);
+        return true;
+    }
+
+    @Override
+    public List<Dropdown> getDropdownList() {
+        int tenantId = StpUtil.getTokenSession().getInt("tenantId");
+        List<Role> roleList = this.lambdaQuery()
+                .eq(Role::getTenantId, tenantId)
+                .eq(Role::getIsAdmin, IsAdminEnum.NO.getId())
+                .eq(Role::getStatus, StatusEnum.ENABLE.getId())
+                .list();
+        List<Dropdown> dropdownList = new ArrayList<>();
+        Dropdown dropdown;
+        for (Role role : roleList) {
+            dropdown = new Dropdown();
+            Map<String, String> mapping = new HashMap<>();
+            mapping.put("roleName", "name");
+            BeanUtil.copyProperties(role, dropdown, CopyOptions.create().setFieldMapping(mapping));
+            dropdownList.add(dropdown);
+        }
+        return dropdownList;
+    }
 }

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

@@ -6,6 +6,8 @@ import com.flyer.foster.service.IUserRoleService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * <p>
  * 用户角色表 服务实现类
@@ -17,4 +19,8 @@ import org.springframework.stereotype.Service;
 @Service
 public class UserRoleServiceImpl extends ServiceImpl<IUserRoleMapper, UserRole> implements IUserRoleService {
 
+    @Override
+    public boolean deleteByUserIdList(List<Integer> userIdList) {
+        return baseMapper.deleteByUserIdList(userIdList);
+    }
 }

+ 40 - 33
admin/src/main/java/com/flyer/foster/service/impl/UserServiceImpl.java

@@ -3,17 +3,17 @@ package com.flyer.foster.service.impl;
 import cn.dev33.satoken.session.SaSession;
 import cn.dev33.satoken.stp.StpUtil;
 import cn.hutool.core.bean.BeanUtil;
-import cn.hutool.core.util.StrUtil;
+import cn.hutool.core.convert.Convert;
 import cn.hutool.crypto.SecureUtil;
 import cn.hutool.crypto.asymmetric.KeyType;
 import cn.hutool.crypto.asymmetric.RSA;
-import cn.hutool.setting.dialect.Props;
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.flyer.exception.BusinessException;
 import com.flyer.foster.consts.LoginDevice;
 import com.flyer.foster.consts.RedisKeyConst;
 import com.flyer.foster.dto.LoginDTO;
+import com.flyer.foster.dto.UserAddDto;
 import com.flyer.foster.dto.UserAddOrUpdateDTO;
 import com.flyer.foster.dto.UserSearchDTO;
 import com.flyer.foster.entity.Role;
@@ -26,16 +26,12 @@ import com.flyer.foster.service.IUserService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.flyer.util.RedisUtil;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.core.env.Environment;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -118,7 +114,7 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I
 
     @Override
     public IPage<UserSearchDTO> selectByPage(IPage<User> page, UserSearchDTO searchDTO) {
-        int tenantId = Integer.parseInt(StpUtil.getTokenSession().get("tenantId").toString());
+        int tenantId = StpUtil.getTokenSession().getInt("tenantId");
         searchDTO.setTenantId(tenantId);
         // 查询管理员角色的账号
         Role adminRole = iRoleService.lambdaQuery().eq(Role::getIsAdmin, 1).eq(Role::getTenantId, tenantId).one();
@@ -141,34 +137,45 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I
 
     @Transactional
     @Override
-    public boolean addUserAndRole(UserAddOrUpdateDTO addDTO) {
-        log.info("UserServiceImpl--->addUserAndRole params is {}", JSON.toJSONString(addDTO));
-        int tenantId = Integer.parseInt(StpUtil.getTokenSession().get("tenantId").toString());
-        // 查看用户名是否存在
-        String userName = addDTO.getUsername();
-        long count = this.lambdaQuery().eq(User::getUsername, userName).count();
-        if (count != 0) {
-            throw new BusinessException("用户已存在");
-        }
-        User user = new User();
-        BeanUtil.copyProperties(addDTO, user);
-        // 密码MD5加密存入
-        user.setPassword(SecureUtil.md5(user.getPassword()));
-        user.setTenantId(tenantId);
-        boolean saveResult = this.save(user);
-        if (!saveResult) {
-            throw new BusinessException("新增用户失败");
+    public boolean removeByIdList(List<Integer> idList) {
+        int tenantId = StpUtil.getTokenSession().getInt("tenantId");
+        // 删除用户
+        baseMapper.deleteByIdList(idList, tenantId);
+        // 删除用户的角色
+        iUserRoleService.deleteByUserIdList(idList);
+        return true;
+    }
+
+    @Transactional
+    @Override
+    public boolean addUser(UserAddDto addDto) {
+        addDto.setUsername(addDto.getUsername().trim());
+        int tenantId = StpUtil.getTokenSession().getInt("tenantId");
+        User user;
+        if (addDto.getRoleId() == null) {
+            throw new BusinessException("请选择角色");
         }
-        UserRole insertEntity;
-        for (Integer roleId : addDTO.getRoleIdList()) {
-            insertEntity = new UserRole();
-            insertEntity.setUserId(user.getId());
-            insertEntity.setRoleId(roleId);
-            boolean saveRoleResult = iUserRoleService.save(insertEntity);
-            if (!saveRoleResult) {
-                throw new BusinessException("新增用户角色关系数据失败");
-            }
+        user = this.lambdaQuery()
+                .eq(User::getUsername, addDto.getUsername())
+                .eq(User::getTenantId, tenantId)
+                .one();
+        if (user != null) {
+            throw new BusinessException("用户名已存在");
         }
+        user = new User();
+        BeanUtil.copyProperties(addDto, user);
+        user.setTenantId(tenantId);
+        // md5加密
+        user.setPassword(SecureUtil.md5(user.getPassword()));
+        // 1.添加用户
+        this.save(user);
+
+        UserRole userRole = new UserRole();
+        userRole.setUserId(user.getId());
+        userRole.setRoleId(addDto.getRoleId());
+        userRole.setTenantId(tenantId);
+        // 2.添加用户角色
+        iUserRoleService.save(userRole);
         return true;
     }
 }

+ 6 - 0
admin/src/main/resources/mapper/RoleMapper.xml

@@ -2,4 +2,10 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.flyer.foster.mapper.IRoleMapper">
 
+    <delete id="deleteByIdList">
+        delete from tb_role where id in
+        <foreach collection="idList" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </delete>
 </mapper>

+ 6 - 0
admin/src/main/resources/mapper/RoleMenuMapper.xml

@@ -2,4 +2,10 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.flyer.foster.mapper.IRoleMenuMapper">
 
+    <delete id="deleteByRoleIdList">
+        delete from tb_role_menu where role_id in
+        <foreach collection="roleIdList" item="roleId" open="(" separator="," close=")">
+            #{roleId}
+        </foreach>
+    </delete>
 </mapper>

+ 6 - 0
admin/src/main/resources/mapper/UserMapper.xml

@@ -1,6 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.flyer.foster.mapper.IUserMapper">
+    <delete id="deleteByIdList">
+        delete from tb_user where tenant_id = #{tenantId} and id in
+        <foreach collection="idList" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </delete>
     <select id="selectByPage" resultType="com.flyer.foster.dto.UserSearchDTO">
         select a.id        as id,
                a.username  as userName,

+ 13 - 0
admin/src/main/resources/mapper/UserRoleMapper.xml

@@ -2,4 +2,17 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.flyer.foster.mapper.IUserRoleMapper">
 
+    <delete id="deleteByUserIdList">
+        delete from tb_user_role where user_id in
+        <foreach collection="userIdList" item="userId" open="(" separator="," close=")">
+            #{userId}
+        </foreach>
+    </delete>
+
+    <delete id="deleteByRoleIdList">
+        delete from tb_user_role where role_id in
+        <foreach collection="roleIdList" item="roleId" open="(" separator="," close=")">
+            #{roleId}
+        </foreach>
+    </delete>
 </mapper>