ソースを参照

no commit message

wms仓库管理系统 5 年 前
コミット
8c500cf2cd
28 ファイル変更2438 行追加0 行削除
  1. 86 0
      wms-generator/pom.xml
  2. 73 0
      wms-generator/src/main/java/com/deer/wms/generator/config/GenConfig.java
  3. 90 0
      wms-generator/src/main/java/com/deer/wms/generator/controller/GenController.java
  4. 37 0
      wms-generator/src/main/java/com/deer/wms/generator/dao/GenMapper.java
  5. 72 0
      wms-generator/src/main/java/com/deer/wms/generator/domain/ColumnConfigInfo.java
  6. 125 0
      wms-generator/src/main/java/com/deer/wms/generator/domain/ColumnInfo.java
  7. 103 0
      wms-generator/src/main/java/com/deer/wms/generator/domain/TableInfo.java
  8. 36 0
      wms-generator/src/main/java/com/deer/wms/generator/service/IGenService.java
  9. 141 0
      wms-generator/src/main/java/com/deer/wms/generator/service/impl/GenServiceImpl.java
  10. 242 0
      wms-generator/src/main/java/com/deer/wms/generator/util/GenUtils.java
  11. 36 0
      wms-generator/src/main/java/com/deer/wms/generator/util/VelocityInitializer.java
  12. 40 0
      wms-generator/src/main/java/com/deer/wms/generator2/DeerGenerator.java
  13. 249 0
      wms-generator/src/main/java/com/deer/wms/generator2/Generator.java
  14. 136 0
      wms-generator/src/main/java/com/deer/wms/generator2/configurer/DatasourceConfigurer.java
  15. 58 0
      wms-generator/src/main/java/com/deer/wms/generator2/configurer/Table.java
  16. 11 0
      wms-generator/src/main/resources/generator.yml
  17. 52 0
      wms-generator/src/main/resources/mapper/generator/GenMapper.xml
  18. 123 0
      wms-generator/src/main/resources/templates/tool/gen/gen.html
  19. 61 0
      wms-generator/src/main/resources/vm/html/add.html.vm
  20. 62 0
      wms-generator/src/main/resources/vm/html/edit.html.vm
  21. 133 0
      wms-generator/src/main/resources/vm/html/list.html.vm
  22. 126 0
      wms-generator/src/main/resources/vm/java/Controller.java.vm
  23. 62 0
      wms-generator/src/main/resources/vm/java/Mapper.java.vm
  24. 54 0
      wms-generator/src/main/resources/vm/java/Service.java.vm
  25. 83 0
      wms-generator/src/main/resources/vm/java/ServiceImpl.java.vm
  26. 56 0
      wms-generator/src/main/resources/vm/java/domain.java.vm
  27. 19 0
      wms-generator/src/main/resources/vm/sql/sql.vm
  28. 72 0
      wms-generator/src/main/resources/vm/xml/Mapper.xml.vm

+ 86 - 0
wms-generator/pom.xml

@@ -0,0 +1,86 @@
+<?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">
+    <parent>
+        <artifactId>wms-parent</artifactId>
+        <groupId>com.deer</groupId>
+        <version>3.3</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>wms-generator</artifactId>
+	
+	<description>
+	    generator代码生成
+	</description>
+	
+    <dependencies>
+    
+    	<!--Shiro核心框架 -->
+       <dependency>
+            <groupId>org.apache.shiro</groupId>
+            <artifactId>shiro-core</artifactId>
+       </dependency>
+    
+        <!--velocity代码生成使用模板 -->
+        <dependency>
+            <groupId>org.apache.velocity</groupId>
+            <artifactId>velocity</artifactId>
+        </dependency>
+		
+        <!-- 通用工具-->
+        <dependency>
+            <groupId>com.deer</groupId>
+            <artifactId>wms-common</artifactId>
+            <version>3.3</version>
+            <scope>compile</scope>
+        </dependency>
+
+
+
+        <dependency>
+            <groupId>com.squareup.okhttp</groupId>
+            <artifactId>okhttp</artifactId>
+            <version>2.7.5</version>
+        </dependency>
+
+        <!--代码生成器依赖-->
+        <dependency>
+            <groupId>org.freemarker</groupId>
+            <artifactId>freemarker</artifactId>
+            <version>2.3.23</version>
+            <!--<scope>test</scope>-->
+        </dependency>
+        <dependency>
+            <groupId>org.mybatis.generator</groupId>
+            <artifactId>mybatis-generator-core</artifactId>
+            <version>1.3.5</version>
+            <!--<scope>test</scope>-->
+        </dependency>
+        <dependency>
+            <groupId>javax.mail</groupId>
+            <artifactId>mail</artifactId>
+            <version>1.5.0-b01</version>
+        </dependency>
+
+
+        <!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+            <version>28.0-jre</version>
+        </dependency>
+
+
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <version>5.1.25</version>
+        </dependency>
+
+
+
+    </dependencies>
+	
+</project>

+ 73 - 0
wms-generator/src/main/java/com/deer/wms/generator/config/GenConfig.java

@@ -0,0 +1,73 @@
+package com.deer.wms.generator.config;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.stereotype.Component;
+
+/**
+ * 读取代码生成相关配置
+ * 
+ * @author deer
+ */
+@Component
+@ConfigurationProperties(prefix = "gen")
+@PropertySource(value = { "classpath:generator.yml" })
+public class GenConfig
+{
+    /** 作者 */
+    public static String author;
+
+    /** 生成包路径 */
+    public static String packageName;
+
+    /** 自动去除表前缀,默认是true */
+    public static String autoRemovePre;
+
+    /** 表前缀(类名不会包含表前缀) */
+    public static String tablePrefix;
+
+    public static String getAuthor()
+    {
+        return author;
+    }
+
+    @Value("${author}")
+    public void setAuthor(String author)
+    {
+        GenConfig.author = author;
+    }
+
+    public static String getPackageName()
+    {
+        return packageName;
+    }
+
+    @Value("${packageName}")
+    public void setPackageName(String packageName)
+    {
+        GenConfig.packageName = packageName;
+    }
+
+    public static String getAutoRemovePre()
+    {
+        return autoRemovePre;
+    }
+
+    @Value("${autoRemovePre}")
+    public void setAutoRemovePre(String autoRemovePre)
+    {
+        GenConfig.autoRemovePre = autoRemovePre;
+    }
+
+    public static String getTablePrefix()
+    {
+        return tablePrefix;
+    }
+
+    @Value("${tablePrefix}")
+    public void setTablePrefix(String tablePrefix)
+    {
+        GenConfig.tablePrefix = tablePrefix;
+    }
+}

+ 90 - 0
wms-generator/src/main/java/com/deer/wms/generator/controller/GenController.java

@@ -0,0 +1,90 @@
+package com.deer.wms.generator.controller;
+
+import java.io.IOException;
+import java.util.List;
+import javax.servlet.http.HttpServletResponse;
+
+import com.deer.wms.generator.domain.TableInfo;
+import org.apache.commons.io.IOUtils;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+import com.deer.wms.common.annotation.Log;
+import com.deer.wms.common.core.controller.BaseController;
+import com.deer.wms.common.core.page.TableDataInfo;
+import com.deer.wms.common.core.text.Convert;
+import com.deer.wms.common.enums.BusinessType;
+import com.deer.wms.generator.service.IGenService;
+
+/**
+ * 代码生成 操作处理
+ * 
+ * @author deer
+ */
+@Controller
+@RequestMapping("/tool/gen")
+public class GenController extends BaseController
+{
+    private String prefix = "tool/gen";
+
+    @Autowired
+    private IGenService genService;
+
+    @RequiresPermissions("tool:gen:view")
+    @GetMapping()
+    public String gen()
+    {
+        return prefix + "/gen";
+    }
+
+    @RequiresPermissions("tool:gen:list")
+    @PostMapping("/list")
+    @ResponseBody
+    public TableDataInfo list(TableInfo tableInfo)
+    {
+        startPage();
+        List<TableInfo> list = genService.selectTableList(tableInfo);
+        return getDataTable(list);
+    }
+
+    /**
+     * 生成代码
+     */
+    @RequiresPermissions("tool:gen:code")
+    @Log(title = "代码生成", businessType = BusinessType.GENCODE)
+    @GetMapping("/genCode/{tableName}")
+    public void genCode(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException
+    {
+        byte[] data = genService.generatorCode(tableName);
+        response.reset();
+        response.setHeader("Content-Disposition", "attachment; filename=\"deer.zip\"");
+        response.addHeader("Content-Length", "" + data.length);
+        response.setContentType("application/octet-stream; charset=UTF-8");
+
+        IOUtils.write(data, response.getOutputStream());
+    }
+
+    /**
+     * 批量生成代码
+     */
+    @RequiresPermissions("tool:gen:code")
+    @Log(title = "代码生成", businessType = BusinessType.GENCODE)
+    @GetMapping("/batchGenCode")
+    @ResponseBody
+    public void batchGenCode(HttpServletResponse response, String tables) throws IOException
+    {
+        String[] tableNames = Convert.toStrArray(tables);
+        byte[] data = genService.generatorCode(tableNames);
+        response.reset();
+        response.setHeader("Content-Disposition", "attachment; filename=\"deer.zip\"");
+        response.addHeader("Content-Length", "" + data.length);
+        response.setContentType("application/octet-stream; charset=UTF-8");
+
+        IOUtils.write(data, response.getOutputStream());
+    }
+}

+ 37 - 0
wms-generator/src/main/java/com/deer/wms/generator/dao/GenMapper.java

@@ -0,0 +1,37 @@
+package com.deer.wms.generator.dao;
+
+import java.util.List;
+import com.deer.wms.generator.domain.ColumnInfo;
+import com.deer.wms.generator.domain.TableInfo;
+
+/**
+ * 代码生成 数据层
+ * 
+ * @author deer
+ */
+public interface GenMapper
+{
+    /**
+     * 查询ry数据库表信息
+     * 
+     * @param tableInfo 表信息
+     * @return 数据库表列表
+     */
+    public List<TableInfo> selectTableList(TableInfo tableInfo);
+
+    /**
+     * 根据表名称查询信息
+     * 
+     * @param tableName 表名称
+     * @return 表信息
+     */
+    public TableInfo selectTableByName(String tableName);
+
+    /**
+     * 根据表名称查询列信息
+     * 
+     * @param tableName 表名称
+     * @return 列信息
+     */
+    public List<ColumnInfo> selectTableColumnsByName(String tableName);
+}

+ 72 - 0
wms-generator/src/main/java/com/deer/wms/generator/domain/ColumnConfigInfo.java

@@ -0,0 +1,72 @@
+package com.deer.wms.generator.domain;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+/**
+ * 字段类型配置 由数据库字段的注释解析而来
+ * 注释结构示例:{"title": "状态", "type": "dict", "value": "sys_common_status"} {"title": "登录时间", "type": "date"}
+ * 
+ * @author deer
+ *
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ColumnConfigInfo
+{
+    /**
+     * 属性标题
+     */
+    private String title;
+
+    /**
+     * 属性类型 dict(字典,value对应字典管理的字典类型), date(包括date)
+     */
+    private String type;
+
+    /**
+     * 属性值,参考数据类型,可为空
+     */
+    private String value;
+
+    public ColumnConfigInfo()
+    {
+        super();
+    }
+
+    public ColumnConfigInfo(String title, String type, String value)
+    {
+        super();
+        this.title = title;
+        this.type = type;
+        this.value = value;
+    }
+
+    public String getTitle()
+    {
+        return title;
+    }
+
+    public void setTitle(String title)
+    {
+        this.title = title;
+    }
+
+    public String getType()
+    {
+        return type;
+    }
+
+    public void setType(String type)
+    {
+        this.type = type;
+    }
+
+    public String getValue()
+    {
+        return value;
+    }
+
+    public void setValue(String value)
+    {
+        this.value = value;
+    }
+}

