caixin 3 years ago
commit
248ee23786

+ 46 - 0
pom.xml

@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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.yonyou.occ</groupId>
+    <artifactId>toolkit</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <packaging>jar</packaging>
+    <name>OCC TOOLKIT</name>
+    <description>OCC 代码生成工具</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.jdom</groupId>
+            <artifactId>jdom2</artifactId>
+            <version>2.0.6</version>
+        </dependency>
+        <dependency>
+            <groupId>jaxen</groupId>
+            <artifactId>jaxen</artifactId>
+            <version>1.2.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.freemarker</groupId>
+            <artifactId>freemarker</artifactId>
+            <version>2.3.31</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+            <version>3.12.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>1.7.30</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-slf4j-impl</artifactId>
+            <version>2.13.3</version>
+        </dependency>
+    </dependencies>
+</project>

+ 221 - 0
src/main/java/com/yonyou/occ/codegenerator/CodeGenerator.java

@@ -0,0 +1,221 @@
+package com.yonyou.occ.codegenerator;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+import freemarker.template.TemplateExceptionHandler;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.time.DateFormatUtils;
+import org.jdom2.Document;
+import org.jdom2.Element;
+import org.jdom2.JDOMException;
+import org.jdom2.Namespace;
+import org.jdom2.filter.Filters;
+import org.jdom2.input.SAXBuilder;
+import org.jdom2.xpath.XPathExpression;
+import org.jdom2.xpath.XPathFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 代码生成器
+ *
+ * @author wangruiv
+ * @date 2017-06-18 11:21:31
+ */
+public class CodeGenerator {
+    private static List<String> EXCLUDE_COLUMNS = null;
+
+    private final Logger log = LoggerFactory.getLogger(CodeGenerator.class);
+
+    private final String oldBasePackage;
+    private final String newBasePackage;
+    private final String pdmFile;
+    private final String tableCode;
+    private String author;
+    private String referenceType;
+    private boolean ifUseCustDocDefRef;
+    private String targetProjectRootPath;
+
+    private String moduleName;
+
+    private final String templateDir = getClass().getResource("/").getPath() + "generator/";
+
+    public CodeGenerator(String oldBasePackage, String newBasePackage, String pdmFile, String tableCode,
+            String referenceType, boolean ifUseCustDocDefRef, String author, String targetProjectRootPath) {
+        this.oldBasePackage = oldBasePackage;
+        this.newBasePackage = newBasePackage;
+        this.pdmFile = pdmFile;
+        this.tableCode = tableCode;
+        this.referenceType = referenceType;
+        this.ifUseCustDocDefRef = ifUseCustDocDefRef;
+        this.author = author;
+        this.targetProjectRootPath = targetProjectRootPath;
+
+        moduleName = getModuleNameByTable(tableCode);
+
+        final String[] array = {"ID", "DR", "TS", "CREATOR", "CREATION_TIME", "MODIFIER", "MODIFIED_TIME"};
+        EXCLUDE_COLUMNS = Arrays.asList(array);
+    }
+
+    public void run() {
+        try {
+            Table table = getTableFromPdmXml(pdmFile, tableCode, referenceType);
+
+            generateEntity(table);
+            generateRepository(table);
+            generateDto(table);
+            generateMapper(table);
+            generateService(table);
+            generateController(table);
+            if (StringUtils.isNotEmpty(referenceType)) {
+                generateRefController(table);
+            }
+            if (ifUseCustDocDefRef) {
+                generateMapperDecorator(table);
+            }
+        } catch (JDOMException e) {
+            log.error("解析XML文件时发生错误", e);
+        } catch (IOException e) {
+            log.error("读取XML文件时发生错误", e);
+        } catch (TemplateException e) {
+            log.error("解析模板文件时发生错误", e);
+        }
+    }
+
+    private String getModuleNameByTable(String tableCode) {
+        return tableCode.split("_")[0].toLowerCase();
+    }
+
+    private Table getTableFromPdmXml(String pdmFile, String tableCode, String referenceType)
+            throws JDOMException, IOException {
+        // read the XML into a JDOM2 document.
+        SAXBuilder jdomBuilder = new SAXBuilder();
+        Document jdomDocument = jdomBuilder.build(pdmFile);
+
+        // use the default implementation
+        XPathFactory xFactory = XPathFactory.instance();
+
+        // namespaces
+        Namespace nsAttribute = jdomDocument.getRootElement().getNamespace("a");
+        Namespace nsCollection = jdomDocument.getRootElement().getNamespace("c");
+        Namespace nsObject = jdomDocument.getRootElement().getNamespace("o");
+
+        XPathExpression<Element> expr = xFactory.compile("//a:Code[text()='" + tableCode + "']", Filters.element(),
+                null, nsAttribute);
+        Element tableElement = expr.evaluateFirst(jdomDocument).getParentElement();
+        String tableName = tableElement.getChild("Name", nsAttribute).getText();
+        String tableComment;
+        Element tableCommentElement = tableElement.getChild("Comment", nsAttribute);
+        if (tableCommentElement == null || StringUtils.isBlank(tableComment = tableCommentElement.getText())) {
+            tableComment = tableName;
+        }
+        Table table = new Table(tableName, tableCode, tableComment, referenceType);
+
+        List<Element> columnElements = tableElement.getChild("Columns", nsCollection).getChildren();
+        for (Element columnElement : columnElements) {
+            String code = columnElement.getChild("Code", nsAttribute).getText();
+            if (EXCLUDE_COLUMNS.contains(code.toUpperCase())) {
+                continue;
+            }
+            String name = columnElement.getChild("Name", nsAttribute).getText();
+            String comment;
+            Element commentElement = columnElement.getChild("Comment", nsAttribute);
+            if (commentElement == null || StringUtils.isBlank(comment = commentElement.getText())) {
+                comment = name;
+            }
+            String dataType = columnElement.getChild("DataType", nsAttribute).getText();
+            Integer length = null;
+            Element lengthElement = columnElement.getChild("Length", nsAttribute);
+            if (lengthElement != null) {
+                length = Integer.parseInt(lengthElement.getText());
+            }
+            Integer precision = null;
+            Element precisionElement = columnElement.getChild("Precision", nsAttribute);
+            if (precisionElement != null) {
+                precision = Integer.parseInt(precisionElement.getText());
+            }
+            Table.Column column = table.new Column(name, code, comment, dataType, length, precision);
+            table.getColumns().add(column);
+        }
+
+        return table;
+    }
+
+    private void generate(Table table, String templateName, String targetSubPath)
+            throws IOException, TemplateException {
+        Configuration cfg = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
+        cfg.setDirectoryForTemplateLoading(new File(templateDir));
+        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.IGNORE_HANDLER);
+        Template template = cfg.getTemplate(templateName + ".ftl", "UTF-8");
+
+        // 定义模板数据
+        Map<String, Object> data = new HashMap<String, Object>();
+        data.put("oldBasePackage", oldBasePackage);
+        data.put("newBasePackage", newBasePackage);
+        data.put("moduleName", moduleName);
+        data.put("date", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
+        data.put("ifUseCustDocDefRef", ifUseCustDocDefRef);
+        data.put("author", author);
+        data.put("table", table);
+
+        // 输出文件
+        String fileName = table.getClassName();
+        if (!templateName.equalsIgnoreCase("entity")) {
+            fileName += templateName.substring(0, 1).toUpperCase() + templateName.substring(1);
+        }
+        final String outFolderPath = targetProjectRootPath + "src/main/java/" + newBasePackage.replace(".", "/") + "/" +
+                moduleName + targetSubPath;
+        File outFolder = new File(outFolderPath);
+        if (!outFolder.exists()) {
+            outFolder.mkdirs();
+        }
+        final String outFilePath = outFolderPath + fileName + ".java";
+        Writer outFile = new FileWriter(outFilePath);
+        template.process(data, outFile);
+
+        System.out.println(templateName + "文件生成成功:" + outFilePath);
+    }
+
+    private void generateEntity(Table table) throws IOException, TemplateException {
+        generate(table, "entity", "/entity/");
+    }
+
+    private void generateRepository(Table table) throws IOException, TemplateException {
+        generate(table, "repository", "/repository/");
+    }
+
+    private void generateDto(Table table) throws IOException, TemplateException {
+        generate(table, "dto", "/service/dto/");
+    }
+
+    private void generateMapper(Table table) throws IOException, TemplateException {
+        generate(table, "mapper", "/service/mapper/");
+    }
+
+    private void generateService(Table table) throws IOException, TemplateException {
+        generate(table, "service", "/service/");
+    }
+
+    private void generateController(Table table) throws IOException, TemplateException {
+        generate(table, "controller", "/web/");
+    }
+
+    private void generateRefController(Table table) throws IOException, TemplateException {
+        generate(table, "refController", "/web/");
+    }
+
+    private void generateMapperDecorator(Table table) throws IOException, TemplateException {
+        generate(table, "mapperDecorator", "/service/mapper/");
+    }
+}

