代码生成工具支持MyBatisDynamicSql

This commit is contained in:
AlanScipio
2024-02-02 18:46:25 +08:00
parent 566227d699
commit 906a6d7467
32 changed files with 1678 additions and 790 deletions

View File

@@ -1,22 +1,5 @@
package com.ruoyi.gen.controller;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
@@ -28,6 +11,16 @@ import com.ruoyi.gen.domain.GenTable;
import com.ruoyi.gen.domain.GenTableColumn;
import com.ruoyi.gen.service.IGenTableColumnService;
import com.ruoyi.gen.service.IGenTableService;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 代码生成 操作处理
@@ -167,8 +160,8 @@ public class GenController extends BaseController {
*/
@RequiresPermissions("tool:gen:edit")
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
@GetMapping("/synchDb/{tableName}")
public AjaxResult synchDb(@PathVariable("tableName") String tableName) {
@GetMapping("/syncDb/{tableName}")
public AjaxResult syncDb(@PathVariable("tableName") String tableName) {
genTableService.synchDb(tableName);
return success();
}
@@ -190,7 +183,7 @@ public class GenController extends BaseController {
*/
private void genCode(HttpServletResponse response, byte[] data) throws IOException {
response.reset();
response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\"");
response.setHeader("Content-Disposition", "attachment; filename=\"generatedCodes.zip\"");
response.addHeader("Content-Length", "" + data.length);
response.setContentType("application/octet-stream; charset=UTF-8");
IOUtils.write(data, response.getOutputStream());

View File

@@ -1,13 +1,14 @@
package com.ruoyi.gen.domain;
import java.io.Serial;
import java.util.List;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import org.apache.commons.lang3.ArrayUtils;
import com.ruoyi.common.core.constant.GenConstants;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.web.domain.BaseEntity;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import org.apache.commons.lang3.ArrayUtils;
import java.io.Serial;
import java.util.List;
/**
* 业务表 gen_table
@@ -46,6 +47,9 @@ public class GenTable extends BaseEntity
/** 前端类型element-ui模版 element-plus模版 */
private String tplWebType;
/** 后端类型MyBaitsDynamicSQL模板常规模板 */
private String tplBackendType;
/** 生成包路径 */
@NotBlank(message = "生成包路径不能为空")
private String packageName;
@@ -100,6 +104,14 @@ public class GenTable extends BaseEntity
/** 上级菜单名称字段 */
private String parentMenuName;
public String getTplBackendType() {
return tplBackendType;
}
public void setTplBackendType(String tplBackendType) {
this.tplBackendType = tplBackendType;
}
public Long getTableId()
{
return tableId;

View File

@@ -1,5 +1,6 @@
package com.ruoyi.gen.domain;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.validation.constraints.NotBlank;
import com.ruoyi.common.core.utils.StringUtils;
@@ -52,6 +53,12 @@ public class GenTableColumn extends BaseEntity {
@NotBlank(message = "Java属性不能为空")
private String javaField;
/**
* JAVA字段名开头大写
*/
@JsonIgnore
private transient String javaFieldUpper;
/**
* 是否主键1是
*/
@@ -107,6 +114,14 @@ public class GenTableColumn extends BaseEntity {
*/
private Integer sort;
public String getJavaFieldUpper() {
return javaFieldUpper;
}
public void setJavaFieldUpper(String javaFieldUpper) {
this.javaFieldUpper = javaFieldUpper;
}
public void setColumnId(Long columnId) {
this.columnId = columnId;
}

View File

@@ -1,27 +1,5 @@
package com.ruoyi.gen.service;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.constant.Constants;
@@ -37,6 +15,28 @@ import com.ruoyi.gen.mapper.GenTableMapper;
import com.ruoyi.gen.util.GenUtils;
import com.ruoyi.gen.util.VelocityInitializer;
import com.ruoyi.gen.util.VelocityUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* 业务 服务层实现
@@ -187,7 +187,7 @@ public class GenTableServiceImpl implements IGenTableService {
VelocityContext context = VelocityUtils.prepareContext(table);
// 获取模板列表
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType());
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType(), table.getTplBackendType());
for (String template : templates) {
// 渲染模板
StringWriter sw = new StringWriter();
@@ -232,7 +232,7 @@ public class GenTableServiceImpl implements IGenTableService {
VelocityContext context = VelocityUtils.prepareContext(table);
// 获取模板列表
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType());
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType(), table.getTplBackendType());
for (String template : templates) {
if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) {
// 渲染模板
@@ -329,7 +329,7 @@ public class GenTableServiceImpl implements IGenTableService {
VelocityContext context = VelocityUtils.prepareContext(table);
// 获取模板列表
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType());
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType(), table.getTplBackendType());
for (String template : templates) {
// 渲染模板
StringWriter sw = new StringWriter();

View File

@@ -1,25 +1,24 @@
package com.ruoyi.gen.util;
import java.util.Arrays;
import org.apache.commons.lang3.RegExUtils;
import com.ruoyi.common.core.constant.GenConstants;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.gen.config.GenConfig;
import com.ruoyi.gen.domain.GenTable;
import com.ruoyi.gen.domain.GenTableColumn;
import org.apache.commons.lang3.RegExUtils;
import java.util.Arrays;
/**
* 代码生成器 工具类
*
*
* @author ruoyi
*/
public class GenUtils
{
public class GenUtils {
/**
* 初始化表信息
*/
public static void initTable(GenTable genTable, String operName)
{
public static void initTable(GenTable genTable, String operName) {
genTable.setClassName(convertClassName(genTable.getTableName()));
genTable.setPackageName(GenConfig.getPackageName());
genTable.setModuleName(getModuleName(GenConfig.getPackageName()));
@@ -32,8 +31,7 @@ public class GenUtils
/**
* 初始化列属性字段
*/
public static void initColumnField(GenTableColumn column, GenTable table)
{
public static void initColumnField(GenTableColumn column, GenTable table) {
String dataType = getDbType(column.getColumnType());
String columnName = column.getColumnName();
column.setTableId(table.getTableId());
@@ -44,36 +42,28 @@ public class GenUtils
column.setJavaType(GenConstants.TYPE_STRING);
column.setQueryType(GenConstants.QUERY_EQ);
if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType))
{
if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType)) {
// 字符串长度超过500设置为文本域
Integer columnLength = getColumnLength(column.getColumnType());
String htmlType = columnLength >= 500 || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType) ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT;
column.setHtmlType(htmlType);
}
else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType))
{
} else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)) {
column.setJavaType(GenConstants.TYPE_DATE);
column.setHtmlType(GenConstants.HTML_DATETIME);
}
else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType))
{
} else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) {
column.setHtmlType(GenConstants.HTML_INPUT);
// 如果是浮点型 统一用BigDecimal
String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ",");
if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0)
{
if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) {
column.setJavaType(GenConstants.TYPE_BIGDECIMAL);
}
// 如果是整形
else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10)
{
else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) {
column.setJavaType(GenConstants.TYPE_INTEGER);
}
// 长整形
else
{
else {
column.setJavaType(GenConstants.TYPE_LONG);
}
}
@@ -82,74 +72,63 @@ public class GenUtils
column.setIsInsert(GenConstants.REQUIRE);
// 编辑字段
if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk())
{
if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk()) {
column.setIsEdit(GenConstants.REQUIRE);
}
// 列表字段
if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk())
{
if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk()) {
column.setIsList(GenConstants.REQUIRE);
}
// 查询字段
if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk())
{
if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk()) {
column.setIsQuery(GenConstants.REQUIRE);
}
// 查询字段类型
if (StringUtils.endsWithIgnoreCase(columnName, "name"))
{
if (StringUtils.endsWithIgnoreCase(columnName, "name")) {
column.setQueryType(GenConstants.QUERY_LIKE);
}
// 状态字段设置单选框
if (StringUtils.endsWithIgnoreCase(columnName, "status"))
{
if (StringUtils.endsWithIgnoreCase(columnName, "status")) {
column.setHtmlType(GenConstants.HTML_RADIO);
}
// 类型&性别字段设置下拉框
else if (StringUtils.endsWithIgnoreCase(columnName, "type")
|| StringUtils.endsWithIgnoreCase(columnName, "sex"))
{
|| StringUtils.endsWithIgnoreCase(columnName, "sex")) {
column.setHtmlType(GenConstants.HTML_SELECT);
}
// 图片字段设置图片上传控件
else if (StringUtils.endsWithIgnoreCase(columnName, "image"))
{
else if (StringUtils.endsWithIgnoreCase(columnName, "image")) {
column.setHtmlType(GenConstants.HTML_IMAGE_UPLOAD);
}
// 文件字段设置文件上传控件
else if (StringUtils.endsWithIgnoreCase(columnName, "file"))
{
else if (StringUtils.endsWithIgnoreCase(columnName, "file")) {
column.setHtmlType(GenConstants.HTML_FILE_UPLOAD);
}
// 内容字段设置富文本控件
else if (StringUtils.endsWithIgnoreCase(columnName, "content"))
{
else if (StringUtils.endsWithIgnoreCase(columnName, "content")) {
column.setHtmlType(GenConstants.HTML_EDITOR);
}
}
/**
* 校验数组是否包含指定值
*
* @param arr 数组
*
* @param arr 数组
* @param targetValue 值
* @return 是否包含
*/
public static boolean arraysContains(String[] arr, String targetValue)
{
public static boolean arraysContains(String[] arr, String targetValue) {
return Arrays.asList(arr).contains(targetValue);
}
/**
* 获取模块名
*
*
* @param packageName 包名
* @return 模块名
*/
public static String getModuleName(String packageName)
{
public static String getModuleName(String packageName) {
int lastIndex = packageName.lastIndexOf(".");
int nameLength = packageName.length();
return StringUtils.substring(packageName, lastIndex + 1, nameLength);
@@ -157,12 +136,11 @@ public class GenUtils
/**
* 获取业务名
*
*
* @param tableName 表名
* @return 业务名
*/
public static String getBusinessName(String tableName)
{
public static String getBusinessName(String tableName) {
int lastIndex = tableName.lastIndexOf("_");
int nameLength = tableName.length();
return StringUtils.substring(tableName, lastIndex + 1, nameLength);
@@ -170,16 +148,14 @@ public class GenUtils
/**
* 表名转换成Java类名
*
*
* @param tableName 表名称
* @return 类名
*/
public static String convertClassName(String tableName)
{
public static String convertClassName(String tableName) {
boolean autoRemovePre = GenConfig.getAutoRemovePre();
String tablePrefix = GenConfig.getTablePrefix();
if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix))
{
if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) {
String[] searchList = StringUtils.split(tablePrefix, ",");
tableName = replaceFirst(tableName, searchList);
}
@@ -188,19 +164,15 @@ public class GenUtils
/**
* 批量替换前缀
*
* @param replacementm 替换值
* @param searchList 替换列表
* @return
*
* @param replacement 替换值
* @param searchList 替换列表
*/
public static String replaceFirst(String replacementm, String[] searchList)
{
String text = replacementm;
for (String searchString : searchList)
{
if (replacementm.startsWith(searchString))
{
text = replacementm.replaceFirst(searchString, "");
public static String replaceFirst(String replacement, String[] searchList) {
String text = replacement;
for (String searchString : searchList) {
if (replacement.startsWith(searchString)) {
text = replacement.replaceFirst(searchString, "");
break;
}
}
@@ -209,48 +181,39 @@ public class GenUtils
/**
* 关键字替换
*
*
* @param text 需要被替换的名字
* @return 替换后的名字
*/
public static String replaceText(String text)
{
public static String replaceText(String text) {
return RegExUtils.replaceAll(text, "(?:表|若依)", "");
}
/**
* 获取数据库类型字段
*
*
* @param columnType 列类型
* @return 截取后的列类型
*/
public static String getDbType(String columnType)
{
if (StringUtils.indexOf(columnType, "(") > 0)
{
public static String getDbType(String columnType) {
if (StringUtils.indexOf(columnType, "(") > 0) {
return StringUtils.substringBefore(columnType, "(");
}
else
{
} else {
return columnType;
}
}
/**
* 获取字段长度
*
*
* @param columnType 列类型
* @return 截取后的列类型
*/
public static Integer getColumnLength(String columnType)
{
if (StringUtils.indexOf(columnType, "(") > 0)
{
public static Integer getColumnLength(String columnType) {
if (StringUtils.indexOf(columnType, "(") > 0) {
String length = StringUtils.substringBetween(columnType, "(", ")");
return Integer.valueOf(length);
}
else
{
} else {
return 0;
}
}

View File

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

View File

@@ -1,10 +1,5 @@
package com.ruoyi.gen.util;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.velocity.VelocityContext;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.constant.GenConstants;
@@ -12,21 +7,32 @@ import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.gen.domain.GenTable;
import com.ruoyi.gen.domain.GenTableColumn;
import org.apache.velocity.VelocityContext;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* 模板工具类
*
*
* @author ruoyi
*/
public class VelocityUtils
{
/** 项目空间路径 */
public class VelocityUtils {
/**
* 项目空间路径
*/
private static final String PROJECT_PATH = "main/java";
/** mybatis空间路径 */
/**
* mybatis空间路径
*/
private static final String MYBATIS_PATH = "main/resources/mapper";
/** 默认上级菜单,系统工具 */
/**
* 默认上级菜单,系统工具
*/
private static final String DEFAULT_PARENT_MENU_ID = "3";
/**
@@ -34,8 +40,7 @@ public class VelocityUtils
*
* @return 模板列表
*/
public static VelocityContext prepareContext(GenTable genTable)
{
public static VelocityContext prepareContext(GenTable genTable) {
String moduleName = genTable.getModuleName();
String businessName = genTable.getBusinessName();
String packageName = genTable.getPackageName();
@@ -62,30 +67,27 @@ public class VelocityUtils
velocityContext.put("table", genTable);
velocityContext.put("dicts", getDicts(genTable));
setMenuVelocityContext(velocityContext, genTable);
if (GenConstants.TPL_TREE.equals(tplCategory))
{
if (GenConstants.TPL_TREE.equals(tplCategory)) {
setTreeVelocityContext(velocityContext, genTable);
}
if (GenConstants.TPL_SUB.equals(tplCategory))
{
if (GenConstants.TPL_SUB.equals(tplCategory)) {
setSubVelocityContext(velocityContext, genTable);
}
addJavaFieldUpperCase(genTable.getColumns()); //javaField首字母大写
return velocityContext;
}
public static void setMenuVelocityContext(VelocityContext context, GenTable genTable)
{
public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) {
String options = genTable.getOptions();
JSONObject paramsObj = JSON.parseObject(options);
String parentMenuId = getParentMenuId(paramsObj);
context.put("parentMenuId", parentMenuId);
}
public static void setTreeVelocityContext(VelocityContext context, GenTable genTable)
{
public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) {
String options = genTable.getOptions();
JSONObject paramsObj = JSON.parseObject(options);
String treeCode = getTreecode(paramsObj);
String treeCode = getTreeCode(paramsObj);
String treeParentCode = getTreeParentCode(paramsObj);
String treeName = getTreeName(paramsObj);
@@ -93,18 +95,15 @@ public class VelocityUtils
context.put("treeParentCode", treeParentCode);
context.put("treeName", treeName);
context.put("expandColumn", getExpandColumn(genTable));
if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE))
{
if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) {
context.put("tree_parent_code", paramsObj.getString(GenConstants.TREE_PARENT_CODE));
}
if (paramsObj.containsKey(GenConstants.TREE_NAME))
{
if (paramsObj.containsKey(GenConstants.TREE_NAME)) {
context.put("tree_name", paramsObj.getString(GenConstants.TREE_NAME));
}
}
public static void setSubVelocityContext(VelocityContext context, GenTable genTable)
{
public static void setSubVelocityContext(VelocityContext context, GenTable genTable) {
GenTable subTable = genTable.getSubTable();
String subTableName = genTable.getSubTableName();
String subTableFkName = genTable.getSubTableFkName();
@@ -123,36 +122,40 @@ public class VelocityUtils
/**
* 获取模板信息
* @param tplCategory 生成的模板
* @param tplWebType 前端类型
*
* @param tplCategory 生成的模板
* @param tplWebType 前端类型
* @param tplBackendType 后端类型
* @return 模板列表
*/
public static List<String> getTemplateList(String tplCategory, String tplWebType)
{
public static List<String> getTemplateList(String tplCategory, String tplWebType, String tplBackendType) {
List<String> templates = new ArrayList<>();
//后端
if ("mybatis-dynamic".equals(tplBackendType)) {
//MyBatis Dynamic SQL
templates.add("vm/java/controller-dynamic.java.vm");
templates.add("vm/java/serviceImpl-dynamic.java.vm");
} else {
//常规
templates.add("vm/java/domain.java.vm");
templates.add("vm/java/controller.java.vm");
templates.add("vm/java/serviceImpl.java.vm");
templates.add("vm/java/mapper.java.vm");
templates.add("vm/xml/mapper.xml.vm");
}
templates.add("vm/java/service.java.vm");
templates.add("vm/sql/sql.vm");
//前端
templates.add("vm/js/api.js.vm");
String useWebType = "vm/vue";
if ("element-plus".equals(tplWebType))
{
if ("element-plus".equals(tplWebType)) {
useWebType = "vm/vue/v3";
}
List<String> templates = new ArrayList<String>();
templates.add("vm/java/domain.java.vm");
templates.add("vm/java/mapper.java.vm");
templates.add("vm/java/service.java.vm");
templates.add("vm/java/serviceImpl.java.vm");
templates.add("vm/java/controller.java.vm");
templates.add("vm/xml/mapper.xml.vm");
templates.add("vm/sql/sql.vm");
templates.add("vm/js/api.js.vm");
if (GenConstants.TPL_CRUD.equals(tplCategory))
{
if (GenConstants.TPL_CRUD.equals(tplCategory)) {
templates.add(useWebType + "/index.vue.vm");
}
else if (GenConstants.TPL_TREE.equals(tplCategory))
{
} else if (GenConstants.TPL_TREE.equals(tplCategory)) {
templates.add(useWebType + "/index-tree.vue.vm");
}
else if (GenConstants.TPL_SUB.equals(tplCategory))
{
} else if (GenConstants.TPL_SUB.equals(tplCategory)) {
templates.add(useWebType + "/index.vue.vm");
templates.add("vm/java/sub-domain.java.vm");
}
@@ -162,8 +165,7 @@ public class VelocityUtils
/**
* 获取文件名
*/
public static String getFileName(String template, GenTable genTable)
{
public static String getFileName(String template, GenTable genTable) {
// 文件名称
String fileName = "";
// 包路径
@@ -179,48 +181,32 @@ public class VelocityUtils
String mybatisPath = MYBATIS_PATH + "/" + moduleName;
String vuePath = "vue";
if (template.contains("domain.java.vm"))
{
if (template.contains("domain.java.vm")) {
fileName = StringUtils.format("{}/domain/{}.java", javaPath, className);
}
if (template.contains("sub-domain.java.vm") && StringUtils.equals(GenConstants.TPL_SUB, genTable.getTplCategory()))
{
if (template.contains("sub-domain.java.vm") && StringUtils.equals(GenConstants.TPL_SUB, genTable.getTplCategory())) {
fileName = StringUtils.format("{}/domain/{}.java", javaPath, genTable.getSubTable().getClassName());
}
else if (template.contains("mapper.java.vm"))
{
} else if (template.contains("mapper.java.vm")) {
fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className);
}
else if (template.contains("service.java.vm"))
{
} else if (template.contains("service.java.vm")) {
fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className);
}
else if (template.contains("serviceImpl.java.vm"))
{
} else if (template.contains("serviceImpl.java.vm")) {
fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className);
}
else if (template.contains("controller.java.vm"))
{
} else if (template.contains("serviceImpl-dynamic.java.vm")) {
fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className);
} else if (template.contains("controller.java.vm")) {
fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className);
}
else if (template.contains("mapper.xml.vm"))
{
} else if (template.contains("controller-dynamic.java.vm")) {
fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className);
} else if (template.contains("mapper.xml.vm")) {
fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className);
}
else if (template.contains("sql.vm"))
{
} else if (template.contains("sql.vm")) {
fileName = businessName + "Menu.sql";
}
else if (template.contains("api.js.vm"))
{
} else if (template.contains("api.js.vm")) {
fileName = StringUtils.format("{}/api/{}/{}.js", vuePath, moduleName, businessName);
}
else if (template.contains("index.vue.vm"))
{
} else if (template.contains("index.vue.vm")) {
fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName);
}
else if (template.contains("index-tree.vue.vm"))
{
} else if (template.contains("index-tree.vue.vm")) {
fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName);
}
return fileName;
@@ -232,36 +218,29 @@ public class VelocityUtils
* @param packageName 包名称
* @return 包前缀名称
*/
public static String getPackagePrefix(String packageName)
{
public static String getPackagePrefix(String packageName) {
int lastIndex = packageName.lastIndexOf(".");
return StringUtils.substring(packageName, 0, lastIndex);
}
/**
* 根据列类型获取导入包
*
*
* @param genTable 业务表对象
* @return 返回需要导入的包列表
*/
public static HashSet<String> getImportList(GenTable genTable)
{
public static HashSet<String> getImportList(GenTable genTable) {
List<GenTableColumn> columns = genTable.getColumns();
GenTable subGenTable = genTable.getSubTable();
HashSet<String> importList = new HashSet<String>();
if (StringUtils.isNotNull(subGenTable))
{
if (StringUtils.isNotNull(subGenTable)) {
importList.add("java.util.List");
}
for (GenTableColumn column : columns)
{
if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType()))
{
for (GenTableColumn column : columns) {
if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) {
importList.add("java.util.Date");
importList.add("com.fasterxml.jackson.annotation.JsonFormat");
}
else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType()))
{
} else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType())) {
importList.add("java.math.BigDecimal");
}
}
@@ -270,17 +249,15 @@ public class VelocityUtils
/**
* 根据列类型获取字典组
*
*
* @param genTable 业务表对象
* @return 返回字典组
*/
public static String getDicts(GenTable genTable)
{
public static String getDicts(GenTable genTable) {
List<GenTableColumn> columns = genTable.getColumns();
Set<String> dicts = new HashSet<String>();
addDicts(dicts, columns);
if (StringUtils.isNotNull(genTable.getSubTable()))
{
if (StringUtils.isNotNull(genTable.getSubTable())) {
List<GenTableColumn> subColumns = genTable.getSubTable().getColumns();
addDicts(dicts, subColumns);
}
@@ -289,18 +266,15 @@ public class VelocityUtils
/**
* 添加字典列表
*
* @param dicts 字典列表
*
* @param dicts 字典列表
* @param columns 列集合
*/
public static void addDicts(Set<String> dicts, List<GenTableColumn> columns)
{
for (GenTableColumn column : columns)
{
public static void addDicts(Set<String> dicts, List<GenTableColumn> columns) {
for (GenTableColumn column : columns) {
if (!column.isSuperColumn() && StringUtils.isNotEmpty(column.getDictType()) && StringUtils.equalsAny(
column.getHtmlType(),
new String[] { GenConstants.HTML_SELECT, GenConstants.HTML_RADIO, GenConstants.HTML_CHECKBOX }))
{
new String[]{GenConstants.HTML_SELECT, GenConstants.HTML_RADIO, GenConstants.HTML_CHECKBOX})) {
dicts.add("'" + column.getDictType() + "'");
}
}
@@ -309,12 +283,11 @@ public class VelocityUtils
/**
* 获取权限前缀
*
* @param moduleName 模块名称
* @param moduleName 模块名称
* @param businessName 业务名称
* @return 返回权限前缀
*/
public static String getPermissionPrefix(String moduleName, String businessName)
{
public static String getPermissionPrefix(String moduleName, String businessName) {
return StringUtils.format("{}:{}", moduleName, businessName);
}
@@ -324,11 +297,9 @@ public class VelocityUtils
* @param paramsObj 生成其他选项
* @return 上级菜单ID字段
*/
public static String getParentMenuId(JSONObject paramsObj)
{
public static String getParentMenuId(JSONObject paramsObj) {
if (StringUtils.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID)
&& StringUtils.isNotEmpty(paramsObj.getString(GenConstants.PARENT_MENU_ID)))
{
&& StringUtils.isNotEmpty(paramsObj.getString(GenConstants.PARENT_MENU_ID))) {
return paramsObj.getString(GenConstants.PARENT_MENU_ID);
}
return DEFAULT_PARENT_MENU_ID;
@@ -340,10 +311,8 @@ public class VelocityUtils
* @param paramsObj 生成其他选项
* @return 树编码
*/
public static String getTreecode(JSONObject paramsObj)
{
if (paramsObj.containsKey(GenConstants.TREE_CODE))
{
public static String getTreeCode(JSONObject paramsObj) {
if (paramsObj.containsKey(GenConstants.TREE_CODE)) {
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE));
}
return StringUtils.EMPTY;
@@ -355,10 +324,8 @@ public class VelocityUtils
* @param paramsObj 生成其他选项
* @return 树父编码
*/
public static String getTreeParentCode(JSONObject paramsObj)
{
if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE))
{
public static String getTreeParentCode(JSONObject paramsObj) {
if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) {
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE));
}
return StringUtils.EMPTY;
@@ -370,10 +337,8 @@ public class VelocityUtils
* @param paramsObj 生成其他选项
* @return 树名称
*/
public static String getTreeName(JSONObject paramsObj)
{
if (paramsObj.containsKey(GenConstants.TREE_NAME))
{
public static String getTreeName(JSONObject paramsObj) {
if (paramsObj.containsKey(GenConstants.TREE_NAME)) {
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME));
}
return StringUtils.EMPTY;
@@ -385,24 +350,26 @@ public class VelocityUtils
* @param genTable 业务表对象
* @return 展开按钮列序号
*/
public static int getExpandColumn(GenTable genTable)
{
public static int getExpandColumn(GenTable genTable) {
String options = genTable.getOptions();
JSONObject paramsObj = JSON.parseObject(options);
String treeName = paramsObj.getString(GenConstants.TREE_NAME);
int num = 0;
for (GenTableColumn column : genTable.getColumns())
{
if (column.isList())
{
for (GenTableColumn column : genTable.getColumns()) {
if (column.isList()) {
num++;
String columnName = column.getColumnName();
if (columnName.equals(treeName))
{
if (columnName.equals(treeName)) {
break;
}
}
}
return num;
}
public static void addJavaFieldUpperCase(List<GenTableColumn> columns) {
for (GenTableColumn column : columns) {
column.setJavaFieldUpper(column.getCapJavaField());
}
}
}

View File

@@ -1,177 +1,304 @@
<?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">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.gen.mapper.GenTableMapper">
<resultMap type="GenTable" id="GenTableResult">
<id property="tableId" column="table_id" />
<result property="tableName" column="table_name" />
<result property="tableComment" column="table_comment" />
<result property="subTableName" column="sub_table_name" />
<result property="subTableFkName" column="sub_table_fk_name" />
<result property="className" column="class_name" />
<result property="tplCategory" column="tpl_category" />
<result property="tplWebType" column="tpl_web_type" />
<result property="packageName" column="package_name" />
<result property="moduleName" column="module_name" />
<result property="businessName" column="business_name" />
<result property="functionName" column="function_name" />
<result property="functionAuthor" column="function_author" />
<result property="genType" column="gen_type" />
<result property="genPath" column="gen_path" />
<result property="options" column="options" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<collection property="columns" javaType="java.util.List" resultMap="GenTableColumnResult" />
</resultMap>
<resultMap type="GenTableColumn" id="GenTableColumnResult">
<id property="columnId" column="column_id" />
<result property="tableId" column="table_id" />
<result property="columnName" column="column_name" />
<result property="columnComment" column="column_comment" />
<result property="columnType" column="column_type" />
<result property="javaType" column="java_type" />
<result property="javaField" column="java_field" />
<result property="isPk" column="is_pk" />
<result property="isIncrement" column="is_increment" />
<result property="isRequired" column="is_required" />
<result property="isInsert" column="is_insert" />
<result property="isEdit" column="is_edit" />
<result property="isList" column="is_list" />
<result property="isQuery" column="is_query" />
<result property="queryType" column="query_type" />
<result property="htmlType" column="html_type" />
<result property="dictType" column="dict_type" />
<result property="sort" column="sort" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<resultMap type="com.ruoyi.gen.domain.GenTable" id="GenTableResult">
<id property="tableId" column="table_id"/>
<result property="tableName" column="table_name"/>
<result property="tableComment" column="table_comment"/>
<result property="subTableName" column="sub_table_name"/>
<result property="subTableFkName" column="sub_table_fk_name"/>
<result property="className" column="class_name"/>
<result property="tplCategory" column="tpl_category"/>
<result property="tplWebType" column="tpl_web_type"/>
<result property="tplBackendType" column="tpl_backend_type"/>
<result property="packageName" column="package_name"/>
<result property="moduleName" column="module_name"/>
<result property="businessName" column="business_name"/>
<result property="functionName" column="function_name"/>
<result property="functionAuthor" column="function_author"/>
<result property="genType" column="gen_type"/>
<result property="genPath" column="gen_path"/>
<result property="options" column="options"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="remark" column="remark"/>
<collection property="columns" javaType="java.util.List" resultMap="GenTableColumnResult"/>
</resultMap>
<sql id="selectGenTableVo">
select table_id, table_name, table_comment, sub_table_name, sub_table_fk_name, class_name, tpl_category, tpl_web_type, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table
</sql>
<select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult">
<include refid="selectGenTableVo"/>
<where>
<if test="tableName != null and tableName != ''">
AND lower(table_name) like lower(concat('%', #{tableName}, '%'))
</if>
<if test="tableComment != null and tableComment != ''">
AND lower(table_comment) like lower(concat('%', #{tableComment}, '%'))
</if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if>
</where>
</select>
<select id="selectDbTableList" parameterType="GenTable" resultMap="GenTableResult">
select table_name, table_comment, create_time, update_time from information_schema.tables
where table_schema = (select database())
AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%'
AND table_name NOT IN (select table_name from gen_table)
<if test="tableName != null and tableName != ''">
AND lower(table_name) like lower(concat('%', #{tableName}, '%'))
</if>
<if test="tableComment != null and tableComment != ''">
AND lower(table_comment) like lower(concat('%', #{tableComment}, '%'))
</if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if>
<resultMap type="com.ruoyi.gen.domain.GenTableColumn" id="GenTableColumnResult">
<id property="columnId" column="column_id"/>
<result property="tableId" column="table_id"/>
<result property="columnName" column="column_name"/>
<result property="columnComment" column="column_comment"/>
<result property="columnType" column="column_type"/>
<result property="javaType" column="java_type"/>
<result property="javaField" column="java_field"/>
<result property="isPk" column="is_pk"/>
<result property="isIncrement" column="is_increment"/>
<result property="isRequired" column="is_required"/>
<result property="isInsert" column="is_insert"/>
<result property="isEdit" column="is_edit"/>
<result property="isList" column="is_list"/>
<result property="isQuery" column="is_query"/>
<result property="queryType" column="query_type"/>
<result property="htmlType" column="html_type"/>
<result property="dictType" column="dict_type"/>
<result property="sort" column="sort"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
</resultMap>
<sql id="selectGenTableVo">
select table_id,
table_name,
table_comment,
sub_table_name,
sub_table_fk_name,
class_name,
tpl_category,
tpl_web_type,
tpl_backend_type,
package_name,
module_name,
business_name,
function_name,
function_author,
gen_type,
gen_path,
options,
create_by,
create_time,
update_by,
update_time,
remark
from gen_table
</sql>
<select id="selectGenTableList" parameterType="com.ruoyi.gen.domain.GenTable" resultMap="GenTableResult">
<include refid="selectGenTableVo"/>
<where>
<if test="tableName != null and tableName != ''">
AND lower(table_name) like lower(concat('%', #{tableName}, '%'))
</if>
<if test="tableComment != null and tableComment != ''">
AND lower(table_comment) like lower(concat('%', #{tableComment}, '%'))
</if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if>
</where>
</select>
<select id="selectDbTableList" parameterType="com.ruoyi.gen.domain.GenTable" resultMap="GenTableResult">
select table_name, table_comment, create_time, update_time from information_schema.tables
where table_schema = (select database())
AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%'
AND table_name NOT IN (select table_name from gen_table)
<if test="tableName != null and tableName != ''">
AND lower(table_name) like lower(concat('%', #{tableName}, '%'))
</if>
<if test="tableComment != null and tableComment != ''">
AND lower(table_comment) like lower(concat('%', #{tableComment}, '%'))
</if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if>
order by create_time desc
</select>
<select id="selectDbTableListByNames" resultMap="GenTableResult">
select table_name, table_comment, create_time, update_time from information_schema.tables
where table_name NOT LIKE 'qrtz_%' and table_name NOT LIKE 'gen_%' and table_schema = (select database())
and table_name in
<foreach collection="array" item="name" open="(" separator="," close=")">
#{name}
</foreach>
</select>
<select id="selectTableByName" parameterType="String" resultMap="GenTableResult">
select table_name, table_comment, create_time, update_time from information_schema.tables
where table_comment <![CDATA[ <> ]]> '' and table_schema = (select database())
and table_name = #{tableName}
</select>
<select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult">
SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.tpl_web_type, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
where t.table_id = #{tableId} order by c.sort
</select>
<select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult">
SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.tpl_web_type, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
where t.table_name = #{tableName} order by c.sort
</select>
<select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult">
SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.tpl_web_type, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.options, t.remark,
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
order by c.sort
</select>
<insert id="insertGenTable" parameterType="GenTable" useGeneratedKeys="true" keyProperty="tableId">
</select>
<select id="selectDbTableListByNames" resultMap="GenTableResult">
select table_name, table_comment, create_time, update_time from information_schema.tables
where table_name NOT LIKE 'qrtz_%' and table_name NOT LIKE 'gen_%' and table_schema = (select database())
and table_name in
<foreach collection="array" item="name" open="(" separator="," close=")">
#{name}
</foreach>
</select>
<select id="selectTableByName" parameterType="String" resultMap="GenTableResult">
select table_name, table_comment, create_time, update_time
from information_schema.tables
where table_comment <![CDATA[ <> ]]> ''
and table_schema = (select database())
and table_name = #{tableName}
</select>
<select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult">
SELECT t.table_id,
t.table_name,
t.table_comment,
t.sub_table_name,
t.sub_table_fk_name,
t.class_name,
t.tpl_category,
t.tpl_web_type,
t.tpl_backend_type,
t.package_name,
t.module_name,
t.business_name,
t.function_name,
t.function_author,
t.gen_type,
t.gen_path,
t.options,
t.remark,
c.column_id,
c.column_name,
c.column_comment,
c.column_type,
c.java_type,
c.java_field,
c.is_pk,
c.is_increment,
c.is_required,
c.is_insert,
c.is_edit,
c.is_list,
c.is_query,
c.query_type,
c.html_type,
c.dict_type,
c.sort
FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
where t.table_id = #{tableId}
order by c.sort
</select>
<select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult">
SELECT t.table_id,
t.table_name,
t.table_comment,
t.sub_table_name,
t.sub_table_fk_name,
t.class_name,
t.tpl_category,
t.tpl_web_type,
t.tpl_backend_type,
t.package_name,
t.module_name,
t.business_name,
t.function_name,
t.function_author,
t.gen_type,
t.gen_path,
t.options,
t.remark,
c.column_id,
c.column_name,
c.column_comment,
c.column_type,
c.java_type,
c.java_field,
c.is_pk,
c.is_increment,
c.is_required,
c.is_insert,
c.is_edit,
c.is_list,
c.is_query,
c.query_type,
c.html_type,
c.dict_type,
c.sort
FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
where t.table_name = #{tableName}
order by c.sort
</select>
<select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult">
SELECT t.table_id,
t.table_name,
t.table_comment,
t.sub_table_name,
t.sub_table_fk_name,
t.class_name,
t.tpl_category,
t.tpl_web_type,
t.tpl_backend_type,
t.package_name,
t.module_name,
t.business_name,
t.function_name,
t.function_author,
t.options,
t.remark,
c.column_id,
c.column_name,
c.column_comment,
c.column_type,
c.java_type,
c.java_field,
c.is_pk,
c.is_increment,
c.is_required,
c.is_insert,
c.is_edit,
c.is_list,
c.is_query,
c.query_type,
c.html_type,
c.dict_type,
c.sort
FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
order by c.sort
</select>
<insert id="insertGenTable" parameterType="com.ruoyi.gen.domain.GenTable" useGeneratedKeys="true"
keyProperty="tableId">
insert into gen_table (
<if test="tableName != null">table_name,</if>
<if test="tableComment != null and tableComment != ''">table_comment,</if>
<if test="className != null and className != ''">class_name,</if>
<if test="tplCategory != null and tplCategory != ''">tpl_category,</if>
<if test="tplWebType != null and tplWebType != ''">tpl_web_type,</if>
<if test="packageName != null and packageName != ''">package_name,</if>
<if test="moduleName != null and moduleName != ''">module_name,</if>
<if test="businessName != null and businessName != ''">business_name,</if>
<if test="functionName != null and functionName != ''">function_name,</if>
<if test="functionAuthor != null and functionAuthor != ''">function_author,</if>
<if test="genType != null and genType != ''">gen_type,</if>
<if test="genPath != null and genPath != ''">gen_path,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)values(
<if test="tableName != null">#{tableName},</if>
<if test="tableComment != null and tableComment != ''">#{tableComment},</if>
<if test="className != null and className != ''">#{className},</if>
<if test="tplCategory != null and tplCategory != ''">#{tplCategory},</if>
<if test="tplWebType != null and tplWebType != ''">#{tplWebType},</if>
<if test="packageName != null and packageName != ''">#{packageName},</if>
<if test="moduleName != null and moduleName != ''">#{moduleName},</if>
<if test="businessName != null and businessName != ''">#{businessName},</if>
<if test="functionName != null and functionName != ''">#{functionName},</if>
<if test="functionAuthor != null and functionAuthor != ''">#{functionAuthor},</if>
<if test="genType != null and genType != ''">#{genType},</if>
<if test="genPath != null and genPath != ''">#{genPath},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
<if test="tableName != null">table_name,</if>
<if test="tableComment != null and tableComment != ''">table_comment,</if>
<if test="className != null and className != ''">class_name,</if>
<if test="tplCategory != null and tplCategory != ''">tpl_category,</if>
<if test="tplWebType != null and tplWebType != ''">tpl_web_type,</if>
<if test="tplBackendType != null and tplBackendType != ''">tpl_backend_type,</if>
<if test="packageName != null and packageName != ''">package_name,</if>
<if test="moduleName != null and moduleName != ''">module_name,</if>
<if test="businessName != null and businessName != ''">business_name,</if>
<if test="functionName != null and functionName != ''">function_name,</if>
<if test="functionAuthor != null and functionAuthor != ''">function_author,</if>
<if test="genType != null and genType != ''">gen_type,</if>
<if test="genPath != null and genPath != ''">gen_path,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)values(
<if test="tableName != null">#{tableName},</if>
<if test="tableComment != null and tableComment != ''">#{tableComment},</if>
<if test="className != null and className != ''">#{className},</if>
<if test="tplCategory != null and tplCategory != ''">#{tplCategory},</if>
<if test="tplWebType != null and tplWebType != ''">#{tplWebType},</if>
<if test="tplBackendType != null and tplBackendType != ''">#{tplBackendType},</if>
<if test="packageName != null and packageName != ''">#{packageName},</if>
<if test="moduleName != null and moduleName != ''">#{moduleName},</if>
<if test="businessName != null and businessName != ''">#{businessName},</if>
<if test="functionName != null and functionName != ''">#{functionName},</if>
<if test="functionAuthor != null and functionAuthor != ''">#{functionAuthor},</if>
<if test="genType != null and genType != ''">#{genType},</if>
<if test="genPath != null and genPath != ''">#{genPath},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
</insert>
<update id="updateGenTable" parameterType="GenTable">
<update id="updateGenTable" parameterType="com.ruoyi.gen.domain.GenTable">
update gen_table
<set>
<if test="tableName != null">table_name = #{tableName},</if>
@@ -184,6 +311,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="genPath != null and genPath != ''">gen_path = #{genPath},</if>
<if test="tplCategory != null and tplCategory != ''">tpl_category = #{tplCategory},</if>
<if test="tplWebType != null and tplWebType != ''">tpl_web_type = #{tplWebType},</if>
<if test="tplBackendType != null and tplBackendType != ''">tpl_backend_type = #{tplBackendType},</if>
<if test="packageName != null and packageName != ''">package_name = #{packageName},</if>
<if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if>
<if test="businessName != null and businessName != ''">business_name = #{businessName},</if>
@@ -195,9 +323,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</set>
where table_id = #{tableId}
</update>
<delete id="deleteGenTableByIds" parameterType="Long">
delete from gen_table where table_id in
delete from gen_table where table_id in
<foreach collection="array" item="tableId" open="(" separator="," close=")">
#{tableId}
</foreach>

View File

@@ -0,0 +1,116 @@
package ${packageName}.controller;
import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import ${packageName}.domain.${ClassName};
import ${packageName}.service.I${ClassName}Service;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
#if($table.crud || $table.sub)
import com.ruoyi.common.core.web.page.TableDataInfo;
#elseif($table.tree)
#end
/**
* ${functionName}Controller
*
* @author ${author}
* created on ${datetime}
*/
@RestController
@RequestMapping("/${businessName}")
public class ${ClassName}Controller extends BaseController
{
@Autowired
private I${ClassName}Service ${className}Service;
/**
* 查询${functionName}列表
*/
@RequiresPermissions("${permissionPrefix}:list")
@GetMapping("/list")
#if($table.crud || $table.sub)
public TableDataInfo list(${ClassName} ${className})
{
startPage();
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
return getDataTable(list);
}
#elseif($table.tree)
public AjaxResult list(${ClassName} ${className})
{
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
return success(list);
}
#end
//TODO 如果要启用导出功能需要在domain实体类的字段上添加注解@com.ruoyi.common.core.annotation.Excel(name = "字段名")
/*
* 导出${functionName}列表
*/
// @RequiresPermissions("${permissionPrefix}:export")
// @Log(title = "${functionName}", businessType = BusinessType.EXPORT)
// @PostMapping("/export")
// public void export(HttpServletResponse response, ${ClassName} ${className})
// {
// List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
// ExcelUtil<${ClassName}> util = new ExcelUtil<>(${ClassName}.class);
// util.exportExcel(response, list, "${functionName}数据");
// }
/**
* 获取${functionName}详细信息
*/
@RequiresPermissions("${permissionPrefix}:query")
@GetMapping(value = "/{${pkColumn.javaField}}")
public AjaxResult getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField})
{
return success(${className}Service.select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField}));
}
/**
* 新增${functionName}
*/
@RequiresPermissions("${permissionPrefix}:add")
@Log(title = "${functionName}", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody ${ClassName} ${className})
{
return toAjax(${className}Service.insert${ClassName}(${className}));
}
/**
* 修改${functionName}
*/
@RequiresPermissions("${permissionPrefix}:edit")
@Log(title = "${functionName}", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody ${ClassName} ${className})
{
return toAjax(${className}Service.update${ClassName}(${className}));
}
/**
* 删除${functionName}
*/
@RequiresPermissions("${permissionPrefix}:remove")
@Log(title = "${functionName}", businessType = BusinessType.DELETE)
@DeleteMapping("/{${pkColumn.javaField}s}")
public AjaxResult remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s)
{
return toAjax(${className}Service.delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaField}s));
}
}

View File

@@ -1,8 +1,7 @@
package ${packageName}.controller;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@@ -29,7 +28,7 @@ import com.ruoyi.common.core.web.page.TableDataInfo;
* ${functionName}Controller
*
* @author ${author}
* @date ${datetime}
* created on ${datetime}
*/
@RestController
@RequestMapping("/${businessName}")
@@ -67,7 +66,7 @@ public class ${ClassName}Controller extends BaseController
public void export(HttpServletResponse response, ${ClassName} ${className})
{
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
ExcelUtil<${ClassName}> util = new ExcelUtil<>(${ClassName}.class);
util.exportExcel(response, list, "${functionName}数据");
}
@@ -108,7 +107,7 @@ public class ${ClassName}Controller extends BaseController
*/
@RequiresPermissions("${permissionPrefix}:remove")
@Log(title = "${functionName}", businessType = BusinessType.DELETE)
@DeleteMapping("/{${pkColumn.javaField}s}")
@DeleteMapping("/{${pkColumn.javaField}s}")
public AjaxResult remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s)
{
return toAjax(${className}Service.delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaField}s));

View File

@@ -16,7 +16,7 @@ import com.ruoyi.common.core.web.domain.TreeEntity;
* ${functionName}对象 ${tableName}
*
* @author ${author}
* @date ${datetime}
* created on ${datetime}
*/
#if($table.crud || $table.sub)
#set($Entity="BaseEntity")

View File

@@ -10,7 +10,7 @@ import ${packageName}.domain.${subClassName};
* ${functionName}Mapper接口
*
* @author ${author}
* @date ${datetime}
* created on ${datetime}
*/
public interface ${ClassName}Mapper
{
@@ -20,7 +20,7 @@ public interface ${ClassName}Mapper
* @param ${pkColumn.javaField} ${functionName}主键
* @return ${functionName}
*/
public ${ClassName} select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField});
${ClassName} select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField});
/**
* 查询${functionName}列表
@@ -28,7 +28,7 @@ public interface ${ClassName}Mapper
* @param ${className} ${functionName}
* @return ${functionName}集合
*/
public List<${ClassName}> select${ClassName}List(${ClassName} ${className});
List<${ClassName}> select${ClassName}List(${ClassName} ${className});
/**
* 新增${functionName}
@@ -36,7 +36,7 @@ public interface ${ClassName}Mapper
* @param ${className} ${functionName}
* @return 结果
*/
public int insert${ClassName}(${ClassName} ${className});
int insert${ClassName}(${ClassName} ${className});
/**
* 修改${functionName}
@@ -44,7 +44,7 @@ public interface ${ClassName}Mapper
* @param ${className} ${functionName}
* @return 结果
*/
public int update${ClassName}(${ClassName} ${className});
int update${ClassName}(${ClassName} ${className});
/**
* 删除${functionName}
@@ -52,7 +52,7 @@ public interface ${ClassName}Mapper
* @param ${pkColumn.javaField} ${functionName}主键
* @return 结果
*/
public int delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField});
int delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField});
/**
* 批量删除${functionName}
@@ -60,7 +60,7 @@ public interface ${ClassName}Mapper
* @param ${pkColumn.javaField}s 需要删除的数据主键集合
* @return 结果
*/
public int delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaType}[] ${pkColumn.javaField}s);
int delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaType}[] ${pkColumn.javaField}s);
#if($table.sub)
/**
@@ -69,7 +69,7 @@ public interface ${ClassName}Mapper
* @param ${pkColumn.javaField}s 需要删除的数据主键集合
* @return 结果
*/
public int delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaType}[] ${pkColumn.javaField}s);
int delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaType}[] ${pkColumn.javaField}s);
/**
* 批量新增${subTable.functionName}
@@ -77,7 +77,7 @@ public interface ${ClassName}Mapper
* @param ${subclassName}List ${subTable.functionName}列表
* @return 结果
*/
public int batch${subClassName}(List<${subClassName}> ${subclassName}List);
int batch${subClassName}(List<${subClassName}> ${subclassName}List);
/**

View File

@@ -1,61 +1,61 @@
package ${packageName}.service;
import java.util.List;
import ${packageName}.domain.${ClassName};
import ${packageName}.domain .${ClassName};
/**
* ${functionName}Service接口
*
*
* @author ${author}
* @date ${datetime}
* created on ${datetime}
*/
public interface I${ClassName}Service
{
public interface I${ClassName}Service {
/**
* 查询${functionName}
*
*
* @param ${pkColumn.javaField} ${functionName}主键
* @return ${functionName}
*/
public ${ClassName} select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField});
${ClassName} select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField});
/**
* 查询${functionName}列表
*
*
* @param ${className} ${functionName}
* @return ${functionName}集合
*/
public List<${ClassName}> select${ClassName}List(${ClassName} ${className});
List<${ClassName}> select${ClassName}List(${ClassName} ${className});
/**
* 新增${functionName}
*
*
* @param ${className} ${functionName}
* @return 结果
*/
public int insert${ClassName}(${ClassName} ${className});
int insert${ClassName}(${ClassName} ${className});
/**
* 修改${functionName}
*
*
* @param ${className} ${functionName}
* @return 结果
*/
public int update${ClassName}(${ClassName} ${className});
int update${ClassName}(${ClassName} ${className});
/**
* 批量删除${functionName}
*
*
* @param ${pkColumn.javaField}s 需要删除的${functionName}主键集合
* @return 结果
*/
public int delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaType}[] ${pkColumn.javaField}s);
int delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaType}[] ${pkColumn.javaField}s);
/**
* 删除${functionName}信息
*
*
* @param ${pkColumn.javaField} ${functionName}主键
* @return 结果
*/
public int delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField});
int delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField});
}

View File

@@ -0,0 +1,217 @@
package ${packageName}.service.impl;
import java.util.List;
#foreach ($column in $columns)
#if($column.javaField == 'createTime' || $column.javaField == 'updateTime')
import com.ruoyi.common.core.utils.DateUtils;
#break
#end
#end
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.mybatis.dynamic.sql.where.condition.IsEqualTo;
import org.mybatis.dynamic.sql.where.condition.IsIn;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.SqlBuilder;
#if($table.sub)
import java.util.ArrayList;
import com.ruoyi.common.core.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import ${packageName}.domain.${subClassName};
#end
import ${packageName}.mapper.${ClassName}Mapper;
import ${packageName}.domain.${ClassName};
import ${packageName}.mapper.${ClassName}DynamicSqlSupport;
import ${packageName}.service.I${ClassName}Service;
import java.util.List;
import java.util.Optional;
/**
* ${functionName}Service业务层处理
*
* @author ${author}
* created on ${datetime}
*/
@Service
public class ${ClassName}ServiceImpl implements I${ClassName}Service
{
@Autowired
private ${ClassName}Mapper ${className}Mapper;
/**
* 查询${functionName}
*
* @param ${pkColumn.javaField} ${functionName}主键
* @return ${functionName}
*/
@Override
public ${ClassName} select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField})
{
Optional<${ClassName}> result = ${className}Mapper.selectOne(dsl -> dsl.where(${ClassName}DynamicSqlSupport.${pkColumn.javaField}, SqlBuilder.isEqualTo(${pkColumn.javaField})));
return result.orElse(null);
}
/**
* 查询${functionName}列表
*
* @param ${className} ${functionName}
* @return ${functionName}
*/
@Override
public List<${ClassName}> select${ClassName}List(${ClassName} ${className})
{
## return ${className}Mapper.select(SelectDSLCompleter.allRows()); //查询全部字段
#set ($whereFuncName = "where")
#set ($conditionFuncName = "isEqualToWhenPresent")
return unitInfoMapper.select(dsl -> dsl
#foreach ($column in $columns)
## where语句是where还是and开头
#if (!$foreach.first)
#set ($whereFuncName = "and")
#end
## 查询条件
#if ($columne.queryType == "EQ")
#set ($conditionFuncName = "isEqualToWhenPresent")
#elseif ($columne.queryType == "NE")
#set ($conditionFuncName = "isNotEqualToWhenPresent")
#elseif ($columne.queryType == "GT")
#set ($conditionFuncName = "isGreaterThanWhenPresent")
#elseif ($columne.queryType == "GTE")
#set ($conditionFuncName = "isGreaterThanOrEqualToWhenPresent")
#elseif ($columne.queryType == "LT")
#set ($conditionFuncName = "isLessThanWhenPresent")
#elseif ($columne.queryType == "LTE")
#set ($conditionFuncName = "isLessThanOrEqualToWhenPresent")
#elseif ($columne.queryType == "LIKE")
#set ($conditionFuncName = "isLikeWhenPresent")
#elseif ($columne.queryType == "BETWEEN")
#set ($conditionFuncName = "isBetweenWhenPresent")
## #elseif ($columne.queryType == "IN")
## #set ($conditionFuncName = "isIn")
## #elseif ($columne.queryType == "NI")
## #set ($conditionFuncName = "isNotIn")
#end
## 对like条件的特殊处理
#if ($columne.queryType == "LIKE")
.${whereFuncName}(${ClassName}DynamicSqlSupport.$column.javaField, SqlBuilder.${conditionFuncName}(${className}.get${column.javaFieldUpper}() == null ? null : "%" + ${className}.get${column.javaFieldUpper}() + "%")
#else
.${whereFuncName}(${ClassName}DynamicSqlSupport.$column.javaField, SqlBuilder.${conditionFuncName}(${className}.get${column.javaFieldUpper}()))
#end
#end
);
}
/**
* 新增${functionName}
*
* @param ${className} ${functionName}
* @return 结果
*/
#if($table.sub)
@Transactional
#end
@Override
public int insert${ClassName}(${ClassName} ${className})
{
#foreach ($column in $columns)
#if($column.javaField == 'createTime')
${className}.setCreateTime(DateUtils.getNowDate());
#end
#end
#if($table.sub)
int rows = ${className}Mapper.insertSelective(${className});
insert${subClassName}(${className});
return rows;
#else
return ${className}Mapper.insertSelective(${className});
#end
}
/**
* 修改${functionName}
*
* @param ${className} ${functionName}
* @return 结果
*/
#if($table.sub)
@Transactional
#end
@Override
public int update${ClassName}(${ClassName} ${className})
{
#foreach ($column in $columns)
#if($column.javaField == 'updateTime')
${className}.setUpdateTime(DateUtils.getNowDate());
#end
#end
#if($table.sub)
${className}Mapper.delete${subClassName}By${subTableFkClassName}(${className}.get${pkColumn.capJavaField}());
insert${subClassName}(${className});
#end
return ${className}Mapper.updateByPrimaryKeySelective(${className});
}
/**
* 批量删除${functionName}
*
* @param ${pkColumn.javaField}s 需要删除的${functionName}主键
* @return 结果
*/
#if($table.sub)
@Transactional
#end
@Override
public int delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaType}[] ${pkColumn.javaField}s)
{
#if($table.sub)
${className}Mapper.delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaField}s);
#end
return ${className}Mapper.delete(dsl -> dsl.where(${ClassName}DynamicSqlSupport.${pkColumn.javaField}, SqlBuilder.isIn(${pkColumn.javaField}s)));
}
/**
* 删除${functionName}信息
*
* @param ${pkColumn.javaField} ${functionName}主键
* @return 结果
*/
#if($table.sub)
@Transactional
#end
@Override
public int delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField})
{
#if($table.sub)
${className}Mapper.delete${subClassName}By${subTableFkClassName}(${pkColumn.javaField});
#end
return ${className}Mapper.delete(dsl -> dsl.where(${ClassName}DynamicSqlSupport.${pkColumn.javaField}, SqlBuilder.isEqualTo(${pkColumn.javaField})));
}
#if($table.sub)
/**
* 新增${subTable.functionName}信息
*
* @param ${className} ${functionName}对象
*/
public void insert${subClassName}(${ClassName} ${className})
{
List<${subClassName}> ${subclassName}List = ${className}.get${subClassName}List();
${pkColumn.javaType} ${pkColumn.javaField} = ${className}.get${pkColumn.capJavaField}();
if (StringUtils.isNotNull(${subclassName}List))
{
List<${subClassName}> list = new ArrayList<${subClassName}>();
for (${subClassName} ${subclassName} : ${subclassName}List)
{
${subclassName}.set${subTableFkClassName}(${pkColumn.javaField});
list.add(${subclassName});
}
if (!list.isEmpty())
{
${className}Mapper.batch${subClassName}(list);
}
}
}
#end
}

View File

@@ -23,7 +23,7 @@ import ${packageName}.service.I${ClassName}Service;
* ${functionName}Service业务层处理
*
* @author ${author}
* @date ${datetime}
* created on ${datetime}
*/
@Service
public class ${ClassName}ServiceImpl implements I${ClassName}Service
@@ -159,7 +159,7 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service
${subclassName}.set${subTableFkClassName}(${pkColumn.javaField});
list.add(${subclassName});
}
if (list.size() > 0)
if (!list.isEmpty())
{
${className}Mapper.batch${subClassName}(list);
}

View File

@@ -12,7 +12,7 @@ import com.ruoyi.common.core.web.domain.BaseEntity;
* ${subTable.functionName}对象 ${subTableName}
*
* @author ${author}
* @date ${datetime}
* created on ${datetime}
*/
public class ${subClassName} extends BaseEntity
{

View File

@@ -1,96 +1,105 @@
<?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">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.SysConfigMapper">
<resultMap type="SysConfig" id="SysConfigResult">
<id property="configId" column="config_id" />
<result property="configName" column="config_name" />
<result property="configKey" column="config_key" />
<result property="configValue" column="config_value" />
<result property="configType" column="config_type" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<resultMap type="com.ruoyi.system.domain.SysConfig" id="SysConfigResult">
<id property="configId" column="config_id"/>
<result property="configName" column="config_name"/>
<result property="configKey" column="config_key"/>
<result property="configValue" column="config_value"/>
<result property="configType" column="config_type"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
</resultMap>
<sql id="selectConfigVo">
select config_id, config_name, config_key, config_value, config_type, create_by, create_time, update_by, update_time, remark
from sys_config
select config_id,
config_name,
config_key,
config_value,
config_type,
create_by,
create_time,
update_by,
update_time,
remark
from sys_config
</sql>
<!-- 查询条件 -->
<sql id="sqlwhereSearch">
<where>
<if test="configId !=null">
and config_id = #{configId}
</if>
<if test="configKey !=null and configKey != ''">
and config_key = #{configKey}
</if>
</where>
</sql>
<select id="selectConfig" parameterType="SysConfig" resultMap="SysConfigResult">
<sql id="sqlWhereSearch">
<where>
<if test="configId !=null">
and config_id = #{configId}
</if>
<if test="configKey !=null and configKey != ''">
and config_key = #{configKey}
</if>
</where>
</sql>
<select id="selectConfig" parameterType="com.ruoyi.system.domain.SysConfig" resultMap="SysConfigResult">
<include refid="selectConfigVo"/>
<include refid="sqlwhereSearch"/>
<include refid="sqlWhereSearch"/>
</select>
<select id="selectConfigList" parameterType="SysConfig" resultMap="SysConfigResult">
<select id="selectConfigList" parameterType="com.ruoyi.system.domain.SysConfig" resultMap="SysConfigResult">
<include refid="selectConfigVo"/>
<where>
<if test="configName != null and configName != ''">
AND config_name like concat('%', #{configName}, '%')
</if>
<if test="configType != null and configType != ''">
AND config_type = #{configType}
</if>
<if test="configKey != null and configKey != ''">
AND config_key like concat('%', #{configKey}, '%')
</if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
and date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
and date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if>
</where>
<if test="configName != null and configName != ''">
AND config_name like concat('%', #{configName}, '%')
</if>
<if test="configType != null and configType != ''">
AND config_type = #{configType}
</if>
<if test="configKey != null and configKey != ''">
AND config_key like concat('%', #{configKey}, '%')
</if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
and date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
and date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if>
</where>
</select>
<select id="selectConfigById" parameterType="Long" resultMap="SysConfigResult">
<include refid="selectConfigVo"/>
where config_id = #{configId}
</select>
<select id="checkConfigKeyUnique" parameterType="String" resultMap="SysConfigResult">
<include refid="selectConfigVo"/>
where config_key = #{configKey} limit 1
</select>
<insert id="insertConfig" parameterType="SysConfig">
<insert id="insertConfig" parameterType="com.ruoyi.system.domain.SysConfig">
insert into sys_config (
<if test="configName != null and configName != '' ">config_name,</if>
<if test="configKey != null and configKey != '' ">config_key,</if>
<if test="configValue != null and configValue != '' ">config_value,</if>
<if test="configType != null and configType != '' ">config_type,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="remark != null and remark != ''">remark,</if>
create_time
<if test="configName != null and configName != '' ">config_name,</if>
<if test="configKey != null and configKey != '' ">config_key,</if>
<if test="configValue != null and configValue != '' ">config_value,</if>
<if test="configType != null and configType != '' ">config_type,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="remark != null and remark != ''">remark,</if>
create_time
)values(
<if test="configName != null and configName != ''">#{configName},</if>
<if test="configKey != null and configKey != ''">#{configKey},</if>
<if test="configValue != null and configValue != ''">#{configValue},</if>
<if test="configType != null and configType != ''">#{configType},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="remark != null and remark != ''">#{remark},</if>
sysdate()
)
<if test="configName != null and configName != ''">#{configName},</if>
<if test="configKey != null and configKey != ''">#{configKey},</if>
<if test="configValue != null and configValue != ''">#{configValue},</if>
<if test="configType != null and configType != ''">#{configType},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="remark != null and remark != ''">#{remark},</if>
sysdate()
)
</insert>
<update id="updateConfig" parameterType="SysConfig">
update sys_config
<update id="updateConfig" parameterType="com.ruoyi.system.domain.SysConfig">
update sys_config
<set>
<if test="configName != null and configName != ''">config_name = #{configName},</if>
<if test="configKey != null and configKey != ''">config_key = #{configKey},</if>
@@ -98,20 +107,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="configType != null and configType != ''">config_type = #{configType},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="remark != null">remark = #{remark},</if>
update_time = sysdate()
update_time = sysdate()
</set>
where config_id = #{configId}
</update>
<delete id="deleteConfigById" parameterType="Long">
delete from sys_config where config_id = #{configId}
delete
from sys_config
where config_id = #{configId}
</delete>
<delete id="deleteConfigByIds" parameterType="Long">
delete from sys_config where config_id in
delete from sys_config where config_id in
<foreach item="configId" collection="array" open="(" separator="," close=")">
#{configId}
#{configId}
</foreach>
</delete>
</mapper>

View File

@@ -0,0 +1,97 @@
package com.ruoyi.wms.controller;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.wms.domain.UnitInfo;
import com.ruoyi.wms.service.IUnitInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 单位信息管理Controller
*
* @author ruoyi
* created on 2024-02-02
*/
@RestController
@RequestMapping("/UnitInfo")
public class UnitInfoController extends BaseController
{
@Autowired
private IUnitInfoService unitInfoService;
/**
* 查询单位信息管理列表
*/
@RequiresPermissions("wms:UnitInfo:list")
@GetMapping("/list")
public TableDataInfo list(UnitInfo unitInfo)
{
startPage();
List<UnitInfo> list = unitInfoService.selectUnitInfoList(unitInfo);
return getDataTable(list);
}
//TODO 如果要启用导出功能需要在domain实体类的字段上添加注解@com.ruoyi.common.core.annotation.Excel(name = "字段名")
/*
* 导出单位信息管理列表
*/
// @RequiresPermissions("wms:UnitInfo:export")
// @Log(title = "单位信息管理", businessType = BusinessType.EXPORT)
// @PostMapping("/export")
// public void export(HttpServletResponse response, UnitInfo unitInfo)
// {
// List<UnitInfo> list = unitInfoService.selectUnitInfoList(unitInfo);
// ExcelUtil<UnitInfo> util = new ExcelUtil<>(UnitInfo.class);
// util.exportExcel(response, list, "单位信息管理数据");
// }
/**
* 获取单位信息管理详细信息
*/
@RequiresPermissions("wms:UnitInfo:query")
@GetMapping(value = "/{orgCd}")
public AjaxResult getInfo(@PathVariable("orgCd") String orgCd)
{
return success(unitInfoService.selectUnitInfoByOrgCd(orgCd));
}
/**
* 新增单位信息管理
*/
@RequiresPermissions("wms:UnitInfo:add")
@Log(title = "单位信息管理", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody UnitInfo unitInfo)
{
return toAjax(unitInfoService.insertUnitInfo(unitInfo));
}
/**
* 修改单位信息管理
*/
@RequiresPermissions("wms:UnitInfo:edit")
@Log(title = "单位信息管理", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody UnitInfo unitInfo)
{
return toAjax(unitInfoService.updateUnitInfo(unitInfo));
}
/**
* 删除单位信息管理
*/
@RequiresPermissions("wms:UnitInfo:remove")
@Log(title = "单位信息管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{orgCds}")
public AjaxResult remove(@PathVariable String[] orgCds)
{
return toAjax(unitInfoService.deleteUnitInfoByOrgCds(orgCds));
}
}

View File

@@ -1,18 +1,8 @@
package com.ruoyi.wms.mapper;
import static com.ruoyi.wms.mapper.UnitInfoDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;
import com.ruoyi.wms.domain.UnitInfo;
import jakarta.annotation.Generated;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
@@ -23,11 +13,14 @@ import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.CommonCountMapper;
import org.mybatis.dynamic.sql.util.mybatis3.CommonDeleteMapper;
import org.mybatis.dynamic.sql.util.mybatis3.CommonInsertMapper;
import org.mybatis.dynamic.sql.util.mybatis3.CommonUpdateMapper;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;
import org.mybatis.dynamic.sql.util.mybatis3.*;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import static com.ruoyi.wms.mapper.UnitInfoDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;
@Mapper
public interface UnitInfoMapper extends CommonCountMapper, CommonDeleteMapper, CommonInsertMapper<UnitInfo>, CommonUpdateMapper {

View File

@@ -0,0 +1,61 @@
package com.ruoyi.wms.service;
import com.ruoyi.wms.domain.UnitInfo;
import java.util.List;
/**
* 单位信息管理Service接口
*
* @author ruoyi
* created on 2024-02-02
*/
public interface IUnitInfoService {
/**
* 查询单位信息管理
*
* @param orgCd 单位信息管理主键
* @return 单位信息管理
*/
UnitInfo selectUnitInfoByOrgCd(String orgCd);
/**
* 查询单位信息管理列表
*
* @param unitInfo 单位信息管理
* @return 单位信息管理集合
*/
List<UnitInfo> selectUnitInfoList(UnitInfo unitInfo);
/**
* 新增单位信息管理
*
* @param unitInfo 单位信息管理
* @return 结果
*/
int insertUnitInfo(UnitInfo unitInfo);
/**
* 修改单位信息管理
*
* @param unitInfo 单位信息管理
* @return 结果
*/
int updateUnitInfo(UnitInfo unitInfo);
/**
* 批量删除单位信息管理
*
* @param orgCds 需要删除的单位信息管理主键集合
* @return 结果
*/
int deleteUnitInfoByOrgCds(String[] orgCds);
/**
* 删除单位信息管理信息
*
* @param orgCd 单位信息管理主键
* @return 结果
*/
int deleteUnitInfoByOrgCd(String orgCd);
}

View File

@@ -0,0 +1,113 @@
package com.ruoyi.wms.service.impl;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.wms.domain.UnitInfo;
import com.ruoyi.wms.mapper.UnitInfoDynamicSqlSupport;
import com.ruoyi.wms.mapper.UnitInfoMapper;
import com.ruoyi.wms.service.IUnitInfoService;
import org.mybatis.dynamic.sql.SqlBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
/**
* 单位信息管理Service业务层处理
*
* @author ruoyi
* created on 2024-02-02
*/
@Service
public class UnitInfoServiceImpl implements IUnitInfoService {
@Autowired
private UnitInfoMapper unitInfoMapper;
/**
* 查询单位信息管理
*
* @param orgCd 单位信息管理主键
* @return 单位信息管理
*/
@Override
public UnitInfo selectUnitInfoByOrgCd(String orgCd) {
Optional<UnitInfo> result = unitInfoMapper.selectOne(dsl -> dsl.where(UnitInfoDynamicSqlSupport.orgCd, SqlBuilder.isEqualTo(orgCd)));
return result.orElse(null);
}
/**
* 查询单位信息管理列表
*
* @param unitInfo 单位信息管理
* @return 单位信息管理
*/
@Override
public List<UnitInfo> selectUnitInfoList(UnitInfo unitInfo) {
return unitInfoMapper.select(dsl -> dsl
.where(UnitInfoDynamicSqlSupport.orgCd, SqlBuilder.isEqualToWhenPresent(unitInfo.getOrgCd()))
.and(UnitInfoDynamicSqlSupport.unit, SqlBuilder.isEqualToWhenPresent(unitInfo.getUnit()))
.and(UnitInfoDynamicSqlSupport.unitName, SqlBuilder.isEqualToWhenPresent(unitInfo.getUnitName()))
.and(UnitInfoDynamicSqlSupport.unitConvRate, SqlBuilder.isEqualToWhenPresent(unitInfo.getUnitConvRate()))
.and(UnitInfoDynamicSqlSupport.srcConvUnit, SqlBuilder.isEqualToWhenPresent(unitInfo.getSrcConvUnit()))
.and(UnitInfoDynamicSqlSupport.remark1, SqlBuilder.isEqualToWhenPresent(unitInfo.getRemark1()))
.and(UnitInfoDynamicSqlSupport.remark2, SqlBuilder.isEqualToWhenPresent(unitInfo.getRemark2()))
.and(UnitInfoDynamicSqlSupport.remark3, SqlBuilder.isEqualToWhenPresent(unitInfo.getRemark3()))
.and(UnitInfoDynamicSqlSupport.remark4, SqlBuilder.isEqualToWhenPresent(unitInfo.getRemark4()))
.and(UnitInfoDynamicSqlSupport.remark5, SqlBuilder.isEqualToWhenPresent(unitInfo.getRemark5()))
.and(UnitInfoDynamicSqlSupport.updateCount, SqlBuilder.isEqualToWhenPresent(unitInfo.getUpdateCount()))
.and(UnitInfoDynamicSqlSupport.deleteFlag, SqlBuilder.isEqualToWhenPresent(unitInfo.getDeleteFlag()))
.and(UnitInfoDynamicSqlSupport.createBy, SqlBuilder.isEqualToWhenPresent(unitInfo.getCreateBy()))
.and(UnitInfoDynamicSqlSupport.createTime, SqlBuilder.isEqualToWhenPresent(unitInfo.getCreateTime()))
.and(UnitInfoDynamicSqlSupport.updateBy, SqlBuilder.isEqualToWhenPresent(unitInfo.getUpdateBy()))
.and(UnitInfoDynamicSqlSupport.updateTime, SqlBuilder.isEqualToWhenPresent(unitInfo.getUpdateTime()))
.and(UnitInfoDynamicSqlSupport.remark, SqlBuilder.isEqualToWhenPresent(unitInfo.getRemark()))
);
}
/**
* 新增单位信息管理
*
* @param unitInfo 单位信息管理
* @return 结果
*/
@Override
public int insertUnitInfo(UnitInfo unitInfo) {
unitInfo.setCreateTime(DateUtils.getNowDate());
return unitInfoMapper.insertSelective(unitInfo);
}
/**
* 修改单位信息管理
*
* @param unitInfo 单位信息管理
* @return 结果
*/
@Override
public int updateUnitInfo(UnitInfo unitInfo) {
unitInfo.setUpdateTime(DateUtils.getNowDate());
return unitInfoMapper.updateByPrimaryKeySelective(unitInfo);
}
/**
* 批量删除单位信息管理
*
* @param orgCds 需要删除的单位信息管理主键
* @return 结果
*/
@Override
public int deleteUnitInfoByOrgCds(String[] orgCds) {
return unitInfoMapper.delete(dsl -> dsl.where(UnitInfoDynamicSqlSupport.orgCd, SqlBuilder.isIn(orgCds)));
}
/**
* 删除单位信息管理信息
*
* @param orgCd 单位信息管理主键
* @return 结果
*/
@Override
public int deleteUnitInfoByOrgCd(String orgCd) {
return unitInfoMapper.delete(dsl -> dsl.where(UnitInfoDynamicSqlSupport.orgCd, SqlBuilder.isEqualTo(orgCd)));
}
}