+ 125 - 0
wms-generator/src/main/java/com/deer/wms/generator/domain/ColumnInfo.java

@@ -0,0 +1,125 @@
+package com.deer.wms.generator.domain;
+
+import com.deer.wms.common.json.JSON;
+import com.deer.wms.common.utils.StringUtils;
+
+/**
+ * ry数据库表列信息
+ * 
+ * @author deer
+ */
+public class ColumnInfo
+{
+    /** 字段名称 */
+    private String columnName;
+
+    /** 字段类型 */
+    private String dataType;
+
+    /** 列描述 */
+    private String columnComment;
+
+    /** 列配置 */
+    private ColumnConfigInfo configInfo;
+
+    /** Java属性类型 */
+    private String attrType;
+
+    /** Java属性名称(第一个字母大写),如:user_name => UserName */
+    private String attrName;
+
+    /** Java属性名称(第一个字母小写),如:user_name => userName */
+    private String attrname;
+
+    /** 执行计划(包含了与索引相关的一些细节信息) */
+    private String extra;
+
+    public String getColumnName()
+    {
+        return columnName;
+    }
+
+    public void setColumnName(String columnName)
+    {
+        this.columnName = columnName;
+    }
+
+    public String getDataType()
+    {
+        return dataType;
+    }
+
+    public void setDataType(String dataType)
+    {
+        this.dataType = dataType;
+    }
+
+    public String getColumnComment()
+    {
+        return columnComment;
+    }
+
+    public void setColumnComment(String columnComment) throws Exception
+    {
+        // 根据列描述解析列的配置信息
+        if (StringUtils.isNotEmpty(columnComment) && columnComment.startsWith("{"))
+        {
+            this.configInfo = JSON.unmarshal(columnComment, ColumnConfigInfo.class);
+            this.columnComment = configInfo.getTitle();
+        }
+        else
+        {
+            this.columnComment = columnComment;
+        }
+    }
+
+    public String getAttrName()
+    {
+        return attrName;
+    }
+
+    public void setAttrName(String attrName)
+    {
+        this.attrName = attrName;
+    }
+
+    public String getAttrname()
+    {
+        return attrname;
+    }
+
+    public void setAttrname(String attrname)
+    {
+        this.attrname = attrname;
+    }
+
+    public String getAttrType()
+    {
+        return attrType;
+    }
+
+    public void setAttrType(String attrType)
+    {
+        this.attrType = attrType;
+    }
+
+    public String getExtra()
+    {
+        return extra;
+    }
+
+    public void setExtra(String extra)
+    {
+        this.extra = extra;
+    }
+
+    public ColumnConfigInfo getConfigInfo()
+    {
+        return configInfo;
+    }
+
+    public void setConfigInfo(ColumnConfigInfo configInfo)
+    {
+        this.configInfo = configInfo;
+    }
+}

+ 103 - 0
wms-generator/src/main/java/com/deer/wms/generator/domain/TableInfo.java

@@ -0,0 +1,103 @@
+package com.deer.wms.generator.domain;
+
+import java.util.List;
+import com.deer.wms.common.core.domain.BaseEntity;
+import com.deer.wms.common.utils.StringUtils;
+
+/**
+ * ry 数据库表
+ * 
+ * @author deer
+ */
+public class TableInfo extends BaseEntity
+{
+    private static final long serialVersionUID = 1L;
+
+    /** 表名称 */
+    private String tableName;
+
+    /** 表描述 */
+    private String tableComment;
+
+    /** 表的主键列信息 */
+    private ColumnInfo primaryKey;
+
+    /** 表的列名(不包含主键) */
+    private List<ColumnInfo> columns;
+
+    /** 类名(第一个字母大写) */
+    private String className;
+
+    /** 类名(第一个字母小写) */
+    private String classname;
+
+    public String getTableName()
+    {
+        return tableName;
+    }
+
+    public void setTableName(String tableName)
+    {
+        this.tableName = tableName;
+    }
+
+    public String getTableComment()
+    {
+        return tableComment;
+    }
+
+    public void setTableComment(String tableComment)
+    {
+        this.tableComment = tableComment;
+    }
+
+    public List<ColumnInfo> getColumns()
+    {
+        return columns;
+    }
+
+    public ColumnInfo getColumnsLast()
+    {
+        ColumnInfo columnInfo = null;
+        if (StringUtils.isNotNull(columns) && columns.size() > 0)
+        {
+            columnInfo = columns.get(0);
+        }
+        return columnInfo;
+    }
+
+    public void setColumns(List<ColumnInfo> columns)
+    {
+        this.columns = columns;
+    }
+
+    public String getClassName()
+    {
+        return className;
+    }
+
+    public void setClassName(String className)
+    {
+        this.className = className;
+    }
+
+    public String getClassname()
+    {
+        return classname;
+    }
+
+    public void setClassname(String classname)
+    {
+        this.classname = classname;
+    }
+
+    public ColumnInfo getPrimaryKey()
+    {
+        return primaryKey;
+    }
+
+    public void setPrimaryKey(ColumnInfo primaryKey)
+    {
+        this.primaryKey = primaryKey;
+    }
+}

+ 36 - 0
wms-generator/src/main/java/com/deer/wms/generator/service/IGenService.java

@@ -0,0 +1,36 @@
+package com.deer.wms.generator.service;
+
+import java.util.List;
+import com.deer.wms.generator.domain.TableInfo;
+
+/**
+ * 代码生成 服务层
+ * 
+ * @author deer
+ */
+public interface IGenService
+{
+    /**
+     * 查询ry数据库表信息
+     * 
+     * @param tableInfo 表信息
+     * @return 数据库表列表
+     */
+    public List<TableInfo> selectTableList(TableInfo tableInfo);
+
+    /**
+     * 生成代码
+     * 
+     * @param tableName 表名称
+     * @return 数据
+     */
+    public byte[] generatorCode(String tableName);
+
+    /**
+     * 批量生成代码
+     * 
+     * @param tableNames 表数组
+     * @return 数据
+     */
+    public byte[] generatorCode(String[] tableNames);
+}

+ 141 - 0
wms-generator/src/main/java/com/deer/wms/generator/service/impl/GenServiceImpl.java

@@ -0,0 +1,141 @@
+package com.deer.wms.generator.service.impl;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import com.deer.wms.generator.config.GenConfig;
+import com.deer.wms.generator.domain.TableInfo;
+import com.deer.wms.generator.service.IGenService;
+import com.deer.wms.generator.util.GenUtils;
+import com.deer.wms.generator.util.VelocityInitializer;
+import org.apache.commons.io.IOUtils;
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.Velocity;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import com.deer.wms.common.constant.Constants;
+import com.deer.wms.common.utils.StringUtils;
+import com.deer.wms.generator.domain.ColumnInfo;
+import com.deer.wms.generator.dao.GenMapper;
+
+/**
+ * 代码生成 服务层处理
+ * 
+ * @author deer
+ */
+@Service
+public class GenServiceImpl implements IGenService
+{
+    private static final Logger log = LoggerFactory.getLogger(GenServiceImpl.class);
+
+    @Autowired
+    private GenMapper genMapper;
+
+    /**
+     * 查询ry数据库表信息
+     * 
+     * @param tableInfo 表信息
+     * @return 数据库表列表
+     */
+    @Override
+    public List<TableInfo> selectTableList(TableInfo tableInfo)
+    {
+        return genMapper.selectTableList(tableInfo);
+    }
+
+    /**
+     * 生成代码
+     * 
+     * @param tableName 表名称
+     * @return 数据
+     */
+    @Override
+    public byte[] generatorCode(String tableName)
+    {
+        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+        ZipOutputStream zip = new ZipOutputStream(outputStream);
+        // 查询表信息
+        TableInfo table = genMapper.selectTableByName(tableName);
+        // 查询列信息
+        List<ColumnInfo> columns = genMapper.selectTableColumnsByName(tableName);
+        // 生成代码
+        generatorCode(table, columns, zip);
+        IOUtils.closeQuietly(zip);
+        return outputStream.toByteArray();
+    }
+
+    /**
+     * 批量生成代码
+     * 
+     * @param tableNames 表数组
+     * @return 数据
+     */
+    @Override
+    public byte[] generatorCode(String[] tableNames)
+    {
+        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+        ZipOutputStream zip = new ZipOutputStream(outputStream);
+        for (String tableName : tableNames)
+        {
+            // 查询表信息
+            TableInfo table = genMapper.selectTableByName(tableName);
+            // 查询列信息
+            List<ColumnInfo> columns = genMapper.selectTableColumnsByName(tableName);
+            // 生成代码
+            generatorCode(table, columns, zip);
+        }
+        IOUtils.closeQuietly(zip);
+        return outputStream.toByteArray();
+    }
+
+    /**
+     * 生成代码
+     */
+    public void generatorCode(TableInfo table, List<ColumnInfo> columns, ZipOutputStream zip)
+    {
+        // 表名转换成Java属性名
+        String className = GenUtils.tableToJava(table.getTableName());
+        table.setClassName(className);
+        table.setClassname(StringUtils.uncapitalize(className));
+        // 列信息
+        table.setColumns(GenUtils.transColums(columns));
+        // 设置主键
+        table.setPrimaryKey(table.getColumnsLast());
+
+        VelocityInitializer.initVelocity();
+
+        String packageName = GenConfig.getPackageName();
+        String moduleName = GenUtils.getModuleName(packageName);
+
+        VelocityContext context = GenUtils.getVelocityContext(table);
+
+        // 获取模板列表
+        List<String> templates = GenUtils.getTemplates();
+        for (String template : templates)
+        {
+            // 渲染模板
+            StringWriter sw = new StringWriter();
+            Template tpl = Velocity.getTemplate(template, Constants.UTF8);
+            tpl.merge(context, sw);
+            try
+            {
+                // 添加到zip
+                zip.putNextEntry(new ZipEntry(GenUtils.getFileName(template, table, moduleName)));
+                IOUtils.write(sw.toString(), zip, Constants.UTF8);
+                IOUtils.closeQuietly(sw);
+                zip.closeEntry();
+            }
+            catch (IOException e)
+            {
+                log.error("渲染模板失败,表名:" + table.getTableName(), e);
+            }
+        }
+    }
+}

