Переглянути джерело

组织机构和用户组相关代码

hym 4 роки тому
батько
коміт
62695b955c
42 змінених файлів з 1553 додано та 70 видалено
  1. 2 0
      common/src/main/java/com/huaxu/model/LoginUser.java
  2. 2 0
      common/src/main/java/com/huaxu/model/ResultStatus.java
  3. 5 3
      common/src/main/java/com/huaxu/util/UserUtil.java
  4. 1 1
      user_center/src/main/java/com/huaxu/config/ResourceServerConfig.java
  5. 3 1
      user_center/src/main/java/com/huaxu/controller/AppController.java
  6. 109 0
      user_center/src/main/java/com/huaxu/controller/AreaController.java
  7. 25 30
      user_center/src/main/java/com/huaxu/controller/OrgController.java
  8. 1 1
      user_center/src/main/java/com/huaxu/controller/RoleController.java
  9. 9 0
      user_center/src/main/java/com/huaxu/controller/UserGroupController.java
  10. 84 0
      user_center/src/main/java/com/huaxu/dao/AreaMapper.java
  11. 3 2
      user_center/src/main/java/com/huaxu/dao/GroupUserMapper.java
  12. 5 0
      user_center/src/main/java/com/huaxu/dao/OrgMapper.java
  13. 1 0
      user_center/src/main/java/com/huaxu/dao/RoleMapper.java
  14. 83 0
      user_center/src/main/java/com/huaxu/dao/RoleMenuMapper.java
  15. 2 1
      user_center/src/main/java/com/huaxu/dao/RoleOrgMapper.java
  16. 7 1
      user_center/src/main/java/com/huaxu/dao/UserGroupMapper.java
  17. 84 0
      user_center/src/main/java/com/huaxu/dao/UserGroupRoleMapper.java
  18. 30 0
      user_center/src/main/java/com/huaxu/dto/OrgTree.java
  19. 1 0
      user_center/src/main/java/com/huaxu/dto/RoleDto.java
  20. 2 2
      user_center/src/main/java/com/huaxu/dto/RoleRequestDto.java
  21. 3 1
      user_center/src/main/java/com/huaxu/dto/UserGroupDto.java
  22. 49 0
      user_center/src/main/java/com/huaxu/entity/Area.java
  23. 1 1
      user_center/src/main/java/com/huaxu/entity/GroupUser.java
  24. 16 0
      user_center/src/main/java/com/huaxu/entity/Org.java
  25. 36 0
      user_center/src/main/java/com/huaxu/entity/RoleMenu.java
  26. 7 2
      user_center/src/main/java/com/huaxu/entity/UserGroup.java
  27. 54 0
      user_center/src/main/java/com/huaxu/entity/UserGroupRole.java
  28. 80 0
      user_center/src/main/java/com/huaxu/service/AreaService.java
  29. 2 0
      user_center/src/main/java/com/huaxu/service/OrgService.java
  30. 1 0
      user_center/src/main/java/com/huaxu/service/RoleService.java
  31. 119 0
      user_center/src/main/java/com/huaxu/service/impl/AreaServiceImpl.java
  32. 50 0
      user_center/src/main/java/com/huaxu/service/impl/OrgServiceImpl.java
  33. 27 5
      user_center/src/main/java/com/huaxu/service/impl/RoleServiceImpl.java
  34. 16 5
      user_center/src/main/java/com/huaxu/service/impl/UserGroupServiceImpl.java
  35. 2 2
      user_center/src/main/resources/application-dev.properties
  36. 227 0
      user_center/src/main/resources/mapper/AreaMapper.xml
  37. 29 4
      user_center/src/main/resources/mapper/OrgMapper.xml
  38. 6 2
      user_center/src/main/resources/mapper/RoleMapper.xml
  39. 155 0
      user_center/src/main/resources/mapper/RoleMenuMapper.xml
  40. 33 6
      user_center/src/main/resources/mapper/UserGroupMapper.xml
  41. 156 0
      user_center/src/main/resources/mapper/UserGroupRoleMapper.xml
  42. 25 0
      user_center/src/test/com/huaxu/test/TestOrgTree.java

+ 2 - 0
common/src/main/java/com/huaxu/model/LoginUser.java

