diff --git a/src/main/resources/modules/SpringBoot/java/action/ajax/system/RoleResourceAjax.java b/src/main/resources/modules/SpringBoot/java/action/ajax/system/RoleResourceAjax.java index fe8f3bc7..9a436759 100644 --- a/src/main/resources/modules/SpringBoot/java/action/ajax/system/RoleResourceAjax.java +++ b/src/main/resources/modules/SpringBoot/java/action/ajax/system/RoleResourceAjax.java @@ -1,25 +1,15 @@ package ${basePackage}.action.ajax.system; -import com.fasterxml.jackson.core.TreeNode; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.multipart.MultipartFile; -import ${basePackage}.frame.excel.WSheet; -import ${basePackage}.frame.utils.LogUtil; import ${basePackage}.frame.auth.LocalData; -import ${basePackage}.frame.base.ErrorType; -import ${basePackage}.frame.utils.MapperUtil; -import ${basePackage}.frame.base.BaseResponse; -import ${basePackage}.frame.utils.ResponseUtil; -import ${basePackage}.frame.utils.ValidationUtil; -import ${basePackage}.frame.excel.exception.ReadErrorException; -import ${basePackage}.frame.excel.exception.TemplateNotMatchException; -import ${basePackage}.module.system.ent.RoleResource; import ${basePackage}.module.system.mgr.RoleResourceManager; +import ${basePackage}.module.system.req.RoleResourceCheckRequest; import ${basePackage}.module.system.req.RoleResourceCreateRequest; import ${basePackage}.module.system.req.RoleResourceDeleteRequest; import ${basePackage}.module.system.req.RoleResourceFindRequest; import ${basePackage}.module.system.req.RoleResourceGetRequest; import ${basePackage}.module.system.req.RoleResourceUpdateRequest; +import ${basePackage}.module.system.rsp.RoleResourceCheckResponse; import ${basePackage}.module.system.rsp.RoleResourceCreateResponse; import ${basePackage}.module.system.rsp.RoleResourceDeleteResponse; import ${basePackage}.module.system.rsp.RoleResourceFindResponse; @@ -53,4 +43,8 @@ public class RoleResourceAjax{ public RoleResourceGetResponse get(RoleResourceGetRequest request) { return roleResourceManager.get(request, LocalData.getToken()); } + + public RoleResourceCheckResponse check(RoleResourceCheckRequest request) { + return roleResourceManager.check(request, LocalData.getToken()); + } } diff --git a/src/main/resources/modules/SpringBoot/java/action/ajax/system/UserRoleAjax.java b/src/main/resources/modules/SpringBoot/java/action/ajax/system/UserRoleAjax.java index 24dec1d6..b6c828bb 100644 --- a/src/main/resources/modules/SpringBoot/java/action/ajax/system/UserRoleAjax.java +++ b/src/main/resources/modules/SpringBoot/java/action/ajax/system/UserRoleAjax.java @@ -1,19 +1,7 @@ package ${basePackage}.action.ajax.system; -import com.fasterxml.jackson.core.TreeNode; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.multipart.MultipartFile; -import ${basePackage}.frame.excel.WSheet; -import ${basePackage}.frame.utils.LogUtil; import ${basePackage}.frame.auth.LocalData; -import ${basePackage}.frame.base.ErrorType; -import ${basePackage}.frame.utils.MapperUtil; -import ${basePackage}.frame.base.BaseResponse; -import ${basePackage}.frame.utils.ResponseUtil; -import ${basePackage}.frame.utils.ValidationUtil; -import ${basePackage}.frame.excel.exception.ReadErrorException; -import ${basePackage}.frame.excel.exception.TemplateNotMatchException; -import ${basePackage}.module.system.ent.UserRole; import ${basePackage}.module.system.mgr.UserRoleManager; import ${basePackage}.module.system.req.UserRoleCreateRequest; import ${basePackage}.module.system.req.UserRoleDeleteRequest; diff --git a/src/main/resources/modules/SpringBoot/java/module/system/mgr/RoleResourceManager.java b/src/main/resources/modules/SpringBoot/java/module/system/mgr/RoleResourceManager.java index 689b314a..64c93a8a 100644 --- a/src/main/resources/modules/SpringBoot/java/module/system/mgr/RoleResourceManager.java +++ b/src/main/resources/modules/SpringBoot/java/module/system/mgr/RoleResourceManager.java @@ -1,11 +1,13 @@ package ${basePackage}.module.system.mgr; import ${basePackage}.frame.base.Token; +import ${basePackage}.module.system.req.RoleResourceCheckRequest; import ${basePackage}.module.system.req.RoleResourceCreateRequest; import ${basePackage}.module.system.req.RoleResourceDeleteRequest; import ${basePackage}.module.system.req.RoleResourceFindRequest; import ${basePackage}.module.system.req.RoleResourceGetRequest; import ${basePackage}.module.system.req.RoleResourceUpdateRequest; +import ${basePackage}.module.system.rsp.RoleResourceCheckResponse; import ${basePackage}.module.system.rsp.RoleResourceCreateResponse; import ${basePackage}.module.system.rsp.RoleResourceDeleteResponse; import ${basePackage}.module.system.rsp.RoleResourceFindResponse; @@ -65,4 +67,13 @@ public interface RoleResourceManager { * @return */ RoleResourceGetResponse get(RoleResourceGetRequest request, Token token); + + /** + * 选中或取消资源 + * + * @param request 请求对象 + * @param token 令牌 + * @return 响应 + */ + RoleResourceCheckResponse check(RoleResourceCheckRequest request, Token token); } diff --git a/src/main/resources/modules/SpringBoot/java/module/system/mgr/RoleResourceManagerImpl.java b/src/main/resources/modules/SpringBoot/java/module/system/mgr/RoleResourceManagerImpl.java index 30fd5c56..cd446ae1 100644 --- a/src/main/resources/modules/SpringBoot/java/module/system/mgr/RoleResourceManagerImpl.java +++ b/src/main/resources/modules/SpringBoot/java/module/system/mgr/RoleResourceManagerImpl.java @@ -6,6 +6,7 @@ import com.github.pagehelper.util.StringUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.interceptor.TransactionAspectSupport; import ${basePackage}.frame.base.ErrorType; import ${basePackage}.frame.base.Token; import ${basePackage}.frame.utils.IDgenerator; @@ -14,11 +15,13 @@ import ${basePackage}.frame.utils.Message; import ${basePackage}.frame.utils.ValidationUtil; import ${basePackage}.module.system.ent.RoleResource; import ${basePackage}.module.system.mpr.RoleResourceMapper; +import ${basePackage}.module.system.req.RoleResourceCheckRequest; import ${basePackage}.module.system.req.RoleResourceCreateRequest; import ${basePackage}.module.system.req.RoleResourceDeleteRequest; import ${basePackage}.module.system.req.RoleResourceFindRequest; import ${basePackage}.module.system.req.RoleResourceGetRequest; import ${basePackage}.module.system.req.RoleResourceUpdateRequest; +import ${basePackage}.module.system.rsp.RoleResourceCheckResponse; import ${basePackage}.module.system.rsp.RoleResourceCreateResponse; import ${basePackage}.module.system.rsp.RoleResourceDeleteResponse; import ${basePackage}.module.system.rsp.RoleResourceFindResponse; @@ -172,4 +175,53 @@ public class RoleResourceManagerImpl implements RoleResourceManager { return response; } + + /** + * 选中或取消资源 + * + * @param request 请求对象 + * @param token 令牌 + * @return 响应 + */ + public RoleResourceCheckResponse check(RoleResourceCheckRequest request, Token token) { + RoleResourceCheckResponse response = new RoleResourceCheckResponse(); + + ValidationUtil.validate(request, response); + if (response.hasError()) { + return response; + } + + RoleResourceFindRequest roleResourceFindRequest = new RoleResourceFindRequest(); + roleResourceFindRequest.setRoleId(request.getRoleId()); + roleResourceFindRequest.setResourceId(request.getResourceId()); + RoleResourceFindResponse roleResourceFindResponse = this.find(roleResourceFindRequest, token); + if (roleResourceFindResponse.hasError()) { + response.addErrors(roleResourceFindResponse.getErrors()); + return response; + } + + if (request.getChecked() && roleResourceFindResponse.getResult().size() == 0) { + RoleResourceCreateRequest roleResourceCreateRequest = new RoleResourceCreateRequest(); + roleResourceCreateRequest.setRoleId(request.getRoleId()); + roleResourceCreateRequest.setResourceId(request.getResourceId()); + RoleResourceCreateResponse roleResourceCreateResponse = this.create(roleResourceCreateRequest, token); + if (roleResourceCreateResponse.hasError()) { + response.addErrors(roleResourceCreateResponse.getErrors()); + return response; + } + } else if (!request.getChecked() && roleResourceFindResponse.getResult().size() > 0) { + for (RoleResource roleResource : roleResourceFindResponse.getResult()) { + RoleResourceDeleteRequest roleResourceDeleteRequest = new RoleResourceDeleteRequest(); + roleResourceDeleteRequest.setId(roleResource.getId()); + RoleResourceDeleteResponse roleResourceDeleteResponse = this.delete(roleResourceDeleteRequest, token); + if (roleResourceDeleteResponse.hasError()) { + response.addErrors(roleResourceDeleteResponse.getErrors()); + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + return response; + } + } + } + + return response; + } } diff --git a/src/main/resources/modules/SpringBoot/java/module/system/req/RoleResourceCheckRequest.java b/src/main/resources/modules/SpringBoot/java/module/system/req/RoleResourceCheckRequest.java new file mode 100644 index 00000000..2a8ca27a --- /dev/null +++ b/src/main/resources/modules/SpringBoot/java/module/system/req/RoleResourceCheckRequest.java @@ -0,0 +1,58 @@ +package ${basePackage}.module.system.req; + +import ${basePackage}.frame.base.BaseUpdateRequest; + +import javax.validation.constraints.NotNull; + +/** + * RoleResourceUpdateRequest - 角色资源关系更新 + * + * @author wangbing + * @version 0.0.1 + * @since 2017-01-01 + */ +public class RoleResourceCheckRequest extends BaseUpdateRequest { + + /** + * 角色主键 + */ + @NotNull(message = "[roleId]角色主键不能为NULL") + private Long roleId; + + /** + * 资源主键 + */ + @NotNull(message = "[resourceId]资源主键不能为NULL") + private Long resourceId; + + /** + * 是否选中 + */ + @NotNull(message = "[checked]是否选中不能为NULL") + private Boolean checked; + + public Long getRoleId() { + return this.roleId; + } + + public void setRoleId(Long roleId) { + this.roleId = roleId; + } + + public Long getResourceId() { + return this.resourceId; + } + + public void setResourceId(Long resourceId) { + this.resourceId = resourceId; + } + + public Boolean getChecked() { + return checked; + } + + public void setChecked(Boolean checked) { + this.checked = checked; + } +} + diff --git a/src/main/resources/modules/SpringBoot/java/module/system/rsp/RoleResourceCheckResponse.java b/src/main/resources/modules/SpringBoot/java/module/system/rsp/RoleResourceCheckResponse.java new file mode 100644 index 00000000..72d79d60 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/java/module/system/rsp/RoleResourceCheckResponse.java @@ -0,0 +1,26 @@ +package ${basePackage}.module.system.rsp; + +import ${basePackage}.frame.base.BaseResponse; + +/** + * RoleResourceCreateResponse - 角色资源关系 + * + * @author wangbing + * @version 0.0.1 + * @since 2017-01-01 + */ +public class RoleResourceCheckResponse extends BaseResponse { + + /** + * ID + */ + private Long id; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } +} diff --git a/src/main/resources/modules/SpringBoot/resources/templates/screen/module/system/role.ftl b/src/main/resources/modules/SpringBoot/resources/templates/screen/module/system/role.ftl index 0eba8c0b..ec8459ab 100644 --- a/src/main/resources/modules/SpringBoot/resources/templates/screen/module/system/role.ftl +++ b/src/main/resources/modules/SpringBoot/resources/templates/screen/module/system/role.ftl @@ -90,12 +90,11 @@ width="120" label="操作"> - - 编辑 + + 编辑 - 删除 - + 分配资源 + 删除 @@ -117,21 +116,42 @@ - - - - - - - - - - - + + + + + + + + + + + + 取 消 保存 - + + + + + + {{ data.comment }}[{{data.code}}] + + + + + 关 闭 + +