+ 73 - 0
src/main/java/com/yonyou/occ/codegenerator/CodeGeneratorEntry.java

@@ -0,0 +1,73 @@
+package com.yonyou.occ.codegenerator;
+
+import org.apache.commons.lang3.StringUtils;
+
+/**
+ * 代码生成器入口
+ *
+ * @author wangruiv
+ * @date 2017-06-18 11:21:31
+ */
+public class CodeGeneratorEntry {
+    /**
+     * 原顶级包路径
+     */
+    private static final String OLD_BASE_PACKAGE = "com.yonyou.ocm";
+
+    /**
+     * 新的顶级包路径
+     */
+    private static final String NEW_BASE_PACKAGE = "com.yonyou.occ";
+
+    /**
+     * PDM文件路径
+     */
+    private static final String PDM_FILE = "D:\\work\\用友\\project\\科顺\\sql\\PhysicalDataModel_3.pdm";
+
+
+    /**
+     * 物理表名称(英文逗号分隔)
+     */
+    private static final String TABLE_CODES = "CKS_CUST_OBJECTIVE,CKS_CUST_OBJ_ITEM";
+
+    /**
+     * 参照类型
+     */
+    private static final String REFERENCE_TYPE = ""; // [空字符串], Grid, Tree, TreeGrid
+
+    /**
+     * 是否使用了自定义档案参照
+     */
+    private static final boolean IF_USE_CUST_DOC_DEF_REF = false;
+
+    /**
+     * 作者
+     */
+    private static final String AUTHOR = "yonyou";
+
+    /**
+     * 目标项目根路径
+     */
+    private static final String TARGET_PROJECT_ROOT_PATH = "E:\\Yonyou\\project\\OTHER\\occ-toolkit\\code\\";
+
+
+    /**
+     * dzz 代码生成
+     * @param args
+     */
+    public static void main(String[] args) {
+        String pdmFile = "E:\\Yonyou\\project\\OCC\\PDM\\demo.pdm";
+        String tableCodes = "DEMO_PERSON_INFO";
+
+
+        for (String tableCode : tableCodes.split(",")) {
+            if (StringUtils.isEmpty(tableCode)) {
+                continue;
+            }
+            tableCode = tableCode.trim();
+            CodeGenerator codeGenerator = new CodeGenerator(OLD_BASE_PACKAGE, NEW_BASE_PACKAGE, pdmFile, tableCode,
+                    REFERENCE_TYPE, IF_USE_CUST_DOC_DEF_REF, AUTHOR, TARGET_PROJECT_ROOT_PATH);
+            codeGenerator.run();
+        }
+    }
+}