@@ -38,6 +38,8 @@ public class LoginUser implements UserDetails {
 
     @ApiModelProperty(value="租户标识")
     private String tenantId;
+    @ApiModelProperty(value="用户权限类型")
+    private Integer permissonType;
 
     @JsonIgnore
     private String LoginToken;

+ 2 - 0
common/src/main/java/com/huaxu/model/ResultStatus.java

@@ -43,6 +43,8 @@ public enum ResultStatus {
     SMS_CODE_COUNT(300001,"需进行随机码校验"),
     SMS_CODE_LIMIT(300002,"频繁获取验证码,请联系系统管理员"),
     ORG_HAS_USER(300003,"请先删除机构下的用户"),
+    ORG_CHIRDTYPE_ERROR(300006,"下级机构存在公司,请先修改下级机构类型"),
+    ORG_PARENT_ERROR(300007,"上级机构为部门,请先修改上级机构类型或更换上级机构"),
     ROLE_HAS_USER(300004,"请先解除用户与此角色绑定关系"),
     USERGROUP_HAS_USER(300005,"请先解除用户与此用户组绑定关系"),
 

+ 5 - 3
common/src/main/java/com/huaxu/util/UserUtil.java

@@ -22,7 +22,7 @@ public class UserUtil {
         Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
         if (authentication != null) {
             if (authentication instanceof AnonymousAuthenticationToken) {
-                return null;
+                return new LoginUser(null);
             }
 
             if (authentication instanceof UsernamePasswordAuthenticationToken) {
@@ -50,8 +50,10 @@ public class UserUtil {
                     loginUser.setDepartmentId(userJson.getInteger("departmentId"));
                     loginUser.setTenantId(userJson.getString("tenantId"));
                     JSONArray programItemListArray = userJson.getJSONArray("programItemList");
+                    loginUser.setPermissonType(userJson.getInteger("permissonType"));
                     if (programItemListArray != null) {
-                        List<ProgramItem> collection = JSONObject.parseArray(programItemListArray.toJSONString(), ProgramItem.class);
+                        List<ProgramItem> collection =
+                                JSONObject.parseArray(programItemListArray.toJSONString(), ProgramItem.class);
                         loginUser.setProgramItemList(collection);
                     }
                     return loginUser;
@@ -59,6 +61,6 @@ public class UserUtil {
             }
         }
 
-        return null;
+        return new LoginUser(null);
     }
 }

+ 1 - 1
user_center/src/main/java/com/huaxu/config/ResourceServerConfig.java

@@ -17,7 +17,7 @@ public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
                 .and()
                 .authorizeRequests()
                 .antMatchers("/swagger-ui.html","/webjars/**", "/webjars/**", "/swagger-resources/**",
-                        "/v2/**","/app/**","/user/**","/menu/**")
+                        "/v2/**","/app/**","/user/**","/menu/**","/role/**","/org/**","/userGroup/**")
                 .permitAll() //配置不需要身份认证的请求路径
                 .anyRequest().authenticated() //其他所有访问路径都需要身份认证
                 .and()

+ 3 - 1
user_center/src/main/java/com/huaxu/controller/AppController.java

@@ -4,9 +4,11 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.huaxu.entity.App;
 import com.huaxu.model.AjaxMessage;
+import com.huaxu.model.LoginUser;
 import com.huaxu.model.Pagination;
 import com.huaxu.model.ResultStatus;
 import com.huaxu.service.AppService;
+import com.huaxu.util.UserUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
@@ -45,7 +47,7 @@ public class AppController {
     public AjaxMessage<App> selectOne(
             @ApiParam(value = "设置配置", required = true) @RequestBody App app) {
         App result = appService.selectById(app.getId());
-
+        LoginUser currentUser = UserUtil.getCurrentUser();
         return new AjaxMessage<>(ResultStatus.OK, result);
     }
 

+ 109 - 0
user_center/src/main/java/com/huaxu/controller/AreaController.java

@@ -0,0 +1,109 @@
+package com.huaxu.controller;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.huaxu.entity.Area;
+import com.huaxu.model.AjaxMessage;
+import com.huaxu.model.Pagination;
+import com.huaxu.model.ResultStatus;
+import com.huaxu.service.AreaService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * (Area)控制层
+ *
+ * @author makejava
+ * @since 2020-10-28 16:51:27
+ */
+@RestController
+@RequestMapping("/area")
+@Api(tags = "")
+public class AreaController {
+    /**
+     * 服务对象
+     */
+    @Autowired
+    private AreaService areaService;
+
+    /**
+     * 通过主键查询单条数据
+     *
+     * @param area 参数对象
+     * @return 单条数据
+     */
+    @RequestMapping(value = "get", method = RequestMethod.POST)
+    @ApiOperation(value = "查询设施配置列表")
+    public AjaxMessage<Area> selectOne(
+            @ApiParam(value = "设置配置", required = true) @RequestBody Area area) {
+        Area result = areaService.selectById(area.getId());
+
+        return new AjaxMessage<>(ResultStatus.OK, result);
+    }
+
+    /**
+     * 新增一条数据
+     *
+     * @param area 实体类
+     * @return Response对象
+     */
+    @RequestMapping(value = "insert", method = RequestMethod.POST)
+    @ApiOperation(value = "查询设施配置列表")
+    public AjaxMessage<Integer> insert(@ApiParam(value = "设置配置", required = true) @RequestBody Area area) {
+        int result = areaService.insert(area);
+
+        return new AjaxMessage<>(ResultStatus.OK, result);
+    }
+
+    /**
+     * 修改一条数据
+     *
+     * @param area 实体类
+     * @return Response对象
+     */
+    @RequestMapping(value = "update", method = RequestMethod.POST)
+    @ApiOperation(value = "查询设施配置列表")
+    public AjaxMessage<Integer> update(@ApiParam(value = "设置配置", required = true) @RequestBody Area area) {
+        int result = areaService.update(area);
+        return new AjaxMessage<>(ResultStatus.OK, result);
+
+    }
+
+    /**
+     * 删除一条数据
+     *
+     * @param area 参数对象
+     * @return Response对象
+     */
+    @RequestMapping(value = "delete", method = RequestMethod.POST)
+    @ApiOperation(value = "查询设施配置列表")
+    public AjaxMessage<Integer> delete(@ApiParam(value = "设置配置", required = true) @RequestBody Area area) {
+        int result = areaService.deleteById(area.getId());
+        return new AjaxMessage<>(ResultStatus.OK, result);
+    }
+
+
+    /**
+     * 分页查询
+     *
+     * @param pageNum  偏移
+     * @param pageSize 条数
+     * @return Response对象
+     */
+    @RequestMapping(value = "selectPage", method = RequestMethod.POST)
+    @ApiOperation(value = "查询设施配置列表")
+    public AjaxMessage<Pagination<Area>> selectPage(Integer pageNum, Integer pageSize) {
+        Area area = new Area();
+        IPage<Area> iPage = new Page<>(pageNum, pageSize);
+        iPage = areaService.selectPage(area, iPage);
+        Pagination<Area> pages = new Pagination<>(iPage);
+        return new AjaxMessage<>(ResultStatus.OK, pages);
+    }
+
+}

+ 25 - 30
user_center/src/main/java/com/huaxu/controller/OrgController.java

@@ -2,23 +2,23 @@ package com.huaxu.controller;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.huaxu.dto.OrgTree;
 import com.huaxu.entity.Org;
 import com.huaxu.model.AjaxMessage;
-import com.huaxu.model.LoginUser;
 import com.huaxu.model.Pagination;
 import com.huaxu.model.ResultStatus;
 import com.huaxu.service.OrgService;
-import com.huaxu.util.UserUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
+
 /**
  * 组织(Org)控制层
  *
@@ -27,7 +27,7 @@ import org.springframework.web.bind.annotation.RestController;
  */
 @RestController
 @RequestMapping("/org")
-@Api(tags = "组织机构crud")
+@Api(tags = "组织机构")
 public class OrgController {
     /**
      * 服务对象
@@ -38,13 +38,15 @@ public class OrgController {
     /**
      * 通过主键查询单条数据
      *
-     * @param org 参数对象
+     * @param id 参数对象
      * @return 单条数据
      */
     @RequestMapping(value = "get", method = RequestMethod.POST)
     @ApiOperation(value = "查询设施配置列表")
     public AjaxMessage<Org> selectOne(
-            @ApiParam(value = "设置配置", required = true) @RequestBody Org org) {
+            @ApiParam(value = "设置配置", required = true) Integer id) {
+        Org org=new Org();
+        org.setId(id);
         Org result = orgService.selectById(org.getId());
 
         return new AjaxMessage<>(ResultStatus.OK, result);
@@ -76,7 +78,11 @@ public class OrgController {
     public AjaxMessage<Integer> update(@ApiParam(value = "设置配置", required = true) @RequestBody Org org) {
         int result = orgService.update(org);
         if(result==-1){
-            return new AjaxMessage<>(ResultStatus.OK, result);
+            return new AjaxMessage<>(ResultStatus.ORG_HAS_USER);
+        }else if(result==-2){
+            return new AjaxMessage<>(ResultStatus.ORG_CHIRDTYPE_ERROR);
+        }else if(result==-3){
+            return new AjaxMessage<>(ResultStatus.ORG_PARENT_ERROR);
         }else{
             return new AjaxMessage<>(ResultStatus.OK, result);
         }
@@ -84,35 +90,24 @@ public class OrgController {
 
     }
 
-    /**
-     * 删除一条数据
-     *
-     * @param org 参数对象
-     * @return Response对象
-     */
-    @RequestMapping(value = "delete", method = RequestMethod.POST)
-    @ApiOperation(value = "查询设施配置列表")
-    public AjaxMessage<Integer> delete(@ApiParam(value = "设置配置", required = true) @RequestBody Org org) {
-        int result = orgService.deleteById(org.getId());
-        return new AjaxMessage<>(ResultStatus.OK, result);
-    }
+
+
 
 
     /**
-     * 分页查询
+     * 获取机构树
      *
-     * @param pageNum  偏移
-     * @param pageSize 条数
+     * @param
+     * @param
      * @return Response对象
      */
-    @RequestMapping(value = "selectPage", method = RequestMethod.POST)
-    @ApiOperation(value = "查询设施配置列表")
-    public AjaxMessage<Pagination<Org>> selectPage(Integer pageNum, Integer pageSize) {
-        Org org = new Org();
-        IPage<Org> iPage = new Page<>(pageNum, pageSize);
-        iPage = orgService.selectPage(org, iPage);
-        Pagination<Org> pages = new Pagination<>(iPage);
-        return new AjaxMessage<>(ResultStatus.OK, pages);
+    @RequestMapping(value = "getOrgTree", method = RequestMethod.POST)
+    @ApiOperation(value = "获取机构树")
+    public AjaxMessage<List<OrgTree>> getOrgTree(@ApiParam(value = "机构类型", required = true)String orgType) {
+        Org org=new Org();
+        org.setOrgType(orgType);
+        ;
+        return new AjaxMessage<>(ResultStatus.OK, orgService.getTrees(org));
     }
 
 }

+ 1 - 1
user_center/src/main/java/com/huaxu/controller/RoleController.java

@@ -103,7 +103,7 @@ public class RoleController {
     }
     @RequestMapping(value = "findUsersByUserGroup", method = RequestMethod.POST)
     @ApiOperation(value = "查询角色对应user")
-    AjaxMessage<List<UserEntity>>  findUsersByUserGroup(@ApiParam(value = "角色id", required = true)Integer id){
+    AjaxMessage<List<UserEntity>>  findUsersByRole(@ApiParam(value = "角色id", required = true)Integer id){
         Role role=new Role();
         role.setId(id);
         return new AjaxMessage<>(ResultStatus.OK,

+ 9 - 0
user_center/src/main/java/com/huaxu/controller/UserGroupController.java

@@ -2,6 +2,7 @@ package com.huaxu.controller;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.huaxu.dto.UserGroupDto;
 import com.huaxu.entity.UserEntity;
 import com.huaxu.entity.UserGroup;
 import com.huaxu.model.AjaxMessage;
@@ -108,5 +109,13 @@ public class UserGroupController {
         return new AjaxMessage<>(ResultStatus.OK,
                 userGroupService.findUsersByUserGroup(userGroup));
     }
+    @RequestMapping(value = "updateRolesByUserGroup", method = RequestMethod.POST)
+    @ApiOperation(value = "绑定用户组")
+    AjaxMessage  updateRolesByUserGroup(@ApiParam(value = "用户组绑定信息", required = true) @RequestBody
+                                                UserGroupDto userGroupDto){
+
+        userGroupService.updateRolesByUserGroup(userGroupDto);
+        return new AjaxMessage<>(ResultStatus.OK);
+    }
 
 }

+ 84 - 0
user_center/src/main/java/com/huaxu/dao/AreaMapper.java

@@ -0,0 +1,84 @@
+package com.huaxu.dao;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.huaxu.entity.Area;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * (Area)表数据库访问层
+ *
+ * @author makejava
+ * @since 2020-10-28 16:51:29
+ */
+@Mapper
+public interface AreaMapper {
+
+    /**
+     * 通过ID查询单条数据
+     *
+     * @param id 主键
+     * @return 实例对象
+     */
+    Area selectById(Integer id);
+
+
+    /**
+     * 查询全部
+     *
+     * @return 对象列表
+     */
+    List<Area> selectAll();
+
+    /**
+     * 通过实体作为筛选条件查询
+     *
+     * @param area 实例对象
+     * @return 对象列表
+     */
+    List<Area> selectList(Area area);
+
+    /**
+     * 新增数据
+     *
+     * @param area 实例对象
+     * @return 影响行数
+     */
+    int insert(Area area);
+
+    /**
+     * 批量新增
+     *
+     * @param areas 实例对象的集合
+     * @return 影响行数
+     */
+    int batchInsert(@Param("areas") List<Area> areas);
+
+    /**
+     * 修改数据
+     *
+     * @param area 实例对象
+     * @return 影响行数
+     */
+    int update(Area area);
+
+    /**
+     * 通过主键删除数据
+     *
+     * @param id 主键
+     * @return 影响行数
+     */
+    int deleteById(Integer id);
+
+    /**
+     * 查询总数据数
+     *
+     * @return 数据总数
+     */
+    int count();
+
+    IPage<Area> selectPage(IPage<Area> page, Area area);
+
+}

+ 3 - 2
user_center/src/main/java/com/huaxu/dao/GroupUserMapper.java

@@ -3,6 +3,7 @@ package com.huaxu.dao;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.huaxu.entity.GroupUser;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -10,7 +11,7 @@ import java.util.List;
  * 用户组用户(GroupUser)表数据库访问层
  *
  * @author makejava
- * @since 2020-10-27 14:57:41
+ * @since 2020-10-27 16:46:22
  */
 @Mapper
 public interface GroupUserMapper {
@@ -53,7 +54,7 @@ public interface GroupUserMapper {
      * @param groupUsers 实例对象的集合
      * @return 影响行数
      */
-    int batchInsert(List<GroupUser> groupUsers);
+    int batchInsert(@Param("groupUsers") List<GroupUser> groupUsers);
 
     /**
      * 修改数据

+ 5 - 0
user_center/src/main/java/com/huaxu/dao/OrgMapper.java

@@ -1,6 +1,7 @@
 package com.huaxu.dao;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.huaxu.dto.OrgTree;
 import com.huaxu.entity.Org;
 import org.apache.ibatis.annotations.Mapper;
 
@@ -80,5 +81,9 @@ public interface OrgMapper {
 
     IPage<Org> selectPage(IPage<Org> page, Org org);
     Org findOrgUser(Org org);
+    Org findOrgType(Org org);
+
+
+    List<OrgTree> selectTrees(Org org);
 
 }

+ 1 - 0
user_center/src/main/java/com/huaxu/dao/RoleMapper.java

@@ -84,6 +84,7 @@ public interface RoleMapper {
 
     Role findRoleUser(Role role);
     int deleteRoleUser(Role role);
+    int deleteRoleMenu(Role role);
 
     List<UserEntity> findUsersByRole(Role role);
 

+ 83 - 0
user_center/src/main/java/com/huaxu/dao/RoleMenuMapper.java

@@ -0,0 +1,83 @@
+package com.huaxu.dao;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.huaxu.entity.RoleMenu;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+/**
+ * (RoleMenu)表数据库访问层
+ *
+ * @author makejava
+ * @since 2020-10-27 15:21:33
+ */
+@Mapper
+public interface RoleMenuMapper {
+
+    /**
+     * 通过ID查询单条数据
+     *
+     * @param id 主键
+     * @return 实例对象
+     */
+    RoleMenu selectById(Integer id);
+
+
+    /**
+     * 查询全部
+     *
+     * @return 对象列表
+     */
+    List<RoleMenu> selectAll();
+
+    /**
+     * 通过实体作为筛选条件查询
+     *
+     * @param roleMenu 实例对象
+     * @return 对象列表
+     */
+    List<RoleMenu> selectList(RoleMenu roleMenu);
+
+    /**
+     * 新增数据
+     *
+     * @param roleMenu 实例对象
+     * @return 影响行数
+     */
+    int insert(RoleMenu roleMenu);
+
+    /**
+     * 批量新增
+     *
+     * @param roleMenus 实例对象的集合
+     * @return 影响行数
+     */
+    int batchInsert(List<RoleMenu> roleMenus);
+
+    /**
+     * 修改数据
+     *
+     * @param roleMenu 实例对象
+     * @return 影响行数
+     */
+    int update(RoleMenu roleMenu);
+
+    /**
+     * 通过主键删除数据
+     *
+     * @param id 主键
+     * @return 影响行数
+     */
+    int deleteById(Integer id);
+
+    /**
+     * 查询总数据数
+     *
+     * @return 数据总数
+     */
+    int count();
+
+    IPage<RoleMenu> selectPage(IPage<RoleMenu> page, RoleMenu roleMenu);
+
+}

+ 2 - 1
user_center/src/main/java/com/huaxu/dao/RoleOrgMapper.java

@@ -3,6 +3,7 @@ package com.huaxu.dao;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.huaxu.entity.RoleOrg;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -53,7 +54,7 @@ public interface RoleOrgMapper {
      * @param roleOrgs 实例对象的集合
      * @return 影响行数
      */
-    int batchInsert(List<RoleOrg> roleOrgs);
+    int batchInsert(@Param("roleOrgs") List<RoleOrg> roleOrgs);
 
     /**
      * 修改数据

+ 7 - 1
user_center/src/main/java/com/huaxu/dao/UserGroupMapper.java

@@ -1,9 +1,12 @@
 package com.huaxu.dao;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.huaxu.dto.UserGroupDto;
 import com.huaxu.entity.UserEntity;
 import com.huaxu.entity.UserGroup;
+import com.huaxu.entity.UserRoleEntity;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -54,7 +57,7 @@ public interface UserGroupMapper {
      * @param userGroups 实例对象的集合
      * @return 影响行数
      */
-    int batchInsert(List<UserGroup> userGroups);
+    int batchInsert(@Param("userGroups") List<UserGroup> userGroups);
 
     /**
      * 修改数据
@@ -85,5 +88,8 @@ public interface UserGroupMapper {
     int deleteUserGroupRelations(UserGroup userGroup);
 
     List<UserEntity> findUsersByUserGroup(UserGroup userGroup);
+    int deleteUserRoles(@Param("userGroupDto") UserGroupDto userGroupDto);
+    int batchInsertRoles(@Param("uimsUserRoles") List<UserRoleEntity> userRoleEntity);
+
 
 }

+ 84 - 0
user_center/src/main/java/com/huaxu/dao/UserGroupRoleMapper.java

@@ -0,0 +1,84 @@
+package com.huaxu.dao;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.huaxu.entity.UserGroupRole;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * 用户组角色(UserGroupRole)表数据库访问层
+ *
+ * @author makejava
+ * @since 2020-10-28 17:09:50
+ */
+@Mapper
+public interface UserGroupRoleMapper {
+
+    /**
+     * 通过ID查询单条数据
+     *
+     * @param id 主键
+     * @return 实例对象
+     */
+    UserGroupRole selectById(Integer id);
+
+
+    /**
+     * 查询全部
+     *
+     * @return 对象列表
+     */
+    List<UserGroupRole> selectAll();
+
+    /**
+     * 通过实体作为筛选条件查询
+     *
+     * @param userGroupRole 实例对象
+     * @return 对象列表
+     */
+    List<UserGroupRole> selectList(UserGroupRole userGroupRole);
+
+    /**
+     * 新增数据
+     *
+     * @param userGroupRole 实例对象
+     * @return 影响行数
+     */
+    int insert(UserGroupRole userGroupRole);
+
+    /**
+     * 批量新增
+     *
+     * @param userGroupRoles 实例对象的集合
+     * @return 影响行数
+     */
+    int batchInsert(@Param("userGroupRoles") List<UserGroupRole> userGroupRoles);
+
+    /**
+     * 修改数据
+     *
+     * @param userGroupRole 实例对象
+     * @return 影响行数
+     */
+    int update(UserGroupRole userGroupRole);
+
+    /**
+     * 通过主键删除数据
+     *
+     * @param id 主键
+     * @return 影响行数
+     */
+    int deleteById(Integer id);
+
+    /**
+     * 查询总数据数
+     *
+     * @return 数据总数
+     */
+    int count();
+
+    IPage<UserGroupRole> selectPage(IPage<UserGroupRole> page, UserGroupRole userGroupRole);
+
+}

+ 30 - 0
user_center/src/main/java/com/huaxu/dto/OrgTree.java

@@ -0,0 +1,30 @@
+package com.huaxu.dto;
+
+import com.huaxu.entity.Org;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+@Data
+public class OrgTree {
+   /**
+    * 主键
+    */
+   @ApiModelProperty(value = "主键")
+   private Integer id;
+   /**
+    * 租户标识
+    */
+   @ApiModelProperty(value = "租户标识")
+   private String tenantId;
+   /**
+    * 机构名称
+    */
+   @ApiModelProperty(value = "机构名称")
+   private String orgName;
+   @ApiModelProperty(value = "上级机构")
+   private Integer parentOrgId;
+   private List<OrgTree>orgs;
+   private boolean display;
+}
+

+ 1 - 0
user_center/src/main/java/com/huaxu/dto/RoleDto.java

@@ -13,4 +13,5 @@ public class RoleDto {
     private Integer users;
     @ApiModelProperty(value = "状态",notes = "0:开启,1禁用")
     private Integer roleState;
+
 }

+ 2 - 2
user_center/src/main/java/com/huaxu/dto/RoleRequestDto.java

@@ -9,6 +9,6 @@ import java.util.List;
 public class RoleRequestDto {
     @ApiModelProperty(value = "角色基础信息")
     private Role role;
-    @ApiModelProperty(value = "自定义权限的组织id")
-    private List<Integer> orgIds;
+    @ApiModelProperty(value = "权限/菜单id集合")
+    private List<Integer> ids;
 }

+ 3 - 1
user_center/src/main/java/com/huaxu/dto/UserGroupDto.java

@@ -9,5 +9,7 @@ public class UserGroupDto {
     @ApiModelProperty(value = "用户组id")
     private Integer groupId;
     @ApiModelProperty(value = "用户ids")
-    private List<Integer> userIds;
+    private List<Long> userIds;
+    @ApiModelProperty(value = "角色id")
+    private Long roleId;
 }

+ 49 - 0
user_center/src/main/java/com/huaxu/entity/Area.java

@@ -0,0 +1,49 @@
+package com.huaxu.entity;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * (Area)实体类
+ *
+ * @author makejava
+ * @since 2020-10-28 16:51:30
+ */
+@Data
+@ApiModel
+public class Area implements Serializable {
+    private static final long serialVersionUID = 626982881165746171L;
+    @ApiModelProperty(value = "")
+    private Integer id;
+    @ApiModelProperty(value = "")
+    private Integer parentId;
+    @ApiModelProperty(value = "")
+    private String name;
+    @ApiModelProperty(value = "")
+    private String mangerName;
+    @ApiModelProperty(value = "")
+    private String shortName;
+    @ApiModelProperty(value = "")
+    private String mangerShortName;
+    @ApiModelProperty(value = "")
+    private Integer levelType;
+    @ApiModelProperty(value = "")
+    private String cityCode;
+    @ApiModelProperty(value = "")
+    private String zipCode;
+    @ApiModelProperty(value = "")
+    private String pinYin;
+    @ApiModelProperty(value = "")
+    private String jianPin;
+    @ApiModelProperty(value = "")
+    private String firstChar;
+    @ApiModelProperty(value = "")
+    private String lng;
+    @ApiModelProperty(value = "")
+    private String lat;
+    @ApiModelProperty(value = "")
+    private String remark;
+}

+ 1 - 1
user_center/src/main/java/com/huaxu/entity/GroupUser.java

@@ -31,7 +31,7 @@ public class GroupUser implements Serializable {
      * 用户ID
      */
     @ApiModelProperty(value = "用户ID")
-    private Integer userId;
+    private Long userId;
     /**
      * 数据删除标记
      */

+ 16 - 0
user_center/src/main/java/com/huaxu/entity/Org.java

@@ -1,5 +1,6 @@
 package com.huaxu.entity;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -96,4 +97,19 @@ public class Org implements Serializable {
     private Date dateUpdate;
     @ApiModelProperty(value = "")
     private String updateBy;
+    @ApiModelProperty(value = "父组织类型")
+    @TableField(exist = false)
+    private String parentType;
+    @ApiModelProperty(value = "子组织类型")
+    @TableField(exist = false)
+    private String childType;
+    @ApiModelProperty(value = "父组织id")
+    @TableField(exist = false)
+    private Integer parentId;
+    @ApiModelProperty(value = "父组织名称")
+    @TableField(exist = false)
+    private String parentName;
+    @ApiModelProperty(value = "区域名称")
+    @TableField(exist = false)
+    private String areaName;
 }

+ 36 - 0
user_center/src/main/java/com/huaxu/entity/RoleMenu.java

@@ -0,0 +1,36 @@
+package com.huaxu.entity;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * (RoleMenu)实体类
+ *
+ * @author makejava
+ * @since 2020-10-27 15:21:33
+ */
+@Data
+@ApiModel
+public class RoleMenu implements Serializable {
+    private static final long serialVersionUID = -87910708070688178L;
+    @ApiModelProperty(value = "")
+    private Integer id;
+    @ApiModelProperty(value = "")
+    private Integer menuId;
+    @ApiModelProperty(value = "")
+    private Integer roleId;
+    @ApiModelProperty(value = "")
+    private Integer status;
+    @ApiModelProperty(value = "")
+    private Date dateCreate;
+    @ApiModelProperty(value = "")
+    private String createBy;
+    @ApiModelProperty(value = "")
+    private Date dateUpdate;
+    @ApiModelProperty(value = "")
+    private String updateBy;
+}

+ 7 - 2
user_center/src/main/java/com/huaxu/entity/UserGroup.java

@@ -11,12 +11,12 @@ import java.util.Date;
  * 用户组(UserGroup)实体类
  *
  * @author makejava
- * @since 2020-10-27 09:13:57
+ * @since 2020-10-28 17:13:53
  */
 @Data
 @ApiModel
 public class UserGroup implements Serializable {
-    private static final long serialVersionUID = 770600290905563666L;
+    private static final long serialVersionUID = -20377759533507662L;
     /**
      * 主键
      */
@@ -64,4 +64,9 @@ public class UserGroup implements Serializable {
      */
     @ApiModelProperty(value = "更新人")
     private String updateBy;
+    /**
+     * 角色id
+     */
+    @ApiModelProperty(value = "角色id")
+    private Integer roleId;
 }

+ 54 - 0
user_center/src/main/java/com/huaxu/entity/UserGroupRole.java

@@ -0,0 +1,54 @@
+package com.huaxu.entity;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 用户组角色(UserGroupRole)实体类
+ *
+ * @author makejava
+ * @since 2020-10-28 17:09:50
+ */
+@Data
+@ApiModel
+public class UserGroupRole implements Serializable {
+    private static final long serialVersionUID = -15737171918281912L;
+    /**
+     * 主键
+     */
+    @ApiModelProperty(value = "主键")
+    private Integer id;
+    /**
+     * 用户组ID
+     */
+    @ApiModelProperty(value = "用户组ID")
+    private Integer userGroupId;
+    /**
+     * 角色ID
+     */
+    @ApiModelProperty(value = "角色ID")
+    private Integer roleId;
+    /**
+     * 数据删除标记
+     */
+    @ApiModelProperty(value = "数据删除标记")
+    private Integer status;
+    /**
+     * 创建时间
+     */
+    @ApiModelProperty(value = "创建时间")
+    private Date dateCreate;
+    /**
+     * 创建人
+     */
+    @ApiModelProperty(value = "创建人")
+    private String createBy;
+    @ApiModelProperty(value = "")
+    private Date dateUpdate;
+    @ApiModelProperty(value = "")
+    private String updateBy;
+}

+ 80 - 0
user_center/src/main/java/com/huaxu/service/AreaService.java

@@ -0,0 +1,80 @@
+package com.huaxu.service;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.huaxu.entity.Area;
+
+import java.util.List;
+
+/**
+ * (Area)表服务接口
+ *
+ * @author makejava
+ * @since 2020-10-28 16:51:29
+ */
+public interface AreaService {
+
+    /**
+     * 通过ID查询单条数据
+     *
+     * @param id 主键
+     * @return 实例对象
+     */
+    Area selectById(Integer id);
+
+
+    /**
+     * 查询全部
+     *
+     * @return 对象列表
+     */
+    List<Area> selectAll();
+
+    /**
+     * 通过实体作为筛选条件查询
+     *
+     * @param area 实例对象
+     * @return 对象列表
+     */
+    List<Area> selectList(Area area);
+
+    /**
+     * 新增数据
+     *
+     * @param area 实例对象
+     * @return 影响行数
+     */
+    int insert(Area area);
+
+    /**
+     * 批量新增
+     *
+     * @param areas 实例对象的集合
+     * @return 影响行数
+     */
+    int batchInsert(List<Area> areas);
+
+    /**
+     * 修改数据
+     *
+     * @param area 实例对象
+     * @return 修改
+     */
+    int update(Area area);
+
+    /**
+     * 通过主键删除数据
+     *
+     * @param id 主键
+     * @return 影响行数
+     */
+    int deleteById(Integer id);
+
+    /**
+     * 查询总数据数
+     *
+     * @return 数据总数
+     */
+    int count();
+
+    IPage<Area> selectPage(Area area, IPage<Area> page);
+}

+ 2 - 0
user_center/src/main/java/com/huaxu/service/OrgService.java

@@ -1,6 +1,7 @@
 package com.huaxu.service;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.huaxu.dto.OrgTree;
 import com.huaxu.entity.Org;
 
 import java.util.List;
@@ -77,4 +78,5 @@ public interface OrgService {
     int count();
 
     IPage<Org> selectPage(Org org, IPage<Org> page);
+    List<OrgTree>getTrees(Org org);
 }

+ 1 - 0
user_center/src/main/java/com/huaxu/service/RoleService.java

@@ -81,5 +81,6 @@ public interface RoleService {
 
     IPage<RoleDto> selectPage(Role role, IPage<RoleDto> page);
      List<UserEntity>findUsersByRole(Role role);
+     int updateRoleMenuRelations(RoleRequestDto dto);
 
 }

+ 119 - 0
user_center/src/main/java/com/huaxu/service/impl/AreaServiceImpl.java

@@ -0,0 +1,119 @@
+package com.huaxu.service.impl;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.huaxu.dao.AreaMapper;
+import com.huaxu.entity.Area;
+import com.huaxu.service.AreaService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * (Area表)服务实现类
+ *
+ * @author makejava
+ * @since 2020-10-28 16:51:30
+ */
+@Service("areaService")
+public class AreaServiceImpl implements AreaService {
+    @Autowired
+    private AreaMapper areaMapper;
+
+    /**
+     * 通过ID查询单条数据
+     *
+     * @param id 主键
+     * @return 实例对象
+     */
+    @Override
+    public Area selectById(Integer id) {
+        return this.areaMapper.selectById(id);
+    }
+
+
+    /**
+     * 查询所有
+     *
+     * @return 实例对象的集合
+     */
+    @Override
+    public List<Area> selectAll() {
+        return this.areaMapper.selectAll();
+    }
+
+    /**
+     * 根据条件查询
+     *
+     * @return 实例对象的集合
+     */
+    @Override
+    public List<Area> selectList(Area area) {
+        return this.areaMapper.selectList(area);
+    }
+
+    /**
+     * 新增数据
+     *
+     * @param area 实例对象
+     * @return 实例对象
+     */
+    @Override
+    public int insert(Area area) {
+        return this.areaMapper.insert(area);
+    }
+
+    /**
+     * 批量新增
+     *
+     * @param areas 实例对象的集合
+     * @return 生效的条数
+     */
+    @Override
+    public int batchInsert(List<Area> areas) {
+        return this.areaMapper.batchInsert(areas);
+    }
+
+    /**
+     * 修改数据
+     *
+     * @param area 实例对象
+     * @return 实例对象
+     */
+    @Override
+    public int update(Area area) {
+
+        return this.areaMapper.update(area);
+    }
+
+    /**
+     * 通过主键删除数据
+     *
+     * @param id 主键
+     * @return 是否成功
+     */
+    @Override
+    public int deleteById(Integer id) {
+        return this.areaMapper.deleteById(id);
+    }
+
+    /**
+     * 查询总数据数
+     *
+     * @return 数据总数
+     */
+    @Override
+    public int count() {
+        return this.areaMapper.count();
+    }
+
+    /**
+     * 分页查询
+     *
+     * @return 对象列表
+     */
+    @Override
+    public IPage<Area> selectPage(Area area, IPage<Area> page) {
+        return this.areaMapper.selectPage(page, area);
+    }
+}

+ 50 - 0
user_center/src/main/java/com/huaxu/service/impl/OrgServiceImpl.java

@@ -2,15 +2,21 @@ package com.huaxu.service.impl;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.huaxu.dao.OrgMapper;
+import com.huaxu.dto.OrgTree;
 import com.huaxu.dto.RoleRequestDto;
 import com.huaxu.entity.Org;
 import com.huaxu.model.LoginUser;
 import com.huaxu.service.OrgService;
 import com.huaxu.util.UserUtil;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
+
+import static com.google.common.collect.Lists.newArrayList;
 
 /**
  * 组织(Org表)服务实现类
@@ -90,6 +96,16 @@ public class OrgServiceImpl implements OrgService {
      */
     @Override
     public int update(Org org) {
+        Org orgType = orgMapper.findOrgType(org);
+        if(!orgType.getOrgType().equals(org.getOrgType())){
+            if(org.getOrgType().equals("department")
+                    &&orgType.getChildType().equals("company")){
+                    return -2;
+            }else if(org.getOrgType().equals("company")&&
+                      orgType.getParentType().equals("department")){
+                    return -3;
+            }
+        }
         //删除前先查询机构下是否还有用户
         if(org.getStatus()==-1){
             Org orgUser = orgMapper.findOrgUser(org);
@@ -134,4 +150,38 @@ public class OrgServiceImpl implements OrgService {
         org.setTenantId(currentUser.getTenantId());
         return this.orgMapper.selectPage(page, org);
     }
+
+    @Override
+    public List<OrgTree> getTrees(Org org) {
+        List<OrgTree> trees=orgMapper.selectTrees(org);
+        trees=getOrgTree(trees,0,1,new HashSet<>());
+        return trees;
+    }
+    public static List<OrgTree> getOrgTree(List<OrgTree> list, Integer id, Integer leve, Set<Integer> set) {
+        List<OrgTree> temList = newArrayList();
+        if (list != null) {
+            for (OrgTree orgTree : list) {
+
+                if (id.equals(orgTree.getParentOrgId())) {
+                    //拥有权限可以显示
+                    if(!set.contains(id)){
+                        orgTree.setDisplay(true);
+                    }
+                    List<OrgTree> chidren = getOrgTree(list, orgTree.getId(), ++leve,set);
+                    OrgTree temPermission = new OrgTree();
+                    BeanUtils.copyProperties(orgTree, temPermission);
+                    temPermission.setOrgs(chidren);
+                    temList.add(temPermission);
+                    leve--;
+                }
+
+            }
+        }
+        if (temList.size() > 0) {
+            return temList;
+        } else {
+            return null;
+        }
+    }
+
 }

+ 27 - 5
user_center/src/main/java/com/huaxu/service/impl/RoleServiceImpl.java

@@ -3,18 +3,17 @@ package com.huaxu.service.impl;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.api.R;
 import com.huaxu.dao.RoleMapper;
+import com.huaxu.dao.RoleMenuMapper;
 import com.huaxu.dao.RoleOrgMapper;
 import com.huaxu.dto.RoleDto;
 import com.huaxu.dto.RoleRequestDto;
-import com.huaxu.entity.Org;
-import com.huaxu.entity.Role;
-import com.huaxu.entity.RoleOrg;
-import com.huaxu.entity.UserEntity;
+import com.huaxu.entity.*;
 import com.huaxu.model.LoginUser;
 import com.huaxu.service.RoleService;
 import com.huaxu.util.UserUtil;
 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.List;
@@ -31,6 +30,8 @@ public class RoleServiceImpl implements RoleService {
     private RoleMapper roleMapper;
     @Autowired
     private RoleOrgMapper roleOrgMapper;
+    @Autowired
+    private RoleMenuMapper roleMenuMapper;
 
     /**
      * 通过ID查询单条数据
@@ -71,6 +72,7 @@ public class RoleServiceImpl implements RoleService {
      * @return 实例对象
      */
     @Override
+    @Transactional
     public int insert(RoleRequestDto roleRequestDto) {
         configDataPermission(roleRequestDto);
         Role role = roleRequestDto.getRole();
@@ -98,6 +100,7 @@ public class RoleServiceImpl implements RoleService {
      * @return 实例对象
      */
     @Override
+    @Transactional
     public int update(RoleRequestDto roleRequestDto) {
         Role role=roleRequestDto.getRole();
 
@@ -108,6 +111,8 @@ public class RoleServiceImpl implements RoleService {
             }
             //删除用户与角色的关系
             roleMapper.deleteRoleUser(role);
+            //删除用户与菜单关系
+            roleMapper.deleteRoleMenu(role);
         }
         LoginUser currentUser = UserUtil.getCurrentUser();
         role.setUpdateBy(currentUser.getUsername());
@@ -120,7 +125,7 @@ public class RoleServiceImpl implements RoleService {
             Integer roleId=roleRequestDto.getRole().getId();
             roleOrgDelete.setRoleId(roleId);
             roleOrgMapper.update(roleOrgDelete);
-            List<Integer> orgIds = roleRequestDto.getOrgIds();
+            List<Integer> orgIds = roleRequestDto.getIds();
             List<RoleOrg>roleOrgs=new ArrayList<>();
             orgIds.forEach(id->{
                 RoleOrg roleOrg = new RoleOrg();
@@ -169,4 +174,21 @@ public class RoleServiceImpl implements RoleService {
     public List<UserEntity> findUsersByRole(Role role) {
         return  roleMapper.findUsersByRole(role);
     }
+
+    @Override
+    @Transactional
+    public int updateRoleMenuRelations(RoleRequestDto dto) {
+        Integer roleId =dto.getRole().getId();
+        List<Integer> menuIds = dto.getIds();
+        List<RoleMenu>menus=new ArrayList<>();
+        roleMapper.deleteRoleMenu(dto.getRole());
+        menuIds.forEach(id->{
+            RoleMenu roleMenu=new RoleMenu();
+            roleMenu.setRoleId(roleId);
+            roleMenu.setMenuId(id);
+            menus.add(roleMenu);
+        });
+        roleMenuMapper.batchInsert(menus);
+        return 0;
+    }
 }

+ 16 - 5
user_center/src/main/java/com/huaxu/service/impl/UserGroupServiceImpl.java

@@ -3,16 +3,15 @@ package com.huaxu.service.impl;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.huaxu.dao.GroupUserMapper;
 import com.huaxu.dao.UserGroupMapper;
+import com.huaxu.dao.UserRoleMapper;
 import com.huaxu.dto.UserGroupDto;
-import com.huaxu.entity.GroupUser;
-import com.huaxu.entity.Org;
-import com.huaxu.entity.UserEntity;
-import com.huaxu.entity.UserGroup;
+import com.huaxu.entity.*;
 import com.huaxu.model.LoginUser;
 import com.huaxu.service.UserGroupService;
 import com.huaxu.util.UserUtil;
 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.List;
@@ -30,6 +29,9 @@ public class UserGroupServiceImpl implements UserGroupService {
     @Autowired
     private GroupUserMapper groupUserMapper;
 
+
+
+
     /**
      * 通过ID查询单条数据
      *
@@ -94,6 +96,7 @@ public class UserGroupServiceImpl implements UserGroupService {
      * @return 实例对象
      */
     @Override
+    @Transactional
     public int update(UserGroup userGroup) {
         if(userGroup.getStatus()==-1){
             UserGroup hasUserGroupUsers = userGroupMapper.findHasUserGroupUsers(userGroup);
@@ -148,19 +151,27 @@ public class UserGroupServiceImpl implements UserGroupService {
     }
 
     @Override
+    @Transactional
     public int updateRolesByUserGroup(UserGroupDto userGroupDto) {
         UserGroup userGroup=new UserGroup();
         Integer groupId=userGroupDto.getGroupId();
         userGroup.setId(groupId);
         userGroupMapper.deleteUserGroupRelations(userGroup);
-        List<Integer> userIds = userGroupDto.getUserIds();
+        List<Long> userIds = userGroupDto.getUserIds();
         List<GroupUser>groupUsers=new ArrayList<>();
+        List<UserRoleEntity>userRoleEntities=new ArrayList<>();
         userIds.forEach(id->{
             GroupUser user=new GroupUser();
             user.setUserId(id);
             user.setGroupId(groupId);
+            UserRoleEntity userRoleEntity=new UserRoleEntity();
+            userRoleEntity.setRoleId(userGroupDto.getRoleId());
+            userRoleEntity.setUserId(id);
             groupUsers.add(user);
+            userRoleEntities.add(userRoleEntity);
         });
+        userGroupMapper.deleteUserRoles(userGroupDto);
+        userGroupMapper.batchInsertRoles(userRoleEntities);
         groupUserMapper.batchInsert(groupUsers);
         return 0;
     }

+ 2 - 2
user_center/src/main/resources/application-dev.properties

@@ -7,10 +7,10 @@ spring.datasource.url=jdbc:mysql://114.135.61.188:33306/uims?characterEncoding=u
 spring.datasource.username=root
 spring.datasource.password=100Zone@123
 spring.datasource.driver-class-name=com.mysql.jdbc.Driver
-
+spring.datasource.hikari.max-lifetime=30000
 mybatis-plus.mapper-locations=classpath:mapper/*.xml
 mybatis-plus.type-aliases-package=com.huaxu.entity
-mybatis-plus.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
+mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
 mybatis-plus.global-config.db-config.logic-delete-value=0 
 mybatis-plus.global-config.db-config.logic-not-delete-value=1
 spring.jackson.time-zone=GMT+8

+ 227 - 0
user_center/src/main/resources/mapper/AreaMapper.xml

@@ -0,0 +1,227 @@
+<?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.huaxu.dao.AreaMapper">
+    <!-- 结果集 -->
+    <resultMap type="com.huaxu.entity.Area" id="AreaMap">
+        <result property="id" column="id" jdbcType="INTEGER"/>
+        <result property="parentId" column="parent_id" jdbcType="INTEGER"/>
+        <result property="name" column="name" jdbcType="VARCHAR"/>
+        <result property="mangerName" column="manger_name" jdbcType="VARCHAR"/>
+        <result property="shortName" column="short_name" jdbcType="VARCHAR"/>
+        <result property="mangerShortName" column="manger_short_name" jdbcType="VARCHAR"/>
+        <result property="levelType" column="level_type" jdbcType="INTEGER"/>
+        <result property="cityCode" column="city_code" jdbcType="VARCHAR"/>
+        <result property="zipCode" column="zip_code" jdbcType="VARCHAR"/>
+        <result property="pinYin" column="pin_yin" jdbcType="VARCHAR"/>
+        <result property="jianPin" column="jian_pin" jdbcType="VARCHAR"/>
+        <result property="firstChar" column="first_char" jdbcType="VARCHAR"/>
+        <result property="lng" column="lng" jdbcType="VARCHAR"/>
+        <result property="lat" column="lat" jdbcType="VARCHAR"/>
+        <result property="remark" column="remark" jdbcType="VARCHAR"/>
+    </resultMap>
+
+    <!-- 基本字段 -->
+    <sql id="Base_Column_List">
+        id, parent_id, name, manger_name, short_name, manger_short_name, level_type, city_code, zip_code, pin_yin, jian_pin, first_char, lng, lat, remark    </sql>
+
+    <!-- 查询单个 -->
+    <select id="selectById" resultMap="AreaMap">
+        select
+        <include refid="Base_Column_List"/>
+        from uims_area
+        where id = #{id}
+    </select>
+
+
+    <!-- 查询全部 -->
+    <select id="selectAll" resultMap="AreaMap">
+        select
+        <include refid="Base_Column_List"/>
+        from uims_area
+    </select>
+
+    <!--通过实体作为筛选条件查询-->
+    <select id="selectList" resultMap="AreaMap">
+        select
+        <include refid="Base_Column_List"/>
+        from uims_area
+        <where>
+            <if test="id != null">
+                and id = #{id}
+            </if>
+            <if test="parentId != null">
+                and parent_id = #{parentId}
+            </if>
+            <if test="name != null and name != ''">
+                and name = #{name}
+            </if>
+            <if test="mangerName != null and mangerName != ''">
+                and manger_name = #{mangerName}
+            </if>
+            <if test="shortName != null and shortName != ''">
+                and short_name = #{shortName}
+            </if>
+            <if test="mangerShortName != null and mangerShortName != ''">
+                and manger_short_name = #{mangerShortName}
+            </if>
+            <if test="levelType != null">
+                and level_type = #{levelType}
+            </if>
+            <if test="cityCode != null and cityCode != ''">
+                and city_code = #{cityCode}
+            </if>
+            <if test="zipCode != null and zipCode != ''">
+                and zip_code = #{zipCode}
+            </if>
+            <if test="pinYin != null and pinYin != ''">
+                and pin_yin = #{pinYin}
+            </if>
+            <if test="jianPin != null and jianPin != ''">
+                and jian_pin = #{jianPin}
+            </if>
+            <if test="firstChar != null and firstChar != ''">
+                and first_char = #{firstChar}
+            </if>
+            <if test="lng != null and lng != ''">
+                and lng = #{lng}
+            </if>
+            <if test="lat != null and lat != ''">
+                and lat = #{lat}
+            </if>
+            <if test="remark != null and remark != ''">
+                and remark = #{remark}
+            </if>
+        </where>
+    </select>
+
+    <!-- 新增所有列 -->
+    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
+        insert into uims_area(id, parent_id, name, manger_name, short_name, manger_short_name, level_type, city_code, zip_code, pin_yin, jian_pin, first_char, lng, lat, remark)
+        values ( #{id}, #{parentId}, #{name}, #{mangerName}, #{shortName}, #{mangerShortName}, #{levelType}, #{cityCode}, #{zipCode}, #{pinYin}, #{jianPin}, #{firstChar}, #{lng}, #{lat}, #{remark})
+    </insert>
+
+    <!-- 批量新增 -->
+    <insert id="batchInsert">
+        insert into uims_area(id, parent_id, name, manger_name, short_name, manger_short_name, level_type, city_code,
+        zip_code, pin_yin, jian_pin, first_char, lng, lat, remark)
+        values
+        <foreach collection="areas" item="item" index="index" separator=",">
+            (
+            #{item.id}, #{item.parentId}, #{item.name}, #{item.mangerName}, #{item.shortName}, #{item.mangerShortName},
+            #{item.levelType}, #{item.cityCode}, #{item.zipCode}, #{item.pinYin}, #{item.jianPin}, #{item.firstChar},
+            #{item.lng}, #{item.lat}, #{item.remark} )
+        </foreach>
+    </insert>
+
+    <!-- 通过主键修改数据 -->
+    <update id="update">
+        update uims.uims_area
+        <set>
+            <if test="parentId != null">
+                parent_id = #{parentId},
+            </if>
+            <if test="name != null and name != ''">
+                name = #{name},
+            </if>
+            <if test="mangerName != null and mangerName != ''">
+                manger_name = #{mangerName},
+            </if>
+            <if test="shortName != null and shortName != ''">
+                short_name = #{shortName},
+            </if>
+            <if test="mangerShortName != null and mangerShortName != ''">
+                manger_short_name = #{mangerShortName},
+            </if>
+            <if test="levelType != null">
+                level_type = #{levelType},
+            </if>
+            <if test="cityCode != null and cityCode != ''">
+                city_code = #{cityCode},
+            </if>
+            <if test="zipCode != null and zipCode != ''">
+                zip_code = #{zipCode},
+            </if>
+            <if test="pinYin != null and pinYin != ''">
+                pin_yin = #{pinYin},
+            </if>
+            <if test="jianPin != null and jianPin != ''">
+                jian_pin = #{jianPin},
+            </if>
+            <if test="firstChar != null and firstChar != ''">
+                first_char = #{firstChar},
+            </if>
+            <if test="lng != null and lng != ''">
+                lng = #{lng},
+            </if>
+            <if test="lat != null and lat != ''">
+                lat = #{lat},
+            </if>
+            <if test="remark != null and remark != ''">
+                remark = #{remark},
+            </if>
+        </set>
+        where id = #{id}
+    </update>
+
+    <!--通过主键删除-->
+    <delete id="deleteById">
+        delete from uims_area where id = #{id}
+    </delete>
+
+    <!-- 总数 -->
+    <select id="count" resultType="int">
+        select count(*) from uims_area
+    </select>
+    <select id="selectPage" resultMap="AreaMap">
+        select
+        <include refid="Base_Column_List"/>
+        from uims_area
+        <where>
+            <if test="area.id != null">
+                and id = #{area.id}
+            </if>
+            <if test="area.parentId != null">
+                and parent_id = #{area.parentId}
+            </if>
+            <if test="area.name != null and area.name != ''">
+                and name = #{area.name}
+            </if>
+            <if test="area.mangerName != null and area.mangerName != ''">
+                and manger_name = #{area.mangerName}
+            </if>
+            <if test="area.shortName != null and area.shortName != ''">
+                and short_name = #{area.shortName}
+            </if>
+            <if test="area.mangerShortName != null and area.mangerShortName != ''">
+                and manger_short_name = #{area.mangerShortName}
+            </if>
+            <if test="area.levelType != null">
+                and level_type = #{area.levelType}
+            </if>
+            <if test="area.cityCode != null and area.cityCode != ''">
+                and city_code = #{area.cityCode}
+            </if>
+            <if test="area.zipCode != null and area.zipCode != ''">
+                and zip_code = #{area.zipCode}
+            </if>
+            <if test="area.pinYin != null and area.pinYin != ''">
+                and pin_yin = #{area.pinYin}
+            </if>
+            <if test="area.jianPin != null and area.jianPin != ''">
+                and jian_pin = #{area.jianPin}
+            </if>
+            <if test="area.firstChar != null and area.firstChar != ''">
+                and first_char = #{area.firstChar}
+            </if>
+            <if test="area.lng != null and area.lng != ''">
+                and lng = #{area.lng}
+            </if>
+            <if test="area.lat != null and area.lat != ''">
+                and lat = #{area.lat}
+            </if>
+            <if test="area.remark != null and area.remark != ''">
+                and remark = #{area.remark}
+            </if>
+        </where>
+    </select>
+</mapper>

+ 29 - 4
user_center/src/main/resources/mapper/OrgMapper.xml

@@ -20,6 +20,10 @@
         <result property="createBy" column="CREATE_BY" jdbcType="VARCHAR"/>
         <result property="dateUpdate" column="DATE_UPDATE" jdbcType="TIMESTAMP"/>
         <result property="updateBy" column="UPDATE_BY" jdbcType="VARCHAR"/>
+        <result property="parentId" column="parentId" jdbcType="INTEGER"/>
+        <result property="parentName" column="parentName" jdbcType="VARCHAR"/>
+        <result property="areaName" column="areaName" jdbcType="VARCHAR"/>
+
     </resultMap>
 
     <!-- 基本字段 -->
@@ -28,10 +32,11 @@
 
     <!-- 查询单个 -->
     <select id="selectById" resultMap="OrgMap">
-        select
-        <include refid="Base_Column_List"/>
-        from uims_org
-        where ID = #{id}
+        select   a.id, a.tenant_id, a.org_type, a.parent_org_id, a.org_area_id, a.org_name, a.org_state, a.remark, a.org_leader_name, a.org_leader_phone, a.org_leader_email, a.org_leader_sex, a.status
+        ,b.id parentId,b.ORG_NAME parentName,c.NAME areaName
+        from uims_org a left join uims_org b on a.PARENT_ORG_ID=b.ID
+        left join uims_area c on a.ORG_AREA_ID=c.id
+        where a.ID = #{id}
     </select>
 
 
@@ -46,6 +51,7 @@
     <select id="selectList" resultMap="OrgMap">
         select
         <include refid="Base_Column_List"/>
+
         from uims_org
         <where>
             <if test="id != null">
@@ -252,4 +258,23 @@
          where a.id=#{id} and b.status!=-1
          limit 1
     </select>
+    <select id="selectTrees" resultType="com.huaxu.dto.OrgTree">
+          select ID, TENANT_ID, PARENT_ORG_ID,ORG_NAME
+           from uims_org
+           <where>
+               <if test="tenantId!=null ">
+                   TENANT_ID=#{tenantId}
+               </if>
+               <if test="orgType=='company'">
+                   ORG_TYPE=#{orgType}
+               </if>
+           </where>
+
+    </select>
+    <select id="findOrgType" resultType="com.huaxu.entity.Org">
+        select a.ORG_TYPE ,  b.ORG_TYPE parentType,c.ORG_TYPE childType
+         from uims_org a left join uims_org b on a.PARENT_ORG_ID=b.ID
+        left join uims_org c on a.id=c.PARENT_ORG_ID
+        where a.id=#{id}
+    </select>
 </mapper>

+ 6 - 2
user_center/src/main/resources/mapper/RoleMapper.xml

@@ -156,6 +156,7 @@
     </delete>
 
 
+
     <!-- 总数 -->
     <select id="count" resultType="int">
         select count(*) from uims_role
@@ -165,7 +166,7 @@
         <include refid="Base_Column_List"/>,users
         from uims_role a left join
         (select count(*) users ,ROLE_ID from uims_user a join uims_user_role b
-        where a.TENANT_ID=#{tenantId} group by b.ROLE_ID)
+        where a.TENANT_ID=#{role.tenantId} group by b.ROLE_ID) b
         ON a.id=b.ROLE_ID
         <where>
             <if test="role.id != null">
@@ -239,9 +240,12 @@
         select 	<include refid="userColumns"/>
          from uims_user_role b join uims_user a on b.USER_ID=a.ID
         <include refid="sysAreaJoins"/>
-        where a.ROLE_ID=#{id}
+        where b.ROLE_ID=#{id} and b.status!=-1
     </select>
     <update id="deleteRoleUser">
         update uims_user_role set status=-1 where ROLE_ID=#{id}
     </update>
+    <update id="deleteRoleMenu">
+        update uims_role_menu set status=-1 where ROLE_ID=#{id}
+    </update>
 </mapper>

+ 155 - 0
user_center/src/main/resources/mapper/RoleMenuMapper.xml

@@ -0,0 +1,155 @@
+<?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.huaxu.dao.RoleMenuMapper">
+    <!-- 结果集 -->
+    <resultMap type="com.huaxu.entity.RoleMenu" id="RoleMenuMap">
+        <result property="id" column="ID" jdbcType="INTEGER"/>
+        <result property="menuId" column="MENU_ID" jdbcType="INTEGER"/>
+        <result property="roleId" column="ROLE_ID" jdbcType="INTEGER"/>
+        <result property="status" column="STATUS" jdbcType="INTEGER"/>
+        <result property="dateCreate" column="DATE_CREATE" jdbcType="TIMESTAMP"/>
+        <result property="createBy" column="CREATE_BY" jdbcType="VARCHAR"/>
+        <result property="dateUpdate" column="DATE_UPDATE" jdbcType="TIMESTAMP"/>
+        <result property="updateBy" column="UPDATE_BY" jdbcType="VARCHAR"/>
+    </resultMap>
+
+    <!-- 基本字段 -->
+    <sql id="Base_Column_List">
+        ID, MENU_ID, ROLE_ID, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY    </sql>
+
+    <!-- 查询单个 -->
+    <select id="selectById" resultMap="RoleMenuMap">
+        select
+        <include refid="Base_Column_List"/>
+        from uims_role_menu
+        where ID = #{id}
+    </select>
+
+
+    <!-- 查询全部 -->
+    <select id="selectAll" resultMap="RoleMenuMap">
+        select
+        <include refid="Base_Column_List"/>
+        from uims_role_menu
+    </select>
+
+    <!--通过实体作为筛选条件查询-->
+    <select id="selectList" resultMap="RoleMenuMap">
+        select
+        <include refid="Base_Column_List"/>
+        from uims_role_menu
+        <where>
+            <if test="id != null">
+                and ID = #{id}
+            </if>
+            <if test="menuId != null">
+                and MENU_ID = #{menuId}
+            </if>
+            <if test="roleId != null">
+                and ROLE_ID = #{roleId}
+            </if>
+            <if test="status != null">
+                and STATUS = #{status}
+            </if>
+            <if test="dateCreate != null">
+                and DATE_CREATE = #{dateCreate}
+            </if>
+            <if test="createBy != null and createBy != ''">
+                and CREATE_BY = #{createBy}
+            </if>
+            <if test="dateUpdate != null">
+                and DATE_UPDATE = #{dateUpdate}
+            </if>
+            <if test="updateBy != null and updateBy != ''">
+                and UPDATE_BY = #{updateBy}
+            </if>
+        </where>
+    </select>
+
+    <!-- 新增所有列 -->
+    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
+        insert into uims_role_menu(ID, MENU_ID, ROLE_ID, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY)
+        values ( #{id}, #{menuId}, #{roleId}, #{status}, #{dateCreate}, #{createBy}, #{dateUpdate}, #{updateBy})
+    </insert>
+
+    <!-- 批量新增 -->
+    <insert id="batchInsert">
+        insert into uims_role_menu(ID, MENU_ID, ROLE_ID, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY)
+        values
+        <foreach collection="roleMenus" item="item" index="index" separator=",">
+            (
+            #{item.id}, #{item.menuId}, #{item.roleId}, #{item.status}, #{item.dateCreate}, #{item.createBy},
+            #{item.dateUpdate}, #{item.updateBy} )
+        </foreach>
+    </insert>
+
+    <!-- 通过主键修改数据 -->
+    <update id="update">
+        update uims.uims_role_menu
+        <set>
+            <if test="menuId != null">
+                MENU_ID = #{menuId},
+            </if>
+            <if test="roleId != null">
+                ROLE_ID = #{roleId},
+            </if>
+            <if test="status != null">
+                STATUS = #{status},
+            </if>
+            <if test="dateCreate != null">
+                DATE_CREATE = #{dateCreate},
+            </if>
+            <if test="createBy != null and createBy != ''">
+                CREATE_BY = #{createBy},
+            </if>
+            <if test="dateUpdate != null">
+                DATE_UPDATE = #{dateUpdate},
+            </if>
+            <if test="updateBy != null and updateBy != ''">
+                UPDATE_BY = #{updateBy},
+            </if>
+        </set>
+        where ID = #{id}
+    </update>
+
+    <!--通过主键删除-->
+    <delete id="deleteById">
+        delete from uims_role_menu where ID = #{id}
+    </delete>
+
+    <!-- 总数 -->
+    <select id="count" resultType="int">
+        select count(*) from uims_role_menu
+    </select>
+    <select id="selectPage" resultMap="RoleMenuMap">
+        select
+        <include refid="Base_Column_List"/>
+        from uims_role_menu
+        <where>
+            <if test="roleMenu.id != null">
+                and ID = #{roleMenu.id}
+            </if>
+            <if test="roleMenu.menuId != null">
+                and MENU_ID = #{roleMenu.menuId}
+            </if>
+            <if test="roleMenu.roleId != null">
+                and ROLE_ID = #{roleMenu.roleId}
+            </if>
+            <if test="roleMenu.status != null">
+                and STATUS = #{roleMenu.status}
+            </if>
+            <if test="roleMenu.dateCreate != null">
+                and DATE_CREATE = #{roleMenu.dateCreate}
+            </if>
+            <if test="roleMenu.createBy != null and roleMenu.createBy != ''">
+                and CREATE_BY = #{roleMenu.createBy}
+            </if>
+            <if test="roleMenu.dateUpdate != null">
+                and DATE_UPDATE = #{roleMenu.dateUpdate}
+            </if>
+            <if test="roleMenu.updateBy != null and roleMenu.updateBy != ''">
+                and UPDATE_BY = #{roleMenu.updateBy}
+            </if>
+        </where>
+    </select>
+</mapper>

+ 33 - 6
user_center/src/main/resources/mapper/UserGroupMapper.xml

@@ -13,11 +13,12 @@
         <result property="createBy" column="CREATE_BY" jdbcType="VARCHAR"/>
         <result property="dateUpdate" column="DATE_UPDATE" jdbcType="TIMESTAMP"/>
         <result property="updateBy" column="UPDATE_BY" jdbcType="VARCHAR"/>
+        <result property="roleId" column="ROLE_ID" jdbcType="INTEGER"/>
     </resultMap>
 
     <!-- 基本字段 -->
     <sql id="Base_Column_List">
-        ID, TENANT_ID, GROUP_NAME, GROUP_STATE, REMARK, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY    </sql>
+        ID, TENANT_ID, GROUP_NAME, GROUP_STATE, REMARK, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY, ROLE_ID    </sql>
 
     <!-- 查询单个 -->
     <select id="selectById" resultMap="UserGroupMap">
@@ -71,24 +72,27 @@
             <if test="updateBy != null and updateBy != ''">
                 and UPDATE_BY = #{updateBy}
             </if>
+            <if test="roleId != null">
+                and ROLE_ID = #{roleId}
+            </if>
         </where>
     </select>
 
     <!-- 新增所有列 -->
     <insert id="insert" keyProperty="id" useGeneratedKeys="true">
-        insert into uims_user_group(ID, TENANT_ID, GROUP_NAME, GROUP_STATE, REMARK, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY)
-        values ( #{id}, #{tenantId}, #{groupName}, #{groupState}, #{remark}, #{status}, #{dateCreate}, #{createBy}, #{dateUpdate}, #{updateBy})
+        insert into uims_user_group(ID, TENANT_ID, GROUP_NAME, GROUP_STATE, REMARK, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY, ROLE_ID)
+        values ( #{id}, #{tenantId}, #{groupName}, #{groupState}, #{remark}, #{status}, #{dateCreate}, #{createBy}, #{dateUpdate}, #{updateBy}, #{roleId})
     </insert>
 
     <!-- 批量新增 -->
     <insert id="batchInsert">
         insert into uims_user_group(ID, TENANT_ID, GROUP_NAME, GROUP_STATE, REMARK, STATUS, DATE_CREATE, CREATE_BY,
-        DATE_UPDATE, UPDATE_BY)
+        DATE_UPDATE, UPDATE_BY, ROLE_ID)
         values
         <foreach collection="userGroups" item="item" index="index" separator=",">
             (
             #{item.id}, #{item.tenantId}, #{item.groupName}, #{item.groupState}, #{item.remark}, #{item.status},
-            #{item.dateCreate}, #{item.createBy}, #{item.dateUpdate}, #{item.updateBy} )
+            #{item.dateCreate}, #{item.createBy}, #{item.dateUpdate}, #{item.updateBy}, #{item.roleId} )
         </foreach>
     </insert>
 
@@ -123,6 +127,9 @@
             <if test="updateBy != null and updateBy != ''">
                 UPDATE_BY = #{updateBy},
             </if>
+            <if test="roleId != null">
+                ROLE_ID = #{roleId},
+            </if>
         </set>
         where ID = #{id}
     </update>
@@ -172,6 +179,9 @@
             <if test="userGroup.updateBy != null and userGroup.updateBy != ''">
                 and UPDATE_BY = #{userGroup.updateBy}
             </if>
+            <if test="userGroup.roleId != null">
+                and ROLE_ID = #{userGroup.roleId}
+            </if>
         </where>
     </select>
     <select id="findHasUserGroupUsers" resultType="com.huaxu.entity.UserGroup">
@@ -208,9 +218,26 @@
         select 	<include refid="userColumns"/>,b.id userGroupId
          from uims_user a left join uims_group_user b on a.id=b.USER_ID
         <include refid="sysAreaJoins"/>
-        where b.GROUP_ID=#{id}
+        where b.GROUP_ID=#{id} and b.status!=-1
     </select>
     <update id="deleteUserGroupRelations">
         update uims_group_user set STATUS=-1 where GROUP_ID=#{id}
     </update>
+    <update id="deleteUserRoles">
+       update uims_user_role set STATUS=-1 where USER_ID in
+        <foreach collection="userGroupDto.userIds" item="id" index="index" open="(" close=")" separator=",">
+            #{id}
+        </foreach>
+
+    </update>
+    <!-- 批量新增 -->
+    <insert id="batchInsertRoles">
+        insert into uims_user_role(ID, USER_ID, ROLE_ID, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY)
+        values
+        <foreach collection="uimsUserRoles" item="item" index="index" separator=",">
+            (
+            #{item.id}, #{item.userId}, #{item.roleId}, #{item.status}, #{item.dateCreate}, #{item.createBy},
+            #{item.dateUpdate}, #{item.updateBy} )
+        </foreach>
+    </insert>
 </mapper>

+ 156 - 0
user_center/src/main/resources/mapper/UserGroupRoleMapper.xml

@@ -0,0 +1,156 @@
+<?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.huaxu.dao.UserGroupRoleMapper">
+    <!-- 结果集 -->
+    <resultMap type="com.huaxu.entity.UserGroupRole" id="UserGroupRoleMap">
+        <result property="id" column="ID" jdbcType="INTEGER"/>
+        <result property="userGroupId" column="USER_GROUP_ID" jdbcType="INTEGER"/>
+        <result property="roleId" column="ROLE_ID" jdbcType="INTEGER"/>
+        <result property="status" column="STATUS" jdbcType="INTEGER"/>
+        <result property="dateCreate" column="DATE_CREATE" jdbcType="TIMESTAMP"/>
+        <result property="createBy" column="CREATE_BY" jdbcType="VARCHAR"/>
+        <result property="dateUpdate" column="DATE_UPDATE" jdbcType="TIMESTAMP"/>
+        <result property="updateBy" column="UPDATE_BY" jdbcType="VARCHAR"/>
+    </resultMap>
+
+    <!-- 基本字段 -->
+    <sql id="Base_Column_List">
+        ID, USER_GROUP_ID, ROLE_ID, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY    </sql>
+
+    <!-- 查询单个 -->
+    <select id="selectById" resultMap="UserGroupRoleMap">
+        select
+        <include refid="Base_Column_List"/>
+        from uims_user_group_role
+        where ID = #{id}
+    </select>
+
+
+    <!-- 查询全部 -->
+    <select id="selectAll" resultMap="UserGroupRoleMap">
+        select
+        <include refid="Base_Column_List"/>
+        from uims_user_group_role
+    </select>
+
+    <!--通过实体作为筛选条件查询-->
+    <select id="selectList" resultMap="UserGroupRoleMap">
+        select
+        <include refid="Base_Column_List"/>
+        from uims_user_group_role
+        <where>
+            <if test="id != null">
+                and ID = #{id}
+            </if>
+            <if test="userGroupId != null">
+                and USER_GROUP_ID = #{userGroupId}
+            </if>
+            <if test="roleId != null">
+                and ROLE_ID = #{roleId}
+            </if>
+            <if test="status != null">
+                and STATUS = #{status}
+            </if>
+            <if test="dateCreate != null">
+                and DATE_CREATE = #{dateCreate}
+            </if>
+            <if test="createBy != null and createBy != ''">
+                and CREATE_BY = #{createBy}
+            </if>
+            <if test="dateUpdate != null">
+                and DATE_UPDATE = #{dateUpdate}
+            </if>
+            <if test="updateBy != null and updateBy != ''">
+                and UPDATE_BY = #{updateBy}
+            </if>
+        </where>
+    </select>
+
+    <!-- 新增所有列 -->
+    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
+        insert into uims_user_group_role(ID, USER_GROUP_ID, ROLE_ID, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY)
+        values ( #{id}, #{userGroupId}, #{roleId}, #{status}, #{dateCreate}, #{createBy}, #{dateUpdate}, #{updateBy})
+    </insert>
+
+    <!-- 批量新增 -->
+    <insert id="batchInsert">
+        insert into uims_user_group_role(ID, USER_GROUP_ID, ROLE_ID, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE,
+        UPDATE_BY)
+        values
+        <foreach collection="userGroupRoles" item="item" index="index" separator=",">
+            (
+            #{item.id}, #{item.userGroupId}, #{item.roleId}, #{item.status}, #{item.dateCreate}, #{item.createBy},
+            #{item.dateUpdate}, #{item.updateBy} )
+        </foreach>
+    </insert>
+
+    <!-- 通过主键修改数据 -->
+    <update id="update">
+        update uims.uims_user_group_role
+        <set>
+            <if test="userGroupId != null">
+                USER_GROUP_ID = #{userGroupId},
+            </if>
+            <if test="roleId != null">
+                ROLE_ID = #{roleId},
+            </if>
+            <if test="status != null">
+                STATUS = #{status},
+            </if>
+            <if test="dateCreate != null">
+                DATE_CREATE = #{dateCreate},
+            </if>
+            <if test="createBy != null and createBy != ''">
+                CREATE_BY = #{createBy},
+            </if>
+            <if test="dateUpdate != null">
+                DATE_UPDATE = #{dateUpdate},
+            </if>
+            <if test="updateBy != null and updateBy != ''">
+                UPDATE_BY = #{updateBy},
+            </if>
+        </set>
+        where ID = #{id}
+    </update>
+
+    <!--通过主键删除-->
+    <delete id="deleteById">
+        delete from uims_user_group_role where ID = #{id}
+    </delete>
+
+    <!-- 总数 -->
+    <select id="count" resultType="int">
+        select count(*) from uims_user_group_role
+    </select>
+    <select id="selectPage" resultMap="UserGroupRoleMap">
+        select
+        <include refid="Base_Column_List"/>
+        from uims_user_group_role
+        <where>
+            <if test="userGroupRole.id != null">
+                and ID = #{userGroupRole.id}
+            </if>
+            <if test="userGroupRole.userGroupId != null">
+                and USER_GROUP_ID = #{userGroupRole.userGroupId}
+            </if>
+            <if test="userGroupRole.roleId != null">
+                and ROLE_ID = #{userGroupRole.roleId}
+            </if>
+            <if test="userGroupRole.status != null">
+                and STATUS = #{userGroupRole.status}
+            </if>
+            <if test="userGroupRole.dateCreate != null">
+                and DATE_CREATE = #{userGroupRole.dateCreate}
+            </if>
+            <if test="userGroupRole.createBy != null and userGroupRole.createBy != ''">
+                and CREATE_BY = #{userGroupRole.createBy}
+            </if>
+            <if test="userGroupRole.dateUpdate != null">
+                and DATE_UPDATE = #{userGroupRole.dateUpdate}
+            </if>
+            <if test="userGroupRole.updateBy != null and userGroupRole.updateBy != ''">
+                and UPDATE_BY = #{userGroupRole.updateBy}
+            </if>
+        </where>
+    </select>
+</mapper>

+ 25 - 0
user_center/src/test/com/huaxu/test/TestOrgTree.java

@@ -0,0 +1,25 @@
+package com.huaxu.test;
+
+import com.huaxu.dto.OrgTree;
+import com.huaxu.entity.Org;
+import com.huaxu.model.Permission;
+import com.huaxu.model.ProgramItem;
+import org.junit.Test;
+import org.springframework.beans.BeanUtils;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static com.google.common.collect.Lists.newArrayList;
+
+public class TestOrgTree {
+    @Test
+    public void test(){
+
+    }
+
+    public void getOrg(){
+
+    }
+}