From 8726265999e43390dd7f33e79769b5f6cb1a3af4 Mon Sep 17 00:00:00 2001 From: wangbing <1919101440@qq.com> Date: Fri, 27 Dec 2019 00:09:15 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 3c59756b7f7c4eb5f39f0188812efb0e875f115d --- .../java/action/ajax/system/ResourceAjax.java | 56 +++++++++-------- .../java/module/system/ent/ResourceCheck.java | 33 ++++++++++ .../java/module/system/ent/ResourceTree.java | 26 ++++++++ .../module/system/mgr/ResourceManager.java | 4 ++ .../system/mgr/ResourceManagerImpl.java | 60 +++++++++++++++++++ .../system/req/ResourceLoadRequest.java | 15 +++++ .../system/rsp/ResourceLoadResponse.java | 26 ++++++++ .../resources/templates/screen/login.ftl | 4 +- .../templates/screen/module/system/role.ftl | 21 +++++-- 9 files changed, 214 insertions(+), 31 deletions(-) create mode 100644 src/main/resources/modules/SpringBoot/java/module/system/ent/ResourceCheck.java create mode 100644 src/main/resources/modules/SpringBoot/java/module/system/ent/ResourceTree.java create mode 100644 src/main/resources/modules/SpringBoot/java/module/system/req/ResourceLoadRequest.java create mode 100644 src/main/resources/modules/SpringBoot/java/module/system/rsp/ResourceLoadResponse.java diff --git a/src/main/resources/modules/SpringBoot/java/action/ajax/system/ResourceAjax.java b/src/main/resources/modules/SpringBoot/java/action/ajax/system/ResourceAjax.java index ffb60d91..22da2635 100644 --- a/src/main/resources/modules/SpringBoot/java/action/ajax/system/ResourceAjax.java +++ b/src/main/resources/modules/SpringBoot/java/action/ajax/system/ResourceAjax.java @@ -1,35 +1,37 @@ -package ${basePackage}.action.ajax.system; +package xyz.wbsite.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.Resource; -import ${basePackage}.module.system.mgr.ResourceManager; -import ${basePackage}.module.system.req.ResourceCreateRequest; -import ${basePackage}.module.system.req.ResourceDeleteRequest; -import ${basePackage}.module.system.req.ResourceFindRequest; -import ${basePackage}.module.system.req.ResourceGetRequest; -import ${basePackage}.module.system.req.ResourceUpdateRequest; -import ${basePackage}.module.system.rsp.ResourceCreateResponse; -import ${basePackage}.module.system.rsp.ResourceDeleteResponse; -import ${basePackage}.module.system.rsp.ResourceFindResponse; -import ${basePackage}.module.system.rsp.ResourceGetResponse; -import ${basePackage}.module.system.rsp.ResourceUpdateResponse; +import xyz.wbsite.frame.auth.LocalData; +import xyz.wbsite.frame.base.BaseResponse; +import xyz.wbsite.frame.base.ErrorType; +import xyz.wbsite.frame.excel.WSheet; +import xyz.wbsite.frame.excel.exception.ReadErrorException; +import xyz.wbsite.frame.excel.exception.TemplateNotMatchException; +import xyz.wbsite.frame.utils.LogUtil; +import xyz.wbsite.frame.utils.MapperUtil; +import xyz.wbsite.frame.utils.ResponseUtil; +import xyz.wbsite.frame.utils.ValidationUtil; +import xyz.wbsite.module.system.ent.Resource; +import xyz.wbsite.module.system.mgr.ResourceManager; +import xyz.wbsite.module.system.req.ResourceCreateRequest; +import xyz.wbsite.module.system.req.ResourceDeleteRequest; +import xyz.wbsite.module.system.req.ResourceFindRequest; +import xyz.wbsite.module.system.req.ResourceGetRequest; +import xyz.wbsite.module.system.req.ResourceLoadRequest; +import xyz.wbsite.module.system.req.ResourceUpdateRequest; +import xyz.wbsite.module.system.rsp.ResourceCreateResponse; +import xyz.wbsite.module.system.rsp.ResourceDeleteResponse; +import xyz.wbsite.module.system.rsp.ResourceFindResponse; +import xyz.wbsite.module.system.rsp.ResourceGetResponse; +import xyz.wbsite.module.system.rsp.ResourceLoadResponse; +import xyz.wbsite.module.system.rsp.ResourceUpdateResponse; import java.io.IOException; import java.util.List; -public class ResourceAjax{ +public class ResourceAjax { @Autowired private ResourceManager resourceManager; @@ -54,7 +56,11 @@ public class ResourceAjax{ return resourceManager.get(request, LocalData.getToken()); } - public Object template(){ + public ResourceLoadResponse load(ResourceLoadRequest request) { + return resourceManager.load(request, LocalData.getToken()); + } + + public Object template() { return ResponseUtil.apply(new WSheet<>(Resource.class)); } diff --git a/src/main/resources/modules/SpringBoot/java/module/system/ent/ResourceCheck.java b/src/main/resources/modules/SpringBoot/java/module/system/ent/ResourceCheck.java new file mode 100644 index 00000000..fe815116 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/java/module/system/ent/ResourceCheck.java @@ -0,0 +1,33 @@ +package ${basePackage}.module.system.ent; + +public class ResourceCheck { + + private long resourceId; + private String resourceValue; + private boolean check; + + + public long getResourceId() { + return resourceId; + } + + public void setResourceId(long resourceId) { + this.resourceId = resourceId; + } + + public String getResourceValue() { + return resourceValue; + } + + public void setResourceValue(String resourceValue) { + this.resourceValue = resourceValue; + } + + public boolean isCheck() { + return check; + } + + public void setCheck(boolean check) { + this.check = check; + } +} diff --git a/src/main/resources/modules/SpringBoot/java/module/system/ent/ResourceTree.java b/src/main/resources/modules/SpringBoot/java/module/system/ent/ResourceTree.java new file mode 100644 index 00000000..fc93b938 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/java/module/system/ent/ResourceTree.java @@ -0,0 +1,26 @@ +package ${basePackage}.module.system.ent; + +import java.util.List; + +public class ResourceTree { + + private String resourceModule; + + private List resourceChecks; + + public String getResourceModule() { + return resourceModule; + } + + public void setResourceModule(String resourceModule) { + this.resourceModule = resourceModule; + } + + public List getResourceChecks() { + return resourceChecks; + } + + public void setResourceChecks(List resourceChecks) { + this.resourceChecks = resourceChecks; + } +} diff --git a/src/main/resources/modules/SpringBoot/java/module/system/mgr/ResourceManager.java b/src/main/resources/modules/SpringBoot/java/module/system/mgr/ResourceManager.java index de171307..81556097 100644 --- a/src/main/resources/modules/SpringBoot/java/module/system/mgr/ResourceManager.java +++ b/src/main/resources/modules/SpringBoot/java/module/system/mgr/ResourceManager.java @@ -5,11 +5,13 @@ import ${basePackage}.module.system.req.ResourceCreateRequest; import ${basePackage}.module.system.req.ResourceDeleteRequest; import ${basePackage}.module.system.req.ResourceFindRequest; import ${basePackage}.module.system.req.ResourceGetRequest; +import ${basePackage}.module.system.req.ResourceLoadRequest; import ${basePackage}.module.system.req.ResourceUpdateRequest; import ${basePackage}.module.system.rsp.ResourceCreateResponse; import ${basePackage}.module.system.rsp.ResourceDeleteResponse; import ${basePackage}.module.system.rsp.ResourceFindResponse; import ${basePackage}.module.system.rsp.ResourceGetResponse; +import ${basePackage}.module.system.rsp.ResourceLoadResponse; import ${basePackage}.module.system.rsp.ResourceUpdateResponse; /** @@ -65,4 +67,6 @@ public interface ResourceManager { * @return */ ResourceGetResponse get(ResourceGetRequest request, Token token); + + ResourceLoadResponse load(ResourceLoadRequest request, Token token); } diff --git a/src/main/resources/modules/SpringBoot/java/module/system/mgr/ResourceManagerImpl.java b/src/main/resources/modules/SpringBoot/java/module/system/mgr/ResourceManagerImpl.java index 33b8e818..68e6b8eb 100644 --- a/src/main/resources/modules/SpringBoot/java/module/system/mgr/ResourceManagerImpl.java +++ b/src/main/resources/modules/SpringBoot/java/module/system/mgr/ResourceManagerImpl.java @@ -7,24 +7,32 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import ${basePackage}.frame.base.ErrorType; +import ${basePackage}.frame.base.SortType; import ${basePackage}.frame.base.Token; import ${basePackage}.frame.utils.IDgenerator; import ${basePackage}.frame.utils.MapperUtil; import ${basePackage}.frame.utils.Message; import ${basePackage}.frame.utils.ValidationUtil; import ${basePackage}.module.system.ent.Resource; +import ${basePackage}.module.system.ent.ResourceCheck; +import ${basePackage}.module.system.ent.ResourceTree; import ${basePackage}.module.system.mpr.ResourceMapper; import ${basePackage}.module.system.req.ResourceCreateRequest; import ${basePackage}.module.system.req.ResourceDeleteRequest; import ${basePackage}.module.system.req.ResourceFindRequest; import ${basePackage}.module.system.req.ResourceGetRequest; +import ${basePackage}.module.system.req.ResourceLoadRequest; import ${basePackage}.module.system.req.ResourceUpdateRequest; import ${basePackage}.module.system.rsp.ResourceCreateResponse; import ${basePackage}.module.system.rsp.ResourceDeleteResponse; import ${basePackage}.module.system.rsp.ResourceFindResponse; import ${basePackage}.module.system.rsp.ResourceGetResponse; +import ${basePackage}.module.system.rsp.ResourceLoadResponse; import ${basePackage}.module.system.rsp.ResourceUpdateResponse; +import java.util.ArrayList; +import java.util.List; + /** * RESOURCE - 资源 * @@ -38,6 +46,8 @@ public class ResourceManagerImpl implements ResourceManager { @Autowired private ResourceMapper resourceMapper; + @Autowired + private DictItemManager dictItemManager; /** * 插入 @@ -172,4 +182,54 @@ public class ResourceManagerImpl implements ResourceManager { return response; } + + @Override + public ResourceLoadResponse load(ResourceLoadRequest request, Token token) { + ResourceLoadResponse response = new ResourceLoadResponse(); + + ValidationUtil.validate(request, response); + if (response.hasError()) { + return response; + } + + ResourceFindRequest resourceFindRequest = new ResourceFindRequest(); + resourceFindRequest.setPageSize(0); + resourceFindRequest.setValid(true); + resourceFindRequest.setSortType(SortType.ASC); + resourceFindRequest.setSortKey("RESOURCE_MODULE,RESOURCE_TYPE"); + ResourceFindResponse resourceFindResponse = this.find(resourceFindRequest, token); + + if (resourceFindResponse.hasError()) { + response.addErrors(resourceFindResponse.getErrors()); + return response; + } + + List data = new ArrayList<>(); + ResourceTree tree = null; + List checks = null; + + for (Resource resource : resourceFindResponse.getResult()) { + if (tree != null && tree.getResourceModule().equals(resource.getResourceModule())) { + + ResourceCheck check = new ResourceCheck(); + check.setResourceId(resource.getId()); + check.setResourceValue(resource.getValue()); + checks.add(check); + } else { + tree = new ResourceTree(); + data.add(tree); + tree.setResourceModule(resource.getResourceModule()); + checks = new ArrayList<>(); + tree.setResourceChecks(checks); + + ResourceCheck check = new ResourceCheck(); + check.setResourceId(resource.getId()); + check.setResourceValue(resource.getValue()); + checks.add(check); + } + } + + response.setData(data); + return response; + } } diff --git a/src/main/resources/modules/SpringBoot/java/module/system/req/ResourceLoadRequest.java b/src/main/resources/modules/SpringBoot/java/module/system/req/ResourceLoadRequest.java new file mode 100644 index 00000000..54dc4056 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/java/module/system/req/ResourceLoadRequest.java @@ -0,0 +1,15 @@ +package ${basePackage}.module.system.req; + +import ${basePackage}.frame.base.BaseRequest; + +/** + * ResourceGetRequest - 资源获取 + * + * @author wangbing + * @version 0.0.1 + * @since 2019-12-26 + */ +public class ResourceLoadRequest extends BaseRequest { + + +} diff --git a/src/main/resources/modules/SpringBoot/java/module/system/rsp/ResourceLoadResponse.java b/src/main/resources/modules/SpringBoot/java/module/system/rsp/ResourceLoadResponse.java new file mode 100644 index 00000000..b763a112 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/java/module/system/rsp/ResourceLoadResponse.java @@ -0,0 +1,26 @@ +package ${basePackage}.module.system.rsp; + +import ${basePackage}.frame.base.BaseResponse; +import ${basePackage}.module.system.ent.ResourceTree; + +import java.util.List; + +/** + * ResourceLoadResponse - 资源 + * + * @author author + * @version 0.0.1 + * @since 2017-01-01 + */ +public class ResourceLoadResponse extends BaseResponse { + + private List data; + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } +} diff --git a/src/main/resources/modules/SpringBoot/resources/templates/screen/login.ftl b/src/main/resources/modules/SpringBoot/resources/templates/screen/login.ftl index 6abcaa72..f79b0ede 100644 --- a/src/main/resources/modules/SpringBoot/resources/templates/screen/login.ftl +++ b/src/main/resources/modules/SpringBoot/resources/templates/screen/login.ftl @@ -40,8 +40,8 @@ } .frame { - width: 600px; - height: 500px; + width: 500px; + height: 450px; background: #42424263; border-radius: 10px; display: flex; 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 c52aa1fe..66affcc5 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 @@ -18,7 +18,7 @@ - + 新增 @@ -26,7 +26,8 @@ 导出 - + @@ -34,7 +35,8 @@ - + @@ -170,7 +172,8 @@ roleComment: [ {min: 1, max: 50, message: '角色描述长度在 1 到 50 个字符', trigger: 'blur'} ], - } + }, + resourceTree: {} }, methods: { onCreate: function () { @@ -202,9 +205,19 @@ break; } }, + ss: function () { + this.$ajax.load("system", "resource", {}).then(function (response) { + if (response.errors.length > 0) { + console.error(response.errors[0].message) + } else { + this.resourceTree = response.resourceChecks; + } + }.bind(this)) + } }, mounted: function () { this.onFind(); + this.ss(); }, })