+ 104 - 0
src/main/java/com/yonyou/occ/codegenerator/GeneratorHelper.java

@@ -0,0 +1,104 @@
+package com.yonyou.occ.codegenerator;
+
+/**
+ * 代码生成器帮助类。
+ *
+ * @author wangruiv
+ * @date 2017-06-18 16:56:34
+ */
+public class GeneratorHelper {
+	/**
+	 * 通过数据库表名获取类名。
+	 *
+	 * @param tableCode 数据库表名。
+	 * @return 类名。
+	 */
+	public static String getClassName(String tableCode) {
+		String className = "";
+		String[] parts = tableCode.split("_");
+		for (int i = 1; i < parts.length; ++i) {
+			String part = parts[i];
+			part = part.substring(0, 1).toUpperCase() + part.substring(1).toLowerCase();
+			className += part;
+		}
+		return className;
+	}
+
+	/**
+	 * 通过数据库表名获取请求路径。
+	 *
+	 * @param tableCode 数据库表名。
+	 * @return 类名。
+	 */
+	public static String getRequestMapping(String tableCode) {
+		String className = "";
+		String[] parts = tableCode.split("_");
+		for (int i = 1; i < parts.length; ++i) {
+			String part = parts[i];
+			part = part.toLowerCase();
+			className += "-" + part;
+		}
+		return parts[0].toLowerCase() + "/" + className.substring(1);
+	}
+
+	/**
+	 * 通过数据库列名获取字段名。
+	 *
+	 * @param columnCode 数据库列名。
+	 * @return 字段名。
+	 */
+	public static String getFieldName(String columnCode) {
+		String fieldName = "";
+		String[] parts = columnCode.split("_");
+		for (int i = 0; i < parts.length; ++i) {
+			String part = parts[i];
+			if (i == 0) {
+				part = part.toLowerCase();
+			}
+			else {
+				part = part.substring(0, 1).toUpperCase() + part.substring(1).toLowerCase();
+			}
+			fieldName += part;
+		}
+		return fieldName;
+	}
+
+	/**
+	 * 通过数据库列名获取属性名。
+	 *
+	 * @param columnCode 数据库列名。
+	 * @return 字段名。
+	 */
+	public static String getPropertyName(String columnCode) {
+		String className = "";
+		String[] parts = columnCode.split("_");
+		for (int i = 0; i < parts.length; ++i) {
+			String part = parts[i];
+			part = part.substring(0, 1).toUpperCase() + part.substring(1).toLowerCase();
+			className += part;
+		}
+		return className;
+	}
+
+	public static String getFieldType(String typeInDb) {
+		typeInDb = typeInDb.toUpperCase();
+
+//		if (typeInDb.equals("NUMBER(1)")) {
+//			return "Boolean";
+//		}
+
+		if (typeInDb.matches("NUMBER\\(\\s*\\d+\\s*\\)")) {
+			return "Integer";
+		}
+
+		if (typeInDb.matches("NUMBER\\(\\s*\\d+\\s*,\\s*\\d+\\s*\\)")) {
+			return "BigDecimal";
+		}
+
+		if (typeInDb.equals("DATE")) {
+			return "Date";
+		}
+
+		return "String";
+	}
+}

