生成代码
This commit is contained in:
parent
94fd5425f6
commit
917fb785f9
|
|
@ -14,6 +14,7 @@ import com.hxkj.common.entity.system.SystemPost;
|
||||||
import com.hxkj.common.mapper.system.SystemAdminMapper;
|
import com.hxkj.common.mapper.system.SystemAdminMapper;
|
||||||
import com.hxkj.common.mapper.system.SystemPostMapper;
|
import com.hxkj.common.mapper.system.SystemPostMapper;
|
||||||
import com.hxkj.common.utils.TimeUtil;
|
import com.hxkj.common.utils.TimeUtil;
|
||||||
|
import com.hxkj.common.utils.UrlUtil;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,100 +0,0 @@
|
||||||
package com.hxkj.common.constant;
|
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class GenConstants {
|
|
||||||
|
|
||||||
/** 单表(增删改查) */
|
|
||||||
public static final String TPL_CRUD = "crud";
|
|
||||||
|
|
||||||
/** 树表(增删改查) */
|
|
||||||
public static final String TPL_TREE = "tree";
|
|
||||||
|
|
||||||
/** 主子表(增删改查) */
|
|
||||||
public static final String TPL_SUB = "sub";
|
|
||||||
|
|
||||||
/** 树编码字段 */
|
|
||||||
public static final String TREE_CODE = "treeCode";
|
|
||||||
|
|
||||||
/** 树父编码字段 */
|
|
||||||
public static final String TREE_PARENT_CODE = "treeParentCode";
|
|
||||||
|
|
||||||
/** 树名称字段 */
|
|
||||||
public static final String TREE_NAME = "treeName";
|
|
||||||
|
|
||||||
/** 数据库字符串类型 */
|
|
||||||
public static final String[] COLUMN_TYPE_STR = {"char", "varchar", "nvarchar", "varchar2"};
|
|
||||||
|
|
||||||
/** 数据库文本类型 */
|
|
||||||
public static final String[] COLUMN_TYPE_TEXT = {"tinytext", "text", "mediumtext", "longtext"};
|
|
||||||
|
|
||||||
/** 数据库时间类型 */
|
|
||||||
public static final String[] COLUMN_TYPE_TIME = {"datetime", "time", "date", "timestamp"};
|
|
||||||
|
|
||||||
/** 数据库数字类型 */
|
|
||||||
public static final String[] COLUMN_TYPE_NUMBER = {
|
|
||||||
"tinyint", "smallint", "mediumint", "int", "number",
|
|
||||||
"integer", "bit", "bigint", "float", "double", "decimal"};
|
|
||||||
|
|
||||||
/** 页面不需要编辑字段 */
|
|
||||||
public static final String[] COLUMN_NAME_NOT_EDIT = {"id", "create_time", "update_time", "delete_time"};
|
|
||||||
|
|
||||||
/** 页面不需要列表字段 */
|
|
||||||
public static final String[] COLUMN_NAME_NOT_LIST = {"id", "create_time", "update_time", "delete_time"};
|
|
||||||
|
|
||||||
/** 页面不需要查询字段 */
|
|
||||||
public static final String[] COLUMN_NAME_NOT_QUERY = {"id", "create_time", "update_time", "delete_time"};
|
|
||||||
|
|
||||||
/** 文本框 */
|
|
||||||
public static final String HTML_INPUT = "input";
|
|
||||||
|
|
||||||
/** 文本域 */
|
|
||||||
public static final String HTML_TEXTAREA = "textarea";
|
|
||||||
|
|
||||||
/** 下拉框 */
|
|
||||||
public static final String HTML_SELECT = "select";
|
|
||||||
|
|
||||||
/** 单选框 */
|
|
||||||
public static final String HTML_RADIO = "radio";
|
|
||||||
|
|
||||||
/** 复选框 */
|
|
||||||
public static final String HTML_CHECKBOX = "checkbox";
|
|
||||||
|
|
||||||
/** 日期控件 */
|
|
||||||
public static final String HTML_DATETIME = "datetime";
|
|
||||||
|
|
||||||
/** 图片上传控件 */
|
|
||||||
public static final String HTML_IMAGE_UPLOAD = "imageUpload";
|
|
||||||
|
|
||||||
/** 文件上传控件 */
|
|
||||||
public static final String HTML_FILE_UPLOAD = "fileUpload";
|
|
||||||
|
|
||||||
/** 富文本控件 */
|
|
||||||
public static final String HTML_EDITOR = "editor";
|
|
||||||
|
|
||||||
/** 字符串类型 */
|
|
||||||
public static final String TYPE_STRING = "String";
|
|
||||||
|
|
||||||
/** 整型 */
|
|
||||||
public static final String TYPE_INTEGER = "Integer";
|
|
||||||
|
|
||||||
/** 长整型 */
|
|
||||||
public static final String TYPE_LONG = "Long";
|
|
||||||
|
|
||||||
/** 高精度计算类型 */
|
|
||||||
public static final String TYPE_BIG_DECIMAL = "BigDecimal";
|
|
||||||
|
|
||||||
/** 时间类型 */
|
|
||||||
public static final String TYPE_DATE = "Date";
|
|
||||||
|
|
||||||
/** 模糊查询 */
|
|
||||||
public static final String QUERY_LIKE = "LIKE";
|
|
||||||
|
|
||||||
/** 相等查询 */
|
|
||||||
public static final String QUERY_EQ = "=";
|
|
||||||
|
|
||||||
/** 需要 */
|
|
||||||
public static final Integer REQUIRE = 1;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -6,7 +6,13 @@ public class GenConfig {
|
||||||
public static String authorName = "LikeAdmin";
|
public static String authorName = "LikeAdmin";
|
||||||
|
|
||||||
// 生成包名
|
// 生成包名
|
||||||
public static String packageName = "com.hxkj.like-admin";
|
public static String packageName = "com.hxkj.admin";
|
||||||
|
|
||||||
|
// 主要应用
|
||||||
|
public static String mainApp = "like-{}/src/main/java/";
|
||||||
|
|
||||||
|
// 公共应用
|
||||||
|
public static String commonApp = "like-common/src/main/java/";
|
||||||
|
|
||||||
// 表前缀名
|
// 表前缀名
|
||||||
public static String tablePrefix = "ls_";
|
public static String tablePrefix = "ls_";
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.hxkj.generator.constant;
|
||||||
|
|
||||||
|
public class GenConstants {
|
||||||
|
|
||||||
|
/** UTF-8 字符集 */
|
||||||
|
public static final String UTF8 = "UTF-8";
|
||||||
|
|
||||||
|
/** 单表 (增删改查) */
|
||||||
|
public static final String TPL_CRUD = "crud";
|
||||||
|
|
||||||
|
/** 树表 (增删改查) */
|
||||||
|
public static final String TPL_TREE = "tree";
|
||||||
|
|
||||||
|
/** 模糊查询 */
|
||||||
|
public static final String QUERY_LIKE = "LIKE";
|
||||||
|
|
||||||
|
/** 相等查询 */
|
||||||
|
public static final String QUERY_EQ = "=";
|
||||||
|
|
||||||
|
/** 需要的 */
|
||||||
|
public static final Integer REQUIRE = 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.hxkj.generator.constant;
|
||||||
|
|
||||||
|
public class HtmlConstants {
|
||||||
|
|
||||||
|
/** 文本框 */
|
||||||
|
public static final String HTML_INPUT = "input";
|
||||||
|
|
||||||
|
/** 文本域 */
|
||||||
|
public static final String HTML_TEXTAREA = "textarea";
|
||||||
|
|
||||||
|
/** 下拉框 */
|
||||||
|
public static final String HTML_SELECT = "select";
|
||||||
|
|
||||||
|
/** 单选框 */
|
||||||
|
public static final String HTML_RADIO = "radio";
|
||||||
|
|
||||||
|
/** 日期控件 */
|
||||||
|
public static final String HTML_DATETIME = "datetime";
|
||||||
|
|
||||||
|
/** 图片上传控件 */
|
||||||
|
public static final String HTML_IMAGE_UPLOAD = "imageUpload";
|
||||||
|
|
||||||
|
/** 文件上传控件 */
|
||||||
|
public static final String HTML_FILE_UPLOAD = "fileUpload";
|
||||||
|
|
||||||
|
/** 富文本控件 */
|
||||||
|
public static final String HTML_EDITOR = "editor";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.hxkj.generator.constant;
|
||||||
|
|
||||||
|
public class JavaConstants {
|
||||||
|
|
||||||
|
/** 字符串类型 */
|
||||||
|
public static final String TYPE_STRING = "String";
|
||||||
|
|
||||||
|
/** 整型 */
|
||||||
|
public static final String TYPE_INTEGER = "Integer";
|
||||||
|
|
||||||
|
/** 长整型 */
|
||||||
|
public static final String TYPE_LONG = "Long";
|
||||||
|
|
||||||
|
/** 高精度计算类型 */
|
||||||
|
public static final String TYPE_BIG_DECIMAL = "BigDecimal";
|
||||||
|
|
||||||
|
/** 时间类型 */
|
||||||
|
public static final String TYPE_DATE = "Date";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.hxkj.generator.constant;
|
||||||
|
|
||||||
|
public class SqlConstants {
|
||||||
|
|
||||||
|
/** 数据库字符串类型 */
|
||||||
|
public static final String[] COLUMN_TYPE_STR = {"char", "varchar", "nvarchar", "varchar2"};
|
||||||
|
|
||||||
|
/** 数据库文本类型 */
|
||||||
|
public static final String[] COLUMN_TYPE_TEXT = {"tinytext", "text", "mediumtext", "longtext"};
|
||||||
|
|
||||||
|
/** 数据库时间类型 */
|
||||||
|
public static final String[] COLUMN_TYPE_TIME = {"datetime", "time", "date", "timestamp"};
|
||||||
|
|
||||||
|
/** 数据库数字类型 */
|
||||||
|
public static final String[] COLUMN_TYPE_NUMBER = {"tinyint", "smallint", "mediumint", "int", "number", "integer", "bit", "bigint", "float", "double", "decimal"};
|
||||||
|
|
||||||
|
/** 时间日期字段名 */
|
||||||
|
public static final String[] COLUMN_TIME_NAME = {"create_time", "update_time", "delete_time", "start_time", "end_time"};
|
||||||
|
|
||||||
|
/** 页面不需要编辑字段 */
|
||||||
|
public static final String[] COLUMN_NAME_NOT_EDIT = {"id", "create_time", "update_time", "delete_time"};
|
||||||
|
|
||||||
|
/** 页面不需要列表字段 */
|
||||||
|
public static final String[] COLUMN_NAME_NOT_LIST = {"id", "intro", "content", "is_delete", "delete_time"};
|
||||||
|
|
||||||
|
/** 页面不需要查询字段 */
|
||||||
|
public static final String[] COLUMN_NAME_NOT_QUERY = {"id", "image", "intro", "content", "sort", "is_delete", "create_time", "update_time", "delete_time"};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -137,11 +137,23 @@ public class GenController {
|
||||||
/**
|
/**
|
||||||
* 生成代码
|
* 生成代码
|
||||||
*
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param tableName 表名
|
||||||
|
*/
|
||||||
|
@GetMapping("/genCode")
|
||||||
|
public void genCode(String tableName) {
|
||||||
|
Assert.notNull(tableName, "请选择要生成的表");
|
||||||
|
iGenerateService.genCode(tableName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载代码
|
||||||
|
*
|
||||||
* @param response 响应对象
|
* @param response 响应对象
|
||||||
* @param tables 表名
|
* @param tables 表名
|
||||||
* @throws IOException 异常
|
* @throws IOException 异常
|
||||||
*/
|
*/
|
||||||
@GetMapping("/genCode")
|
@GetMapping("/downloadCode")
|
||||||
public void genCode(HttpServletResponse response, String tables) throws IOException {
|
public void genCode(HttpServletResponse response, String tables) throws IOException {
|
||||||
Assert.notNull(tables, "请选择要生成的表");
|
Assert.notNull(tables, "请选择要生成的表");
|
||||||
String[] tableNames = tables.split(",");
|
String[] tableNames = tables.split(",");
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@ public class GenTable implements Serializable {
|
||||||
private String moduleName;
|
private String moduleName;
|
||||||
private String businessName;
|
private String businessName;
|
||||||
private String functionName;
|
private String functionName;
|
||||||
|
private String treePrimary;
|
||||||
|
private String treeParent;
|
||||||
private String genTpl;
|
private String genTpl;
|
||||||
private Integer genType;
|
private Integer genType;
|
||||||
private String genPath;
|
private String genPath;
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,14 @@ public interface IGenerateService {
|
||||||
*/
|
*/
|
||||||
Map<String, String> previewCode(Integer id);
|
Map<String, String> previewCode(Integer id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成代码
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param tableName 表名
|
||||||
|
*/
|
||||||
|
void genCode(String tableName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下载代码
|
* 下载代码
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import com.hxkj.common.core.PageResult;
|
||||||
import com.hxkj.common.exception.OperateException;
|
import com.hxkj.common.exception.OperateException;
|
||||||
import com.hxkj.common.utils.StringUtil;
|
import com.hxkj.common.utils.StringUtil;
|
||||||
import com.hxkj.common.utils.TimeUtil;
|
import com.hxkj.common.utils.TimeUtil;
|
||||||
|
import com.hxkj.generator.constant.GenConstants;
|
||||||
import com.hxkj.generator.entity.GenTable;
|
import com.hxkj.generator.entity.GenTable;
|
||||||
import com.hxkj.generator.entity.GenTableColumn;
|
import com.hxkj.generator.entity.GenTableColumn;
|
||||||
import com.hxkj.generator.mapper.GenTableColumnMapper;
|
import com.hxkj.generator.mapper.GenTableColumnMapper;
|
||||||
|
|
@ -22,6 +23,7 @@ import com.hxkj.generator.validate.PageParam;
|
||||||
import com.hxkj.generator.vo.DbTableVo;
|
import com.hxkj.generator.vo.DbTableVo;
|
||||||
import com.hxkj.generator.vo.GenColumnVo;
|
import com.hxkj.generator.vo.GenColumnVo;
|
||||||
import com.hxkj.generator.vo.GenTableVo;
|
import com.hxkj.generator.vo.GenTableVo;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.velocity.Template;
|
import org.apache.velocity.Template;
|
||||||
import org.apache.velocity.VelocityContext;
|
import org.apache.velocity.VelocityContext;
|
||||||
|
|
@ -34,6 +36,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
@ -211,6 +214,11 @@ public class GenerateServiceImpl implements IGenerateService {
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void editTable(GenParam genParam) {
|
public void editTable(GenParam genParam) {
|
||||||
|
if (genParam.getGenTpl().equals(GenConstants.TPL_TREE)) {
|
||||||
|
Assert.isFalse(genParam.getTreePrimary().equals(""), "树主ID不能为空");
|
||||||
|
Assert.isFalse(genParam.getTreeParent().equals(""), "树父ID不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
GenTable model = genTableMapper.selectById(genParam.getId());
|
GenTable model = genTableMapper.selectById(genParam.getId());
|
||||||
Assert.notNull(model, "数据已丢失");
|
Assert.notNull(model, "数据已丢失");
|
||||||
|
|
||||||
|
|
@ -222,6 +230,8 @@ public class GenerateServiceImpl implements IGenerateService {
|
||||||
model.setPackageName(genParam.getPackageName());
|
model.setPackageName(genParam.getPackageName());
|
||||||
model.setBusinessName(genParam.getBusinessName());
|
model.setBusinessName(genParam.getBusinessName());
|
||||||
model.setFunctionName(genParam.getFunctionName());
|
model.setFunctionName(genParam.getFunctionName());
|
||||||
|
model.setTreePrimary(genParam.getTreePrimary());
|
||||||
|
model.setTreeParent(genParam.getTreeParent());
|
||||||
model.setRemarks(genParam.getRemarks());
|
model.setRemarks(genParam.getRemarks());
|
||||||
model.setGenTpl(genParam.getGenTpl());
|
model.setGenTpl(genParam.getGenTpl());
|
||||||
model.setGenType(genParam.getGenType());
|
model.setGenType(genParam.getGenType());
|
||||||
|
|
@ -347,10 +357,10 @@ public class GenerateServiceImpl implements IGenerateService {
|
||||||
|
|
||||||
// 渲染模板
|
// 渲染模板
|
||||||
Map<String, String> map = new LinkedHashMap<>();
|
Map<String, String> map = new LinkedHashMap<>();
|
||||||
List<String> templates = VelocityUtil.getTemplateList("curd");
|
List<String> templates = VelocityUtil.getTemplateList(table.getGenTpl());
|
||||||
for (String template : templates) {
|
for (String template : templates) {
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
Template tpl = Velocity.getTemplate(template, "UTF-8");
|
Template tpl = Velocity.getTemplate(template, GenConstants.UTF8);
|
||||||
tpl.merge(context, sw);
|
tpl.merge(context, sw);
|
||||||
map.put(template, sw.toString());
|
map.put(template, sw.toString());
|
||||||
System.out.println(sw);
|
System.out.println(sw);
|
||||||
|
|
@ -378,8 +388,49 @@ public class GenerateServiceImpl implements IGenerateService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成代码
|
* 生成代码 (自定义路径)
|
||||||
*
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param tableName 表名
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void genCode(String tableName) {
|
||||||
|
// 查表信息
|
||||||
|
GenTable table = genTableMapper.selectOne(new QueryWrapper<GenTable>()
|
||||||
|
.eq("table_name", tableName)
|
||||||
|
.last("limit 1"));
|
||||||
|
|
||||||
|
// 查列信息
|
||||||
|
Integer tableId = table.getId();
|
||||||
|
List<GenTableColumn> columns = genTableColumnMapper.selectList(
|
||||||
|
new QueryWrapper<GenTableColumn>()
|
||||||
|
.orderByAsc("sort")
|
||||||
|
.eq("table_id", tableId));
|
||||||
|
|
||||||
|
// 初始模板
|
||||||
|
VelocityUtil.initVelocity();
|
||||||
|
VelocityContext context = VelocityUtil.prepareContext(table, columns);
|
||||||
|
|
||||||
|
// 渲染模板
|
||||||
|
List<String> templates = VelocityUtil.getTemplateList(table.getGenTpl());
|
||||||
|
for (String template : templates) {
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
Template tpl = Velocity.getTemplate(template, GenConstants.UTF8);
|
||||||
|
tpl.merge(context, sw);
|
||||||
|
try {
|
||||||
|
String basePath = VelocityUtil.getGenPath(table);
|
||||||
|
String filePath = basePath + VelocityUtil.getFileName(template, table);
|
||||||
|
FileUtils.writeStringToFile(new File(filePath), sw.toString(), GenConstants.UTF8);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("生成渲染模板失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成代码 (压缩包下载)
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
* @param tableName 表名
|
* @param tableName 表名
|
||||||
* @param zip 压缩包
|
* @param zip 压缩包
|
||||||
*/
|
*/
|
||||||
|
|
@ -403,11 +454,11 @@ public class GenerateServiceImpl implements IGenerateService {
|
||||||
List<String> templates = VelocityUtil.getTemplateList(table.getGenTpl());
|
List<String> templates = VelocityUtil.getTemplateList(table.getGenTpl());
|
||||||
for (String template : templates) {
|
for (String template : templates) {
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
Template tpl = Velocity.getTemplate(template, "UTF-8");
|
Template tpl = Velocity.getTemplate(template, GenConstants.UTF8);
|
||||||
tpl.merge(context, sw);
|
tpl.merge(context, sw);
|
||||||
try {
|
try {
|
||||||
zip.putNextEntry(new ZipEntry(VelocityUtil.getFileName(template, table)));
|
zip.putNextEntry(new ZipEntry(VelocityUtil.getFileName(template, table)));
|
||||||
IOUtils.write(sw.toString(), zip, "UTF-8");
|
IOUtils.write(sw.toString(), zip, GenConstants.UTF8);
|
||||||
zip.flush();
|
zip.flush();
|
||||||
zip.closeEntry();
|
zip.closeEntry();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
package com.hxkj.generator.util;
|
package com.hxkj.generator.util;
|
||||||
|
|
||||||
import com.hxkj.common.constant.GenConstants;
|
import com.hxkj.generator.constant.GenConstants;
|
||||||
import com.hxkj.common.utils.StringUtil;
|
import com.hxkj.common.utils.StringUtil;
|
||||||
import com.hxkj.admin.config.GenConfig;
|
import com.hxkj.generator.config.GenConfig;
|
||||||
|
import com.hxkj.generator.constant.HtmlConstants;
|
||||||
|
import com.hxkj.generator.constant.JavaConstants;
|
||||||
|
import com.hxkj.generator.constant.SqlConstants;
|
||||||
import com.hxkj.generator.entity.GenTable;
|
import com.hxkj.generator.entity.GenTable;
|
||||||
import com.hxkj.generator.entity.GenTableColumn;
|
import com.hxkj.generator.entity.GenTableColumn;
|
||||||
import org.apache.commons.lang3.RegExUtils;
|
import org.apache.commons.lang3.RegExUtils;
|
||||||
|
|
@ -46,78 +49,90 @@ public class GenUtil {
|
||||||
String columnType = GenUtil.getDbType(column.getColumnType());
|
String columnType = GenUtil.getDbType(column.getColumnType());
|
||||||
column.setTableId(table.getId());
|
column.setTableId(table.getId());
|
||||||
column.setJavaField(StringUtil.toCamelCase(columnName));
|
column.setJavaField(StringUtil.toCamelCase(columnName));
|
||||||
column.setJavaType(GenConstants.TYPE_STRING);
|
column.setJavaType(JavaConstants.TYPE_STRING);
|
||||||
column.setQueryType(GenConstants.QUERY_EQ);
|
column.setQueryType(GenConstants.QUERY_EQ);
|
||||||
column.setIsInsert(GenConstants.REQUIRE);
|
column.setIsInsert(GenConstants.REQUIRE);
|
||||||
column.setUpdateTime(table.getUpdateTime());
|
column.setUpdateTime(table.getUpdateTime());
|
||||||
column.setCreateTime(table.getCreateTime());
|
column.setCreateTime(table.getCreateTime());
|
||||||
|
|
||||||
// 文本域组
|
// 文本域组
|
||||||
if (GenUtil.isArraysContains(GenConstants.COLUMN_TYPE_STR, columnType) ||
|
if (GenUtil.isArraysContains(SqlConstants.COLUMN_TYPE_STR, columnType) ||
|
||||||
GenUtil.isArraysContains(GenConstants.COLUMN_TYPE_TEXT, columnType)) {
|
GenUtil.isArraysContains(SqlConstants.COLUMN_TYPE_TEXT, columnType)) {
|
||||||
Integer columnLength = GenUtil.getColumnLength(column.getColumnType());
|
Integer columnLength = GenUtil.getColumnLength(column.getColumnType());
|
||||||
String htmlType = columnLength >= 500 || GenUtil.isArraysContains(GenConstants.COLUMN_TYPE_TEXT, columnType)
|
String htmlType = columnLength >= 500 || GenUtil.isArraysContains(SqlConstants.COLUMN_TYPE_TEXT, columnType)
|
||||||
? GenConstants.HTML_TEXTAREA
|
? HtmlConstants.HTML_TEXTAREA
|
||||||
: GenConstants.HTML_INPUT;
|
: HtmlConstants.HTML_INPUT;
|
||||||
column.setHtmlType(htmlType);
|
column.setHtmlType(htmlType);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 日期组件
|
// 日期字段
|
||||||
else if (GenUtil.isArraysContains(GenConstants.COLUMN_TYPE_TIME, columnType)) {
|
else if (GenUtil.isArraysContains(SqlConstants.COLUMN_TYPE_TIME, columnType)) {
|
||||||
column.setJavaType(GenConstants.TYPE_DATE);
|
column.setJavaType(JavaConstants.TYPE_DATE);
|
||||||
column.setHtmlType(GenConstants.HTML_DATETIME);
|
column.setHtmlType(HtmlConstants.HTML_DATETIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 数字组件
|
// 时间字段
|
||||||
else if (GenUtil.isArraysContains(GenConstants.COLUMN_TYPE_NUMBER, columnType)) {
|
else if (GenUtil.isArraysContains(SqlConstants.COLUMN_TIME_NAME, columnName)) {
|
||||||
column.setHtmlType(GenConstants.HTML_INPUT);
|
column.setJavaType(JavaConstants.TYPE_LONG);
|
||||||
|
column.setHtmlType(HtmlConstants.HTML_DATETIME);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 数字字段
|
||||||
|
else if (GenUtil.isArraysContains(SqlConstants.COLUMN_TYPE_NUMBER, columnType)) {
|
||||||
|
column.setHtmlType(HtmlConstants.HTML_INPUT); // 输入框
|
||||||
String[] str = StringUtil.split(StringUtil.substringBetween(column.getColumnType(), "(", ")"), ",");
|
String[] str = StringUtil.split(StringUtil.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_BIG_DECIMAL); // 浮点形
|
column.setJavaType(JavaConstants.TYPE_BIG_DECIMAL); // 浮点形
|
||||||
} 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); // 整数形
|
column.setJavaType(JavaConstants.TYPE_INTEGER); // 整数形
|
||||||
} else {
|
} else {
|
||||||
column.setJavaType(GenConstants.TYPE_LONG); // 长整形
|
column.setJavaType(JavaConstants.TYPE_LONG); // 长整形
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 编辑字段
|
// 需编辑字段
|
||||||
if (!GenUtil.isArraysContains(GenConstants.COLUMN_NAME_NOT_EDIT, columnName) && column.getIsPk() == 0) {
|
if (!GenUtil.isArraysContains(SqlConstants.COLUMN_NAME_NOT_EDIT, columnName) && column.getIsPk() == 0) {
|
||||||
column.setIsEdit(GenConstants.REQUIRE);
|
column.setIsEdit(GenConstants.REQUIRE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列表字段
|
// 需列表字段
|
||||||
if (!GenUtil.isArraysContains(GenConstants.COLUMN_NAME_NOT_LIST, columnName) && column.getIsPk() == 0) {
|
if (!GenUtil.isArraysContains(SqlConstants.COLUMN_NAME_NOT_LIST, columnName) && column.getIsPk() == 0) {
|
||||||
column.setIsList(GenConstants.REQUIRE);
|
column.setIsList(GenConstants.REQUIRE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询字段
|
// 需查询字段
|
||||||
if (!GenUtil.isArraysContains(GenConstants.COLUMN_NAME_NOT_QUERY, columnName) && column.getIsPk() == 0) {
|
if (!GenUtil.isArraysContains(SqlConstants.COLUMN_NAME_NOT_QUERY, columnName) && column.getIsPk() == 0) {
|
||||||
column.setIsQuery(GenConstants.REQUIRE);
|
column.setIsQuery(GenConstants.REQUIRE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询字段类型
|
// 模糊查字段
|
||||||
if (StringUtil.endsWithIgnoreCase(columnName, "name")) {
|
if (StringUtil.endsWithIgnoreCase(columnName, "name") ||
|
||||||
|
columnName.equals("nickname") ||
|
||||||
|
columnName.equals("username") ||
|
||||||
|
columnName.equals("title") ||
|
||||||
|
columnName.equals("mobile")) {
|
||||||
column.setQueryType(GenConstants.QUERY_LIKE);
|
column.setQueryType(GenConstants.QUERY_LIKE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据字段设置
|
// 根据字段设置
|
||||||
if (StringUtil.endsWithIgnoreCase(columnName, "status")) {
|
if (StringUtil.endsWithIgnoreCase(columnName, "status")
|
||||||
|
|| columnName.equals("isShow")
|
||||||
|
|| columnName.equals("isDisable")) {
|
||||||
// 状态字段设置单选框
|
// 状态字段设置单选框
|
||||||
column.setHtmlType(GenConstants.HTML_RADIO);
|
column.setHtmlType(HtmlConstants.HTML_RADIO);
|
||||||
} else if (StringUtil.endsWithIgnoreCase(columnName, "type") ||
|
} else if (StringUtil.endsWithIgnoreCase(columnName, "type") ||
|
||||||
StringUtil.endsWithIgnoreCase(columnName, "sex")) {
|
StringUtil.endsWithIgnoreCase(columnName, "sex")) {
|
||||||
// 类型&性别字段设置下拉框
|
// 类型&性别字段设置下拉框
|
||||||
column.setHtmlType(GenConstants.HTML_SELECT);
|
column.setHtmlType(HtmlConstants.HTML_SELECT);
|
||||||
} else if (StringUtil.endsWithIgnoreCase(columnName, "image")) {
|
} else if (StringUtil.endsWithIgnoreCase(columnName, "image")) {
|
||||||
// 图片字段设置图片上传控件
|
// 图片字段设置图片上传控件
|
||||||
column.setHtmlType(GenConstants.HTML_IMAGE_UPLOAD);
|
column.setHtmlType(HtmlConstants.HTML_IMAGE_UPLOAD);
|
||||||
} else if (StringUtil.endsWithIgnoreCase(columnName, "file")) {
|
} else if (StringUtil.endsWithIgnoreCase(columnName, "file")) {
|
||||||
// 文件字段设置文件上传控件
|
// 文件字段设置文件上传控件
|
||||||
column.setHtmlType(GenConstants.HTML_FILE_UPLOAD);
|
column.setHtmlType(HtmlConstants.HTML_FILE_UPLOAD);
|
||||||
} else if (StringUtil.endsWithIgnoreCase(columnName, "content")) {
|
} else if (StringUtil.endsWithIgnoreCase(columnName, "content")) {
|
||||||
// 内容字段的设置富文本控件
|
// 内容字段的设置富文本控件
|
||||||
column.setHtmlType(GenConstants.HTML_EDITOR);
|
column.setHtmlType(HtmlConstants.HTML_EDITOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -155,8 +170,8 @@ public class GenUtil {
|
||||||
* @return 类名
|
* @return 类名
|
||||||
*/
|
*/
|
||||||
public static String toClassName(String tableName) {
|
public static String toClassName(String tableName) {
|
||||||
String tablePrefix = "ls_";
|
String tablePrefix = GenConfig.tablePrefix;
|
||||||
if (StringUtil.isNotEmpty(tablePrefix)) {
|
if (GenConfig.isRemoveTablePrefix && StringUtil.isNotEmpty(tablePrefix)) {
|
||||||
String[] searchList = StringUtil.split(tablePrefix, ",");
|
String[] searchList = StringUtil.split(tablePrefix, ",");
|
||||||
tableName = replaceFirst(tableName, searchList);
|
tableName = replaceFirst(tableName, searchList);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
package com.hxkj.generator.util;
|
package com.hxkj.generator.util;
|
||||||
|
|
||||||
import com.hxkj.common.utils.StringUtil;
|
import com.hxkj.common.utils.StringUtil;
|
||||||
|
import com.hxkj.common.utils.UrlUtil;
|
||||||
|
import com.hxkj.generator.config.GenConfig;
|
||||||
|
import com.hxkj.generator.constant.GenConstants;
|
||||||
import com.hxkj.generator.entity.GenTable;
|
import com.hxkj.generator.entity.GenTable;
|
||||||
import com.hxkj.generator.entity.GenTableColumn;
|
import com.hxkj.generator.entity.GenTableColumn;
|
||||||
import org.apache.velocity.VelocityContext;
|
import org.apache.velocity.VelocityContext;
|
||||||
|
|
@ -8,6 +11,7 @@ import org.apache.velocity.app.Velocity;
|
||||||
import org.apache.velocity.runtime.RuntimeConstants;
|
import org.apache.velocity.runtime.RuntimeConstants;
|
||||||
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
|
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -68,6 +72,21 @@ public class VelocityUtil {
|
||||||
return velocityContext;
|
return velocityContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取生成路径
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param table 表
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public static String getGenPath(GenTable table) {
|
||||||
|
String genPath = table.getGenPath();
|
||||||
|
if (StringUtil.equals(genPath, "/")) {
|
||||||
|
return System.getProperty("user.dir") + File.separator + "src" + File.separator;
|
||||||
|
}
|
||||||
|
return genPath + File.separator;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取模板列表
|
* 获取模板列表
|
||||||
*
|
*
|
||||||
|
|
@ -76,51 +95,65 @@ public class VelocityUtil {
|
||||||
*/
|
*/
|
||||||
public static List<String> getTemplateList(String genTpl) {
|
public static List<String> getTemplateList(String genTpl) {
|
||||||
List<String> templates = new LinkedList<>();
|
List<String> templates = new LinkedList<>();
|
||||||
// templates.add("java/controller.java.vm");
|
templates.add("java/controller.java.vm");
|
||||||
// templates.add("java/entity.java.vm");
|
templates.add("java/entity.java.vm");
|
||||||
// templates.add("java/mapper.java.vm");
|
templates.add("java/mapper.java.vm");
|
||||||
// templates.add("java/service.java.vm");
|
templates.add("java/service.java.vm");
|
||||||
templates.add("java/serviceImpl.java.vm");
|
templates.add("java/serviceImpl.java.vm");
|
||||||
// templates.add("java/validate.java.vm");
|
templates.add("java/validate.java.vm");
|
||||||
|
templates.add("java/vo.java.vm");
|
||||||
|
// if (GenConstants.TPL_CRUD.equals(genTpl)) {
|
||||||
|
// templates.add("vue/index.vue.vm");
|
||||||
|
// }
|
||||||
|
// else if (GenConstants.TPL_TREE.equals(genTpl)) {
|
||||||
|
// templates.add("vue/index-tree.vue.vm");
|
||||||
|
// }
|
||||||
return templates;
|
return templates;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取文件名
|
* 获取文件名
|
||||||
*/
|
*/
|
||||||
public static String getFileName(String template, GenTable genTable)
|
public static String getFileName(String template, GenTable genTable) {
|
||||||
{
|
|
||||||
// 文件名称
|
|
||||||
String fileName = "";
|
String fileName = "";
|
||||||
String entityName = genTable.getEntityName();
|
String entityName = genTable.getEntityName();
|
||||||
String moduleName = genTable.getModuleName();
|
|
||||||
String packageName = genTable.getPackageName();
|
String packageName = genTable.getPackageName();
|
||||||
String businessName = genTable.getBusinessName();
|
String moduleName = genTable.getModuleName();
|
||||||
|
String[] arrPackage = packageName.split("\\.");
|
||||||
|
|
||||||
String javaPath = StringUtil.replace(packageName, ".", "/");
|
// 生成路径
|
||||||
|
String javaPath = StringUtil.replace(packageName, ".", "/");
|
||||||
|
String basePackage = arrPackage[0] + "/" + arrPackage[1]+"/";
|
||||||
|
String commonPackage = GenConfig.commonApp + basePackage + "common";
|
||||||
|
String mainPackage = StringUtil.format(GenConfig.mainApp, arrPackage.length>=3?arrPackage[2]:"admin")+javaPath;
|
||||||
|
String subPackage = !moduleName.equals("") ? StringUtil.replace(moduleName, ".", "/") + "/" : "";
|
||||||
|
|
||||||
if (template.contains("mapper.java.vm")) {
|
if (template.contains("mapper.java.vm")) {
|
||||||
fileName = StringUtil.format("{}/mapper/{}Mapper.java", "com/hxkj/common", entityName);
|
fileName = StringUtil.format("{}/mapper/{}{}Mapper.java", commonPackage, subPackage, entityName);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (template.contains("entity.java.vm")) {
|
else if (template.contains("entity.java.vm")) {
|
||||||
fileName = StringUtil.format("{}/entity/{}Entity.java", "com/hxkj/common", entityName);
|
fileName = StringUtil.format("{}/entity/{}{}Entity.java", commonPackage, subPackage, entityName);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (template.contains("service.java.vm")) {
|
else if (template.contains("service.java.vm")) {
|
||||||
fileName = StringUtil.format("{}/service/I{}Service.java", javaPath, entityName);
|
fileName = StringUtil.format("{}/service/I{}Service.java", mainPackage, entityName);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (template.contains("serviceImpl.java.vm")) {
|
else if (template.contains("serviceImpl.java.vm")) {
|
||||||
fileName = StringUtil.format("{}/service/impl/{}ServiceImpl.java", javaPath, entityName);
|
fileName = StringUtil.format("{}/service/impl/{}ServiceImpl.java", mainPackage, entityName);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (template.contains("controller.java.vm")) {
|
else if (template.contains("controller.java.vm")) {
|
||||||
fileName = StringUtil.format("{}/controller/{}Controller.java", javaPath, entityName);
|
fileName = StringUtil.format("{}/controller/{}{}Controller.java", mainPackage, subPackage, entityName);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (template.contains("validate.java.vm")) {
|
else if (template.contains("validate.java.vm")) {
|
||||||
fileName = StringUtil.format("{}/validate/{}Param.java", javaPath, entityName);
|
fileName = StringUtil.format("{}/validate/{}{}Param.java", mainPackage, subPackage, entityName);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (template.contains("vo.java.vm")) {
|
||||||
|
fileName = StringUtil.format("{}/vo/{}{}Vo.java", mainPackage, subPackage, entityName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return fileName;
|
return fileName;
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import org.hibernate.validator.constraints.Length;
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -78,8 +79,12 @@ public class GenParam implements Serializable {
|
||||||
private Integer genType;
|
private Integer genType;
|
||||||
|
|
||||||
@Length(max = 200, message = "生成代码路径不能大于200个字符")
|
@Length(max = 200, message = "生成代码路径不能大于200个字符")
|
||||||
private String genPath;
|
private String genPath = "/";
|
||||||
|
|
||||||
private List<Map<String, String>> columns;
|
private List<Map<String, String>> columns = new ArrayList<>();
|
||||||
|
|
||||||
|
private String treePrimary = "";
|
||||||
|
|
||||||
|
private String treeParent = "";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
package com.hxkj.common.mapper;
|
package com.hxkj.common.mapper;
|
||||||
|
|
||||||
import com.hxkj.common.core.basics.IBaseMapper;
|
import com.hxkj.common.core.basics.IBaseMapper;
|
||||||
import com.hxkj.common.entity.${entityName};
|
import com.hxkj.common.entity.${EntityName};
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${functionName}
|
* ${functionName}
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface ${entityName}Mapper extends IBaseMapper<${entityName}> {
|
public interface ${EntityName}Mapper extends IBaseMapper<${EntityName}> {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@ package com.hxkj.admin.service;
|
||||||
|
|
||||||
import com.hxkj.admin.validate.PageParam;
|
import com.hxkj.admin.validate.PageParam;
|
||||||
import com.hxkj.admin.validate.${EntityName}Param;
|
import com.hxkj.admin.validate.${EntityName}Param;
|
||||||
|
#if($table.genTpl=="curd")
|
||||||
import com.hxkj.admin.vo.system.${EntityName}Vo;
|
import com.hxkj.admin.vo.system.${EntityName}Vo;
|
||||||
|
#end
|
||||||
import com.hxkj.common.core.PageResult;
|
import com.hxkj.common.core.PageResult;
|
||||||
import com.hxkj.common.entity.${EntityName};
|
import com.hxkj.common.entity.${EntityName};
|
||||||
|
|
||||||
|
|
@ -11,25 +13,37 @@ import java.util.Map;
|
||||||
/**
|
/**
|
||||||
* ${functionName}服务接口类
|
* ${functionName}服务接口类
|
||||||
*/
|
*/
|
||||||
public interface ISystemAdminService {
|
public interface I${EntityName}Service {
|
||||||
|
|
||||||
|
#if($table.genTpl=="curd")
|
||||||
/**
|
/**
|
||||||
* ${functionName}列表
|
* ${functionName}列表
|
||||||
*
|
*
|
||||||
* @author ${authorName}
|
* @author ${authorName}
|
||||||
* @param pageParam 分页参数
|
* @param pageParam 分页参数
|
||||||
|
* @param params 搜索参数
|
||||||
* @return PageResult<${EntityName}Vo}>
|
* @return PageResult<${EntityName}Vo}>
|
||||||
*/
|
*/
|
||||||
PageResult<${EntityName}Vo> list(PageParam pageParam, Map<String, String> params);
|
PageResult<${EntityName}Vo> list(PageParam pageParam, Map<String, String> params);
|
||||||
|
#elseif($table.genTpl=="tree")
|
||||||
|
/**
|
||||||
|
* ${functionName}列表
|
||||||
|
*
|
||||||
|
* @author ${authorName}
|
||||||
|
* @param params 搜索参数
|
||||||
|
* @return JSONArray
|
||||||
|
*/
|
||||||
|
JSONArray list(Map<String, String> params);
|
||||||
|
#end
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${functionName}详情
|
* ${functionName}详情
|
||||||
*
|
*
|
||||||
* @author ${authorName}
|
* @author ${authorName}
|
||||||
* @param id 主键参数
|
* @param id 主键ID
|
||||||
* @return ${EntityName}Vo
|
* @return ${EntityName}
|
||||||
*/
|
*/
|
||||||
SystemAdminVo detail(Integer id);
|
${EntityName} detail(Integer id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${functionName}新增
|
* ${functionName}新增
|
||||||
|
|
@ -51,7 +65,7 @@ public interface ISystemAdminService {
|
||||||
* ${functionName}删除
|
* ${functionName}删除
|
||||||
*
|
*
|
||||||
* @author ${authorName}
|
* @author ${authorName}
|
||||||
* @param id 主键参数
|
* @param id 主键ID
|
||||||
*/
|
*/
|
||||||
void del(Integer id);
|
void del(Integer id);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,54 +35,471 @@ public class ${EntityName}ServiceImpl implements I${EntityName}Service {
|
||||||
@Resource
|
@Resource
|
||||||
${EntityName}Mapper ${entityName}Mapper;
|
${EntityName}Mapper ${entityName}Mapper;
|
||||||
|
|
||||||
|
#if($table.sub_table_name.equals(""))
|
||||||
|
#if($table.genTpl=="curd")
|
||||||
/**
|
/**
|
||||||
* ${functionName}列表
|
* ${functionName}列表
|
||||||
*
|
*
|
||||||
* @author ${authorName}
|
* @author ${authorName}
|
||||||
* @param pageParam 分页参数
|
* @param pageParam 分页参数
|
||||||
* @return PageResult<SysAdminListVo>
|
* @param params 搜索参数
|
||||||
|
* @return PageResult<${EntityName}Vo>
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public PageResult<${EntityName}Vo> list(PageParam pageParam, Map<String, String> params) {
|
public PageResult<${EntityName}Vo> list(PageParam pageParam, Map<String, String> params) {
|
||||||
Integer page = pageParam.getPageNo();
|
Integer page = pageParam.getPageNo();
|
||||||
Integer limit = pageParam.getPageSize();
|
Integer limit = pageParam.getPageSize();
|
||||||
|
|
||||||
QueryWrapper<SystemAdmin> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<${EntityName}> queryWrapper = new QueryWrapper<>();
|
||||||
|
#if($isSearch)
|
||||||
|
#if($fields.contains("is_delete"))
|
||||||
queryWrapper.eq("is_delete", 0);
|
queryWrapper.eq("is_delete", 0);
|
||||||
queryWrapper.orderByDesc(Arrays.asList("id", "sort"));
|
#end
|
||||||
|
#if($fields.contains("sort"))
|
||||||
|
queryWrapper.orderByDesc(Arrays.asList("sort", "id"));
|
||||||
|
#else
|
||||||
|
queryWrapper.orderByDesc("id");
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
#if($isSearch)
|
#if($isSearch)
|
||||||
${entityName}Mapper.setSearch(queryWrapper, params, new String[]{
|
${entityName}Mapper.setSearch(queryWrapper, params, new String[]{
|
||||||
#foreach ($column in $columns)
|
#foreach ($column in $columns)
|
||||||
#if($column.isQuery)
|
#if($column.isQuery)
|
||||||
#if($column.queryType=="EQ")
|
#if($column.queryType=="datetime")
|
||||||
#if($column.javaType=="String")
|
"datetime:startTime-endTime@${column.columnName}:str"
|
||||||
#if($column.javaField.equals($column.columnName))
|
#else
|
||||||
"=:${column.javaField}:str",
|
#if($column.javaType=="Integer")
|
||||||
#else
|
#if($column.javaField.equals($column.columnName))
|
||||||
"=:${column.javaField}@${column.columnName}:str",
|
"${column.queryType}:${column.javaField}:int",
|
||||||
#end
|
#else
|
||||||
#elseif($column.javaType=="Integer")
|
"${column.queryType}:${column.javaField}@${column.columnName}:int",
|
||||||
#if($column.javaField.equals($column.columnName))
|
#end
|
||||||
"=:${column.javaField}:int",
|
#elseif($column.javaType=="Long")
|
||||||
#else
|
#if($column.javaField.equals($column.columnName))
|
||||||
"=:${column.javaField}@${column.columnName}:int",
|
"${column.queryType}:${column.javaField}:long",
|
||||||
#end
|
#else
|
||||||
#end
|
"${column.queryType}:${column.javaField}@${column.columnName}:long",
|
||||||
#end
|
#end
|
||||||
|
#else
|
||||||
|
#if($column.javaField.equals($column.columnName))
|
||||||
|
"${column.queryType}:${column.javaField}:str",
|
||||||
|
#else
|
||||||
|
"${column.queryType}:${column.javaField}@${column.columnName}:str",
|
||||||
|
#end
|
||||||
#end
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
#end
|
#end
|
||||||
});
|
});
|
||||||
#end
|
#end
|
||||||
|
|
||||||
IPage<SystemAdminVo> iPage = systemAdminMapper.selectPage(new Page<>(page, limit), queryWrapper);
|
IPage<${EntityName}Vo> iPage = ${entityName}Mapper.selectPage(new Page<>(page, limit), queryWrapper);
|
||||||
for (SystemAdminVo vo : iPage.getRecords()) {
|
|
||||||
vo.setCreateTime(TimeUtil.timestampToDate(vo.getCreateTime()));
|
#if($fields.contains("create_time") || $fields.contains("update_time"))
|
||||||
vo.setUpdateTime(TimeUtil.timestampToDate(vo.getUpdateTime()));
|
List<${EntityName}Vo> list = new ArrayList<>();
|
||||||
vo.setLastLoginTime(TimeUtil.timestampToDate(vo.getLastLoginTime()));
|
for (${EntityName} item : iPage.getRecords()) {
|
||||||
|
${EntityName}Vo vo = new ${EntityName}Vo();
|
||||||
|
BeanUtils.copyProperties(item, vo);
|
||||||
|
#if($fields.contains("image"))
|
||||||
|
vo.setImage(UrlUtil.toAbsoluteUrl(vo.getImage))
|
||||||
|
#end
|
||||||
|
#if($fields.contains("avatar"))
|
||||||
|
vo.setAvatar(UrlUtil.toAbsoluteUrl(vo.getAvatar))
|
||||||
|
#end
|
||||||
|
#if($fields.contains("logo"))
|
||||||
|
vo.setLogo(UrlUtil.toAbsoluteUrl(vo.getLogo))
|
||||||
|
#end
|
||||||
|
#if($fields.contains("create_time"))
|
||||||
|
vo.setCreateTime(TimeUtil.timestampToDate(item.getCreateTime()));
|
||||||
|
#end
|
||||||
|
#if($fields.contains("update_time"))
|
||||||
|
vo.setUpdateTime(TimeUtil.timestampToDate(item.getUpdateTime()));
|
||||||
|
#end
|
||||||
|
list.add(vo);
|
||||||
|
}
|
||||||
|
return PageResult.iPageHandle(iPage.getTotal(), iPage.getCurrent(), iPage.getSize(), list);
|
||||||
|
#else
|
||||||
|
return PageResult.iPageHandle(iPage);
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
#elseif($table.genTpl=="tree")
|
||||||
|
/**
|
||||||
|
* ${functionName}列表
|
||||||
|
*
|
||||||
|
* @author ${authorName}
|
||||||
|
* @param params 搜索参数
|
||||||
|
* @return PageResult<${EntityName}Vo>
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public JSONArray list(Map<String, String> params) {
|
||||||
|
QueryWrapper<${EntityName}> queryWrapper = new QueryWrapper<>();
|
||||||
|
#if($isSearch)
|
||||||
|
#if($fields.contains("is_delete"))
|
||||||
|
queryWrapper.eq("is_delete", 0);
|
||||||
|
#end
|
||||||
|
#if($fields.contains("sort"))
|
||||||
|
queryWrapper.orderByDesc(Arrays.asList("sort", "id"));
|
||||||
|
#else
|
||||||
|
queryWrapper.orderByDesc("id");
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
|
#if($isSearch)
|
||||||
|
${entityName}Mapper.setSearch(queryWrapper, params, new String[]{
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.isQuery)
|
||||||
|
#if($column.queryType=="datetime")
|
||||||
|
"datetime:startTime-endTime@${column.columnName}:str"
|
||||||
|
#else
|
||||||
|
#if($column.javaType=="Integer")
|
||||||
|
#if($column.javaField.equals($column.columnName))
|
||||||
|
"${column.queryType}:${column.javaField}:int",
|
||||||
|
#else
|
||||||
|
"${column.queryType}:${column.javaField}@${column.columnName}:int",
|
||||||
|
#end
|
||||||
|
#elseif($column.javaType=="Long")
|
||||||
|
#if($column.javaField.equals($column.columnName))
|
||||||
|
"${column.queryType}:${column.javaField}:long",
|
||||||
|
#else
|
||||||
|
"${column.queryType}:${column.javaField}@${column.columnName}:long",
|
||||||
|
#end
|
||||||
|
#else
|
||||||
|
#if($column.javaField.equals($column.columnName))
|
||||||
|
"${column.queryType}:${column.javaField}:str",
|
||||||
|
#else
|
||||||
|
"${column.queryType}:${column.javaField}@${column.columnName}:str",
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
});
|
||||||
|
#end
|
||||||
|
|
||||||
|
List<${EntityName}> arrayData = ${entityName}Mapper.selectList(queryWrapper);
|
||||||
|
|
||||||
|
#if($fields.contains("create_time") || $fields.contains("update_time"))
|
||||||
|
List<${EntityName}Vo> list = new ArrayList<>();
|
||||||
|
for (${EntityName} item : arrayData) {
|
||||||
|
${EntityName}Vo vo = new ${EntityName}Vo();
|
||||||
|
BeanUtils.copyProperties(item, vo);
|
||||||
|
#if($fields.contains("image"))
|
||||||
|
vo.setImage(UrlUtil.toAbsoluteUrl(vo.getImage))
|
||||||
|
#end
|
||||||
|
#if($fields.contains("avatar"))
|
||||||
|
vo.setAvatar(UrlUtil.toAbsoluteUrl(vo.getAvatar))
|
||||||
|
#end
|
||||||
|
#if($fields.contains("logo"))
|
||||||
|
vo.setLogo(UrlUtil.toAbsoluteUrl(vo.getLogo))
|
||||||
|
#end
|
||||||
|
#if($fields.contains("create_time"))
|
||||||
|
vo.setCreateTime(TimeUtil.timestampToDate(item.getCreateTime()));
|
||||||
|
#end
|
||||||
|
#if($fields.contains("update_time"))
|
||||||
|
vo.setUpdateTime(TimeUtil.timestampToDate(item.getUpdateTime()));
|
||||||
|
#end
|
||||||
|
list.add(vo);
|
||||||
|
}
|
||||||
|
JSONArray jsonArray = JSONArray.parseArray(JSONArray.toJSONString(list));
|
||||||
|
return ArrayUtil.listToTree(jsonArray, "${table.treePrimary}", "${table.treeParent}", "children");
|
||||||
|
#else
|
||||||
|
JSONArray jsonArray = JSONArray.parseArray(JSONArray.toJSONString(arrayData));
|
||||||
|
return ArrayUtil.listToTree(jsonArray, "${table.treePrimary}", "${table.treeParent}", "children");
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
#else
|
||||||
|
#if($table.genTpl=="curd")
|
||||||
|
/**
|
||||||
|
* ${functionName}列表
|
||||||
|
*
|
||||||
|
* @author ${authorName}
|
||||||
|
* @param pageParam 分页参数
|
||||||
|
* @param params 搜索参数
|
||||||
|
* @return PageResult<${EntityName}Vo>
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PageResult<${EntityName}Vo> list(PageParam pageParam, Map<String, String> params) {
|
||||||
|
Integer page = pageParam.getPageNo();
|
||||||
|
Integer limit = pageParam.getPageSize();
|
||||||
|
|
||||||
|
MPJQueryWrapper<${EntityName}> mpjQueryWrapper = new MPJQueryWrapper<>();
|
||||||
|
mpjQueryWrapper.join("${table.sub_table_name} f ON f.${table.sub_table_fk}=t.id")
|
||||||
|
#if($isSearch)
|
||||||
|
#if($fields.contains("is_delete"))
|
||||||
|
mpjQueryWrapper.eq("is_delete", 0);
|
||||||
|
#end
|
||||||
|
#if($fields.contains("sort"))
|
||||||
|
mpjQueryWrapper.orderByDesc(Arrays.asList("sort", "id"));
|
||||||
|
#else
|
||||||
|
mpjQueryWrapper.orderByDesc("id");
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
|
#if($isSearch)
|
||||||
|
${entityName}Mapper.setSearch(mpjQueryWrapper, params, new String[]{
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.isQuery)
|
||||||
|
#if($column.queryType=="datetime")
|
||||||
|
"datetime:startTime-endTime@${column.columnName}:str"
|
||||||
|
#else
|
||||||
|
#if($column.javaType=="Integer")
|
||||||
|
#if($column.javaField.equals($column.columnName))
|
||||||
|
"${column.queryType}:${column.javaField}:int",
|
||||||
|
#else
|
||||||
|
"${column.queryType}:${column.javaField}@${column.columnName}:int",
|
||||||
|
#end
|
||||||
|
#elseif($column.javaType=="Long")
|
||||||
|
#if($column.javaField.equals($column.columnName))
|
||||||
|
"${column.queryType}:${column.javaField}:long",
|
||||||
|
#else
|
||||||
|
"${column.queryType}:${column.javaField}@${column.columnName}:long",
|
||||||
|
#end
|
||||||
|
#else
|
||||||
|
#if($column.javaField.equals($column.columnName))
|
||||||
|
"${column.queryType}:${column.javaField}:str",
|
||||||
|
#else
|
||||||
|
"${column.queryType}:${column.javaField}@${column.columnName}:str",
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
});
|
||||||
|
#end
|
||||||
|
|
||||||
|
IPage<${EntityName}Vo> iPage = ${entityName}Mapper.selectJoinPage(
|
||||||
|
new Page<>(page, limit),
|
||||||
|
${EntityName}Vo.class,
|
||||||
|
mpjQueryWrapper);
|
||||||
|
|
||||||
|
#if($fields.contains("create_time") || $fields.contains("update_time"))
|
||||||
|
for (${EntityName} item : iPage.getRecords()) {
|
||||||
|
${EntityName}Vo vo = new ${EntityName}Vo();
|
||||||
|
BeanUtils.copyProperties(item, vo);
|
||||||
|
#if($fields.contains("image"))
|
||||||
|
vo.setImage(UrlUtil.toAbsoluteUrl(vo.getImage))
|
||||||
|
#end
|
||||||
|
#if($fields.contains("avatar"))
|
||||||
|
vo.setAvatar(UrlUtil.toAbsoluteUrl(vo.getAvatar))
|
||||||
|
#end
|
||||||
|
#if($fields.contains("logo"))
|
||||||
|
vo.setLogo(UrlUtil.toAbsoluteUrl(vo.getLogo))
|
||||||
|
#end
|
||||||
|
#if($fields.contains("create_time"))
|
||||||
|
vo.setCreateTime(TimeUtil.timestampToDate(item.getCreateTime()));
|
||||||
|
#end
|
||||||
|
#if($fields.contains("update_time"))
|
||||||
|
vo.setUpdateTime(TimeUtil.timestampToDate(item.getUpdateTime()));
|
||||||
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#end
|
||||||
return PageResult.iPageHandle(iPage);
|
return PageResult.iPageHandle(iPage);
|
||||||
|
}
|
||||||
|
#elseif($table.genTpl=="tree")
|
||||||
|
/**
|
||||||
|
* ${functionName}列表
|
||||||
|
*
|
||||||
|
* @author ${authorName}
|
||||||
|
* @param params 搜索参数
|
||||||
|
* @return PageResult<${EntityName}Vo>
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public JSONArray list(Map<String, String> params) {
|
||||||
|
MPJQueryWrapper<${EntityName}> mpjQueryWrapper = new MPJQueryWrapper<>();
|
||||||
|
#if($isSearch)
|
||||||
|
#if($fields.contains("is_delete"))
|
||||||
|
mpjQueryWrapper.eq("t.is_delete", 0);
|
||||||
|
#end
|
||||||
|
#if($fields.contains("sort"))
|
||||||
|
mpjQueryWrapper.orderByDesc(Arrays.asList("t.sort", "t.id"));
|
||||||
|
#else
|
||||||
|
mpjQueryWrapper.orderByDesc("t.id");
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
|
#if($isSearch)
|
||||||
|
${entityName}Mapper.setSearch(mpjQueryWrapper, params, new String[]{
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.isQuery)
|
||||||
|
#if($column.queryType=="datetime")
|
||||||
|
"datetime:startTime-endTime@t.${column.columnName}:str"
|
||||||
|
#else
|
||||||
|
#if($column.javaType=="Integer")
|
||||||
|
"${column.queryType}:${column.javaField}@t.${column.columnName}:int",
|
||||||
|
#elseif($column.javaType=="Long")
|
||||||
|
"${column.queryType}:${column.javaField}@t.${column.columnName}:long",
|
||||||
|
#else
|
||||||
|
"${column.queryType}:${column.javaField}@t.${column.columnName}:str",
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
});
|
||||||
|
#end
|
||||||
|
|
||||||
|
List<${EntityName}> arrayData = ${entityName}Mapper.selectJoinList(
|
||||||
|
${EntityName}Vo.class,
|
||||||
|
mpjQueryWrapper);
|
||||||
|
|
||||||
|
#if($fields.contains("create_time") || $fields.contains("update_time"))
|
||||||
|
for (${EntityName} item : arrayData) {
|
||||||
|
${EntityName}Vo vo = new ${EntityName}Vo();
|
||||||
|
BeanUtils.copyProperties(item, vo);
|
||||||
|
#if($fields.contains("image"))
|
||||||
|
vo.setImage(UrlUtil.toAbsoluteUrl(vo.getImage))
|
||||||
|
#end
|
||||||
|
#if($fields.contains("avatar"))
|
||||||
|
vo.setAvatar(UrlUtil.toAbsoluteUrl(vo.getAvatar))
|
||||||
|
#end
|
||||||
|
#if($fields.contains("logo"))
|
||||||
|
vo.setLogo(UrlUtil.toAbsoluteUrl(vo.getLogo))
|
||||||
|
#end
|
||||||
|
#if($fields.contains("create_time"))
|
||||||
|
vo.setCreateTime(TimeUtil.timestampToDate(item.getCreateTime()));
|
||||||
|
#end
|
||||||
|
#if($fields.contains("update_time"))
|
||||||
|
vo.setUpdateTime(TimeUtil.timestampToDate(item.getUpdateTime()));
|
||||||
|
#end
|
||||||
|
list.add(vo);
|
||||||
|
}
|
||||||
|
|
||||||
|
#end
|
||||||
|
JSONArray jsonArray = JSONArray.parseArray(JSONArray.toJSONString(arrayData));
|
||||||
|
return ArrayUtil.listToTree(jsonArray, "${table.treePrimary}", "${table.treeParent}", "children");
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${functionName}详情
|
||||||
|
*
|
||||||
|
* @author ${authorName}
|
||||||
|
* @param id 主键参数
|
||||||
|
* @return ${EntityName}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ${EntityName} detail(Integer id) {
|
||||||
|
Article model = ${entityName}Mapper.selectOne(
|
||||||
|
#if($field.contains("is_delete"))
|
||||||
|
new QueryWrapper<${EntityName}>()
|
||||||
|
.eq("id", id)
|
||||||
|
.eq("is_delete", 0)
|
||||||
|
.last("limit 1"));
|
||||||
|
#else
|
||||||
|
new QueryWrapper<${EntityName}>()
|
||||||
|
.eq("id", id)
|
||||||
|
.last("limit 1"));
|
||||||
|
#end
|
||||||
|
|
||||||
|
Assert.notNull(model, "${functionName}不存在}");
|
||||||
|
|
||||||
|
#if($field.contains("image"))
|
||||||
|
model.setImage(UrlUtil.toAbsoluteUrl(model.getImage()));
|
||||||
|
#end
|
||||||
|
#if($field.contains("avatar"))
|
||||||
|
model.setAvatar(UrlUtil.toAbsoluteUrl(model.getAvatar()));
|
||||||
|
#end
|
||||||
|
#if($field.contains("logo"))
|
||||||
|
model.setLogo(UrlUtil.toAbsoluteUrl(model.getLogo()));
|
||||||
|
#end
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${functionName}新增
|
||||||
|
*
|
||||||
|
* @author ${authorName}
|
||||||
|
* @param ${entityName}Param 参数
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void add(${EntityName}Param ${entityName}Param) {
|
||||||
|
${EntityName} model = new ${EntityName}();
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if(!$column.isIncrement)
|
||||||
|
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#if($column.javaField.equals("image") || $colum.javaField.equals("avatar") || $colum.javaField.equals("logo"))
|
||||||
|
model.set${AttrName}(UrlUtil.toRelativeUrl(Param.get${AttrName}()))
|
||||||
|
#elseif(!$column.javaField.equals("createTime") and !$column.javaField.equals("deleteTime") and !$column.javaField.equals("updateTime") and !$column.javaField.equals("isDelete"))
|
||||||
|
model.set${AttrName}(${entityName}Param.get${AttrName}());
|
||||||
|
#elseif($column.javaField.equals("createTime") || $column.javaField.equals("updateTime"))
|
||||||
|
model.set${AttrName}(System.currentTimeMillis() / 1000);
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
${entityName}Mapper.insert(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${functionName}编辑
|
||||||
|
*
|
||||||
|
* @author ${authorName}
|
||||||
|
* @param ${entityName}Param 参数
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void edit(${EntityName}Param ${entityName}Param) {
|
||||||
|
${EntityName} model = ${entityName}Mapper.selectOne(
|
||||||
|
#if($field.contains("is_delete"))
|
||||||
|
new QueryWrapper<${EntityName}>()
|
||||||
|
.eq("id", ${entityName}Param.getId())
|
||||||
|
.eq("is_delete", 0)
|
||||||
|
.last("limit 1"));
|
||||||
|
#else
|
||||||
|
new QueryWrapper<${EntityName}>()
|
||||||
|
.eq("id", ${entityName}Param.getId())
|
||||||
|
.last("limit 1"));
|
||||||
|
#end
|
||||||
|
|
||||||
|
Assert.notNull(model, "${functionName}不存在!");
|
||||||
|
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if(!$column.isIncrement)
|
||||||
|
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#if($column.javaField.equals("image") || $colum.javaField.equals("avatar") || $colum.javaField.equals("logo"))
|
||||||
|
model.set${AttrName}(UrlUtil.toRelativeUrl(Param.get${AttrName}()))
|
||||||
|
#elseif(!$column.javaField.equals("createTime") and !$column.javaField.equals("deleteTime") and !$column.javaField.equals("updateTime") and !$column.javaField.equals("isDelete"))
|
||||||
|
model.set${AttrName}(${entityName}Param.get${AttrName}());
|
||||||
|
#elseif($column.javaField.equals("updateTime"))
|
||||||
|
model.set${AttrName}(System.currentTimeMillis() / 1000);
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
${entityName}Mapper.updateById(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${functionName}删除
|
||||||
|
*
|
||||||
|
* @author ${authorName}
|
||||||
|
* @param id 主键ID
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void del(Integer id) {
|
||||||
|
${EntityName} model = ${entityName}Mapper.selectOne(
|
||||||
|
#if($fields.contains("is_delete"))
|
||||||
|
new QueryWrapper<${EntityName}>()
|
||||||
|
.eq("id", id)
|
||||||
|
.eq("is_delete", 0)
|
||||||
|
.last("limit 1"));
|
||||||
|
#else
|
||||||
|
new QueryWrapper<${EntityName}>()
|
||||||
|
.eq("id", id)
|
||||||
|
.last("limit 1"));
|
||||||
|
#end
|
||||||
|
|
||||||
|
Assert.notNull(model, "${functionName}不存在!");
|
||||||
|
|
||||||
|
#if($fields.contains("is_delete"))
|
||||||
|
model.setIsDelete(1);
|
||||||
|
#if($fields.contains("delete_time"))
|
||||||
|
model.setDeleteTime(System.currentTimeMillis() / 1000);
|
||||||
|
#end
|
||||||
|
${entityName}Mapper.updateById(article);
|
||||||
|
#else
|
||||||
|
${entityName}Mapper.delete(new QueryWrapper<${EntityName}>().eq("id", id));
|
||||||
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.hxkj.admin.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${EntityName}Vo
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ${EntityName}Vo implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.isList==1)
|
||||||
|
#if($column.javaField.equals("createTime") || $column.javaField.equals("updateTime") || $column.javaField.equals("deleteTime"))
|
||||||
|
private String ${column.javaField};
|
||||||
|
#else
|
||||||
|
private ${column.javaType} ${column.javaField};
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue