Commit 0f29cd3995d28921d7d22501aabc73e33628344a

Authored by maliang
1 parent adba8e2709
Exists in master

添加角色基础信息操作

Showing 14 changed files with 303 additions and 128 deletions

center.manager/src/main/java/com/lyms/cm/controller/sys/SysUsersController.java View file @ 0f29cd3
... ... @@ -41,9 +41,10 @@
41 41 * @return
42 42 */
43 43 @RequestMapping(value = "/create", method = RequestMethod.POST)
44   - public String create(SysUsers user) {
45   - boolean tag = userService.addUser(user);
46   - return null;
  44 + @ResponseBody
  45 + public AjaxResult create(SysUsers user, AjaxResult ajaxResult) {
  46 + boolean tag = userService.updateUser(user);
  47 + return handleAjaxResult(ajaxResult, tag, OperationName.UPDATE);
47 48 }
48 49  
49 50 /**
... ... @@ -92,6 +93,18 @@
92 93 boolean tag = userService.updateUser(user);
93 94 return handleAjaxResult(ajaxResult, tag, OperationName.UPDATE);
94 95  
  96 + }
  97 +
  98 + /**
  99 + * 删除用户
  100 + *
  101 + * @return
  102 + */
  103 + @RequestMapping(value = "/{id}/delete", method = { RequestMethod.GET, RequestMethod.POST })
  104 + @ResponseBody
  105 + public AjaxResult del(@PathVariable String id, AjaxResult ajaxResult) {
  106 + boolean tag = userService.delete(id);
  107 + return handleAjaxResult(ajaxResult, tag, OperationName.DELETE);
95 108 }
96 109  
97 110 }
center.manager/src/main/java/com/lyms/cm/entity/sys/SysRoles.java View file @ 0f29cd3
1 1 package com.lyms.cm.entity.sys;
2 2  
3   -
4   -import com.baomidou.mybatisplus.annotations.TableName;
5   -import com.baomidou.mybatisplus.annotations.TableField;
6 3 import java.io.Serializable;
7 4 import java.util.Date;
8 5  
  6 +import com.baomidou.mybatisplus.annotations.TableField;
  7 +import com.baomidou.mybatisplus.annotations.TableName;
  8 +import com.lyms.cm.enums.StatusEnum;
  9 +
9 10 /**
10 11 * <p>
11 12 * 角色表
12 13  
13 14  
14 15  
15 16  
16 17  
17 18  
18 19  
19 20  
20 21  
21 22  
22 23  
23 24  
... ... @@ -17,65 +18,64 @@
17 18 @TableName("SYS_ROLES")
18 19 public class SysRoles implements Serializable {
19 20  
20   - private static final long serialVersionUID = 1L;
  21 + private static final long serialVersionUID = 1L;
21 22  
22 23 /**
23 24 *
24 25 */
25   - @TableField(value="ID")
  26 + @TableField(value = "ID")
26 27 private String id;
27 28 /**
28 29 * 0:管理员角色,1:用户角色
29 30 */
30   - @TableField(value="TYPE")
  31 + @TableField(value = "TYPE")
31 32 private Integer type;
32 33 /**
33 34 * 角色名称
34 35 */
35   - @TableField(value="NAME")
  36 + @TableField(value = "NAME")
36 37 private String name;
37 38 /**
38 39 *
39 40 */
40   - @TableField(value="PUBLISH_ID")
  41 + @TableField(value = "PUBLISH_ID")
41 42 private String publishId;
42 43 /**
43 44 * 1:启用,2:停用
44 45 */
45   - @TableField(value="ENABLE")
  46 + @TableField(value = "ENABLE")
46 47 private Integer enable;
47 48 /**
48 49 * 1:有效,2:无效
49 50 */
50   - @TableField(value="YN")
  51 + @TableField(value = "YN")
51 52 private Integer yn;
52 53 /**
53 54 * 备注
54 55 */
55   - @TableField(value="REMARKS")
  56 + @TableField(value = "REMARKS")
56 57 private String remarks;
57 58 /**
58 59 * 简码
59 60 */
60   - @TableField(value="SHORT_CODE")
  61 + @TableField(value = "SHORT_CODE")
61 62 private String shortCode;
62 63 /**
63 64 * 机构id
64 65 */
65   - @TableField(value="ORG_ID")
  66 + @TableField(value = "ORG_ID")
66 67 private String orgId;
67 68 /**
68 69 *
69 70 */
70   - @TableField(value="CREATED")
  71 + @TableField(value = "CREATED")
71 72 private Date created;
72 73 /**
73 74 *
74 75 */
75   - @TableField(value="MODIFIED")
  76 + @TableField(value = "MODIFIED")
76 77 private Date modified;
77 78  
78   -
79 79 public String getId() {
80 80 return id;
81 81 }
... ... @@ -162,6 +162,10 @@
162 162  
163 163 public void setModified(Date modified) {
164 164 this.modified = modified;
  165 + }
  166 +
  167 + public boolean isEnable() {
  168 + return StatusEnum.isEnabled(this.getEnable());
165 169 }
166 170  
167 171 }
center.manager/src/main/java/com/lyms/cm/entity/sys/SysUsers.java View file @ 0f29cd3
... ... @@ -5,9 +5,9 @@
5 5  
6 6 import com.baomidou.mybatisplus.annotations.TableField;
7 7 import com.baomidou.mybatisplus.annotations.TableName;
8   -import com.lyms.cm.enums.UserStatusEnum;
9   -import com.lyms.cm.enums.UserTypeEnum;
10   -import com.lyms.cm.enums.UserValidityEnum;
  8 +import com.lyms.cm.enums.StatusEnum;
  9 +import com.lyms.cm.enums.TypeEnum;
  10 +import com.lyms.cm.enums.ValidityEnum;
11 11  
12 12 /**
13 13 * <p>
14 14  
... ... @@ -37,10 +37,10 @@
37 37 /**
38 38 * 0:管理员,1:用户
39 39 * <p>
40   - * {@link UserTypeEnum#MANAGER} OR {@link UserTypeEnum#USER}
  40 + * {@link TypeEnum#MANAGER} OR {@link TypeEnum#USER}
41 41 */
42 42 @TableField(value = "TYPE")
43   - private Integer type = UserTypeEnum.USER.getType();
  43 + private Integer type = TypeEnum.USER.getType();
44 44 /**
45 45 * 机构id
46 46 */
47 47  
48 48  
49 49  
... ... @@ -79,17 +79,17 @@
79 79 /**
80 80 * 1:有效,2:无效
81 81 * <p>
82   - * {@link UserValidityEnum#VALIDITY} OR {@link UserValidityEnum#UNVALIDITY}
  82 + * {@link ValidityEnum#VALIDITY} OR {@link ValidityEnum#UNVALIDITY}
83 83 */
84 84 @TableField(value = "YN")
85   - private Integer yn = UserValidityEnum.VALIDITY.getValidity();
  85 + private Integer yn = ValidityEnum.VALIDITY.getValidity();
86 86 /**
87 87 * 1:启用,2:停用
88 88 * <p>
89   - * {@link UserStatusEnum#ENABLED} OR {@link UserStatusEnum#DISENABLED}
  89 + * {@link StatusEnum#ENABLED} OR {@link StatusEnum#DISENABLED}
90 90 */
91 91 @TableField(value = "ENABLE")
92   - private Integer enable = UserStatusEnum.ENABLED.getStatus();
  92 + private Integer enable = StatusEnum.ENABLED.getStatus();
93 93 /**
94 94 * 最后修改时间
95 95 */
... ... @@ -336,7 +336,7 @@
336 336 }
337 337  
338 338 public boolean isEnabled() {
339   - return UserStatusEnum.isEnabled(this.getEnable());
  339 + return StatusEnum.isEnabled(this.getEnable());
340 340 }
341 341  
342 342 }
center.manager/src/main/java/com/lyms/cm/enums/StatusEnum.java View file @ 0f29cd3
  1 +package com.lyms.cm.enums;
  2 +
  3 +/**
  4 + * 用户状态标识
  5 + *
  6 + * @author maliang
  7 + *
  8 + */
  9 +public enum StatusEnum {
  10 +
  11 + // 启用
  12 + ENABLED(1),
  13 + // 禁用
  14 + DISENABLED(2);
  15 +
  16 + private int status;
  17 +
  18 + private StatusEnum(int status) {
  19 + this.status = status;
  20 + }
  21 +
  22 + public int getStatus() {
  23 + return this.status;
  24 + }
  25 +
  26 + public static boolean isEnabled(Integer status) {
  27 + return status != null && ENABLED.getStatus() == status;
  28 + }
  29 +
  30 + public static boolean isDisEnabled(Integer status) {
  31 + return status != null && DISENABLED.getStatus() == status;
  32 + }
  33 +
  34 +}
