Commit 1a45eacb by huangjinxin

feat:角色增删改

1 parent e91d8816
...@@ -16,80 +16,90 @@ ...@@ -16,80 +16,90 @@
package com.dituhui.pea.common; package com.dituhui.pea.common;
import com.dituhui.pea.enums.StatusCodeEnum;
/** /**
* @author TrevorLink * @author TrevorLink
*/ */
public class Result<T> { public class Result<T> {
private String code; private String code;
private String message; private String message;
private T result; private T result;
public static <T> Result<T> success(T result) { public static <T> Result<T> success(T result) {
return new Result<>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(), result); return new Result<>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(), result);
} }
public static <T> Result<T> success(String message, T result) { public static <T> Result<T> success(String message, T result) {
return new Result<>(ResultEnum.SUCCESS.getCode(), message, result); return new Result<>(ResultEnum.SUCCESS.getCode(), message, result);
} }
public static Result<?> failed() { public static Result<?> failed() {
return new Result<>(ResultEnum.COMMON_FAILED.getCode(), return new Result<>(ResultEnum.COMMON_FAILED.getCode(),
ResultEnum.COMMON_FAILED.getMessage(), null); ResultEnum.COMMON_FAILED.getMessage(), null);
} }
public static Result<?> failed(String message) { public static Result<?> failed(String message) {
return new Result<>(ResultEnum.COMMON_FAILED.getCode(), message, null); return new Result<>(ResultEnum.COMMON_FAILED.getCode(), message, null);
} }
public static <T> Result<T> failure(String message) { public static <T> Result<T> failure(String message) {
return new Result<>(ResultEnum.COMMON_FAILED.getCode(), message, null); return new Result<>(ResultEnum.COMMON_FAILED.getCode(), message, null);
} }
public static Result<?> failed(IResult errorResult) { public static Result<?> failed(IResult errorResult) {
return new Result<>(errorResult.getCode(), errorResult.getMessage(), null); return new Result<>(errorResult.getCode(), errorResult.getMessage(), null);
} }
public Result() { public static <T> Result<T> failed(T result) {
} return new Result<>(ResultEnum.COMMON_FAILED.getCode(), ResultEnum.COMMON_FAILED.getMessage(), result);
}
public Result(String code, String message, T result) {
this.code = code; public static <T> Result<T> failed(StatusCodeEnum resultEnum, T result) {
this.message = message; return new Result<>(resultEnum.getCode(), resultEnum.getDesc(), result);
this.result = result; }
}
public Result() {
public String getCode() { }
return this.code;
} public Result(String code, String message, T result) {
this.code = code;
public void setCode(String code) { this.message = message;
this.code = code; this.result = result;
} }
public String getMessage() { public String getCode() {
return this.message; return this.code;
} }
public void setMessage(String message) { public void setCode(String code) {
this.message = message; this.code = code;
} }
public T getResult() { public String getMessage() {
return this.result; return this.message;
} }
public void setResult(T result) { public void setMessage(String message) {
this.result = result; this.message = message;
} }
public static <T> Result<T> instance(String code, String message, T result) { public T getResult() {
Result<T> r = new Result<>(); return this.result;
r.setCode(code); }
r.setMessage(message);
r.setResult(result); public void setResult(T result) {
return r; this.result = result;
} }
public static <T> Result<T> instance(String code, String message, T result) {
Result<T> r = new Result<>();
r.setCode(code);
r.setMessage(message);
r.setResult(result);
return r;
}
} }
...@@ -32,9 +32,14 @@ public class RoleInfo { ...@@ -32,9 +32,14 @@ public class RoleInfo {
private String groupId; private String groupId;
/** /**
* 备注
*/
private String notes;
/**
* 角色自定义条件 * 角色自定义条件
*/ */
@NotBlank(message = "角色条件不能为空!") // @NotBlank(message = "角色条件不能为空!")
private String extra; private String extra;
/** /**
...@@ -50,4 +55,12 @@ public class RoleInfo { ...@@ -50,4 +55,12 @@ public class RoleInfo {
private Date updatedTime; private Date updatedTime;
private List<RoleResourceInfo> resourceInfos; private List<RoleResourceInfo> resourceInfos;
/**
* 创建人
*/
private String createdBy;
/**
* 更新人
*/
private String updatedBy;
} }
...@@ -27,7 +27,7 @@ public interface IRole { ...@@ -27,7 +27,7 @@ public interface IRole {
* @return * @return
*/ */
@RequestMapping(value = "/pea-user/role/add", method = RequestMethod.POST) @RequestMapping(value = "/pea-user/role/add", method = RequestMethod.POST)
WebResult<RoleInfo> addRole(@RequestBody RoleInfo roleInfo); Result<RoleInfo> addRole(@RequestBody RoleInfo roleInfo);
/** /**
...@@ -37,7 +37,7 @@ public interface IRole { ...@@ -37,7 +37,7 @@ public interface IRole {
* @return * @return
*/ */
@RequestMapping(value = "/pea-user/role/update", method = RequestMethod.POST) @RequestMapping(value = "/pea-user/role/update", method = RequestMethod.POST)
WebResult<RoleInfo> updateRole(@RequestBody RoleInfo roleInfo); Result<RoleInfo> updateRole(@RequestBody RoleInfo roleInfo);
/** /**
* 删除角色 * 删除角色
...@@ -46,7 +46,7 @@ public interface IRole { ...@@ -46,7 +46,7 @@ public interface IRole {
* @return * @return
*/ */
@RequestMapping(value = "/pea-user/role/delete", method = RequestMethod.POST) @RequestMapping(value = "/pea-user/role/delete", method = RequestMethod.POST)
WebResult<Boolean> deleteRole(@RequestParam("id") String roleId); Result<Boolean> deleteRole(@RequestParam("id") String roleId);
/** /**
* 添加用户角色 * 添加用户角色
......
...@@ -33,25 +33,25 @@ public class RoleController implements IRole { ...@@ -33,25 +33,25 @@ public class RoleController implements IRole {
RoleService roleService; RoleService roleService;
@Override @Override
public WebResult<RoleInfo> addRole(@Validated RoleInfo roleInfo) { public Result<RoleInfo> addRole(@Validated RoleInfo roleInfo) {
roleInfo = roleService.addRole(roleInfo); roleInfo = roleService.addRole(roleInfo);
return WebResult.ok(roleInfo); return Result.success(roleInfo);
} }
@Override @Override
public WebResult<RoleInfo> updateRole(@Validated RoleInfo roleInfo) { public Result<RoleInfo> updateRole(@Validated RoleInfo roleInfo) {
roleInfo = roleService.updateRole(roleInfo); roleInfo = roleService.updateRole(roleInfo);
return WebResult.ok(roleInfo); return Result.success(roleInfo);
} }
@Override @Override
public WebResult<Boolean> deleteRole(String roleId) { public Result<Boolean> deleteRole(String roleId) {
if (StringUtils.isBlank(roleId)) { if (StringUtils.isBlank(roleId)) {
return WebResult.failed(StatusCodeEnum.COMMON_PARAM_EMPTY); return Result.failed(StatusCodeEnum.COMMON_PARAM_EMPTY, false);
} }
roleService.deleteRole(roleId); roleService.deleteRole(roleId);
return WebResult.ok(); return Result.success(true);
} }
@Override @Override
......
...@@ -69,4 +69,9 @@ public class RoleEntity implements Serializable { ...@@ -69,4 +69,9 @@ public class RoleEntity implements Serializable {
@LastModifiedDate @LastModifiedDate
private Date updatedTime; private Date updatedTime;
/**
* 备注
*/
private String notes;
} }
...@@ -84,9 +84,9 @@ public class RoleService { ...@@ -84,9 +84,9 @@ public class RoleService {
roleEntity = roleDao.save(roleEntity); roleEntity = roleDao.save(roleEntity);
List<RoleResourceInfo> resourceInfos = roleInfo.getResourceInfos(); List<RoleResourceInfo> resourceInfos = roleInfo.getResourceInfos();
if (CollectionUtils.isNotEmpty(resourceInfos)) { if (CollectionUtils.isNotEmpty(resourceInfos)) {
// 先清除
roleResourceDao.deleteByRoleId(roleEntity.getId());
for (RoleResourceInfo resourceInfo : resourceInfos) { for (RoleResourceInfo resourceInfo : resourceInfos) {
// 先清除
roleResourceDao.deleteByRoleId(roleEntity.getId());
RoleResourceEntity roleResourceEntity = assembleRoleResource(roleEntity.getId(), resourceInfo.getResourceId()); RoleResourceEntity roleResourceEntity = assembleRoleResource(roleEntity.getId(), resourceInfo.getResourceId());
roleResourceDao.save(roleResourceEntity); roleResourceDao.save(roleResourceEntity);
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!