+ 158 - 0
src/main/java/com/yonyou/occ/codegenerator/Table.java

@@ -0,0 +1,158 @@
+package com.yonyou.occ.codegenerator;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Table {
+	private final String name;
+
+	private final String code;
+
+	private final String comment;
+
+	private final String className;
+
+	private final String requestMapping;
+
+	private final String referenceType;
+
+	private List<Column> columns = new ArrayList<Column>();
+
+	public Table(String name, String code, String comment, String referenceType) {
+		this.name = name;
+		this.code = code;
+		this.comment = comment;
+
+		className = GeneratorHelper.getClassName(code);
+		requestMapping = GeneratorHelper.getRequestMapping(code);
+		this.referenceType = referenceType;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public String getCode() {
+		return code;
+	}
+
+	public String getComment() {
+		return comment;
+	}
+
+	public String getClassName() {
+		return className;
+	}
+
+	public String getRequestMapping() {
+		return requestMapping;
+	}
+
+	public String getReferenceType() {
+		return referenceType;
+	}
+
+	public List<Column> getColumns() {
+		return columns;
+	}
+
+	public void setColumns(List<Column> columns) {
+		this.columns = columns;
+	}
+
+	public class Column {
+		/**
+		 * 名称
+		 */
+		private final String name;
+
+		/**
+		 * 编码
+		 */
+		private final String code;
+
+		/**
+		 * 注释
+		 */
+		private final String comment;
+
+		/**
+		 * 数据类型
+		 */
+		private final String dataType;
+
+		/**
+		 * 长度
+		 */
+		private final Integer length;
+
+		/**
+		 * 精度
+		 */
+		private final Integer precision;
+
+		/**
+		 * 字段名
+		 */
+		private final String fieldName;
+
+		/**
+		 * 属性名
+		 */
+		private final String propertyName;
+
+		/**
+		 * 字段类型
+		 */
+		private final String fieldType;
+
+		public Column(String name, String code, String comment, String dataType, Integer length, Integer precision) {
+			this.name = name;
+			this.code = code;
+			this.comment = comment;
+			this.dataType = dataType;
+			this.length = length;
+			this.precision = precision;
+
+			fieldName = GeneratorHelper.getFieldName(code);
+			propertyName = GeneratorHelper.getPropertyName(code);
+			fieldType = GeneratorHelper.getFieldType(dataType);
+		}
+
+		public String getName() {
+			return name;
+		}
+
+		public String getCode() {
+			return code;
+		}
+
+		public String getComment() {
+			return comment;
+		}
+
+		public String getDataType() {
+			return dataType;
+		}
+
+		public Integer getLength() {
+			return length;
+		}
+
+		public Integer getPrecision() {
+			return precision;
+		}
+
+		public String getFieldName() {
+			return fieldName;
+		}
+
+		public String getPropertyName() {
+			return propertyName;
+		}
+
+		public String getFieldType() {
+			return fieldType;
+		}
+	}
+}

+ 38 - 0
src/main/resources/generator/controller.ftl

@@ -0,0 +1,38 @@
+package ${newBasePackage}.${moduleName}.web;
+
+import javax.annotation.Generated;
+
+import ${newBasePackage}.${moduleName}.service.${table.className}Service;
+import ${newBasePackage}.${moduleName}.service.dto.${table.className}Dto;
+import ${oldBasePackage}.common.web.AbstractController;
+import io.swagger.annotations.Api;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * ${table.comment}的控制器
+ *
+ * @author ${author}
+ * @date ${date}
+ */
+@Api(value = "${table.comment}Controller", tags = { "${table.comment}访问接口" })
+@RestController
+@RequestMapping(value = "/${table.requestMapping}s")
+@Generated(value = "${oldBasePackage}.util.codegenerator.CodeGenerator")
+public class ${table.className}Controller extends AbstractController<${table.className}Dto, ${table.className}Service> {
+
+    @ApiOperation(value = "查询示例接口", notes = "本接口只做展示,方便对照getAll接口的请求参数规则,无实际功能")
+    @ApiImplicitParams({
+    @ApiImplicitParam(name = "offset", value = "分页-偏移页数", required = true, paramType = "form"),
+    @ApiImplicitParam(name = "pageNumber", value = "分页-当前页数", required = true, paramType = "form"),
+    @ApiImplicitParam(name = "pageSize", value = "分页-没页查询总数", required = true, paramType = "form"),
+    @ApiImplicitParam(name = "sort", value = "分页-排序方式(按字段)", required = false, paramType = "form"),
+    @ApiImplicitParam(name = "search_id", value = "实体-主键id", required = false, paramType = "form"),
+    @ApiImplicitParam(name = "search_name", value = "实体-名称", required = false, paramType = "form")
+    })
+    @GetMapping("/getAllTemplate")
+    public List<${table.className}Dto> getAllTemplate(@RequestParam Integer offset, @RequestParam Integer pageNumber, @RequestParam Integer pageSize, @RequestParam String sort,
+     @RequestParam Integer id, @RequestParam String search_name) {
+       return null;
+     }
+}

+ 48 - 0
src/main/resources/generator/dto.ftl

@@ -0,0 +1,48 @@
+package ${newBasePackage}.${moduleName}.service.dto;
+
+import java.math.BigDecimal;
+import java.util.Date;
+import javax.annotation.Generated;
+import javax.validation.constraints.Size;
+
+import ${oldBasePackage}.common.service.dto.BaseDto;
+import ${oldBasePackage}.common.annos.Display;
+<#if (table.referenceType != "")>
+import ${oldBasePackage}.common.entity.ReferenceFields;
+</#if>
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+
+/**
+ * ${table.comment}的数据传输对象类
+ *
+ * @author ${author}
+ * @date ${date}
+ */
+@ApiModel(description = "${table.comment}的数据传输对象类")
+@Getter
+@Setter
+@ToString
+<#if (table.referenceType != "")>
+@ReferenceFields(nameField = "name", codeField = "code"<#if (table.referenceType == "Tree")>, parentIdField="parentId"</#if>)
+</#if>
+@Generated(value = "${oldBasePackage}.util.codegenerator.CodeGenerator")
+public class ${table.className}Dto extends BaseDto {
+    <#list table.columns as column>
+    <#if (column_index != 0)>
+
+    </#if>
+    /**
+     * ${column.comment}
+     */
+    @ApiModelProperty(value = "${column.comment}", position = ${column_index})
+    @Display("${column.comment}")
+    <#if (column.fieldType == "String")>
+    @Size(max = ${column.length})
+    </#if>
+    private ${column.fieldType} ${column.fieldName};
+    </#list>
+}

+ 51 - 0
src/main/resources/generator/entity.ftl

@@ -0,0 +1,51 @@
+package ${newBasePackage}.${moduleName}.entity;
+
+import java.math.BigDecimal;
+import java.util.Date;
+import javax.annotation.Generated;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+import javax.validation.constraints.Size;
+
+import ${oldBasePackage}.common.entity.BaseEntity;
+<#if (table.referenceType != "")>
+import ${oldBasePackage}.common.entity.ReferenceFields;
+</#if>
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+
+/**
+ * ${table.comment}的实体类
+ *
+ * @author ${author}
+ * @date ${date}
+ */
+@Getter
+@Setter
+@ToString
+@Entity
+@Table(name = "${table.code}")
+@Inheritance(strategy = InheritanceType.JOINED)
+<#if (table.referenceType != "")>
+@ReferenceFields(nameField = "name", codeField = "code"<#if (table.referenceType == "Tree")>, parentIdField="parent.id"</#if>)
+</#if>
+@Generated(value = "${oldBasePackage}.util.codegenerator.CodeGenerator")
+public class ${table.className} extends BaseEntity {
+    <#list table.columns as column>
+    <#if (column_index != 0)>
+
+    </#if>
+    /**
+     * ${column.comment}
+     */
+    <#if (column.fieldType == "String")>
+    @Size(max = ${column.length})
+    </#if>
+    @Column(name = "${column.code}"<#if (column.fieldType == "String")>, length = ${column.length}</#if><#if (column.fieldType == "BigDecimal")>, scale = ${column.length}, precision = ${column.precision}</#if>)
+    private ${column.fieldType} ${column.fieldName};
+    </#list>
+}

+ 25 - 0
src/main/resources/generator/mapper.ftl

@@ -0,0 +1,25 @@
+package ${newBasePackage}.${moduleName}.service.mapper;
+
+import javax.annotation.Generated;
+
+import ${newBasePackage}.${moduleName}.entity.${table.className};
+import ${newBasePackage}.${moduleName}.service.dto.${table.className}Dto;
+import ${oldBasePackage}.common.service.mapper.BaseMapper;
+<#if (ifUseCustDocDefRef == true)>
+import org.mapstruct.DecoratedWith;
+</#if>
+import org.mapstruct.Mapper;
+
+/**
+ * ${table.comment}的映射抽象类
+ *
+ * @author ${author}
+ * @date ${date}
+ */
+<#if (ifUseCustDocDefRef == true)>
+@DecoratedWith(${table.className}MapperDecorator.class)
+</#if>
+@Mapper(componentModel = "spring")
+@Generated(value = "${oldBasePackage}.util.codegenerator.CodeGenerator")
+public abstract class ${table.className}Mapper extends BaseMapper<${table.className}, ${table.className}Dto> {
+}

+ 46 - 0
src/main/resources/generator/mapperDecorator.ftl

@@ -0,0 +1,46 @@
+package ${newBasePackage}.${moduleName}.service.mapper;
+
+import java.util.List;
+import javax.annotation.Generated;
+
+import ${oldBasePackage}.base.api.CustDocDefApi;
+import ${oldBasePackage}.common.mapper.MapperDecoratorHelper;
+import ${newBasePackage}.${moduleName}.entity.${table.className};
+import ${newBasePackage}.${moduleName}.service.dto.${table.className}Dto;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+
+/**
+ * ${table.comment}映射的装饰器
+ *
+ * @author ${author}
+ * @date ${date}
+ */
+@Generated(value = "${oldBasePackage}.util.codegenerator.CodeGenerator")
+public abstract class ${table.className}MapperDecorator extends ${table.className}Mapper {
+    @Autowired
+    @Qualifier("delegate")
+    protected ${table.className}Mapper delegate;
+
+    @Autowired
+    private CustDocDefApi custDocDefApi;
+
+    private MapperDecoratorHelper<${table.className}, ${table.className}Dto, ${table.className}Mapper> helper = null;
+
+    private MapperDecoratorHelper<${table.className}, ${table.className}Dto, ${table.className}Mapper> getHelper() {
+        if (helper == null) {
+            helper = new MapperDecoratorHelper<>(${table.className}.class, ${table.className}Dto.class, delegate, custDocDefApi);
+        }
+        return helper;
+    }
+
+    @Override
+    public ${table.className}Dto entityToDto(${table.className} entity) {
+        return getHelper().entityToDto(entity);
+    }
+
+    @Override
+    public List<${table.className}Dto> entitiesToDtos(List<${table.className}> entities) {
+        return getHelper().entitiesToDtos(entities);
+    }
+}

+ 24 - 0
src/main/resources/generator/refController.ftl

@@ -0,0 +1,24 @@
+package ${newBasePackage}.${moduleName}.web;
+
+import javax.annotation.Generated;
+
+import ${oldBasePackage}.common.web.Abstract${table.referenceType}RefController;
+import ${newBasePackage}.${moduleName}.entity.${table.className};
+import ${newBasePackage}.${moduleName}.service.${table.className}Service;
+import ${newBasePackage}.${moduleName}.service.dto.${table.className}Dto;
+import io.swagger.annotations.Api;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * ${table.comment}的参照控制器
+ *
+ * @author ${author}
+ * @date ${date}
+ */
+@Api(value = "${table.comment}参照Controller", tags = { "${table.comment}参照控制器访问接口" })
+@RestController
+@RequestMapping(value = "/${table.requestMapping}-ref")
+@Generated(value = "${oldBasePackage}.util.codegenerator.CodeGenerator")
+public class ${table.className}RefController extends Abstract${table.referenceType}RefController<${table.className}, ${table.className}Dto, ${table.className}Service> {
+}

+ 18 - 0
src/main/resources/generator/repository.ftl

@@ -0,0 +1,18 @@
+package ${newBasePackage}.${moduleName}.repository;
+
+import javax.annotation.Generated;
+
+import ${newBasePackage}.${moduleName}.entity.${table.className};
+import ${oldBasePackage}.common.repository.BaseRepository;
+import org.springframework.stereotype.Repository;
+
+/**
+ * ${table.comment}的仓储接口
+ *
+ * @author ${author}
+ * @date ${date}
+ */
+@Repository
+@Generated(value = "${oldBasePackage}.util.codegenerator.CodeGenerator")
+public interface ${table.className}Repository extends BaseRepository<${table.className}> {
+}

+ 21 - 0
src/main/resources/generator/service.ftl

@@ -0,0 +1,21 @@
+package ${newBasePackage}.${moduleName}.service;
+
+import javax.annotation.Generated;
+
+import ${newBasePackage}.${moduleName}.entity.${table.className};
+import ${newBasePackage}.${moduleName}.repository.${table.className}Repository;
+import ${newBasePackage}.${moduleName}.service.dto.${table.className}Dto;
+import ${newBasePackage}.${moduleName}.service.mapper.${table.className}Mapper;
+import ${oldBasePackage}.common.service.BaseService;
+import org.springframework.stereotype.Service;
+
+/**
+ * ${table.comment}的服务类
+ *
+ * @author ${author}
+ * @date ${date}
+ */
+@Service
+@Generated(value = "${oldBasePackage}.util.codegenerator.CodeGenerator")
+public class ${table.className}Service extends BaseService<${table.className}, ${table.className}Dto, ${table.className}Repository, ${table.className}Mapper> {
+}