center.manager/src/main/java/com/lyms/cm/enums/TypeEnum.java View file @ 0f29cd3
  1 +package com.lyms.cm.enums;
  2 +
  3 +/**
  4 + * 用户类型
  5 + *
  6 + * @author maliang
  7 + *
  8 + */
  9 +public enum TypeEnum {
  10 +
  11 + // 管理员
  12 + MANAGER(0),
  13 + // 用户
  14 + USER(1);
  15 +
  16 + private int type;
  17 +
  18 + private TypeEnum(int type) {
  19 + this.type = type;
  20 + }
  21 +
  22 + /**
  23 + * 获取类型
  24 + *
  25 + * @return
  26 + */
  27 + public int getType() {
  28 + return this.type;
  29 + }
  30 +
  31 +}
center.manager/src/main/java/com/lyms/cm/enums/UserStatusEnum.java View file @ 0f29cd3
1   -package com.lyms.cm.enums;
2   -
3   -/**
4   - * 用户状态标识
5   - *
6   - * @author maliang
7   - *
8   - */
9   -public enum UserStatusEnum {
10   -
11   - // 启用
12   - ENABLED(1),
13   - // 禁用
14   - DISENABLED(2);
15   -
16   - private int status;
17   -
18   - private UserStatusEnum(int status) {
19   - this.status = status;
20   - }
21   -
22   - public int getStatus() {
23   - return this.status;
24   - }
25   -
26   - public static boolean isEnabled(Integer status) {
27   - return status != null && ENABLED.getStatus() == status;
28   - }
29   -
30   - public static boolean isDisEnabled(Integer status) {
31   - return status != null && DISENABLED.getStatus() == status;
32   - }
33   -
34   -}
center.manager/src/main/java/com/lyms/cm/enums/UserTypeEnum.java View file @ 0f29cd3
1   -package com.lyms.cm.enums;
2   -
3   -/**
4   - * 用户类型
5   - *
6   - * @author maliang
7   - *
8   - */
9   -public enum UserTypeEnum {
10   -
11   - // 管理员
12   - MANAGER(0),
13   - // 用户
14   - USER(1);
15   -
16   - private int type;
17   -
18   - private UserTypeEnum(int type) {
19   - this.type = type;
20   - }
21   -
22   - /**
23   - * 获取类型
24   - *
25   - * @return
26   - */
27   - public int getType() {
28   - return this.type;
29   - }
30   -
31   -}
center.manager/src/main/java/com/lyms/cm/enums/UserValidityEnum.java View file @ 0f29cd3
1   -package com.lyms.cm.enums;
2   -
3   -/**
4   - * 用户是否有效
5   - *
6   - * @author maliang
7   - *
8   - */
9   -public enum UserValidityEnum {
10   -
11   - // 有效
12   - VALIDITY(1),
13   - // 无效
14   - UNVALIDITY(2);
15   -
16   - private int validity;
17   -
18   - private UserValidityEnum(int validity) {
19   - this.validity = validity;
20   - }
21   -
22   - public int getValidity() {
23   - return this.validity;
24   - }
25   -
26   -}
center.manager/src/main/java/com/lyms/cm/enums/ValidityEnum.java View file @ 0f29cd3
  1 +package com.lyms.cm.enums;
  2 +
  3 +/**
  4 + * 用户是否有效
  5 + *
  6 + * @author maliang
  7 + *
  8 + */
  9 +public enum ValidityEnum {
  10 +
  11 + // 有效
  12 + VALIDITY(1),
  13 + // 无效
  14 + UNVALIDITY(2);
  15 +
  16 + private int validity;
  17 +
  18 + private ValidityEnum(int validity) {
  19 + this.validity = validity;
  20 + }
  21 +
  22 + public int getValidity() {
  23 + return this.validity;
  24 + }
  25 +
  26 +}
center.manager/src/main/java/com/lyms/cm/service/sys/SysRolesService.java View file @ 0f29cd3
1 1 package com.lyms.cm.service.sys;
2 2  
  3 +import com.baomidou.mybatisplus.plugins.Page;
3 4 import com.lyms.cm.entity.sys.SysRoles;
4 5 import com.lyms.exception.SystemException;
5 6 import com.lyms.web.service.BaseService;
... ... @@ -32,8 +33,42 @@
32 33 */
33 34 public boolean updateRole(SysRoles role) throws SystemException;
34 35  
35   -
36   -
37   -
  36 + /**
  37 + * 删除角色信息
  38 + *
  39 + * @param roleId
  40 + * @return
  41 + * @throws SystemException
  42 + */
  43 + public boolean deleteRole(String roleId) throws SystemException;
  44 +
  45 + /**
  46 + * 分页获取角色信息
  47 + * <p>
  48 + * 目前没有参数设置,过滤
  49 + *
  50 + * @param page
  51 + * @return
  52 + */
  53 + public Page<SysRoles> getRolesByPage(Page<SysRoles> page) throws SystemException;
  54 +
  55 + /**
  56 + * 根据roleId 获取角色信息
  57 + *
  58 + * @param roleId
  59 + * @return
  60 + * @throws SystemException
  61 + */
  62 + public SysRoles getRoleById(String roleId) throws SystemException;
  63 +
  64 + /**
  65 + * 禁/启用角色
  66 + *
  67 + * @param roleId
  68 + * @return
  69 + * @throws SystemException
  70 + */
  71 + public boolean enable(String roleId) throws SystemException;
  72 +
38 73 }
center.manager/src/main/java/com/lyms/cm/service/sys/SysUsersService.java View file @ 0f29cd3
... ... @@ -66,5 +66,14 @@
66 66 */
67 67 public boolean enabled(String userId) throws SystemException;
68 68  
  69 + /**
  70 + * 删除用户信息
  71 + *
  72 + * @param userId
  73 + * @return
  74 + * @throws SystemException
  75 + */
  76 + public boolean delete(String userId) throws SystemException;
  77 +
69 78 }
center.manager/src/main/java/com/lyms/cm/service/sys/impl/SysRolesServiceImpl.java View file @ 0f29cd3
1 1 package com.lyms.cm.service.sys.impl;
2 2  
  3 +import java.util.List;
  4 +
  5 +import org.apache.commons.lang3.StringUtils;
  6 +import org.springframework.beans.factory.annotation.Autowired;
3 7 import org.springframework.stereotype.Service;
  8 +import org.springframework.transaction.annotation.Transactional;
4 9  
  10 +import com.baomidou.mybatisplus.plugins.Page;
5 11 import com.baomidou.mybatisplus.service.impl.ServiceImpl;
6 12 import com.lyms.cm.dao.sys.SysRolesMapper;
7 13 import com.lyms.cm.entity.sys.SysRoles;
  14 +import com.lyms.cm.enums.StatusEnum;
  15 +import com.lyms.cm.enums.ValidityEnum;
