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 fb5afb35..e2d81f79 100644 --- a/modules/core/src/main/resources/templates/modules/gen/config.xml +++ b/modules/core/src/main/resources/templates/modules/gen/config.xml @@ -10,8 +10,8 @@ - + @@ -22,8 +22,9 @@ - + + @@ -31,8 +32,9 @@ - + + @@ -70,6 +72,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 c5aa8441..a550ce66 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,8 +84,8 @@ public class ${ClassName}Controller extends BaseController { return ${className}Service.getAndValid(${className}); <% } %> } - <% if(table.isTreeEntity){ %> - + <% if(table.isTreeEntity || isNotBlank(table.optionMap['leftTreeRightTableUrl'])){ %> + /** * 管理主页 */ @@ -204,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 4ae504b3..f915d114 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 @@ - - -