+ 242 - 0
wms-generator/src/main/java/com/deer/wms/generator/util/GenUtils.java

@@ -0,0 +1,242 @@
+package com.deer.wms.generator.util;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.deer.wms.generator.config.GenConfig;
+import com.deer.wms.generator.domain.TableInfo;
+import org.apache.velocity.VelocityContext;
+import com.deer.wms.common.constant.Constants;
+import com.deer.wms.common.utils.DateUtils;
+import com.deer.wms.common.utils.StringUtils;
+import com.deer.wms.generator.domain.ColumnInfo;
+
+/**
+ * 代码生成器 工具类
+ * 
+ * @author deer
+ */
+public class GenUtils
+{
+    /** 项目空间路径 */
+    private static final String PROJECT_PATH = getProjectPath();
+
+    /** mybatis空间路径 */
+    private static final String MYBATIS_PATH = "main/resources/mapper";
+
+    /** html空间路径 */
+    private static final String TEMPLATES_PATH = "main/resources/templates";
+
+    /** 类型转换 */
+    public static Map<String, String> javaTypeMap = new HashMap<String, String>();
+
+    /**
+     * 设置列信息
+     */
+    public static List<ColumnInfo> transColums(List<ColumnInfo> columns)
+    {
+        // 列信息
+        List<ColumnInfo> columsList = new ArrayList<>();
+        for (ColumnInfo column : columns)
+        {
+            // 列名转换成Java属性名
+            String attrName = StringUtils.convertToCamelCase(column.getColumnName());
+            column.setAttrName(attrName);
+            column.setAttrname(StringUtils.uncapitalize(attrName));
+            column.setExtra(column.getExtra());
+
+            // 列的数据类型,转换成Java类型
+            String attrType = javaTypeMap.get(column.getDataType());
+            column.setAttrType(attrType);
+
+            columsList.add(column);
+        }
+        return columsList;
+    }
+
+    /**
+     * 获取模板信息
+     * 
+     * @return 模板列表
+     */
+    public static VelocityContext getVelocityContext(TableInfo table)
+    {
+        // java对象数据传递到模板文件vm
+        VelocityContext velocityContext = new VelocityContext();
+        String packageName = GenConfig.getPackageName();
+        velocityContext.put("tableName", table.getTableName());
+        velocityContext.put("tableComment", replaceKeyword(table.getTableComment()));
+        velocityContext.put("primaryKey", table.getPrimaryKey());
+        velocityContext.put("className", table.getClassName());
+        velocityContext.put("classname", table.getClassname());
+        velocityContext.put("moduleName", getModuleName(packageName));
+        velocityContext.put("columns", table.getColumns());
+        velocityContext.put("basePackage", getBasePackage(packageName));
+        velocityContext.put("package", packageName);
+        velocityContext.put("author", GenConfig.getAuthor());
+        velocityContext.put("datetime", DateUtils.getDate());
+        return velocityContext;
+    }
+
+    /**
+     * 获取模板信息
+     * 
+     * @return 模板列表
+     */
+    public static List<String> getTemplates()
+    {
+        List<String> templates = new ArrayList<String>();
+        templates.add("vm/java/domain.java.vm");
+        templates.add("vm/java/Mapper.java.vm");
+        templates.add("vm/java/Service.java.vm");
+        templates.add("vm/java/ServiceImpl.java.vm");
+        templates.add("vm/java/Controller.java.vm");
+        templates.add("vm/xml/Mapper.xml.vm");
+        templates.add("vm/html/list.html.vm");
+        templates.add("vm/html/add.html.vm");
+        templates.add("vm/html/edit.html.vm");
+        templates.add("vm/sql/sql.vm");
+        return templates;
+    }
+
+    /**
+     * 表名转换成Java类名
+     */
+    public static String tableToJava(String tableName)
+    {
+        String autoRemovePre = GenConfig.getAutoRemovePre();
+        String tablePrefix = GenConfig.getTablePrefix();
+        if (Constants.AUTO_REOMVE_PRE.equals(autoRemovePre) && StringUtils.isNotEmpty(tablePrefix))
+        {
+            tableName = tableName.replaceFirst(tablePrefix, "");
+        }
+        return StringUtils.convertToCamelCase(tableName);
+    }
+
+    /**
+     * 获取文件名
+     */
+    public static String getFileName(String template, TableInfo table, String moduleName)
+    {
+        // 小写类名
+        String classname = table.getClassname();
+        // 大写类名
+        String className = table.getClassName();
+        String javaPath = PROJECT_PATH;
+        String mybatisPath = MYBATIS_PATH + "/" + moduleName + "/" + className;
+        String htmlPath = TEMPLATES_PATH + "/" + moduleName + "/" + classname;
+
+        if (template.contains("domain.java.vm"))
+        {
+            return javaPath + "domain" + "/" + className + ".java";
+        }
+
+        if (template.contains("Mapper.java.vm"))
+        {
+            return javaPath + "mapper" + "/" + className + "Mapper.java";
+        }
+
+        if (template.contains("Service.java.vm"))
+        {
+            return javaPath + "service" + "/" + "I" + className + "Service.java";
+        }
+
+        if (template.contains("ServiceImpl.java.vm"))
+        {
+            return javaPath + "service" + "/impl/" + className + "ServiceImpl.java";
+        }
+
+        if (template.contains("Controller.java.vm"))
+        {
+            return javaPath + "controller" + "/" + className + "Controller.java";
+        }
+
+        if (template.contains("Mapper.xml.vm"))
+        {
+            return mybatisPath + "Mapper.xml";
+        }
+
+        if (template.contains("list.html.vm"))
+        {
+            return htmlPath + "/" + classname + ".html";
+        }
+        if (template.contains("add.html.vm"))
+        {
+            return htmlPath + "/" + "add.html";
+        }
+        if (template.contains("edit.html.vm"))
+        {
+            return htmlPath + "/" + "edit.html";
+        }
+        if (template.contains("sql.vm"))
+        {
+            return classname + "Menu.sql";
+        }
+        return null;
+    }
+
+    /**
+     * 获取模块名
+     * 
+     * @param packageName 包名
+     * @return 模块名
+     */
+    public static String getModuleName(String packageName)
+    {
+        int lastIndex = packageName.lastIndexOf(".");
+        int nameLength = packageName.length();
+        String moduleName = StringUtils.substring(packageName, lastIndex + 1, nameLength);
+        return moduleName;
+    }
+
+    public static String getBasePackage(String packageName)
+    {
+        int lastIndex = packageName.lastIndexOf(".");
+        String basePackage = StringUtils.substring(packageName, 0, lastIndex);
+        return basePackage;
+    }
+
+    public static String getProjectPath()
+    {
+        String packageName = GenConfig.getPackageName();
+        StringBuffer projectPath = new StringBuffer();
+        projectPath.append("main/java/");
+        projectPath.append(packageName.replace(".", "/"));
+        projectPath.append("/");
+        return projectPath.toString();
+    }
+
+    public static String replaceKeyword(String keyword)
+    {
+        String keyName = keyword.replaceAll("(?:表|信息|管理)", "");
+        return keyName;
+    }
+
+    static
+    {
+        javaTypeMap.put("tinyint", "Integer");
+        javaTypeMap.put("smallint", "Integer");
+        javaTypeMap.put("mediumint", "Integer");
+        javaTypeMap.put("int", "Integer");
+        javaTypeMap.put("number", "Integer");
+        javaTypeMap.put("integer", "integer");
+        javaTypeMap.put("bigint", "Long");
+        javaTypeMap.put("float", "Float");
+        javaTypeMap.put("double", "Double");
+        javaTypeMap.put("decimal", "BigDecimal");
+        javaTypeMap.put("bit", "Boolean");
+        javaTypeMap.put("char", "String");
+        javaTypeMap.put("varchar", "String");
+        javaTypeMap.put("varchar2", "String");
+        javaTypeMap.put("tinytext", "String");
+        javaTypeMap.put("text", "String");
+        javaTypeMap.put("mediumtext", "String");
+        javaTypeMap.put("longtext", "String");
+        javaTypeMap.put("time", "Date");
+        javaTypeMap.put("date", "Date");
+        javaTypeMap.put("datetime", "Date");
+        javaTypeMap.put("timestamp", "Date");
+    }
+}

+ 36 - 0
wms-generator/src/main/java/com/deer/wms/generator/util/VelocityInitializer.java

@@ -0,0 +1,36 @@
+package com.deer.wms.generator.util;
+
+import java.util.Properties;
+import org.apache.velocity.app.Velocity;
+import com.deer.wms.common.constant.Constants;
+
+/**
+ * VelocityEngine工厂
+ * 
+ * @author RuoYi
+ */
+public class VelocityInitializer
+{
+    /**
+     * 初始化vm方法
+     */
+    public static void initVelocity()
+    {
+        Properties p = new Properties();
+        try
+        {
+            // 加载classpath目录下的vm文件
+            p.setProperty("file.resource.loader.class",
+                    "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
+            // 定义字符集
+            p.setProperty(Velocity.ENCODING_DEFAULT, Constants.UTF8);
+            p.setProperty(Velocity.OUTPUT_ENCODING, Constants.UTF8);
+            // 初始化Velocity引擎,指定配置Properties
+            Velocity.init(p);
+        }
+        catch (Exception e)
+        {
+            throw new RuntimeException(e);
+        }
+    }
+}

+ 40 - 0
wms-generator/src/main/java/com/deer/wms/generator2/DeerGenerator.java

@@ -0,0 +1,40 @@
+package com.deer.wms.generator2;
+
+
+import com.deer.wms.generator2.configurer.DatasourceConfigurer;
+import com.deer.wms.generator2.configurer.Table;
+
+/**
+ * Created by Floki on 2017/9/29.
+ */
+public class DeerGenerator {
+    public static void main(String[] args) {
+        DatasourceConfigurer configurer = new DatasourceConfigurer();
+        //设置数据库连接信息
+//        configurer.setUrl("jdbc:mysql://sh-cdb-60jldfhk.sql.tencentcdb.com:62802/wuxi_wms?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false");
+        configurer.setUrl("jdbc:mysql://localhost:3306/wxwms?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false");
+        configurer.setPassword("1234");
+        configurer.setUserName("root");
+//        configurer.setPassword("12!@qwQW");
+        configurer.setDiverClassName("com.mysql.jdbc.Driver");
+
+        //设置需要生成代码的基础路径,生成的代码都会在该路径下面
+        configurer.setBasePackage("com.deer.wms.base.system");
+        configurer.setAuthor("");
+
+        //设置子模块名称(如果要生成子模块的代码,一定要设置该值,否则代码将会生成到父项目中了)
+        configurer.setModuleName("/wms-base-system");
+
+        //设置需要生成的表
+       // configurer.getTables().add(new Table("bill_master", null, "id", "Integer"));
+        //configurer.getTables().add(new Table("bill_detail",null,"id","Integer"));
+        //configurer.getTables().add(new Table("Shelf_info", null, "ShelfIdInt", "Integer"));
+        //configurer.getTables().add(new Table("help_content", null, "content_id", "Integer"));
+        //configurer.getTables().add(new Table("validate_record", null, "record_id", "Long"));
+
+        configurer.getTables().add(new Table("transfer_reason",null,"transfer_reason_id","Integer"));
+
+        //生成代码
+        Generator.genCode(configurer);
+    }
+}

+ 249 - 0
wms-generator/src/main/java/com/deer/wms/generator2/Generator.java

@@ -0,0 +1,249 @@
+package com.deer.wms.generator2;
+
+import com.deer.wms.generator2.configurer.DatasourceConfigurer;
+import com.deer.wms.generator2.configurer.Table;
+import com.google.common.base.CaseFormat;
+import freemarker.template.TemplateExceptionHandler;
+import org.mybatis.generator.api.MyBatisGenerator;
+import org.mybatis.generator.config.*;
+import org.mybatis.generator.internal.DefaultShellCallback;
+import org.springframework.util.StringUtils;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+/**
+ * 代码生成器,根据数据表名称生成对应的Model、Mapper、Service、Controller简化开发。
+ *
+ * Created by Floki on 2017/7/30.
+ */
+public class Generator {
+
+    private static final String JAVA_PATH = "/src/main/java"; //java文件路径
+    //private static final String RESOURCES_PATH = "/src/main/resources";//资源文件路径
+    private static final String PROJECT_PATH = System.getProperty("user.dir");//项目在硬盘上的基础路径
+    private static final String TEMPLATE_FILE_PATH = PROJECT_PATH + "/src/test/resources/generator/template";//模板位置
+    private static final String DATE = new SimpleDateFormat("yyyy/MM/dd").format(new Date());//@date
+    /**
+     * 通过数据表名称生成代码,Model 名称通过解析数据表名称获得,下划线转大驼峰的形式。
+     * 如输入表名称 "t_user_detail" 将生成 TUserDetail、TUserDetailMapper、TUserDetailService ...
+     *
+     * @param configurer 生成代码的配置信息
+     */
+    public static void genCode(DatasourceConfigurer configurer) {
+        if (null == configurer) {
+            System.out.println("没有生成代码的配置文件......");
+            return;
+        }
+
+        List<Table> tables = configurer.getTables();
+        if (null == tables || tables.isEmpty()) {
+            System.out.println("没有生成代码的数据表......");
+            return;
+        }
+
+        tables.forEach(table -> genCode(configurer, table));
+    }
+
+    /**
+     * 通过数据表名称,和自定义的 Model 名称生成代码
+     * 如输入表名称 "t_user_detail" 和自定义的 Model 名称 "User" 将生成 User、UserMapper、UserService ...
+     * @param configurer 配置文件
+     * @param table 需要生成代码的数据表信息
+     */
+    public static void genCode(DatasourceConfigurer configurer, Table table) {
+        Long start = System.currentTimeMillis();
+        genModelAndMapper(configurer, table.getTableName(), table.getModelName(), table.getColumn());
+        genCriteria(configurer, table.getTableName(), table.getModelName());
+        genService(configurer, table.getTableName(), table.getModelName(), table.getType());
+        genController(configurer, table.getTableName(), table.getModelName(), table.getType());
+        System.out.println("耗时 " + (System.currentTimeMillis() - start) + " 毫秒");
+    }
+
+    public static void genModelAndMapper(DatasourceConfigurer configurer, String tableName, String modelName, String column) {
+        Context context = new Context(ModelType.FLAT);
+        context.setId("Potato");
+        context.setTargetRuntime("MyBatis3Simple");
+        context.addProperty(PropertyRegistry.CONTEXT_BEGINNING_DELIMITER, "`");
+        context.addProperty(PropertyRegistry.CONTEXT_ENDING_DELIMITER, "`");
+
+        JDBCConnectionConfiguration jdbcConnectionConfiguration = new JDBCConnectionConfiguration();
+        jdbcConnectionConfiguration.setConnectionURL(configurer.getUrl());
+        jdbcConnectionConfiguration.setUserId(configurer.getUserName());
+        jdbcConnectionConfiguration.setPassword(configurer.getPassword());
+        jdbcConnectionConfiguration.setDriverClass(configurer.getDiverClassName());
+        context.setJdbcConnectionConfiguration(jdbcConnectionConfiguration);
+
+        PluginConfiguration pluginConfiguration = new PluginConfiguration();
+        pluginConfiguration.setConfigurationType("tk.mybatis.mapper.generator.MapperPlugin");
+        pluginConfiguration.addProperty("mappers", "Mapper");
+        context.addPluginConfiguration(pluginConfiguration);
+
+        JavaModelGeneratorConfiguration javaModelGeneratorConfiguration = new JavaModelGeneratorConfiguration();
+        javaModelGeneratorConfiguration.setTargetProject(PROJECT_PATH + configurer.getModuleName() + JAVA_PATH);
+        javaModelGeneratorConfiguration.setTargetPackage(configurer.getModelPackage());
+        context.setJavaModelGeneratorConfiguration(javaModelGeneratorConfiguration);
+
+        SqlMapGeneratorConfiguration sqlMapGeneratorConfiguration = new SqlMapGeneratorConfiguration();
+        sqlMapGeneratorConfiguration.setTargetProject(PROJECT_PATH + configurer.getModuleName() + JAVA_PATH);
+        sqlMapGeneratorConfiguration.setTargetPackage(configurer.getMapperPackage());
+        context.setSqlMapGeneratorConfiguration(sqlMapGeneratorConfiguration);
+
+        JavaClientGeneratorConfiguration javaClientGeneratorConfiguration = new JavaClientGeneratorConfiguration();
+        javaClientGeneratorConfiguration.setTargetProject(PROJECT_PATH + configurer.getModuleName() + JAVA_PATH);
+        javaClientGeneratorConfiguration.setTargetPackage(configurer.getDaoPackage());
+        javaClientGeneratorConfiguration.setConfigurationType("XMLMAPPER");
+        context.setJavaClientGeneratorConfiguration(javaClientGeneratorConfiguration);
+
+        TableConfiguration tableConfiguration = new TableConfiguration(context);
+        tableConfiguration.setTableName(tableName);
+        tableConfiguration.setDomainObjectName(modelName);
+        tableConfiguration.setGeneratedKey(new GeneratedKey(column, "Mysql", true, null));
+        context.addTableConfiguration(tableConfiguration);
+
+        List<String> warnings;
+        MyBatisGenerator generator;
+        try {
+            Configuration config = new Configuration();
+            config.addContext(context);
+            config.validate();
+
+            boolean overwrite = true;
+            DefaultShellCallback callback = new DefaultShellCallback(overwrite);
+            warnings = new ArrayList<>();
+            generator = new MyBatisGenerator(config, callback, warnings);
+            generator.generate(null);
+        } catch (Exception e) {
+            throw new RuntimeException("生成Model和Mapper失败", e);
+        }
+
+        if (generator.getGeneratedJavaFiles().isEmpty() || generator.getGeneratedXmlFiles().isEmpty()) {
+            throw new RuntimeException("生成Model和Mapper失败:" + warnings);
+        }
+        if (StringUtils.isEmpty(modelName)) modelName = tableNameConvertUpperCamel(tableName);
+        System.out.println(modelName + ".java 生成成功");
+        System.out.println(modelName + "Mapper.java 生成成功");
+        System.out.println(modelName + "Mapper.xml 生成成功");
+    }
+
+    public static void genService(DatasourceConfigurer configurer, String tableName, String modelName, String type) {
+        try {
+            freemarker.template.Configuration cfg = getConfiguration();
+
+            Map<String, Object> data = new HashMap<>();
+            data.put("date", DATE);
+            data.put("author", configurer.getAuthor());
+            String modelNameUpperCamel = StringUtils.isEmpty(modelName) ? tableNameConvertUpperCamel(tableName) : modelName;
+            data.put("modelNameUpperCamel", modelNameUpperCamel);
+            data.put("modelNameLowerCamel", tableNameConvertLowerCamel(tableName));
+            data.put("basePackage", configurer.getBasePackage());
+            data.put("type", type);
+
+            String servicePathPackage = packageConvertPath(configurer.getServicePackage());//生成的Service存放路径
+            File file = new File(PROJECT_PATH + configurer.getModuleName() + JAVA_PATH + servicePathPackage + modelNameUpperCamel + "Service.java");
+            if (!file.getParentFile().exists()) {
+                file.getParentFile().mkdirs();
+            }
+            cfg.getTemplate("service.ftl").process(data, new FileWriter(file));
+            System.out.println(modelNameUpperCamel + "Service.java 生成成功");
+
+            String serviceImplPathPackage = packageConvertPath(configurer.getServiceImplPackage());//生成的Service实现存放路径
+            File file1 = new File(PROJECT_PATH + configurer.getModuleName() + JAVA_PATH + serviceImplPathPackage + modelNameUpperCamel + "ServiceImpl.java");
+            if (!file1.getParentFile().exists()) {
+                file1.getParentFile().mkdirs();
+            }
+            cfg.getTemplate("service-impl.ftl").process(data, new FileWriter(file1));
+            System.out.println(modelNameUpperCamel + "ServiceImpl.java 生成成功");
+        } catch (Exception e) {
+            throw new RuntimeException("生成Service失败", e);
+        }
+    }
+
+    public static void genController(DatasourceConfigurer configurer, String tableName, String modelName, String type) {
+        try {
+            freemarker.template.Configuration cfg = getConfiguration();
+
+            Map<String, Object> data = new HashMap<>();
+            data.put("date", DATE);
+            data.put("author", configurer.getAuthor());
+            String modelNameUpperCamel = StringUtils.isEmpty(modelName) ? tableNameConvertUpperCamel(tableName) : modelName;
+            data.put("baseRequestMapping", modelNameConvertMappingPath(modelNameUpperCamel));
+            data.put("modelNameUpperCamel", modelNameUpperCamel);
+            data.put("modelNameLowerCamel", CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, modelNameUpperCamel));
+            data.put("basePackage", configurer.getBasePackage());
+            data.put("type", type);
+
+            String controllerPathPackage = packageConvertPath(configurer.getControllerPackage());//生成的Controller存放路径
+            File file = new File(PROJECT_PATH + configurer.getModuleName() + JAVA_PATH + controllerPathPackage + modelNameUpperCamel + "Controller.java");
+            if (!file.getParentFile().exists()) {
+                file.getParentFile().mkdirs();
+            }
+            cfg.getTemplate("controller-restful.ftl").process(data, new FileWriter(file));
+            //cfg.getTemplate("controller.ftl").process(data, new FileWriter(file));
+
+            System.out.println(modelNameUpperCamel + "Controller.java 生成成功");
+        } catch (Exception e) {
+            throw new RuntimeException("生成Controller失败", e);
+        }
+
+    }
+
+    public static void genCriteria(DatasourceConfigurer configurer, String tableName, String modelName) {
+        try {
+            freemarker.template.Configuration cfg = getConfiguration();
+
+            Map<String, Object> data = new HashMap<>();
+            data.put("date", DATE);
+            data.put("author", configurer.getAuthor());
+            String modelNameUpperCamel = StringUtils.isEmpty(modelName) ? tableNameConvertUpperCamel(tableName) : modelName;
+            data.put("modelNameUpperCamel", modelNameUpperCamel);
+            data.put("basePackage", configurer.getBasePackage());
+
+            String criteriaPathPackage = packageConvertPath(configurer.getModelPackage());//生成的criteria存放路径
+            File file = new File(PROJECT_PATH + configurer.getModuleName() + JAVA_PATH + criteriaPathPackage + modelNameUpperCamel + "Criteria.java");
+            if (!file.getParentFile().exists()) {
+                file.getParentFile().mkdirs();
+            }
+            cfg.getTemplate("criteria.ftl").process(data, new FileWriter(file));
+
+            System.out.println(modelNameUpperCamel + "Criteria.java 生成成功");
+        } catch (Exception e) {
+            throw new RuntimeException("生成Criteria失败", e);
+        }
+
+    }
+
+    private static freemarker.template.Configuration getConfiguration() throws IOException {
+        freemarker.template.Configuration cfg = new freemarker.template.Configuration(freemarker.template.Configuration.VERSION_2_3_23);
+        cfg.setDirectoryForTemplateLoading(new File(TEMPLATE_FILE_PATH));
+        cfg.setDefaultEncoding("UTF-8");
+        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.IGNORE_HANDLER);
+        return cfg;
+    }
+
+    private static String tableNameConvertLowerCamel(String tableName) {
+        return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, tableName.toLowerCase());
+    }
+
+    private static String tableNameConvertUpperCamel(String tableName) {
+        return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, tableName.toLowerCase());
+
+    }
+
+    private static String tableNameConvertMappingPath(String tableName) {
+        tableName = tableName.toLowerCase();//兼容使用大写的表名
+        return "/" + (tableName.contains("_") ? tableName.replaceAll("_", "/") : tableName);
+    }
+
+    private static String modelNameConvertMappingPath(String modelName) {
+        String tableName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, modelName);
+        return tableNameConvertMappingPath(tableName);
+    }
+
+    private static String packageConvertPath(String packageName) {
+        return String.format("/%s/", packageName.contains(".") ? packageName.replaceAll("\\.", "/") : packageName);
+    }
+
+}