8 16 import com.lyms.cm.service.sys.SysRolesService;
9 17 import com.lyms.exception.SystemException;
10 18  
11 19  
12 20  
13 21  
... ... @@ -19,13 +27,95 @@
19 27 @Service
20 28 public class SysRolesServiceImpl extends ServiceImpl<SysRolesMapper, SysRoles> implements SysRolesService {
21 29  
  30 + @Autowired
  31 + private SysRolesMapper roleMapper;
  32 +
  33 + /**
  34 + * 实体空判断
  35 + *
  36 + * @param role
  37 + * @return
  38 + */
  39 + private boolean empty(SysRoles role) {
  40 + return role == null;
  41 + }
  42 +
  43 + @Transactional
22 44 @Override
23 45 public boolean addRole(SysRoles role) throws SystemException {
24   - return false;
  46 + if (empty(role))
  47 + return false;
  48 + Integer tag = roleMapper.insert(role);
  49 + return tag != null && tag >= 1;
25 50 }
26 51  
27 52 @Override
  53 + @Transactional
28 54 public boolean updateRole(SysRoles role) throws SystemException {
  55 + if (empty(role))
  56 + return false;
  57 + Integer tag = roleMapper.updateById(role);
  58 + return tag != null && tag >= 1;
  59 + }
  60 +
  61 + @Override
  62 + @Transactional
  63 + public boolean deleteRole(String roleId) throws SystemException {
  64 + if (StringUtils.isBlank(roleId))
  65 + return false;
  66 + // 并非真实删除,通过字段属性控制
  67 + // TODO 通过sql 修改
  68 + SysRoles role = roleMapper.selectById(roleId);
  69 + if (role != null) {
  70 + Integer yn = role.getYn();
  71 + if (yn == null || yn == ValidityEnum.VALIDITY.getValidity()) {
  72 + yn = ValidityEnum.UNVALIDITY.getValidity();
  73 + } else {
  74 + yn = ValidityEnum.VALIDITY.getValidity();
  75 + }
  76 + role.setYn(yn);
  77 + Integer tag = roleMapper.updateById(role);
  78 + return tag != null && tag >= 1;
  79 + }
  80 + return false;
  81 + }
  82 +
  83 + @Override
  84 + public Page<SysRoles> getRolesByPage(Page<SysRoles> page) throws SystemException {
  85 +
  86 + if (page == null)
  87 + return null;
  88 +
  89 + // TODO 添加参数过滤
  90 + List<SysRoles> roles = roleMapper.selectPage(page, null);
  91 + page.setRecords(roles);
  92 +
  93 + return page;
  94 + }
  95 +
  96 + @Override
  97 + public SysRoles getRoleById(String roleId) throws SystemException {
  98 + if (StringUtils.isBlank(roleId))
  99 + return null;
  100 + return roleMapper.selectById(roleId);
  101 + }
  102 +
  103 + @Override
  104 + public boolean enable(String roleId) throws SystemException {
  105 +
  106 + SysRoles role = this.getRoleById(roleId);
  107 +
  108 + if (empty(role))
  109 + return false;
  110 +
  111 + // 判断当前用户的启用,禁用情况
  112 + // TODO 拆分成SQL执行,两种操作
  113 + if (role.isEnable()) {
  114 + role.setEnable(StatusEnum.DISENABLED.getStatus());
  115 + } else {
  116 + role.setEnable(StatusEnum.ENABLED.getStatus());
  117 + }
  118 +
29 119 return false;
30 120 }
31 121  
center.manager/src/main/java/com/lyms/cm/service/sys/impl/SysUsersServiceImpl.java View file @ 0f29cd3
... ... @@ -11,7 +11,8 @@
11 11 import com.baomidou.mybatisplus.service.impl.ServiceImpl;
12 12 import com.lyms.cm.dao.sys.SysUsersMapper;
13 13 import com.lyms.cm.entity.sys.SysUsers;
14   -import com.lyms.cm.enums.UserStatusEnum;
  14 +import com.lyms.cm.enums.StatusEnum;
  15 +import com.lyms.cm.enums.ValidityEnum;
15 16 import com.lyms.cm.service.sys.SysUsersService;
16 17 import com.lyms.exception.SystemException;
17 18 import com.lyms.util.MD5Utils;
18 19  
... ... @@ -99,9 +100,9 @@
99 100  
100 101 // 判断当前用户的启用,禁用情况
101 102 if (user.isEnabled()) {
102   - user.setEnable(UserStatusEnum.DISENABLED.getStatus());
  103 + user.setEnable(StatusEnum.DISENABLED.getStatus());
103 104 } else {
104   - user.setEnable(UserStatusEnum.ENABLED.getStatus());
  105 + user.setEnable(StatusEnum.ENABLED.getStatus());
105 106 }
106 107 return this.updateUser(user);
107 108 }
108 109  
... ... @@ -111,9 +112,32 @@
111 112  
112 113 if (page == null)
113 114 return null;
  115 + // TODO 添加过过滤条件
114 116 List<SysUsers> users = userMapper.selectPage(page, null);
115 117 page.setRecords(users);
116 118 return page;
  119 + }
  120 +
  121 + @Override
  122 + @Transactional
  123 + public boolean delete(String userId) throws SystemException {
  124 +
  125 + if (StringUtils.isBlank(userId))
  126 + return false;
  127 + // TODO 通过sql 修改
  128 + SysUsers user = userMapper.selectById(userId);
  129 + if (user != null) {
  130 + Integer yn = user.getYn();
  131 + if (yn == null || yn == ValidityEnum.VALIDITY.getValidity()) {
  132 + yn = ValidityEnum.UNVALIDITY.getValidity();
  133 + } else {
  134 + yn = ValidityEnum.VALIDITY.getValidity();
  135 + }
  136 + user.setYn(yn);
  137 + Integer tag = userMapper.updateById(user);
  138 + return tag != null && tag >= 1;
  139 + }
  140 + return false;
117 141 }
118 142  
119 143 }
center.manager/src/main/webapp/WEB-INF/views/user/user_list.html View file @ 0f29cd3
... ... @@ -45,7 +45,7 @@
45 45 }
46 46  
47 47 function del(){
48   - goDelete("dataTable","id", APP.PATH + "/user/@value@/delete");
  48 + goDelete("dataTable","id", APP.PATH + "/sysUsers/@value@/delete");
49 49 }
50 50 ## 参考 base_table_init.js 或者根据empty_bootstrap_table_init.js 来自己创建特殊的table
51 51 ## 注意:自己创建的特殊的table不能extends base_list.html