Commit 5442f6522e5e25fc2472626470bb7877ddffe06f

Authored by YunaiV
1 parent 2210ed5c

整理 vm 模板

提交 test 生成的示例
Showing 25 changed files with 412 additions and 246 deletions
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java
... ... @@ -5,6 +5,7 @@ import java.util.HashMap;
5 5 import java.util.List;
6 6 import java.util.Map;
7 7 import javax.servlet.http.HttpServletResponse;
  8 +
8 9 import org.apache.commons.io.IOUtils;
9 10 import org.springframework.beans.factory.annotation.Autowired;
10 11 import org.springframework.security.access.prepost.PreAuthorize;
... ... @@ -30,13 +31,12 @@ import com.ruoyi.generator.service.IGenTableService;
30 31  
31 32 /**
32 33 * 代码生成 操作处理
33   - *
  34 + *
34 35 * @author ruoyi
35 36 */
36 37 @RestController
37 38 @RequestMapping("/tool/gen")
38   -public class GenController extends BaseController
39   -{
  39 +public class GenController extends BaseController {
40 40 @Autowired
41 41 private IGenTableService genTableService;
42 42  
... ... @@ -48,8 +48,7 @@ public class GenController extends BaseController
48 48 */
49 49 @PreAuthorize("@ss.hasPermi('tool:gen:list')")
50 50 @GetMapping("/list")
51   - public TableDataInfo genList(GenTable genTable)
52   - {
  51 + public TableDataInfo genList(GenTable genTable) {
53 52 startPage();
54 53 List<GenTable> list = genTableService.selectGenTableList(genTable);
55 54 return getDataTable(list);
... ... @@ -60,8 +59,7 @@ public class GenController extends BaseController
60 59 */
61 60 @PreAuthorize("@ss.hasPermi('tool:gen:query')")
62 61 @GetMapping(value = "/{talbleId}")
63   - public AjaxResult getInfo(@PathVariable Long talbleId)
64   - {
  62 + public AjaxResult getInfo(@PathVariable Long talbleId) {
65 63 GenTable table = genTableService.selectGenTableById(talbleId);
66 64 List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(talbleId);
67 65 Map<String, Object> map = new HashMap<String, Object>();
... ... @@ -75,8 +73,7 @@ public class GenController extends BaseController
75 73 */
76 74 @PreAuthorize("@ss.hasPermi('tool:gen:list')")
77 75 @GetMapping("/db/list")
78   - public TableDataInfo dataList(GenTable genTable)
79   - {
  76 + public TableDataInfo dataList(GenTable genTable) {
80 77 startPage();
81 78 List<GenTable> list = genTableService.selectDbTableList(genTable);
82 79 return getDataTable(list);
... ... @@ -87,8 +84,7 @@ public class GenController extends BaseController
87 84 */
88 85 @PreAuthorize("@ss.hasPermi('tool:gen:list')")
89 86 @GetMapping(value = "/column/{talbleId}")
90   - public TableDataInfo columnList(Long tableId)
91   - {
  87 + public TableDataInfo columnList(Long tableId) {
92 88 TableDataInfo dataInfo = new TableDataInfo();
93 89 List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
94 90 dataInfo.setRows(list);
... ... @@ -102,8 +98,7 @@ public class GenController extends BaseController
102 98 @PreAuthorize("@ss.hasPermi('tool:gen:list')")
103 99 @Log(title = "代码生成", businessType = BusinessType.IMPORT)
104 100 @PostMapping("/importTable")
105   - public AjaxResult importTableSave(String tables)
106   - {
  101 + public AjaxResult importTableSave(String tables) {
107 102 String[] tableNames = Convert.toStrArray(tables);
108 103 // 查询表信息
109 104 List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames);
... ... @@ -117,8 +112,7 @@ public class GenController extends BaseController
117 112 @PreAuthorize("@ss.hasPermi('tool:gen:edit')")
118 113 @Log(title = "代码生成", businessType = BusinessType.UPDATE)
119 114 @PutMapping
120   - public AjaxResult editSave(@Validated @RequestBody GenTable genTable)
121   - {
  115 + public AjaxResult editSave(@Validated @RequestBody GenTable genTable) {
122 116 genTableService.validateEdit(genTable);
123 117 genTableService.updateGenTable(genTable);
124 118 return AjaxResult.success();
... ... @@ -130,8 +124,7 @@ public class GenController extends BaseController
130 124 @PreAuthorize("@ss.hasPermi('tool:gen:remove')")
131 125 @Log(title = "代码生成", businessType = BusinessType.DELETE)
132 126 @DeleteMapping("/{tableIds}")
133   - public AjaxResult remove(@PathVariable Long[] tableIds)
134   - {
  127 + public AjaxResult remove(@PathVariable Long[] tableIds) {
135 128 genTableService.deleteGenTableByIds(tableIds);
136 129 return AjaxResult.success();
137 130 }
... ... @@ -141,8 +134,7 @@ public class GenController extends BaseController
141 134 */
142 135 @PreAuthorize("@ss.hasPermi('tool:gen:preview')")
143 136 @GetMapping("/preview/{tableId}")
144   - public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException
145   - {
  137 + public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException {
146 138 Map<String, String> dataMap = genTableService.previewCode(tableId);
147 139 return AjaxResult.success(dataMap);
148 140 }
... ... @@ -153,8 +145,7 @@ public class GenController extends BaseController
153 145 @PreAuthorize("@ss.hasPermi('tool:gen:code')")
154 146 @Log(title = "代码生成", businessType = BusinessType.GENCODE)
155 147 @GetMapping("/download/{tableName}")
156   - public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException
157   - {
  148 + public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException {
158 149 byte[] data = genTableService.downloadCode(tableName);
159 150 genCode(response, data);
160 151 }
... ... @@ -165,8 +156,7 @@ public class GenController extends BaseController
165 156 @PreAuthorize("@ss.hasPermi('tool:gen:code')")
166 157 @Log(title = "代码生成", businessType = BusinessType.GENCODE)
167 158 @GetMapping("/genCode/{tableName}")
168   - public AjaxResult genCode(@PathVariable("tableName") String tableName)
169   - {
  159 + public AjaxResult genCode(@PathVariable("tableName") String tableName) {
170 160 genTableService.generatorCode(tableName);
171 161 return AjaxResult.success();
172 162 }
... ... @@ -177,8 +167,7 @@ public class GenController extends BaseController
177 167 @PreAuthorize("@ss.hasPermi('tool:gen:edit')")
178 168 @Log(title = "代码生成", businessType = BusinessType.UPDATE)
179 169 @GetMapping("/synchDb/{tableName}")
180   - public AjaxResult synchDb(@PathVariable("tableName") String tableName)
181   - {
  170 + public AjaxResult synchDb(@PathVariable("tableName") String tableName) {
182 171 genTableService.synchDb(tableName);
183 172 return AjaxResult.success();
184 173 }
... ... @@ -189,8 +178,7 @@ public class GenController extends BaseController
189 178 @PreAuthorize("@ss.hasPermi('tool:gen:code')")
190 179 @Log(title = "代码生成", businessType = BusinessType.GENCODE)
191 180 @GetMapping("/batchGenCode")
192   - public void batchGenCode(HttpServletResponse response, String tables) throws IOException
193   - {
  181 + public void batchGenCode(HttpServletResponse response, String tables) throws IOException {
194 182 String[] tableNames = Convert.toStrArray(tables);
195 183 byte[] data = genTableService.downloadCode(tableNames);
196 184 genCode(response, data);
... ... @@ -199,8 +187,7 @@ public class GenController extends BaseController
199 187 /**
200 188 * 生成zip文件
201 189 */
202   - private void genCode(HttpServletResponse response, byte[] data) throws IOException
203   - {
  190 + private void genCode(HttpServletResponse response, byte[] data) throws IOException {
204 191 response.reset();
205 192 response.addHeader("Access-Control-Allow-Origin", "*");
206 193 response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
... ... @@ -209,4 +196,4 @@ public class GenController extends BaseController
209 196 response.setContentType("application/octet-stream; charset=UTF-8");
210 197 IOUtils.write(data, response.getOutputStream());
211 198 }
212   -}
213 199 \ No newline at end of file
  200 +}
... ...
ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java
... ... @@ -23,11 +23,6 @@ public class GenTable extends BaseEntity {
23 23 private String packageName;
24 24  
25 25 /**
26   - * 主键信息
27   - */
28   - private GenTableColumn pkColumn;
29   -
30   - /**
31 26 * 其它生成选项
32 27 */
33 28 private String options;
... ... @@ -57,31 +52,4 @@ public class GenTable extends BaseEntity {
57 52 */
58 53 private String parentMenuName;
59 54  
60   - public boolean isTree() {
61   - return isTree(this.tplCategory);
62   - }
63   -
64   - public static boolean isTree(String tplCategory) {
65   - return tplCategory != null && StringUtils.equals(GenConstants.TPL_TREE, tplCategory);
66   - }
67   -
68   - public boolean isCrud() {
69   - return isCrud(this.tplCategory);
70   - }
71   -
72   - public static boolean isCrud(String tplCategory) {
73   - return tplCategory != null && StringUtils.equals(GenConstants.TPL_CRUD, tplCategory);
74   - }
75   -
76   - public boolean isSuperColumn(String javaField) {
77   - return isSuperColumn(this.tplCategory, javaField);
78   - }
79   -
80   - public static boolean isSuperColumn(String tplCategory, String javaField) {
81   - if (isTree(tplCategory)) {
82   - return StringUtils.equalsAnyIgnoreCase(javaField,
83   - ArrayUtils.addAll(GenConstants.TREE_ENTITY, GenConstants.BASE_ENTITY));
84   - }
85   - return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY);
86   - }
87 55 }
... ...
ruoyi-generator/src/main/resources/vm/java/service.java.vm deleted
1   -package ${packageName}.service;
2   -
3   -import java.util.List;
4   -import ${packageName}.domain.${ClassName};
5   -
6   -/**
7   - * ${functionName}Service接口
8   - *
9   - * @author ${author}
10   - * @date ${datetime}
11   - */
12   -public interface I${ClassName}Service
13   -{
14   - /**
15   - * 查询${functionName}
16   - *
17   - * @param ${pkColumn.javaField} ${functionName}ID
18   - * @return ${functionName}
19   - */
20   - public ${ClassName} select${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField});
21   -
22   - /**
23   - * 查询${functionName}列表
24   - *
25   - * @param ${className} ${functionName}
26   - * @return ${functionName}集合
27   - */
28   - public List<${ClassName}> select${ClassName}List(${ClassName} ${className});
29   -
30   - /**
31   - * 新增${functionName}
32   - *
33   - * @param ${className} ${functionName}
34   - * @return 结果
35   - */
36   - public int insert${ClassName}(${ClassName} ${className});
37   -
38   - /**
39   - * 修改${functionName}
40   - *
41   - * @param ${className} ${functionName}
42   - * @return 结果
43   - */
44   - public int update${ClassName}(${ClassName} ${className});
45   -
46   - /**
47   - * 批量删除${functionName}
48   - *
49   - * @param ${pkColumn.javaField}s 需要删除的${functionName}ID
50   - * @return 结果
51   - */
52   - public int delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s);
53   -
54   - /**
55   - * 删除${functionName}信息
56   - *
57   - * @param ${pkColumn.javaField} ${functionName}ID
58   - * @return 结果
59   - */
60   - public int delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField});
61   -}
ruoyi-generator/src/main/resources/vm/xml/mapper.xml.vm deleted
1   -<?xml version="1.0" encoding="UTF-8" ?>
2   -<!DOCTYPE mapper
3   -PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
4   -"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
5   -<mapper namespace="${packageName}.mapper.${ClassName}Mapper">
6   -
7   - <resultMap type="${ClassName}" id="${ClassName}Result">
8   -#foreach ($column in $columns)
9   - <result property="${column.javaField}" column="${column.columnName}" />
10   -#end
11   - </resultMap>
12   -
13   - <sql id="select${ClassName}Vo">
14   - select#foreach($column in $columns) $column.columnName#if($velocityCount != $columns.size()),#end#end from ${tableName}
15   - </sql>
16   -
17   - <select id="select${ClassName}List" parameterType="${ClassName}" resultMap="${ClassName}Result">
18   - <include refid="select${ClassName}Vo"/>
19   - <where>
20   -#foreach($column in $columns)
21   -#set($queryType=$column.queryType)
22   -#set($javaField=$column.javaField)
23   -#set($javaType=$column.javaType)
24   -#set($columnName=$column.columnName)
25   -#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
26   -#if($column.query)
27   -#if($column.queryType == "EQ")
28   - <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName = #{$javaField}</if>
29   -#elseif($queryType == "NE")
30   - <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName != #{$javaField}</if>
31   -#elseif($queryType == "GT")
32   - <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &gt; #{$javaField}</if>
33   -#elseif($queryType == "GTE")
34   - <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &gt;= #{$javaField}</if>
35   -#elseif($queryType == "LT")
36   - <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &lt; #{$javaField}</if>
37   -#elseif($queryType == "LTE")
38   - <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &lt;= #{$javaField}</if>
39   -#elseif($queryType == "LIKE")
40   - <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName like concat('%', #{$javaField}, '%')</if>
41   -#elseif($queryType == "BETWEEN")
42   - <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>
43   -#end
44   -#end
45   -#end
46   - </where>
47   - </select>
48   -
49   - <select id="select${ClassName}ById" parameterType="${pkColumn.javaType}" resultMap="${ClassName}Result">
50   - <include refid="select${ClassName}Vo"/>
51   - where ${pkColumn.columnName} = #{${pkColumn.javaField}}
52   - </select>
53   -
54   - <insert id="insert${ClassName}" parameterType="${ClassName}"#if($pkColumn.increment) useGeneratedKeys="true" keyProperty="$pkColumn.javaField"#end>
55   - insert into ${tableName}
56   - <trim prefix="(" suffix=")" suffixOverrides=",">
57   -#foreach($column in $columns)
58   -#if($column.columnName != $pkColumn.columnName || !$pkColumn.increment)
59   - <if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">$column.columnName,</if>
60   -#end
61   -#end
62   - </trim>
63   - <trim prefix="values (" suffix=")" suffixOverrides=",">
64   -#foreach($column in $columns)
65   -#if($column.columnName != $pkColumn.columnName || !$pkColumn.increment)
66   - <if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">#{$column.javaField},</if>
67   -#end
68   -#end
69   - </trim>
70   - </insert>
71   -
72   - <update id="update${ClassName}" parameterType="${ClassName}">
73   - update ${tableName}
74   - <trim prefix="SET" suffixOverrides=",">
75   -#foreach($column in $columns)
76   -#if($column.columnName != $pkColumn.columnName)
77   - <if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">$column.columnName = #{$column.javaField},</if>
78   -#end
79   -#end
80   - </trim>
81   - where ${pkColumn.columnName} = #{${pkColumn.javaField}}
82   - </update>
83   -
84   - <delete id="delete${ClassName}ById" parameterType="${pkColumn.javaType}">
85   - delete from ${tableName} where ${pkColumn.columnName} = #{${pkColumn.javaField}}
86   - </delete>
87   -
88   - <delete id="delete${ClassName}ByIds" parameterType="String">
89   - delete from ${tableName} where ${pkColumn.columnName} in
90   - <foreach item="${pkColumn.javaField}" collection="array" open="(" separator="," close=")">
91   - #{${pkColumn.javaField}}
92   - </foreach>
93   - </delete>
94   -
95   -</mapper>
96 0 \ No newline at end of file
src/main/java/cn/iocoder/dashboard/modules/infra/convert/package-info.java deleted
1   -package cn.iocoder.dashboard.modules.infra.convert;
src/main/java/cn/iocoder/dashboard/modules/system/controller/test/package-info.java 0 → 100644
  1 +package cn.iocoder.dashboard.modules.system.controller.test;
... ...
src/main/java/cn/iocoder/dashboard/modules/system/controller/test/vo/SysTestDemoBaseVO.java 0 → 100644
  1 +package cn.iocoder.dashboard.modules.system.controller.test.vo;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import lombok.Data;
  5 +
  6 +import javax.validation.constraints.NotNull;
  7 +
  8 +/**
  9 +* 字典类型 Base VO,提供给添加、修改、详细的子 VO 使用
  10 +* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
  11 +*/
  12 +@Data
  13 +public class SysTestDemoBaseVO {
  14 +
  15 + @ApiModelProperty(value = "字典名称", required = true, example = "性别额")
  16 + @NotNull(message = "字典名称不能为空")
  17 + private String name;
  18 +
  19 + @ApiModelProperty(value = "字典类型", required = true, example = "sys_sex")
  20 + @NotNull(message = "字典类型不能为空")
  21 + private String dictType;
  22 +
  23 + @ApiModelProperty(value = "状态", required = true, example = "1")
  24 + @NotNull(message = "状态不能为空")
  25 + private Integer status;
  26 +
  27 + @ApiModelProperty(value = "备注", example = "我是备注")
  28 + private String remark;
  29 +
  30 +}
... ...
src/main/java/cn/iocoder/dashboard/modules/system/controller/test/vo/SysTestDemoCreateReqVO.java 0 → 100644
  1 +package cn.iocoder.dashboard.modules.system.controller.test.vo;
  2 +
  3 +import io.swagger.annotations.ApiModel;
  4 +import lombok.Data;
  5 +import lombok.EqualsAndHashCode;
  6 +import lombok.ToString;
  7 +
  8 +@ApiModel("字典类型创建 Request VO")
  9 +@Data
  10 +@EqualsAndHashCode(callSuper = true)
  11 +@ToString(callSuper = true)
  12 +public class SysTestDemoCreateReqVO extends SysTestDemoBaseVO {
  13 +
  14 +}
... ...
src/main/java/cn/iocoder/dashboard/modules/system/controller/test/vo/SysTestDemoPageReqVO.java 0 → 100644
  1 +package cn.iocoder.dashboard.modules.system.controller.test.vo;
  2 +
  3 +import cn.iocoder.dashboard.common.pojo.PageParam;
  4 +import io.swagger.annotations.ApiModel;
  5 +import io.swagger.annotations.ApiModelProperty;
  6 +import lombok.Data;
  7 +import lombok.EqualsAndHashCode;
  8 +import lombok.ToString;
  9 +import org.springframework.format.annotation.DateTimeFormat;
  10 +
  11 +import java.util.Date;
  12 +
  13 +import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
  14 +
  15 +@ApiModel("字典类型分页 Request VO")
  16 +@Data
  17 +@EqualsAndHashCode(callSuper = true)
  18 +@ToString(callSuper = true)
  19 +public class SysTestDemoPageReqVO extends PageParam {
  20 +
  21 + @ApiModelProperty(value = "字典名称", example = "性别额")
  22 + private String name;
  23 +
  24 + @ApiModelProperty(value = "字典类型", example = "sys_sex")
  25 + private String dictType;
  26 +
  27 + @ApiModelProperty(value = "状态", example = "1")
  28 + private Integer status;
  29 +
  30 + @ApiModelProperty(value = "备注", example = "我是备注")
  31 + private String remark;
  32 +
  33 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  34 + @ApiModelProperty(value = "开始创建时间")
  35 + private Date beginCreateTime;
  36 +
  37 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  38 + @ApiModelProperty(value = "结束创建时间")
  39 + private Date endCreateTime;
  40 +
  41 +}
... ...
src/main/java/cn/iocoder/dashboard/modules/system/controller/test/vo/SysTestDemoRespVO.java 0 → 100644
  1 +package cn.iocoder.dashboard.modules.system.controller.test.vo;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import io.swagger.annotations.*;
  6 +
  7 +@ApiModel("字典类型 Response VO")
  8 +@Data
  9 +@EqualsAndHashCode(callSuper = true)
  10 +@ToString(callSuper = true)
  11 +public class SysTestDemoRespVO extends SysTestDemoBaseVO {
  12 +
  13 + @ApiModelProperty(value = "字典主键", required = true, example = "1")
  14 + private Long id;
  15 +
  16 + @ApiModelProperty(value = "创建时间", required = true)
  17 + private Date createTime;
  18 +
  19 +}
... ...
src/main/java/cn/iocoder/dashboard/modules/system/controller/test/vo/SysTestDemoUpdateReqVO.java 0 → 100644
  1 +package cn.iocoder.dashboard.modules.system.controller.test.vo;
  2 +
  3 +import io.swagger.annotations.ApiModel;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +import lombok.Data;
  6 +import lombok.EqualsAndHashCode;
  7 +import lombok.ToString;
  8 +
  9 +import javax.validation.constraints.NotNull;
  10 +
  11 +@ApiModel("字典类型更新 Request VO")
  12 +@Data
  13 +@EqualsAndHashCode(callSuper = true)
  14 +@ToString(callSuper = true)
  15 +public class SysTestDemoUpdateReqVO extends SysTestDemoBaseVO {
  16 +
  17 + @ApiModelProperty(value = "字典主键", required = true, example = "1")
  18 + @NotNull(message = "字典主键不能为空")
  19 + private Long id;
  20 +
  21 +}
... ...
src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/test/SysTestDemoMapper.java 0 → 100644
  1 +package cn.iocoder.dashboard.modules.system.dal.mysql.dao.test;
  2 +
  3 +import cn.iocoder.dashboard.common.pojo.PageResult;
  4 +import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX;
  5 +import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
  6 +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.test.SysTestDemoDO;
  7 +import org.apache.ibatis.annotations.Mapper;
  8 +import cn.iocoder.dashboard.modules.system.controller.test.vo.SysTestDemoPageReqVO;
  9 +
  10 +/**
  11 +* 字典类型 Mapper
  12 +*
  13 +* @author 芋艿
  14 +*/
  15 +@Mapper
  16 +public interface SysTestDemoMapper extends BaseMapperX<SysTestDemoDO> {
  17 +
  18 + default PageResult<SysTestDemoDO> selectPage(SysTestDemoPageReqVO reqVO) {
  19 + return selectPage(reqVO, new QueryWrapperX<SysTestDemoDO>()
  20 + .likeIfPresent("name", reqVO.getName())
  21 + .eqIfPresent("dict_type", reqVO.getDictType())
  22 + .eqIfPresent("status", reqVO.getStatus())
  23 + .eqIfPresent("remark", reqVO.getRemark())
  24 + .betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
  25 + );
  26 + }
  27 +
  28 +}
... ...
src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/test/SysTestDemoDO.java 0 → 100644
  1 +package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.test;
  2 +
  3 +import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
  4 +import com.baomidou.mybatisplus.annotation.TableId;
  5 +import com.baomidou.mybatisplus.annotation.TableName;
  6 +import lombok.*;
  7 +
  8 +/**
  9 +* 字典类型 DO
  10 +*
  11 +* @author 芋艿
  12 +*/
  13 +@TableName("sys_test_demo")
  14 +@Data
  15 +@EqualsAndHashCode(callSuper = true)
  16 +@ToString(callSuper = true)
  17 +@Builder
  18 +@NoArgsConstructor
  19 +@AllArgsConstructor
  20 +public class SysTestDemoDO extends BaseDO {
  21 +
  22 + /**
  23 + * 字典主键
  24 + */
  25 + @TableId
  26 + private Long id;
  27 + /**
  28 + * 字典名称
  29 + */
  30 + private String name;
  31 + /**
  32 + * 字典类型
  33 + */
  34 + private String dictType;
  35 + /**
  36 + * 状态
  37 + */
  38 + private Integer status;
  39 + /**
  40 + * 备注
  41 + */
  42 + private String remark;
  43 +
  44 +}
... ...
src/main/java/cn/iocoder/dashboard/modules/system/service/test/SysTestDemoService.java 0 → 100644
  1 +package cn.iocoder.dashboard.modules.system.service.test;
  2 +
  3 +import cn.iocoder.dashboard.common.pojo.PageResult;
  4 +import cn.iocoder.dashboard.modules.system.controller.test.vo.SysTestDemoCreateReqVO;
  5 +import cn.iocoder.dashboard.modules.system.controller.test.vo.SysTestDemoPageReqVO;
  6 +import cn.iocoder.dashboard.modules.system.controller.test.vo.SysTestDemoUpdateReqVO;
  7 +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.test.SysTestDemoDO;
  8 +
  9 +import javax.validation.Valid;
  10 +import java.util.Collection;
  11 +import java.util.List;
  12 +
  13 +/**
  14 +* 字典类型 Service 接口
  15 +*
  16 +* @author 芋艿
  17 +*/
  18 +public interface SysTestDemoService {
  19 +
  20 + /**
  21 + * 创建字典类型
  22 + *
  23 + * @param createReqVO 创建信息
  24 + * @return 编号
  25 + */
  26 + Long createTestDemo(@Valid SysTestDemoCreateReqVO createReqVO);
  27 +
  28 + /**
  29 + * 更新字典类型
  30 + *
  31 + * @param updateReqVO 更新信息
  32 + */
  33 + void updateTestDemo(@Valid SysTestDemoUpdateReqVO updateReqVO);
  34 +
  35 + /**
  36 + * 删除字典类型
  37 + *
  38 + * @param id 编号
  39 + */
  40 + void deleteTestDemo(Long id);
  41 +
  42 + /**
  43 + * 获得字典类型
  44 + *
  45 + * @param id 编号
  46 + * @return 字典类型
  47 + */
  48 + SysTestDemoDO getTestDemo(Long id);
  49 +
  50 + /**
  51 + * 获得字典类型列表
  52 + *
  53 + * @param ids 编号
  54 + * @return 字典类型列表
  55 + */
  56 + List<SysTestDemoDO> getTestDemoList(Collection<Long> ids);
  57 +
  58 + /**
  59 + * 获得字典类型分页
  60 + *
  61 + * @param pageReqVO 分页查询
  62 + * @return 字典类型分页
  63 + */
  64 + PageResult<SysTestDemoDO> getTestDemoPage(SysTestDemoPageReqVO pageReqVO);
  65 +
  66 +}
... ...
src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenBuilder.java
... ... @@ -17,6 +17,8 @@ import org.springframework.stereotype.Component;
17 17 import java.math.BigDecimal;
18 18 import java.util.*;
19 19  
  20 +import static cn.hutool.core.text.CharSequenceUtil.*;
  21 +
20 22 /**
21 23 * 代码生成器的 Builder,负责:
22 24 * 1. 将数据库的表 {@link ToolInformationSchemaTableDO} 定义,构建成 {@link ToolCodegenTableDO}
... ... @@ -26,6 +28,18 @@ import java.util.*;
26 28 public class ToolCodegenBuilder {
27 29  
28 30 /**
  31 + * Module 名字的映射 TODO 后续梳理到配置类
  32 + *
  33 + * key:模块的完整名
  34 + * value:模块的缩写名
  35 + */
  36 + private static final Map<String, String> moduleNames = MapUtil.<String, String>builder()
  37 + .put("system", "sys")
  38 + .put("infra", "inf")
  39 + .put("tool", "tool")
  40 + .build();
  41 +
  42 + /**
29 43 * 字段名与 {@link ToolCodegenColumnListConditionEnum} 的默认映射
30 44 * 注意,字段的匹配以后缀的方式
31 45 */
... ... @@ -93,9 +107,9 @@ public class ToolCodegenBuilder {
93 107 CREATE_OPERATION_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS);
94 108 UPDATE_OPERATION_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS);
95 109 LIST_OPERATION_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS);
96   - LIST_OPERATION_EXCLUDE_COLUMN.remove("create_time"); // 创建时间,还是可能需要传递的
  110 + LIST_OPERATION_EXCLUDE_COLUMN.remove("createTime"); // 创建时间,还是可能需要传递的
97 111 LIST_OPERATION_RESULT_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS);
98   - LIST_OPERATION_RESULT_EXCLUDE_COLUMN.remove("create_time"); // 创建时间,还是需要返回的
  112 + LIST_OPERATION_RESULT_EXCLUDE_COLUMN.remove("createTime"); // 创建时间,还是需要返回的
99 113 }
100 114  
101 115 public ToolCodegenTableDO buildTable(ToolInformationSchemaTableDO schemaTable) {
... ... @@ -110,13 +124,12 @@ public class ToolCodegenBuilder {
110 124 * @param table 表定义
111 125 */
112 126 private void initTableDefault(ToolCodegenTableDO table) {
113   - table.setModuleName(StrUtil.subBefore(table.getTableName(),
114   - '_', false)); // 第一个 _ 前缀的前面,作为 module 名字
115   - table.setBusinessName(StrUtil.subAfter(table.getTableName(),
116   - '_', false)); // 第一个 _ 前缀的后面,作为 module 名字
117   - table.setBusinessName(StrUtil.toCamelCase(table.getBusinessName())); // 可能存在多个 _ 的情况,转换成驼峰
118   - table.setClassName(StrUtil.upperFirst(StrUtil.toCamelCase(table.getTableName()))); // 驼峰 + 首字母大写
119   - table.setClassComment(StrUtil.subBefore(table.getTableComment(), // 去除结尾的表,作为类描述
  127 + table.setModuleName(getFullModuleName(StrUtil.subBefore(table.getTableName(),
  128 + '_', false))); // 第一个 _ 前缀的前面,作为 module 名字
  129 + table.setBusinessName(toCamelCase(subAfter(table.getTableName(),
  130 + '_', false))); // 第一步,第一个 _ 前缀的后面,作为 module 名字; 第二步,可能存在多个 _ 的情况,转换成驼峰
  131 + table.setClassName(upperFirst(toCamelCase(table.getTableName()))); // 驼峰 + 首字母大写
  132 + table.setClassComment(subBefore(table.getTableComment(), // 去除结尾的表,作为类描述
120 133 '表', true));
121 134 table.setAuthor("芋艿"); // TODO 稍后改成创建人
122 135 table.setTemplateType(ToolCodegenTemplateTypeEnum.CRUD.getType());
... ... @@ -144,7 +157,7 @@ public class ToolCodegenBuilder {
144 157  
145 158 private void processColumnJava(ToolCodegenColumnDO column) {
146 159 // 处理 javaField 字段
147   - column.setJavaField(StrUtil.toCamelCase(column.getColumnName()));
  160 + column.setJavaField(toCamelCase(column.getColumnName()));
148 161 // 处理 dictType 字段,暂无
149 162 // 处理 javaType 字段
150 163 String dbType = StrUtil.subBefore(column.getColumnType(), '(', false);
... ... @@ -194,4 +207,27 @@ public class ToolCodegenBuilder {
194 207 }
195 208 }
196 209  
  210 + /**
  211 + * 获得模块的缩略名
  212 + *
  213 + * @param fullModuleName 模块的完整名
  214 + * @return 缩略名
  215 + */
  216 + public String getSimpleModuleName(String fullModuleName) {
  217 + return moduleNames.getOrDefault(fullModuleName, fullModuleName);
  218 + }
  219 +
  220 + /**
  221 + * 获得模块的完整名
  222 + *
  223 + * @param shortModuleName 模块的缩略名
  224 + * @return 完整名
  225 + */
  226 + public String getFullModuleName(String shortModuleName) {
  227 + return moduleNames.entrySet().stream()
  228 + .filter(entry -> entry.getValue().equals(shortModuleName)) // 匹配
  229 + .findFirst().map(Map.Entry::getKey) // 返回 key
  230 + .orElse(shortModuleName); // 兜底返回 shortModuleName
  231 + }
  232 +
197 233 }
... ...
src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenEngine.java
... ... @@ -14,6 +14,7 @@ import cn.iocoder.dashboard.util.collection.CollectionUtils;
14 14 import cn.iocoder.dashboard.util.date.DateUtils;
15 15 import org.springframework.stereotype.Component;
16 16  
  17 +import javax.annotation.Resource;
17 18 import java.util.HashMap;
18 19 import java.util.List;
19 20 import java.util.Map;
... ... @@ -31,6 +32,9 @@ import static cn.hutool.core.text.CharSequenceUtil.*;
31 32 @Component
32 33 public class ToolCodegenEngine {
33 34  
  35 + @Resource
  36 + private ToolCodegenBuilder codegenBuilder;
  37 +
34 38 /**
35 39 * 模板引擎,由 hutool 实现
36 40 */
... ... @@ -69,9 +73,15 @@ public class ToolCodegenEngine {
69 73 Map<String, Object> bindingMap = new HashMap<>(globalBindingMap);
70 74 bindingMap.put("table", table);
71 75 bindingMap.put("columns", columns);
72   - bindingMap.put("primaryColumn", CollectionUtils.findFirst(columns, ToolCodegenColumnDO::getPrimaryKey));
73   - bindingMap.put("simpleClassName", upperFirst(toCamelCase(subAfter( // 去掉第一个驼峰,例如说 SysUser 去掉后是 User
74   - toUnderlineCase(table.getClassName()), '_', false))));
  76 + bindingMap.put("primaryColumn", CollectionUtils.findFirst(columns, ToolCodegenColumnDO::getPrimaryKey)); // 主键字段
  77 + String simpleModuleName = codegenBuilder.getSimpleModuleName(table.getModuleName());
  78 + bindingMap.put("simpleModuleName", simpleModuleName); // 将 system 转成 sys
  79 + // className 相关
  80 + String simpleClassName = subAfter(table.getClassName(), upperFirst(simpleModuleName)
  81 + , false); // 将 TestDictType 转换成 DictType. 因为在 create 等方法后,不需要带上 Test 前缀
  82 + bindingMap.put("simpleClassName", simpleClassName);
  83 + bindingMap.put("simpleClassName_underlineCase", toUnderlineCase(simpleClassName)); // 将 DictType 转换成 dict_type
  84 + bindingMap.put("classNameVar", lowerFirst(simpleClassName)); // 将 DictType 转换成 dictType,用于变量
75 85 // 执行生成
76 86 // String result = templateEngine.getTemplate("codegen/dal/do.vm").render(bindingMap);
77 87 // String result = templateEngine.getTemplate("codegen/dal/mapper.vm").render(bindingMap);
... ... @@ -80,7 +90,10 @@ public class ToolCodegenEngine {
80 90 // String result = templateEngine.getTemplate("codegen/controller/vo/createReqVO.vm").render(bindingMap);
81 91 // String result = templateEngine.getTemplate("codegen/controller/vo/updateReqVO.vm").render(bindingMap);
82 92 // String result = templateEngine.getTemplate("codegen/controller/vo/respVO.vm").render(bindingMap);
  93 +// String result = templateEngine.getTemplate("codegen/convert/convert.vm").render(bindingMap);
  94 +// String result = templateEngine.getTemplate("codegen/enums/errorcode.vm").render(bindingMap);
83 95 String result = templateEngine.getTemplate("codegen/service/service.vm").render(bindingMap);
  96 +// String result = templateEngine.getTemplate("codegen/service/serviceImpl.vm").render(bindingMap);
84 97 System.out.println(result);
85 98 }
86 99  
... ...
src/main/resources/codegen/controller/vo/updateReqVO.vm
... ... @@ -6,8 +6,8 @@ import io.swagger.annotations.*;
6 6 import javax.validation.constraints.*;
7 7 ## 处理 Date 字段的引入
8 8 #foreach ($column in $columns)
9   -#if (${column.updateOperation} && (!${column.createOperation} || !${column.listOperationResult}))
10   - && ${column.javaType} == "Date")## 时间类型
  9 +#if (${column.updateOperation} && (!${column.createOperation} || !${column.listOperationResult})
  10 + && ${column.javaType} == "Date"))## 时间类型
11 11 import org.springframework.format.annotation.DateTimeFormat;
12 12  
13 13 import static ${DateUtilsClassName}.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
... ...
src/main/resources/codegen/convert/convert.vm 0 → 100644
  1 +package ${basePackage}.${table.moduleName}.convert.${table.businessName};
  2 +
  3 +import org.mapstruct.Mapper;
  4 +import org.mapstruct.factory.Mappers;
  5 +import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.*;
  6 +import ${basePackage}.${table.moduleName}.dal.mysql.dataobject.${table.businessName}.${table.className}DO;
  7 +
  8 +/**
  9 +* ${table.classComment} Convert
  10 +*
  11 +* @author ${table.author}
  12 +*/
  13 +@Mapper
  14 +public interface ${table.className}Convert {
  15 +
  16 + ${table.className}Convert INSTANCE = Mappers.getMapper(${table.className}Convert.class);
  17 +
  18 + ${table.className}DO convert(${table.className}CreateReqVO bean);
  19 +
  20 + ${table.className}DO convert(${table.className}UpdateReqVO bean);
  21 +
  22 +}
... ...
src/main/resources/codegen/dal/do.vm
... ... @@ -3,7 +3,7 @@ package ${basePackage}.${table.moduleName}.dal.mysql.dataobject.${table.business
3 3 import lombok.*;
4 4 import java.util.*;
5 5 import com.baomidou.mybatisplus.annotation.*;
6   -import ${BaseDOClassName};
  6 +import ${baseDOClassName};
7 7  
8 8 /**
9 9 * ${table.classComment} DO
... ...
src/main/resources/codegen/dal/mapper.vm
... ... @@ -5,6 +5,7 @@ import ${QueryWrapperClassName};
5 5 import ${BaseMapperClassName};
6 6 import ${basePackage}.${table.moduleName}.dal.mysql.dataobject.${table.businessName}.${table.className}DO;
7 7 import org.apache.ibatis.annotations.Mapper;
  8 +import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.${table.className}PageReqVO;
8 9  
9 10 /**
10 11 * ${table.classComment} Mapper
... ... @@ -26,19 +27,19 @@ public interface ${table.className}Mapper extends BaseMapperX&lt;${table.className}
26 27 .neIfPresent("${column.columnName}", reqVO.get${JavaField}())
27 28 #end
28 29 #if (${column.listOperationCondition} == ">")##情况三,> 的时候
29   - .gtIfPresent("${column.columnName}", reqVO.get${JavaField}())
  30 + .gtIfPresent("${column.columnName}", reqVO.get${JavaField}())
30 31 #end
31 32 #if (${column.listOperationCondition} == ">=")##情况四,>= 的时候
32   - .geIfPresent("${column.columnName}", reqVO.get${JavaField}())
  33 + .geIfPresent("${column.columnName}", reqVO.get${JavaField}())
33 34 #end
34 35 #if (${column.listOperationCondition} == "<")##情况五,< 的时候
35   - .gtIfPresent("${column.columnName}", reqVO.get${JavaField}())
  36 + .gtIfPresent("${column.columnName}", reqVO.get${JavaField}())
36 37 #end
37 38 #if (${column.listOperationCondition} == "LIKE")##情况七,Like 的时候
38   - .likeIfPresent("${column.columnName}", reqVO.get${JavaField}())
  39 + .likeIfPresent("${column.columnName}", reqVO.get${JavaField}())
39 40 #end
40 41 #if (${column.listOperationCondition} == "BETWEEN")##情况八,Between 的时候
41   - .betweenIfPresent("${column.columnName}", reqVO.getBegin${JavaField}(), reqVO.getEnd${JavaField}())
  42 + .betweenIfPresent("${column.columnName}", reqVO.getBegin${JavaField}(), reqVO.getEnd${JavaField}())
42 43 #end
43 44 #end
44 45 #end
... ...
src/main/resources/codegen/enums/errorcode.vm 0 → 100644
  1 +// ========== ${table.classCommet} TODO 补充编号 ==========
  2 +ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_NOT_FOUND = new ErrorCode(TODO 补充编号, "${table.classComment}不存在}");
... ...
src/main/resources/codegen/service/service.vm
... ... @@ -17,7 +17,7 @@ public interface ${table.className}Service {
17 17 * 创建${table.classComment}
18 18 *
19 19 * @param createReqVO 创建信息
20   - * @return ${class.description}
  20 + * @return 编号
21 21 */
22 22 ${primaryColumn.javaType} create${simpleClassName}(@Valid ${table.className}CreateReqVO createReqVO);
23 23  
... ... @@ -39,7 +39,7 @@ public interface ${table.className}Service {
39 39 * 获得${table.classComment}
40 40 *
41 41 * @param id 编号
42   - * @return ${class.description}
  42 + * @return ${table.classComment}
43 43 */
44 44 ${table.className}DO get${simpleClassName}(${primaryColumn.javaType} id);
45 45  
... ... @@ -47,7 +47,7 @@ public interface ${table.className}Service {
47 47 * 获得${table.classComment}列表
48 48 *
49 49 * @param ids 编号
50   - * @return ${class.classComment}列表
  50 + * @return ${table.classComment}列表
51 51 */
52 52 List<${table.className}DO> get${simpleClassName}List(Collection<${primaryColumn.javaType}> ids);
53 53  
... ... @@ -55,7 +55,7 @@ public interface ${table.className}Service {
55 55 * 获得${table.classComment}分页
56 56 *
57 57 * @param pageReqVO 分页查询
58   - * @return ${class.classComment}分页
  58 + * @return ${table.classComment}分页
59 59 */
60 60 PageResult<${table.className}DO> get${simpleClassName}Page(${table.className}PageReqVO pageReqVO);
61 61  
... ...
src/main/resources/codegen/service/serviceImpl.vm 0 → 100644
  1 +package ${basePackage}.${table.moduleName}.service.${table.businessName}.impl;
  2 +
  3 +import org.springframework.beans.factory.annotation.Autowired;
  4 +import org.springframework.stereotype.Service;
  5 +import javax.annotation.Resource;
  6 +import org.springframework.validation.annotation.Validated;
  7 +
  8 +import java.util.*;
  9 +import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.*;
  10 +import ${basePackage}.${table.moduleName}.dal.mysql.dataobject.${table.businessName}.${table.className}DO;
  11 +import ${PageResultClassName};
  12 +
  13 +import static ${basePackage}.${table.moduleName}.enums.${simpleModuleName.substring(0,1).toUpperCase()}${simpleModuleName.substring(1)}ErrorCodeConstants.*;
  14 +
  15 +/**
  16 +* ${table.classComment} Service 实现类
  17 +*
  18 +* @author ${table.author}
  19 +*/
  20 +@Validated
  21 +public class ${table.className}ServiceImpl implements {table.className}Service {
  22 +
  23 + @Resource
  24 + private ${table.className}Mapper ${classNameVar}Mapper;
  25 +
  26 + @Override
  27 + public ${primaryColumn.javaType} create${simpleClassName}(@Valid ${table.className}CreateReqVO createReqVO) {
  28 + }
  29 +
  30 +}
... ...
src/test/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenEngineTest.java
... ... @@ -24,7 +24,7 @@ public class ToolCodegenEngineTest {
24 24  
25 25 @Test
26 26 public void testExecute() {
27   - ToolCodegenTableDO table = codegenTableMapper.selectById(8);
  27 + ToolCodegenTableDO table = codegenTableMapper.selectById(10);
28 28 List<ToolCodegenColumnDO> columns = codegenColumnMapper.selectByTableId(table.getId());
29 29 codegenEngine.execute(table, columns);
30 30 }
... ...
src/test/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenServiceImplTest.java
... ... @@ -16,7 +16,7 @@ class ToolCodegenServiceImplTest {
16 16  
17 17 @Test
18 18 public void tetCreateCodegenTable() {
19   - toolCodegenService.createCodegenTable("sys_dict_type");
  19 + toolCodegenService.createCodegenTable("sys_test_demo");
20 20 }
21 21  
22 22 }
... ...