From 34e326aff66d34173c4afa5b48004a028bafef8d Mon Sep 17 00:00:00 2001 From: thinkgem Date: Tue, 12 Jul 2022 16:38:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=B7=A6=E6=A0=91=E5=8F=B3?= =?UTF-8?q?=E8=A1=A8=E5=92=8C=E5=AF=BC=E5=85=A5=E5=AF=BC=E5=87=BA=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=94=9F=E6=88=90=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/modules/gen/config.xml | 2 + .../templates/modules/gen/crud/controller.xml | 71 +- .../templates/modules/gen/crud/entity.xml | 732 +++++++++--------- .../templates/modules/gen/crud/service.xml | 63 +- .../templates/modules/gen/crud/viewIndex.xml | 96 +++ .../templates/modules/gen/crud/viewList.xml | 63 +- .../modules/gen/crud_cloud/controller.xml | 71 +- .../modules/gen/crud_cloud/entity.xml | 729 ++++++++--------- .../modules/gen/crud_cloud/service.xml | 70 +- .../modules/gen/crud_cloud/viewIndex.xml | 96 +++ .../modules/gen/crud_cloud/viewList.xml | 63 +- 11 files changed, 1330 insertions(+), 726 deletions(-) create mode 100644 modules/core/src/main/resources/templates/modules/gen/crud/viewIndex.xml create mode 100644 modules/core/src/main/resources/templates/modules/gen/crud_cloud/viewIndex.xml diff --git a/modules/core/src/main/resources/templates/modules/gen/config.xml b/modules/core/src/main/resources/templates/modules/gen/config.xml index 1fd2789b..47ed8517 100644 --- a/modules/core/src/main/resources/templates/modules/gen/config.xml +++ b/modules/core/src/main/resources/templates/modules/gen/config.xml @@ -11,6 +11,7 @@ + @@ -32,6 +33,7 @@ + diff --git a/modules/core/src/main/resources/templates/modules/gen/crud/controller.xml b/modules/core/src/main/resources/templates/modules/gen/crud/controller.xml index b8b2685a..302ee4af 100644 --- a/modules/core/src/main/resources/templates/modules/gen/crud/controller.xml +++ b/modules/core/src/main/resources/templates/modules/gen/crud/controller.xml @@ -9,9 +9,10 @@ package ${packageName}.${moduleName}.web${isNotEmpty(subModuleName)?'.'+subModuleName:''}; <% if (table.isTreeEntity){ %> -import java.util.List; import java.util.Map; -<% }else{ %> +<% } %> +<% if (!table.isTreeEntity || toBoolean(table.optionMap['isImportExport'])){ %> +import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; <% } %> @@ -27,8 +28,10 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.jeesite.common.config.Global; -<% if(table.isTreeEntity){ %> +<% if(table.isTreeEntity || toBoolean(table.optionMap['isImportExport'])){ %> import com.jeesite.common.collect.ListUtils; +<% } %> +<% if(table.isTreeEntity){ %> import com.jeesite.common.collect.MapUtils; import com.jeesite.common.lang.StringUtils; import com.jeesite.common.idgen.IdGen; @@ -36,6 +39,12 @@ import com.jeesite.modules.sys.utils.UserUtils; <% }else{ %> import com.jeesite.common.entity.Page; <% } %> +<% if(toBoolean(table.optionMap['isImportExport'])){ %> +import com.jeesite.common.lang.DateUtils; +import com.jeesite.common.utils.excel.ExcelExport; +import com.jeesite.common.utils.excel.annotation.ExcelField.Type; +import org.springframework.web.multipart.MultipartFile; +<% } %> <% if (table.tplCategory == 'crud_select'){ %> import com.alibaba.fastjson.JSONValidator; import com.jeesite.common.codec.EncodeUtils; @@ -75,6 +84,18 @@ public class ${ClassName}Controller extends BaseController { return ${className}Service.getAndValid(${className}); <% } %> } + <% if(table.isTreeEntity || isNotBlank(table.optionMap['leftTreeRightTableUrl'])){ %> + + /** + * 管理主页 + */ + @RequiresPermissions("${permissionPrefix}:view") + @RequestMapping(value = "index") + public String index(${ClassName} ${className}, Model model) { + model.addAttribute("${className}", ${className}); + return "${lastPackageName}/${viewPrefix}Index"; + } + <% } %> /** * 查询列表 @@ -192,6 +213,50 @@ public class ${ClassName}Controller extends BaseController { ${className}Service.save(${className}); return renderResult(Global.TRUE, text("保存${functionNameSimple}成功!")); } + <% if(toBoolean(table.optionMap['isImportExport'])){ %> + + /** + * 导出数据 + */ + @RequiresPermissions("${permissionPrefix}:view") + @RequestMapping(value = "exportData") + public void exportData(${ClassName} ${className}, HttpServletResponse response) { + List<${ClassName}> list = ${className}Service.findList(${className}); + String fileName = "${functionNameSimple}" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx"; + try(ExcelExport ee = new ExcelExport("${functionNameSimple}", ${ClassName}.class)){ + ee.setDataList(list).write(response, fileName); + } + } + + /** + * 下载模板 + */ + @RequiresPermissions("${permissionPrefix}:view") + @RequestMapping(value = "importTemplate") + public void importTemplate(HttpServletResponse response) { + ${ClassName} ${className} = new ${ClassName}(); + List<${ClassName}> list = ListUtils.newArrayList(${className}); + String fileName = "${functionNameSimple}模板.xlsx"; + try(ExcelExport ee = new ExcelExport("${functionNameSimple}", ${ClassName}.class, Type.IMPORT)){ + ee.setDataList(list).write(response, fileName); + } + } + + /** + * 导入数据 + */ + @ResponseBody + @RequiresPermissions("${permissionPrefix}:edit") + @PostMapping(value = "importData") + public String importData(MultipartFile file) { + try { + String message = ${className}Service.importData(file); + return renderResult(Global.TRUE, "posfull:"+message); + } catch (Exception ex) { + return renderResult(Global.FALSE, "posfull:"+ex.getMessage()); + } + } + <% } %> <% if(toBoolean(table.optionMap['isHaveDisableEnable'])){ %> /** diff --git a/modules/core/src/main/resources/templates/modules/gen/crud/entity.xml b/modules/core/src/main/resources/templates/modules/gen/crud/entity.xml index 97a6a990..7b80ca95 100644 --- a/modules/core/src/main/resources/templates/modules/gen/crud/entity.xml +++ b/modules/core/src/main/resources/templates/modules/gen/crud/entity.xml @@ -1,359 +1,375 @@ - - - \ No newline at end of file diff --git a/modules/core/src/main/resources/templates/modules/gen/crud_cloud/controller.xml b/modules/core/src/main/resources/templates/modules/gen/crud_cloud/controller.xml index 1d5952a3..6517d403 100644 --- a/modules/core/src/main/resources/templates/modules/gen/crud_cloud/controller.xml +++ b/modules/core/src/main/resources/templates/modules/gen/crud_cloud/controller.xml @@ -9,9 +9,10 @@ package ${packageName}.${moduleName}.web${isNotEmpty(subModuleName)?'.'+subModuleName:''}; <% if (table.isTreeEntity){ %> -import java.util.List; import java.util.Map; -<% }else{ %> +<% } %> +<% if (!table.isTreeEntity || toBoolean(table.optionMap['isImportExport'])){ %> +import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; <% } %> @@ -27,8 +28,10 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.jeesite.common.config.Global; -<% if(table.isTreeEntity){ %> +<% if(table.isTreeEntity || toBoolean(table.optionMap['isImportExport'])){ %> import com.jeesite.common.collect.ListUtils; +<% } %> +<% if(table.isTreeEntity){ %> import com.jeesite.common.collect.MapUtils; import com.jeesite.common.lang.StringUtils; import com.jeesite.common.idgen.IdGen; @@ -36,6 +39,12 @@ import com.jeesite.modules.sys.utils.UserUtils; <% }else{ %> import com.jeesite.common.entity.Page; <% } %> +<% if(toBoolean(table.optionMap['isImportExport'])){ %> +import com.jeesite.common.lang.DateUtils; +import com.jeesite.common.utils.excel.ExcelExport; +import com.jeesite.common.utils.excel.annotation.ExcelField.Type; +import org.springframework.web.multipart.MultipartFile; +<% } %> <% if (table.tplCategory == 'crud_select'){ %> import com.alibaba.fastjson.JSONValidator; import com.jeesite.common.codec.EncodeUtils; @@ -75,6 +84,18 @@ public class ${ClassName}Controller extends BaseController { return ${className}Service.getAndValid(${className}); <% } %> } + <% if(table.isTreeEntity || isNotBlank(table.optionMap['leftTreeRightTableUrl'])){ %> + + /** + * 管理主页 + */ + @RequiresPermissions("${permissionPrefix}:view") + @RequestMapping(value = "index") + public String index(${ClassName} ${className}, Model model) { + model.addAttribute("${className}", ${className}); + return "${lastPackageName}/${viewPrefix}Index"; + } + <% } %> /** * 查询列表 @@ -192,6 +213,50 @@ public class ${ClassName}Controller extends BaseController { ${className}Service.save(${className}); return renderResult(Global.TRUE, text("保存${functionNameSimple}成功!")); } + <% if(toBoolean(table.optionMap['isImportExport'])){ %> + + /** + * 导出数据 + */ + @RequiresPermissions("${permissionPrefix}:view") + @RequestMapping(value = "exportData") + public void exportData(${ClassName} ${className}, HttpServletResponse response) { + List<${ClassName}> list = ${className}Service.findList(${className}); + String fileName = "${functionNameSimple}" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx"; + try(ExcelExport ee = new ExcelExport("${functionNameSimple}", ${ClassName}.class)){ + ee.setDataList(list).write(response, fileName); + } + } + + /** + * 下载模板 + */ + @RequiresPermissions("${permissionPrefix}:view") + @RequestMapping(value = "importTemplate") + public void importTemplate(HttpServletResponse response) { + ${ClassName} ${className} = new ${ClassName}(); + List<${ClassName}> list = ListUtils.newArrayList(${className}); + String fileName = "${functionNameSimple}模板.xlsx"; + try(ExcelExport ee = new ExcelExport("${functionNameSimple}", ${ClassName}.class, Type.IMPORT)){ + ee.setDataList(list).write(response, fileName); + } + } + + /** + * 导入数据 + */ + @ResponseBody + @RequiresPermissions("${permissionPrefix}:edit") + @PostMapping(value = "importData") + public String importData(MultipartFile file) { + try { + String message = ${className}Service.importData(file); + return renderResult(Global.TRUE, "posfull:"+message); + } catch (Exception ex) { + return renderResult(Global.FALSE, "posfull:"+ex.getMessage()); + } + } + <% } %> <% if(toBoolean(table.optionMap['isHaveDisableEnable'])){ %> /** diff --git a/modules/core/src/main/resources/templates/modules/gen/crud_cloud/entity.xml b/modules/core/src/main/resources/templates/modules/gen/crud_cloud/entity.xml index de773d8b..9a362616 100644 --- a/modules/core/src/main/resources/templates/modules/gen/crud_cloud/entity.xml +++ b/modules/core/src/main/resources/templates/modules/gen/crud_cloud/entity.xml @@ -1,356 +1,375 @@ - - - \ No newline at end of file