diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/controller/sys/SysRoleController.java b/api-admin/src/main/java/com/glxp/udidl/admin/controller/sys/SysRoleController.java index 14b92da..ffe095c 100644 --- a/api-admin/src/main/java/com/glxp/udidl/admin/controller/sys/SysRoleController.java +++ b/api-admin/src/main/java/com/glxp/udidl/admin/controller/sys/SysRoleController.java @@ -1,6 +1,7 @@ package com.glxp.udidl.admin.controller.sys; import com.glxp.udidl.admin.annotation.AuthRuleAnnotation; +import com.glxp.udidl.admin.dto.sys.SysRoleMenuModel; import com.glxp.udidl.admin.dto.sys.SysRoleModel; import com.glxp.udidl.admin.dto.sys.SysRoleParam; import com.glxp.udidl.admin.service.sys.SysRoleService; @@ -42,4 +43,14 @@ public class SysRoleController { public BaseResponse delete(Integer id){ return sysRoleService.delete(id); } + @AuthRuleAnnotation("sys_role_all") + @PostMapping("/getRoleMenu") + public BaseResponse getRoleMenu(Integer roleId){ + return sysRoleService.getRoleMenu(roleId); + } + @AuthRuleAnnotation("sys_role_all") + @PostMapping("/saveRoleMenu") + public BaseResponse saveRoleMenu(@RequestBody SysRoleMenuModel model){ + return sysRoleService.saveRoleMenu(model); + } } diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/controller/sys/SysUserController.java b/api-admin/src/main/java/com/glxp/udidl/admin/controller/sys/SysUserController.java new file mode 100644 index 0000000..e88abd2 --- /dev/null +++ b/api-admin/src/main/java/com/glxp/udidl/admin/controller/sys/SysUserController.java @@ -0,0 +1,45 @@ +package com.glxp.udidl.admin.controller.sys; + +import com.glxp.udidl.admin.annotation.AuthRuleAnnotation; +import com.glxp.udidl.admin.dto.sys.SysUserModel; +import com.glxp.udidl.admin.dto.sys.SysUserParam; +import com.glxp.udidl.admin.service.sys.SysUserService; +import com.glxp.udidl.common.res.BaseResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("sys/user") +public class SysUserController { + @Autowired + SysUserService sysUserService; + + @AuthRuleAnnotation("sys_user_all") + @PostMapping("/list") + public BaseResponse getList(@RequestBody SysUserParam param){ + return sysUserService.list(param); + } + @AuthRuleAnnotation("sys_user_all") + @PostMapping("/insert") + public BaseResponse insert(@RequestBody SysUserModel model){ + return sysUserService.insert(model); + } + @AuthRuleAnnotation("sys_user_all") + @PostMapping("update") + public BaseResponse update(@RequestBody SysUserModel model){ + return sysUserService.update(model); + } + @AuthRuleAnnotation("sys_user_all") + @PostMapping("/detail") + public BaseResponse detail(Integer id){ + return sysUserService.detail(id); + } + @AuthRuleAnnotation("sys_user_all") + @PostMapping("/delete") + public BaseResponse delete(Integer id){ + return sysUserService.delete(id); + } +} diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/dao/sys/SysMenuMapper.java b/api-admin/src/main/java/com/glxp/udidl/admin/dao/sys/SysMenuMapper.java index db36dcb..f804ac7 100644 --- a/api-admin/src/main/java/com/glxp/udidl/admin/dao/sys/SysMenuMapper.java +++ b/api-admin/src/main/java/com/glxp/udidl/admin/dao/sys/SysMenuMapper.java @@ -17,4 +17,5 @@ public interface SysMenuMapper { int updateByPrimaryKey(SysMenu record); int getChildCount(Integer parentId); + List selectActiveAll(); } \ No newline at end of file diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/dao/sys/SysRoleMenuMapper.java b/api-admin/src/main/java/com/glxp/udidl/admin/dao/sys/SysRoleMenuMapper.java index 93e1312..8b7190f 100644 --- a/api-admin/src/main/java/com/glxp/udidl/admin/dao/sys/SysRoleMenuMapper.java +++ b/api-admin/src/main/java/com/glxp/udidl/admin/dao/sys/SysRoleMenuMapper.java @@ -2,6 +2,7 @@ package com.glxp.udidl.admin.dao.sys; import com.glxp.udidl.admin.entity.sys.SysRoleMenu; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -11,4 +12,6 @@ public interface SysRoleMenuMapper { int insert(SysRoleMenu record); List selectAll(); + List selectByRoleId(@Param("roleId") Integer roleId); + int deleteByRoleId(@Param("roleId") Integer roleId); } \ No newline at end of file diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/dao/sys/SysUserMapper.java b/api-admin/src/main/java/com/glxp/udidl/admin/dao/sys/SysUserMapper.java index a85580b..b64bda4 100644 --- a/api-admin/src/main/java/com/glxp/udidl/admin/dao/sys/SysUserMapper.java +++ b/api-admin/src/main/java/com/glxp/udidl/admin/dao/sys/SysUserMapper.java @@ -1,5 +1,6 @@ package com.glxp.udidl.admin.dao.sys; +import com.glxp.udidl.admin.dto.sys.SysUserParam; import com.glxp.udidl.admin.entity.sys.SysUser; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -18,4 +19,5 @@ public interface SysUserMapper { int updateByPrimaryKey(SysUser record); int hasAuthPerms(@Param("userKey") String user_key, @Param("perms" ) String perms); + List list(SysUserParam param); } \ No newline at end of file diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/dto/sys/RoleMenuTreeModel.java b/api-admin/src/main/java/com/glxp/udidl/admin/dto/sys/RoleMenuTreeModel.java new file mode 100644 index 0000000..09491af --- /dev/null +++ b/api-admin/src/main/java/com/glxp/udidl/admin/dto/sys/RoleMenuTreeModel.java @@ -0,0 +1,13 @@ +package com.glxp.udidl.admin.dto.sys; + +import lombok.Builder; +import lombok.Data; + +import java.util.List; + +@Data +@Builder +public class RoleMenuTreeModel { + private List menuTrees; + private List roleMenuIds; +} diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/dto/sys/SysRoleMenuModel.java b/api-admin/src/main/java/com/glxp/udidl/admin/dto/sys/SysRoleMenuModel.java new file mode 100644 index 0000000..48552b7 --- /dev/null +++ b/api-admin/src/main/java/com/glxp/udidl/admin/dto/sys/SysRoleMenuModel.java @@ -0,0 +1,11 @@ +package com.glxp.udidl.admin.dto.sys; + +import lombok.Data; + +import java.util.List; + +@Data +public class SysRoleMenuModel { + private Integer roleId; + private List menuIds; +} diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/entity/sys/SysUser.java b/api-admin/src/main/java/com/glxp/udidl/admin/entity/sys/SysUser.java index 5542bd4..c01c2bd 100644 --- a/api-admin/src/main/java/com/glxp/udidl/admin/entity/sys/SysUser.java +++ b/api-admin/src/main/java/com/glxp/udidl/admin/entity/sys/SysUser.java @@ -1,5 +1,8 @@ package com.glxp.udidl.admin.entity.sys; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + import java.util.Date; /** @@ -8,6 +11,7 @@ import java.util.Date; * @author hong * @date 2022/01/17 */ +@Data public class SysUser { /** * 用户ID @@ -41,6 +45,7 @@ public class SysUser { /** * 创建时间 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") private Date createTime; /** @@ -48,7 +53,7 @@ public class SysUser { */ private Integer roleId; - private String Udplat_appId; - private String Udplat_secretKey; - private String Udplat_userName; + private String udplat_appId; + private String udplat_secretKey; + private String udplat_userName; } \ No newline at end of file diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/service/sys/SysMenuService.java b/api-admin/src/main/java/com/glxp/udidl/admin/service/sys/SysMenuService.java index 533f434..e9c1772 100644 --- a/api-admin/src/main/java/com/glxp/udidl/admin/service/sys/SysMenuService.java +++ b/api-admin/src/main/java/com/glxp/udidl/admin/service/sys/SysMenuService.java @@ -5,6 +5,7 @@ import com.glxp.udidl.common.res.BaseResponse; public interface SysMenuService { BaseResponse getMenuTree(); + BaseResponse getMenuTreeActive(); BaseResponse insert(SysMenuModel model); BaseResponse update(SysMenuModel model); BaseResponse detail(Integer id); diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/service/sys/SysRoleService.java b/api-admin/src/main/java/com/glxp/udidl/admin/service/sys/SysRoleService.java index 78d18f7..f06c856 100644 --- a/api-admin/src/main/java/com/glxp/udidl/admin/service/sys/SysRoleService.java +++ b/api-admin/src/main/java/com/glxp/udidl/admin/service/sys/SysRoleService.java @@ -1,5 +1,6 @@ package com.glxp.udidl.admin.service.sys; +import com.glxp.udidl.admin.dto.sys.SysRoleMenuModel; import com.glxp.udidl.admin.dto.sys.SysRoleModel; import com.glxp.udidl.admin.dto.sys.SysRoleParam; import com.glxp.udidl.common.res.BaseResponse; @@ -10,4 +11,6 @@ public interface SysRoleService { BaseResponse update(SysRoleModel model); BaseResponse detail(Integer id); BaseResponse delete(Integer id); + BaseResponse getRoleMenu(Integer roleId); + BaseResponse saveRoleMenu(SysRoleMenuModel model); } diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/service/sys/SysUserService.java b/api-admin/src/main/java/com/glxp/udidl/admin/service/sys/SysUserService.java new file mode 100644 index 0000000..2765c83 --- /dev/null +++ b/api-admin/src/main/java/com/glxp/udidl/admin/service/sys/SysUserService.java @@ -0,0 +1,13 @@ +package com.glxp.udidl.admin.service.sys; + +import com.glxp.udidl.admin.dto.sys.SysUserModel; +import com.glxp.udidl.admin.dto.sys.SysUserParam; +import com.glxp.udidl.common.res.BaseResponse; + +public interface SysUserService { + BaseResponse list(SysUserParam param); + BaseResponse insert(SysUserModel model); + BaseResponse update(SysUserModel model); + BaseResponse detail(Integer id); + BaseResponse delete(Integer id); +} diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/service/sys/impl/SysMenuServiceImpl.java b/api-admin/src/main/java/com/glxp/udidl/admin/service/sys/impl/SysMenuServiceImpl.java index fdb2416..51ad8ba 100644 --- a/api-admin/src/main/java/com/glxp/udidl/admin/service/sys/impl/SysMenuServiceImpl.java +++ b/api-admin/src/main/java/com/glxp/udidl/admin/service/sys/impl/SysMenuServiceImpl.java @@ -27,6 +27,12 @@ public class SysMenuServiceImpl implements SysMenuService { List resutl = getChild(menus, 0); return ResultVOUtils.success(resutl); } + @Override + public BaseResponse getMenuTreeActive(){ + List menus = sysMenuMapper.selectActiveAll(); + List resutl = getChild(menus, 0); + return ResultVOUtils.success(resutl); + } public BaseResponse insert(SysMenuModel model){ SysMenu sysMenu = new SysMenu(); BeanUtils.copyProperties(model,sysMenu); diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/service/sys/impl/SysRoleServiceImpl.java b/api-admin/src/main/java/com/glxp/udidl/admin/service/sys/impl/SysRoleServiceImpl.java index 9de6b03..be64f40 100644 --- a/api-admin/src/main/java/com/glxp/udidl/admin/service/sys/impl/SysRoleServiceImpl.java +++ b/api-admin/src/main/java/com/glxp/udidl/admin/service/sys/impl/SysRoleServiceImpl.java @@ -3,10 +3,12 @@ package com.glxp.udidl.admin.service.sys.impl; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.glxp.udidl.admin.dao.sys.SysRoleMapper; -import com.glxp.udidl.admin.dto.sys.SysRoleModel; -import com.glxp.udidl.admin.dto.sys.SysRoleParam; +import com.glxp.udidl.admin.dao.sys.SysRoleMenuMapper; +import com.glxp.udidl.admin.dto.sys.*; import com.glxp.udidl.admin.entity.sys.SysRole; +import com.glxp.udidl.admin.entity.sys.SysRoleMenu; import com.glxp.udidl.admin.res.PageSimpleResponse; +import com.glxp.udidl.admin.service.sys.SysMenuService; import com.glxp.udidl.admin.service.sys.SysRoleService; import com.glxp.udidl.common.res.BaseResponse; import com.glxp.udidl.common.util.ResultVOUtils; @@ -21,7 +23,10 @@ import java.util.List; public class SysRoleServiceImpl implements SysRoleService { @Autowired SysRoleMapper mapper; - + @Autowired + SysRoleMenuMapper sysRoleMenuMapper; + @Autowired + SysMenuService sysMenuService; @Override public BaseResponse list(SysRoleParam param) { PageHelper.startPage(param.getPage(), param.getLimit()); @@ -65,4 +70,22 @@ public class SysRoleServiceImpl implements SysRoleService { mapper.deleteByPrimaryKey(id); return ResultVOUtils.success(); } + + @Override + public BaseResponse getRoleMenu(Integer roleId) { + List menuTree =(List)sysMenuService.getMenuTreeActive().getData(); + List list = sysRoleMenuMapper.selectByRoleId(roleId); + return ResultVOUtils.success(RoleMenuTreeModel.builder().menuTrees(menuTree).roleMenuIds(list).build()); + } + @Override + public BaseResponse saveRoleMenu(SysRoleMenuModel model){ + sysRoleMenuMapper.deleteByRoleId(model.getRoleId()); + for(Integer menuId:model.getMenuIds()){ + SysRoleMenu roleMenu = new SysRoleMenu(); + roleMenu.setRoleId(model.getRoleId()); + roleMenu.setMenuId(menuId); + sysRoleMenuMapper.insert(roleMenu); + } + return ResultVOUtils.success(); + } } diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/service/sys/impl/SysUserServiceImpl.java b/api-admin/src/main/java/com/glxp/udidl/admin/service/sys/impl/SysUserServiceImpl.java new file mode 100644 index 0000000..8a4f8f7 --- /dev/null +++ b/api-admin/src/main/java/com/glxp/udidl/admin/service/sys/impl/SysUserServiceImpl.java @@ -0,0 +1,73 @@ +package com.glxp.udidl.admin.service.sys.impl; + +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.glxp.udidl.admin.dao.sys.SysUserMapper; +import com.glxp.udidl.admin.dto.sys.SysUserModel; +import com.glxp.udidl.admin.dto.sys.SysUserParam; +import com.glxp.udidl.admin.entity.sys.SysUser; +import com.glxp.udidl.admin.res.PageSimpleResponse; +import com.glxp.udidl.admin.service.sys.SysUserService; +import com.glxp.udidl.common.res.BaseResponse; +import com.glxp.udidl.common.util.ResultVOUtils; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; +import java.util.UUID; + +@Service +public class SysUserServiceImpl implements SysUserService { + @Autowired + SysUserMapper mapper; + @Override + public BaseResponse list(SysUserParam param) { + PageHelper.startPage(param.getPage(), param.getLimit()); + List list = mapper.list(param); + PageInfo pageInfo = new PageInfo<>(list); + PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); + pageSimpleResponse.setTotal(pageInfo.getTotal()); + pageSimpleResponse.setList(list); + return ResultVOUtils.success(pageSimpleResponse); + } + + @Override + public BaseResponse insert(SysUserModel model) { + SysUser sysUser = new SysUser(); + BeanUtils.copyProperties(model, sysUser); + sysUser.setCreateTime(new Date()); + sysUser.setUserKey(getUUId()); + mapper.insert(sysUser); + return ResultVOUtils.success(); + } + + @Override + public BaseResponse update(SysUserModel model) { + SysUser sysUser = mapper.selectByPrimaryKey(model.getId()); + if (sysUser == null) + return ResultVOUtils.error(-1, "找不到记录"); + BeanUtils.copyProperties(model, sysUser); + mapper.updateByPrimaryKey(sysUser); + return ResultVOUtils.success(); + } + + @Override + public BaseResponse detail(Integer id) { + SysUser sysUser = mapper.selectByPrimaryKey(id); + if (sysUser == null) + return ResultVOUtils.error(-1, "找不到记录"); + return ResultVOUtils.success(sysUser); + } + + @Override + public BaseResponse delete(Integer id) { + mapper.deleteByPrimaryKey(id); + return ResultVOUtils.success(); + } + private String getUUId() { + UUID uuid = UUID.randomUUID(); + return uuid.toString().replace("-", ""); + } +} diff --git a/api-admin/src/main/resources/mybatis/mapper/sys/SysMenuMapper.xml b/api-admin/src/main/resources/mybatis/mapper/sys/SysMenuMapper.xml index 11ef354..b6823e9 100644 --- a/api-admin/src/main/resources/mybatis/mapper/sys/SysMenuMapper.xml +++ b/api-admin/src/main/resources/mybatis/mapper/sys/SysMenuMapper.xml @@ -39,10 +39,13 @@ where id = #{id,jdbcType=INTEGER} + \ No newline at end of file diff --git a/api-admin/src/main/resources/mybatis/mapper/sys/SysRoleMenuMapper.xml b/api-admin/src/main/resources/mybatis/mapper/sys/SysRoleMenuMapper.xml index a27b820..d96ae00 100644 --- a/api-admin/src/main/resources/mybatis/mapper/sys/SysRoleMenuMapper.xml +++ b/api-admin/src/main/resources/mybatis/mapper/sys/SysRoleMenuMapper.xml @@ -9,8 +9,19 @@ insert into sys_role_menu (role_id, menu_id) values (#{roleId,jdbcType=INTEGER}, #{menuId,jdbcType=INTEGER}) + + delete + from sys_role_menu + where role_id=#{roleId} + + \ No newline at end of file diff --git a/api-admin/src/main/resources/mybatis/mapper/sys/SysUserMapper.xml b/api-admin/src/main/resources/mybatis/mapper/sys/SysUserMapper.xml index 8024133..ffc4442 100644 --- a/api-admin/src/main/resources/mybatis/mapper/sys/SysUserMapper.xml +++ b/api-admin/src/main/resources/mybatis/mapper/sys/SysUserMapper.xml @@ -6,9 +6,9 @@ - - - + + + @@ -19,22 +19,21 @@ where id = #{id,jdbcType=INTEGER} - insert into sys_user (id, user_key, user_name, Udplat_appId,Udplat_secretKey,Udplat_userName - nick_name, password, sort, create_time, + insert into sys_user (id, user_key, user_name, udplat_appId,udplat_secretKey,udplat_userName + nick_name, password, status, create_time, role_id) values (#{id,jdbcType=INTEGER}, #{userKey,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR}, - #{Udplat_appId,jdbcType=VARCHAR}, #{Udplat_secretKey,jdbcType=VARCHAR}, #{Udplat_userName,jdbcType=VARCHAR}, - #{nickName,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},#{sort,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, + #{udplat_appId,jdbcType=VARCHAR}, #{udplat_secretKey,jdbcType=VARCHAR}, #{udplat_userName,jdbcType=VARCHAR}, + #{nickName,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},#{status,jdbcType=CHAR}, #{createTime,jdbcType=TIMESTAMP}, #{roleId,jdbcType=INTEGER}) update sys_user - set user_key = #{userKey,jdbcType=VARCHAR}, - user_name = #{userName,jdbcType=VARCHAR}, + set user_name = #{userName,jdbcType=VARCHAR}, nick_name = #{nickName,jdbcType=VARCHAR}, - Udplat_appId = #{Udplat_appId,jdbcType=VARCHAR}, - Udplat_secretKey = #{Udplat_secretKey,jdbcType=VARCHAR}, - Udplat_userName = #{Udplat_userName,jdbcType=VARCHAR}, + udplat_appId = #{udplat_appId,jdbcType=VARCHAR}, + udplat_secretKey = #{udplat_secretKey,jdbcType=VARCHAR}, + udplat_userName = #{udplat_userName,jdbcType=VARCHAR}, status = #{status,jdbcType=CHAR}, password = #{password,jdbcType=VARCHAR}, role_id = #{roleId,jdbcType=INTEGER} @@ -53,6 +52,17 @@ SELECT count(u.id) FROM `sys_user` as u LEFT JOIN sys_role r on u.role_id=r.id LEFT JOIN sys_role_menu rm on r.id=rm.role_id LEFT JOIN sys_menu m on rm.menu_id=m.id - where u.user_key= #{userKey,jdbcType=VARCHAR} and m.perms= #{perms,jdbcType=VARCHAR} + where u.user_key= #{userKey,jdbcType=VARCHAR} and m.perms= #{perms,jdbcType=VARCHAR} and m.status='0' + + \ No newline at end of file