From de04085526eda992155716eda98af621ad681e4e Mon Sep 17 00:00:00 2001 From: Helius <wangdoubleone@gmail.com> Date: Fri, 26 Feb 2021 09:49:14 +0800 Subject: [PATCH] init --- src/main/resources/template/excelTempLateCopy/dao.ftl | 38 src/main/resources/config/code-generation.xml | 157 + src/main/java/com/matrix/codeGeneration/plugin/DateUtils.java | 557 +++++ src/main/java/com/matrix/codeGeneration/core/Generator.java | 105 src/main/java/com/matrix/codeGeneration/ext/AhcsModels.java | 276 ++ src/main/java/com/matrix/codeGeneration/ext/OracleStyleNameConvert.java | 86 src/main/resources/template/excelTempLateCopy/form.ftl | 82 src/main/resources/template/excelTemplateForHis/action.ftl | 71 src/main/resources/template/excelTemplateForBoot/list.ftl | 161 + src/main/resources/template/excelTemplateForCloud/list.ftl | 161 + src/main/java/com/matrix/codeGeneration/model/ModelType.java | 78 src/main/resources/template/excelTempLateCopy/action.ftl | 122 + src/main/java/com/matrix/codeGeneration/convert/DefaultNameConvert.java | 88 src/main/resources/template/excelTempLateCopy/javaBean.ftl | 41 src/main/resources/template/excelTemplateForCloud/daoImpl.ftl | 252 ++ src/main/resources/template/excelTemplateForCloud/javaBean.ftl | 42 src/main/resources/template/excelTemplateForHis/service.ftl | 92 README.md | 5 src/main/java/com/matrix/codeGeneration/ext/Matrix4Models.java | 318 ++ src/main/resources/template/excelTemplate/serviceImpl.ftl | 132 + src/main/resources/template/excelTemplate/sqlFile.ftl | 16 src/main/resources/template/excelTemplateForCloud/dao.ftl | 40 src/main/resources/template/excelTemplateForHis/mybatis-config.ftl | 33 src/main/java/com/matrix/codeGeneration/model/CodeFile.java | 65 src/main/resources/template/excelTemplateForBoot/action.ftl | 122 + src/main/resources/template/excelTemplateForHis/javaBean.ftl | 49 src/main/resources/template/excelTemplate/mybatis-config.ftl | 33 src/main/resources/template/excelTemplateForHis/dao.ftl | 15 src/main/resources/template/excelTemplateForCloud/form.ftl | 82 src/main/resources/template/excelTemplateForBoot/mybatis-config.ftl | 33 src/main/java/com/matrix/codeGeneration/model/PropertyColumn.java | 218 + src/main/resources/template/excelTemplate/list.ftl | 132 + src/main/java/com/matrix/codeGeneration/core/MainClass.java | 26 src/main/java/com/matrix/codeGeneration/model/CodeModel.java | 13 src/main/resources/template/excelTempLateCopy/mybatis-config.ftl | 33 matrix-codeGenerator.zip | 0 src/main/resources/template/excelTemplate/service.ftl | 72 src/main/resources/template/excelTemplateForBoot/数据字典表(模板).xlsx | 0 pom.xml | 94 src/main/java/com/matrix/codeGeneration/model/Constant.java | 68 src/main/resources/template/excelTempLateCopy/数据字典表(模板).xlsx | 0 src/main/resources/template/excelTemplateForHis/daoImpl.ftl | 104 src/main/java/com/matrix/codeGeneration/ext/ExcelDataSource.java | 207 + src/main/java/com/matrix/codeGeneration/convert/NameConvert.java | 57 src/main/resources/template/excelTempLateCopy/sqlFile.ftl | 29 src/main/resources/template/excelTemplateForCloud/mybatis-config.ftl | 33 src/main/resources/template/excelTemplateForBoot/sqlFile.ftl | 46 src/main/resources/template/excelTemplateForCloud/sqlFile.ftl | 54 src/main/resources/template/excelTemplate/form.ftl | 82 src/main/resources/template/excelTemplateForCloud/数据字典表(模板).xlsx | 0 src/main/java/com/matrix/codeGeneration/model/OutDataSource.java | 89 src/main/java/com/matrix/codeGeneration/convert/DefaultTypeHandle.java | 91 src/main/java/com/matrix/codeGeneration/plugin/ExcelImport.java | 326 ++ src/main/resources/template/excelTemplate/daoImpl.ftl | 226 ++ src/main/resources/template/excelTemplateForCloud/action.ftl | 81 src/main/resources/template/excelTemplate/action.ftl | 88 src/main/resources/template/excelTemplateForBoot/daoImpl.ftl | 226 ++ src/main/java/com/matrix/codeGeneration/model/TableClassModel.java | 150 + src/main/resources/template/excelTempLateCopy/daoImpl.ftl | 226 ++ src/main/resources/template/excelTemplate/javaBean.ftl | 41 src/main/java/com/matrix/codeGeneration/model/CommonData.java | 19 src/main/resources/template/excelTemplateForBoot/form.ftl | 82 src/main/java/com/matrix/codeGeneration/model/Attribute.java | 43 src/main/resources/template/excelTemplateForBoot/javaBean.ftl | 42 src/main/resources/template/excelTemplate/dao.ftl | 38 src/main/resources/template/excelTemplateForBoot/dao.ftl | 38 src/main/resources/template/excelTemplateForHis/sqlFile.ftl | 34 src/main/java/com/matrix/codeGeneration/model/TypeHandle.java | 9 src/main/resources/template/excelTempLateCopy/list.ftl | 132 + 69 files changed, 6,597 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 68633ed..27f0de7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1 @@ -## matrix-codeGenerator - -matrix-codeGenerator - +#codegen3.0 diff --git a/matrix-codeGenerator.zip b/matrix-codeGenerator.zip new file mode 100755 index 0000000..7022f26 --- /dev/null +++ b/matrix-codeGenerator.zip Binary files differ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..8a6190e --- /dev/null +++ b/pom.xml @@ -0,0 +1,94 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>com.zkingsoft</groupId> + <artifactId>CodeGenerator</artifactId> + <version>0.0.1-SNAPSHOT</version> + <name>CodeGenerator</name> + <description>CodeGenerator</description> + <dependencies> + <dependency> + <groupId>org.httpobjects.freemarker</groupId> + <artifactId>httpobjects-freemarker</artifactId> + <version>0.5.0</version> + </dependency> + + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + <version>1.0.4</version> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-jcl</artifactId> + <version>2.5</version> + <classifier>sources</classifier> + </dependency> + + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + <version>3.2.11.RELEASE</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context-support</artifactId> + <version>3.2.11.RELEASE</version> + </dependency> + + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.4</version> + </dependency> + <dependency> + <groupId>commons-codec</groupId> + <artifactId>commons-codec</artifactId> + <version>1.3</version> + </dependency> + + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + <version>3.2.12.RELEASE</version> + </dependency> + + <dependency> + <groupId>org.mybatis</groupId> + <artifactId>mybatis</artifactId> + <version>3.2.1</version> + </dependency> + <dependency> + <groupId>mysql</groupId> + <artifactId>mysql-connector-java</artifactId> + <version>5.1.26</version> + </dependency> + + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.6</version> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.apache.poi</groupId> + <artifactId>poi-ooxml</artifactId> + <version>3.8</version> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.1</version> + <configuration> + <source>1.7</source> + <target>1.7</target> + </configuration> + </plugin> + </plugins> + </build> + +</project> \ No newline at end of file diff --git a/src/main/java/com/matrix/codeGeneration/convert/DefaultNameConvert.java b/src/main/java/com/matrix/codeGeneration/convert/DefaultNameConvert.java new file mode 100644 index 0000000..2c28502 --- /dev/null +++ b/src/main/java/com/matrix/codeGeneration/convert/DefaultNameConvert.java @@ -0,0 +1,88 @@ +package com.matrix.codeGeneration.convert; + +/** + * 默认的名称实现的转换器 + * + * @author Administrator + * + */ +public class DefaultNameConvert implements NameConvert { + + @Override + public String propertyToColumn(String property) { + StringBuffer columnName = new StringBuffer(property); + for (int i = 0; i < columnName.length(); i++) { + if (columnName.charAt(i) >= 'A' && columnName.charAt(i) <= 'Z') { + String upcase = "_" + (columnName.charAt(i) + "").toLowerCase(); + columnName.replace(i, i + 1, upcase); + } + } + return columnName.toString(); + } + + /** + * + */ + @Override + public String columnToProperty(String column) { + // 如果数据库字段为大写则使用这里的方法 + // StringBuffer property = new + // StringBuffer(tableNameToClassName(column.toLowerCase())); + + StringBuffer property = new StringBuffer(tableNameToClassName(column)); + String tempF = (property.charAt(0) + "").toLowerCase(); + property.replace(0, 1, tempF); + return property.toString(); + } + + @Override + public String classNameToTableName(String calssName) { + return propertyToColumn(calssName).substring(1, propertyToColumn(calssName).length()); + } + + /** + * + * 首字母改为大写 去除_ 下划线后一个字符变为大写字符 + */ + @Override + public String tableNameToClassName(String tableName) { + StringBuffer calssName = new StringBuffer(tableName); + String tempF = (calssName.charAt(0) + "").toUpperCase(); + calssName.replace(0, 1, tempF); + for (int i = 0; i < calssName.length(); i++) { + if (calssName.charAt(i) == '_' && i + 1 < tableName.length()) { + String upcase = (calssName.charAt(i + 1) + "").toUpperCase(); + calssName.replace(i, i + 2, upcase); + } + } + return calssName.toString(); + } + + /** + * 第一个字母大写 + */ + @Override + public String propertyToMethod(String property) { + StringBuffer method = new StringBuffer(property); + String tempF = (method.charAt(0) + "").toUpperCase(); + method.replace(0, 1, tempF); + return method.toString(); + } + + /** + * 第一个字母小写 + */ + @Override + public String classNameToVariableName(String className) { + StringBuffer variableName = new StringBuffer(className); + String tempF = (variableName.charAt(0) + "").toLowerCase(); + variableName.replace(0, 1, tempF); + return variableName.toString(); + } + + public static void main(String[] args) { + DefaultNameConvert convert = new DefaultNameConvert(); + System.out.println(convert.propertyToColumn("userName")); + + } +} diff --git a/src/main/java/com/matrix/codeGeneration/convert/DefaultTypeHandle.java b/src/main/java/com/matrix/codeGeneration/convert/DefaultTypeHandle.java new file mode 100644 index 0000000..808266c --- /dev/null +++ b/src/main/java/com/matrix/codeGeneration/convert/DefaultTypeHandle.java @@ -0,0 +1,91 @@ +package com.matrix.codeGeneration.convert; + +import java.util.HashMap; + +import com.matrix.codeGeneration.model.TypeHandle; +/** + * 默认的类型处理器 + * @author Matrix-J + * + */ +public class DefaultTypeHandle implements TypeHandle { + + + public static HashMap<String, HashMap<String, String>> TypeMapping; + + + static { + + TypeMapping = new HashMap<String, HashMap<String, String>>(); + + /** + * mysql映射设置 + */ + HashMap<String, String> mysqlMap = new HashMap<String, String>(); + mysqlMap.put("double", "Double"); + mysqlMap.put("int", "Integer"); + mysqlMap.put("bigint", "Long"); + mysqlMap.put("float", "Float"); + mysqlMap.put("varchar", "String"); + mysqlMap.put("tinyint", "Boolean"); + mysqlMap.put("datetime", "Date"); + mysqlMap.put("date", "Date"); + mysqlMap.put("text", "String"); + mysqlMap.put("char", "String"); + mysqlMap.put("enum", "String"); + mysqlMap.put("smallint", "Integer"); + mysqlMap.put("mediumtext", "String"); + mysqlMap.put("tinyint", "Integer"); + mysqlMap.put("tinyint", "Integer"); + mysqlMap.put("bit", "Integer"); + mysqlMap.put("real", "Double"); + mysqlMap.put("decimal", "BigDecimal"); + mysqlMap.put("numeric", "BigDecimal"); + mysqlMap.put("time", "Date"); + mysqlMap.put("year", "Date"); + mysqlMap.put("timestamp", "Date"); + mysqlMap.put("tinyblob", "byte[]"); + mysqlMap.put("blob", "byte[]"); + mysqlMap.put("mediumblob", "byte[]"); + mysqlMap.put("longblob", "byte[]"); + mysqlMap.put("longtext", "String"); + mysqlMap.put("tinytext", "String"); + mysqlMap.put("mediumtext", "String"); + mysqlMap.put("set", "String"); + mysqlMap.put("binary", "byte[]"); + mysqlMap.put("varbinary", "byte[]"); + mysqlMap.put("point", "String"); + mysqlMap.put("linestring", "String"); + mysqlMap.put("polygon", "String"); + mysqlMap.put("geometry", "String"); + mysqlMap.put("multipoint", "String"); + mysqlMap.put("multilinestring", "String"); + mysqlMap.put("multipolygon", "String"); + mysqlMap.put("geometrycollection", "String"); + TypeMapping.put("mysql", mysqlMap); + + + + /**============================================================================================================================================ + * oracleMap映射设置 + * =========================================================================================================================================== + */ + HashMap<String, String> oracleMap = new HashMap<String, String>(); + oracleMap.put("CHAR", "String"); + oracleMap.put("VARCHAR2", "String"); + oracleMap.put("LONG", "String"); + oracleMap.put("NUMBER", "BigDecimal"); + oracleMap.put("VARCHAR", "String"); + oracleMap.put("DATE", "Date"); + oracleMap.put("TIMESTAMP", "Date"); + TypeMapping.put("oracle", oracleMap); + + + + + } + + + + +} diff --git a/src/main/java/com/matrix/codeGeneration/convert/NameConvert.java b/src/main/java/com/matrix/codeGeneration/convert/NameConvert.java new file mode 100644 index 0000000..00a3bc0 --- /dev/null +++ b/src/main/java/com/matrix/codeGeneration/convert/NameConvert.java @@ -0,0 +1,57 @@ +package com.matrix.codeGeneration.convert; +/** + * 名称转换接口 + * @author Matrix-J + * + */ +public interface NameConvert { + /** + * 属性转数据库字段格式转换接口 + * + * @param property + * @return + */ + public String propertyToColumn(String property); + + /** + * 数据库字段转属性格式转换接口 + * + * @param column + * @return + */ + public String columnToProperty(String column); + + + /** + * 表名类名转换接口 + * + * @param column + * @return + */ + public String tableNameToClassName(String tableName); + + + /** + * 类名表名转换接口 + * + * @param column + * @return + */ + public String classNameToTableName(String calssName); + /** + * 属性名称转方法名称 + * @param property + * @return + */ + public String propertyToMethod(String property); + + /** + * 类名转类名的变量名 + * @param property + * @return + */ + public String classNameToVariableName(String className); + + + +} diff --git a/src/main/java/com/matrix/codeGeneration/core/Generator.java b/src/main/java/com/matrix/codeGeneration/core/Generator.java new file mode 100644 index 0000000..1a6a5ab --- /dev/null +++ b/src/main/java/com/matrix/codeGeneration/core/Generator.java @@ -0,0 +1,105 @@ +package com.matrix.codeGeneration.core; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +import com.matrix.codeGeneration.model.CodeFile; +import com.matrix.codeGeneration.model.CodeModel; +import com.matrix.codeGeneration.model.OutDataSource; + +import freemarker.template.Template; + +/** + * @author 姜友瑶 + * @e-mail:<935090232@qq.com> + * @date 2015-10-23 + * @description 代码生成器 + */ +public class Generator { + + public static void buildCodeFiles(OutDataSource outDataSource) { + // 构建模型文件 + outDataSource.convertToTableModel(); + // 根据模型生成代码模型文件 + List<CodeFile> codeFileModel = generatorFile(outDataSource); + // 根据模型文件生成实体文件 + createCodeFile(codeFileModel, outDataSource); + } + + /** + * 创建要生成的所有文件的模型 + * + * @param configuration + * @return + */ + private static List<CodeFile> generatorFile(OutDataSource outDataSource) { + List<CodeFile> codeFiles = new ArrayList<CodeFile>(); + Set<String> modelSet = outDataSource.getCodeModels().keySet(); + // 由模型来生成对应的codeFile,因为模型最知道自己需要的数据是什么,codeFile不关心数据 + for (String modelName : modelSet) { + CodeModel codeModel = outDataSource.getCodeModels().get(modelName); + List<CodeFile> thisModelFiles = codeModel.buildCodeFile(outDataSource); + codeFiles.addAll(thisModelFiles); + } + return codeFiles; + } + + /** + * 创建 + * + * @param configuration + * @param dbModel + * @return + */ + private static void createCodeFile(List<CodeFile> codeFiles, OutDataSource coutDataSource) { + try { + freemarker.template.Configuration cfg = new freemarker.template.Configuration(); + cfg.setLocale(Locale.SIMPLIFIED_CHINESE); + cfg.setDefaultEncoding("utf-8"); + cfg.setEncoding(Locale.SIMPLIFIED_CHINESE, "utf-8"); + cfg.setEncoding(Locale.SIMPLIFIED_CHINESE, "utf-8"); + for (CodeFile codeFile : codeFiles) { + Map<String, Object> root = new HashMap<String, Object>(); + // 设置文件需要的数据 + root.putAll(codeFile.getData()); + // 生成代码文件 + System.out.println("生成" + codeFile.getFileName() + "文件..."); + cfg.setDirectoryForTemplateLoading(new File(coutDataSource.getUserTempLataHome())); + // 获取模板(template) + Template template = cfg.getTemplate(codeFile.getTemplateName(), "utf-8"); + // 把文件写入磁盘 + String filePath = coutDataSource.getTargetPath() + codeFile.getSavePath(); + File file = new File(filePath); + if (file.getParentFile().exists() && file.exists()) { + File javaBean = new File(filePath + codeFile.getFileName()); + javaBean.createNewFile(); + BufferedWriter bf = new BufferedWriter(new FileWriter(javaBean)); + template.process(root, bf); + bf.flush(); + bf.close(); + } else { + if (file.mkdirs()) { + File javaBean = new File(filePath + codeFile.getFileName()); + javaBean.createNewFile(); + BufferedWriter bf = new BufferedWriter(new FileWriter(javaBean)); + template.process(root, bf); + bf.flush(); + bf.close(); + } else { + System.out.println("创建文件失败" + filePath); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + +} \ No newline at end of file diff --git a/src/main/java/com/matrix/codeGeneration/core/MainClass.java b/src/main/java/com/matrix/codeGeneration/core/MainClass.java new file mode 100644 index 0000000..f92d930 --- /dev/null +++ b/src/main/java/com/matrix/codeGeneration/core/MainClass.java @@ -0,0 +1,26 @@ +package com.matrix.codeGeneration.core; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import com.matrix.codeGeneration.model.OutDataSource; + +/** + * @author 姜友瑶 + * @e-mail:<935090232@qq.com> + * @date 2015-10-23 + * @description 代码生成器 + */ +public class MainClass { + + public static void main(String[] args) { + + ApplicationContext context = new ClassPathXmlApplicationContext("config/code-generation.xml"); + // 根据需要注入自己的数据源 + OutDataSource outDataSource = (OutDataSource) context.getBean("outDataSource"); + // 生成代码文件 + Generator.buildCodeFiles(outDataSource); + + } + +} \ No newline at end of file diff --git a/src/main/java/com/matrix/codeGeneration/ext/AhcsModels.java b/src/main/java/com/matrix/codeGeneration/ext/AhcsModels.java new file mode 100644 index 0000000..4855efd --- /dev/null +++ b/src/main/java/com/matrix/codeGeneration/ext/AhcsModels.java @@ -0,0 +1,276 @@ +package com.matrix.codeGeneration.ext; + +import java.io.File; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.poi.ss.usermodel.DataFormatter; + +import com.matrix.codeGeneration.model.CodeFile; +import com.matrix.codeGeneration.model.CodeModel; +import com.matrix.codeGeneration.model.CommonData; +import com.matrix.codeGeneration.model.Constant; +import com.matrix.codeGeneration.model.OutDataSource; +import com.matrix.codeGeneration.model.TableClassModel; +import com.matrix.codeGeneration.plugin.DateUtils; + +/** + * 平安意健险代码文件模型 + */ +public class AhcsModels implements CodeModel { + + /** + * 模型名称用来标识这个模型 + */ + String modelName=""; + + /** + * 包名 + */ + private String packageName=""; + + /** + * 名称后缀 + */ + private String suffixName=""; + + /** + * 名称前缀 + */ + private String prefixName=""; + + /** + * 文件扩展名称 + */ + private String fileExtName=""; + + /** + * 模板名称 + */ + private String templateName=""; + + /** + * 导入类列表 + */ + private Map<String, String> importList = new HashMap<>(); + + /** + * 类的变量名称 + */ + private String classVariableName=""; + + + + @Override + public List<CodeFile> buildCodeFile(OutDataSource dataSource) { + List<CodeFile> codeFileList = new ArrayList<>(); + for (TableClassModel tableClassModel : dataSource.getTableClassModels()) { + Map<String, Object> fileData = new HashMap<>(); + System.out.println(tableClassModel.getClassName()); + System.out.println(this.modelName); + System.out.println("--------------"); + + if (Constant.JAVA_BEAN.equals(this.modelName)) { + + this.getImportList().put("Extend", "com.zkingsoft.anotations.Extend"); + + } else if (Constant.MYBATIS_DAO.equals(this.modelName)) { + this.setImportList(new HashMap<String, String>()); + this.getImportList().put("bean", + getModelQualifiedClassName(Constant.JAVA_BEAN, tableClassModel, dataSource)); + + this.getImportList().put("List", "java.util.List"); + this.getImportList().put("Param", "org.apache.ibatis.annotations.Param"); + this.getImportList().put("PaginationVO", "com.zkingsoft.pojo.PaginationVO"); + this.getImportList().put("Map", "java.util.Map"); + + } else if (Constant.MYBATIS_DAO_IMPL.equals(this.modelName)) { + + } else if (Constant.SERVICE.equals(this.modelName)) { + + this.setImportList(new HashMap<String, String>()); + this.getImportList().put("bean", + getModelQualifiedClassName(Constant.JAVA_BEAN, tableClassModel, dataSource)); + this.getImportList().put("List", "java.util.List"); + this.getImportList().put("BaseServices", "com.zkingsoft.constraint.BaseServices"); + this.getImportList().put("PaginationVO", "com.zkingsoft.pojo.PaginationVO"); + + } else if (Constant.SERVICE_IMPL.equals(this.modelName)) { + this.setImportList(new HashMap<String, String>()); + this.getImportList().put("bean", + getModelQualifiedClassName(Constant.JAVA_BEAN, tableClassModel, dataSource)); + + this.getImportList().put("services", + getModelQualifiedClassName(Constant.SERVICE, tableClassModel, dataSource)); + this.getImportList().put("dao", + getModelQualifiedClassName(Constant.MYBATIS_DAO, tableClassModel, dataSource)); + this.getImportList().put("springframework.Service", "org.springframework.stereotype.Service"); + this.getImportList().put("Autowired", "org.springframework.beans.factory.annotation.Autowired"); + this.getImportList().put("List", "java.util.List"); + this.getImportList().put("Map", "java.util.Map"); + + } else if (Constant.ACTION.equals(this.modelName)) { + + this.getImportList().put("Controller", "org.springframework.stereotype.Controller"); + this.getImportList().put("Resource", "javax.annotation.Resource"); + this.getImportList().put("AjaxResult", "com.zkingsoft.pojo.AjaxResult"); + this.getImportList().put("PaginationVO", "com.zkingsoft.pojo.PaginationVO"); + this.getImportList().put("WebUtil", "com.zkingsoft.util.WebUtil"); + this.getImportList().put("SaveRequestToken", "com.zkingsoft.anotations.SaveRequestToken"); + this.getImportList().put("RemoveRequestToken", "com.zkingsoft.anotations.RemoveRequestToken"); + this.getImportList().put("BaseController", "com.zkingsoft.constraint.BaseController"); + this.getImportList().put("RequestMapping", "org.springframework.web.bind.annotation.RequestMapping"); + this.getImportList().put("ResponseBody", "org.springframework.web.bind.annotation.ResponseBody"); + } + fileData.put("importList", this.getImportList()); + CodeFile codeFile = new CodeFile(); + // 计算文件的名称 + codeFile.setFileName(getFileName(tableClassModel, this)); + codeFile.setSavePath(File.separator + getPackageName().replace(".", File.separator) + File.separator); + fileData.put("codeModel", this); + fileData.put("dataSource", dataSource); + fileData.put("tableClassModel", tableClassModel); + fileData.put("commonData", new CommonData()); + fileData.put("time", DateUtils.dateFormatStr(new Date(), "yyyy-MM-dd HH:mm")); + + fileData.put("ClassName", getModelClassName(this.getModelName(), tableClassModel, dataSource)); + codeFile.setData(fileData); + codeFile.setTemplateName(this.templateName); + codeFileList.add(codeFile); + } + return codeFileList; + + } + + /** + * 计算文件名称 + * + * @param tableClassModel + * @return + */ + public String getFileName(TableClassModel tableClassModel, AhcsModels ahcsModels) { + StringBuffer name = new StringBuffer(); + String prefix = ahcsModels.getPrefixName(); + String suffix = ahcsModels.getSuffixName(); + String extensionName = ahcsModels.getFileExtName(); + if (prefix != null) { + name.append(prefix); + } + name.append(tableClassModel.getClassName()); + if (suffix != null) { + name.append(suffix); + } + name.append(extensionName); + return name.toString(); + } + + /** + * 获取一个模型的变量名 + * + * @param modelName + * @param dataSource + * @return + */ + public String getModelVariablesName(String modelName, TableClassModel tableClassModel, OutDataSource dataSource) { + return dataSource.getNameConvert() + .classNameToTableName(getModelClassName(modelName, tableClassModel, dataSource)); + } + + /** + * 获取一个模型的全类名 + * + * @param modelName + * @param dataSource + * @return + */ + public String getModelQualifiedClassName(String modelName, TableClassModel tableClassModel, + OutDataSource dataSource) { + AhcsModels ahcsMOdels = ((AhcsModels) dataSource.getCodeModels().get(modelName)); + String className = ahcsMOdels.getPackageName() + "." + ahcsMOdels.getPrefixName() + + tableClassModel.getClassName() + ahcsMOdels.getSuffixName(); + return className; + } + + /** + * 获取一个模型的类名 + * + * @param modelName + * @param dataSource + * @return + */ + public String getModelClassName(String modelName, TableClassModel tableClassModel, OutDataSource dataSource) { + AhcsModels ahcsMOdels = ((AhcsModels) dataSource.getCodeModels().get(modelName)); + String className = ahcsMOdels.getPrefixName() + tableClassModel.getClassName() + ahcsMOdels.getSuffixName(); + return className; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getPackageName() { + return packageName; + } + + public void setPackageName(String packageName) { + this.packageName = packageName; + } + + public String getSuffixName() { + return suffixName; + } + + public void setSuffixName(String suffixName) { + this.suffixName = suffixName; + } + + public String getPrefixName() { + return prefixName; + } + + public void setPrefixName(String prefixName) { + this.prefixName = prefixName; + } + + public String getFileExtName() { + return fileExtName; + } + + public void setFileExtName(String fileExtName) { + this.fileExtName = fileExtName; + } + + public String getTemplateName() { + return templateName; + } + + public void setTemplateName(String templateName) { + this.templateName = templateName; + } + + public Map<String, String> getImportList() { + return importList; + } + + public void setImportList(Map<String, String> importList) { + this.importList = importList; + } + + public String getClassVariableName() { + return classVariableName; + } + + public void setClassVariableName(String classVariableName) { + this.classVariableName = classVariableName; + } + + + +} diff --git a/src/main/java/com/matrix/codeGeneration/ext/ExcelDataSource.java b/src/main/java/com/matrix/codeGeneration/ext/ExcelDataSource.java new file mode 100644 index 0000000..136a47b --- /dev/null +++ b/src/main/java/com/matrix/codeGeneration/ext/ExcelDataSource.java @@ -0,0 +1,207 @@ +package com.matrix.codeGeneration.ext; + +import com.matrix.codeGeneration.convert.DefaultTypeHandle; +import com.matrix.codeGeneration.model.OutDataSource; +import com.matrix.codeGeneration.model.PropertyColumn; +import com.matrix.codeGeneration.model.TableClassModel; +import com.matrix.codeGeneration.plugin.ExcelImport; +import org.apache.commons.lang.StringUtils; + +import java.io.File; +import java.io.IOException; +import java.util.*; + +/** + * excel数据源 + * + * @author jiangyouyao + * + */ +public class ExcelDataSource extends OutDataSource { + // excel文件地址 + private String sourcePath; + private String author; + + private String dbType; + + public ExcelDataSource() { + } + + @Override + public List<TableClassModel> convertToTableModel() { + + Map<String, List<List<Object>>> analysisExcel = new HashMap<>(); + // 源文件路径 + File sourceDir = new File(sourcePath); + if (!sourceDir.isDirectory()) { + new Exception("目标目录不存在"); + } + File[] files = sourceDir.listFiles(); + if (files != null) { + for (File file : files) { + if (file.canRead()) {// 是否为一个可读文件 + String fileName = file.getName(); + // 检查扩展名称 + String extension = fileName.lastIndexOf(".") == -1 ? "" + : fileName.substring(fileName.lastIndexOf(".") + 1); + if (extension.equals("xls") || extension.equals("xlsx")) { + System.out.println(fileName); + // 读取excel文件的内容 + try { + analysisExcel.putAll(ExcelImport.read2007ExcelAllShell(file, null, 6)); + } catch (IOException e) { + e.printStackTrace(); + } + } + } else { + new RuntimeException(file.getName() + "文件不可读"); + } + } + } + List<TableClassModel> models = analysisExcel(analysisExcel); + this.setTableClassModels(models); + return this.getTableClassModels(); + } + + /** + * 解析excel文件中数据表信息 + * + * @param analysisExcel + * @return + */ + private List<TableClassModel> analysisExcel(Map<String, List<List<Object>>> analysisExcel) { + List<TableClassModel> models = new ArrayList<>(); + Set<String> keys = analysisExcel.keySet(); + // 除了第一行,其他每一行代表一个字段,一个key是一个表 + for (String tableName : keys) { + TableClassModel model = new TableClassModel(); + List<List<Object>> data = analysisExcel.get(tableName); + // 设置数据表基本信息 + // 构建表名 + + int nameIndex = tableName.indexOf("("); + model.setTableMemo(tableName.substring(nameIndex+1, tableName.length()-1)); + model.setTableName(tableName.substring(0, nameIndex)); + // 设置类名和变量名称 + model.setClassName(getNameConvert().tableNameToClassName(model.getTableName())); + model.setClassVariableName(getNameConvert().classNameToVariableName(model.getClassName())); + + // 该表需要展示到页面的字段个数 + int showCount=0; + // 遍历设置字段信息 + for (int i = 1; i < data.size(); i++) { + List<Object> row = data.get(i); + PropertyColumn p = new PropertyColumn(); + // 列名 + String columnName = (String) row.get(0); + p.setColumn(columnName); + // 属性名称 + p.setProperty(getNameConvert().columnToProperty(columnName)); + + // 字段类型、长度 + String type = (String) row.get(2); + p.setFullJdbcType(type); + + // jdbc类型设置 + int index = type.indexOf("(") > 0 ? type.indexOf("(") : type.length(); + + p.setJdbcType(type.substring(0, index).trim().replaceAll("2", "")); + System.out.println("jdbctype=" + p.getJdbcType()); + // 基本类型 + p.setClassType(DefaultTypeHandle.TypeMapping.get(dbType).get(p.getJdbcType())); + + String isAllowNull = (String) row.get(3); + + if (isAllowNull != null && isAllowNull.equals("N")) { + isAllowNull = " NOT NULL "; + } else { + isAllowNull = ""; + } + + p.setIsAllowNull(isAllowNull); + + // 备注中 [表示界面显示字段] [表示必填字段*] + String memo = (String) row.get(1); + int begin = memo.indexOf("["); + int end = memo.indexOf("]"); + + if (begin > -1 && end - begin > 1) { + showCount++; + // 显示到页面上的字段 + String subString1 = memo.substring(begin, end); + boolean isNecessary = subString1.indexOf("*") > 0; + if (isNecessary) { + p.setShowName(memo.substring(begin + 1, end - 1)); + } else { + p.setShowName(memo.substring(begin + 1, end)); + } + p.setIsNecessary(isNecessary); + p.setIsVisible(true); + // 截取[符号前面的字段作为数据库的备注 + p.setMemo(memo.substring(0, begin)); + } else { + p.setIsNecessary(false); + p.setIsVisible(false); + p.setMemo(memo); + } + // get,set方法名称 + p.setMethodName(getNameConvert().propertyToMethod(p.getProperty())); + + // 设置主键 + if (p.getMemo() != null && p.getMemo().equals("主键")) { + p.setIsPrimaryKey(true); + model.setPrimaryKey(p); + } else { + p.setIsPrimaryKey(false); + } + + // 索引 + String indexName = (String) row.get(5); + if(null == indexName || "".equals(indexName)){ + indexName = null; + } + p.setIndexName(indexName); + + // 设置jsp编辑页面字段长度限制 + String columnLengthStr = row.get(6) == null ? null : (String) row.get(6); + if (columnLengthStr!=null && columnLengthStr.trim().length()>0) { + // 从excel中读取的数字默认是double类型的,所以做如下处理去掉小数点 + Double columnLength = Double.parseDouble(columnLengthStr); + p.setColumnLength(columnLength.intValue()+""); + } + + model.getMapping().add(p); + } + // 需要加上该表有多少个显示到list列表的字段个数 + model.setShowCount(showCount); + models.add(model); + } + System.out.println(analysisExcel); + return models; + } + + public String getSourcePath() { + return sourcePath; + } + + public void setDbType(String dbType) { + this.dbType = dbType; + } + + public void setSourcePath(String sourcePath) { + this.sourcePath = sourcePath; + } + + public void setAuthor(String author) { + this.author = author; + } + + public String getAuthor() { + return author; + } + + public String getDbType() { + return dbType; + } + +} diff --git a/src/main/java/com/matrix/codeGeneration/ext/Matrix4Models.java b/src/main/java/com/matrix/codeGeneration/ext/Matrix4Models.java new file mode 100644 index 0000000..b23f98f --- /dev/null +++ b/src/main/java/com/matrix/codeGeneration/ext/Matrix4Models.java @@ -0,0 +1,318 @@ +package com.matrix.codeGeneration.ext; + +import java.io.File; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.springframework.beans.BeanUtils; + +import com.matrix.codeGeneration.model.CodeFile; +import com.matrix.codeGeneration.model.CodeModel; +import com.matrix.codeGeneration.model.CommonData; +import com.matrix.codeGeneration.model.Constant; +import com.matrix.codeGeneration.model.OutDataSource; +import com.matrix.codeGeneration.model.TableClassModel; +import com.matrix.codeGeneration.plugin.DateUtils; + +/** + * matrix4代码文件模型 + */ +public class Matrix4Models implements CodeModel { + + /** + * 模型名称用来标识这个模型 + */ + String modelName=""; + + /** + * 包名 + */ + private String packageName=""; + + /** + * 名称后缀 + */ + private String suffixName=""; + + /** + * 名称前缀 + */ + private String prefixName=""; + + /** + * 文件扩展名称 + */ + private String fileExtName=""; + + /** + * 模板名称 + */ + private String templateName=""; + + /** + * 导入类列表 + */ + private Map<String, String> importList = new HashMap<>(); + + /** + * 类的变量名称 + */ + private String classVariableName=""; + + + + @Override + public List<CodeFile> buildCodeFile(OutDataSource dataSource) { + List<CodeFile> codeFileList = new ArrayList<>(); + for (TableClassModel tableClassModel : dataSource.getTableClassModels()) { + Map<String, Object> fileData = new HashMap<>(); + tableClassModel.setBeanClassName(getModelClassName(Constant.JAVA_BEAN,tableClassModel,dataSource)); + tableClassModel.setFullClassName(getModelClassName(modelName,tableClassModel,dataSource)); + tableClassModel.setQualifiedClassName(getModelQualifiedClassName(modelName,tableClassModel,dataSource)); + System.out.println(tableClassModel.getClassName()); + System.out.println(this.modelName); + System.out.println("--------------"); + + if (Constant.JAVA_BEAN.equals(this.modelName)) { + + this.getImportList().put("Extend", "com.matrix.core.anotations.Extend"); + this.getImportList().put("EntityDTO", "com.matrix.core.pojo.EntityDTO"); + this.getImportList().put("EntityDTOExt", "com.matrix.core.publicBean.EntityDTOExt"); + + } else if (Constant.MYBATIS_DAO.equals(this.modelName)) { + this.setImportList(new HashMap<String, String>()); + this.getImportList().put("bean", + getModelQualifiedClassName(Constant.JAVA_BEAN, tableClassModel, dataSource)); + + this.getImportList().put("List", "java.util.List"); + this.getImportList().put("Param", "org.apache.ibatis.annotations.Param"); + this.getImportList().put("PaginationVO", "com.matrix.core.pojo.PaginationVO"); + this.getImportList().put("Map", "java.util.Map"); + + } else if (Constant.MYBATIS_DAO_IMPL.equals(this.modelName)) { + + } else if (Constant.SERVICE.equals(this.modelName)) { + + this.setImportList(new HashMap<String, String>()); + this.getImportList().put("bean", + getModelQualifiedClassName(Constant.JAVA_BEAN, tableClassModel, dataSource)); + this.getImportList().put("List", "java.util.List"); + this.getImportList().put("BaseServices", "com.matrix.core.web.BaseServices"); + this.getImportList().put("PaginationVO", "com.matrix.core.pojo.PaginationVO"); + + } else if (Constant.SERVICE_IMPL.equals(this.modelName)) { + this.setImportList(new HashMap<String, String>()); + this.getImportList().put("bean", + getModelQualifiedClassName(Constant.JAVA_BEAN, tableClassModel, dataSource)); + + this.getImportList().put("services", + getModelQualifiedClassName(Constant.SERVICE, tableClassModel, dataSource)); + this.getImportList().put("dao", + getModelQualifiedClassName(Constant.MYBATIS_DAO, tableClassModel, dataSource)); + this.getImportList().put("springframework.Service", "org.springframework.stereotype.Service"); + this.getImportList().put("Autowired", "org.springframework.beans.factory.annotation.Autowired"); + this.getImportList().put("List", "java.util.List"); + this.getImportList().put("Map", "java.util.Map"); + this.getImportList().put("MatrixConstance", "com.matrix.core.constance.MatrixConstance"); + this.getImportList().put("WebUtil", "com.matrix.core.tools.WebUtil"); + this.getImportList().put("GlobleException", "com.matrix.core.exception.GlobleException"); + this.getImportList().put("ModelUtils", "com.matrix.core.tools.ModelUtils"); + this.getImportList().put("SystemErrorCode", "com.matrix.core.constance.SystemErrorCode"); + this.getImportList().put("UUIDUtil", "com.matrix.core.tools.UUIDUtil"); + this.getImportList().put("PaginationVO", "com.matrix.core.pojo.PaginationVO"); + this.getImportList().put("SysUsers", "com.xincheng.common.bean.SysUsers"); + + + fileData.put("daoClassName", getModelClassName(Constant.MYBATIS_DAO, tableClassModel, dataSource)); + fileData.put("daoVariableName", getModelVariablesName(Constant.MYBATIS_DAO, tableClassModel, dataSource)); + fileData.put("serviceInterface", getModelClassName(Constant.SERVICE, tableClassModel, dataSource)); + + + } else if (Constant.ACTION.equals(this.modelName)) { + this.getImportList().put("bean", + getModelQualifiedClassName(Constant.JAVA_BEAN, tableClassModel, dataSource)); + //this.getImportList().put("services", + // getModelQualifiedClassName(Constant.SERVICE, tableClassModel, dataSource)); + this.getImportList().put("Controller", "org.springframework.stereotype.Controller"); + this.getImportList().put("Autowired", "org.springframework.beans.factory.annotation.Autowired"); + this.getImportList().put("AjaxResult", "com.matrix.core.pojo.AjaxResult"); + this.getImportList().put("GlobleException", "com.matrix.core.exception.GlobleException"); + this.getImportList().put("PaginationVO", "com.matrix.core.pojo.PaginationVO"); + this.getImportList().put("WebUtil", "com.matrix.core.tools.WebUtil"); + this.getImportList().put("SaveRequestToken", "com.matrix.core.anotations.SaveRequestToken"); + this.getImportList().put("RemoveRequestToken", "com.matrix.core.anotations.RemoveRequestToken"); + this.getImportList().put("BaseController", "com.matrix.core.web.BaseAction"); + this.getImportList().put("RequestMapping", "org.springframework.web.bind.annotation.RequestMapping"); + this.getImportList().put("ResponseBody", "org.springframework.web.bind.annotation.ResponseBody"); + this.getImportList().put("AppConstance", "static com.xincheng.common.constance.AppConstance.*"); + this.getImportList().put("SystemMessageCode", "com.matrix.core.constance.SystemMessageCode"); + this.getImportList().put("SystemErrorCode", "com.matrix.core.constance.SystemErrorCode"); + this.getImportList().put("Map", "java.util.Map"); + this.getImportList().put("RedisUserLoginUtils", "com.matrix.core.redis.RedisUserLoginUtils"); + this.getImportList().put("SysUsers", "com.xincheng.commonApi.bean.SysUsers"); + } + fileData.put("importList", this.getImportList()); + CodeFile codeFile = new CodeFile(); + // 计算文件的名称 + codeFile.setFileName(getFileName(tableClassModel, this)); + codeFile.setSavePath(File.separator + getPackageName().replace(".", File.separator) + File.separator); + fileData.put("codeModel", this); + fileData.put("beanQualifiedClassName", getModelQualifiedClassName(Constant.JAVA_BEAN, tableClassModel, dataSource)); + fileData.put("dataSource", dataSource); + TableClassModel thisTableClassModel= new TableClassModel(); + BeanUtils.copyProperties(tableClassModel, thisTableClassModel); + fileData.put("tableClassModel", thisTableClassModel); + fileData.put("commonData", new CommonData()); + fileData.put("time", DateUtils.dateFormatStr(new Date(), "yyyy-MM-dd HH:mm")); + fileData.put("ClassName", getModelClassName(this.getModelName(), tableClassModel, dataSource)); + codeFile.setData(fileData); + codeFile.setTemplateName(this.templateName); + codeFileList.add(codeFile); + } + return codeFileList; + + } + + /** + * 计算文件名称 + * + * @param tableClassModel + * @return + */ + public String getFileName(TableClassModel tableClassModel, Matrix4Models ahcsModels) { + StringBuffer name = new StringBuffer(); + String prefix = ahcsModels.getPrefixName(); + String suffix = ahcsModels.getSuffixName(); + + + String extensionName = ahcsModels.getFileExtName(); + if (prefix != null) { + name.append(prefix); + } + // 这里判断如果是html 则应该将文件名首字母小写 + if(".html".equals(extensionName)) { + String className = tableClassModel.getClassName(); + String initial = className.substring(0, 1).toLowerCase(); + name.append(initial+className.substring(1)); + }else { + name.append(tableClassModel.getClassName()); + } + if (suffix != null) { + name.append(suffix); + } + name.append(extensionName); + return name.toString(); + } + + /** + * 获取一个模型的变量名 + * + * @param modelName + * @param dataSource + * @return + */ + public String getModelVariablesName(String modelName, TableClassModel tableClassModel, OutDataSource dataSource) { + return dataSource.getNameConvert() + .classNameToVariableName(getModelClassName(modelName, tableClassModel, dataSource)); + } + + /** + * 获取一个模型的全类名 + * + * @param modelName + * @param dataSource + * @return + */ + public String getModelQualifiedClassName(String modelName, TableClassModel tableClassModel, + OutDataSource dataSource) { + Matrix4Models ahcsMOdels = ((Matrix4Models) dataSource.getCodeModels().get(modelName)); + String className = ahcsMOdels.getPackageName() + "." + ahcsMOdels.getPrefixName() + + tableClassModel.getClassName() + ahcsMOdels.getSuffixName(); + return className; + } + + /** + * 获取一个模型的类名 + * + * @param modelName + * @param dataSource + * @return + */ + public String getModelClassName(String modelName, TableClassModel tableClassModel, OutDataSource dataSource) { + Matrix4Models ahcsMOdels = ((Matrix4Models) dataSource.getCodeModels().get(modelName)); + String className = ahcsMOdels.getPrefixName() + tableClassModel.getClassName() + ahcsMOdels.getSuffixName(); + return className; + } + + + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getPackageName() { + return packageName; + } + + public void setPackageName(String packageName) { + this.packageName = packageName; + } + + public String getSuffixName() { + return suffixName; + } + + public void setSuffixName(String suffixName) { + this.suffixName = suffixName; + } + + public String getPrefixName() { + return prefixName; + } + + public void setPrefixName(String prefixName) { + this.prefixName = prefixName; + } + + public String getFileExtName() { + return fileExtName; + } + + public void setFileExtName(String fileExtName) { + this.fileExtName = fileExtName; + } + + public String getTemplateName() { + return templateName; + } + + public void setTemplateName(String templateName) { + this.templateName = templateName; + } + + public Map<String, String> getImportList() { + return importList; + } + + public void setImportList(Map<String, String> importList) { + this.importList = importList; + } + + public String getClassVariableName() { + return classVariableName; + } + + public void setClassVariableName(String classVariableName) { + this.classVariableName = classVariableName; + } + + + +} diff --git a/src/main/java/com/matrix/codeGeneration/ext/OracleStyleNameConvert.java b/src/main/java/com/matrix/codeGeneration/ext/OracleStyleNameConvert.java new file mode 100644 index 0000000..3889eff --- /dev/null +++ b/src/main/java/com/matrix/codeGeneration/ext/OracleStyleNameConvert.java @@ -0,0 +1,86 @@ +package com.matrix.codeGeneration.ext; + +import com.matrix.codeGeneration.convert.NameConvert; + +/** + * oracle风格的名称实现的转换器 + * + * @author Administrator + * + */ +public class OracleStyleNameConvert implements NameConvert { + + @Override + public String propertyToColumn(String property) { + StringBuffer columnName = new StringBuffer(property); + for (int i = 0; i < columnName.length(); i++) { + if (columnName.charAt(i) >= 'A' && columnName.charAt(i) <= 'Z') { + String upcase = "_" + (columnName.charAt(i) + "").toLowerCase(); + columnName.replace(i, i + 1, upcase); + } + } + return columnName.toString(); + } + + /** + * + */ + @Override + public String columnToProperty(String column) { + // 如果数据库字段为大写则使用这里的方法 + StringBuffer property = new StringBuffer(tableNameToClassName(column.toLowerCase())); + String tempF = (property.charAt(0) + "").toLowerCase(); + property.replace(0, 1, tempF); + return property.toString(); + } + + @Override + public String classNameToTableName(String calssName) { + return propertyToColumn(calssName).substring(1, propertyToColumn(calssName).length()); + } + + /** + * + * 首字母改为大写 去除_ 下划线后一个字符变为大写字符 + */ + @Override + public String tableNameToClassName(String tableName) { + StringBuffer calssName = new StringBuffer(tableName.toLowerCase()); + String tempF = (calssName.charAt(0) + "").toUpperCase(); + calssName.replace(0, 1, tempF); + for (int i = 0; i < calssName.length(); i++) { + if (calssName.charAt(i) == '_' && i + 1 < tableName.length()) { + String upcase = (calssName.charAt(i + 1) + "").toUpperCase(); + calssName.replace(i, i + 2, upcase); + } + } + return calssName.toString(); + } + + /** + * 第一个字母大写 + */ + @Override + public String propertyToMethod(String property) { + StringBuffer method = new StringBuffer(property); + String tempF = (method.charAt(0) + "").toUpperCase(); + method.replace(0, 1, tempF); + return method.toString(); + } + + /** + * 第一个字母小写 + */ + @Override + public String classNameToVariableName(String className) { + StringBuffer variableName = new StringBuffer(className); + String tempF = (variableName.charAt(0) + "").toLowerCase(); + variableName.replace(0, 1, tempF); + return variableName.toString(); + } + + public static void main(String[] args) { + OracleStyleNameConvert convert = new OracleStyleNameConvert(); + System.out.println(convert.columnToProperty("user_id")); + } +} diff --git a/src/main/java/com/matrix/codeGeneration/model/Attribute.java b/src/main/java/com/matrix/codeGeneration/model/Attribute.java new file mode 100644 index 0000000..fa0d5c4 --- /dev/null +++ b/src/main/java/com/matrix/codeGeneration/model/Attribute.java @@ -0,0 +1,43 @@ +package com.matrix.codeGeneration.model; + +/** + * 类属性 + * + * @author Matrix-J + */ +public class Attribute { + + /** + * 注解 + */ + private String annotate; + + private String className; + + private String variableName; + + public String getAnnotate() { + return annotate; + } + + public void setAnnotate(String annotate) { + this.annotate = annotate; + } + + public String getClassName() { + return className; + } + + public void setClassName(String className) { + this.className = className; + } + + public String getVariableName() { + return variableName; + } + + public void setVariableName(String variableName) { + this.variableName = variableName; + } + +} diff --git a/src/main/java/com/matrix/codeGeneration/model/CodeFile.java b/src/main/java/com/matrix/codeGeneration/model/CodeFile.java new file mode 100644 index 0000000..013b1ed --- /dev/null +++ b/src/main/java/com/matrix/codeGeneration/model/CodeFile.java @@ -0,0 +1,65 @@ +package com.matrix.codeGeneration.model; + +import java.util.Map; + + +/**每一个codeFile 代表一个要生成的文件 + * + * @author jiangyouyao + * + */ +public class CodeFile { + + /** + * 模板文件名称 + */ + private String fileName; + /** + * 模板文件保存地址 + */ + private String savePath; + + /** + * 模型文件地址 + */ + private String templateName; + + + public String getTemplateName() { + return templateName; + } + + public void setTemplateName(String templateName) { + this.templateName = templateName; + } + + /** + * 模板文件需要的数据 + */ + private Map<String, Object> data; + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public String getSavePath() { + return savePath; + } + + public void setSavePath(String savePath) { + this.savePath = savePath; + } + + public Map<String, Object> getData() { + return data; + } + + public void setData(Map<String, Object> data) { + this.data = data; + } + +} diff --git a/src/main/java/com/matrix/codeGeneration/model/CodeModel.java b/src/main/java/com/matrix/codeGeneration/model/CodeModel.java new file mode 100644 index 0000000..89d052a --- /dev/null +++ b/src/main/java/com/matrix/codeGeneration/model/CodeModel.java @@ -0,0 +1,13 @@ +package com.matrix.codeGeneration.model; + +import java.util.List; + +/** + * 代码文件模型 + * + * @author Matrix-J + * + */ +public interface CodeModel { + public List<CodeFile> buildCodeFile(OutDataSource dataSource); + } diff --git a/src/main/java/com/matrix/codeGeneration/model/CommonData.java b/src/main/java/com/matrix/codeGeneration/model/CommonData.java new file mode 100644 index 0000000..d7b1ed1 --- /dev/null +++ b/src/main/java/com/matrix/codeGeneration/model/CommonData.java @@ -0,0 +1,19 @@ +package com.matrix.codeGeneration.model; + +import java.util.Date; + +import com.matrix.codeGeneration.plugin.DateUtils; + +public class CommonData { + @SuppressWarnings("unused") + private String now; + + public String getNow() { + return DateUtils.dateFormatStr(new Date(), "yyyy-MM-dd HH:mm"); + } + + public void setNow(String now) { + this.now = now; + } + +} diff --git a/src/main/java/com/matrix/codeGeneration/model/Constant.java b/src/main/java/com/matrix/codeGeneration/model/Constant.java new file mode 100644 index 0000000..142d40b --- /dev/null +++ b/src/main/java/com/matrix/codeGeneration/model/Constant.java @@ -0,0 +1,68 @@ +package com.matrix.codeGeneration.model; + +/** + * 文件类型 + * + * @author Matrix-J + * + */ +public class Constant { + + /** + * javabean类型模型 + */ + public static String MYSQL_SQL = "MYSQL_SQL"; + + + /** + * javabean类型模型 + */ + public static String JAVA_BEAN = "JAVA_BEAN"; + + /** + * mybatis dao模型文件 + */ + public static String MYBATIS_DAO_IMPL = "MYBATIS_DAO_IMPL"; + + /** + * mybatis dao模型文件 + */ + public static String MYBATIS_DAO = "MYBATIS_DAO"; + + /** + * SERVICE接口 模型文件 + */ + public static String SERVICE = "SERVICE"; + + /** + * SERVICE 实现类模型文件 + */ + public static String SERVICE_IMPL = "SERVICE_IMPL"; + + /** + * ACTION 类模型文件 + */ + public static String ACTION = "ACTION"; + + /** + * LIST VIEW 视图模型文件 + */ + public static String LIST = "LIST"; + /** + * FORM VIEW 视图模型文件 + */ + public static String FORM = "FORM"; + + /** + * MABATIS 的配置文件 + */ + public static String MABATIS_CONFIG = "MABATIS_CONFIG"; + /** + * MYSQL数据库类型 + */ + public static String DB_MYSQL = "DB_MYSQL"; + /** + * oracle数据库类型 + */ + public static String DB_ORACLE = "DB_ORACLE"; +} diff --git a/src/main/java/com/matrix/codeGeneration/model/ModelType.java b/src/main/java/com/matrix/codeGeneration/model/ModelType.java new file mode 100644 index 0000000..9f64e31 --- /dev/null +++ b/src/main/java/com/matrix/codeGeneration/model/ModelType.java @@ -0,0 +1,78 @@ +package com.matrix.codeGeneration.model; + +/** + * 文件类型 + * + * @author Matrix-J + * + */ +public enum ModelType { + /** + * javabean类型模型 + */ + JAVA_BEAN, + + /** + * mybatis dao模型文件 + */ + MYBATIS_DAO_IMPL, + + /** + * mybatis dao模型文件 + */ + MYBATIS_DAO, + + /** + * SERVICE接口 模型文件 + */ + SERVICE, + + /** + * SERVICE 实现类模型文件 + */ + SERVICE_IMPL, + + /** + * ACTION 类模型文件 + */ + ACTION, + + /** + * LIST VIEW 视图模型文件 + */ + LIST, + /** + * FORM VIEW 视图模型文件 + */ + FORM, + + /** + * MABATIS 的配置文件 + */ + MABATIS_CONFIG,; + + public static ModelType get(String source) { + + if (source.equals(JAVA_BEAN.toString())) { + return JAVA_BEAN; + } else if (source.equals(MYBATIS_DAO_IMPL.toString())) { + return MYBATIS_DAO_IMPL; + } else if (source.equals(MYBATIS_DAO.toString())) { + return MYBATIS_DAO; + } else if (source.equals(SERVICE.toString())) { + return SERVICE; + } else if (source.equals(SERVICE_IMPL.toString())) { + return SERVICE_IMPL; + } else if (source.equals(ACTION.toString())) { + return ACTION; + } else if (source.equals(LIST.toString())) { + return LIST; + }else if (source.equals(FORM.toString())) { + return FORM; + } else if (source.equals(MABATIS_CONFIG.toString())) { + return MABATIS_CONFIG; + } + return null; + } + +} diff --git a/src/main/java/com/matrix/codeGeneration/model/OutDataSource.java b/src/main/java/com/matrix/codeGeneration/model/OutDataSource.java new file mode 100644 index 0000000..2fb2668 --- /dev/null +++ b/src/main/java/com/matrix/codeGeneration/model/OutDataSource.java @@ -0,0 +1,89 @@ +package com.matrix.codeGeneration.model; + +import java.util.List; +import java.util.Map; + +import com.matrix.codeGeneration.convert.DefaultNameConvert; +import com.matrix.codeGeneration.convert.NameConvert; + +public abstract class OutDataSource { + + private String targetPath; + + private NameConvert nameConvert = new DefaultNameConvert(); + /** + * 根据客户的选择生成表与类的对应 + */ + private List<TableClassModel> tableClassModels; + + /** + * 根据客户的选择生成模型文件 + */ + private Map<String, CodeModel> codeModels; + + /** + * 是否要生成文件 的包名 + */ + private List<String> modelPackages; + + /** + * 用户模板根目录 + */ + private String userTempLataHome; + + public abstract List<TableClassModel> convertToTableModel(); + + public String getTargetPath() { + return targetPath; + } + + public void setTargetPath(String targetPath) { + this.targetPath = targetPath; + } + + public List<TableClassModel> getTableClassModels() { + return tableClassModels; + } + + public void setTableClassModels(List<TableClassModel> tableClassModels) { + this.tableClassModels = tableClassModels; + } + + public Map<String, CodeModel> getCodeModels() { + return codeModels; + } + + public void setCodeModels(Map<String, CodeModel> codeModels) { + this.codeModels = codeModels; + } + + public List<String> getModelPackages() { + return modelPackages; + } + + public void setModelPackages(List<String> modelPackages) { + this.modelPackages = modelPackages; + } + + public String getUserTempLataHome() { + return userTempLataHome; + } + + // 这里支持classpath + public void setUserTempLataHome(String userTempLataHome) { + String cuttentPath = ClassLoader.getSystemResource("").toString().substring(5); + cuttentPath = cuttentPath + userTempLataHome; + this.userTempLataHome = cuttentPath; + } + + public NameConvert getNameConvert() { + return nameConvert; + } + + public void setNameConvert(NameConvert nameConvert) { + this.nameConvert = nameConvert; + } + + + +} diff --git a/src/main/java/com/matrix/codeGeneration/model/PropertyColumn.java b/src/main/java/com/matrix/codeGeneration/model/PropertyColumn.java new file mode 100644 index 0000000..efe47eb --- /dev/null +++ b/src/main/java/com/matrix/codeGeneration/model/PropertyColumn.java @@ -0,0 +1,218 @@ +package com.matrix.codeGeneration.model; + +/** + * 属性名称和字段名称的对应bean + * + * @author Matrix-j + * + */ +public class PropertyColumn { + /** + * 属性名称 + */ + private String property; + /** + * 字段名称 + */ + private String column; + /** + * 类型名称 + */ + private String classType; + + /** + * JDBC名称 + */ + private String jdbcType; + + /** + * JDBC名称 加长度 + */ + private String fullJdbcType; + + + /** + * 是否为主键 + * + */ + private Boolean isPrimaryKey; + + /** + * 是否在界面显示 + * 在数据库用[显示字段]备注表示在界面显示 + */ + private Boolean isVisible; + + /** + * 是否必填 + * 在数据库用[显示字段*]备注表示必填项 + */ + private Boolean isNecessary; + + /** + * 是否可为空 + */ + private String isAllowNull; + /** + * 显示在界面的名称 + */ + private String showName; + + /** + * 是否为外键 + */ + private Boolean isForeignKey; + + /** + * 外键表名 + */ + private String foreignTableName; + + /** + * 备注 + */ + private String memo; + + /** + * 字段最大长度 + */ + private String columnLength; + + /** + * 方法名称 + */ + private String methodName; + + /** + * 索引名称 + */ + private String indexName; + + public String getMethodName() { + return methodName; + } + + public void setMethodName(String methodName) { + this.methodName = methodName; + } + + public String getMemo() { + return memo; + } + + public void setMemo(String memo) { + this.memo = memo; + } + + public String getForeignTableName() { + return foreignTableName; + } + + public void setForeignTableName(String foreignTableName) { + this.foreignTableName = foreignTableName; + } + + public String getProperty() { + return property; + } + + public void setProperty(String property) { + this.property = property; + } + + public String getColumn() { + return column; + } + + public void setColumn(String column) { + this.column = column; + } + + public String getClassType() { + return classType; + } + + public void setClassType(String classType) { + this.classType = classType; + } + + + public Boolean getIsVisible() { + return isVisible; + } + + public void setIsVisible(Boolean isVisible) { + this.isVisible = isVisible; + } + + public Boolean getIsNecessary() { + return isNecessary; + } + + public void setIsNecessary(Boolean isNecessary) { + this.isNecessary = isNecessary; + } + + public String getJdbcType() { + return jdbcType; + } + + public void setJdbcType(String jdbcType) { + this.jdbcType = jdbcType; + } + + public Boolean getIsPrimaryKey() { + return isPrimaryKey; + } + + public void setIsPrimaryKey(Boolean isPrimaryKey) { + this.isPrimaryKey = isPrimaryKey; + } + + public Boolean getIsForeignKey() { + return isForeignKey; + } + + public void setIsForeignKey(Boolean isForeignKey) { + this.isForeignKey = isForeignKey; + } + + public String getColumnLength() { + return columnLength; + } + + public void setColumnLength(String columnLength) { + this.columnLength = columnLength; + } + + public String getShowName() { + return showName; + } + + public void setShowName(String showName) { + this.showName = showName; + } + + public String getFullJdbcType() { + return fullJdbcType; + } + + public void setFullJdbcType(String fullJdbcType) { + this.fullJdbcType = fullJdbcType; + } + public String getIsAllowNull() { + return isAllowNull; + } + + public void setIsAllowNull(String isAllowNull) { + this.isAllowNull = isAllowNull; + } + + public String getIndexName() { + return indexName; + } + + public void setIndexName(String indexName) { + this.indexName = indexName; + } +} diff --git a/src/main/java/com/matrix/codeGeneration/model/TableClassModel.java b/src/main/java/com/matrix/codeGeneration/model/TableClassModel.java new file mode 100644 index 0000000..a197118 --- /dev/null +++ b/src/main/java/com/matrix/codeGeneration/model/TableClassModel.java @@ -0,0 +1,150 @@ +package com.matrix.codeGeneration.model; + +import java.util.ArrayList; +import java.util.List; + +/** + * 数据表和java的对应模型 + * + * @author Matrix-J + * + */ +public class TableClassModel { + + /** + * 类的中文名称 + */ + private String tableMemo; + + /** + * 类名 + */ + private String className; + + /** + * bean的名称 + */ + private String beanClassName; + + private String fullClassName; + + private String qualifiedClassName; + + /** + * 表名 + */ + private String tableName; + + /** + * 类的变量名称 + */ + private String classVariableName; + /** + * 主键 + */ + private PropertyColumn primaryKey; + + private List<PropertyColumn> mapping = new ArrayList<PropertyColumn>(); + + /** + * 展示到页面的字段个数 addByzhangheng + */ + private Integer showCount; + + public TableClassModel() { + } + + + public String getTableName() { + return tableName; + } + + public void setTableName(String tableName) { + this.tableName = tableName; + } + + public String getClassName() { + return className; + } + + public void setClassName(String className) { + this.className = className; + } + + public List<PropertyColumn> getMapping() { + return mapping; + } + + public void setMapping(List<PropertyColumn> mapping) { + this.mapping = mapping; + } + + public PropertyColumn getPrimaryKey() { + return primaryKey; + } + + public void setPrimaryKey(PropertyColumn primaryKey) { + this.primaryKey = primaryKey; + } + + + public String getClassVariableName() { + return classVariableName; + } + + public void setClassVariableName(String classVariableName) { + this.classVariableName = classVariableName; + } + + + + public String getTableMemo() { + return tableMemo; + } + + public void setTableMemo(String tableMemo) { + this.tableMemo = tableMemo; + } + + + public String getBeanClassName() { + return beanClassName; + } + + + public void setBeanClassName(String beanClassName) { + this.beanClassName = beanClassName; + } + + + public String getFullClassName() { + return fullClassName; + } + + + public void setFullClassName(String fullClassName) { + this.fullClassName = fullClassName; + } + + + public String getQualifiedClassName() { + return qualifiedClassName; + } + + + public void setQualifiedClassName(String qualifiedClassName) { + this.qualifiedClassName = qualifiedClassName; + } + + + public Integer getShowCount() { + return showCount; + } + + + public void setShowCount(Integer showCount) { + this.showCount = showCount; + } + + +} diff --git a/src/main/java/com/matrix/codeGeneration/model/TypeHandle.java b/src/main/java/com/matrix/codeGeneration/model/TypeHandle.java new file mode 100644 index 0000000..f62ec9c --- /dev/null +++ b/src/main/java/com/matrix/codeGeneration/model/TypeHandle.java @@ -0,0 +1,9 @@ +package com.matrix.codeGeneration.model; +/** + * 类型处理器 + * @author Matrix-j + * + */ +public interface TypeHandle { + +} diff --git a/src/main/java/com/matrix/codeGeneration/plugin/DateUtils.java b/src/main/java/com/matrix/codeGeneration/plugin/DateUtils.java new file mode 100644 index 0000000..8d45c05 --- /dev/null +++ b/src/main/java/com/matrix/codeGeneration/plugin/DateUtils.java @@ -0,0 +1,557 @@ +package com.matrix.codeGeneration.plugin; + +import java.sql.Timestamp; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +/** + * 日期格式化,转换工具类 + * + * @author 姜友瑶 + * @createTime 2014.08.30 + */ +public class DateUtils { + + + public static final String DATE_FORMAT_SS = "yyyy-MM-dd HH:mm:ss"; + + public static final String DATE_FORMAT_MONGO = "yyyy-MM-dd'T'HH:mm:ss.SSS"; + + public static final String DATE_FORMAT_STS = "yyyy-MM-dd'T'HH:mm:ss"; + + public static final String DATE_FORMAT_MM = "yyyy-MM-dd HH:mm"; + + public static final String DATE_FORMAT_HH = "yyyy-MM-dd HH"; + + public static final String DATE_FORMAT_DD = "yyyy-MM-dd"; + + public static final String DATE_FORMAT_SPLITE_DD = "yyyy.MM.dd"; + + public static final String DATE_FORMAT_NO_SPLITE_DD = "yyyyMMdd"; + + public static final String DATE_FORMAT_MM_NO_DD = "yyyyMM"; + + public static final String DATE_FORMAT_NO_SPLITE_MM = "yyyyMMddHHmm"; + + public static final String DATE_FORMAT_NO_SPLITE_MM_HH = "yyyyMMddHH"; + + public static final String YEAR = "yyyy"; + + public static final String DATE_FORMAT_MMDD = "M月d日"; + + public static final String DATE_FORMAT_WEEK = "星期"; + + public static final String DATE_TIME_MORNING = "早上"; + + public static final String DATE_TIME_AFTERNOON = "下午"; + + public static final String DATE_TIME_NIGHT = "晚上"; + + public static final String CENTRE_SCRIBING = "-"; + + protected static final String EMPTY = ""; + + protected static final String ZERO = "0"; + + protected static final String SPLITE_CHAR = ":"; + + protected static final String START_TIME = " 00:00:00";// 空格不能删除 + + protected static final String END_TIME = " 23:59:59";// 空格不能删除 + + protected static final int WEEK_DAYS = 7; + + public static String yyyy_MM_dd_HH_mm_ss = "yyyy-MM-dd HH:mm:ss"; + + protected static final String[] weeks = { "一", "二", "三", "四", "五", "六", "日" }; + + /** + * 返回年份 + * + * @param date + * 日期 + * @return 返回年份 + */ + public static int getYear(java.util.Date date) { + + try { + java.util.Calendar c = java.util.Calendar.getInstance(); + c.setTime(date); + return c.get(java.util.Calendar.YEAR); + } catch (Exception e) { + } + + return 0; + } + + /** + * 返回月份 + * + * @param date + * 日期 + * @return 返回月份 + */ + public static int getMonth(java.util.Date date) { + + try { + java.util.Calendar c = java.util.Calendar.getInstance(); + c.setTime(date); + return c.get(java.util.Calendar.MONTH) + 1; + } catch (Exception e) { + + } + return 0; + } + + /** + * 日期转字符串 + * + * @param date + * @param format + * @return + */ + public static String dateToString(Date date, String format) { + + if (date == null) { + return EMPTY; + } + DateFormat fmt = new SimpleDateFormat(format); + return fmt.format(date); + } + + /** + * 字符串转日期 + * + * @param dateStr + * @param format + * @return + */ + public static Date stringToDate(String dateStr, String format) { + + DateFormat fmt = new SimpleDateFormat(format); + try { + return fmt.parse(dateStr); + } catch (ParseException e) { + + } + return null; + } + + + /** + * 判断给定的日期是一周中的第几天,注意:按照中国的习惯,周日是第七天 + * + * @param date + * @return + */ + public static int dateToWeek(Date date) { + + if (date == null) { + return 0; + } + + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + if (cal.get(Calendar.DAY_OF_WEEK) == 1) { + return 7; + } else { + return cal.get(Calendar.DAY_OF_WEEK) - 1; + } + } + + public static String dateOfWeek(Date date) { + + return DATE_FORMAT_WEEK + weeks[dateToWeek(date) - 1]; + } + + /** + * 指定时间的下一天 + * + * @param date + * @return + */ + public static Date nextDate(Date date) { + + if (date == null) { + return date; + } + + Calendar cal = Calendar.getInstance(); + try { + cal.setTime(date); + cal.add(Calendar.DATE, 1); + return cal.getTime(); + } catch (Exception e) { + + } + + return null; + } + + /** + * 指定时间的前一天 + * + * @param date + * @return + */ + public static Date previousDate(Date date) { + + if (date == null) { + return date; + } + + Calendar cal = Calendar.getInstance(); + try { + cal.setTime(date); + cal.add(Calendar.DATE, -1); + return cal.getTime(); + } catch (Exception e) { + + } + + return null; + } + + /** + * 指定时间的下N天 + * + * @param date + * @return + */ + public static Date nextNDate(Date date, int nDay) { + + if (date == null) { + return date; + } + + Calendar cal = Calendar.getInstance(); + try { + cal.setTime(date); + cal.add(Calendar.DATE, nDay); + return cal.getTime(); + } catch (Exception e) { + + } + + return null; + } + + /** + * 指定时间的前N天 + * + * @param date + * @return + */ + public static Date previousNDate(Date date, int nDay) { + + if (date == null) { + return date; + } + + Calendar cal = Calendar.getInstance(); + try { + cal.setTime(date); + cal.add(Calendar.DATE, -nDay); + return cal.getTime(); + } catch (Exception e) { + + } + + return null; + } + + /** + * 获取一天的起始时间 + * + * @param date + * @return + */ + public static Date getStartDate(Date date) { + + if (date == null) { + return date; + } + + DateFormat fmt = new SimpleDateFormat(DATE_FORMAT_DD); + String dateStr = fmt.format(date); + dateStr = dateStr + START_TIME; + fmt = new SimpleDateFormat(DATE_FORMAT_SS); + try { + return fmt.parse(dateStr); + } catch (ParseException e) { + + } + + return date; + } + + /** + * 获取一天的结束时间 + * + * @param date + * @return + */ + public static Date getEndDate(Date date) { + + if (date == null) { + return date; + } + + DateFormat fmt = new SimpleDateFormat(DATE_FORMAT_DD); + String dateStr = fmt.format(date); + dateStr = dateStr + END_TIME; + fmt = new SimpleDateFormat(DATE_FORMAT_SS); + try { + return fmt.parse(dateStr); + } catch (ParseException e) { + + } + + return date; + } + + /** + * currentDat是否在referenceDate日期之前 + * + * @param referenceDate + * @param currentDat + * @return + */ + public static boolean isBeforeDate(Date referenceDate, Date currentDate) { + + if (currentDate == null) { + return false; + } + if (referenceDate == null) { + return true; + } + return currentDate.before(referenceDate); + } + + /** + * currentDat是否在referenceDate日期之后 + * + * @param referenceDate + * @param currentDat + * @return + */ + public static boolean isAffterDate(Date referenceDate, Date currentDate) { + + if (currentDate == null) { + return false; + } + if (referenceDate == null) { + return true; + } + return currentDate.after(referenceDate); + } + + /** + * 判断currentDate是否在startDate和endDate之间,不包括startDate和endDate + * + * @param startDate + * @param endDate + * @param currentDate + * @return + */ + public static boolean isDuringDate(Date startDate, Date endDate, Date currentDate) { + + if (currentDate == null) { + return false; + } + + if (isAffterDate(startDate, currentDate) && isBeforeDate(endDate, currentDate)) { + return true; + } + return false; + } + + + + /** + * 获取startDate到endDate之间的星期day(中文星期)不包括startDate和endDate + * + * @param startDate + * @param endDate + * @param day + * @return + */ + public static List<Date> findDayDuringDate(Date startDate, Date endDate, int day) { + + List<Date> listDate = new ArrayList<Date>(); + int startDay = dateToWeek(startDate); + + Date date = null; + if (startDay == day) { + date = nextNDate(startDate, WEEK_DAYS); + } else { + date = nextNDate(startDate, day - startDay); + } + while (isDuringDate(startDate, endDate, date)) { + listDate.add(date); + date = nextNDate(date, WEEK_DAYS); + } + + return listDate; + } + + + + /** + * date转换成Timestamp + * + * @param date + * @param format + * @return + */ + public static Timestamp dateToTimestamp(Date date, String format) { + + if (date == null) { + return null; + } + + format = DATE_FORMAT_SS; + + DateFormat fmt = new SimpleDateFormat(format); + + return Timestamp.valueOf(fmt.format(date)); + } + + /** + * 获取早中晚 + * + * @param time + * @return + */ + public static String getDateTime(int time) { + + // 早上 + if (time == 1) { + return DateUtils.DATE_TIME_MORNING; + } + // 下午 + else if (time == 2) { + return DateUtils.DATE_TIME_AFTERNOON; + } + // 晚上 + else if (time == 3) { + return DateUtils.DATE_TIME_NIGHT; + } + return null; + } + + /** + * 获取早中晚的开始时间 + * + * @param date + * @param time + * @return + */ + public static Date getMeetTimeStart(String date, int time) { + + // 早上 + if (time == 1) { + return DateUtils.stringToDate(date + " 06:00", DateUtils.DATE_FORMAT_MM); + } + // 下午 + else if (time == 2) { + return DateUtils.stringToDate(date + " 13:00", DateUtils.DATE_FORMAT_MM); + } + // 晚上 + else if (time == 3) { + return DateUtils.stringToDate(date + " 19:00", DateUtils.DATE_FORMAT_MM); + } + return null; + } + + /** + * 获取早中晚的结束时间 + * + * @param date + * @param time + * @return + */ + + public static Date getMeetTimeEnd(String date, int time) { + // 早上 + if (time == 1) { + return DateUtils.stringToDate(date + " 13:00", DateUtils.DATE_FORMAT_MM); + } + // 下午 + else if (time == 2) { + return DateUtils.stringToDate(date + " 19:00", DateUtils.DATE_FORMAT_MM); + } + // 晚上 + else if (time == 3) { + return DateUtils.stringToDate(date + " 23:00", DateUtils.DATE_FORMAT_MM); + } + return null; + } + + /** + * 得到几天前的时间 + * + * @param d + * @param day + * @return + */ + public static Timestamp getDateBefore(Date d, int day) { + Calendar now = Calendar.getInstance(); + now.setTime(d); + now.set(Calendar.DATE, now.get(Calendar.DATE) - day); + return new Timestamp(now.getTime().getTime()); + } + + /** + * 得到几天后的时间 + * + * @param d + * @param day + * @return + */ + public static Timestamp getDateAfter(Date d, int day) { + Calendar now = Calendar.getInstance(); + now.setTime(d); + now.set(Calendar.DATE, now.get(Calendar.DATE) + day); + return new Timestamp(now.getTime().getTime()); + } + + /** + * 将日期类型格式化成字符串 + * + * @param date + * @return 格式化后日期字符串 + * @throws ParseException + */ + public static String dateFormatStr(Date date, String dateStyle) { + String dateStr = null; + if (date != null) { + SimpleDateFormat sdf = new SimpleDateFormat(dateStyle); + dateStr = sdf.format(date); + } + return dateStr; + } + + /** + * 获取时间戳 + * + * @return + */ + public static String getTimeMark() { + Calendar c = Calendar.getInstance(); + int year = c.get(Calendar.YEAR); + int mouth = c.get(Calendar.MONTH); + int day = c.get(Calendar.DAY_OF_MONTH); + int hour = c.get(Calendar.HOUR_OF_DAY); + int minute = c.get(Calendar.MINUTE); + int second = c.get(Calendar.SECOND); + int haomiao = c.get(Calendar.MILLISECOND); + return "" + year + mouth + day + hour + minute + second + haomiao; + } + +} diff --git a/src/main/java/com/matrix/codeGeneration/plugin/ExcelImport.java b/src/main/java/com/matrix/codeGeneration/plugin/ExcelImport.java new file mode 100644 index 0000000..c94d153 --- /dev/null +++ b/src/main/java/com/matrix/codeGeneration/plugin/ExcelImport.java @@ -0,0 +1,326 @@ +package com.matrix.codeGeneration.plugin; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFDateUtil; +import org.apache.poi.hssf.usermodel.HSSFRow; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.xssf.usermodel.XSSFCell; +import org.apache.poi.xssf.usermodel.XSSFRow; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + +/** + * excel导入(根据需求调用03/07版本方法导入) + * + * @ClassName: ExcelImport + * @Description: TODO + * @author 肖崇高 xiaochonggao@zkingsoft.com + * @date 2016年8月2日 上午10:39:04 + * + */ +public class ExcelImport { + /** + * 对外提供读取excel 的方法 + */ + public static List<List<Object>> readExcel(File file, String fileName, Integer rowNum, Integer cellNum) + throws IOException { + String extension = fileName.lastIndexOf(".") == -1 ? "" : fileName.substring(fileName.lastIndexOf(".") + 1); + if ("xls".equals(extension)) { + return read2003Excel(file, rowNum, cellNum); + } else if ("xlsx".equals(extension)) { + return read2007Excel(file, rowNum, cellNum); + } else { + throw new IOException("不支持的文件类型"); + } + } + + /** + * + * @Title: read2003Excel @Description: TODO @param @param file + * 待读取的文件 @param @param rowNum 行数 @param @param cellNum + * 列数 @param @return @param @throws IOException 设定文件 @return + * List<List<Object>> 返回类型 Object:单元格对象 List<Object>:行对象 + * List<List<Object>>:整个excel对象 @throws + */ + private static List<List<Object>> read2003Excel(File file, Integer rowNum, Integer cellNum) throws IOException { + List<List<Object>> list = new LinkedList<List<Object>>(); + HSSFWorkbook hwb = new HSSFWorkbook(new FileInputStream(file)); + HSSFSheet sheet = hwb.getSheetAt(0); + Object value = null; + HSSFRow row = null; + HSSFCell cell = null; + Integer rowsNum = 0;// 读取的行数 + Integer cellsNum = 0;// 读取的列数 + if (rowNum != null) { + rowsNum = rowNum; + } else { + rowsNum = sheet.getPhysicalNumberOfRows(); + } + for (int i = sheet.getFirstRowNum(); i <= rowsNum; i++) { + row = sheet.getRow(i); + if (row == null) { + continue; + } + if (row.getFirstCellNum() < 0) { + continue; + } + List<Object> linked = new LinkedList<Object>(); + if (cellNum != null) { + cellsNum = cellNum; + } else { + cellsNum = (int) row.getLastCellNum(); + } + for (int j = 0; j <= cellsNum; j++) {// row.getFirstCellNum() + cell = row.getCell(j); + if (cell == null) { + value = null; + } else { + DecimalFormat df = new DecimalFormat("0");// 格式化 number + // String + // 字符 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 格式化日期字符串 + DecimalFormat nf = new DecimalFormat("0.00");// 格式化数字 + switch (cell.getCellType()) { + case XSSFCell.CELL_TYPE_STRING: + value = cell.getStringCellValue(); + break; + case XSSFCell.CELL_TYPE_NUMERIC: + if ("@".equals(cell.getCellStyle().getDataFormatString())) { + value = df.format(cell.getNumericCellValue()); + } else if ("General".equals(cell.getCellStyle().getDataFormatString())) { + value = nf.format(cell.getNumericCellValue()); + } else { + value = sdf.format(HSSFDateUtil.getJavaDate(cell.getNumericCellValue())); + } + break; + case XSSFCell.CELL_TYPE_BOOLEAN: + value = cell.getBooleanCellValue(); + break; + case XSSFCell.CELL_TYPE_BLANK: + value = ""; + break; + default: + value = cell.toString(); + } + } + linked.add(value); + } + list.add(linked); + } + return list; + } + + /** + * + * @Title: read2007Excel @Description: TODO @param @param file + * 待读取的文件 @param @param rowNum 行数 @param @param cellNum + * 列数 @param @return @param @throws IOException 设定文件 @return + * List<List<Object>> 返回类型 Object:单元格对象 List<Object>:行对象 + * List<List<Object>>:整个excel对象 @throws + */ + private static List<List<Object>> read2007Excel(File file, Integer rowNum, Integer cellNum) throws IOException { + List<List<Object>> list = new LinkedList<List<Object>>(); + // 构造 XSSFWorkbook 对象,strPath 传入文件路径 + XSSFWorkbook xwb = new XSSFWorkbook(new FileInputStream(file)); + // 读取第一章表格内容 + XSSFSheet sheet = xwb.getSheetAt(0); + Object value = null; + XSSFRow row = null; + XSSFCell cell = null; + Integer rowsNum = 0;// 读取的行数 + Integer cellsNum = 0;// 读取的列数 + if (rowNum != null) { + rowsNum = rowNum; + } else { + rowsNum = sheet.getPhysicalNumberOfRows(); + } + for (int i = sheet.getFirstRowNum(); i <= rowsNum; i++) { + row = sheet.getRow(i); + if (row == null) { + continue; + } + if (row.getFirstCellNum() < 0) { + continue; + } + if (cellNum != null) { + cellsNum = cellNum; + } else { + cellsNum = (int) row.getLastCellNum(); + } + List<Object> linked = new LinkedList<Object>(); + for (int j = 0; j <= cellsNum; j++) { + cell = row.getCell(j); + if (cell == null) { + value = null; + } else { + DecimalFormat df = new DecimalFormat("0");// 格式化 number + // String + // 字符 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 格式化日期字符串 + DecimalFormat nf = new DecimalFormat("0.00");// 格式化数字 + switch (cell.getCellType()) { + case XSSFCell.CELL_TYPE_STRING: + value = cell.getStringCellValue(); + break; + case XSSFCell.CELL_TYPE_NUMERIC: + if ("@".equals(cell.getCellStyle().getDataFormatString())) { + value = df.format(cell.getNumericCellValue()); + } else if ("General".equals(cell.getCellStyle().getDataFormatString())) { + value = nf.format(cell.getNumericCellValue()); + } else { + value = sdf.format(HSSFDateUtil.getJavaDate(cell.getNumericCellValue())); + } + break; + case XSSFCell.CELL_TYPE_BOOLEAN: + value = cell.getBooleanCellValue(); + break; + case XSSFCell.CELL_TYPE_BLANK: + value = ""; + break; + default: + value = cell.toString(); + } + } + linked.add(value); + } + list.add(linked); + } + return list; + } + + /** + * + * @Title: getCellValue @Description: TODO 获取某个单元格数据 @param @param + * cell @param @return @param @throws Exception 设定文件 @return Object + * 返回类型 @throws + */ + public static Object getCellValue(HSSFCell cell) throws Exception { + Object value = null; + if (cell != null) { + DecimalFormat df = new DecimalFormat("0");// 格式化 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 格式化日期字符串 + DecimalFormat nf = new DecimalFormat("0.00");// 格式化数字 + switch (cell.getCellType()) { + case XSSFCell.CELL_TYPE_STRING: + value = cell.getStringCellValue(); + break; + case XSSFCell.CELL_TYPE_NUMERIC: + if ("@".equals(cell.getCellStyle().getDataFormatString())) { + value = df.format(cell.getNumericCellValue()); + } else if ("General".equals(cell.getCellStyle().getDataFormatString())) { + value = nf.format(cell.getNumericCellValue()); + } else { + value = sdf.format(HSSFDateUtil.getJavaDate(cell.getNumericCellValue())); + } + break; + case XSSFCell.CELL_TYPE_BOOLEAN: + value = cell.getBooleanCellValue(); + break; + case XSSFCell.CELL_TYPE_BLANK: + value = ""; + break; + default: + value = cell.toString(); + } + } + return value; + } + + /** + * + * @Title: read2007Excel @Description: TODO @param @param file + * 待读取的文件 @param @param rowNum 行数 @param @param cellNum + * 列数 @param @return @param @throws IOException 设定文件 @return + * List<List<Object>> 返回类型 Object:单元格对象 List<Object>:行对象 + * List<List<Object>>:整个excel对象 @throws + */ + public static Map<String, List<List<Object>>> read2007ExcelAllShell(File file, Integer rowNum, Integer cellNum) + throws IOException { + + Map<String, List<List<Object>>> resultSheet = new HashMap<String, List<List<Object>>>(); + + // 构造 XSSFWorkbook 对象,strPath 传入文件路径 + XSSFWorkbook xwb = new XSSFWorkbook(new FileInputStream(file)); + for (int i = 0; i < xwb.getNumberOfSheets(); i++) { + List<List<Object>> list = new LinkedList<List<Object>>(); + XSSFSheet sheet = xwb.getSheetAt(i); + String sheetName = sheet.getSheetName(); + System.out.println("读取第" + i + "章表格内容->" + sheetName);// + Object value = null; + XSSFRow row = null; + XSSFCell cell = null; + Integer rowsNum = 0;// 读取的行数 + Integer cellsNum = 0;// 读取的列数 + if (rowNum != null) { + rowsNum = rowNum; + } else { + rowsNum = sheet.getPhysicalNumberOfRows(); + } + for (int j = sheet.getFirstRowNum(); j <= rowsNum; j++) { + row = sheet.getRow(j); + if (row == null) { + continue; + } + if (row.getFirstCellNum() < 0) { + continue; + } + if (cellNum != null) { + cellsNum = cellNum; + } else { + cellsNum = (int) row.getLastCellNum(); + } + List<Object> linked = new LinkedList<Object>(); + for (int k = 0; k <= cellsNum; k++) { + cell = row.getCell(k); + if (cell == null) { + value = null; + } else { + DecimalFormat df = new DecimalFormat("0");// 格式化 number + // String + // 字符 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 格式化日期字符串 + DecimalFormat nf = new DecimalFormat("0.00");// 格式化数字 + switch (cell.getCellType()) { + case XSSFCell.CELL_TYPE_STRING: + value = cell.getStringCellValue(); + break; + case XSSFCell.CELL_TYPE_NUMERIC: + if ("@".equals(cell.getCellStyle().getDataFormatString())) { + value = df.format(cell.getNumericCellValue()); + } else if ("General".equals(cell.getCellStyle().getDataFormatString())) { + value = nf.format(cell.getNumericCellValue()); + } else { + value = sdf.format(HSSFDateUtil.getJavaDate(cell.getNumericCellValue())); + } + break; + case XSSFCell.CELL_TYPE_BOOLEAN: + value = cell.getBooleanCellValue(); + break; + case XSSFCell.CELL_TYPE_BLANK: + value = ""; + break; + default: + value = cell.toString(); + } + } + linked.add(value); + } + list.add(linked); + } + resultSheet.put(sheetName, list); + } + + return resultSheet; + } +} diff --git a/src/main/resources/config/code-generation.xml b/src/main/resources/config/code-generation.xml new file mode 100644 index 0000000..301657d --- /dev/null +++ b/src/main/resources/config/code-generation.xml @@ -0,0 +1,157 @@ +<?xml version="1.0" encoding="UTF-8"?> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd + http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd"> + + <!-- 根据需要调整注入的outDataSource --> + + <!-- EXCEL 构建代码 --> + <bean id="outDataSource" class="com.matrix.codeGeneration.ext.ExcelDataSource"> + <property name="author" value="yourName"></property> + <!-- excel所在目录 --> + <property name="sourcePath" value="E:\生成代码" /> + <!-- 数据库类型 --> + <property name="dbType" value="mysql" /> + <!-- 目标代码位置 --> + <property name="targetPath" value="E:\生成代码" /> + <!-- 模板文件位置 --> + <property name="userTempLataHome" value="template/excelTemplateForBoot" /> + <!-- <property name="userTempLataHome" value="template/excelTemplate" /> --> + <property name="nameConvert"> + <bean class="com.matrix.codeGeneration.ext.OracleStyleNameConvert"></bean> + </property> + <!-- 配置需要生成的文件 --> + <property name="codeModels"> + <map> + <entry key="JAVA_BEAN" value-ref="javaBean" /> + <entry key="MYSQL_SQL" value-ref="mysqlModel" /> + <entry key="MYBATIS_DAO" value-ref="mybatisDao" /> + <entry key="MYBATIS_DAO_IMPL" value-ref="mybatisDaoImpl" /> + <!-- <entry key="SERVICE" value-ref="service" /> --> + <!-- <entry key="SERVICE_IMPL" value-ref="serviceImpl" /> --> + <entry key="ACTION" value-ref="action" /> + <entry key="LIST" value-ref="list" /> + <entry key="FORM" value-ref="form" /> + </map> + </property> + </bean> + <!-- 生成文件模型相关配置 --> + <bean id="mysqlModel" class="com.matrix.codeGeneration.ext.Matrix4Models"> + <!-- javaBean类型 --> + <property name="modelName" value="MYSQL_SQL" /> + <!-- 包名 --> + <property name="packageName" value="sql" /> + <!-- 文件后缀名称 --> + <property name="fileExtName" value=".sql" /> + <!-- 对应的framwork模板文件名称 --> + <property name="templateName" value="sqlFile.ftl" /> + </bean> + <!-- 生成文件模型相关配置 --> + <bean id="javaBean" class="com.matrix.codeGeneration.ext.Matrix4Models"> + <!-- javaBean类型 --> + <property name="modelName" value="JAVA_BEAN" /> + <!-- 包名 --> + <property name="packageName" value="com.xincheng.biz2.bean" /> + <!-- 文件后缀名称 --> + <property name="fileExtName" value=".java" /> + <!-- 对应的framwork模板文件名称 --> + <property name="templateName" value="javaBean.ftl" /> + + </bean> + + <bean id="mybatisDao" class="com.matrix.codeGeneration.ext.Matrix4Models"> + <!-- dao接口类型 --> + <property name="modelName" value="MYBATIS_DAO" /> + <!-- 包名 --> + <property name="packageName" value="com.xincheng.biz2.dao" /> + <!-- 文件后缀名称 --> + <property name="fileExtName" value=".java" /> + <!-- 对应的framwork模板文件名称 --> + <property name="templateName" value="dao.ftl" /> + <!-- 类名称后缀 --> + <property name="suffixName" value="Dao" /> + </bean> + + <bean id="mybatisDaoImpl" class="com.matrix.codeGeneration.ext.Matrix4Models"> + <!-- dao接口类型 --> + <property name="modelName" value="MYBATIS_DAO_IMPL" /> + <!-- 包名 --> + <property name="packageName" value="com.xincheng.biz2.dao" /> + <!-- 文件后缀名称 --> + <property name="fileExtName" value=".xml" /> + <!-- 对应的framwork模板文件名称 --> + <property name="templateName" value="daoImpl.ftl" /> + <!-- 类名称后缀 --> + <property name="suffixName" value="Dao" /> + </bean> + + <bean id="service" class="com.matrix.codeGeneration.ext.Matrix4Models"> + <!-- dao接口类型 --> + <property name="modelName" value="SERVICE" /> + <!-- 包名 --> + <property name="packageName" value="com.xincheng.biz2.service" /> + <!-- 文件后缀名称 --> + <property name="fileExtName" value=".java" /> + <!-- 对应的framwork模板文件名称 --> + <property name="templateName" value="service.ftl" /> + <!-- 类名称后缀 --> + <property name="suffixName" value="Service" /> + </bean> + + <bean id="serviceImpl" class="com.matrix.codeGeneration.ext.Matrix4Models"> + <!-- dao接口类型 --> + <property name="modelName" value="SERVICE_IMPL" /> + <!-- 包名 --> + <property name="packageName" value="com.xincheng.biz2.service.impl" /> + <!-- 文件后缀名称 --> + <property name="fileExtName" value=".java" /> + <!-- 对应的framwork模板文件名称 --> + <property name="templateName" value="serviceImpl.ftl" /> + <!-- 类名称后缀 --> + <property name="suffixName" value="ServiceImpl" /> + </bean> + + <bean id="action" class="com.matrix.codeGeneration.ext.Matrix4Models"> + <!-- dao接口类型 --> + <property name="modelName" value="ACTION" /> + <!-- 包名 --> + <property name="packageName" value="com.xincheng.biz2.action" /> + <!-- 文件后缀名称 --> + <property name="fileExtName" value=".java" /> + <!-- 对应的framwork模板文件名称 --> + <property name="templateName" value="action.ftl" /> + <!-- 类名称后缀 --> + <property name="suffixName" value="Action" /> + + </bean> + <bean id="list" class="com.matrix.codeGeneration.ext.Matrix4Models"> + <!-- dao接口类型 --> + <property name="modelName" value="LIST" /> + <!-- 包名 --> + <property name="packageName" value="com.xincheng.biz2.html" /> + <!-- 文件后缀名称 --> + <property name="fileExtName" value=".html" /> + <!-- 对应的framwork模板文件名称 --> + <property name="templateName" value="list.ftl" /> + <!-- 类名称后缀 --> + <property name="suffixName" value="-list" /> + + </bean> + <bean id="form" class="com.matrix.codeGeneration.ext.Matrix4Models"> + <!-- dao接口类型 --> + <property name="modelName" value="FORM" /> + <!-- 包名 --> + <property name="packageName" value="com.xincheng.biz2.html" /> + <!-- 文件后缀名称 --> + <property name="fileExtName" value=".html" /> + <!-- 对应的framwork模板文件名称 --> + <property name="templateName" value="form.ftl" /> + <!-- 类名称后缀 --> + <property name="suffixName" value="-form" /> + + </bean> + +</beans> \ No newline at end of file diff --git a/src/main/resources/template/excelTempLateCopy/action.ftl b/src/main/resources/template/excelTempLateCopy/action.ftl new file mode 100644 index 0000000..bb5f979 --- /dev/null +++ b/src/main/resources/template/excelTempLateCopy/action.ftl @@ -0,0 +1,122 @@ +package ${codeModel.packageName}; + +<#list importList?keys as key> +import ${importList[key]}; +</#list> + +/** + * @description ${tableClassModel.tableMemo} + * @author ${dataSource.author} + * @date ${time} + */ +@Controller +@RequestMapping(value = "admin/${tableClassModel.classVariableName}") +public class ${ClassName} { + + @Autowired + private ${tableClassModel.className}Dao ${tableClassModel.classVariableName}Dao; + + //记录编辑前的值Before_Edit_Value + public static final String BEV="${tableClassModel.className}_BEV"; + + + /** + * 列表显示 + */ + @RequestMapping(value = "/showList") + public @ResponseBody AjaxResult showList(${tableClassModel.className} ${tableClassModel.classVariableName}, PaginationVO pageVo) { + if (pageVo == null) { + pageVo = new PaginationVO(); + } + List<${tableClassModel.className}> dataList = ${tableClassModel.classVariableName}Dao.selectInPage(${tableClassModel.classVariableName}, pageVo); + AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, dataList, + ${tableClassModel.classVariableName}Dao.selectTotalRecord(${tableClassModel.classVariableName})); + return result; + } + + /** + * 新增 + */ + @RemoveRequestToken + @RequestMapping(value = "/add${tableClassModel.className}") + public @ResponseBody AjaxResult add${tableClassModel.className}(${tableClassModel.className} ${tableClassModel.classVariableName}) { + SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); + ${tableClassModel.classVariableName}.set${tableClassModel.primaryKey.property?cap_first}(UUIDUtil.getRandomID()); + ${tableClassModel.classVariableName}.setCreateBy(user.getSuName()); + ${tableClassModel.classVariableName}.setUpdateBy(user.getSuName()); + int i=${tableClassModel.classVariableName}Dao.insert(${tableClassModel.classVariableName}); + if(i > 0){ + return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.ADD_SUCCES, "${tableClassModel.tableMemo}"); + }else { + throw new GlobleException(SystemErrorCode.DATA_ADD_FAIL); + } + } + + + + + + /** + * 修改 + */ + @RemoveRequestToken + @RequestMapping(value = "/modify${tableClassModel.className}") + public @ResponseBody AjaxResult modify${tableClassModel.className}(${tableClassModel.className} new${tableClassModel.className}) { + ${tableClassModel.className} old${tableClassModel.className} = WebUtil.getSessionAttribute(BEV); + int i = 0; + Map<String, Object> modifyMap = null; + try { + if (!ModelUtils.isModified(old${tableClassModel.className}, new${tableClassModel.className})) { + i = MatrixConstance.DML_SUCCESSS; + } + modifyMap = ModelUtils.comparePojo2Map(old${tableClassModel.className}, new${tableClassModel.className}); + } catch (Exception e) { + throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL, e, new${tableClassModel.className}); + } + if (modifyMap.size() > 0) { + modifyMap.put("${tableClassModel.primaryKey.property}", old${tableClassModel.className}.get${tableClassModel.primaryKey.property?cap_first}()); + ${tableClassModel.classVariableName}Dao.updateByMap(modifyMap); + } + i = MatrixConstance.DML_SUCCESSS; + WebUtil.removeSessionAttribute(BEV); + if (i > 0) { + return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.UPDATE_SUCCES, "${tableClassModel.tableMemo}"); + } else { + throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL); + } + } + + + + + /** + * 进入修改界面 + */ + @SaveRequestToken + @RequestMapping(value = "/editForm") + public String editForm(${tableClassModel.primaryKey.classType} id) { + ${tableClassModel.className} ${tableClassModel.classVariableName}; + if (id != null) { + ${tableClassModel.classVariableName} = ${tableClassModel.classVariableName}Dao.selectById(id); + WebUtil.getRequest().setAttribute("obj", ${tableClassModel.classVariableName}); + WebUtil.setSessionAttribute(BEV, ${tableClassModel.classVariableName}); + } + return "admin/${tableClassModel.className}-form"; + } + + + /** + * 删除 + */ + @RequestMapping(value = "/del") + public @ResponseBody AjaxResult del(String keys) { + List<String> ids = StringUtils.strToCollToString(keys, ","); + int i = ${tableClassModel.classVariableName}Dao.deleteByIds(ids); + if (i > 0) { + return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.DELETE_SUCCES, i); + } else { + throw new GlobleException(SystemErrorCode.DATA_DELETE_FAIL); + } + } + +} \ No newline at end of file diff --git a/src/main/resources/template/excelTempLateCopy/dao.ftl b/src/main/resources/template/excelTempLateCopy/dao.ftl new file mode 100644 index 0000000..43f2ef2 --- /dev/null +++ b/src/main/resources/template/excelTempLateCopy/dao.ftl @@ -0,0 +1,38 @@ +package ${codeModel.packageName}; + +<#list importList?keys as key> +import ${importList[key]}; +</#list> + +/** + * @description ${tableClassModel.tableMemo} + * @author ${dataSource.author} + * @date ${time} + */ +public interface ${ClassName}{ + + public int insert(@Param("item") ${tableClassModel.className} ${tableClassModel.classVariableName}); + + public int batchInsert(@Param("list") List<${tableClassModel.className}> ${tableClassModel.classVariableName}List); + + public int updateByMap(Map<String, Object> modifyMap); + + public int updateByModel(@Param("record")${tableClassModel.className} ${tableClassModel.classVariableName}); + + public int deleteByIds(@Param("list") List<${tableClassModel.primaryKey.classType}> list); + + public int deleteById(${tableClassModel.primaryKey.classType} ${tableClassModel.primaryKey.property}); + + public int deleteByModel(@Param("record") ${tableClassModel.className} ${tableClassModel.classVariableName}); + + public List<${tableClassModel.className}> selectInPage(@Param("record") ${tableClassModel.className} ${tableClassModel.classVariableName}, @Param("pageVo") PaginationVO pageVo); + + public List<${tableClassModel.className}> selectByModel(@Param("record") ${tableClassModel.className} ${tableClassModel.classVariableName}); + + public int selectTotalRecord(@Param("record") ${tableClassModel.className} ${tableClassModel.classVariableName}); + + public ${tableClassModel.className} selectById(${tableClassModel.primaryKey.classType} ${tableClassModel.primaryKey.property}); + + public ${tableClassModel.className} selectForUpdate(${tableClassModel.primaryKey.classType} ${tableClassModel.primaryKey.property}); + +} \ No newline at end of file diff --git a/src/main/resources/template/excelTempLateCopy/daoImpl.ftl b/src/main/resources/template/excelTempLateCopy/daoImpl.ftl new file mode 100644 index 0000000..2720efa --- /dev/null +++ b/src/main/resources/template/excelTempLateCopy/daoImpl.ftl @@ -0,0 +1,226 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" +"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> + +<mapper namespace="${tableClassModel.qualifiedClassName}"> + <!-- 定义${tableClassModel.className} 的复杂关联map --> + <resultMap type="${beanQualifiedClassName}" id="${tableClassModel.className}Map"> + <id property="${tableClassModel.primaryKey.property}" column="${tableClassModel.primaryKey.column}" /> + <result property="createBy" column="create_by" /> + <result property="createTime" column="create_time" /> + <result property="updateBy" column="update_by" /> + <result property="updateTime" column="update_time" /> + <#list tableClassModel.mapping as item> + <#if !item.isPrimaryKey> + <result property="${item.property}" column="${item.column}" /> + </#if> + </#list> + </resultMap> + + + <!-- 定义${tableClassModel.className} 的简单map ,本map不添加其他的关联属性 --> + <resultMap type="${beanQualifiedClassName}" id="${tableClassModel.className}SimpleMap"> + <id property="${tableClassModel.primaryKey.property}" column="${tableClassModel.primaryKey.column}" /> + <result property="createBy" column="create_by" /> + <result property="createTime" column="create_time" /> + <result property="updateBy" column="update_by" /> + <result property="updateTime" column="update_time" /> + <#list tableClassModel.mapping as item> + <#if !item.isPrimaryKey> + <result property="${item.property}" column="${item.column}" /> + </#if> + </#list> + </resultMap> + + <!-- 字段sql --> + <sql id="columns"> + create_by, + create_time, + update_by, + update_time, + <#list tableClassModel.mapping as item> + <#if item_has_next> + ${item.column}, + <#else> + ${item.column} + </#if> + </#list> + </sql> + + <!-- 属性sql --> + <sql id="propertys"> + ${'#'}{item.createBy}, + now(), + ${'#'}{item.updateBy}, + now(), + <#list tableClassModel.mapping as propertyitem> + <#if propertyitem_has_next> + ${'#'}{item.${propertyitem.property}}, + <#else> + ${'#'}{item.${propertyitem.property}} + </#if> + </#list> + </sql> + + <!-- where sql --> + <sql id="where_sql"> + + <if test="record!=null"> + <#list tableClassModel.mapping as item> + <if test="(record.${item.property}!=null and record.${item.property}!='') or (record.${item.property}!='' and record.${item.property}==0) "> + and ${item.column} = ${'#'}{record.${item.property}} + </if> + </#list> + </if> + + </sql> + + <!-- 插入方法 --> + <insert id="insert" parameterType="${beanQualifiedClassName}" + useGeneratedKeys="true" keyProperty="item.${tableClassModel.primaryKey.property}"> + INSERT INTO ${tableClassModel.tableName} ( + <include refid="columns"></include> + ) + VALUES ( + <include refid="propertys"></include> + ) + </insert> + + + + <!-- 批量插入 --> + <insert id="batchInsert" parameterType="java.util.List"> + INSERT INTO ${tableClassModel.tableName} ( + <include refid="columns"></include> + ) + VALUES + <foreach collection="list" item="item" index="index" separator=",">( + <include refid="propertys"></include> + )</foreach> + </insert> + + + + + + <!-- 根据Map更新 部分更新 --> + <update id="updateByMap" parameterType="java.util.HashMap" > + UPDATE ${tableClassModel.tableName} + <set> + <#list tableClassModel.mapping as item> + <#if !item.isPrimaryKey> + <if test="_parameter.containsKey('${item.property}')"> + ${item.column} = ${'#'}{${item.property}}, + </if> + </#if> + </#list> + </set> + WHERE ${tableClassModel.primaryKey.column}=${'#'}{${tableClassModel.primaryKey.property}} + </update> + + + <!-- 根据对象更新 部分更新 --> + <update id="updateByModel" parameterType="${tableClassModel.primaryKey.classType}"> + UPDATE ${tableClassModel.tableName} + <set> + <#list tableClassModel.mapping as item> + <#if !item.isPrimaryKey> + <#if item.classType = "String"> + <if test="record.${item.property} != null and record.${item.property} != '' "> + ${item.column} = ${'#'}{record.${item.property}}, + </if> + <#else> + <if test="record.${item.property} != null "> + ${item.column} = ${'#'}{record.${item.property}}, + </if> + </#if> + </#if> + </#list> + </set> + WHERE ${tableClassModel.primaryKey.column}=${'#'}{record.${tableClassModel.primaryKey.property}} + </update> + + <!-- 批量删除 --> + <delete id="deleteByIds" parameterType="java.util.List"> + delete from ${tableClassModel.tableName} where ${tableClassModel.primaryKey.column} in + <foreach collection="list" index="index" item="item" open="(" + separator="," close=")"> + ${'#'}{item} + </foreach> + </delete> + + <!-- 根据id删除--> + <delete id="deleteById" parameterType="${tableClassModel.primaryKey.classType}"> + DELETE FROM ${tableClassModel.tableName} + where ${tableClassModel.primaryKey.column}=${'#'}{${tableClassModel.primaryKey.property}} + </delete> + + <!-- 根据对象删除--> + <delete id="deleteByModel" parameterType="${beanQualifiedClassName}"> + DELETE FROM ${tableClassModel.tableName} + <where> + <include refid="where_sql" ></include> + </where> + </delete> + + + + <!-- 分页查询 --> + <select id="selectInPage" resultMap="${tableClassModel.className}Map"> + select + <include refid="columns" ></include> + from ${tableClassModel.tableName} + <where> + <include refid="where_sql"></include> + </where> + <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 --> + <if test="pageVo.sort !=null and pageVo.order !=null"> + order by + ${'$'}{pageVo.sort} ${'$'}{pageVo.order} + </if> + <if test="pageVo.offset >=0 and pageVo.limit >0"> + limit + ${'#'}{pageVo.offset},${'#'}{pageVo.limit} + </if> + </if> + </select> + + <!-- 查询总条数 --> + <select id="selectTotalRecord" parameterType="long" resultType="java.lang.Integer"> + select count(*) + from ${tableClassModel.tableName} + <where> + <include refid="where_sql"></include> + </where> + </select> + + <!-- 根据id查询--> + <select id="selectById" resultMap="${tableClassModel.className}Map"> + select + <include refid="columns" ></include> + from ${tableClassModel.tableName} + where ${tableClassModel.primaryKey.column}=${'#'}{${tableClassModel.primaryKey.property}} + </select> + + + <!-- 根据id 锁表查询--> + <select id="selectForUpdate" resultMap="${tableClassModel.className}Map"> + select + <include refid="columns" ></include> + from ${tableClassModel.tableName} + where ${tableClassModel.primaryKey.column}=${'#'}{${tableClassModel.primaryKey.column}} + for update + </select> + + + + <!-- 根据对象查询--> + <select id="selectByModel" resultMap="${tableClassModel.className}Map"> + select + <include refid="columns" ></include> + from ${tableClassModel.tableName} + <where> + <include refid="where_sql"></include> + </where> + </select> +</mapper> \ No newline at end of file diff --git a/src/main/resources/template/excelTempLateCopy/form.ftl b/src/main/resources/template/excelTempLateCopy/form.ftl new file mode 100644 index 0000000..6174abb --- /dev/null +++ b/src/main/resources/template/excelTempLateCopy/form.ftl @@ -0,0 +1,82 @@ +<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> +<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%> +<c:set var="path" value="${'$'}{pageContext.request.contextPath }" /> +<!DOCTYPE HTML> +<html> +<head> +<meta charset="utf-8"> +<META HTTP-EQUIV="Pragma" CONTENT="no-cache"> +<meta name="renderer" content="webkit|ie-comp|ie-stand"> +<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> +<meta name="viewport" + content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" /> +<meta http-equiv="Cache-Control" content="no-siteapp" /> +<!-- 本框架基本脚本和样式 --> +<script type="text/javascript" + src="${'$'}{path }/resource/js/plugin/jquery-2.1.4.min.js"></script> +<script type="text/javascript" + src="${'$'}{path }/resource/js/systools/MBase.js"></script> +</head> +<body> +<div class="ibox-content"> + <form class="form-horizontal" id="dataform" onsubmit="javascripr:return false;"> + <input type="hidden" name="tokenUrl" value="${'$'}{tokenUrl}"> + <input type="hidden" name="token" value="${'$'}{token}"> + <c:if test="${'$'}{obj ne null }"> + <input type="hidden" name="${tableClassModel.primaryKey.property}" value="${'$'}{obj.${tableClassModel.primaryKey.property} }"> + </c:if> + <#assign x = 1> + <#assign nodelSize = tableClassModel.mapping?size > + <#list tableClassModel.mapping as being> + <#if being.isVisible> + <#assign x = x + 1> + <#if x%2 = 0 || x = nodelSize> + <div class="form-group"> + </#if> + <label class="col-sm-2 control-label">${being.showName} + <#if being.isNecessary> + <span class="text-danger">*</span> + </#if> + </label> + <div class="col-sm-4"> + <input type="text" class="form-control" name="${being.property}" + <#if being.columnLength??> + maxLength="${being.columnLength}" dataType="s1-${being.columnLength}" + </#if> + <#if !being.isNecessary> + ignore="ignore" + </#if> + value="<c:out value="${'$'}{obj.${being.property} }"></c:out>" nullmsg="${being.showName}不能为空"> + </div> + <#if x%2 = 1 || x = nodelSize> + </div> + </#if> + </#if> + </#list> + <div class="form-group "> + <div class="col-sm-12 text-center"> + <a href="javascript:;" onclick="myForm.submit()" + class="btn btn-success radius"><i class="fa fa-check"></i> 保存</a> <a + class="btn btn-danger radius" href="javascript:;" onclick="MTools.closeForm()" ><i class="fa fa-close"></i> 关闭</a> + </div> + </div> + </form> + </div> +</body> +<script type="text/javascript" src="${'$'}{path }/resource/js/systools/MJsBase.js"></script> +<script type="text/javascript"> + MTools.autoFullSelect(); + $(".select2").select2(); + var invokeUrl="${'$'}{path}/do/admin/${tableClassModel.classVariableName}/add${tableClassModel.className}"; + <c:if test="${'$'}{obj ne null }"> + invokeUrl = "${'$'}{path}/do/admin/${tableClassModel.classVariableName}/modify${tableClassModel.className}"; + </c:if> + var myForm=MForm.initForm({ + invokeUrl:invokeUrl, + afterSubmit:function(){ + parent.myGrid.serchData(); + }, + }); +</script> +</body> +</html> \ No newline at end of file diff --git a/src/main/resources/template/excelTempLateCopy/javaBean.ftl b/src/main/resources/template/excelTempLateCopy/javaBean.ftl new file mode 100644 index 0000000..0da2f4b --- /dev/null +++ b/src/main/resources/template/excelTempLateCopy/javaBean.ftl @@ -0,0 +1,41 @@ +package ${codeModel.packageName}; + +<#list importList?keys as key> +import ${importList[key]}; +</#list> + +/** + * @description ${tableClassModel.tableMemo} + * @author ${dataSource.author} + * @date ${time} + */ +public class ${tableClassModel.className} extends EntityDTO{ + @Extend + private static final long serialVersionUID = 1L; + +<#list tableClassModel.mapping as being> + + <#if being.memo!=""> + /** + * ${being.memo} + */ + </#if> + private ${being.classType} ${being.property}; + +</#list> + +<#list tableClassModel.mapping as being> + + public ${being.classType} get${being.methodName}() { + return ${being.property}; + } + + public void set${being.methodName}(${being.classType} ${being.property}) { + this.${being.property}=${being.property}; + } + +</#list> + + + +} \ No newline at end of file diff --git a/src/main/resources/template/excelTempLateCopy/list.ftl b/src/main/resources/template/excelTempLateCopy/list.ftl new file mode 100644 index 0000000..b80d170 --- /dev/null +++ b/src/main/resources/template/excelTempLateCopy/list.ftl @@ -0,0 +1,132 @@ +<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> +<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%> +<%@ taglib uri="http://www.zkingsoft.com" prefix="matrix"%> +<c:set var="path" value="${'$'}{pageContext.request.contextPath }" /> +<!DOCTYPE HTML> +<html> +<head> +<meta charset="utf-8"> +<META HTTP-EQUIV="Pragma" CONTENT="no-cache"> +<meta name="renderer" content="webkit|ie-comp|ie-stand"> +<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> +<meta name="viewport" + content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" /> +<meta http-equiv="Cache-Control" content="no-siteapp" /> +<!-- 本框架基本脚本和样式 --> +<script type="text/javascript" + src="${'$'}{path }/resource/js/plugin/jquery-2.1.4.min.js"></script> +<script type="text/javascript" + src="${'$'}{path }/resource/js/systools/MBase.js"></script> +</head> +<body class="gray-bg"> +<div class="wrapper wrapper-content animated fadeInRight"> + <!-- 搜索框部分start --> + <matrix:btn value="${tableClassModel.className}:search"> +<div class="row" > + <div class="col-sm-12" > + <form class="form-inline" id="serchform"> + <div class="form-group mr-20"> + <input placeholder="请输入关键词" name="" type="text" class="form-control"> + </div> + <button onclick="myGrid.serchData()" type="button" + class="btn btn-info btn-sm"> + <i class="fa fa-search "></i> 搜索 + </button> + <button onclick="MForm.reset('#serchform');" type="button" class="btn btn-info btn-sm"> + <i class="fa fa-refresh "></i> 重置 + </button> + </form> + </div> + </div> + </matrix:btn> + <!-- 搜索框部分en --> + <div class="ibox-content radius-5 mt-5 mpanel"> + + <div class="row" > + <div class="col-sm-12" > + <div class="option-bar"> + <matrix:btn value="${tableClassModel.className}:dels"> + <button onclick="myGrid.delItems('${tableClassModel.primaryKey.property}')" type="button" + class="btn btn-danger btn-sm"> + <i class="fa fa-trash"></i>批量删除 + </button> + </matrix:btn> + <matrix:btn value="${tableClassModel.className}:add"> + <button onclick="openAdd()" type="button" + class="btn btn-success btn-sm"> + <i class="fa fa-plus"></i> 新增 + </button> + </matrix:btn> + </div> + <table id="mgrid"> + <thead> + <tr> + <th data-checkbox="true"></th> + <th data-formatter="MGrid.indexfn" data-align="center" data-width="30px" >序号</th> + <#list tableClassModel.mapping as being> + <#if being.isVisible> + <th data-field="${being.property}" >${being.showName}</th> + </#if> + </#list> + <th data-align="center" data-width="195px" data-field="${tableClassModel.primaryKey.property}" data-formatter="buidOperate">操作</th> + </tr> + </thead> + </table> + </div> +</div> +</div> +</div> +<script type="text/javascript" + src="${'$'}{path }/resource/js/systools/MJsBase.js"></script> + <script type="text/javascript"> + var myGrid; + $(function(){ + var delUrl=""; + <matrix:btn value="${tableClassModel.className}:del"> + delUrl="${'$'}{path}/do/admin/${tableClassModel.classVariableName}/del" ; + </matrix:btn> + myGrid=MGrid.initGrid({ + url:"${'$'}{path}/do/admin/${tableClassModel.classVariableName}/showList", + delUrl:delUrl, + }); + + }); + + function buidOperate(value, row, index){ + var html = []; + <matrix:btn value="${tableClassModel.className}:edit"> + html[0] = '<a onClick="openEdit(\''+value+'\')" title="编辑" class="fa fa-edit option"></a>' + </matrix:btn> + <matrix:btn value="${tableClassModel.className}:del"> + html[1] = '<a onClick="myGrid.delItem(\''+value+'\')" title="删除" class="fa fa-close option text-danger"></a>'; + </matrix:btn> + return html.join(""); + } + //打开添加界面 + <matrix:btn value="${tableClassModel.className}:add"> + function openAdd() { + layer.open({ + type : 2, + title : "添加${tableClassModel.tableMemo}", + area : [ MUI.SIZE_L, '400px' ], + maxmin : true, + content : [ '${'$'}{path}/do/admin/${tableClassModel.classVariableName}/editForm'] + }); + } + </matrix:btn> + + //打开编辑界面 + <matrix:btn value="${tableClassModel.className}:edit"> + function openEdit(id) { + layer.open({ + type : 2, + title : "编辑${tableClassModel.tableMemo}", + area : [ MUI.SIZE_L, '400px' ], + maxmin : true, + content : [ '${'$'}{path}/do/admin/${tableClassModel.classVariableName}/editForm?id=' + id] + }); + } + </matrix:btn> + </script> +</body> +</html> diff --git a/src/main/resources/template/excelTempLateCopy/mybatis-config.ftl b/src/main/resources/template/excelTempLateCopy/mybatis-config.ftl new file mode 100644 index 0000000..8851a3b --- /dev/null +++ b/src/main/resources/template/excelTempLateCopy/mybatis-config.ftl @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> + +<configuration> + <settings> + <setting name="cacheEnabled" value="false" /> + <setting name="lazyLoadingEnabled" value="false" /> + <setting name="multipleResultSetsEnabled" value="true" /> + <setting name="useColumnLabel" value="true" /> + <setting name="useGeneratedKeys" value="false" /> + <setting name="defaultExecutorType" value="SIMPLE" /> + <setting name="defaultStatementTimeout" value="25000" /> + </settings> + + + + + <typeAliases> + + <#list alias as item> + ${item} + </#list> + + </typeAliases> + + <mappers> + + <#list mappers as item> + ${item} + </#list> + + </mappers> +</configuration> \ No newline at end of file diff --git a/src/main/resources/template/excelTempLateCopy/sqlFile.ftl b/src/main/resources/template/excelTempLateCopy/sqlFile.ftl new file mode 100644 index 0000000..8054cf5 --- /dev/null +++ b/src/main/resources/template/excelTempLateCopy/sqlFile.ftl @@ -0,0 +1,29 @@ + +/** + * ${tableClassModel.tableMemo} + * @author ${dataSource.author} + * @date ${time} + */ + CREATE TABLE ${tableClassModel.tableName}( + create_by varchar(100) NOT NULL COMMENT '创建人', + create_time datetime NOT NULL COMMENT '创建时间', + update_by varchar(100) NOT NULL COMMENT '更新人', + update_time datetime NOT NULL COMMENT '更新时间', +<#list tableClassModel.mapping as being> + ${being.column} ${being.fullJdbcType} ${being.isAllowNull} COMMENT '${being.memo}', +</#list> +PRIMARY KEY(${tableClassModel.primaryKey.column}) +)ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='${tableClassModel.tableMemo}'; + +/** + * + *生成菜单的sql 默认在权限管理目录下 + */ +INSERT INTO `sys_function` +VALUES + ('开发者', now(), + '开发者', now(), + replace(uuid(), '-', ''), + '', 'admin/${tableClassModel.className}-list', '否', '2', + '05fb2915b39b4021a51d406473f0ee91', + '${tableClassModel.tableMemo}', '4', '${tableClassModel.className}', '123', '是', null); diff --git "a/src/main/resources/template/excelTempLateCopy/\346\225\260\346\215\256\345\255\227\345\205\270\350\241\250\050\346\250\241\346\235\277\051.xlsx" "b/src/main/resources/template/excelTempLateCopy/\346\225\260\346\215\256\345\255\227\345\205\270\350\241\250\050\346\250\241\346\235\277\051.xlsx" new file mode 100644 index 0000000..4f23622 --- /dev/null +++ "b/src/main/resources/template/excelTempLateCopy/\346\225\260\346\215\256\345\255\227\345\205\270\350\241\250\050\346\250\241\346\235\277\051.xlsx" Binary files differ diff --git a/src/main/resources/template/excelTemplate/action.ftl b/src/main/resources/template/excelTemplate/action.ftl new file mode 100644 index 0000000..0fd3b81 --- /dev/null +++ b/src/main/resources/template/excelTemplate/action.ftl @@ -0,0 +1,88 @@ +package ${codeModel.packageName}; + +<#list importList?keys as key> +import ${importList[key]}; +</#list> + +/** + * @description ${tableClassModel.tableMemo} + * @author ${dataSource.author} + * @date ${time} + */ +@Controller +@RequestMapping(value = "admin/${tableClassModel.classVariableName}") +public class ${ClassName} extends BaseAction{ + + @Autowired + private ${tableClassModel.className}Service ${tableClassModel.classVariableName}Service; + + //记录编辑前的值Before_Edit_Value + public static final String BEV="${tableClassModel.className}_BEV"; + + + /** + * 列表显示 + */ + @RequestMapping(value = SAFEPATH+"/showList") + public @ResponseBody AjaxResult showList(${tableClassModel.className} ${tableClassModel.classVariableName}, PaginationVO pageVo) { + return showList(${tableClassModel.classVariableName}Service, ${tableClassModel.classVariableName}, pageVo); + } + + /** + * 新增 + */ + @RemoveRequestToken + @RequestMapping(value = SAFEPATH+"/add${tableClassModel.className}") + public @ResponseBody AjaxResult add${tableClassModel.className}(${tableClassModel.className} ${tableClassModel.classVariableName}) { + int i=${tableClassModel.classVariableName}Service.add(${tableClassModel.classVariableName}); + if(i > 0){ + return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.ADD_SUCCES, "${tableClassModel.tableMemo}"); + }else { + throw new GlobleException(SystemErrorCode.DATA_ADD_FAIL); + } + } + + + + + + /** + * 修改 + */ + @RemoveRequestToken + @RequestMapping(value = SAFEPATH+"/modify${tableClassModel.className}") + public @ResponseBody AjaxResult modify${tableClassModel.className}(${tableClassModel.className} ${tableClassModel.classVariableName}) { + ${tableClassModel.classVariableName}.set${tableClassModel.primaryKey.methodName}(((${tableClassModel.className})WebUtil.getSessionAttribute(BEV)).get${tableClassModel.primaryKey.methodName}()); + AjaxResult result=modify(${tableClassModel.classVariableName}Service, WebUtil.getSessionAttribute(BEV), ${tableClassModel.classVariableName}, "${tableClassModel.tableMemo}"); + WebUtil.removeSessionAttribute(BEV); + return result; + } + + + + + /** + * 进入修改界面 + */ + @SaveRequestToken + @RequestMapping(value = SAFEPATH+"/editForm") + public String editForm(${tableClassModel.primaryKey.classType} id) { + ${tableClassModel.className} ${tableClassModel.classVariableName}; + if (id != null) { + ${tableClassModel.classVariableName} = ${tableClassModel.classVariableName}Service.findById(id); + WebUtil.getRequest().setAttribute("obj", ${tableClassModel.classVariableName}); + WebUtil.setSessionAttribute(BEV, ${tableClassModel.classVariableName}); + } + return "admin/${tableClassModel.className}-form"; + } + + + /** + * 删除 + */ + @RequestMapping(value = SAFEPATH+"/del") + public @ResponseBody AjaxResult del(String keys) { + return remove(${tableClassModel.classVariableName}Service, keys); + } + +} \ No newline at end of file diff --git a/src/main/resources/template/excelTemplate/dao.ftl b/src/main/resources/template/excelTemplate/dao.ftl new file mode 100644 index 0000000..43f2ef2 --- /dev/null +++ b/src/main/resources/template/excelTemplate/dao.ftl @@ -0,0 +1,38 @@ +package ${codeModel.packageName}; + +<#list importList?keys as key> +import ${importList[key]}; +</#list> + +/** + * @description ${tableClassModel.tableMemo} + * @author ${dataSource.author} + * @date ${time} + */ +public interface ${ClassName}{ + + public int insert(@Param("item") ${tableClassModel.className} ${tableClassModel.classVariableName}); + + public int batchInsert(@Param("list") List<${tableClassModel.className}> ${tableClassModel.classVariableName}List); + + public int updateByMap(Map<String, Object> modifyMap); + + public int updateByModel(@Param("record")${tableClassModel.className} ${tableClassModel.classVariableName}); + + public int deleteByIds(@Param("list") List<${tableClassModel.primaryKey.classType}> list); + + public int deleteById(${tableClassModel.primaryKey.classType} ${tableClassModel.primaryKey.property}); + + public int deleteByModel(@Param("record") ${tableClassModel.className} ${tableClassModel.classVariableName}); + + public List<${tableClassModel.className}> selectInPage(@Param("record") ${tableClassModel.className} ${tableClassModel.classVariableName}, @Param("pageVo") PaginationVO pageVo); + + public List<${tableClassModel.className}> selectByModel(@Param("record") ${tableClassModel.className} ${tableClassModel.classVariableName}); + + public int selectTotalRecord(@Param("record") ${tableClassModel.className} ${tableClassModel.classVariableName}); + + public ${tableClassModel.className} selectById(${tableClassModel.primaryKey.classType} ${tableClassModel.primaryKey.property}); + + public ${tableClassModel.className} selectForUpdate(${tableClassModel.primaryKey.classType} ${tableClassModel.primaryKey.property}); + +} \ No newline at end of file diff --git a/src/main/resources/template/excelTemplate/daoImpl.ftl b/src/main/resources/template/excelTemplate/daoImpl.ftl new file mode 100644 index 0000000..2720efa --- /dev/null +++ b/src/main/resources/template/excelTemplate/daoImpl.ftl @@ -0,0 +1,226 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" +"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> + +<mapper namespace="${tableClassModel.qualifiedClassName}"> + <!-- 定义${tableClassModel.className} 的复杂关联map --> + <resultMap type="${beanQualifiedClassName}" id="${tableClassModel.className}Map"> + <id property="${tableClassModel.primaryKey.property}" column="${tableClassModel.primaryKey.column}" /> + <result property="createBy" column="create_by" /> + <result property="createTime" column="create_time" /> + <result property="updateBy" column="update_by" /> + <result property="updateTime" column="update_time" /> + <#list tableClassModel.mapping as item> + <#if !item.isPrimaryKey> + <result property="${item.property}" column="${item.column}" /> + </#if> + </#list> + </resultMap> + + + <!-- 定义${tableClassModel.className} 的简单map ,本map不添加其他的关联属性 --> + <resultMap type="${beanQualifiedClassName}" id="${tableClassModel.className}SimpleMap"> + <id property="${tableClassModel.primaryKey.property}" column="${tableClassModel.primaryKey.column}" /> + <result property="createBy" column="create_by" /> + <result property="createTime" column="create_time" /> + <result property="updateBy" column="update_by" /> + <result property="updateTime" column="update_time" /> + <#list tableClassModel.mapping as item> + <#if !item.isPrimaryKey> + <result property="${item.property}" column="${item.column}" /> + </#if> + </#list> + </resultMap> + + <!-- 字段sql --> + <sql id="columns"> + create_by, + create_time, + update_by, + update_time, + <#list tableClassModel.mapping as item> + <#if item_has_next> + ${item.column}, + <#else> + ${item.column} + </#if> + </#list> + </sql> + + <!-- 属性sql --> + <sql id="propertys"> + ${'#'}{item.createBy}, + now(), + ${'#'}{item.updateBy}, + now(), + <#list tableClassModel.mapping as propertyitem> + <#if propertyitem_has_next> + ${'#'}{item.${propertyitem.property}}, + <#else> + ${'#'}{item.${propertyitem.property}} + </#if> + </#list> + </sql> + + <!-- where sql --> + <sql id="where_sql"> + + <if test="record!=null"> + <#list tableClassModel.mapping as item> + <if test="(record.${item.property}!=null and record.${item.property}!='') or (record.${item.property}!='' and record.${item.property}==0) "> + and ${item.column} = ${'#'}{record.${item.property}} + </if> + </#list> + </if> + + </sql> + + <!-- 插入方法 --> + <insert id="insert" parameterType="${beanQualifiedClassName}" + useGeneratedKeys="true" keyProperty="item.${tableClassModel.primaryKey.property}"> + INSERT INTO ${tableClassModel.tableName} ( + <include refid="columns"></include> + ) + VALUES ( + <include refid="propertys"></include> + ) + </insert> + + + + <!-- 批量插入 --> + <insert id="batchInsert" parameterType="java.util.List"> + INSERT INTO ${tableClassModel.tableName} ( + <include refid="columns"></include> + ) + VALUES + <foreach collection="list" item="item" index="index" separator=",">( + <include refid="propertys"></include> + )</foreach> + </insert> + + + + + + <!-- 根据Map更新 部分更新 --> + <update id="updateByMap" parameterType="java.util.HashMap" > + UPDATE ${tableClassModel.tableName} + <set> + <#list tableClassModel.mapping as item> + <#if !item.isPrimaryKey> + <if test="_parameter.containsKey('${item.property}')"> + ${item.column} = ${'#'}{${item.property}}, + </if> + </#if> + </#list> + </set> + WHERE ${tableClassModel.primaryKey.column}=${'#'}{${tableClassModel.primaryKey.property}} + </update> + + + <!-- 根据对象更新 部分更新 --> + <update id="updateByModel" parameterType="${tableClassModel.primaryKey.classType}"> + UPDATE ${tableClassModel.tableName} + <set> + <#list tableClassModel.mapping as item> + <#if !item.isPrimaryKey> + <#if item.classType = "String"> + <if test="record.${item.property} != null and record.${item.property} != '' "> + ${item.column} = ${'#'}{record.${item.property}}, + </if> + <#else> + <if test="record.${item.property} != null "> + ${item.column} = ${'#'}{record.${item.property}}, + </if> + </#if> + </#if> + </#list> + </set> + WHERE ${tableClassModel.primaryKey.column}=${'#'}{record.${tableClassModel.primaryKey.property}} + </update> + + <!-- 批量删除 --> + <delete id="deleteByIds" parameterType="java.util.List"> + delete from ${tableClassModel.tableName} where ${tableClassModel.primaryKey.column} in + <foreach collection="list" index="index" item="item" open="(" + separator="," close=")"> + ${'#'}{item} + </foreach> + </delete> + + <!-- 根据id删除--> + <delete id="deleteById" parameterType="${tableClassModel.primaryKey.classType}"> + DELETE FROM ${tableClassModel.tableName} + where ${tableClassModel.primaryKey.column}=${'#'}{${tableClassModel.primaryKey.property}} + </delete> + + <!-- 根据对象删除--> + <delete id="deleteByModel" parameterType="${beanQualifiedClassName}"> + DELETE FROM ${tableClassModel.tableName} + <where> + <include refid="where_sql" ></include> + </where> + </delete> + + + + <!-- 分页查询 --> + <select id="selectInPage" resultMap="${tableClassModel.className}Map"> + select + <include refid="columns" ></include> + from ${tableClassModel.tableName} + <where> + <include refid="where_sql"></include> + </where> + <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 --> + <if test="pageVo.sort !=null and pageVo.order !=null"> + order by + ${'$'}{pageVo.sort} ${'$'}{pageVo.order} + </if> + <if test="pageVo.offset >=0 and pageVo.limit >0"> + limit + ${'#'}{pageVo.offset},${'#'}{pageVo.limit} + </if> + </if> + </select> + + <!-- 查询总条数 --> + <select id="selectTotalRecord" parameterType="long" resultType="java.lang.Integer"> + select count(*) + from ${tableClassModel.tableName} + <where> + <include refid="where_sql"></include> + </where> + </select> + + <!-- 根据id查询--> + <select id="selectById" resultMap="${tableClassModel.className}Map"> + select + <include refid="columns" ></include> + from ${tableClassModel.tableName} + where ${tableClassModel.primaryKey.column}=${'#'}{${tableClassModel.primaryKey.property}} + </select> + + + <!-- 根据id 锁表查询--> + <select id="selectForUpdate" resultMap="${tableClassModel.className}Map"> + select + <include refid="columns" ></include> + from ${tableClassModel.tableName} + where ${tableClassModel.primaryKey.column}=${'#'}{${tableClassModel.primaryKey.column}} + for update + </select> + + + + <!-- 根据对象查询--> + <select id="selectByModel" resultMap="${tableClassModel.className}Map"> + select + <include refid="columns" ></include> + from ${tableClassModel.tableName} + <where> + <include refid="where_sql"></include> + </where> + </select> +</mapper> \ No newline at end of file diff --git a/src/main/resources/template/excelTemplate/form.ftl b/src/main/resources/template/excelTemplate/form.ftl new file mode 100644 index 0000000..6174abb --- /dev/null +++ b/src/main/resources/template/excelTemplate/form.ftl @@ -0,0 +1,82 @@ +<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> +<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%> +<c:set var="path" value="${'$'}{pageContext.request.contextPath }" /> +<!DOCTYPE HTML> +<html> +<head> +<meta charset="utf-8"> +<META HTTP-EQUIV="Pragma" CONTENT="no-cache"> +<meta name="renderer" content="webkit|ie-comp|ie-stand"> +<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> +<meta name="viewport" + content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" /> +<meta http-equiv="Cache-Control" content="no-siteapp" /> +<!-- 本框架基本脚本和样式 --> +<script type="text/javascript" + src="${'$'}{path }/resource/js/plugin/jquery-2.1.4.min.js"></script> +<script type="text/javascript" + src="${'$'}{path }/resource/js/systools/MBase.js"></script> +</head> +<body> +<div class="ibox-content"> + <form class="form-horizontal" id="dataform" onsubmit="javascripr:return false;"> + <input type="hidden" name="tokenUrl" value="${'$'}{tokenUrl}"> + <input type="hidden" name="token" value="${'$'}{token}"> + <c:if test="${'$'}{obj ne null }"> + <input type="hidden" name="${tableClassModel.primaryKey.property}" value="${'$'}{obj.${tableClassModel.primaryKey.property} }"> + </c:if> + <#assign x = 1> + <#assign nodelSize = tableClassModel.mapping?size > + <#list tableClassModel.mapping as being> + <#if being.isVisible> + <#assign x = x + 1> + <#if x%2 = 0 || x = nodelSize> + <div class="form-group"> + </#if> + <label class="col-sm-2 control-label">${being.showName} + <#if being.isNecessary> + <span class="text-danger">*</span> + </#if> + </label> + <div class="col-sm-4"> + <input type="text" class="form-control" name="${being.property}" + <#if being.columnLength??> + maxLength="${being.columnLength}" dataType="s1-${being.columnLength}" + </#if> + <#if !being.isNecessary> + ignore="ignore" + </#if> + value="<c:out value="${'$'}{obj.${being.property} }"></c:out>" nullmsg="${being.showName}不能为空"> + </div> + <#if x%2 = 1 || x = nodelSize> + </div> + </#if> + </#if> + </#list> + <div class="form-group "> + <div class="col-sm-12 text-center"> + <a href="javascript:;" onclick="myForm.submit()" + class="btn btn-success radius"><i class="fa fa-check"></i> 保存</a> <a + class="btn btn-danger radius" href="javascript:;" onclick="MTools.closeForm()" ><i class="fa fa-close"></i> 关闭</a> + </div> + </div> + </form> + </div> +</body> +<script type="text/javascript" src="${'$'}{path }/resource/js/systools/MJsBase.js"></script> +<script type="text/javascript"> + MTools.autoFullSelect(); + $(".select2").select2(); + var invokeUrl="${'$'}{path}/do/admin/${tableClassModel.classVariableName}/add${tableClassModel.className}"; + <c:if test="${'$'}{obj ne null }"> + invokeUrl = "${'$'}{path}/do/admin/${tableClassModel.classVariableName}/modify${tableClassModel.className}"; + </c:if> + var myForm=MForm.initForm({ + invokeUrl:invokeUrl, + afterSubmit:function(){ + parent.myGrid.serchData(); + }, + }); +</script> +</body> +</html> \ No newline at end of file diff --git a/src/main/resources/template/excelTemplate/javaBean.ftl b/src/main/resources/template/excelTemplate/javaBean.ftl new file mode 100644 index 0000000..0da2f4b --- /dev/null +++ b/src/main/resources/template/excelTemplate/javaBean.ftl @@ -0,0 +1,41 @@ +package ${codeModel.packageName}; + +<#list importList?keys as key> +import ${importList[key]}; +</#list> + +/** + * @description ${tableClassModel.tableMemo} + * @author ${dataSource.author} + * @date ${time} + */ +public class ${tableClassModel.className} extends EntityDTO{ + @Extend + private static final long serialVersionUID = 1L; + +<#list tableClassModel.mapping as being> + + <#if being.memo!=""> + /** + * ${being.memo} + */ + </#if> + private ${being.classType} ${being.property}; + +</#list> + +<#list tableClassModel.mapping as being> + + public ${being.classType} get${being.methodName}() { + return ${being.property}; + } + + public void set${being.methodName}(${being.classType} ${being.property}) { + this.${being.property}=${being.property}; + } + +</#list> + + + +} \ No newline at end of file diff --git a/src/main/resources/template/excelTemplate/list.ftl b/src/main/resources/template/excelTemplate/list.ftl new file mode 100644 index 0000000..b80d170 --- /dev/null +++ b/src/main/resources/template/excelTemplate/list.ftl @@ -0,0 +1,132 @@ +<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> +<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%> +<%@ taglib uri="http://www.zkingsoft.com" prefix="matrix"%> +<c:set var="path" value="${'$'}{pageContext.request.contextPath }" /> +<!DOCTYPE HTML> +<html> +<head> +<meta charset="utf-8"> +<META HTTP-EQUIV="Pragma" CONTENT="no-cache"> +<meta name="renderer" content="webkit|ie-comp|ie-stand"> +<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> +<meta name="viewport" + content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" /> +<meta http-equiv="Cache-Control" content="no-siteapp" /> +<!-- 本框架基本脚本和样式 --> +<script type="text/javascript" + src="${'$'}{path }/resource/js/plugin/jquery-2.1.4.min.js"></script> +<script type="text/javascript" + src="${'$'}{path }/resource/js/systools/MBase.js"></script> +</head> +<body class="gray-bg"> +<div class="wrapper wrapper-content animated fadeInRight"> + <!-- 搜索框部分start --> + <matrix:btn value="${tableClassModel.className}:search"> +<div class="row" > + <div class="col-sm-12" > + <form class="form-inline" id="serchform"> + <div class="form-group mr-20"> + <input placeholder="请输入关键词" name="" type="text" class="form-control"> + </div> + <button onclick="myGrid.serchData()" type="button" + class="btn btn-info btn-sm"> + <i class="fa fa-search "></i> 搜索 + </button> + <button onclick="MForm.reset('#serchform');" type="button" class="btn btn-info btn-sm"> + <i class="fa fa-refresh "></i> 重置 + </button> + </form> + </div> + </div> + </matrix:btn> + <!-- 搜索框部分en --> + <div class="ibox-content radius-5 mt-5 mpanel"> + + <div class="row" > + <div class="col-sm-12" > + <div class="option-bar"> + <matrix:btn value="${tableClassModel.className}:dels"> + <button onclick="myGrid.delItems('${tableClassModel.primaryKey.property}')" type="button" + class="btn btn-danger btn-sm"> + <i class="fa fa-trash"></i>批量删除 + </button> + </matrix:btn> + <matrix:btn value="${tableClassModel.className}:add"> + <button onclick="openAdd()" type="button" + class="btn btn-success btn-sm"> + <i class="fa fa-plus"></i> 新增 + </button> + </matrix:btn> + </div> + <table id="mgrid"> + <thead> + <tr> + <th data-checkbox="true"></th> + <th data-formatter="MGrid.indexfn" data-align="center" data-width="30px" >序号</th> + <#list tableClassModel.mapping as being> + <#if being.isVisible> + <th data-field="${being.property}" >${being.showName}</th> + </#if> + </#list> + <th data-align="center" data-width="195px" data-field="${tableClassModel.primaryKey.property}" data-formatter="buidOperate">操作</th> + </tr> + </thead> + </table> + </div> +</div> +</div> +</div> +<script type="text/javascript" + src="${'$'}{path }/resource/js/systools/MJsBase.js"></script> + <script type="text/javascript"> + var myGrid; + $(function(){ + var delUrl=""; + <matrix:btn value="${tableClassModel.className}:del"> + delUrl="${'$'}{path}/do/admin/${tableClassModel.classVariableName}/del" ; + </matrix:btn> + myGrid=MGrid.initGrid({ + url:"${'$'}{path}/do/admin/${tableClassModel.classVariableName}/showList", + delUrl:delUrl, + }); + + }); + + function buidOperate(value, row, index){ + var html = []; + <matrix:btn value="${tableClassModel.className}:edit"> + html[0] = '<a onClick="openEdit(\''+value+'\')" title="编辑" class="fa fa-edit option"></a>' + </matrix:btn> + <matrix:btn value="${tableClassModel.className}:del"> + html[1] = '<a onClick="myGrid.delItem(\''+value+'\')" title="删除" class="fa fa-close option text-danger"></a>'; + </matrix:btn> + return html.join(""); + } + //打开添加界面 + <matrix:btn value="${tableClassModel.className}:add"> + function openAdd() { + layer.open({ + type : 2, + title : "添加${tableClassModel.tableMemo}", + area : [ MUI.SIZE_L, '400px' ], + maxmin : true, + content : [ '${'$'}{path}/do/admin/${tableClassModel.classVariableName}/editForm'] + }); + } + </matrix:btn> + + //打开编辑界面 + <matrix:btn value="${tableClassModel.className}:edit"> + function openEdit(id) { + layer.open({ + type : 2, + title : "编辑${tableClassModel.tableMemo}", + area : [ MUI.SIZE_L, '400px' ], + maxmin : true, + content : [ '${'$'}{path}/do/admin/${tableClassModel.classVariableName}/editForm?id=' + id] + }); + } + </matrix:btn> + </script> +</body> +</html> diff --git a/src/main/resources/template/excelTemplate/mybatis-config.ftl b/src/main/resources/template/excelTemplate/mybatis-config.ftl new file mode 100644 index 0000000..8851a3b --- /dev/null +++ b/src/main/resources/template/excelTemplate/mybatis-config.ftl @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> + +<configuration> + <settings> + <setting name="cacheEnabled" value="false" /> + <setting name="lazyLoadingEnabled" value="false" /> + <setting name="multipleResultSetsEnabled" value="true" /> + <setting name="useColumnLabel" value="true" /> + <setting name="useGeneratedKeys" value="false" /> + <setting name="defaultExecutorType" value="SIMPLE" /> + <setting name="defaultStatementTimeout" value="25000" /> + </settings> + + + + + <typeAliases> + + <#list alias as item> + ${item} + </#list> + + </typeAliases> + + <mappers> + + <#list mappers as item> + ${item} + </#list> + + </mappers> +</configuration> \ No newline at end of file diff --git a/src/main/resources/template/excelTemplate/service.ftl b/src/main/resources/template/excelTemplate/service.ftl new file mode 100644 index 0000000..96815de --- /dev/null +++ b/src/main/resources/template/excelTemplate/service.ftl @@ -0,0 +1,72 @@ +package ${codeModel.packageName}; + +<#list importList?keys as key> +import ${importList[key]}; +</#list> + +/** + * @description service接口类 ${tableClassModel.tableMemo} + * @author ${dataSource.author} + * @date ${time} + */ +public interface ${ClassName} extends BaseServices<${tableClassModel.className}>{ + + /** + * 新增 + */ + public int add(${tableClassModel.className} ${tableClassModel.classVariableName}); + + /** + * 批量新增 + */ + public int batchAdd(List<${tableClassModel.className}> ${tableClassModel.classVariableName}List); + + /** + * 根据map键值对 更新 + */ + public int modifyByMap(${tableClassModel.className} old${tableClassModel.className} ,${tableClassModel.className} new${tableClassModel.className}); + + /** + * 根据对象 更新 + */ + public int modifyByModel(${tableClassModel.className} ${tableClassModel.classVariableName}); + + /** + * 批量删除 + */ + public int remove(List<${tableClassModel.primaryKey.classType}> list); + + /** + * 根据id删除 + */ + public int removeById(${tableClassModel.primaryKey.classType} ${tableClassModel.primaryKey.property}); + + /** + * 根据对象删除 + */ + public int removeByModel(${tableClassModel.className} ${tableClassModel.classVariableName}); + + /** + * 分页查询 + */ + public List<${tableClassModel.className}> findInPage(${tableClassModel.className} ${tableClassModel.classVariableName}, PaginationVO pageVo); + + /** + * 根据对象查询 + */ + public List<${tableClassModel.className}> findByModel(${tableClassModel.className} ${tableClassModel.classVariableName}); + + /** + * 统计记录数 + */ + public int findTotal(${tableClassModel.className} ${tableClassModel.classVariableName}); + + /** + * 根据id查询 + */ + public ${tableClassModel.className} findById(${tableClassModel.primaryKey.classType} ${tableClassModel.primaryKey.property}); + + + + +} \ No newline at end of file diff --git a/src/main/resources/template/excelTemplate/serviceImpl.ftl b/src/main/resources/template/excelTemplate/serviceImpl.ftl new file mode 100644 index 0000000..27479fb --- /dev/null +++ b/src/main/resources/template/excelTemplate/serviceImpl.ftl @@ -0,0 +1,132 @@ +package ${codeModel.packageName}; + +<#list importList?keys as key> +import ${importList[key]}; +</#list> + +/** + * @description service接口实现类${tableClassModel.tableMemo} + * @author ${dataSource.author} + * @date ${time} + */ +@Service +public class ${ClassName} implements ${serviceInterface}{ + + + @Autowired + private ${daoClassName} ${daoVariableName}; + + + @Override + public int add(${tableClassModel.className} ${tableClassModel.classVariableName}){ + // 设置基本字段信息 + SysUsers loginUser = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); + ${tableClassModel.classVariableName}.setCreateBy(loginUser.getSuName()); + ${tableClassModel.classVariableName}.setUpdateBy(loginUser.getSuName()); + ${tableClassModel.classVariableName}.set${tableClassModel.primaryKey.methodName}(UUIDUtil.getRandomID()); + return ${daoVariableName}.insert(${tableClassModel.classVariableName}); + + } + + @Override + public int batchAdd(List<${tableClassModel.className}> ${tableClassModel.classVariableName}List) { + //这里没有做基本字段的设置,如有需要请自己实现 + int num = 0; + int c = 10000; + int size = ${tableClassModel.classVariableName}List.size()/c + 1; + for(int i=0; i<size; i++) { + int begin = i*c; + int end = (i+1)*c; + end = end >= ${tableClassModel.classVariableName}List.size() ? ${tableClassModel.classVariableName}List.size() : end; + List<${tableClassModel.className}> insertList = ${tableClassModel.classVariableName}List.subList(begin, end); + num += ${daoVariableName}.batchInsert(insertList); + } + return num; + + } + + + + @Override + public int modifyByMap(${tableClassModel.className} old${tableClassModel.className} + ,${tableClassModel.className} new${tableClassModel.className}){ + + Map<String, Object> modifyMap = null; + try { + if (!ModelUtils.isModified(old${tableClassModel.className}, new${tableClassModel.className})) { + return MatrixConstance.DML_SUCCESSS; + } + modifyMap = ModelUtils.comparePojo2Map(old${tableClassModel.className}, new${tableClassModel.className}); + } catch (Exception e) { + throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL, e, new${tableClassModel.className}); + } + if (modifyMap.size() > 0) { + modifyMap.put("${tableClassModel.primaryKey.property}", old${tableClassModel.className}.get${tableClassModel.primaryKey.methodName}()); + ${daoVariableName}.updateByMap(modifyMap); + } + return MatrixConstance.DML_SUCCESSS; + } + + @Override + public int modifyByModel(${tableClassModel.className} ${tableClassModel.classVariableName}){ + + return ${daoVariableName}.updateByModel(${tableClassModel.classVariableName}); + + } + + + + @Override + public int remove(List<${tableClassModel.primaryKey.classType}> list){ + + return ${daoVariableName}.deleteByIds(list); + + } + + @Override + public int removeById(${tableClassModel.primaryKey.classType} ${tableClassModel.primaryKey.property}){ + + return ${daoVariableName}.deleteById(${tableClassModel.primaryKey.property}); + + } + + @Override + public int removeByModel(${tableClassModel.className} ${tableClassModel.classVariableName}){ + + return ${daoVariableName}.deleteByModel(${tableClassModel.classVariableName}); + + } + + + @Override + public List<${tableClassModel.className}> findInPage(${tableClassModel.className} ${tableClassModel.classVariableName}, PaginationVO pageVo){ + + return ${daoVariableName}.selectInPage(${tableClassModel.classVariableName} , pageVo); + + } + + @Override + public List<${tableClassModel.className}> findByModel(${tableClassModel.className} ${tableClassModel.classVariableName}){ + + return ${daoVariableName}.selectByModel(${tableClassModel.classVariableName}); + + } + + @Override + public int findTotal(${tableClassModel.className} ${tableClassModel.classVariableName}){ + + return ${daoVariableName}.selectTotalRecord(${tableClassModel.classVariableName}); + + } + + @Override + public ${tableClassModel.className} findById(${tableClassModel.primaryKey.classType} ${tableClassModel.primaryKey.property}){ + + return ${daoVariableName}.selectById(${tableClassModel.primaryKey.property}); + + } + + + + +} \ No newline at end of file diff --git a/src/main/resources/template/excelTemplate/sqlFile.ftl b/src/main/resources/template/excelTemplate/sqlFile.ftl new file mode 100644 index 0000000..5cacf61 --- /dev/null +++ b/src/main/resources/template/excelTemplate/sqlFile.ftl @@ -0,0 +1,16 @@ + +/** + * ${tableClassModel.tableMemo} + * @author ${dataSource.author} + * @date ${time} + */ + CREATE TABLE ${tableClassModel.tableName}( + create_by varchar(100) NOT NULL COMMENT '创建人', + create_time datetime NOT NULL COMMENT '创建时间', + update_by varchar(100) NOT NULL COMMENT '更新人', + update_time datetime NOT NULL COMMENT '更新时间', +<#list tableClassModel.mapping as being> + ${being.column} ${being.fullJdbcType} ${being.isAllowNull} COMMENT '${being.memo}', +</#list> +PRIMARY KEY(${tableClassModel.primaryKey.column}) +)ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='${tableClassModel.tableMemo}'; \ No newline at end of file diff --git a/src/main/resources/template/excelTemplateForBoot/action.ftl b/src/main/resources/template/excelTemplateForBoot/action.ftl new file mode 100644 index 0000000..64aed71 --- /dev/null +++ b/src/main/resources/template/excelTemplateForBoot/action.ftl @@ -0,0 +1,122 @@ +package ${codeModel.packageName}; + +<#list importList?keys as key> +import ${importList[key]}; +</#list> + +/** + * @description ${tableClassModel.tableMemo} + * @author ${dataSource.author} + * @date ${time} + */ +@Controller +@RequestMapping(value = "admin/${tableClassModel.classVariableName}") +public class ${ClassName} { + + @Autowired + private ${tableClassModel.className}Dao ${tableClassModel.classVariableName}Dao; + + //记录编辑前的值Before_Edit_Value + public static final String BEV="${tableClassModel.className}_BEV"; + + + /** + * 列表显示 + */ + @RequestMapping(value = "/showList") + public @ResponseBody AjaxResult showList(${tableClassModel.className} ${tableClassModel.classVariableName}, PaginationVO pageVo) { + if (pageVo == null) { + pageVo = new PaginationVO(); + } + List<${tableClassModel.className}> dataList = ${tableClassModel.classVariableName}Dao.selectInPage(${tableClassModel.classVariableName}, pageVo); + AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, dataList, + ${tableClassModel.classVariableName}Dao.selectTotalRecord(${tableClassModel.classVariableName})); + return result; + } + + /** + * 新增 + */ + @RemoveRequestToken + @RequestMapping(value = "/add${tableClassModel.className}") + public @ResponseBody AjaxResult add${tableClassModel.className}(${tableClassModel.className} ${tableClassModel.classVariableName}) { + SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); + ${tableClassModel.classVariableName}.setCreateBy(user.getSuName()); + ${tableClassModel.classVariableName}.setUpdateBy(user.getSuName()); + int i=${tableClassModel.classVariableName}Dao.insert(${tableClassModel.classVariableName}); + if(i > 0){ + return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.ADD_SUCCES, "${tableClassModel.tableMemo}"); + }else { + throw new GlobleException(SystemErrorCode.DATA_ADD_FAIL); + } + } + + + + + + /** + * 修改 + */ + @RemoveRequestToken + @RequestMapping(value = "/modify${tableClassModel.className}") + public @ResponseBody AjaxResult modify${tableClassModel.className}(${tableClassModel.className} new${tableClassModel.className}) { + ${tableClassModel.className} old${tableClassModel.className} = WebUtil.getSessionAttribute(BEV); + int i = 0; + Map<String, Object> modifyMap = null; + try { + if (!ModelUtils.isModified(old${tableClassModel.className}, new${tableClassModel.className})) { + i = MatrixConstance.DML_SUCCESSS; + } + modifyMap = ModelUtils.comparePojo2Map(old${tableClassModel.className}, new${tableClassModel.className}); + } catch (Exception e) { + throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL, e, new${tableClassModel.className}); + } + if (modifyMap.size() > 0) { + modifyMap.put("${tableClassModel.primaryKey.property}", old${tableClassModel.className}.get${tableClassModel.primaryKey.property?cap_first}()); + ${tableClassModel.classVariableName}Dao.updateByMap(modifyMap); + } + i = MatrixConstance.DML_SUCCESSS; + WebUtil.removeSessionAttribute(BEV); + if (i > 0) { + return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.UPDATE_SUCCES, "${tableClassModel.tableMemo}"); + } else { + throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL); + } + } + + + + + /** + * 进入修改界面 + */ + @SaveRequestToken + @RequestMapping(value = "/editForm") + public ModelAndView editForm(${tableClassModel.primaryKey.classType} id) { + ${tableClassModel.className} ${tableClassModel.classVariableName} = new ${tableClassModel.className}(); + ModelAndView modelAndView = new ModelAndView("admin/${tableClassModel.className?uncap_first}-form"); + if (id != null) { + ${tableClassModel.classVariableName} = ${tableClassModel.classVariableName}Dao.selectById(id); + WebUtil.setSessionAttribute(BEV, ${tableClassModel.classVariableName}); + } + modelAndView.addObject("obj",${tableClassModel.classVariableName}); + return modelAndView; + } + + + /** + * 删除 + */ + @RequestMapping(value = "/del") + public @ResponseBody AjaxResult del(String keys) { + List<String> ids = StringUtils.strToCollToString(keys, ","); + int i = ${tableClassModel.classVariableName}Dao.deleteByIds(ids); + if (i > 0) { + return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.DELETE_SUCCES, i); + } else { + throw new GlobleException(SystemErrorCode.DATA_DELETE_FAIL); + } + } + +} \ No newline at end of file diff --git a/src/main/resources/template/excelTemplateForBoot/dao.ftl b/src/main/resources/template/excelTemplateForBoot/dao.ftl new file mode 100644 index 0000000..5e5d33d --- /dev/null +++ b/src/main/resources/template/excelTemplateForBoot/dao.ftl @@ -0,0 +1,38 @@ +package ${codeModel.packageName}; + +<#list importList?keys as key> +import ${importList[key]}; +</#list> + +/** + * @description ${tableClassModel.tableMemo} + * @author ${dataSource.author} + * @date ${time} + */ +public interface ${ClassName}{ + + public int insert(@Param("item") ${tableClassModel.className} ${tableClassModel.classVariableName}); + + public int batchInsert(@Param("list") List<${tableClassModel.className}> ${tableClassModel.classVariableName}List); + + public int updateByMap(Map<String, Object> modifyMap); + + public int updateByModel(@Param("record")${tableClassModel.className} ${tableClassModel.classVariableName}); + + public int deleteByIds(@Param("list") List<String> list); + + public int deleteById(${tableClassModel.primaryKey.classType} ${tableClassModel.primaryKey.property}); + + public int deleteByModel(@Param("record") ${tableClassModel.className} ${tableClassModel.classVariableName}); + + public List<${tableClassModel.className}> selectInPage(@Param("record") ${tableClassModel.className} ${tableClassModel.classVariableName}, @Param("pageVo") PaginationVO pageVo); + + public List<${tableClassModel.className}> selectByModel(@Param("record") ${tableClassModel.className} ${tableClassModel.classVariableName}); + + public int selectTotalRecord(@Param("record") ${tableClassModel.className} ${tableClassModel.classVariableName}); + + public ${tableClassModel.className} selectById(${tableClassModel.primaryKey.classType} ${tableClassModel.primaryKey.property}); + + public ${tableClassModel.className} selectForUpdate(${tableClassModel.primaryKey.classType} ${tableClassModel.primaryKey.property}); + +} \ No newline at end of file diff --git a/src/main/resources/template/excelTemplateForBoot/daoImpl.ftl b/src/main/resources/template/excelTemplateForBoot/daoImpl.ftl new file mode 100644 index 0000000..2720efa --- /dev/null +++ b/src/main/resources/template/excelTemplateForBoot/daoImpl.ftl @@ -0,0 +1,226 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" +"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> + +<mapper namespace="${tableClassModel.qualifiedClassName}"> + <!-- 定义${tableClassModel.className} 的复杂关联map --> + <resultMap type="${beanQualifiedClassName}" id="${tableClassModel.className}Map"> + <id property="${tableClassModel.primaryKey.property}" column="${tableClassModel.primaryKey.column}" /> + <result property="createBy" column="create_by" /> + <result property="createTime" column="create_time" /> + <result property="updateBy" column="update_by" /> + <result property="updateTime" column="update_time" /> + <#list tableClassModel.mapping as item> + <#if !item.isPrimaryKey> + <result property="${item.property}" column="${item.column}" /> + </#if> + </#list> + </resultMap> + + + <!-- 定义${tableClassModel.className} 的简单map ,本map不添加其他的关联属性 --> + <resultMap type="${beanQualifiedClassName}" id="${tableClassModel.className}SimpleMap"> + <id property="${tableClassModel.primaryKey.property}" column="${tableClassModel.primaryKey.column}" /> + <result property="createBy" column="create_by" /> + <result property="createTime" column="create_time" /> + <result property="updateBy" column="update_by" /> + <result property="updateTime" column="update_time" /> + <#list tableClassModel.mapping as item> + <#if !item.isPrimaryKey> + <result property="${item.property}" column="${item.column}" /> + </#if> + </#list> + </resultMap> + + <!-- 字段sql --> + <sql id="columns"> + create_by, + create_time, + update_by, + update_time, + <#list tableClassModel.mapping as item> + <#if item_has_next> + ${item.column}, + <#else> + ${item.column} + </#if> + </#list> + </sql> + + <!-- 属性sql --> + <sql id="propertys"> + ${'#'}{item.createBy}, + now(), + ${'#'}{item.updateBy}, + now(), + <#list tableClassModel.mapping as propertyitem> + <#if propertyitem_has_next> + ${'#'}{item.${propertyitem.property}}, + <#else> + ${'#'}{item.${propertyitem.property}} + </#if> + </#list> + </sql> + + <!-- where sql --> + <sql id="where_sql"> + + <if test="record!=null"> + <#list tableClassModel.mapping as item> + <if test="(record.${item.property}!=null and record.${item.property}!='') or (record.${item.property}!='' and record.${item.property}==0) "> + and ${item.column} = ${'#'}{record.${item.property}} + </if> + </#list> + </if> + + </sql> + + <!-- 插入方法 --> + <insert id="insert" parameterType="${beanQualifiedClassName}" + useGeneratedKeys="true" keyProperty="item.${tableClassModel.primaryKey.property}"> + INSERT INTO ${tableClassModel.tableName} ( + <include refid="columns"></include> + ) + VALUES ( + <include refid="propertys"></include> + ) + </insert> + + + + <!-- 批量插入 --> + <insert id="batchInsert" parameterType="java.util.List"> + INSERT INTO ${tableClassModel.tableName} ( + <include refid="columns"></include> + ) + VALUES + <foreach collection="list" item="item" index="index" separator=",">( + <include refid="propertys"></include> + )</foreach> + </insert> + + + + + + <!-- 根据Map更新 部分更新 --> + <update id="updateByMap" parameterType="java.util.HashMap" > + UPDATE ${tableClassModel.tableName} + <set> + <#list tableClassModel.mapping as item> + <#if !item.isPrimaryKey> + <if test="_parameter.containsKey('${item.property}')"> + ${item.column} = ${'#'}{${item.property}}, + </if> + </#if> + </#list> + </set> + WHERE ${tableClassModel.primaryKey.column}=${'#'}{${tableClassModel.primaryKey.property}} + </update> + + + <!-- 根据对象更新 部分更新 --> + <update id="updateByModel" parameterType="${tableClassModel.primaryKey.classType}"> + UPDATE ${tableClassModel.tableName} + <set> + <#list tableClassModel.mapping as item> + <#if !item.isPrimaryKey> + <#if item.classType = "String"> + <if test="record.${item.property} != null and record.${item.property} != '' "> + ${item.column} = ${'#'}{record.${item.property}}, + </if> + <#else> + <if test="record.${item.property} != null "> + ${item.column} = ${'#'}{record.${item.property}}, + </if> + </#if> + </#if> + </#list> + </set> + WHERE ${tableClassModel.primaryKey.column}=${'#'}{record.${tableClassModel.primaryKey.property}} + </update> + + <!-- 批量删除 --> + <delete id="deleteByIds" parameterType="java.util.List"> + delete from ${tableClassModel.tableName} where ${tableClassModel.primaryKey.column} in + <foreach collection="list" index="index" item="item" open="(" + separator="," close=")"> + ${'#'}{item} + </foreach> + </delete> + + <!-- 根据id删除--> + <delete id="deleteById" parameterType="${tableClassModel.primaryKey.classType}"> + DELETE FROM ${tableClassModel.tableName} + where ${tableClassModel.primaryKey.column}=${'#'}{${tableClassModel.primaryKey.property}} + </delete> + + <!-- 根据对象删除--> + <delete id="deleteByModel" parameterType="${beanQualifiedClassName}"> + DELETE FROM ${tableClassModel.tableName} + <where> + <include refid="where_sql" ></include> + </where> + </delete> + + + + <!-- 分页查询 --> + <select id="selectInPage" resultMap="${tableClassModel.className}Map"> + select + <include refid="columns" ></include> + from ${tableClassModel.tableName} + <where> + <include refid="where_sql"></include> + </where> + <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 --> + <if test="pageVo.sort !=null and pageVo.order !=null"> + order by + ${'$'}{pageVo.sort} ${'$'}{pageVo.order} + </if> + <if test="pageVo.offset >=0 and pageVo.limit >0"> + limit + ${'#'}{pageVo.offset},${'#'}{pageVo.limit} + </if> + </if> + </select> + + <!-- 查询总条数 --> + <select id="selectTotalRecord" parameterType="long" resultType="java.lang.Integer"> + select count(*) + from ${tableClassModel.tableName} + <where> + <include refid="where_sql"></include> + </where> + </select> + + <!-- 根据id查询--> + <select id="selectById" resultMap="${tableClassModel.className}Map"> + select + <include refid="columns" ></include> + from ${tableClassModel.tableName} + where ${tableClassModel.primaryKey.column}=${'#'}{${tableClassModel.primaryKey.property}} + </select> + + + <!-- 根据id 锁表查询--> + <select id="selectForUpdate" resultMap="${tableClassModel.className}Map"> + select + <include refid="columns" ></include> + from ${tableClassModel.tableName} + where ${tableClassModel.primaryKey.column}=${'#'}{${tableClassModel.primaryKey.column}} + for update + </select> + + + + <!-- 根据对象查询--> + <select id="selectByModel" resultMap="${tableClassModel.className}Map"> + select + <include refid="columns" ></include> + from ${tableClassModel.tableName} + <where> + <include refid="where_sql"></include> + </where> + </select> +</mapper> \ No newline at end of file diff --git a/src/main/resources/template/excelTemplateForBoot/form.ftl b/src/main/resources/template/excelTemplateForBoot/form.ftl new file mode 100644 index 0000000..7e9b950 --- /dev/null +++ b/src/main/resources/template/excelTemplateForBoot/form.ftl @@ -0,0 +1,82 @@ +<!DOCTYPE HTML> +<html xmlns:th="http://www.thymeleaf.org"> +<head> +<meta charset="utf-8"> +<META HTTP-EQUIV="Pragma" CONTENT="no-cache"> +<meta name="renderer" content="webkit|ie-comp|ie-stand"> +<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> +<meta name="viewport" + content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" /> +<meta http-equiv="Cache-Control" content="no-siteapp" /> +<!-- 本框架基本脚本和样式 --> +<script type="text/javascript" + th:src="@{/js/plugin/jquery-2.1.4.min.js}"></script> +<script type="text/javascript" + th:src="@{/js/systools/MBase.js}"></script> +</head> +<body> +<div class="ibox-content"> + <form class="form-horizontal" id="dataform" onsubmit="javascript:return false;"> + <input type="hidden" name="tokenUrl" th:value="${'$'}{tokenUrl}"> + <input type="hidden" name="token" th:value="${'$'}{token}"> + <input type="hidden" name="${tableClassModel.primaryKey.property}" th:value="${'$'}{obj.${tableClassModel.primaryKey.property}}"> + <#assign x = 1> + <#assign nodelSize = tableClassModel.showCount+1 > + <#list tableClassModel.mapping as being> + <#if being.isVisible> + <#assign x = x + 1> + <#if x%2 = 0 > + <div class="form-group"> + </#if> + <label class="col-sm-2 control-label">${being.showName} + <#if being.isNecessary> + <span class="text-danger">*</span> + </#if> + </label> + <div class="col-sm-4"> + <input type="text" class="form-control" name="${being.property}" + <#if being.columnLength??> + maxLength="${being.columnLength}" dataType="s1-${being.columnLength}" + </#if> + <#if !being.isNecessary> + ignore="ignore" + </#if> + th:value="${'$'}{obj.${being.property}}"nullmsg="${being.showName}不能为空"> + </div> + <#if x%2 = 1 || x = nodelSize> + </div> + </#if> + </#if> + </#list> + <div class="form-group "> + <div class="col-sm-12 text-center"> + <a href="javascript:;" onclick="myForm.submit()" + class="btn btn-success radius"><i class="fa fa-check"></i> 保存</a> <a + class="btn btn-danger radius" href="javascript:;" onclick="MTools.closeForm()" ><i class="fa fa-close"></i> 关闭</a> + </div> + </div> + </form> + </div> +</body> +<script type="text/javascript" th:src="@{/js/systools/MJsBase.js}"></script> +<script th:inline="javascript"> + MTools.autoFullSelect(); + $(".select2").select2(); + + /*<![CDATA[*/ + var obj=/*[[${'$'}{obj}]]*/ + /*]]>*/ + + var invokeUrl=basePath+"/admin/${tableClassModel.classVariableName}/add${tableClassModel.className}"; + if(obj.${tableClassModel.primaryKey.property}!=null){ + invokeUrl = basePath+"/admin/${tableClassModel.classVariableName}/modify${tableClassModel.className}"; + } + var myForm=MForm.initForm({ + invokeUrl:invokeUrl, + afterSubmit:function(){ + parent.myGrid.serchData(); + }, + }); +</script> +</body> +</html> \ No newline at end of file diff --git a/src/main/resources/template/excelTemplateForBoot/javaBean.ftl b/src/main/resources/template/excelTemplateForBoot/javaBean.ftl new file mode 100644 index 0000000..0849348 --- /dev/null +++ b/src/main/resources/template/excelTemplateForBoot/javaBean.ftl @@ -0,0 +1,42 @@ +package ${codeModel.packageName}; + +<#list importList?keys as key> +import ${importList[key]}; +</#list> + +/** + * @description ${tableClassModel.tableMemo} + * @author ${dataSource.author} + * @date ${time} + */ +public class ${tableClassModel.className} extends EntityDTO{ + @Extend + private static final long serialVersionUID = 1L; + +<#list tableClassModel.mapping as being> + + <#if being.memo!=""> + /** + * ${being.memo} + */ + </#if> + private ${being.classType} ${being.property}; + +</#list> + +<#list tableClassModel.mapping as being> + + public ${being.classType} get${being.methodName}() { + return ${being.property}; + } + + public ${tableClassModel.className} set${being.methodName}(${being.classType} ${being.property}) { + this.${being.property}=${being.property}; + return this; + } + +</#list> + + + +} \ No newline at end of file diff --git a/src/main/resources/template/excelTemplateForBoot/list.ftl b/src/main/resources/template/excelTemplateForBoot/list.ftl new file mode 100644 index 0000000..4905c30 --- /dev/null +++ b/src/main/resources/template/excelTemplateForBoot/list.ftl @@ -0,0 +1,161 @@ +<!DOCTYPE HTML> +<html xmlns:th="http://www.thymeleaf.org" xmlns:matrix="http://www.w3.org/1999/xhtml"> +<html xmlns:th="http://www.thymeleaf.org"> +<head> + <meta charset="utf-8"> + <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> + <meta name="renderer" content="webkit|ie-comp|ie-stand"> + <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> + <meta name="viewport" + content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/> + <meta http-equiv="Cache-Control" content="no-siteapp"/> + <!-- 本框架基本脚本和样式 --> + <script type="text/javascript" + th:src="@{/js/plugin/jquery-2.1.4.min.js}"></script> + <script type="text/javascript" + th:src="@{/js/systools/MBase.js}"></script> +</head> +<body class=" container-fluid"> + +<div class="pd-10"> + + <!-- 搜索框部分start --> + <div class="row form-head"> + <div class="col-md-4 col-xs-12"> + <button onclick="myGrid.delItems('${tableClassModel.primaryKey.property}')" type="button" matrix:btn="${tableClassModel.className?uncap_first}-dels" + class="btn btn-danger btn-sm"> + <i class="fa fa-trash"></i>批量删除 + </button> + <button onclick="openAdd()" type="button" matrix:btn="${tableClassModel.className?uncap_first}-add" + class="btn btn-success btn-sm"> + <i class="fa fa-plus"></i> 新增 + </button> + </div> + <div class="col-md-8 col-xs-12"> + <div class="row"> + <div class="col-md-11 col-xs-12" style="text-align: right"> + <form class="form-inline" id="serchform" matrix:btn="${tableClassModel.className?uncap_first}-search" > + <div class="input-group"> + <div class="btn-group search-list " data-for="search-text"> + <button type="button" + class="btn btn-default dropdown-toggle searchlist" + data-toggle="dropdown"> + 用户姓名 <span class="caret "></span> + </button> + <ul class="dropdown-menu" role="menu"> + <li data-field="suName"><a>用户姓名</a></li> + <li data-field="suAccount"><a>账号 </a></li> + </ul> + </div> + <div class="form-group mr-20 ml-20"> + <input id="search-text" name="suName" placeholder="输入查询关键词" + type="text" class="form-control"> + </div> + <div class="form-group"> + <button onclick="myGrid.serchData(1)" type="button" + class="btn btn-info"> + <i class="fa fa-search "></i> 搜索 + </button> + <button type="reset" class="btn btn-info "> + <i class="fa fa-refresh "></i> 重置 + </button> + </div> + </div> + <!-- 高级搜索 + <div class="senior-content"> + <div class="serch-headline">高级搜索</div> + <div> + <span class="serch-title">电话:</span> <input type="text" name="suTel" + class="form-control"> + </div> + <div class="button"> + <button type="button" class="btn btn-info" onclick="myGrid.serchData()">确认</button> + <button type="button" class="btn btn-warning serch-close">取消</button> + </div> + </div> --> + </form> + </div> + <!-- <div class="col-md-1 text-r layui-anim" data-anim="layui-anim-up"> + <a class="senior-serch">高级搜索</a> + </div>--> + </div> + </div> + </div> + + <div class="row"> + <table id="mgrid"> + <thead> + <tr> + <th data-checkbox="true"></th> + <th data-formatter="MGrid.indexfn" data-align="center" data-width="30px">序号</th> + <#list tableClassModel.mapping as being> + <#if being.isVisible> + <th data-field="${being.property}">${being.showName}</th> + </#if> + </#list> + <th data-align="center" data-width="195px" data-field="${tableClassModel.primaryKey.property}" + data-formatter="buidOperate">操作 + </th> + </tr> + </thead> + </table> + </div> +</div> +<script type="text/javascript" + th:src="@{/js/systools/MJsBase.js}"></script> +<script type="text/javascript"> + var myGrid; + $(function () { + var delUrl = ""; + delUrl = basePath + "/admin/${tableClassModel.classVariableName}/del"; + myGrid = MGrid.initGrid({ + url: basePath + "/admin/${tableClassModel.classVariableName}/showList", + delUrl: delUrl, + }); + + }); + + function buidOperate(value, row, index) { + var html = ""; + html += '<div class="btn-group">' + + '<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown">' + + '操作 <span class="caret"></span>' + '</button>' + + '<ul class="dropdown-menu" role="menu">' + + '<li><a href="javascript:void(0)" style="display:' + + value + + '" onClick="openEdit(\'' + + value + + '\')" title="编辑">编辑</a></li>' + + '<li><a href="javascript:void(0)" style="display:' + + value + + '" onClick="myGrid.delItem(\'' + + value + + '\')" title="删除">删除</a></li>' + '</ul>' + '</div>'; + html += ''; + return html; + } + + //打开添加界面 + function openAdd() { + layer.open({ + type: 2, + title: "添加${tableClassModel.tableMemo}", + area: [MUI.SIZE_L, '400px'], + maxmin: true, + content: [basePath + '/admin/${tableClassModel.classVariableName}/editForm'] + }); + } + + //打开编辑界面 + function openEdit(id) { + layer.open({ + type: 2, + title: "编辑${tableClassModel.tableMemo}", + area: [MUI.SIZE_L, '400px'], + maxmin: true, + content: [basePath + '/admin/${tableClassModel.classVariableName}/editForm?id=' + id] + }); + } +</script> +</body> +</html> diff --git a/src/main/resources/template/excelTemplateForBoot/mybatis-config.ftl b/src/main/resources/template/excelTemplateForBoot/mybatis-config.ftl new file mode 100644 index 0000000..8851a3b --- /dev/null +++ b/src/main/resources/template/excelTemplateForBoot/mybatis-config.ftl @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> + +<configuration> + <settings> + <setting name="cacheEnabled" value="false" /> + <setting name="lazyLoadingEnabled" value="false" /> + <setting name="multipleResultSetsEnabled" value="true" /> + <setting name="useColumnLabel" value="true" /> + <setting name="useGeneratedKeys" value="false" /> + <setting name="defaultExecutorType" value="SIMPLE" /> + <setting name="defaultStatementTimeout" value="25000" /> + </settings> + + + + + <typeAliases> + + <#list alias as item> + ${item} + </#list> + + </typeAliases> + + <mappers> + + <#list mappers as item> + ${item} + </#list> + + </mappers> +</configuration> \ No newline at end of file diff --git a/src/main/resources/template/excelTemplateForBoot/sqlFile.ftl b/src/main/resources/template/excelTemplateForBoot/sqlFile.ftl new file mode 100644 index 0000000..47e8287 --- /dev/null +++ b/src/main/resources/template/excelTemplateForBoot/sqlFile.ftl @@ -0,0 +1,46 @@ + +/** + * ${tableClassModel.tableMemo} + * @author ${dataSource.author} + * @date ${time} + */ + CREATE TABLE ${tableClassModel.tableName}( + create_by varchar(100) NOT NULL COMMENT '创建人', + create_time datetime NOT NULL COMMENT '创建时间', + update_by varchar(100) NOT NULL COMMENT '更新人', + update_time datetime NOT NULL COMMENT '更新时间', +<#list tableClassModel.mapping as being> +<#if being.column = tableClassModel.primaryKey.column && being.fullJdbcType = "int"> + ${being.column} ${being.fullJdbcType} ${being.isAllowNull} AUTO_INCREMENT COMMENT '${being.memo}', + <#else> + ${being.column} ${being.fullJdbcType} ${being.isAllowNull} COMMENT '${being.memo}', +</#if> + +</#list> +PRIMARY KEY(${tableClassModel.primaryKey.column}) +)ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='${tableClassModel.tableMemo}'; + +/** + * + *生成菜单的sql 默认在权限管理目录下 根据不同的主键类型生成不同的菜单SQL + */ + <#if tableClassModel.primaryKey.fullJdbcType = "int"> +INSERT INTO `sys_function` +VALUES + ('开发者', now(), + '开发者', now(), + null, + '', 'biz/${tableClassModel.className?uncap_first}-list', '否', '2', + 1, + '${tableClassModel.tableMemo}', '4', '${tableClassModel.className?uncap_first}', '123', '是', null); + <#else> +INSERT INTO `sys_function` +VALUES + ('开发者', now(), + '开发者', now(), + replace(uuid(), '-', ''), + '', 'biz/${tableClassModel.className?uncap_first}-list', '否', '2', + '05fb2915b39b4021a51d406473f0ee91', + '${tableClassModel.tableMemo}', '4', '${tableClassModel.className?uncap_first}', '123', '是', null); +</#if> + diff --git "a/src/main/resources/template/excelTemplateForBoot/\346\225\260\346\215\256\345\255\227\345\205\270\350\241\250\050\346\250\241\346\235\277\051.xlsx" "b/src/main/resources/template/excelTemplateForBoot/\346\225\260\346\215\256\345\255\227\345\205\270\350\241\250\050\346\250\241\346\235\277\051.xlsx" new file mode 100644 index 0000000..4f23622 --- /dev/null +++ "b/src/main/resources/template/excelTemplateForBoot/\346\225\260\346\215\256\345\255\227\345\205\270\350\241\250\050\346\250\241\346\235\277\051.xlsx" Binary files differ diff --git a/src/main/resources/template/excelTemplateForCloud/action.ftl b/src/main/resources/template/excelTemplateForCloud/action.ftl new file mode 100644 index 0000000..6f2a931 --- /dev/null +++ b/src/main/resources/template/excelTemplateForCloud/action.ftl @@ -0,0 +1,81 @@ +package ${codeModel.packageName}; + +<#list importList?keys as key> +import ${importList[key]}; +</#list> + +/** + * @description ${tableClassModel.tableMemo} + * @author ${dataSource.author} + * @date ${time} + */ +@Controller +@RequestMapping(value = "admin/${tableClassModel.classVariableName}") +public class ${ClassName} { + + @Autowired + private ${tableClassModel.className}Dao ${tableClassModel.classVariableName}Dao; + @Autowired + RedisUserLoginUtils redisUserLoginUtils; + + /** + * 列表显示 + */ + @RequestMapping(value = "/showList") + public @ResponseBody AjaxResult showList(${tableClassModel.className} ${tableClassModel.classVariableName}) { + List<${tableClassModel.className}> dataList = ${tableClassModel.classVariableName}Dao.selectInPage(${tableClassModel.classVariableName}); + AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, dataList, + ${tableClassModel.classVariableName}Dao.selectTotalRecord(${tableClassModel.classVariableName})); + return result; + } + + /** + * 新增 + */ + @RemoveRequestToken + @RequestMapping(value = "/add${tableClassModel.className}") + public @ResponseBody AjaxResult add${tableClassModel.className}(${tableClassModel.className} ${tableClassModel.classVariableName}) { + SysUsers user = redisUserLoginUtils.getLoginUser(SysUsers.class); + ${tableClassModel.classVariableName}.setCreateBy(user.getSuName()); + ${tableClassModel.classVariableName}.setUpdateBy(user.getSuName()); + int i=${tableClassModel.classVariableName}Dao.insert(${tableClassModel.classVariableName}); + if(i > 0){ + return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.ADD_SUCCES, "${tableClassModel.tableMemo}"); + }else { + throw new GlobleException(SystemErrorCode.DATA_ADD_FAIL); + } + } + + + /** + * 修改 + */ + @RemoveRequestToken + @RequestMapping(value = "/modify${tableClassModel.className}") + public @ResponseBody AjaxResult modify${tableClassModel.className}(${tableClassModel.className} new${tableClassModel.className}) { + int i = ${tableClassModel.classVariableName}Dao.updateByModel(new${tableClassModel.className}); + if (i > 0) { + return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.UPDATE_SUCCES, "${tableClassModel.tableMemo}"); + } else { + throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL); + } + } + + + /** + * 删除 + */ + @RequestMapping(value = "/del") + public @ResponseBody AjaxResult del(String keys) { + SysUsers user = redisUserLoginUtils.getLoginUser(SysUsers.class); + Long companyId = user.getCompanyId(); + List<String> ids = StringUtils.strToCollToString(keys, ","); + int i = ${tableClassModel.classVariableName}Dao.deleteByIds(ids,companyId); + if (i > 0) { + return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.DELETE_SUCCES, i); + } else { + throw new GlobleException(SystemErrorCode.DATA_DELETE_FAIL); + } + } + +} \ No newline at end of file diff --git a/src/main/resources/template/excelTemplateForCloud/dao.ftl b/src/main/resources/template/excelTemplateForCloud/dao.ftl new file mode 100644 index 0000000..114308b --- /dev/null +++ b/src/main/resources/template/excelTemplateForCloud/dao.ftl @@ -0,0 +1,40 @@ +package ${codeModel.packageName}; + +<#list importList?keys as key> +import ${importList[key]}; +</#list> + +/** + * @description ${tableClassModel.tableMemo} + * @author ${dataSource.author} + * @date ${time} + */ +public interface ${ClassName}{ + + public int insert(@Param("item") ${tableClassModel.className} ${tableClassModel.classVariableName}); + + public int batchInsert(@Param("list") List<${tableClassModel.className}> ${tableClassModel.classVariableName}List); + + public int updateByMap(Map<String, Object> modifyMap); + + public int compelUpdateByModel(@Param("record")${tableClassModel.className} ${tableClassModel.classVariableName}); + + public int updateByModel(@Param("record")${tableClassModel.className} ${tableClassModel.classVariableName}); + + public int deleteByIds(@Param("list") List<String> list , @Param("companyId") Long companyId); + + public int deleteById(${tableClassModel.primaryKey.classType} ${tableClassModel.primaryKey.property}, Long companyId); + + public int deleteByModel(@Param("record") ${tableClassModel.className} ${tableClassModel.classVariableName}); + + public List<${tableClassModel.className}> selectInPage(@Param("record") ${tableClassModel.className} ${tableClassModel.classVariableName}); + + public List<${tableClassModel.className}> selectByModel(@Param("record") ${tableClassModel.className} ${tableClassModel.classVariableName}); + + public int selectTotalRecord(@Param("record") ${tableClassModel.className} ${tableClassModel.classVariableName}); + + public ${tableClassModel.className} selectById(${tableClassModel.primaryKey.classType} ${tableClassModel.primaryKey.property}); + + public ${tableClassModel.className} selectForUpdate(${tableClassModel.primaryKey.classType} ${tableClassModel.primaryKey.property}); + +} \ No newline at end of file diff --git a/src/main/resources/template/excelTemplateForCloud/daoImpl.ftl b/src/main/resources/template/excelTemplateForCloud/daoImpl.ftl new file mode 100644 index 0000000..e31a570 --- /dev/null +++ b/src/main/resources/template/excelTemplateForCloud/daoImpl.ftl @@ -0,0 +1,252 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" +"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> + +<mapper namespace="${tableClassModel.qualifiedClassName}"> + <!-- 定义${tableClassModel.className} 的复杂关联map --> + <resultMap type="${beanQualifiedClassName}" id="${tableClassModel.className}Map"> + <id property="${tableClassModel.primaryKey.property}" column="${tableClassModel.primaryKey.column}" /> + <result property="createBy" column="create_by" /> + <result property="createTime" column="create_time" /> + <result property="updateBy" column="update_by" /> + <result property="updateTime" column="update_time" /> + <#list tableClassModel.mapping as item> + <#if !item.isPrimaryKey> + <result property="${item.property}" column="${item.column}" /> + </#if> + </#list> + </resultMap> + + + <!-- 定义${tableClassModel.className} 的简单map ,本map不添加其他的关联属性 --> + <resultMap type="${beanQualifiedClassName}" id="${tableClassModel.className}SimpleMap"> + <id property="${tableClassModel.primaryKey.property}" column="${tableClassModel.primaryKey.column}" /> + <result property="createBy" column="create_by" /> + <result property="createTime" column="create_time" /> + <result property="updateBy" column="update_by" /> + <result property="updateTime" column="update_time" /> + <#list tableClassModel.mapping as item> + <#if !item.isPrimaryKey> + <result property="${item.property}" column="${item.column}" /> + </#if> + </#list> + </resultMap> + + <!-- 字段sql --> + <sql id="columns"> + create_by, + create_time, + update_by, + update_time, + <#list tableClassModel.mapping as item> + <#if item_has_next> + ${item.column}, + <#else> + ${item.column} + </#if> + </#list> + </sql> + + <!-- 属性sql --> + <sql id="propertys"> + ${'#'}{item.createBy}, + now(), + ${'#'}{item.updateBy}, + now(), + <#list tableClassModel.mapping as propertyitem> + <#if propertyitem_has_next> + ${'#'}{item.${propertyitem.property}}, + <#else> + ${'#'}{item.${propertyitem.property}} + </#if> + </#list> + </sql> + + <!-- where sql --> + <sql id="where_sql"> + + <if test="record!=null"> + <#list tableClassModel.mapping as item> + <if test="(record.${item.property}!=null and record.${item.property}!='') or (record.${item.property}!='' and record.${item.property}==0) "> + and ${item.column} = ${'#'}{record.${item.property}} + </if> + </#list> + </if> + + </sql> + + <!-- 插入方法 --> + <insert id="insert" parameterType="${beanQualifiedClassName}" + useGeneratedKeys="true" keyProperty="item.${tableClassModel.primaryKey.property}"> + INSERT INTO ${tableClassModel.tableName} ( + <include refid="columns"></include> + ) + VALUES ( + <include refid="propertys"></include> + ) + </insert> + + + + <!-- 批量插入 --> + <insert id="batchInsert" parameterType="java.util.List"> + INSERT INTO ${tableClassModel.tableName} ( + <include refid="columns"></include> + ) + VALUES + <foreach collection="list" item="item" index="index" separator=",">( + <include refid="propertys"></include> + )</foreach> + </insert> + + + + + + <!-- 根据Map更新 部分更新 --> + <update id="updateByMap" parameterType="java.util.HashMap" > + UPDATE ${tableClassModel.tableName} + <set> + update_time = now(), + <#list tableClassModel.mapping as item> + <#if !item.isPrimaryKey> + <if test="_parameter.containsKey('${item.property}')"> + ${item.column} = ${'#'}{${item.property}}, + </if> + </#if> + </#list> + </set> + WHERE ${tableClassModel.primaryKey.column}=${'#'}{${tableClassModel.primaryKey.property}} + </update> + + + <!-- 根据对象更新 部分更新 --> + <update id="updateByModel" parameterType="${tableClassModel.primaryKey.classType}"> + UPDATE ${tableClassModel.tableName} + <set> + update_time = now(), + <#list tableClassModel.mapping as item> + <#if !item.isPrimaryKey> + <#if item.classType = "String"> + <if test="record.${item.property} != null and record.${item.property} != '' "> + ${item.column} = ${'#'}{record.${item.property}}, + </if> + <#else> + <if test="record.${item.property} != null "> + ${item.column} = ${'#'}{record.${item.property}}, + </if> + </#if> + </#if> + </#list> + </set> + WHERE ${tableClassModel.primaryKey.column}=${'#'}{record.${tableClassModel.primaryKey.property}} + </update> + + <!-- 根据对象更新 部分更新(Integer和String类型为空时也会更新) --> + <update id="compelUpdateByModel" parameterType="${tableClassModel.primaryKey.classType}"> + UPDATE ${tableClassModel.tableName} + <set> + update_time = now(), + <#list tableClassModel.mapping as item> + <#if !item.isPrimaryKey> + <#if item.classType = "String"> + <if test="record.${item.property} != null"> + ${item.column} = ${'#'}{record.${item.property}}, + </if> + <#else> + <if test="record.${item.property} != '' "> + ${item.column} = ${'#'}{record.${item.property}}, + </if> + </#if> + </#if> + </#list> + </set> + WHERE ${tableClassModel.primaryKey.column}=${'#'}{record.${tableClassModel.primaryKey.property}} + </update> + + <!-- 批量删除 --> + <delete id="deleteByIds" parameterType="java.util.List"> + delete from ${tableClassModel.tableName} where ${tableClassModel.primaryKey.column} in + <foreach collection="list" index="index" item="item" open="(" + separator="," close=")"> + ${'#'}{item} + </foreach> + and company_id = ${'#'}{companyId} + </delete> + + <!-- 根据id删除--> + <delete id="deleteById" parameterType="${tableClassModel.primaryKey.classType}"> + DELETE FROM ${tableClassModel.tableName} + where ${tableClassModel.primaryKey.column}=${'#'}{${tableClassModel.primaryKey.property}} + and company_id = ${'#'}{companyId} + </delete> + + <!-- 根据对象删除--> + <delete id="deleteByModel" parameterType="${beanQualifiedClassName}"> + DELETE FROM ${tableClassModel.tableName} + <where> + <include refid="where_sql" ></include> + </where> + </delete> + + + + <!-- 分页查询 --> + <select id="selectInPage" resultMap="${tableClassModel.className}Map"> + select + <include refid="columns" ></include> + from ${tableClassModel.tableName} + <where> + <include refid="where_sql"></include> + </where> + <if test="record !=null"><!-- 判断pageVo对象是否为空 --> + <if test="record.sort !=null and record.order !=null"> + order by + ${'$'}{record.sort} ${'$'}{record.order} + </if> + <if test="record.offset >=0 and record.limit >0"> + limit + ${'#'}{record.offset},${'#'}{record.limit} + </if> + </if> + </select> + + <!-- 查询总条数 --> + <select id="selectTotalRecord" parameterType="long" resultType="java.lang.Integer"> + select count(*) + from ${tableClassModel.tableName} + <where> + <include refid="where_sql"></include> + </where> + </select> + + <!-- 根据id查询--> + <select id="selectById" resultMap="${tableClassModel.className}Map"> + select + <include refid="columns" ></include> + from ${tableClassModel.tableName} + where ${tableClassModel.primaryKey.column}=${'#'}{${tableClassModel.primaryKey.property}} + </select> + + + <!-- 根据id 锁表查询--> + <select id="selectForUpdate" resultMap="${tableClassModel.className}Map"> + select + <include refid="columns" ></include> + from ${tableClassModel.tableName} + where ${tableClassModel.primaryKey.column}=${'#'}{${tableClassModel.primaryKey.column}} + for update + </select> + + + + <!-- 根据对象查询--> + <select id="selectByModel" resultMap="${tableClassModel.className}Map"> + select + <include refid="columns" ></include> + from ${tableClassModel.tableName} + <where> + <include refid="where_sql"></include> + </where> + </select> +</mapper> \ No newline at end of file diff --git a/src/main/resources/template/excelTemplateForCloud/form.ftl b/src/main/resources/template/excelTemplateForCloud/form.ftl new file mode 100644 index 0000000..7e9b950 --- /dev/null +++ b/src/main/resources/template/excelTemplateForCloud/form.ftl @@ -0,0 +1,82 @@ +<!DOCTYPE HTML> +<html xmlns:th="http://www.thymeleaf.org"> +<head> +<meta charset="utf-8"> +<META HTTP-EQUIV="Pragma" CONTENT="no-cache"> +<meta name="renderer" content="webkit|ie-comp|ie-stand"> +<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> +<meta name="viewport" + content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" /> +<meta http-equiv="Cache-Control" content="no-siteapp" /> +<!-- 本框架基本脚本和样式 --> +<script type="text/javascript" + th:src="@{/js/plugin/jquery-2.1.4.min.js}"></script> +<script type="text/javascript" + th:src="@{/js/systools/MBase.js}"></script> +</head> +<body> +<div class="ibox-content"> + <form class="form-horizontal" id="dataform" onsubmit="javascript:return false;"> + <input type="hidden" name="tokenUrl" th:value="${'$'}{tokenUrl}"> + <input type="hidden" name="token" th:value="${'$'}{token}"> + <input type="hidden" name="${tableClassModel.primaryKey.property}" th:value="${'$'}{obj.${tableClassModel.primaryKey.property}}"> + <#assign x = 1> + <#assign nodelSize = tableClassModel.showCount+1 > + <#list tableClassModel.mapping as being> + <#if being.isVisible> + <#assign x = x + 1> + <#if x%2 = 0 > + <div class="form-group"> + </#if> + <label class="col-sm-2 control-label">${being.showName} + <#if being.isNecessary> + <span class="text-danger">*</span> + </#if> + </label> + <div class="col-sm-4"> + <input type="text" class="form-control" name="${being.property}" + <#if being.columnLength??> + maxLength="${being.columnLength}" dataType="s1-${being.columnLength}" + </#if> + <#if !being.isNecessary> + ignore="ignore" + </#if> + th:value="${'$'}{obj.${being.property}}"nullmsg="${being.showName}不能为空"> + </div> + <#if x%2 = 1 || x = nodelSize> + </div> + </#if> + </#if> + </#list> + <div class="form-group "> + <div class="col-sm-12 text-center"> + <a href="javascript:;" onclick="myForm.submit()" + class="btn btn-success radius"><i class="fa fa-check"></i> 保存</a> <a + class="btn btn-danger radius" href="javascript:;" onclick="MTools.closeForm()" ><i class="fa fa-close"></i> 关闭</a> + </div> + </div> + </form> + </div> +</body> +<script type="text/javascript" th:src="@{/js/systools/MJsBase.js}"></script> +<script th:inline="javascript"> + MTools.autoFullSelect(); + $(".select2").select2(); + + /*<![CDATA[*/ + var obj=/*[[${'$'}{obj}]]*/ + /*]]>*/ + + var invokeUrl=basePath+"/admin/${tableClassModel.classVariableName}/add${tableClassModel.className}"; + if(obj.${tableClassModel.primaryKey.property}!=null){ + invokeUrl = basePath+"/admin/${tableClassModel.classVariableName}/modify${tableClassModel.className}"; + } + var myForm=MForm.initForm({ + invokeUrl:invokeUrl, + afterSubmit:function(){ + parent.myGrid.serchData(); + }, + }); +</script> +</body> +</html> \ No newline at end of file diff --git a/src/main/resources/template/excelTemplateForCloud/javaBean.ftl b/src/main/resources/template/excelTemplateForCloud/javaBean.ftl new file mode 100644 index 0000000..efb556f --- /dev/null +++ b/src/main/resources/template/excelTemplateForCloud/javaBean.ftl @@ -0,0 +1,42 @@ +package ${codeModel.packageName}; + +<#list importList?keys as key> +import ${importList[key]}; +</#list> + +/** + * @description ${tableClassModel.tableMemo} + * @author ${dataSource.author} + * @date ${time} + */ +public class ${tableClassModel.className} extends EntityDTOExt{ + @Extend + private static final long serialVersionUID = 1L; + +<#list tableClassModel.mapping as being> + + <#if being.memo!=""> + /** + * ${being.memo} + */ + </#if> + private ${being.classType} ${being.property}; + +</#list> + +<#list tableClassModel.mapping as being> + + public ${being.classType} get${being.methodName}() { + return ${being.property}; + } + + public ${tableClassModel.className} set${being.methodName}(${being.classType} ${being.property}) { + this.${being.property}=${being.property}; + return this; + } + +</#list> + + + +} \ No newline at end of file diff --git a/src/main/resources/template/excelTemplateForCloud/list.ftl b/src/main/resources/template/excelTemplateForCloud/list.ftl new file mode 100644 index 0000000..4905c30 --- /dev/null +++ b/src/main/resources/template/excelTemplateForCloud/list.ftl @@ -0,0 +1,161 @@ +<!DOCTYPE HTML> +<html xmlns:th="http://www.thymeleaf.org" xmlns:matrix="http://www.w3.org/1999/xhtml"> +<html xmlns:th="http://www.thymeleaf.org"> +<head> + <meta charset="utf-8"> + <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> + <meta name="renderer" content="webkit|ie-comp|ie-stand"> + <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> + <meta name="viewport" + content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/> + <meta http-equiv="Cache-Control" content="no-siteapp"/> + <!-- 本框架基本脚本和样式 --> + <script type="text/javascript" + th:src="@{/js/plugin/jquery-2.1.4.min.js}"></script> + <script type="text/javascript" + th:src="@{/js/systools/MBase.js}"></script> +</head> +<body class=" container-fluid"> + +<div class="pd-10"> + + <!-- 搜索框部分start --> + <div class="row form-head"> + <div class="col-md-4 col-xs-12"> + <button onclick="myGrid.delItems('${tableClassModel.primaryKey.property}')" type="button" matrix:btn="${tableClassModel.className?uncap_first}-dels" + class="btn btn-danger btn-sm"> + <i class="fa fa-trash"></i>批量删除 + </button> + <button onclick="openAdd()" type="button" matrix:btn="${tableClassModel.className?uncap_first}-add" + class="btn btn-success btn-sm"> + <i class="fa fa-plus"></i> 新增 + </button> + </div> + <div class="col-md-8 col-xs-12"> + <div class="row"> + <div class="col-md-11 col-xs-12" style="text-align: right"> + <form class="form-inline" id="serchform" matrix:btn="${tableClassModel.className?uncap_first}-search" > + <div class="input-group"> + <div class="btn-group search-list " data-for="search-text"> + <button type="button" + class="btn btn-default dropdown-toggle searchlist" + data-toggle="dropdown"> + 用户姓名 <span class="caret "></span> + </button> + <ul class="dropdown-menu" role="menu"> + <li data-field="suName"><a>用户姓名</a></li> + <li data-field="suAccount"><a>账号 </a></li> + </ul> + </div> + <div class="form-group mr-20 ml-20"> + <input id="search-text" name="suName" placeholder="输入查询关键词" + type="text" class="form-control"> + </div> + <div class="form-group"> + <button onclick="myGrid.serchData(1)" type="button" + class="btn btn-info"> + <i class="fa fa-search "></i> 搜索 + </button> + <button type="reset" class="btn btn-info "> + <i class="fa fa-refresh "></i> 重置 + </button> + </div> + </div> + <!-- 高级搜索 + <div class="senior-content"> + <div class="serch-headline">高级搜索</div> + <div> + <span class="serch-title">电话:</span> <input type="text" name="suTel" + class="form-control"> + </div> + <div class="button"> + <button type="button" class="btn btn-info" onclick="myGrid.serchData()">确认</button> + <button type="button" class="btn btn-warning serch-close">取消</button> + </div> + </div> --> + </form> + </div> + <!-- <div class="col-md-1 text-r layui-anim" data-anim="layui-anim-up"> + <a class="senior-serch">高级搜索</a> + </div>--> + </div> + </div> + </div> + + <div class="row"> + <table id="mgrid"> + <thead> + <tr> + <th data-checkbox="true"></th> + <th data-formatter="MGrid.indexfn" data-align="center" data-width="30px">序号</th> + <#list tableClassModel.mapping as being> + <#if being.isVisible> + <th data-field="${being.property}">${being.showName}</th> + </#if> + </#list> + <th data-align="center" data-width="195px" data-field="${tableClassModel.primaryKey.property}" + data-formatter="buidOperate">操作 + </th> + </tr> + </thead> + </table> + </div> +</div> +<script type="text/javascript" + th:src="@{/js/systools/MJsBase.js}"></script> +<script type="text/javascript"> + var myGrid; + $(function () { + var delUrl = ""; + delUrl = basePath + "/admin/${tableClassModel.classVariableName}/del"; + myGrid = MGrid.initGrid({ + url: basePath + "/admin/${tableClassModel.classVariableName}/showList", + delUrl: delUrl, + }); + + }); + + function buidOperate(value, row, index) { + var html = ""; + html += '<div class="btn-group">' + + '<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown">' + + '操作 <span class="caret"></span>' + '</button>' + + '<ul class="dropdown-menu" role="menu">' + + '<li><a href="javascript:void(0)" style="display:' + + value + + '" onClick="openEdit(\'' + + value + + '\')" title="编辑">编辑</a></li>' + + '<li><a href="javascript:void(0)" style="display:' + + value + + '" onClick="myGrid.delItem(\'' + + value + + '\')" title="删除">删除</a></li>' + '</ul>' + '</div>'; + html += ''; + return html; + } + + //打开添加界面 + function openAdd() { + layer.open({ + type: 2, + title: "添加${tableClassModel.tableMemo}", + area: [MUI.SIZE_L, '400px'], + maxmin: true, + content: [basePath + '/admin/${tableClassModel.classVariableName}/editForm'] + }); + } + + //打开编辑界面 + function openEdit(id) { + layer.open({ + type: 2, + title: "编辑${tableClassModel.tableMemo}", + area: [MUI.SIZE_L, '400px'], + maxmin: true, + content: [basePath + '/admin/${tableClassModel.classVariableName}/editForm?id=' + id] + }); + } +</script> +</body> +</html> diff --git a/src/main/resources/template/excelTemplateForCloud/mybatis-config.ftl b/src/main/resources/template/excelTemplateForCloud/mybatis-config.ftl new file mode 100644 index 0000000..8851a3b --- /dev/null +++ b/src/main/resources/template/excelTemplateForCloud/mybatis-config.ftl @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> + +<configuration> + <settings> + <setting name="cacheEnabled" value="false" /> + <setting name="lazyLoadingEnabled" value="false" /> + <setting name="multipleResultSetsEnabled" value="true" /> + <setting name="useColumnLabel" value="true" /> + <setting name="useGeneratedKeys" value="false" /> + <setting name="defaultExecutorType" value="SIMPLE" /> + <setting name="defaultStatementTimeout" value="25000" /> + </settings> + + + + + <typeAliases> + + <#list alias as item> + ${item} + </#list> + + </typeAliases> + + <mappers> + + <#list mappers as item> + ${item} + </#list> + + </mappers> +</configuration> \ No newline at end of file diff --git a/src/main/resources/template/excelTemplateForCloud/sqlFile.ftl b/src/main/resources/template/excelTemplateForCloud/sqlFile.ftl new file mode 100644 index 0000000..7b20fd3 --- /dev/null +++ b/src/main/resources/template/excelTemplateForCloud/sqlFile.ftl @@ -0,0 +1,54 @@ + +/** + * ${tableClassModel.tableMemo} + * @author ${dataSource.author} + * @date ${time} + */ + CREATE TABLE ${tableClassModel.tableName}( + create_by varchar(100) NOT NULL COMMENT '创建人', + create_time datetime NOT NULL COMMENT '创建时间', + update_by varchar(100) NOT NULL COMMENT '更新人', + update_time datetime NOT NULL COMMENT '更新时间', +<#list tableClassModel.mapping as being> +<#if being.column = tableClassModel.primaryKey.column && being.jdbcType = "int"> + ${being.column} ${being.fullJdbcType} ${being.isAllowNull} AUTO_INCREMENT COMMENT '${being.memo}', + <#else> + ${being.column} ${being.fullJdbcType} ${being.isAllowNull} COMMENT '${being.memo}', +</#if> + +</#list> +PRIMARY KEY(${tableClassModel.primaryKey.column}) +)ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='${tableClassModel.tableMemo}'; + +<#list tableClassModel.mapping as being> +<#if (being.indexName)??> + ALTER TABLE ${tableClassModel.tableName} + ADD INDEX ${being.indexName} (${being.column}) USING BTREE ; +</#if> +</#list> + + +/** + * + *生成菜单的sql 默认在权限管理目录下 根据不同的主键类型生成不同的菜单SQL + */ + <#if tableClassModel.primaryKey.fullJdbcType = "int"> +INSERT INTO `sys_function` +VALUES + ('开发者', now(), + '开发者', now(), + null, + '', 'biz/${tableClassModel.className?uncap_first}-list', '否', '2', + 1, + '${tableClassModel.tableMemo}', '4', '${tableClassModel.className?uncap_first}', '123', '是', null); + <#else> +INSERT INTO `sys_function` +VALUES + ('开发者', now(), + '开发者', now(), + replace(uuid(), '-', ''), + '', 'biz/${tableClassModel.className?uncap_first}-list', '否', '2', + '05fb2915b39b4021a51d406473f0ee91', + '${tableClassModel.tableMemo}', '4', '${tableClassModel.className?uncap_first}', '123', '是', null); +</#if> + diff --git "a/src/main/resources/template/excelTemplateForCloud/\346\225\260\346\215\256\345\255\227\345\205\270\350\241\250\050\346\250\241\346\235\277\051.xlsx" "b/src/main/resources/template/excelTemplateForCloud/\346\225\260\346\215\256\345\255\227\345\205\270\350\241\250\050\346\250\241\346\235\277\051.xlsx" new file mode 100644 index 0000000..4f23622 --- /dev/null +++ "b/src/main/resources/template/excelTemplateForCloud/\346\225\260\346\215\256\345\255\227\345\205\270\350\241\250\050\346\250\241\346\235\277\051.xlsx" Binary files differ diff --git a/src/main/resources/template/excelTemplateForHis/action.ftl b/src/main/resources/template/excelTemplateForHis/action.ftl new file mode 100644 index 0000000..bcc0898 --- /dev/null +++ b/src/main/resources/template/excelTemplateForHis/action.ftl @@ -0,0 +1,71 @@ +package ${codeModel.packageName}; + +<#list importList?keys as key> +import ${importList[key]}; +</#list> +import com.matrix.core.pojo.AjaxResult; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +/** + * @description ${tableClassModel.tableMemo} + * @author ${dataSource.author} + * @date ${time} + */ +@Api(value=" ${tableClassModel.tableMemo}",tags={" ${tableClassModel.tableMemo}接口"}) +@RestController +@RequestMapping(value = "/${tableClassModel.classVariableName}") +public class ${ClassName} { + + @Autowired + private ${tableClassModel.className}Service ${tableClassModel.classVariableName}Service; + + /** + * 列表显示 + */ + @ApiOperation("列表显示") + @PostMapping(value = "/showList") + public AjaxResult showList(@RequestBody ${tableClassModel.className} ${tableClassModel.classVariableName}) { + + return ${tableClassModel.classVariableName}Service.showList(${tableClassModel.classVariableName}); + } + + /** + * 新增 + */ + @ApiOperation("新增") + @PostMapping(value = "/su/add") + public AjaxResult add${tableClassModel.className}(@RequestBody ${tableClassModel.className} ${tableClassModel.classVariableName}) { + return ${tableClassModel.classVariableName}Service.add(${tableClassModel.classVariableName}); + } + + + /** + * 修改 + */ + @ApiOperation("修改") + @PostMapping(value = "/su/modify") + public AjaxResult modify(@RequestBody ${tableClassModel.className} ${tableClassModel.classVariableName}) { + return ${tableClassModel.classVariableName}Service.modify(${tableClassModel.classVariableName}); + } + + + /** + * 批量删除 + */ + @ApiOperation("批量删除") + @PostMapping(value = "/su/deleteIds") + public AjaxResult del(String ids) { + return ${tableClassModel.classVariableName}Service.del(ids); + } + /** + * 删除 + */ + @ApiOperation("删除") + @PostMapping(value = "/su/delete") + public AjaxResult deleteByPrimaryKey(Integer id) { + return ${tableClassModel.classVariableName}Service.deleteByPrimaryKey(id); + } + +} \ No newline at end of file diff --git a/src/main/resources/template/excelTemplateForHis/dao.ftl b/src/main/resources/template/excelTemplateForHis/dao.ftl new file mode 100644 index 0000000..1f6ca5e --- /dev/null +++ b/src/main/resources/template/excelTemplateForHis/dao.ftl @@ -0,0 +1,15 @@ +package ${codeModel.packageName}; + +<#list importList?keys as key> +import ${importList[key]}; +</#list> +import com.xincheng.common.dao.BaseMapper; +/** + * @description ${tableClassModel.tableMemo} + * @author ${dataSource.author} + * @date ${time} + */ +public interface ${ClassName} extends BaseMapper<${tableClassModel.className}>{ + List<${tableClassModel.className}> selectByKeyword(@Param("record") ${tableClassModel.className} ${tableClassModel.classVariableName}); + Integer selectCountByKeyword(@Param("record") ${tableClassModel.className} ${tableClassModel.classVariableName}); +} \ No newline at end of file diff --git a/src/main/resources/template/excelTemplateForHis/daoImpl.ftl b/src/main/resources/template/excelTemplateForHis/daoImpl.ftl new file mode 100644 index 0000000..e21a678 --- /dev/null +++ b/src/main/resources/template/excelTemplateForHis/daoImpl.ftl @@ -0,0 +1,104 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" +"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> + +<mapper namespace="${tableClassModel.qualifiedClassName}"> + <!-- 定义${tableClassModel.className} 的复杂关联map --> + <resultMap type="${beanQualifiedClassName}" id="${tableClassModel.className}Map"> + <id property="${tableClassModel.primaryKey.property}" column="${tableClassModel.primaryKey.column}" /> + <result property="createBy" column="create_by" /> + <result property="createTime" column="create_time" /> + <result property="updateBy" column="update_by" /> + <result property="updateTime" column="update_time" /> + <result property="createDeptId" column="create_dept_id" /> + <result property="createStoreId" column="create_store_id" /> + <result property="companyId" column="company_id" /> + <#list tableClassModel.mapping as item> + <#if !item.isPrimaryKey> + <result property="${item.property}" column="${item.column}" /> + </#if> + </#list> + </resultMap> + + + <!-- 定义${tableClassModel.className} 的简单map ,本map不添加其他的关联属性 --> + <resultMap type="${beanQualifiedClassName}" id="${tableClassModel.className}SimpleMap"> + <result property="createBy" column="create_by" /> + <result property="createTime" column="create_time" /> + <result property="updateBy" column="update_by" /> + <result property="updateTime" column="update_time" /> + <result property="createDeptId" column="create_dept_id" /> + <result property="createStoreId" column="create_store_id" /> + <result property="companyId" column="company_id" /> + <#list tableClassModel.mapping as item> + <#if !item.isPrimaryKey> + <result property="${item.property}" column="${item.column}" /> + </#if> + </#list> + </resultMap> + + <sql id="columns"> + ${r'${alias}'}.create_by ${r'${columnPrefix}'}create_by, + ${r'${alias}'}.create_time ${r'${columnPrefix}'}create_time, + ${r'${alias}'}.update_by ${r'${columnPrefix}'}update_by, + ${r'${alias}'}.update_time ${r'${columnPrefix}'}update_time, + ${r'${alias}'}.create_dept_id ${r'${columnPrefix}'}create_dept_id, + ${r'${alias}'}.create_store_id ${r'${columnPrefix}'}create_store_id, + ${r'${alias}'}.company_id ${r'${columnPrefix}'}company_id, + <#list tableClassModel.mapping as item> + <#if item_has_next> + ${r'${alias}'}.${item.column} ${r'${columnPrefix}'}${item.column}, + <#else> + ${r'${alias}'}.${item.column} ${r'${columnPrefix}'}${item.column} + </#if> + </#list> + </sql> + <!-- where sql --> + <sql id="keyword_where_sql"> + + <if test="record!=null"> + <if test="(record.companyId!=null and record.companyId!='')"> + and ${r'${alias}'}.company_id = ${'#'}{record.companyId} + </if> + <if test="(record.createStoreId!=null and record.createStoreId!='')"> + and ${r'${alias}'}.create_store_id = ${'#'}{record.createStoreId} + </if> + <if test="(record.createDeptId!=null and record.createDeptId!='')"> + and ${r'${alias}'}.create_dept_id = ${'#'}{record.createDeptId} + </if> + <#list tableClassModel.mapping as item> + <#if item.classType=="String"> + <if test="(record.${item.property}!=null and record.${item.property}!='')"> + and ${r'${alias}'}.${item.column} = ${'#'}{record.${item.property}} + </if> + <#else> + <if test="(record.${item.property}!=null)"> + and ${r'${alias}'}.${item.column} = ${'#'}{record.${item.property}} + </if> + </#if> + </#list> + </if> + + </sql> + <!-- 分页查询 --> + <select id="selectByKeyword" resultMap="${tableClassModel.className}Map"> + select + <include refid="columns" > + <property name="alias" value="a"/> + <property name="columnPrefix" value=""/> + </include> + from ${tableClassModel.tableName} a + <where> + <include refid="keyword_where_sql"><property name="alias" value="a"/></include> + </where> + </select> + + <!-- 查询总条数 --> + <select id="selectCountByKeyword" parameterType="long" resultType="java.lang.Integer"> + select count(a.id) + from ${tableClassModel.tableName} a + <where> + <include refid="keyword_where_sql"><property name="alias" value="a"/></include> + </where> + </select> +</mapper> \ No newline at end of file diff --git a/src/main/resources/template/excelTemplateForHis/javaBean.ftl b/src/main/resources/template/excelTemplateForHis/javaBean.ftl new file mode 100644 index 0000000..5645c0c --- /dev/null +++ b/src/main/resources/template/excelTemplateForHis/javaBean.ftl @@ -0,0 +1,49 @@ +package ${codeModel.packageName}; + +<#list importList?keys as key> +import ${importList[key]}; +</#list> +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import javax.persistence.Column; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Transient; +import com.xincheng.common.bean.EntityShoptTkDTO; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +/** + * @description ${tableClassModel.tableMemo} + * @author ${dataSource.author} + * @date ${time} + */ +@Data +@Table(name = "${tableClassModel.tableName}") +@AllArgsConstructor +@NoArgsConstructor +@Builder +@ApiModel(value="${tableClassModel.tableMemo}",description="${tableClassModel.tableMemo}") +public class ${tableClassModel.className} extends EntityShoptTkDTO{ + @Transient + private static final long serialVersionUID = 1L; + +<#list tableClassModel.mapping as being> + <#if being.column = tableClassModel.primaryKey.column && being.jdbcType = "int"> + @Id + @GeneratedValue(generator = "JDBC") + private ${being.classType} ${being.property}; + <#else> + <#if being.memo!=""> + /** + * ${being.memo} + */ + @ApiModelProperty(value="${being.memo}",name="${being.memo}",example="") + </#if> + @Column(name = "${being.column}") + private ${being.classType} ${being.property}; + </#if> +</#list> +} \ No newline at end of file diff --git a/src/main/resources/template/excelTemplateForHis/mybatis-config.ftl b/src/main/resources/template/excelTemplateForHis/mybatis-config.ftl new file mode 100644 index 0000000..8851a3b --- /dev/null +++ b/src/main/resources/template/excelTemplateForHis/mybatis-config.ftl @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> + +<configuration> + <settings> + <setting name="cacheEnabled" value="false" /> + <setting name="lazyLoadingEnabled" value="false" /> + <setting name="multipleResultSetsEnabled" value="true" /> + <setting name="useColumnLabel" value="true" /> + <setting name="useGeneratedKeys" value="false" /> + <setting name="defaultExecutorType" value="SIMPLE" /> + <setting name="defaultStatementTimeout" value="25000" /> + </settings> + + + + + <typeAliases> + + <#list alias as item> + ${item} + </#list> + + </typeAliases> + + <mappers> + + <#list mappers as item> + ${item} + </#list> + + </mappers> +</configuration> \ No newline at end of file diff --git a/src/main/resources/template/excelTemplateForHis/service.ftl b/src/main/resources/template/excelTemplateForHis/service.ftl new file mode 100644 index 0000000..dcdb692 --- /dev/null +++ b/src/main/resources/template/excelTemplateForHis/service.ftl @@ -0,0 +1,92 @@ +package ${codeModel.packageName}; + +<#list importList?keys as key> +import ${importList[key]}; +</#list> +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.matrix.core.constance.SystemErrorCode; +import com.matrix.core.constance.SystemMessageCode; +import com.matrix.core.exception.GlobleException; +import com.matrix.core.pojo.AjaxResult; +import com.matrix.core.tools.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import java.util.List; +import java.util.stream.Collectors; +/** + * @description ${tableClassModel.tableMemo} + * @author ${dataSource.author} + * @date ${time} + */ +@Service +public class ${ClassName} { + + @Autowired + private ${tableClassModel.className}Dao ${tableClassModel.classVariableName}Dao; + + /** + * 列表显示 + */ + public AjaxResult showList(${tableClassModel.className} ${tableClassModel.classVariableName}) { + if (${tableClassModel.classVariableName}.getLimit() != null && ${tableClassModel.classVariableName}.getOffset() != null&&${tableClassModel.classVariableName}.getLimit() !=0) { + PageHelper.startPage((${tableClassModel.classVariableName}.getOffset()/${tableClassModel.classVariableName}.getLimit())+1,${tableClassModel.classVariableName}.getLimit(), + ${tableClassModel.classVariableName}.getSort()+" "+${tableClassModel.classVariableName}.getOrder()); + } + List<${tableClassModel.className}> dataList = ${tableClassModel.classVariableName}Dao.select(${tableClassModel.classVariableName}); + PageInfo pageInfo = new PageInfo(dataList); + AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, pageInfo.getList(), + ${tableClassModel.classVariableName}Dao.selectCount(${tableClassModel.classVariableName})); + return result; + } + + /** + * 新增 + */ + @Transactional + public AjaxResult add(${tableClassModel.className} ${tableClassModel.classVariableName}) { + ${tableClassModel.classVariableName}Dao.insert(${tableClassModel.classVariableName}); + return AjaxResult.buildSuccessInstance("添加成功"); + } + + + /** + * 修改 + */ + @Transactional + public AjaxResult modify(${tableClassModel.className} ${tableClassModel.classVariableName}) { + ${tableClassModel.classVariableName}Dao.updateByPrimaryKeySelective(${tableClassModel.classVariableName}); + return AjaxResult.buildSuccessInstance("修改成功"); + } + + /** + * 删除 + */ + @Transactional + public AjaxResult deleteByPrimaryKey(Integer id) { + + int i = ${tableClassModel.classVariableName}Dao.deleteByPrimaryKey(id); + if (i > 0) { + return AjaxResult.buildSuccessInstance("删除成功"); + } else { + throw new GlobleException(SystemErrorCode.DATA_DELETE_FAIL); + } + } + /** + * 删除 + */ + @Transactional + public AjaxResult del(String keys) { + List<String> ids = StringUtils.strToCollToString(keys, ","); + List<Integer> ${tableClassModel.classVariableName}s = ids.stream().map(a -> + Integer.parseInt(a)).collect(Collectors.toList()); + int i = ${tableClassModel.classVariableName}Dao.deleteByIdList(${tableClassModel.classVariableName}s); + if (i > 0) { + return AjaxResult.buildSuccessInstance("删除成功"); + } else { + throw new GlobleException(SystemErrorCode.DATA_DELETE_FAIL); + } + } + +} \ No newline at end of file diff --git a/src/main/resources/template/excelTemplateForHis/sqlFile.ftl b/src/main/resources/template/excelTemplateForHis/sqlFile.ftl new file mode 100644 index 0000000..8fccb5d --- /dev/null +++ b/src/main/resources/template/excelTemplateForHis/sqlFile.ftl @@ -0,0 +1,34 @@ + +/** + * ${tableClassModel.tableMemo} + * @author ${dataSource.author} + * @date ${time} + */ + CREATE TABLE ${tableClassModel.tableName}( + create_by varchar(100) NOT NULL COMMENT '创建人', + create_time datetime NOT NULL COMMENT '创建时间', + update_by varchar(100) NOT NULL COMMENT '更新人', + update_time datetime NOT NULL COMMENT '更新时间', + create_dept_id int(11) COMMENT '创建部门', + create_store_id int(11) COMMENT '创建门店', + company_id int(11) COMMENT '创建公司', +<#list tableClassModel.mapping as being> +<#if being.column = tableClassModel.primaryKey.column && being.jdbcType = "int"> + ${being.column} ${being.fullJdbcType} ${being.isAllowNull} AUTO_INCREMENT COMMENT '${being.memo}', + <#else> + ${being.column} ${being.fullJdbcType} ${being.isAllowNull} COMMENT '${being.memo}', +</#if> +</#list> +PRIMARY KEY(${tableClassModel.primaryKey.column}) +)ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='${tableClassModel.tableMemo}'; + +<#list tableClassModel.mapping as being> +<#if (being.indexName)??> + ALTER TABLE ${tableClassModel.tableName} + ADD INDEX ${being.indexName} (${being.column}) USING BTREE ; +</#if> +</#list> + + + + -- Gitblit v1.9.1