mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 02:08:43 +08:00 
			
		
		
		
	整理 vm 模板
提交 test 生成的示例
This commit is contained in:
		| @@ -5,6 +5,7 @@ import java.util.HashMap; | |||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
| import javax.servlet.http.HttpServletResponse; | import javax.servlet.http.HttpServletResponse; | ||||||
|  |  | ||||||
| import org.apache.commons.io.IOUtils; | import org.apache.commons.io.IOUtils; | ||||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||||
| import org.springframework.security.access.prepost.PreAuthorize; | import org.springframework.security.access.prepost.PreAuthorize; | ||||||
| @@ -35,8 +36,7 @@ import com.ruoyi.generator.service.IGenTableService; | |||||||
|  */ |  */ | ||||||
| @RestController | @RestController | ||||||
| @RequestMapping("/tool/gen") | @RequestMapping("/tool/gen") | ||||||
| public class GenController extends BaseController | public class GenController extends BaseController { | ||||||
| { |  | ||||||
|     @Autowired |     @Autowired | ||||||
|     private IGenTableService genTableService; |     private IGenTableService genTableService; | ||||||
|  |  | ||||||
| @@ -48,8 +48,7 @@ public class GenController extends BaseController | |||||||
|      */ |      */ | ||||||
|     @PreAuthorize("@ss.hasPermi('tool:gen:list')") |     @PreAuthorize("@ss.hasPermi('tool:gen:list')") | ||||||
|     @GetMapping("/list") |     @GetMapping("/list") | ||||||
|     public TableDataInfo genList(GenTable genTable) |     public TableDataInfo genList(GenTable genTable) { | ||||||
|     { |  | ||||||
|         startPage(); |         startPage(); | ||||||
|         List<GenTable> list = genTableService.selectGenTableList(genTable); |         List<GenTable> list = genTableService.selectGenTableList(genTable); | ||||||
|         return getDataTable(list); |         return getDataTable(list); | ||||||
| @@ -60,8 +59,7 @@ public class GenController extends BaseController | |||||||
|      */ |      */ | ||||||
|     @PreAuthorize("@ss.hasPermi('tool:gen:query')") |     @PreAuthorize("@ss.hasPermi('tool:gen:query')") | ||||||
|     @GetMapping(value = "/{talbleId}") |     @GetMapping(value = "/{talbleId}") | ||||||
|     public AjaxResult getInfo(@PathVariable Long talbleId) |     public AjaxResult getInfo(@PathVariable Long talbleId) { | ||||||
|     { |  | ||||||
|         GenTable table = genTableService.selectGenTableById(talbleId); |         GenTable table = genTableService.selectGenTableById(talbleId); | ||||||
|         List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(talbleId); |         List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(talbleId); | ||||||
|         Map<String, Object> map = new HashMap<String, Object>(); |         Map<String, Object> map = new HashMap<String, Object>(); | ||||||
| @@ -75,8 +73,7 @@ public class GenController extends BaseController | |||||||
|      */ |      */ | ||||||
|     @PreAuthorize("@ss.hasPermi('tool:gen:list')") |     @PreAuthorize("@ss.hasPermi('tool:gen:list')") | ||||||
|     @GetMapping("/db/list") |     @GetMapping("/db/list") | ||||||
|     public TableDataInfo dataList(GenTable genTable) |     public TableDataInfo dataList(GenTable genTable) { | ||||||
|     { |  | ||||||
|         startPage(); |         startPage(); | ||||||
|         List<GenTable> list = genTableService.selectDbTableList(genTable); |         List<GenTable> list = genTableService.selectDbTableList(genTable); | ||||||
|         return getDataTable(list); |         return getDataTable(list); | ||||||
| @@ -87,8 +84,7 @@ public class GenController extends BaseController | |||||||
|      */ |      */ | ||||||
|     @PreAuthorize("@ss.hasPermi('tool:gen:list')") |     @PreAuthorize("@ss.hasPermi('tool:gen:list')") | ||||||
|     @GetMapping(value = "/column/{talbleId}") |     @GetMapping(value = "/column/{talbleId}") | ||||||
|     public TableDataInfo columnList(Long tableId) |     public TableDataInfo columnList(Long tableId) { | ||||||
|     { |  | ||||||
|         TableDataInfo dataInfo = new TableDataInfo(); |         TableDataInfo dataInfo = new TableDataInfo(); | ||||||
|         List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId); |         List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId); | ||||||
|         dataInfo.setRows(list); |         dataInfo.setRows(list); | ||||||
| @@ -102,8 +98,7 @@ public class GenController extends BaseController | |||||||
|     @PreAuthorize("@ss.hasPermi('tool:gen:list')") |     @PreAuthorize("@ss.hasPermi('tool:gen:list')") | ||||||
|     @Log(title = "代码生成", businessType = BusinessType.IMPORT) |     @Log(title = "代码生成", businessType = BusinessType.IMPORT) | ||||||
|     @PostMapping("/importTable") |     @PostMapping("/importTable") | ||||||
|     public AjaxResult importTableSave(String tables) |     public AjaxResult importTableSave(String tables) { | ||||||
|     { |  | ||||||
|         String[] tableNames = Convert.toStrArray(tables); |         String[] tableNames = Convert.toStrArray(tables); | ||||||
|         // 查询表信息 |         // 查询表信息 | ||||||
|         List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames); |         List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames); | ||||||
| @@ -117,8 +112,7 @@ public class GenController extends BaseController | |||||||
|     @PreAuthorize("@ss.hasPermi('tool:gen:edit')") |     @PreAuthorize("@ss.hasPermi('tool:gen:edit')") | ||||||
|     @Log(title = "代码生成", businessType = BusinessType.UPDATE) |     @Log(title = "代码生成", businessType = BusinessType.UPDATE) | ||||||
|     @PutMapping |     @PutMapping | ||||||
|     public AjaxResult editSave(@Validated @RequestBody GenTable genTable) |     public AjaxResult editSave(@Validated @RequestBody GenTable genTable) { | ||||||
|     { |  | ||||||
|         genTableService.validateEdit(genTable); |         genTableService.validateEdit(genTable); | ||||||
|         genTableService.updateGenTable(genTable); |         genTableService.updateGenTable(genTable); | ||||||
|         return AjaxResult.success(); |         return AjaxResult.success(); | ||||||
| @@ -130,8 +124,7 @@ public class GenController extends BaseController | |||||||
|     @PreAuthorize("@ss.hasPermi('tool:gen:remove')") |     @PreAuthorize("@ss.hasPermi('tool:gen:remove')") | ||||||
|     @Log(title = "代码生成", businessType = BusinessType.DELETE) |     @Log(title = "代码生成", businessType = BusinessType.DELETE) | ||||||
|     @DeleteMapping("/{tableIds}") |     @DeleteMapping("/{tableIds}") | ||||||
|     public AjaxResult remove(@PathVariable Long[] tableIds) |     public AjaxResult remove(@PathVariable Long[] tableIds) { | ||||||
|     { |  | ||||||
|         genTableService.deleteGenTableByIds(tableIds); |         genTableService.deleteGenTableByIds(tableIds); | ||||||
|         return AjaxResult.success(); |         return AjaxResult.success(); | ||||||
|     } |     } | ||||||
| @@ -141,8 +134,7 @@ public class GenController extends BaseController | |||||||
|      */ |      */ | ||||||
|     @PreAuthorize("@ss.hasPermi('tool:gen:preview')") |     @PreAuthorize("@ss.hasPermi('tool:gen:preview')") | ||||||
|     @GetMapping("/preview/{tableId}") |     @GetMapping("/preview/{tableId}") | ||||||
|     public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException |     public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException { | ||||||
|     { |  | ||||||
|         Map<String, String> dataMap = genTableService.previewCode(tableId); |         Map<String, String> dataMap = genTableService.previewCode(tableId); | ||||||
|         return AjaxResult.success(dataMap); |         return AjaxResult.success(dataMap); | ||||||
|     } |     } | ||||||
| @@ -153,8 +145,7 @@ public class GenController extends BaseController | |||||||
|     @PreAuthorize("@ss.hasPermi('tool:gen:code')") |     @PreAuthorize("@ss.hasPermi('tool:gen:code')") | ||||||
|     @Log(title = "代码生成", businessType = BusinessType.GENCODE) |     @Log(title = "代码生成", businessType = BusinessType.GENCODE) | ||||||
|     @GetMapping("/download/{tableName}") |     @GetMapping("/download/{tableName}") | ||||||
|     public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException |     public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException { | ||||||
|     { |  | ||||||
|         byte[] data = genTableService.downloadCode(tableName); |         byte[] data = genTableService.downloadCode(tableName); | ||||||
|         genCode(response, data); |         genCode(response, data); | ||||||
|     } |     } | ||||||
| @@ -165,8 +156,7 @@ public class GenController extends BaseController | |||||||
|     @PreAuthorize("@ss.hasPermi('tool:gen:code')") |     @PreAuthorize("@ss.hasPermi('tool:gen:code')") | ||||||
|     @Log(title = "代码生成", businessType = BusinessType.GENCODE) |     @Log(title = "代码生成", businessType = BusinessType.GENCODE) | ||||||
|     @GetMapping("/genCode/{tableName}") |     @GetMapping("/genCode/{tableName}") | ||||||
|     public AjaxResult genCode(@PathVariable("tableName") String tableName) |     public AjaxResult genCode(@PathVariable("tableName") String tableName) { | ||||||
|     { |  | ||||||
|         genTableService.generatorCode(tableName); |         genTableService.generatorCode(tableName); | ||||||
|         return AjaxResult.success(); |         return AjaxResult.success(); | ||||||
|     } |     } | ||||||
| @@ -177,8 +167,7 @@ public class GenController extends BaseController | |||||||
|     @PreAuthorize("@ss.hasPermi('tool:gen:edit')") |     @PreAuthorize("@ss.hasPermi('tool:gen:edit')") | ||||||
|     @Log(title = "代码生成", businessType = BusinessType.UPDATE) |     @Log(title = "代码生成", businessType = BusinessType.UPDATE) | ||||||
|     @GetMapping("/synchDb/{tableName}") |     @GetMapping("/synchDb/{tableName}") | ||||||
|     public AjaxResult synchDb(@PathVariable("tableName") String tableName) |     public AjaxResult synchDb(@PathVariable("tableName") String tableName) { | ||||||
|     { |  | ||||||
|         genTableService.synchDb(tableName); |         genTableService.synchDb(tableName); | ||||||
|         return AjaxResult.success(); |         return AjaxResult.success(); | ||||||
|     } |     } | ||||||
| @@ -189,8 +178,7 @@ public class GenController extends BaseController | |||||||
|     @PreAuthorize("@ss.hasPermi('tool:gen:code')") |     @PreAuthorize("@ss.hasPermi('tool:gen:code')") | ||||||
|     @Log(title = "代码生成", businessType = BusinessType.GENCODE) |     @Log(title = "代码生成", businessType = BusinessType.GENCODE) | ||||||
|     @GetMapping("/batchGenCode") |     @GetMapping("/batchGenCode") | ||||||
|     public void batchGenCode(HttpServletResponse response, String tables) throws IOException |     public void batchGenCode(HttpServletResponse response, String tables) throws IOException { | ||||||
|     { |  | ||||||
|         String[] tableNames = Convert.toStrArray(tables); |         String[] tableNames = Convert.toStrArray(tables); | ||||||
|         byte[] data = genTableService.downloadCode(tableNames); |         byte[] data = genTableService.downloadCode(tableNames); | ||||||
|         genCode(response, data); |         genCode(response, data); | ||||||
| @@ -199,8 +187,7 @@ public class GenController extends BaseController | |||||||
|     /** |     /** | ||||||
|      * 生成zip文件 |      * 生成zip文件 | ||||||
|      */ |      */ | ||||||
|     private void genCode(HttpServletResponse response, byte[] data) throws IOException |     private void genCode(HttpServletResponse response, byte[] data) throws IOException { | ||||||
|     { |  | ||||||
|         response.reset(); |         response.reset(); | ||||||
|         response.addHeader("Access-Control-Allow-Origin", "*"); |         response.addHeader("Access-Control-Allow-Origin", "*"); | ||||||
|         response.addHeader("Access-Control-Expose-Headers", "Content-Disposition"); |         response.addHeader("Access-Control-Expose-Headers", "Content-Disposition"); | ||||||
|   | |||||||
| @@ -22,11 +22,6 @@ public class GenTable extends BaseEntity { | |||||||
|     @NotBlank(message = "生成包路径不能为空") |     @NotBlank(message = "生成包路径不能为空") | ||||||
|     private String packageName; |     private String packageName; | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 主键信息 |  | ||||||
|      */ |  | ||||||
|     private GenTableColumn pkColumn; |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 其它生成选项 |      * 其它生成选项 | ||||||
|      */ |      */ | ||||||
| @@ -57,31 +52,4 @@ public class GenTable extends BaseEntity { | |||||||
|      */ |      */ | ||||||
|     private String parentMenuName; |     private String parentMenuName; | ||||||
|  |  | ||||||
|     public boolean isTree() { |  | ||||||
|         return isTree(this.tplCategory); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public static boolean isTree(String tplCategory) { |  | ||||||
|         return tplCategory != null && StringUtils.equals(GenConstants.TPL_TREE, tplCategory); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public boolean isCrud() { |  | ||||||
|         return isCrud(this.tplCategory); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public static boolean isCrud(String tplCategory) { |  | ||||||
|         return tplCategory != null && StringUtils.equals(GenConstants.TPL_CRUD, tplCategory); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public boolean isSuperColumn(String javaField) { |  | ||||||
|         return isSuperColumn(this.tplCategory, javaField); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public static boolean isSuperColumn(String tplCategory, String javaField) { |  | ||||||
|         if (isTree(tplCategory)) { |  | ||||||
|             return StringUtils.equalsAnyIgnoreCase(javaField, |  | ||||||
|                     ArrayUtils.addAll(GenConstants.TREE_ENTITY, GenConstants.BASE_ENTITY)); |  | ||||||
|         } |  | ||||||
|         return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY); |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,61 +0,0 @@ | |||||||
| package ${packageName}.service; |  | ||||||
|  |  | ||||||
| import java.util.List; |  | ||||||
| import ${packageName}.domain.${ClassName}; |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * ${functionName}Service接口 |  | ||||||
|  *  |  | ||||||
|  * @author ${author} |  | ||||||
|  * @date ${datetime} |  | ||||||
|  */ |  | ||||||
| public interface I${ClassName}Service  |  | ||||||
| { |  | ||||||
|     /** |  | ||||||
|      * 查询${functionName} |  | ||||||
|      *  |  | ||||||
|      * @param ${pkColumn.javaField} ${functionName}ID |  | ||||||
|      * @return ${functionName} |  | ||||||
|      */ |  | ||||||
|     public ${ClassName} select${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}); |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 查询${functionName}列表 |  | ||||||
|      *  |  | ||||||
|      * @param ${className} ${functionName} |  | ||||||
|      * @return ${functionName}集合 |  | ||||||
|      */ |  | ||||||
|     public List<${ClassName}> select${ClassName}List(${ClassName} ${className}); |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 新增${functionName} |  | ||||||
|      *  |  | ||||||
|      * @param ${className} ${functionName} |  | ||||||
|      * @return 结果 |  | ||||||
|      */ |  | ||||||
|     public int insert${ClassName}(${ClassName} ${className}); |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 修改${functionName} |  | ||||||
|      *  |  | ||||||
|      * @param ${className} ${functionName} |  | ||||||
|      * @return 结果 |  | ||||||
|      */ |  | ||||||
|     public int update${ClassName}(${ClassName} ${className}); |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 批量删除${functionName} |  | ||||||
|      *  |  | ||||||
|      * @param ${pkColumn.javaField}s 需要删除的${functionName}ID |  | ||||||
|      * @return 结果 |  | ||||||
|      */ |  | ||||||
|     public int delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s); |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 删除${functionName}信息 |  | ||||||
|      *  |  | ||||||
|      * @param ${pkColumn.javaField} ${functionName}ID |  | ||||||
|      * @return 结果 |  | ||||||
|      */ |  | ||||||
|     public int delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}); |  | ||||||
| } |  | ||||||
| @@ -1,95 +0,0 @@ | |||||||
| <?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="${packageName}.mapper.${ClassName}Mapper"> |  | ||||||
|      |  | ||||||
|     <resultMap type="${ClassName}" id="${ClassName}Result"> |  | ||||||
| #foreach ($column in $columns) |  | ||||||
|         <result property="${column.javaField}"    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) |  | ||||||
| #set($queryType=$column.queryType) |  | ||||||
| #set($javaField=$column.javaField) |  | ||||||
| #set($javaType=$column.javaType) |  | ||||||
| #set($columnName=$column.columnName) |  | ||||||
| #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) |  | ||||||
| #if($column.query) |  | ||||||
| #if($column.queryType == "EQ") |  | ||||||
|             <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName = #{$javaField}</if> |  | ||||||
| #elseif($queryType == "NE") |  | ||||||
|             <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName != #{$javaField}</if> |  | ||||||
| #elseif($queryType == "GT") |  | ||||||
|             <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName > #{$javaField}</if> |  | ||||||
| #elseif($queryType == "GTE") |  | ||||||
|             <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName >= #{$javaField}</if> |  | ||||||
| #elseif($queryType == "LT") |  | ||||||
|             <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName < #{$javaField}</if> |  | ||||||
| #elseif($queryType == "LTE") |  | ||||||
|             <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName <= #{$javaField}</if> |  | ||||||
| #elseif($queryType == "LIKE") |  | ||||||
|             <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName like concat('%', #{$javaField}, '%')</if> |  | ||||||
| #elseif($queryType == "BETWEEN") |  | ||||||
|             <if test="params.begin$AttrName != null and params.begin$AttrName != '' and params.end$AttrName != null and params.end$AttrName != ''"> and $columnName between #{params.begin$AttrName} and #{params.end$AttrName}</if> |  | ||||||
| #end |  | ||||||
| #end |  | ||||||
| #end |  | ||||||
|         </where> |  | ||||||
|     </select> |  | ||||||
|      |  | ||||||
|     <select id="select${ClassName}ById" parameterType="${pkColumn.javaType}" resultMap="${ClassName}Result"> |  | ||||||
|         <include refid="select${ClassName}Vo"/> |  | ||||||
|         where ${pkColumn.columnName} = #{${pkColumn.javaField}} |  | ||||||
|     </select> |  | ||||||
|          |  | ||||||
|     <insert id="insert${ClassName}" parameterType="${ClassName}"#if($pkColumn.increment) useGeneratedKeys="true" keyProperty="$pkColumn.javaField"#end> |  | ||||||
|         insert into ${tableName} |  | ||||||
|         <trim prefix="(" suffix=")" suffixOverrides=","> |  | ||||||
| #foreach($column in $columns) |  | ||||||
| #if($column.columnName != $pkColumn.columnName || !$pkColumn.increment) |  | ||||||
|             <if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">$column.columnName,</if> |  | ||||||
| #end |  | ||||||
| #end |  | ||||||
|          </trim> |  | ||||||
|         <trim prefix="values (" suffix=")" suffixOverrides=","> |  | ||||||
| #foreach($column in $columns) |  | ||||||
| #if($column.columnName != $pkColumn.columnName || !$pkColumn.increment) |  | ||||||
|             <if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">#{$column.javaField},</if> |  | ||||||
| #end |  | ||||||
| #end |  | ||||||
|          </trim> |  | ||||||
|     </insert> |  | ||||||
|  |  | ||||||
|     <update id="update${ClassName}" parameterType="${ClassName}"> |  | ||||||
|         update ${tableName} |  | ||||||
|         <trim prefix="SET" suffixOverrides=","> |  | ||||||
| #foreach($column in $columns) |  | ||||||
| #if($column.columnName != $pkColumn.columnName) |  | ||||||
|             <if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">$column.columnName = #{$column.javaField},</if> |  | ||||||
| #end |  | ||||||
| #end |  | ||||||
|         </trim> |  | ||||||
|         where ${pkColumn.columnName} = #{${pkColumn.javaField}} |  | ||||||
|     </update> |  | ||||||
|  |  | ||||||
|     <delete id="delete${ClassName}ById" parameterType="${pkColumn.javaType}"> |  | ||||||
|         delete from ${tableName} where ${pkColumn.columnName} = #{${pkColumn.javaField}} |  | ||||||
|     </delete> |  | ||||||
|  |  | ||||||
|     <delete id="delete${ClassName}ByIds" parameterType="String"> |  | ||||||
|         delete from ${tableName} where ${pkColumn.columnName} in  |  | ||||||
|         <foreach item="${pkColumn.javaField}" collection="array" open="(" separator="," close=")"> |  | ||||||
|             #{${pkColumn.javaField}} |  | ||||||
|         </foreach> |  | ||||||
|     </delete> |  | ||||||
|      |  | ||||||
| </mapper> |  | ||||||
| @@ -1 +0,0 @@ | |||||||
| package cn.iocoder.dashboard.modules.infra.convert; |  | ||||||
| @@ -0,0 +1 @@ | |||||||
|  | package cn.iocoder.dashboard.modules.system.controller.test; | ||||||
| @@ -0,0 +1,30 @@ | |||||||
|  | package cn.iocoder.dashboard.modules.system.controller.test.vo; | ||||||
|  |  | ||||||
|  | import io.swagger.annotations.ApiModelProperty; | ||||||
|  | import lombok.Data; | ||||||
|  |  | ||||||
|  | import javax.validation.constraints.NotNull; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  | * 字典类型 Base VO,提供给添加、修改、详细的子 VO 使用 | ||||||
|  | * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | ||||||
|  | */ | ||||||
|  | @Data | ||||||
|  | public class SysTestDemoBaseVO { | ||||||
|  |  | ||||||
|  |     @ApiModelProperty(value = "字典名称", required = true, example = "性别额") | ||||||
|  |     @NotNull(message = "字典名称不能为空") | ||||||
|  |     private String name; | ||||||
|  |  | ||||||
|  |     @ApiModelProperty(value = "字典类型", required = true, example = "sys_sex") | ||||||
|  |     @NotNull(message = "字典类型不能为空") | ||||||
|  |     private String dictType; | ||||||
|  |  | ||||||
|  |     @ApiModelProperty(value = "状态", required = true, example = "1") | ||||||
|  |     @NotNull(message = "状态不能为空") | ||||||
|  |     private Integer status; | ||||||
|  |  | ||||||
|  |     @ApiModelProperty(value = "备注", example = "我是备注") | ||||||
|  |     private String remark; | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -0,0 +1,14 @@ | |||||||
|  | package cn.iocoder.dashboard.modules.system.controller.test.vo; | ||||||
|  |  | ||||||
|  | import io.swagger.annotations.ApiModel; | ||||||
|  | import lombok.Data; | ||||||
|  | import lombok.EqualsAndHashCode; | ||||||
|  | import lombok.ToString; | ||||||
|  |  | ||||||
|  | @ApiModel("字典类型创建 Request VO") | ||||||
|  | @Data | ||||||
|  | @EqualsAndHashCode(callSuper = true) | ||||||
|  | @ToString(callSuper = true) | ||||||
|  | public class SysTestDemoCreateReqVO extends SysTestDemoBaseVO { | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -0,0 +1,41 @@ | |||||||
|  | package cn.iocoder.dashboard.modules.system.controller.test.vo; | ||||||
|  |  | ||||||
|  | import cn.iocoder.dashboard.common.pojo.PageParam; | ||||||
|  | import io.swagger.annotations.ApiModel; | ||||||
|  | import io.swagger.annotations.ApiModelProperty; | ||||||
|  | import lombok.Data; | ||||||
|  | import lombok.EqualsAndHashCode; | ||||||
|  | import lombok.ToString; | ||||||
|  | import org.springframework.format.annotation.DateTimeFormat; | ||||||
|  |  | ||||||
|  | import java.util.Date; | ||||||
|  |  | ||||||
|  | import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | ||||||
|  |  | ||||||
|  | @ApiModel("字典类型分页 Request VO") | ||||||
|  | @Data | ||||||
|  | @EqualsAndHashCode(callSuper = true) | ||||||
|  | @ToString(callSuper = true) | ||||||
|  | public class SysTestDemoPageReqVO extends PageParam { | ||||||
|  |  | ||||||
|  |     @ApiModelProperty(value = "字典名称", example = "性别额") | ||||||
|  |     private String name; | ||||||
|  |  | ||||||
|  |     @ApiModelProperty(value = "字典类型", example = "sys_sex") | ||||||
|  |     private String dictType; | ||||||
|  |  | ||||||
|  |     @ApiModelProperty(value = "状态", example = "1") | ||||||
|  |     private Integer status; | ||||||
|  |  | ||||||
|  |     @ApiModelProperty(value = "备注", example = "我是备注") | ||||||
|  |     private String remark; | ||||||
|  |  | ||||||
|  |     @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||||||
|  |     @ApiModelProperty(value = "开始创建时间") | ||||||
|  |     private Date beginCreateTime; | ||||||
|  |  | ||||||
|  |     @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||||||
|  |     @ApiModelProperty(value = "结束创建时间") | ||||||
|  |     private Date endCreateTime; | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -0,0 +1,19 @@ | |||||||
|  | package cn.iocoder.dashboard.modules.system.controller.test.vo; | ||||||
|  |  | ||||||
|  | import lombok.*; | ||||||
|  | import java.util.*; | ||||||
|  | import io.swagger.annotations.*; | ||||||
|  |  | ||||||
|  | @ApiModel("字典类型 Response VO") | ||||||
|  | @Data | ||||||
|  | @EqualsAndHashCode(callSuper = true) | ||||||
|  | @ToString(callSuper = true) | ||||||
|  | public class SysTestDemoRespVO extends SysTestDemoBaseVO { | ||||||
|  |  | ||||||
|  |     @ApiModelProperty(value = "字典主键", required = true, example = "1") | ||||||
|  |     private Long id; | ||||||
|  |  | ||||||
|  |     @ApiModelProperty(value = "创建时间", required = true) | ||||||
|  |     private Date createTime; | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -0,0 +1,21 @@ | |||||||
|  | package cn.iocoder.dashboard.modules.system.controller.test.vo; | ||||||
|  |  | ||||||
|  | import io.swagger.annotations.ApiModel; | ||||||
|  | import io.swagger.annotations.ApiModelProperty; | ||||||
|  | import lombok.Data; | ||||||
|  | import lombok.EqualsAndHashCode; | ||||||
|  | import lombok.ToString; | ||||||
|  |  | ||||||
|  | import javax.validation.constraints.NotNull; | ||||||
|  |  | ||||||
|  | @ApiModel("字典类型更新 Request VO") | ||||||
|  | @Data | ||||||
|  | @EqualsAndHashCode(callSuper = true) | ||||||
|  | @ToString(callSuper = true) | ||||||
|  | public class SysTestDemoUpdateReqVO extends SysTestDemoBaseVO { | ||||||
|  |  | ||||||
|  |     @ApiModelProperty(value = "字典主键", required = true, example = "1") | ||||||
|  |     @NotNull(message = "字典主键不能为空") | ||||||
|  |     private Long id; | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -0,0 +1,28 @@ | |||||||
|  | package cn.iocoder.dashboard.modules.system.dal.mysql.dao.test; | ||||||
|  |  | ||||||
|  | import cn.iocoder.dashboard.common.pojo.PageResult; | ||||||
|  | import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX; | ||||||
|  | import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX; | ||||||
|  | import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.test.SysTestDemoDO; | ||||||
|  | import org.apache.ibatis.annotations.Mapper; | ||||||
|  | import cn.iocoder.dashboard.modules.system.controller.test.vo.SysTestDemoPageReqVO; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  | * 字典类型 Mapper | ||||||
|  | * | ||||||
|  | * @author 芋艿 | ||||||
|  | */ | ||||||
|  | @Mapper | ||||||
|  | public interface SysTestDemoMapper extends BaseMapperX<SysTestDemoDO> { | ||||||
|  |  | ||||||
|  |     default PageResult<SysTestDemoDO> selectPage(SysTestDemoPageReqVO reqVO) { | ||||||
|  |         return selectPage(reqVO, new QueryWrapperX<SysTestDemoDO>() | ||||||
|  |             .likeIfPresent("name", reqVO.getName()) | ||||||
|  |             .eqIfPresent("dict_type", reqVO.getDictType()) | ||||||
|  |             .eqIfPresent("status", reqVO.getStatus()) | ||||||
|  |             .eqIfPresent("remark", reqVO.getRemark()) | ||||||
|  |             .betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) | ||||||
|  |         ); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -0,0 +1,44 @@ | |||||||
|  | package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.test; | ||||||
|  |  | ||||||
|  | import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO; | ||||||
|  | import com.baomidou.mybatisplus.annotation.TableId; | ||||||
|  | import com.baomidou.mybatisplus.annotation.TableName; | ||||||
|  | import lombok.*; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  | * 字典类型 DO | ||||||
|  | * | ||||||
|  | * @author 芋艿 | ||||||
|  | */ | ||||||
|  | @TableName("sys_test_demo") | ||||||
|  | @Data | ||||||
|  | @EqualsAndHashCode(callSuper = true) | ||||||
|  | @ToString(callSuper = true) | ||||||
|  | @Builder | ||||||
|  | @NoArgsConstructor | ||||||
|  | @AllArgsConstructor | ||||||
|  | public class SysTestDemoDO extends BaseDO { | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |     * 字典主键 | ||||||
|  |     */ | ||||||
|  |     @TableId | ||||||
|  |     private Long id; | ||||||
|  |     /** | ||||||
|  |     * 字典名称 | ||||||
|  |     */ | ||||||
|  |     private String name; | ||||||
|  |     /** | ||||||
|  |     * 字典类型 | ||||||
|  |     */ | ||||||
|  |     private String dictType; | ||||||
|  |     /** | ||||||
|  |     * 状态 | ||||||
|  |     */ | ||||||
|  |     private Integer status; | ||||||
|  |     /** | ||||||
|  |     * 备注 | ||||||
|  |     */ | ||||||
|  |     private String remark; | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -0,0 +1,66 @@ | |||||||
|  | package cn.iocoder.dashboard.modules.system.service.test; | ||||||
|  |  | ||||||
|  | import cn.iocoder.dashboard.common.pojo.PageResult; | ||||||
|  | import cn.iocoder.dashboard.modules.system.controller.test.vo.SysTestDemoCreateReqVO; | ||||||
|  | import cn.iocoder.dashboard.modules.system.controller.test.vo.SysTestDemoPageReqVO; | ||||||
|  | import cn.iocoder.dashboard.modules.system.controller.test.vo.SysTestDemoUpdateReqVO; | ||||||
|  | import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.test.SysTestDemoDO; | ||||||
|  |  | ||||||
|  | import javax.validation.Valid; | ||||||
|  | import java.util.Collection; | ||||||
|  | import java.util.List; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  | * 字典类型 Service 接口 | ||||||
|  | * | ||||||
|  | * @author 芋艿 | ||||||
|  | */ | ||||||
|  | public interface SysTestDemoService { | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 创建字典类型 | ||||||
|  |      * | ||||||
|  |      * @param createReqVO 创建信息 | ||||||
|  |      * @return 编号 | ||||||
|  |      */ | ||||||
|  |     Long createTestDemo(@Valid SysTestDemoCreateReqVO createReqVO); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 更新字典类型 | ||||||
|  |      * | ||||||
|  |      * @param updateReqVO 更新信息 | ||||||
|  |      */ | ||||||
|  |     void updateTestDemo(@Valid SysTestDemoUpdateReqVO updateReqVO); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 删除字典类型 | ||||||
|  |      * | ||||||
|  |      * @param id 编号 | ||||||
|  |      */ | ||||||
|  |     void deleteTestDemo(Long id); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 获得字典类型 | ||||||
|  |      * | ||||||
|  |      * @param id 编号 | ||||||
|  |      * @return 字典类型 | ||||||
|  |      */ | ||||||
|  |     SysTestDemoDO getTestDemo(Long id); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 获得字典类型列表 | ||||||
|  |      * | ||||||
|  |      * @param ids 编号 | ||||||
|  |      * @return 字典类型列表 | ||||||
|  |      */ | ||||||
|  |     List<SysTestDemoDO> getTestDemoList(Collection<Long> ids); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 获得字典类型分页 | ||||||
|  |      * | ||||||
|  |      * @param pageReqVO 分页查询 | ||||||
|  |      * @return 字典类型分页 | ||||||
|  |      */ | ||||||
|  | 	PageResult<SysTestDemoDO> getTestDemoPage(SysTestDemoPageReqVO pageReqVO); | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -17,6 +17,8 @@ import org.springframework.stereotype.Component; | |||||||
| import java.math.BigDecimal; | import java.math.BigDecimal; | ||||||
| import java.util.*; | import java.util.*; | ||||||
|  |  | ||||||
|  | import static cn.hutool.core.text.CharSequenceUtil.*; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * 代码生成器的 Builder,负责: |  * 代码生成器的 Builder,负责: | ||||||
|  * 1. 将数据库的表 {@link ToolInformationSchemaTableDO} 定义,构建成 {@link ToolCodegenTableDO} |  * 1. 将数据库的表 {@link ToolInformationSchemaTableDO} 定义,构建成 {@link ToolCodegenTableDO} | ||||||
| @@ -25,6 +27,18 @@ import java.util.*; | |||||||
| @Component | @Component | ||||||
| public class ToolCodegenBuilder { | public class ToolCodegenBuilder { | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Module 名字的映射 TODO 后续梳理到配置类 | ||||||
|  |      * | ||||||
|  |      * key:模块的完整名 | ||||||
|  |      * value:模块的缩写名 | ||||||
|  |      */ | ||||||
|  |     private static final Map<String, String> moduleNames = MapUtil.<String, String>builder() | ||||||
|  |             .put("system", "sys") | ||||||
|  |             .put("infra", "inf") | ||||||
|  |             .put("tool", "tool") | ||||||
|  |             .build(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 字段名与 {@link ToolCodegenColumnListConditionEnum} 的默认映射 |      * 字段名与 {@link ToolCodegenColumnListConditionEnum} 的默认映射 | ||||||
|      * 注意,字段的匹配以后缀的方式 |      * 注意,字段的匹配以后缀的方式 | ||||||
| @@ -93,9 +107,9 @@ public class ToolCodegenBuilder { | |||||||
|         CREATE_OPERATION_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS); |         CREATE_OPERATION_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS); | ||||||
|         UPDATE_OPERATION_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS); |         UPDATE_OPERATION_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS); | ||||||
|         LIST_OPERATION_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS); |         LIST_OPERATION_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS); | ||||||
|         LIST_OPERATION_EXCLUDE_COLUMN.remove("create_time"); // 创建时间,还是可能需要传递的 |         LIST_OPERATION_EXCLUDE_COLUMN.remove("createTime"); // 创建时间,还是可能需要传递的 | ||||||
|         LIST_OPERATION_RESULT_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS); |         LIST_OPERATION_RESULT_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS); | ||||||
|         LIST_OPERATION_RESULT_EXCLUDE_COLUMN.remove("create_time"); // 创建时间,还是需要返回的 |         LIST_OPERATION_RESULT_EXCLUDE_COLUMN.remove("createTime"); // 创建时间,还是需要返回的 | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public ToolCodegenTableDO buildTable(ToolInformationSchemaTableDO schemaTable) { |     public ToolCodegenTableDO buildTable(ToolInformationSchemaTableDO schemaTable) { | ||||||
| @@ -110,13 +124,12 @@ public class ToolCodegenBuilder { | |||||||
|      * @param table 表定义 |      * @param table 表定义 | ||||||
|      */ |      */ | ||||||
|     private void initTableDefault(ToolCodegenTableDO table) { |     private void initTableDefault(ToolCodegenTableDO table) { | ||||||
|         table.setModuleName(StrUtil.subBefore(table.getTableName(), |         table.setModuleName(getFullModuleName(StrUtil.subBefore(table.getTableName(), | ||||||
|                 '_', false)); // 第一个 _ 前缀的前面,作为 module 名字 |                 '_', false))); // 第一个 _ 前缀的前面,作为 module 名字 | ||||||
|         table.setBusinessName(StrUtil.subAfter(table.getTableName(), |         table.setBusinessName(toCamelCase(subAfter(table.getTableName(), | ||||||
|                 '_', false)); // 第一个 _ 前缀的后面,作为 module 名字 |                 '_', false))); // 第一步,第一个 _ 前缀的后面,作为 module 名字; 第二步,可能存在多个 _ 的情况,转换成驼峰 | ||||||
|         table.setBusinessName(StrUtil.toCamelCase(table.getBusinessName())); // 可能存在多个 _ 的情况,转换成驼峰 |         table.setClassName(upperFirst(toCamelCase(table.getTableName()))); // 驼峰 + 首字母大写 | ||||||
|         table.setClassName(StrUtil.upperFirst(StrUtil.toCamelCase(table.getTableName()))); // 驼峰 + 首字母大写 |         table.setClassComment(subBefore(table.getTableComment(), // 去除结尾的表,作为类描述 | ||||||
|         table.setClassComment(StrUtil.subBefore(table.getTableComment(), // 去除结尾的表,作为类描述 |  | ||||||
|                 '表', true)); |                 '表', true)); | ||||||
|         table.setAuthor("芋艿"); // TODO 稍后改成创建人 |         table.setAuthor("芋艿"); // TODO 稍后改成创建人 | ||||||
|         table.setTemplateType(ToolCodegenTemplateTypeEnum.CRUD.getType()); |         table.setTemplateType(ToolCodegenTemplateTypeEnum.CRUD.getType()); | ||||||
| @@ -144,7 +157,7 @@ public class ToolCodegenBuilder { | |||||||
|  |  | ||||||
|     private void processColumnJava(ToolCodegenColumnDO column) { |     private void processColumnJava(ToolCodegenColumnDO column) { | ||||||
|         // 处理 javaField 字段 |         // 处理 javaField 字段 | ||||||
|         column.setJavaField(StrUtil.toCamelCase(column.getColumnName())); |         column.setJavaField(toCamelCase(column.getColumnName())); | ||||||
|         // 处理 dictType 字段,暂无 |         // 处理 dictType 字段,暂无 | ||||||
|         // 处理 javaType 字段 |         // 处理 javaType 字段 | ||||||
|         String dbType = StrUtil.subBefore(column.getColumnType(), '(', false); |         String dbType = StrUtil.subBefore(column.getColumnType(), '(', false); | ||||||
| @@ -194,4 +207,27 @@ public class ToolCodegenBuilder { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 获得模块的缩略名 | ||||||
|  |      * | ||||||
|  |      * @param fullModuleName 模块的完整名 | ||||||
|  |      * @return 缩略名 | ||||||
|  |      */ | ||||||
|  |     public String getSimpleModuleName(String fullModuleName) { | ||||||
|  |         return moduleNames.getOrDefault(fullModuleName, fullModuleName); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 获得模块的完整名 | ||||||
|  |      * | ||||||
|  |      * @param shortModuleName 模块的缩略名 | ||||||
|  |      * @return 完整名 | ||||||
|  |      */ | ||||||
|  |     public String getFullModuleName(String shortModuleName) { | ||||||
|  |         return moduleNames.entrySet().stream() | ||||||
|  |                 .filter(entry -> entry.getValue().equals(shortModuleName)) // 匹配 | ||||||
|  |                 .findFirst().map(Map.Entry::getKey) // 返回 key | ||||||
|  |                 .orElse(shortModuleName); // 兜底返回 shortModuleName | ||||||
|  |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -14,6 +14,7 @@ import cn.iocoder.dashboard.util.collection.CollectionUtils; | |||||||
| import cn.iocoder.dashboard.util.date.DateUtils; | import cn.iocoder.dashboard.util.date.DateUtils; | ||||||
| import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||||
|  |  | ||||||
|  | import javax.annotation.Resource; | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
| @@ -31,6 +32,9 @@ import static cn.hutool.core.text.CharSequenceUtil.*; | |||||||
| @Component | @Component | ||||||
| public class ToolCodegenEngine { | public class ToolCodegenEngine { | ||||||
|  |  | ||||||
|  |     @Resource | ||||||
|  |     private ToolCodegenBuilder codegenBuilder; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 模板引擎,由 hutool 实现 |      * 模板引擎,由 hutool 实现 | ||||||
|      */ |      */ | ||||||
| @@ -69,9 +73,15 @@ public class ToolCodegenEngine { | |||||||
|         Map<String, Object> bindingMap = new HashMap<>(globalBindingMap); |         Map<String, Object> bindingMap = new HashMap<>(globalBindingMap); | ||||||
|         bindingMap.put("table", table); |         bindingMap.put("table", table); | ||||||
|         bindingMap.put("columns", columns); |         bindingMap.put("columns", columns); | ||||||
|         bindingMap.put("primaryColumn", CollectionUtils.findFirst(columns, ToolCodegenColumnDO::getPrimaryKey)); |         bindingMap.put("primaryColumn", CollectionUtils.findFirst(columns, ToolCodegenColumnDO::getPrimaryKey)); // 主键字段 | ||||||
|         bindingMap.put("simpleClassName", upperFirst(toCamelCase(subAfter( // 去掉第一个驼峰,例如说 SysUser 去掉后是 User |         String simpleModuleName = codegenBuilder.getSimpleModuleName(table.getModuleName()); | ||||||
|                 toUnderlineCase(table.getClassName()), '_', false)))); |         bindingMap.put("simpleModuleName", simpleModuleName); // 将 system 转成 sys | ||||||
|  |         // className 相关 | ||||||
|  |         String simpleClassName = subAfter(table.getClassName(), upperFirst(simpleModuleName) | ||||||
|  |                 , false); // 将 TestDictType 转换成 DictType. 因为在 create 等方法后,不需要带上 Test 前缀 | ||||||
|  |         bindingMap.put("simpleClassName", simpleClassName); | ||||||
|  |         bindingMap.put("simpleClassName_underlineCase", toUnderlineCase(simpleClassName)); // 将 DictType 转换成 dict_type | ||||||
|  |         bindingMap.put("classNameVar", lowerFirst(simpleClassName)); // 将 DictType 转换成 dictType,用于变量 | ||||||
|         // 执行生成 |         // 执行生成 | ||||||
| //        String result = templateEngine.getTemplate("codegen/dal/do.vm").render(bindingMap); | //        String result = templateEngine.getTemplate("codegen/dal/do.vm").render(bindingMap); | ||||||
| //        String result = templateEngine.getTemplate("codegen/dal/mapper.vm").render(bindingMap); | //        String result = templateEngine.getTemplate("codegen/dal/mapper.vm").render(bindingMap); | ||||||
| @@ -80,7 +90,10 @@ public class ToolCodegenEngine { | |||||||
| //        String result = templateEngine.getTemplate("codegen/controller/vo/createReqVO.vm").render(bindingMap); | //        String result = templateEngine.getTemplate("codegen/controller/vo/createReqVO.vm").render(bindingMap); | ||||||
| //        String result = templateEngine.getTemplate("codegen/controller/vo/updateReqVO.vm").render(bindingMap); | //        String result = templateEngine.getTemplate("codegen/controller/vo/updateReqVO.vm").render(bindingMap); | ||||||
| //        String result = templateEngine.getTemplate("codegen/controller/vo/respVO.vm").render(bindingMap); | //        String result = templateEngine.getTemplate("codegen/controller/vo/respVO.vm").render(bindingMap); | ||||||
|  | //        String result = templateEngine.getTemplate("codegen/convert/convert.vm").render(bindingMap); | ||||||
|  | //        String result = templateEngine.getTemplate("codegen/enums/errorcode.vm").render(bindingMap); | ||||||
|         String result = templateEngine.getTemplate("codegen/service/service.vm").render(bindingMap); |         String result = templateEngine.getTemplate("codegen/service/service.vm").render(bindingMap); | ||||||
|  | //        String result = templateEngine.getTemplate("codegen/service/serviceImpl.vm").render(bindingMap); | ||||||
|         System.out.println(result); |         System.out.println(result); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -6,8 +6,8 @@ import io.swagger.annotations.*; | |||||||
| import javax.validation.constraints.*; | import javax.validation.constraints.*; | ||||||
| ## 处理 Date 字段的引入 | ## 处理 Date 字段的引入 | ||||||
| #foreach ($column in $columns) | #foreach ($column in $columns) | ||||||
| #if (${column.updateOperation} && (!${column.createOperation} || !${column.listOperationResult})) | #if (${column.updateOperation} && (!${column.createOperation} || !${column.listOperationResult}) | ||||||
|     && ${column.javaType} == "Date")## 时间类型 |     && ${column.javaType} == "Date"))## 时间类型 | ||||||
| import org.springframework.format.annotation.DateTimeFormat; | import org.springframework.format.annotation.DateTimeFormat; | ||||||
|  |  | ||||||
| import static ${DateUtilsClassName}.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | import static ${DateUtilsClassName}.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | ||||||
|   | |||||||
							
								
								
									
										22
									
								
								src/main/resources/codegen/convert/convert.vm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								src/main/resources/codegen/convert/convert.vm
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | |||||||
|  | package ${basePackage}.${table.moduleName}.convert.${table.businessName}; | ||||||
|  |  | ||||||
|  | import org.mapstruct.Mapper; | ||||||
|  | import org.mapstruct.factory.Mappers; | ||||||
|  | import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.*; | ||||||
|  | import ${basePackage}.${table.moduleName}.dal.mysql.dataobject.${table.businessName}.${table.className}DO; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  | * ${table.classComment} Convert | ||||||
|  | * | ||||||
|  | * @author ${table.author} | ||||||
|  | */ | ||||||
|  | @Mapper | ||||||
|  | public interface ${table.className}Convert { | ||||||
|  |  | ||||||
|  |     ${table.className}Convert INSTANCE = Mappers.getMapper(${table.className}Convert.class); | ||||||
|  |  | ||||||
|  |     ${table.className}DO convert(${table.className}CreateReqVO bean); | ||||||
|  |  | ||||||
|  |     ${table.className}DO convert(${table.className}UpdateReqVO bean); | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -3,7 +3,7 @@ package ${basePackage}.${table.moduleName}.dal.mysql.dataobject.${table.business | |||||||
| import lombok.*; | import lombok.*; | ||||||
| import java.util.*; | import java.util.*; | ||||||
| import com.baomidou.mybatisplus.annotation.*; | import com.baomidou.mybatisplus.annotation.*; | ||||||
| import ${BaseDOClassName}; | import ${baseDOClassName}; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| * ${table.classComment} DO | * ${table.classComment} DO | ||||||
|   | |||||||
| @@ -5,6 +5,7 @@ import ${QueryWrapperClassName}; | |||||||
| import ${BaseMapperClassName}; | import ${BaseMapperClassName}; | ||||||
| import ${basePackage}.${table.moduleName}.dal.mysql.dataobject.${table.businessName}.${table.className}DO; | import ${basePackage}.${table.moduleName}.dal.mysql.dataobject.${table.businessName}.${table.className}DO; | ||||||
| import org.apache.ibatis.annotations.Mapper; | import org.apache.ibatis.annotations.Mapper; | ||||||
|  | import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.${table.className}PageReqVO; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| * ${table.classComment} Mapper | * ${table.classComment} Mapper | ||||||
| @@ -26,19 +27,19 @@ public interface ${table.className}Mapper extends BaseMapperX<${table.className} | |||||||
|             .neIfPresent("${column.columnName}", reqVO.get${JavaField}()) |             .neIfPresent("${column.columnName}", reqVO.get${JavaField}()) | ||||||
| #end | #end | ||||||
| #if (${column.listOperationCondition} == ">")##情况三,> 的时候 | #if (${column.listOperationCondition} == ">")##情况三,> 的时候 | ||||||
|         .gtIfPresent("${column.columnName}", reqVO.get${JavaField}()) |             .gtIfPresent("${column.columnName}", reqVO.get${JavaField}()) | ||||||
| #end | #end | ||||||
| #if (${column.listOperationCondition} == ">=")##情况四,>= 的时候 | #if (${column.listOperationCondition} == ">=")##情况四,>= 的时候 | ||||||
|         .geIfPresent("${column.columnName}", reqVO.get${JavaField}()) |             .geIfPresent("${column.columnName}", reqVO.get${JavaField}()) | ||||||
| #end | #end | ||||||
| #if (${column.listOperationCondition} == "<")##情况五,< 的时候 | #if (${column.listOperationCondition} == "<")##情况五,< 的时候 | ||||||
|         .gtIfPresent("${column.columnName}", reqVO.get${JavaField}()) |             .gtIfPresent("${column.columnName}", reqVO.get${JavaField}()) | ||||||
| #end | #end | ||||||
| #if (${column.listOperationCondition} == "LIKE")##情况七,Like 的时候 | #if (${column.listOperationCondition} == "LIKE")##情况七,Like 的时候 | ||||||
|         .likeIfPresent("${column.columnName}", reqVO.get${JavaField}()) |             .likeIfPresent("${column.columnName}", reqVO.get${JavaField}()) | ||||||
| #end | #end | ||||||
| #if (${column.listOperationCondition} == "BETWEEN")##情况八,Between 的时候 | #if (${column.listOperationCondition} == "BETWEEN")##情况八,Between 的时候 | ||||||
|         .betweenIfPresent("${column.columnName}", reqVO.getBegin${JavaField}(), reqVO.getEnd${JavaField}()) |             .betweenIfPresent("${column.columnName}", reqVO.getBegin${JavaField}(), reqVO.getEnd${JavaField}()) | ||||||
| #end | #end | ||||||
| #end | #end | ||||||
| #end | #end | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								src/main/resources/codegen/enums/errorcode.vm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								src/main/resources/codegen/enums/errorcode.vm
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | |||||||
|  | // ========== ${table.classCommet} TODO 补充编号 ========== | ||||||
|  | ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_NOT_FOUND = new ErrorCode(TODO 补充编号, "${table.classComment}不存在}"); | ||||||
| @@ -17,7 +17,7 @@ public interface ${table.className}Service { | |||||||
|      * 创建${table.classComment} |      * 创建${table.classComment} | ||||||
|      * |      * | ||||||
|      * @param createReqVO 创建信息 |      * @param createReqVO 创建信息 | ||||||
|      * @return ${class.description} |      * @return 编号 | ||||||
|      */ |      */ | ||||||
|     ${primaryColumn.javaType} create${simpleClassName}(@Valid ${table.className}CreateReqVO createReqVO); |     ${primaryColumn.javaType} create${simpleClassName}(@Valid ${table.className}CreateReqVO createReqVO); | ||||||
|  |  | ||||||
| @@ -39,7 +39,7 @@ public interface ${table.className}Service { | |||||||
|      * 获得${table.classComment} |      * 获得${table.classComment} | ||||||
|      * |      * | ||||||
|      * @param id 编号 |      * @param id 编号 | ||||||
|      * @return ${class.description} |      * @return ${table.classComment} | ||||||
|      */ |      */ | ||||||
|     ${table.className}DO get${simpleClassName}(${primaryColumn.javaType} id); |     ${table.className}DO get${simpleClassName}(${primaryColumn.javaType} id); | ||||||
|  |  | ||||||
| @@ -47,7 +47,7 @@ public interface ${table.className}Service { | |||||||
|      * 获得${table.classComment}列表 |      * 获得${table.classComment}列表 | ||||||
|      * |      * | ||||||
|      * @param ids 编号 |      * @param ids 编号 | ||||||
|      * @return ${class.classComment}列表 |      * @return ${table.classComment}列表 | ||||||
|      */ |      */ | ||||||
|     List<${table.className}DO> get${simpleClassName}List(Collection<${primaryColumn.javaType}> ids); |     List<${table.className}DO> get${simpleClassName}List(Collection<${primaryColumn.javaType}> ids); | ||||||
|  |  | ||||||
| @@ -55,7 +55,7 @@ public interface ${table.className}Service { | |||||||
|      * 获得${table.classComment}分页 |      * 获得${table.classComment}分页 | ||||||
|      * |      * | ||||||
|      * @param pageReqVO 分页查询 |      * @param pageReqVO 分页查询 | ||||||
|      * @return ${class.classComment}分页 |      * @return ${table.classComment}分页 | ||||||
|      */ |      */ | ||||||
| 	PageResult<${table.className}DO> get${simpleClassName}Page(${table.className}PageReqVO pageReqVO); | 	PageResult<${table.className}DO> get${simpleClassName}Page(${table.className}PageReqVO pageReqVO); | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										30
									
								
								src/main/resources/codegen/service/serviceImpl.vm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								src/main/resources/codegen/service/serviceImpl.vm
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | |||||||
|  | package ${basePackage}.${table.moduleName}.service.${table.businessName}.impl; | ||||||
|  |  | ||||||
|  | import org.springframework.beans.factory.annotation.Autowired; | ||||||
|  | import org.springframework.stereotype.Service; | ||||||
|  | import javax.annotation.Resource; | ||||||
|  | import org.springframework.validation.annotation.Validated; | ||||||
|  |  | ||||||
|  | import java.util.*; | ||||||
|  | import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.*; | ||||||
|  | import ${basePackage}.${table.moduleName}.dal.mysql.dataobject.${table.businessName}.${table.className}DO; | ||||||
|  | import ${PageResultClassName}; | ||||||
|  |  | ||||||
|  | import static ${basePackage}.${table.moduleName}.enums.${simpleModuleName.substring(0,1).toUpperCase()}${simpleModuleName.substring(1)}ErrorCodeConstants.*; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  | * ${table.classComment} Service 实现类 | ||||||
|  | * | ||||||
|  | * @author ${table.author} | ||||||
|  | */ | ||||||
|  | @Validated | ||||||
|  | public class ${table.className}ServiceImpl implements {table.className}Service { | ||||||
|  |  | ||||||
|  |     @Resource | ||||||
|  |     private ${table.className}Mapper ${classNameVar}Mapper; | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public ${primaryColumn.javaType} create${simpleClassName}(@Valid ${table.className}CreateReqVO createReqVO) { | ||||||
|  |     } | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -24,7 +24,7 @@ public class ToolCodegenEngineTest { | |||||||
|  |  | ||||||
|     @Test |     @Test | ||||||
|     public void testExecute() { |     public void testExecute() { | ||||||
|         ToolCodegenTableDO table = codegenTableMapper.selectById(8); |         ToolCodegenTableDO table = codegenTableMapper.selectById(10); | ||||||
|         List<ToolCodegenColumnDO> columns = codegenColumnMapper.selectByTableId(table.getId()); |         List<ToolCodegenColumnDO> columns = codegenColumnMapper.selectByTableId(table.getId()); | ||||||
|         codegenEngine.execute(table, columns); |         codegenEngine.execute(table, columns); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -16,7 +16,7 @@ class ToolCodegenServiceImplTest { | |||||||
|  |  | ||||||
|     @Test |     @Test | ||||||
|     public void tetCreateCodegenTable() { |     public void tetCreateCodegenTable() { | ||||||
|         toolCodegenService.createCodegenTable("sys_dict_type"); |         toolCodegenService.createCodegenTable("sys_test_demo"); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV