From afec7ed79376618c467d709a763152d4d91adeb6 Mon Sep 17 00:00:00 2001 From: wangbing <1919101440@qq.com> Date: Fri, 29 Nov 2019 00:28:56 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 8117d223a3aa66fa9c36c2af712cac6157708310 --- .../manger/callable/SpringBootCallable.java | 76 ++++++++++------ .../java/action/ajax/system/FileAjax.java | 2 +- .../SpringBoot/java/action/api/Api.java | 58 ++++++++++++ .../java/action/api/system/AuthApi.java | 23 +++++ .../java/action/api/system/DictApi.java | 40 +++++++++ .../java/action/api/system/DictItemApi.java | 36 ++++++++ .../java/action/api/system/FileApi.java | 54 ++++++++++++ .../SpringBoot/java/module/mpr/mapper.ftl | 88 ++++++++++++++++++- .../module/system/mgr/DictManagerImpl.java | 2 + .../resources/templates/control/nav.ftl | 2 - .../resources/templates/screen/module/mgr.ftl | 24 ++--- .../templates/screen/module/system/dict.ftl | 13 +-- 12 files changed, 367 insertions(+), 51 deletions(-) create mode 100644 src/main/resources/modules/SpringBoot/java/action/api/Api.java create mode 100644 src/main/resources/modules/SpringBoot/java/action/api/system/AuthApi.java create mode 100644 src/main/resources/modules/SpringBoot/java/action/api/system/DictApi.java create mode 100644 src/main/resources/modules/SpringBoot/java/action/api/system/DictItemApi.java create mode 100644 src/main/resources/modules/SpringBoot/java/action/api/system/FileApi.java diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java index 5905fbef..2ddede74 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java @@ -220,41 +220,65 @@ public class SpringBootCallable implements Callable { ctx.put("modules", project.getModules()); File control = new File(root.getAbsolutePath(), "control"); - control.mkdirs(); - File ajax = new File(root.getAbsolutePath(), "ajax"); - ajax.mkdirs(); - File system = new File(ajax.getAbsolutePath(), "system"); - system.mkdirs(); File screen = new File(root.getAbsolutePath(), "screen"); screen.mkdirs(); + control.mkdirs(); freeMarkerManager.outputTemp(new File(control.getAbsolutePath(), "Header.java"), option + "/java/action/control/Header.java", ctx); - freeMarkerManager.outputTemp(new File(system.getAbsolutePath(), "AuthAjax.java"), option + "/java/action/ajax/system/AuthAjax.java", ctx); - freeMarkerManager.outputTemp(new File(system.getAbsolutePath(), "DictAjax.java"), option + "/java/action/ajax/system/DictAjax.java", ctx); - freeMarkerManager.outputTemp(new File(system.getAbsolutePath(), "DictItemAjax.java"), option + "/java/action/ajax/system/DictItemAjax.java", ctx); - freeMarkerManager.outputTemp(new File(system.getAbsolutePath(), "FileAjax.java"), option + "/java/action/ajax/system/FileAjax.java", ctx); - - - for (Module module : project.getModules()) { - File m = new File(ajax.getAbsolutePath(), module.getModuleName()); - m.mkdirs(); - - for (Table table : module.getTables()) { - HashMap ctxss = new HashMap(); - ctxss.put("basePackage", project.getProjectBasePackage()); - ctxss.put("module", module.getModuleName()); - ctxss.put("author", project.getProjectAuthor()); - ctxss.put("date", new Date()); - ctxss.put("table", table); - - freeMarkerManager.outputTemp(new File(m.getAbsolutePath(), table.getCName() + "Ajax.java"), option + "/java/action/ajax/Ajax.java", ctxss); + { + File ajax = new File(root.getAbsolutePath(), "ajax"); + ajax.mkdirs(); + File system = new File(ajax.getAbsolutePath(), "system"); + system.mkdirs(); + freeMarkerManager.outputTemp(new File(system.getAbsolutePath(), "AuthAjax.java"), option + "/java/action/ajax/system/AuthAjax.java", ctx); + freeMarkerManager.outputTemp(new File(system.getAbsolutePath(), "DictAjax.java"), option + "/java/action/ajax/system/DictAjax.java", ctx); + freeMarkerManager.outputTemp(new File(system.getAbsolutePath(), "DictItemAjax.java"), option + "/java/action/ajax/system/DictItemAjax.java", ctx); + freeMarkerManager.outputTemp(new File(system.getAbsolutePath(), "FileAjax.java"), option + "/java/action/ajax/system/FileAjax.java", ctx); + + for (Module module : project.getModules()) { + File m = new File(ajax.getAbsolutePath(), module.getModuleName()); + m.mkdirs(); + + for (Table table : module.getTables()) { + HashMap ctxss = new HashMap(); + ctxss.put("basePackage", project.getProjectBasePackage()); + ctxss.put("module", module.getModuleName()); + ctxss.put("author", project.getProjectAuthor()); + ctxss.put("date", new Date()); + ctxss.put("table", table); + + freeMarkerManager.outputTemp(new File(m.getAbsolutePath(), table.getCName() + "Ajax.java"), option + "/java/action/ajax/Ajax.java", ctxss); + } } } - + { + File api = new File(root.getAbsolutePath(), "api"); + api.mkdirs(); + File system = new File(api.getAbsolutePath(), "system"); + system.mkdirs(); + freeMarkerManager.outputTemp(new File(system.getAbsolutePath(), "AuthApi.java"), option + "/java/action/api/system/AuthApi.java", ctx); + freeMarkerManager.outputTemp(new File(system.getAbsolutePath(), "DictApi.java"), option + "/java/action/api/system/DictApi.java", ctx); + freeMarkerManager.outputTemp(new File(system.getAbsolutePath(), "DictItemApi.java"), option + "/java/action/api/system/DictItemApi.java", ctx); + freeMarkerManager.outputTemp(new File(system.getAbsolutePath(), "FileApi.java"), option + "/java/action/api/system/FileApi.java", ctx); + + for (Module module : project.getModules()) { + File m = new File(api.getAbsolutePath(), module.getModuleName()); + m.mkdirs(); + + for (Table table : module.getTables()) { + HashMap ctxss = new HashMap(); + ctxss.put("basePackage", project.getProjectBasePackage()); + ctxss.put("module", module.getModuleName()); + ctxss.put("author", project.getProjectAuthor()); + ctxss.put("date", new Date()); + ctxss.put("table", table); + freeMarkerManager.outputTemp(new File(m.getAbsolutePath(), table.getCName() + "Api.java"), option + "/java/action/api/Api.java", ctxss); + } + } + } freeMarkerManager.outputTemp(new File(screen.getAbsolutePath(), "Index.java"), option + "/java/action/screen/Index.java", ctx); - freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "GlobalController.java"), option + "/java/action/GlobalController.java", ctx); // freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "AjaxController.java"), option + "/java/action/AjaxController.java", ctx); diff --git a/src/main/resources/modules/SpringBoot/java/action/ajax/system/FileAjax.java b/src/main/resources/modules/SpringBoot/java/action/ajax/system/FileAjax.java index a735bc66..b6f369f4 100644 --- a/src/main/resources/modules/SpringBoot/java/action/ajax/system/FileAjax.java +++ b/src/main/resources/modules/SpringBoot/java/action/ajax/system/FileAjax.java @@ -15,7 +15,7 @@ import java.net.URLEncoder; public class FileAjax { - public Object upload(MultipartFile file) { + public FileUploadResponse upload(MultipartFile file) { FileUploadResponse fileUploadResponse = new FileUploadResponse(); String fileName = file.getOriginalFilename(); diff --git a/src/main/resources/modules/SpringBoot/java/action/api/Api.java b/src/main/resources/modules/SpringBoot/java/action/api/Api.java new file mode 100644 index 00000000..c4bf74d9 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/java/action/api/Api.java @@ -0,0 +1,58 @@ +package ${basePackage}.action.api.${module}; + +import ${basePackage}.frame.auth.LocalData; +import ${basePackage}.module.${module}.mgr.${table.getCName()}Manager; +import ${basePackage}.module.${module}.req.*; +import ${basePackage}.module.${module}.rsp.*; +import org.springframework.beans.factory.annotation.Autowired; + +import java.io.IOException; +import java.util.List; + +public class ${table.getCName()}Api{ + + @Autowired + private ${table.getCName()}Manager ${table.getFName()}Manager; + +<#if table.getCreate()> + public ${table.getCName()}CreateResponse create(${table.getCName()}CreateRequest request) { + return ${table.getFName()}Manager.create(request, LocalData.getToken()); + } + +<#if table.getDelete()> + + public ${table.getCName()}DeleteResponse delete(${table.getCName()}DeleteRequest request) { + return ${table.getFName()}Manager.delete(request, LocalData.getToken()); + } + +<#if table.getUpdate()> + + public ${table.getCName()}UpdateResponse update(${table.getCName()}UpdateRequest request) { + return ${table.getFName()}Manager.update(request, LocalData.getToken()); + } + +<#if table.getFind()> + + public ${table.getCName()}FindResponse find(${table.getCName()}FindRequest request) { + return ${table.getFName()}Manager.find(request, LocalData.getToken()); + } + +<#if table.getGet()> + + public ${table.getCName()}GetResponse get(${table.getCName()}GetRequest request) { + return ${table.getFName()}Manager.get(request, LocalData.getToken()); + } + +<#if table.getSearch()> + + public ${table.getCName()}SearchResponse search(${table.getCName()}SearchRequest request) { + return ${table.getFName()}Manager.search(request, LocalData.getToken()); + } + +<#if table.getGetAll()> + + public ${table.getCName()}GetAllResponse getAll(${table.getCName()}GetAllRequest request) { + return ${table.getFName()}Manager.getAll(request, LocalData.getToken()); + } + +} diff --git a/src/main/resources/modules/SpringBoot/java/action/api/system/AuthApi.java b/src/main/resources/modules/SpringBoot/java/action/api/system/AuthApi.java new file mode 100644 index 00000000..5bcb8804 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/java/action/api/system/AuthApi.java @@ -0,0 +1,23 @@ +package ${basePackage}.action.api.system; + +import ${basePackage}.module.system.req.AuthLoginRequest; +import ${basePackage}.module.system.rsp.AuthLoginResponse; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class AuthApi { + + public AuthLoginResponse login(AuthLoginRequest request, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { + AuthLoginResponse response = new AuthLoginResponse(); + + // todo 设置cookie + Cookie token = new Cookie("token", ""); + token.setDomain(httpServletRequest.getServerName()); + token.setPath("/"); + httpServletResponse.addCookie(token); + + return response; + } +} diff --git a/src/main/resources/modules/SpringBoot/java/action/api/system/DictApi.java b/src/main/resources/modules/SpringBoot/java/action/api/system/DictApi.java new file mode 100644 index 00000000..dc176d9d --- /dev/null +++ b/src/main/resources/modules/SpringBoot/java/action/api/system/DictApi.java @@ -0,0 +1,40 @@ +package ${basePackage}.action.api.system; + +import ${basePackage}.frame.auth.LocalData; +import ${basePackage}.module.system.mgr.DictManager; +import ${basePackage}.module.system.req.*; +import ${basePackage}.module.system.rsp.*; +import org.springframework.beans.factory.annotation.Autowired; + +import java.io.IOException; +import java.util.List; + +public class DictApi { + + @Autowired + private DictManager dictManager; + + public DictCreateResponse create(DictCreateRequest request) { + return dictManager.create(request, LocalData.getToken()); + } + + public DictDeleteResponse delete(DictDeleteRequest request) { + return dictManager.delete(request, LocalData.getToken()); + } + + public DictUpdateResponse update(DictUpdateRequest request) { + return dictManager.update(request, LocalData.getToken()); + } + + public DictFindResponse find(DictFindRequest request) { + return dictManager.find(request, LocalData.getToken()); + } + + public DictGetResponse get(DictGetRequest request) { + return dictManager.get(request, LocalData.getToken()); + } + + public DictLoadResponse load(DictLoadRequest request) { + return dictManager.load(request, LocalData.getToken()); + } +} diff --git a/src/main/resources/modules/SpringBoot/java/action/api/system/DictItemApi.java b/src/main/resources/modules/SpringBoot/java/action/api/system/DictItemApi.java new file mode 100644 index 00000000..78f16ff2 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/java/action/api/system/DictItemApi.java @@ -0,0 +1,36 @@ +package ${basePackage}.action.api.system; + +import ${basePackage}.frame.auth.LocalData; +import ${basePackage}.module.system.mgr.DictItemManager; +import ${basePackage}.module.system.req.*; +import ${basePackage}.module.system.rsp.*; +import org.springframework.beans.factory.annotation.Autowired; + +import java.io.IOException; +import java.util.List; + +public class DictItemApi { + + @Autowired + private DictItemManager dictItemManager; + + public DictItemCreateResponse create(DictItemCreateRequest request) { + return dictItemManager.create(request, LocalData.getToken()); + } + + public DictItemDeleteResponse delete(DictItemDeleteRequest request) { + return dictItemManager.delete(request, LocalData.getToken()); + } + + public DictItemUpdateResponse update(DictItemUpdateRequest request) { + return dictItemManager.update(request, LocalData.getToken()); + } + + public DictItemFindResponse find(DictItemFindRequest request) { + return dictItemManager.find(request, LocalData.getToken()); + } + + public DictItemGetResponse get(DictItemGetRequest request) { + return dictItemManager.get(request, LocalData.getToken()); + } +} diff --git a/src/main/resources/modules/SpringBoot/java/action/api/system/FileApi.java b/src/main/resources/modules/SpringBoot/java/action/api/system/FileApi.java new file mode 100644 index 00000000..cc6578d8 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/java/action/api/system/FileApi.java @@ -0,0 +1,54 @@ +package ${basePackage}.action.api.system; + +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.multipart.MultipartFile; +import ${basePackage}.frame.base.BaseResponse; +import ${basePackage}.frame.base.ErrorType; +import ${basePackage}.frame.base.FileUploadResponse; + +import javax.swing.tree.TreeNode; +import java.io.IOException; +import java.net.URLEncoder; + +public class FileApi { + + public FileUploadResponse upload(MultipartFile file) { + FileUploadResponse fileUploadResponse = new FileUploadResponse(); + String fileName = file.getOriginalFilename(); + + //======== + // todo 处理文件 + //======== + fileUploadResponse.setId(1L); + fileUploadResponse.setUrl("example.com\\img\\1.jpg"); + fileUploadResponse.setDownloadUrl("example.com\\img\\1.jpg"); + + if (file != null) { + fileUploadResponse.addError(ErrorType.BUSINESS_ERROR, "文件上传成功,但未处理文件[" + fileName + "]!"); + } else { + fileUploadResponse.addError(ErrorType.BUSINESS_ERROR, "文件上传失败!"); + } + + return fileUploadResponse; + } + + public Object download(TreeNode jsonParam) { + try { + //======== + // todo 下载示例 + //======== + byte[] bytes = "test".getBytes(); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); + headers.setContentDispositionFormData("attachment", URLEncoder.encode("example.test", "utf-8")); + return new ResponseEntity<>(bytes, headers, HttpStatus.OK); + } catch (IOException e) { + BaseResponse baseResponse = new BaseResponse(); + baseResponse.addError(ErrorType.BUSINESS_ERROR, ""); + return baseResponse; + } + } +} diff --git a/src/main/resources/modules/SpringBoot/java/module/mpr/mapper.ftl b/src/main/resources/modules/SpringBoot/java/module/mpr/mapper.ftl index bd4af70a..cd9cbd81 100644 --- a/src/main/resources/modules/SpringBoot/java/module/mpr/mapper.ftl +++ b/src/main/resources/modules/SpringBoot/java/module/mpr/mapper.ftl @@ -38,25 +38,105 @@ <#list table.fields as f> <#if f.isQuery> <#if dataBase == 'ORACLE'> +<#if f.fieldType.javaType() == "Boolean"> + + AND "${f.fieldName}" = ${r"#{"}request.${f.getFName()}} + + +<#if f.fieldType.javaType() == "Byte"> + + AND "${f.fieldName}" = ${r"#{"}request.${f.getFName()}} + + +<#if f.fieldType.javaType() == "Short"> + + AND "${f.fieldName}" = ${r"#{"}request.${f.getFName()}} + + +<#if f.fieldType.javaType() == "Integer"> + + AND "${f.fieldName}" = ${r"#{"}request.${f.getFName()}} + + +<#if f.fieldType.javaType() == "Long"> + + AND "${f.fieldName}" = ${r"#{"}request.${f.getFName()}} + + +<#if f.fieldType.javaType() == "Float"> + + AND "${f.fieldName}" = ${r"#{"}request.${f.getFName()}} + + +<#if f.fieldType.javaType() == "Double"> + + AND "${f.fieldName}" = ${r"#{"}request.${f.getFName()}} + + +<#if f.fieldType.javaType() == "Character"> + + AND "${f.fieldName}" = ${r"#{"}request.${f.getFName()}} + + <#if f.fieldType.javaType() == "String"> AND "${f.fieldName}" = ${r"#{"}request.${f.getFName()}} +<#if f.fieldType.javaType() == "Date"> + + AND to_char("${f.fieldName}",'yyyy-MM-dd HH24:mi:ss') = to_char(${r"#{"}request.${f.getFName()}},'yyyy-MM-dd HH24:mi:ss') + + +<#elseif dataBase='MYSQL'> <#if f.fieldType.javaType() == "Boolean"> - AND "${f.fieldName}" = ${r"#{"}request.${f.getFName()}} + AND `${f.fieldName}` = ${r"#{"}request.${f.getFName()}} + + +<#if f.fieldType.javaType() == "Byte"> + + AND `${f.fieldName}` = ${r"#{"}request.${f.getFName()}} + + +<#if f.fieldType.javaType() == "Short"> + + AND `${f.fieldName}` = ${r"#{"}request.${f.getFName()}} + + +<#if f.fieldType.javaType() == "Integer"> + + AND `${f.fieldName}` = ${r"#{"}request.${f.getFName()}} + + +<#if f.fieldType.javaType() == "Long"> + + AND `${f.fieldName}` = ${r"#{"}request.${f.getFName()}} + + +<#if f.fieldType.javaType() == "Float"> + + AND `${f.fieldName}` = ${r"#{"}request.${f.getFName()}} + + +<#if f.fieldType.javaType() == "Double"> + + AND `${f.fieldName}` = ${r"#{"}request.${f.getFName()}} + + +<#if f.fieldType.javaType() == "Character"> + + AND `${f.fieldName}` = ${r"#{"}request.${f.getFName()}} -<#elseif dataBase='MYSQL'> <#if f.fieldType.javaType() == "String"> AND `${f.fieldName}` = ${r"#{"}request.${f.getFName()}} -<#if f.fieldType.javaType() == "Boolean"> +<#if f.fieldType.javaType() == "Date"> - AND `${f.fieldName}` = ${r"#{"}request.${f.getFName()}} + AND DATE_FORMAT(`${f.fieldName}`,"%Y-%m-%d %T") = DATE_FORMAT(${r"#{"}request.${f.getFName()}},"%Y-%m-%d %T") diff --git a/src/main/resources/modules/SpringBoot/java/module/system/mgr/DictManagerImpl.java b/src/main/resources/modules/SpringBoot/java/module/system/mgr/DictManagerImpl.java index 79d88a86..008cbc60 100644 --- a/src/main/resources/modules/SpringBoot/java/module/system/mgr/DictManagerImpl.java +++ b/src/main/resources/modules/SpringBoot/java/module/system/mgr/DictManagerImpl.java @@ -193,6 +193,8 @@ public class DictManagerImpl implements DictManager { DictItemFindRequest dictItemFindRequest = new DictItemFindRequest(); dictItemFindRequest.setDictName(request.getDictName()); + dictItemFindRequest.setValid(true); + dictItemFindRequest.setPageSize(0); DictItemFindResponse dictItemFindResponse = dictItemManager.find(dictItemFindRequest, token); if (dictItemFindResponse.hasError()) { response.addErrors(dictItemFindResponse.getErrors()); diff --git a/src/main/resources/modules/SpringBoot/resources/templates/control/nav.ftl b/src/main/resources/modules/SpringBoot/resources/templates/control/nav.ftl index ff874966..08fdb0fa 100644 --- a/src/main/resources/modules/SpringBoot/resources/templates/control/nav.ftl +++ b/src/main/resources/modules/SpringBoot/resources/templates/control/nav.ftl @@ -129,8 +129,6 @@ nav.e(rsp.errors[0].message) } else { nav.barFinish(); - var blob = utils.base64toBlob(rsp.base64); - utils.blobtoDown(rsp.name,blob); } }); reader.readAsText(response.data, "utf-8"); diff --git a/src/main/resources/modules/SpringBoot/resources/templates/screen/module/mgr.ftl b/src/main/resources/modules/SpringBoot/resources/templates/screen/module/mgr.ftl index 7be3544a..d8e503ce 100644 --- a/src/main/resources/modules/SpringBoot/resources/templates/screen/module/mgr.ftl +++ b/src/main/resources/modules/SpringBoot/resources/templates/screen/module/mgr.ftl @@ -10,14 +10,6 @@ - <#elseif item.fieldType.javaType() =="String" && item.fieldType != "Dict"> - - - - <#elseif item.fieldType.javaType() =="String" && item.fieldType == "Dict"> - - - <#elseif item.fieldType.javaType() =="Byte"> @@ -46,13 +38,21 @@ + <#elseif item.fieldType.javaType() =="String" && item.fieldType != "Dict"> + + + + <#elseif item.fieldType.javaType() =="String" && item.fieldType == "Dict"> + + + <#elseif item.fieldType.javaType() =="Date"> @@ -130,8 +130,8 @@ diff --git a/src/main/resources/modules/SpringBoot/resources/templates/screen/module/system/dict.ftl b/src/main/resources/modules/SpringBoot/resources/templates/screen/module/system/dict.ftl index de4a0d52..28047fa9 100644 --- a/src/main/resources/modules/SpringBoot/resources/templates/screen/module/system/dict.ftl +++ b/src/main/resources/modules/SpringBoot/resources/templates/screen/module/system/dict.ftl @@ -36,12 +36,13 @@ - +