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 new file mode 100644 index 00000000..e49e4aa0 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/java/action/ajax/system/ResourceAjax.java @@ -0,0 +1,90 @@ +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.Resource; +import ${basePackage}.module.system.mgr.ResourceManager; +import ${basePackage}.module.system.req.*; +import ${basePackage}.module.system.rsp.*; + +import java.io.IOException; +import java.util.List; + +public class ResourceAjax{ + + @Autowired + private ResourceManager resourceManager; + + public ResourceCreateResponse create(ResourceCreateRequest request) { + return resourceManager.create(request, LocalData.getToken()); + } + + public ResourceDeleteResponse delete(ResourceDeleteRequest request) { + return resourceManager.delete(request, LocalData.getToken()); + } + + public ResourceUpdateResponse update(ResourceUpdateRequest request) { + return resourceManager.update(request, LocalData.getToken()); + } + + public ResourceFindResponse find(ResourceFindRequest request) { + return resourceManager.find(request, LocalData.getToken()); + } + + public ResourceGetResponse get(ResourceGetRequest request) { + return resourceManager.get(request, LocalData.getToken()); + } + + public Object template(){ + return ResponseUtil.apply(new WSheet<>(Resource.class)); + } + + public Object exports(TreeNode jsonParam) { + ResourceFindRequest request = MapperUtil.toJava(jsonParam, ResourceFindRequest.class); + ResourceFindResponse response = resourceManager.find(request, LocalData.getToken()); + if (response.hasError()) { + return response; + } else if (response.getTotalCount() == 0) { + response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空"); + return response; + } + return ResponseUtil.apply(new WSheet<>(response.getResult())); + } + + public Object imports(MultipartFile file) { + BaseResponse baseResponse = new BaseResponse(); + try { + WSheet sheet = new WSheet<>(file.getBytes(), Resource.class, new WSheet.Validator() { + @Override + public List validate(Resource o) { + ResourceCreateRequest request = MapperUtil.map(o, ResourceCreateRequest.class); + return ValidationUtil.validate(request); + } + }); + + if (sheet.hasError()) { + return ResponseUtil.apply(sheet.getBytes(), sheet.getName() + "-检查.xlsx"); + } else { + return baseResponse; + } + } catch (IOException e) { + e.printStackTrace(); + LogUtil.dumpException(e); + baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错"); + } catch (TemplateNotMatchException | ReadErrorException e) { + baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage()); + } + return baseResponse; + } +} diff --git a/src/main/resources/modules/SpringBoot/java/action/ajax/system/TokensAjax.java b/src/main/resources/modules/SpringBoot/java/action/ajax/system/TokensAjax.java new file mode 100644 index 00000000..ee648deb --- /dev/null +++ b/src/main/resources/modules/SpringBoot/java/action/ajax/system/TokensAjax.java @@ -0,0 +1,90 @@ +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.Tokens; +import ${basePackage}.module.system.mgr.TokensManager; +import ${basePackage}.module.system.req.*; +import ${basePackage}.module.system.rsp.*; + +import java.io.IOException; +import java.util.List; + +public class TokensAjax{ + + @Autowired + private TokensManager tokensManager; + + public TokensCreateResponse create(TokensCreateRequest request) { + return tokensManager.create(request, LocalData.getToken()); + } + + public TokensDeleteResponse delete(TokensDeleteRequest request) { + return tokensManager.delete(request, LocalData.getToken()); + } + + public TokensUpdateResponse update(TokensUpdateRequest request) { + return tokensManager.update(request, LocalData.getToken()); + } + + public TokensFindResponse find(TokensFindRequest request) { + return tokensManager.find(request, LocalData.getToken()); + } + + public TokensGetResponse get(TokensGetRequest request) { + return tokensManager.get(request, LocalData.getToken()); + } + + public Object template(){ + return ResponseUtil.apply(new WSheet<>(Tokens.class)); + } + + public Object exports(TreeNode jsonParam) { + TokensFindRequest request = MapperUtil.toJava(jsonParam, TokensFindRequest.class); + TokensFindResponse response = tokensManager.find(request, LocalData.getToken()); + if (response.hasError()) { + return response; + } else if (response.getTotalCount() == 0) { + response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空"); + return response; + } + return ResponseUtil.apply(new WSheet<>(response.getResult())); + } + + public Object imports(MultipartFile file) { + BaseResponse baseResponse = new BaseResponse(); + try { + WSheet sheet = new WSheet<>(file.getBytes(), Tokens.class, new WSheet.Validator() { + @Override + public List validate(Tokens o) { + TokensCreateRequest request = MapperUtil.map(o, TokensCreateRequest.class); + return ValidationUtil.validate(request); + } + }); + + if (sheet.hasError()) { + return ResponseUtil.apply(sheet.getBytes(), sheet.getName() + "-检查.xlsx"); + } else { + return baseResponse; + } + } catch (IOException e) { + e.printStackTrace(); + LogUtil.dumpException(e); + baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错"); + } catch (TemplateNotMatchException | ReadErrorException e) { + baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage()); + } + return baseResponse; + } +} diff --git a/src/main/resources/modules/SpringBoot/java/action/api/system/ResourceApi.java b/src/main/resources/modules/SpringBoot/java/action/api/system/ResourceApi.java new file mode 100644 index 00000000..db5136a9 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/java/action/api/system/ResourceApi.java @@ -0,0 +1,33 @@ +package ${basePackage}.action.api.system; + +import ${basePackage}.frame.auth.LocalData; +import ${basePackage}.module.system.mgr.ResourceManager; +import ${basePackage}.module.system.req.*; +import ${basePackage}.module.system.rsp.*; +import org.springframework.beans.factory.annotation.Autowired; + +public class ResourceApi{ + + @Autowired + private ResourceManager resourceManager; + + public ResourceCreateResponse create(ResourceCreateRequest request) { + return resourceManager.create(request, LocalData.getToken()); + } + + public ResourceDeleteResponse delete(ResourceDeleteRequest request) { + return resourceManager.delete(request, LocalData.getToken()); + } + + public ResourceUpdateResponse update(ResourceUpdateRequest request) { + return resourceManager.update(request, LocalData.getToken()); + } + + public ResourceFindResponse find(ResourceFindRequest request) { + return resourceManager.find(request, LocalData.getToken()); + } + + public ResourceGetResponse get(ResourceGetRequest request) { + return resourceManager.get(request, LocalData.getToken()); + } +} diff --git a/src/main/resources/modules/SpringBoot/java/action/api/system/TokensApi.java b/src/main/resources/modules/SpringBoot/java/action/api/system/TokensApi.java new file mode 100644 index 00000000..1ff988c7 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/java/action/api/system/TokensApi.java @@ -0,0 +1,33 @@ +package ${basePackage}.action.api.system; + +import ${basePackage}.frame.auth.LocalData; +import ${basePackage}.module.system.mgr.TokensManager; +import ${basePackage}.module.system.req.*; +import ${basePackage}.module.system.rsp.*; +import org.springframework.beans.factory.annotation.Autowired; + +public class TokensApi{ + + @Autowired + private TokensManager tokensManager; + + public TokensCreateResponse create(TokensCreateRequest request) { + return tokensManager.create(request, LocalData.getToken()); + } + + public TokensDeleteResponse delete(TokensDeleteRequest request) { + return tokensManager.delete(request, LocalData.getToken()); + } + + public TokensUpdateResponse update(TokensUpdateRequest request) { + return tokensManager.update(request, LocalData.getToken()); + } + + public TokensFindResponse find(TokensFindRequest request) { + return tokensManager.find(request, LocalData.getToken()); + } + + public TokensGetResponse get(TokensGetRequest request) { + return tokensManager.get(request, LocalData.getToken()); + } +}