+ 136 - 0
wms-generator/src/main/java/com/deer/wms/generator2/configurer/DatasourceConfigurer.java

@@ -0,0 +1,136 @@
+package com.deer.wms.generator2.configurer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 生成代码的数据库链接设置
+ *
+ * Created by Floki on 2017/7/31.
+ */
+public class DatasourceConfigurer {
+    /**
+     * 生成代码的作者
+     */
+    private String author;
+
+    private String url;
+
+    private String userName;
+
+    private String password;
+
+    private String diverClassName;
+
+    private String moduleName;
+
+    private String basePackage;
+
+    private String modelPackage;
+
+    private String mapperPackage;
+
+    private String daoPackage;
+
+    private String servicePackage;
+
+    private String serviceImplPackage;
+
+    private String controllerPackage;
+
+    private List<Table> tables = new ArrayList<>();
+
+    public String getAuthor() {
+        return author;
+    }
+
+    public void setAuthor(String author) {
+        this.author = author;
+    }
+
+    public String getUrl() {
+        return url;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+    }
+
+    public String getUserName() {
+        return userName;
+    }
+
+    public void setUserName(String userName) {
+        this.userName = userName;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public String getDiverClassName() {
+        return diverClassName;
+    }
+
+    public void setDiverClassName(String diverClassName) {
+        this.diverClassName = diverClassName;
+    }
+
+    public String getBasePackage() {
+        return basePackage;
+    }
+
+    public void setBasePackage(String basePackage) {
+        this.basePackage = basePackage;
+        this.modelPackage = basePackage + ".model";
+        this.mapperPackage = basePackage + ".mapper";
+        this.daoPackage = basePackage + ".dao";
+        this.servicePackage = basePackage + ".service";
+        this.serviceImplPackage = this.servicePackage + ".impl";
+        this.controllerPackage = basePackage + ".web";
+    }
+
+    public String getModuleName() {
+        return moduleName;
+    }
+
+    public void setModuleName(String moduleName) {
+        this.moduleName = moduleName;
+    }
+
+    public String getModelPackage() {
+        return modelPackage;
+    }
+
+    public String getMapperPackage() {
+        return mapperPackage;
+    }
+
+    public String getDaoPackage() {
+        return daoPackage;
+    }
+
+    public String getServicePackage() {
+        return servicePackage;
+    }
+
+    public String getServiceImplPackage() {
+        return serviceImplPackage;
+    }
+
+    public String getControllerPackage() {
+        return controllerPackage;
+    }
+
+    public List<Table> getTables() {
+        return tables;
+    }
+
+    public void setTables(List<Table> tables) {
+        this.tables = tables;
+    }
+}

+ 58 - 0
wms-generator/src/main/java/com/deer/wms/generator2/configurer/Table.java

@@ -0,0 +1,58 @@
+package com.deer.wms.generator2.configurer;
+
+/**
+ * Created by Floki on 2017/7/31.
+ */
+public class Table {
+    private String tableName;
+
+    private String modelName;
+
+    private String column;
+
+    private String type;
+
+    public Table() {
+
+    }
+
+    public Table(String tableName, String modelName, String column, String type) {
+        this.tableName = tableName;
+        this.modelName = modelName;
+        this.column = column;
+        this.type = type;
+    }
+
+    public String getTableName() {
+        return tableName;
+    }
+
+    public void setTableName(String tableName) {
+        this.tableName = tableName;
+    }
+
+    public String getModelName() {
+        return modelName;
+    }
+
+    public void setModelName(String modelName) {
+        this.modelName = modelName;
+    }
+
+    public String getColumn() {
+        return column;
+    }
+
+    public void setColumn(String column) {
+        this.column = column;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+}

+ 11 - 0
wms-generator/src/main/resources/generator.yml

@@ -0,0 +1,11 @@
+
+# 代码生成
+gen: 
+  # 作者
+  author: guo
+  # 默认生成包路径 system 需改成自己的模块名称 如 system monitor tool
+  packageName: com.deer.wms.bill.in
+  # 自动去除表前缀,默认是true
+  autoRemovePre: true
+  # 表前缀(类名不会包含表前缀)
+  tablePrefix: sys_

+ 52 - 0
wms-generator/src/main/resources/mapper/generator/GenMapper.xml

@@ -0,0 +1,52 @@
+<?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="com.deer.wms.generator.dao.GenMapper">
+
+	<resultMap type="TableInfo" id="TableInfoResult">
+		<id     property="tableName"      column="table_name"      />
+		<result property="tableComment"   column="table_comment"   />
+		<result property="createTime"     column="create_time"     />
+		<result property="updateTime"     column="update_time"     />
+	</resultMap>
+	
+	<resultMap type="ColumnInfo" id="ColumnInfoResult">
+		<id     property="columnName"     column="column_name"      />
+		<result property="dataType"       column="data_type"        />
+		<result property="columnComment"  column="column_comment"   />
+	</resultMap>
+	
+	<sql id="selectGenVo">
+        select table_name, table_comment, create_time, update_time from information_schema.tables
+    </sql>
+
+	<select id="selectTableList" parameterType="TableInfo" resultMap="TableInfoResult">
+		<include refid="selectGenVo"/>
+		where table_comment <![CDATA[ <> ]]> '' and table_schema = (select database())
+		<if test="tableName != null and tableName != ''">
+			AND table_name like concat('%', #{tableName}, '%')
+		</if>
+		<if test="tableComment != null and tableComment != ''">
+			AND table_comment like concat('%', #{tableComment}, '%')
+		</if>
+		<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
+			and date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
+		</if>
+		<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
+			and date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
+		</if>
+	</select>
+	
+	<select id="selectTableByName" parameterType="String" resultMap="TableInfoResult">
+		<include refid="selectGenVo"/>
+		where table_comment <![CDATA[ <> ]]> '' and table_schema = (select database())
+		and table_name = #{tableName}
+	</select>
+	
+	<select id="selectTableColumnsByName" parameterType="String" resultMap="ColumnInfoResult">
+		select column_name, data_type, column_comment, extra from information_schema.columns
+        where table_name = #{tableName} and table_schema = (select database()) order by ordinal_position
+	</select>
+
+</mapper> 

+ 123 - 0
wms-generator/src/main/resources/templates/tool/gen/gen.html

@@ -0,0 +1,123 @@
+<!DOCTYPE html>
+<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
+<head>
+	<th:block th:include="include :: header('代码生成列表')" />
+</head>
+<body class="gray-bg">
+    <div class="container-div" onmousemove="parent.updateTimeOut()">
+		<div class="row">
+			<div class="col-sm-12 search-collapse">
+				<form id="gen-form">
+					<div class="select-list">
+						<ul>
+							<li>
+								表名称:<input type="text" name="tableName"/>
+							</li>
+							<li>
+								表描述:<input type="text" name="tableComment"/>
+							</li>
+							<li class="select-time">
+								<label>表时间: </label>
+								<input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
+								<span>-</span>
+								<input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
+							</li>
+							<li>
+								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
+								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
+							</li>
+						</ul>
+					</div>
+				</form>
+			</div>
+			
+			<div class="btn-group-sm" id="toolbar" role="group">
+				<a class="btn btn-success" onclick="javascript:batchGenCode()" shiro:hasPermission="tool:gen:code">
+			        <i class="fa fa-download"></i> 批量生成
+			    </a>
+		    </div>
+		
+		    <div class="col-sm-12 select-table table-striped">
+			    <table id="bootstrap-table" data-mobile-responsive="true"></table>
+			</div>
+		</div>
+	</div>
+	<th:block th:include="include :: footer" />
+	<script type="text/javascript">
+		var prefix = ctx + "tool/gen";
+	
+		$(function() {
+		    var options = {
+		        url: prefix + "/list",
+		        sortName: "createTime",
+		        sortOrder: "desc",
+		        showExport: true,
+		        columns: [{
+		            checkbox: true
+		        },
+		        {
+                    title: "序号",
+                    formatter: function (value, row, index) {
+                 	    return $.table.serialNumber(index);
+                    }
+                },
+		        {
+		            field: 'tableName',
+		            title: '表名称',
+		            width: '20%',
+		            sortable: true
+		        },
+		        {
+		            field: 'tableComment',
+		            title: '表描述',
+		            width: '20%',
+		            sortable: true
+		        },
+		        {
+		            field: 'createTime',
+		            title: '创建时间',
+		            width: '20%',
+		            sortable: true
+		        },
+		        {
+		            field: 'updateTime',
+		            title: '更新时间',
+		            width: '20%',
+		            sortable: true
+		        },
+		        {
+		            title: '操作',
+		            width: '20%',
+		            align: 'center',
+		            formatter: function(value, row, index) {
+		                var msg = '<a class="btn btn-primary btn-xs" href="#" onclick="genCode(\'' + row.tableName + '\')"><i class="fa fa-bug"></i>生成代码</a> ';
+		                return msg;
+		            }
+		        }]
+		    };
+		    $.table.init(options);
+		});
+	
+		// 生成代码
+		function genCode(tableName) {
+		    $.modal.confirm("确定要生成" + tableName + "表代码吗?", function() {
+		        location.href = prefix + "/genCode/" + tableName;
+		        layer.msg('执行成功,正在生成代码请稍后…', { icon: 1 });
+		    })
+		}
+	
+		//批量生成代码
+		function batchGenCode() {
+		    var rows = $.table.selectColumns("tableName");
+		    if (rows.length == 0) {
+		        $.modal.alertWarning("请选择要生成的数据");
+		        return;
+		    }
+		    $.modal.confirm("确认要生成选中的" + rows.length + "条数据吗?", function() {
+		        location.href = prefix + "/batchGenCode?tables=" + rows;
+		        layer.msg('执行成功,正在生成代码请稍后…', { icon: 1 });
+		    });
+		}
+	</script>
+</body>
+</html>

+ 61 - 0
wms-generator/src/main/resources/vm/html/add.html.vm

@@ -0,0 +1,61 @@
+<!DOCTYPE html>
+<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
+	<head>
+		<th:block th:include="include :: header('新增${tableComment}')" />
+	</head>
+	<body class="white-bg">
+		<div class="wrapper wrapper-content animated fadeInRight ibox-content">
+			<form class="form-horizontal m" id="form-${classname}-add">
+	#foreach($column in $columns)
+	#if($column.columnName != $primaryKey.columnName)
+	#if(!${column.configInfo})
+				<div class="form-group">
+					<label class="col-sm-3 control-label">${column.columnComment}:</label>
+					<div class="col-sm-8">
+						<input id="${column.attrname}" name="${column.attrname}" class="form-control" type="text">
+					</div>
+				</div>
+	#else
+	#if(${column.configInfo.type} == "dict")
+				<div class="form-group">
+					<label class="col-sm-3 control-label">${column.columnComment}:</label>
+					<div class="col-sm-8">
+						<select name="${column.attrname}" class="form-control m-b" th:with="type=${@dict.getType('${column.configInfo.value}')}">
+							<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
+						</select>
+					</div>
+				</div>
+	#elseif(${column.configInfo.type} == "date")
+				<div class="form-group">
+					<label class="col-sm-3 control-label">${column.columnComment}:</label>
+					<div class="col-sm-8">
+						<input id="${column.attrname}" name="${column.attrname}" class="form-control time-input" type="text">
+					</div>
+				</div>
+	#elseif(${column.configInfo.type} == "fk")
+	#end
+	#end
+	#end
+	#end
+			</form>
+		</div>
+		<div th:include="include::footer"></div>
+		<script type="text/javascript">
+			var prefix = ctx + "${moduleName}/${classname}"
+			$("#form-${classname}-add").validate({
+				rules:{
+					xxxx:{
+						required:true,
+					},
+				},
+				focusCleanup: true
+			});
+
+			function submitHandler() {
+				if ($.validate.form()) {
+					$.operate.save(prefix + "/add", $('#form-${classname}-add').serialize());
+				}
+			}
+		</script>
+	</body>
+</html>

+ 62 - 0
wms-generator/src/main/resources/vm/html/edit.html.vm

@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
+<head>
+	<th:block th:include="include :: header('修改${tableComment}')" />
+</head>
+<body class="white-bg">
+    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
+        <form class="form-horizontal m" id="form-${classname}-edit" th:object="${${classname}}">
+            <input id="${primaryKey.attrname}" name="${primaryKey.attrname}" th:field="*{${primaryKey.attrname}}"  type="hidden">
+#foreach($column in $columns)
+#if($column.columnName != $primaryKey.columnName)
+#if(!${column.configInfo})
+			<div class="form-group">	
+				<label class="col-sm-3 control-label">${column.columnComment}:</label>
+				<div class="col-sm-8">
+					<input id="${column.attrname}" name="${column.attrname}" th:field="*{${column.attrname}}" class="form-control" type="text">
+				</div>
+			</div>
+#else
+#if(${column.configInfo.type} == "dict")
+			<div class="form-group">	
+				<label class="col-sm-3 control-label">${column.columnComment}:</label>
+				<div class="col-sm-8">
+					<select name="${column.attrname}" class="form-control m-b" th:with="type=${@dict.getType('${column.configInfo.value}')}">
+						<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{${column.attrname}}"></option>
+					</select>
+				</div>
+			</div>
+#elseif(${column.configInfo.type} == "date")
+			<div class="form-group">	
+				<label class="col-sm-3 control-label">${column.columnComment}:</label>
+				<div class="col-sm-8">
+					<input id="${column.attrname}"  name="${column.attrname}" th:field="*{${column.attrname}}" class="form-control time-input" type="text">
+				</div>
+			</div>
+#elseif(${column.configInfo.type} == "fk")	
+#end
+#end
+#end
+#end
+		</form>
+    </div>
+    <div th:include="include::footer"></div>
+    <script type="text/javascript">
+		var prefix = ctx + "${moduleName}/${classname}";
+		$("#form-${classname}-edit").validate({
+			rules:{
+				xxxx:{
+					required:true,
+				},
+			},
+			focusCleanup: true
+		});
+		
+		function submitHandler() {
+	        if ($.validate.form()) {
+	            $.operate.save(prefix + "/edit", $('#form-${classname}-edit').serialize());
+	        }
+	    }
+	</script>
+</body>
+</html>

+ 133 - 0
wms-generator/src/main/resources/vm/html/list.html.vm

@@ -0,0 +1,133 @@
+<!DOCTYPE html>
+<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
+<head>
+	<th:block th:include="include :: header('${tableComment}列表')" />
+</head>
+<body class="gray-bg">
+    
+     <div class="container-div" onmousemove="parent.updateTimeOut()">
+		<div class="row">
+			<div class="col-sm-12 search-collapse">
+				<form id="formId">
+					<div class="select-list">
+						<ul>
+#foreach($column in $columns)
+#if($column.columnName != $primaryKey.columnName)
+#if(!${column.configInfo})
+							<li>
+								${column.columnComment}:<input type="text" name="${column.attrname}"/>
+							</li>
+
+#else
+#if(${column.configInfo.type} == "dict")
+							<li>
+								${column.columnComment}:<select name="${column.attrname}" th:with="type=${@dict.getType('${column.configInfo.value}')}">
+									<option value="">所有</option>
+									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
+								</select>
+							</li>
+#elseif(${column.configInfo.type} == "date")
+							<li class="select-time">
+								<label>${column.columnComment}: </label>
+								<input type="text" class="time-input" id="start${column.attrName}" placeholder="开始" name="params[begin${column.attrName}]"/>
+								<span>-</span>
+								<input type="text" class="time-input" id="end${column.attrName}" placeholder="结束" name="params[end${column.attrName}]"/>
+							</li>
+#elseif(${column.configInfo.type} == "fk")					
+#end
+#end
+#end
+#end
+							<li>
+								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
+								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
+							</li>
+						</ul>
+					</div>
+				</form>
+			</div>
+			
+	        <div class="btn-group-sm" id="toolbar" role="group">
+				<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="${moduleName}:${classname}:add">
+					<i class="fa fa-plus"></i> 添加
+				</a>
+				<a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()" shiro:hasPermission="${moduleName}:${classname}:edit">
+					<i class="fa fa-edit"></i> 修改
+				</a>
+				<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="${moduleName}:${classname}:remove">
+					<i class="fa fa-remove"></i> 删除
+				</a>
+				<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="${moduleName}:${classname}:export">
+						<i class="fa fa-download"></i> 导出
+				 </a>
+			</div>
+			<div class="col-sm-12 select-table table-striped">
+				<table id="bootstrap-table" data-mobile-responsive="true"></table>
+			</div>
+		</div>
+	</div>
+    <div th:include="include :: footer"></div>
+    <script th:inline="javascript">
+        var editFlag = [[${@permission.hasPermi('${moduleName}:${classname}:edit')}]];
+        var removeFlag = [[${@permission.hasPermi('${moduleName}:${classname}:remove')}]];
+        var prefix = ctx + "${moduleName}/${classname}";
+#foreach($column in $columns)
+#if(${column.configInfo} && ${column.configInfo.type} == 'dict')
+        var datas = [[${@dict.getType('${column.configInfo.value}')}]];
+#end
+#end
+
+        $(function() {
+            var options = {
+                url: prefix + "/list",
+                createUrl: prefix + "/add",
+                updateUrl: prefix + "/edit/{id}",
+                removeUrl: prefix + "/remove",
+				exportUrl: prefix + "/export",
+                modalName: "${tableComment}",
+		        showExport: true,
+                columns: [{
+		            checkbox: true
+		        },
+#foreach($column in $columns)
+#if($column.columnName == $primaryKey.columnName)
+				{
+					field : '${column.attrname}', 
+					title : '${column.columnComment}',
+					visible: false
+				},
+#elseif($column.columnName != $primaryKey.columnName)
+#if(${column.configInfo} && ${column.configInfo.type} == 'dict')
+				{
+					field : '${column.attrname}', 
+					title : '${column.columnComment}',
+					sortable: true,
+					formatter: function(value, row, index) {
+		            	return $.table.selectDictLabel(datas, value);
+		            }
+				},
+#else
+				{
+					field : '${column.attrname}', 
+					title : '${column.columnComment}',
+					sortable: true
+				},
+#end
+#end				
+#end
+		        {
+		            title: '操作',
+		            align: 'center',
+		            formatter: function(value, row, index) {
+		            	var actions = [];
+		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.${primaryKey.attrname} + '\')"><i class="fa fa-edit"></i>编辑</a> ');
+                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.${primaryKey.attrname} + '\')"><i class="fa fa-remove"></i>删除</a>');
+						return actions.join('');
+		            }
+		        }]
+            };
+            $.table.init(options);
+        });
+    </script>
+</body>
+</html>

+ 126 - 0
wms-generator/src/main/resources/vm/java/Controller.java.vm

@@ -0,0 +1,126 @@
+package ${basePackage}.web.controller.${moduleName};
+
+import java.util.List;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+import com.deer.wms.common.annotation.Log;
+import com.deer.wms.common.enums.BusinessType;
+import ${package}.domain.${className};
+import ${package}.service.I${className}Service;
+import com.deer.wms.common.core.controller.BaseController;
+import com.deer.wms.common.core.page.TableDataInfo;
+import com.deer.wms.common.core.domain.AjaxResult;
+import com.deer.wms.common.utils.poi.ExcelUtil;
+
+/**
+ * ${tableComment} 信息操作处理
+ * 
+ * @author ${author}
+ * @date ${datetime}
+ */
+@Controller
+@RequestMapping("/${moduleName}/${classname}")
+public class ${className}Controller extends BaseController
+{
+    private String prefix = "${moduleName}/${classname}";
+	
+	@Autowired
+	private I${className}Service ${classname}Service;
+	
+	@RequiresPermissions("${moduleName}:${classname}:view")
+	@GetMapping()
+	public String ${classname}()
+	{
+	    return prefix + "/${classname}";
+	}
+	
+	/**
+	 * 查询${tableComment}列表
+	 */
+	@RequiresPermissions("${moduleName}:${classname}:list")
+	@PostMapping("/list")
+	@ResponseBody
+	public TableDataInfo list(${className} ${classname})
+	{
+		startPage();
+        List<${className}> list = ${classname}Service.select${className}List(${classname});
+		return getDataTable(list);
+	}
+	
+	
+	/**
+	 * 导出${tableComment}列表
+	 */
+	@RequiresPermissions("${moduleName}:${classname}:export")
+    @PostMapping("/export")
+    @ResponseBody
+    public AjaxResult export(${className} ${classname})
+    {
+    	List<${className}> list = ${classname}Service.select${className}List(${classname});
+        ExcelUtil<${className}> util = new ExcelUtil<${className}>(${className}.class);
+        return util.exportExcel(list, "${classname}");
+    }
+	
+	/**
+	 * 新增${tableComment}
+	 */
+	@GetMapping("/add")
+	public String add()
+	{
+	    return prefix + "/add";
+	}
+	
+	/**
+	 * 新增保存${tableComment}
+	 */
+	@RequiresPermissions("${moduleName}:${classname}:add")
+	@Log(title = "${tableComment}", businessType = BusinessType.INSERT)
+	@PostMapping("/add")
+	@ResponseBody
+	public AjaxResult addSave(${className} ${classname})
+	{		
+		return toAjax(${classname}Service.insert${className}(${classname}));
+	}
+
+	/**
+	 * 修改${tableComment}
+	 */
+	@GetMapping("/edit/{${primaryKey.attrname}}")
+	public String edit(@PathVariable("${primaryKey.attrname}") ${primaryKey.attrType} ${primaryKey.attrname}, ModelMap mmap)
+	{
+		${className} ${classname} = ${classname}Service.select${className}ById(${primaryKey.attrname});
+		mmap.put("${classname}", ${classname});
+	    return prefix + "/edit";
+	}
+	
+	/**
+	 * 修改保存${tableComment}
+	 */
+	@RequiresPermissions("${moduleName}:${classname}:edit")
+	@Log(title = "${tableComment}", businessType = BusinessType.UPDATE)
+	@PostMapping("/edit")
+	@ResponseBody
+	public AjaxResult editSave(${className} ${classname})
+	{		
+		return toAjax(${classname}Service.update${className}(${classname}));
+	}
+	
+	/**
+	 * 删除${tableComment}
+	 */
+	@RequiresPermissions("${moduleName}:${classname}:remove")
+	@Log(title = "${tableComment}", businessType = BusinessType.DELETE)
+	@PostMapping( "/remove")
+	@ResponseBody
+	public AjaxResult remove(String ids)
+	{		
+		return toAjax(${classname}Service.delete${className}ByIds(ids));
+	}
+	
+}

+ 62 - 0
wms-generator/src/main/resources/vm/java/Mapper.java.vm

@@ -0,0 +1,62 @@
+package ${package}.mapper;
+
+import ${package}.domain.${className};
+import java.util.List;	
+
+/**
+ * ${tableComment} 数据层
+ * 
+ * @author ${author}
+ * @date ${datetime}
+ */
+public interface ${className}Mapper 
+{
+	/**
+     * 查询${tableComment}信息
+     * 
+     * @param ${primaryKey.attrname} ${tableComment}ID
+     * @return ${tableComment}信息
+     */
+	public ${className} select${className}ById(${primaryKey.attrType} ${primaryKey.attrname});
+	
+	/**
+     * 查询${tableComment}列表
+     * 
+     * @param ${classname} ${tableComment}信息
+     * @return ${tableComment}集合
+     */
+	public List<${className}> select${className}List(${className} ${classname});
+	
+	/**
+     * 新增${tableComment}
+     * 
+     * @param ${classname} ${tableComment}信息
+     * @return 结果
+     */
+	public int insert${className}(${className} ${classname});
+	
+	/**
+     * 修改${tableComment}
+     * 
+     * @param ${classname} ${tableComment}信息
+     * @return 结果
+     */
+	public int update${className}(${className} ${classname});
+	
+	/**
+     * 删除${tableComment}
+     * 
+     * @param ${primaryKey.attrname} ${tableComment}ID
+     * @return 结果
+     */
+	public int delete${className}ById(${primaryKey.attrType} ${primaryKey.attrname});
+	
+	/**
+     * 批量删除${tableComment}
+     * 
+     * @param ${primaryKey.attrname}s 需要删除的数据ID
+     * @return 结果
+     */
+	public int delete${className}ByIds(String[] ${primaryKey.attrname}s);
+	
+}

+ 54 - 0
wms-generator/src/main/resources/vm/java/Service.java.vm

@@ -0,0 +1,54 @@
+package ${package}.service;
+
+import ${package}.domain.${className};
+import java.util.List;
+
+/**
+ * ${tableComment} 服务层
+ * 
+ * @author ${author}
+ * @date ${datetime}
+ */
+public interface I${className}Service 
+{
+	/**
+     * 查询${tableComment}信息
+     * 
+     * @param ${primaryKey.attrname} ${tableComment}ID
+     * @return ${tableComment}信息
+     */
+	public ${className} select${className}ById(${primaryKey.attrType} ${primaryKey.attrname});
+	
+	/**
+     * 查询${tableComment}列表
+     * 
+     * @param ${classname} ${tableComment}信息
+     * @return ${tableComment}集合
+     */
+	public List<${className}> select${className}List(${className} ${classname});
+	
+	/**
+     * 新增${tableComment}
+     * 
+     * @param ${classname} ${tableComment}信息
+     * @return 结果
+     */
+	public int insert${className}(${className} ${classname});
+	
+	/**
+     * 修改${tableComment}
+     * 
+     * @param ${classname} ${tableComment}信息
+     * @return 结果
+     */
+	public int update${className}(${className} ${classname});
+		
+	/**
+     * 删除${tableComment}信息
+     * 
+     * @param ids 需要删除的数据ID
+     * @return 结果
+     */
+	public int delete${className}ByIds(String ids);
+	
+}

+ 83 - 0
wms-generator/src/main/resources/vm/java/ServiceImpl.java.vm

@@ -0,0 +1,83 @@
+package ${package}.service.impl;
+
+import java.util.List;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import ${package}.mapper.${className}Mapper;
+import ${package}.domain.${className};
+import ${package}.service.I${className}Service;
+import com.deer.wms.common.core.text.Convert;
+
+/**
+ * ${tableComment} 服务层实现
+ * 
+ * @author ${author}
+ * @date ${datetime}
+ */
+@Service
+public class ${className}ServiceImpl implements I${className}Service 
+{
+	@Autowired
+	private ${className}Mapper ${classname}Mapper;
+
+	/**
+     * 查询${tableComment}信息
+     * 
+     * @param ${primaryKey.attrname} ${tableComment}ID
+     * @return ${tableComment}信息
+     */
+    @Override
+	public ${className} select${className}ById(${primaryKey.attrType} ${primaryKey.attrname})
+	{
+	    return ${classname}Mapper.select${className}ById(${primaryKey.attrname});
+	}
+	
+	/**
+     * 查询${tableComment}列表
+     * 
+     * @param ${classname} ${tableComment}信息
+     * @return ${tableComment}集合
+     */
+	@Override
+	public List<${className}> select${className}List(${className} ${classname})
+	{
+	    return ${classname}Mapper.select${className}List(${classname});
+	}
+	
+    /**
+     * 新增${tableComment}
+     * 
+     * @param ${classname} ${tableComment}信息
+     * @return 结果
+     */
+	@Override
+	public int insert${className}(${className} ${classname})
+	{
+	    return ${classname}Mapper.insert${className}(${classname});
+	}
+	
+	/**
+     * 修改${tableComment}
+     * 
+     * @param ${classname} ${tableComment}信息
+     * @return 结果
+     */
+	@Override
+	public int update${className}(${className} ${classname})
+	{
+	    return ${classname}Mapper.update${className}(${classname});
+	}
+
+	/**
+     * 删除${tableComment}对象
+     * 
+     * @param ids 需要删除的数据ID
+     * @return 结果
+     */
+	@Override
+	public int delete${className}ByIds(String ids)
+	{
+		return ${classname}Mapper.delete${className}ByIds(Convert.toStrArray(ids));
+	}
+	
+}

+ 56 - 0
wms-generator/src/main/resources/vm/java/domain.java.vm

@@ -0,0 +1,56 @@
+package ${package}.domain;
+
+
+import javax.persistence.*;
+
+#foreach ($column in $columns)
+#if($column.attrType == 'Date' && ($column.attrname != 'createBy' && $column.attrname != 'createTime' && $column.attrname != 'updateBy' && $column.attrname != 'updateTime' && $column.attrname != 'remark'))
+    #break
+#end
+#end
+#foreach ($column in $columns)
+#if($column.attrType == 'BigDecimal')
+    #break
+#end
+#end
+
+/**
+ * ${tableComment}表 ${tableName}
+ * 
+ * @author ${author}
+ * @date ${datetime}
+ */
+@Table(name = "${tableName}")
+public class ${className} extends BaseEntity
+{
+	private static final long serialVersionUID = 1L;
+	
+#foreach ($column in $columns)
+#if($column.attrname != 'createBy' && $column.attrname != 'createTime' && $column.attrname != 'updateBy' && $column.attrname != 'updateTime' && $column.attrname != 'remark')
+	/** $column.columnComment */
+	private $column.attrType $column.attrname;
+#end
+#end
+
+#foreach ($column in $columns)
+#if($column.attrname != 'createBy' && $column.attrname != 'createTime' && $column.attrname != 'updateBy' && $column.attrname != 'updateTime' && $column.attrname != 'remark')
+	public void set${column.attrName}($column.attrType $column.attrname) 
+	{
+		this.$column.attrname = $column.attrname;
+	}
+
+	public $column.attrType get${column.attrName}() 
+	{
+		return $column.attrname;
+	}
+#end
+#end
+
+    public String toString() {
+        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
+#foreach ($column in $columns)
+            .append("${column.attrname}", get${column.attrName}())
+#end
+            .toString();
+    }
+}

+ 19 - 0
wms-generator/src/main/resources/vm/sql/sql.vm

@@ -0,0 +1,19 @@
+-- 菜单 SQL
+insert into sys_menu (menu_name, parent_id, order_num, url,menu_type, visible, perms, icon, create_by, create_time, update_by, update_time, remark)
+values('${tableComment}', '3', '1', '/${moduleName}/${classname}', 'C', '0', '${moduleName}:${classname}:view', '#', 'admin', '2018-03-01', 'ry', '2018-03-01', '${tableComment}菜单');
+
+-- 按钮父菜单ID
+SELECT @parentId := LAST_INSERT_ID();
+
+-- 按钮 SQL
+insert into sys_menu  (menu_name, parent_id, order_num, url,menu_type, visible, perms, icon, create_by, create_time, update_by, update_time, remark)
+values('${tableComment}查询', @parentId, '1',  '#',  'F', '0', '${moduleName}:${classname}:list',         '#', 'admin', '2018-03-01', 'ry', '2018-03-01', '');
+
+insert into sys_menu  (menu_name, parent_id, order_num, url,menu_type, visible, perms, icon, create_by, create_time, update_by, update_time, remark)
+values('${tableComment}新增', @parentId, '2',  '#',  'F', '0', '${moduleName}:${classname}:add',          '#', 'admin', '2018-03-01', 'ry', '2018-03-01', '');
+
+insert into sys_menu  (menu_name, parent_id, order_num, url,menu_type, visible, perms, icon, create_by, create_time, update_by, update_time, remark)
+values('${tableComment}修改', @parentId, '3',  '#',  'F', '0', '${moduleName}:${classname}:edit',         '#', 'admin', '2018-03-01', 'ry', '2018-03-01', '');
+
+insert into sys_menu  (menu_name, parent_id, order_num, url,menu_type, visible, perms, icon, create_by, create_time, update_by, update_time, remark)
+values('${tableComment}删除', @parentId, '4',  '#',  'F', '0', '${moduleName}:${classname}:remove',       '#', 'admin', '2018-03-01', 'ry', '2018-03-01', '');

+ 72 - 0
wms-generator/src/main/resources/vm/xml/Mapper.xml.vm

@@ -0,0 +1,72 @@
+<?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="${package}.mapper.${className}Mapper">
+    
+    <resultMap type="${className}" id="${className}Result">
+#foreach ($column in $columns)
+        <result property="${column.attrname}"    column="${column.columnName}"    />
+#end
+    </resultMap>
+	
+	<sql id="select${className}Vo">
+        select#foreach($column in $columns) $column.columnName#if($velocityCount != $columns.size()),#end#end from ${tableName}
+    </sql>
+	
+    <select id="select${className}List" parameterType="${className}" resultMap="${className}Result">
+        <include refid="select${className}Vo"/>
+        <where>  
+#foreach($column in $columns)
+            <if test="$column.attrname != null #if($column.attrType == 'String' ) and $column.attrname.trim() != '' #end"> and $column.columnName = #{$column.attrname}</if>
+ #end
+        </where>
+    </select>
+    
+    <select id="select${className}ById" parameterType="${primaryKey.attrType}" resultMap="${className}Result">
+        <include refid="select${className}Vo"/>
+        where ${primaryKey.columnName} = #{${primaryKey.attrname}}
+    </select>
+        
+    <insert id="insert${className}" parameterType="${className}"#if($primaryKey.extra == 'auto_increment') useGeneratedKeys="true" keyProperty="$primaryKey.attrname"#end>
+        insert into ${tableName}
+		<trim prefix="(" suffix=")" suffixOverrides=",">
+#foreach($column in $columns)
+#if($column.columnName != $primaryKey.columnName || $primaryKey.extra != 'auto_increment')
+			<if test="$column.attrname != null #if($column.attrType == 'String' ) and $column.attrname != '' #end ">$column.columnName,</if>
+#end
+#end
+         </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+#foreach($column in $columns)
+#if($column.columnName != $primaryKey.columnName || $primaryKey.extra != 'auto_increment')
+			<if test="$column.attrname != null #if($column.attrType == 'String' ) and $column.attrname != '' #end ">#{$column.attrname},</if>
+#end			
+#end
+         </trim>
+    </insert>
+	 
+    <update id="update${className}" parameterType="${className}">
+        update ${tableName}
+        <trim prefix="SET" suffixOverrides=",">
+#foreach($column in $columns)
+#if($column.columnName != $primaryKey.columnName)
+            <if test="$column.attrname != null #if($column.attrType == 'String' ) and $column.attrname != '' #end ">$column.columnName = #{$column.attrname},</if>
+#end
+#end
+        </trim>
+        where ${primaryKey.columnName} = #{${primaryKey.attrname}}
+    </update>
+
+	<delete id="delete${className}ById" parameterType="${primaryKey.attrType}">
+        delete from ${tableName} where ${primaryKey.columnName} = #{${primaryKey.attrname}}
+    </delete>
+	
+    <delete id="delete${className}ByIds" parameterType="String">
+        delete from ${tableName} where ${primaryKey.columnName} in 
+        <foreach item="${primaryKey.attrname}" collection="array" open="(" separator="," close=")">
+            #{${primaryKey.attrname}}
+        </foreach>
+    </delete>
+    
+</mapper>