master
周文涛 2 years ago
parent aa13480348
commit 537759af7e

6
.gitignore vendored

@ -1,5 +1,7 @@
# ---> Java
# Compiled class file
target
target/*
*.class
# Log file
@ -9,6 +11,10 @@
*.ctxt
# Mobile Tools for Java (J2ME)
.idea
.idea/*
.mtj.tmp/
# Package Files #

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.yangliu</groupId>
<artifactId>code-generate</artifactId>
<version>1.0</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<codegenerate.version>1.4.3</codegenerate.version>
<mysql-connector-java.version>8.0.27</mysql-connector-java.version>
</properties>
<dependencies>
<!--日志-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.36</version>
</dependency>
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector-java.version}</version>
</dependency>
<!-- postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.16</version>
</dependency>
<!--模板引擎-->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.32</version>
</dependency>
<!--工具包-->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.0</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.16</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
</dependencies>
</project>

@ -0,0 +1,175 @@
package org.yangliu.codegenerate;
import cn.hutool.core.util.StrUtil;
import com.google.common.base.CaseFormat;
import freemarker.cache.ClassTemplateLoader;
import freemarker.core.XMLOutputFormat;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import org.apache.commons.lang.StringUtils;
import org.yangliu.codegenerate.entity.TableEntityVo;
import org.yangliu.codegenerate.entity.TableVo;
import org.yangliu.codegenerate.util.MarkerGenerate;
import org.yangliu.codegenerate.util.TableFieldUtil;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.util.*;
/**
* @Description
* @Author ZhouWenTao
* @Date 2023/8/13 19:16
*/
public class Main {
//包名
private static String bussi_package = "com.enjoy.oqc";
//生成项目目录
private static String project_path = "E:\\workspace_2\\enjoy\\qms\\enjoy-oqc\\src\\main\\java\\";
private static String project_resource_mapper_path = "E:\\workspace_2\\enjoy\\qms\\enjoy-oqc\\src\\main\\resources\\mapper\\oqc\\";
//实体类模板
private static String bussi_entity_template = "XXXEntity.javai";
private static String bussi_entity_dto_template = "XXXEntityDto.javai";
private static String bussi_entity_vo_template = "XXXEntityVo.javai";
//mapper模板
private static String bussi_mapper_template = "XXXMapper.javai";
//mapper.xml模板
private static String bussi_mapperxml_template = "XXXMapper.xmli";
//service 模板
private static String bussi_service_template = "XXXService.javai";
private static String bussi_serviceimpl_template = "XXXServiceImpl.javai";
//controller
private static String bussi_controller_template = "XXXController.javai";
//模板所在目录
private static String templatepath = "/yangliu/";
private static String author = "yangliu";
// postgresql或mysql
private static String dbType = "postgresql";
public static void main(String[] args) throws Exception {
String driver = "org.postgresql.Driver";
String url = "jdbc:postgresql://10.201.145.19:35432/enjoy-oqc?stringtype=unspecified&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false";
String user = "enjoy";
String password = "Nomi1234";
List<TableEntityVo> tableEntityVoList = printTableStructure(driver, url, user, password, "oqc_project");
generate(bussi_package, "oqc_spot_check_record", "OqcSpotCheckRecord","抽检记录表", tableEntityVoList);
}
/**
*
* @param bussiPackage
* @param tableName
* @param entityName
* @param originalColumns
*/
private static void generate(String bussiPackage, String tableName, String entityName,String description, List<TableEntityVo> originalColumns) {
TableVo tableVo = new TableVo();
tableVo.setFtlDescription(description);
//包名
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("bussiPackage", bussiPackage);//包
dataMap.put("entityPackage", "domain");
dataMap.put("tableName", tableName);//表名称
dataMap.put("tableVo", tableVo);//表属性
//主键
dataMap.put("primaryKeyField", "id");
dataMap.put("entityName", entityName);//实体类名称
dataMap.put("author", author);//作者
dataMap.put("originalColumns", originalColumns);//字段
StringBuffer parsePath = new StringBuffer(project_path);
if (StringUtils.isNotBlank(bussi_package)) {
String[] bussiPackageSplit = bussi_package.split("\\.");
for (String bpackage : bussiPackageSplit) {
parsePath = parsePath.append(bpackage).append(File.separator);
}
}
//生成实体类
String entityParsePath = parsePath + (String) dataMap.get("entityPackage") + File.separator;
MarkerGenerate.generate(templatepath, bussi_entity_template, entityParsePath, entityName + ".java", dataMap);
String dtoParsePath = parsePath + "dto" + File.separator;
MarkerGenerate.generate(templatepath, bussi_entity_dto_template, dtoParsePath, entityName + "Dto.java", dataMap);
String voParsePath = parsePath + "vo" + File.separator;
MarkerGenerate.generate(templatepath, bussi_entity_vo_template, voParsePath, entityName + "Vo.java", dataMap);
//生成Mapper
String mapperParsePath = parsePath + "mapper" + File.separator;
MarkerGenerate.generate(templatepath, bussi_mapper_template, mapperParsePath, entityName + "Mapper.java", dataMap);
//生成Mapper.xml
String mapperXmlParsePath = project_resource_mapper_path;
MarkerGenerate.generate(templatepath, bussi_mapperxml_template, mapperXmlParsePath, entityName + "Mapper.xml", dataMap);
//生成Service
String serviceParsePath = parsePath + "service" + File.separator;
MarkerGenerate.generate(templatepath,bussi_service_template,serviceParsePath,String.format("I%sService.java",entityName),dataMap);
//生成ServiceImpl
String serviceImplParsePath = serviceParsePath+"impl"+File.separator;
MarkerGenerate.generate(templatepath,bussi_serviceimpl_template,serviceImplParsePath,String.format("%sServiceImpl.java",entityName),dataMap);
//生成Controller
String controllerParsePath = parsePath + "controller" + File.separator;
MarkerGenerate.generate(templatepath,bussi_controller_template,controllerParsePath,String.format("%sController.java",entityName),dataMap);
}
/**
*
*
* @param driver driver
* @param url url
* @param user user
* @param password password
* @throws Exception exception
*/
private static List<TableEntityVo> printTableStructure(String driver, String url, String user, String password, String table) throws Exception {
Class.forName(driver);
Connection connection = DriverManager.getConnection(url, user, password);
DatabaseMetaData metaData = connection.getMetaData();
// 获取所有表
//ResultSet tableResultSet = metaData.getTables(null, null, table+"%", new String[]{"TABLE"});
//单表
ResultSet tableResultSet = metaData.getTables(null, null, table, new String[]{"TABLE"});
List<TableEntityVo> tableEntityVoList = new ArrayList<>();
while (tableResultSet.next()) {
String tableName = tableResultSet.getString("TABLE_NAME");
System.out.println("table:" + tableName);
// 获取表字段结构
ResultSet columnResultSet = metaData.getColumns(null, "%", tableName, "%");
while (columnResultSet.next()) {
// 字段名称
String columnName = columnResultSet.getString("COLUMN_NAME");
// 数据类型
String columnType = columnResultSet.getString("TYPE_NAME");
// 字段长度
int datasize = columnResultSet.getInt("COLUMN_SIZE");
// 小数部分位数
int digits = columnResultSet.getInt("DECIMAL_DIGITS");
// 是否可为空 1代表可空 0代表不可为空
int nullable = columnResultSet.getInt("NULLABLE");
// 描述
String remarks = columnResultSet.getString("REMARKS");
System.out.println(columnName + " " + columnType + " " + datasize + " " + digits + " " + nullable + " " + remarks);
//System.out.println("1"+TableFieldUtil.fieldTypeParseJava(dbType,columnType));
String entityField = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, columnName);
tableEntityVoList.add(new TableEntityVo(entityField, TableFieldUtil.fieldTypeParseJava(dbType, columnType), columnType, remarks));
}
System.out.println("=================================");
}
return tableEntityVoList;
}
}

@ -0,0 +1,69 @@
package org.yangliu.codegenerate.entity;
/**
* @Description
* @Author ZhouWenTao
* @Date 2023/8/13 20:44
*/
public class TableEntityVo {
//字段
private String fieldName;
private String fieldType;
//字段类型
private String fieldDbType;
//字段描述
private String filedComment;
public TableEntityVo() {
}
public TableEntityVo(String fieldName,String fieldType,String fieldDbType,String filedComment) {
this.filedComment = filedComment;
this.fieldName = fieldName;
this.fieldType = fieldType;
this.fieldDbType = fieldDbType;
}
public String getFiledComment() {
return filedComment;
}
public void setFiledComment(String filedComment) {
this.filedComment = filedComment;
}
public String getFieldName() {
return fieldName;
}
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
public String getFieldDbType() {
return fieldDbType;
}
public void setFieldDbType(String fieldDbType) {
this.fieldDbType = fieldDbType;
}
public String getFieldType() {
return fieldType;
}
public void setFieldType(String fieldType) {
this.fieldType = fieldType;
}
@Override
public String toString() {
return "TableEntityVo{" +
"fieldName='" + fieldName + '\'' +
", fieldType='" + fieldType + '\'' +
", fieldDbType='" + fieldDbType + '\'' +
", filedComment='" + filedComment + '\'' +
'}';
}
}

@ -0,0 +1,22 @@
package org.yangliu.codegenerate.entity;
import java.io.Serializable;
/**
* @Description
* @Author ZhouWenTao
* @Date 2023/8/13 21:43
*/
public class TableVo implements Serializable {
//表描述
private String ftlDescription;
public String getFtlDescription() {
return ftlDescription;
}
public void setFtlDescription(String ftlDescription) {
this.ftlDescription = ftlDescription;
}
}

@ -0,0 +1,91 @@
package org.yangliu.codegenerate.util;
import freemarker.cache.ClassTemplateLoader;
import freemarker.core.XMLOutputFormat;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import org.apache.commons.lang.StringUtils;
import org.yangliu.codegenerate.Main;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Map;
/**
* @Description
* @Author ZhouWenTao
* @Date 2023/8/13 21:04
*/
public class MarkerGenerate {
public static void generate(String basePackagePath,String templateName,String parsePath,String fileName,Map<String,Object> dataMap) {
String entityName = (String) dataMap.get("entityName");
if (StringUtils.isNotBlank(entityName)) {
dataMap.put("uncap_first",StringUtils.uncapitalize(entityName));
}
// 创建生成文件所在目录
folderCreate(parsePath);
//第一步:创建一个 Configuration 对象,直接 new 一个对象。构造方法的参数就是 freemarker的版本号。
Configuration configuration = new Configuration(Configuration.getVersion());
//第二步:设置模板文件所在的路径。
configuration.setTemplateLoader(new ClassTemplateLoader(Main.class,basePackagePath));
//第三步:设置模板文件使用的字符集。一般就是 utf-8.
configuration.setDefaultEncoding("UTF-8");
configuration.setOutputFormat(XMLOutputFormat.INSTANCE);
//第四步:加载一个模板,创建一个模板对象。
Template template = null;
try {
template = configuration.getTemplate(templateName);
} catch (IOException e) {
e.printStackTrace();
}
String outPut=parsePath+fileName;
FileWriter fileWriter = null;
try {
fileWriter = new FileWriter(outPut);
// 第七步:调用模板对象的 process 方法输出文件。
template.process(dataMap,fileWriter);
// 第八步:关闭流
fileWriter.close();
} catch (IOException e) {
e.printStackTrace();
} catch (TemplateException e) {
e.printStackTrace();
}
}
public static void folderCreate(String folder){
if (StringUtils.isNotBlank(folder)) {
File file =new File(folder);
if (file.exists()) {
if (file.isDirectory()) {
System.out.println("dir exists");
}
else {
System.out.println("the same name file exists, can not create dir");
}
} else {
System.out.println("dir not exists, create it ...");
file.mkdirs();
}
/*String[] folderSpilt = folder.split(File.separator);
StringBuffer sb=new StringBuffer();
for (String f : folderSpilt) {
sb=sb.append(f);
File file=new File(sb.toString());
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
}*/
}
}
}

@ -0,0 +1,37 @@
package org.yangliu.codegenerate.util;
import org.yangliu.codegenerate.util.fieldType.DbColumnType;
import org.yangliu.codegenerate.util.fieldType.MySqlTypeConvert;
import org.yangliu.codegenerate.util.fieldType.PostgreSqlTypeConvert;
import java.util.Arrays;
import java.util.List;
/**
* @Description
* @Author ZhouWenTao
* @Date 2023/8/13 21:54
*/
public class TableFieldUtil {
private static List<String> strArray= Arrays.asList("char","varchar","text","xml");
private static List<String> integerArray= Arrays.asList("int","int2","int4","int8","text","xml");
/**
* java
* @param fieldType
* @return
*/
public static String fieldTypeParseJava(String databaseType,String fieldType){
if (databaseType.equals("mysql")) {
DbColumnType dbColumnType = MySqlTypeConvert.processTypeConvert(fieldType);
return dbColumnType.getType();
}else if(databaseType.equals("postgresql")){
DbColumnType dbColumnType = PostgreSqlTypeConvert.processTypeConvert(fieldType);
return dbColumnType.getType();
}
System.out.println("暂不支持该数据库");
return null;
}
}

@ -0,0 +1,48 @@
package org.yangliu.codegenerate.util.fieldType;
/**
* @Description
* @Author ZhouWenTao
* @Date 2023/8/13 22:01
*/
public enum DbColumnType {
BASE_INT("int", (String)null),
BASE_BOOLEAN("boolean", (String)null),
BASE_FLOAT("float", (String)null),
BASE_DOUBLE("double", (String)null),
STRING("String", (String)null),
LONG("Long", (String)null),
INTEGER("Integer", (String)null),
FLOAT("Float", (String)null),
DOUBLE("Double", (String)null),
BOOLEAN("Boolean", (String)null),
BYTE_ARRAY("byte[]", (String)null),
CHARACTER("Character", (String)null),
OBJECT("Object", (String)null),
DATE("Date", "java.util.Date"),
TIME("Time", "java.sql.Time"),
BLOB("Blob", "java.sql.Blob"),
CLOB("Clob", "java.sql.Clob"),
TIMESTAMP("Timestamp", "java.sql.Timestamp"),
BIG_INTEGER("BigInteger", "java.math.BigInteger"),
BIG_DECIMAL("BigDecimal", "java.math.BigDecimal"),
LOCAL_DATE("LocalDate", "java.time.LocalDate"),
LOCAL_TIME("LocalTime", "java.time.LocalTime"),
LOCAL_DATE_TIME("LocalDateTime", "java.time.LocalDateTime");
private final String type;
private final String pkg;
private DbColumnType(String type, String pkg) {
this.type = type;
this.pkg = pkg;
}
public String getType() {
return this.type;
}
public String getPkg() {
return this.pkg;
}
}

@ -0,0 +1,51 @@
package org.yangliu.codegenerate.util.fieldType;
/**
* @Description mysqljava
* @Author ZhouWenTao
* @Date 2023/8/13 22:00
*/
public class MySqlTypeConvert {
public MySqlTypeConvert() {
}
/**
* mysqljava
* @param fieldType mysql
* @return
*/
public static DbColumnType processTypeConvert(String fieldType) {
String t = fieldType.toLowerCase();
if (!t.contains("char") && !t.contains("text")) {
if (t.contains("bigint")) {
return DbColumnType.LONG;
} else if (t.contains("int")) {
return DbColumnType.INTEGER;
} else if (!t.contains("date") && !t.contains("time") && !t.contains("year")) {
if (t.contains("text")) {
return DbColumnType.STRING;
} else if (t.contains("bit")) {
return DbColumnType.BOOLEAN;
} else if (t.contains("decimal")) {
return DbColumnType.BIG_DECIMAL;
} else if (t.contains("clob")) {
return DbColumnType.CLOB;
} else if (t.contains("blob")) {
return DbColumnType.BLOB;
} else if (t.contains("binary")) {
return DbColumnType.BYTE_ARRAY;
} else if (t.contains("float")) {
return DbColumnType.FLOAT;
} else if (t.contains("double")) {
return DbColumnType.DOUBLE;
} else {
return !t.contains("json") && !t.contains("enum") ? DbColumnType.STRING : DbColumnType.STRING;
}
} else {
return DbColumnType.DATE;
}
} else {
return DbColumnType.STRING;
}
}
}

@ -0,0 +1,47 @@
package org.yangliu.codegenerate.util.fieldType;
/**
* @Description pgsqljava
* @Author ZhouWenTao
* @Date 2023/8/13 22:01
*/
public class PostgreSqlTypeConvert {
public PostgreSqlTypeConvert() {
}
public static DbColumnType processTypeConvert(String fieldType) {
String t = fieldType.toLowerCase();
if (!t.contains("char") && !t.contains("text")) {
if (t.contains("bigint")) {
return DbColumnType.LONG;
} else if (t.contains("int")) {
return DbColumnType.INTEGER;
} else if (!t.contains("date") && !t.contains("time") && !t.contains("year")) {
if (t.contains("text")) {
return DbColumnType.STRING;
} else if (t.contains("bit")) {
return DbColumnType.BOOLEAN;
} else if (t.contains("decimal")) {
return DbColumnType.BIG_DECIMAL;
} else if (t.contains("clob")) {
return DbColumnType.CLOB;
} else if (t.contains("blob")) {
return DbColumnType.BYTE_ARRAY;
} else if (t.contains("float")) {
return DbColumnType.FLOAT;
} else if (t.contains("double")) {
return DbColumnType.DOUBLE;
} else if (!t.contains("json") && !t.contains("enum")) {
return t.contains("boolean") ? DbColumnType.BOOLEAN : DbColumnType.STRING;
} else {
return DbColumnType.STRING;
}
} else {
return DbColumnType.DATE;
}
} else {
return DbColumnType.STRING;
}
}
}

@ -0,0 +1,142 @@
package ${bussiPackage}.controller;
import com.enjoy.common.core.web.controller.BaseController;
import com.enjoy.common.core.web.domain.AjaxResult;
import com.enjoy.common.core.web.page.TableDataInfo;
import com.enjoy.common.log.annotation.Log;
import com.enjoy.common.log.enums.BusinessType;
import ${bussiPackage}.${entityPackage}.${entityName};
import ${bussiPackage}.dto.${entityName}Dto;
import ${bussiPackage}.vo.${entityName}Vo;
import ${bussiPackage}.service.I${entityName}Service;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
/**
* @Description: ${tableVo.ftlDescription}
* @Author: ${author}
* @Date: ${.now?string["yyyy-MM-dd"]}
* @Version: V1.0
*/
@Slf4j
@Api(tags="${tableVo.ftlDescription}")
@RestController
@RequestMapping("/${entityName?uncap_first}")
public class ${entityName}Controller extends BaseController {
@Autowired
private I${entityName}Service ${entityName?uncap_first}Service;
/**
* 分页列表查询
*
* @param ${entityName?uncap_first}
* @param pageNo
* @param pageSize
* @param req
* @return
*/
@ApiOperation(value="${tableVo.ftlDescription}-分页列表查询", notes="${tableVo.ftlDescription}-分页列表查询")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNo", value = "分页参数:当前页", dataType = "String", paramType = "query"),
@ApiImplicitParam(name = "pageSize", value = "分页参数:每页数量", dataType = "String", paramType = "query")
})
@GetMapping(value = "/list")
public TableDataInfo queryPageList(${entityName} ${entityName?uncap_first},
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
HttpServletRequest req) {
startPage();
List<${entityName}> list = ${entityName?uncap_first}Service.list();
return getDataTable(list);
}
/**
* ${tableVo.ftlDescription}-查询所有数据
*/
@ApiOperation("${tableVo.ftlDescription}-查询所有数据")
@GetMapping("/listAll")
public AjaxResult listAll() {
return AjaxResult.success(${entityName?uncap_first}Service.list());
}
/**
* 获取${tableVo.ftlDescription}
*/
@ApiOperation("获取${tableVo.ftlDescription}")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") String id) {
return AjaxResult.success(${entityName?uncap_first}Service.getById(id));
}
/**
* 添加
*
* @param ${entityName?uncap_first}
* @return
*/
@ApiOperation(value="${tableVo.ftlDescription}-添加", notes="${tableVo.ftlDescription}-添加")
@Log(title = "${tableVo.ftlDescription}-添加", businessType = BusinessType.INSERT)
@PostMapping(value = "/add")
public AjaxResult add(@RequestBody ${entityName} ${entityName?uncap_first}) {
${entityName?uncap_first}Service.save(${entityName?uncap_first});
return AjaxResult.success("添加成功");
}
/**
* 编辑
*
* @param ${entityName?uncap_first}
* @return
*/
@Log(title = "${tableVo.ftlDescription}-编辑", businessType = BusinessType.UPDATE)
@ApiOperation(value="${tableVo.ftlDescription}-编辑", notes="${tableVo.ftlDescription}-编辑")
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
public AjaxResult edit(@RequestBody ${entityName} ${entityName?uncap_first}) {
${entityName?uncap_first}Service.updateById(${entityName?uncap_first});
return AjaxResult.success("编辑成功!");
}
/**
* 通过id删除
*
* @param id
* @return
*/
@Log(title = "${tableVo.ftlDescription}-通过id删除", businessType = BusinessType.DELETE)
@ApiOperation(value="${tableVo.ftlDescription}-通过id删除", notes="${tableVo.ftlDescription}-通过id删除")
@DeleteMapping(value = "/delete")
public AjaxResult delete(@RequestParam(name="id",required=true) String id) {
${entityName?uncap_first}Service.removeById(id);
return AjaxResult.success("删除成功!");
}
/**
* 批量删除
*
* @param ids
* @return
*/
@Log(title = "${tableVo.ftlDescription}-批量删除", businessType = BusinessType.DELETE)
@ApiOperation(value="${tableVo.ftlDescription}-批量删除", notes="${tableVo.ftlDescription}-批量删除")
@DeleteMapping(value = "/deleteBatch")
public AjaxResult deleteBatch(@RequestParam(name="ids",required=true) String ids) {
this.${entityName?uncap_first}Service.removeByIds(Arrays.asList(ids.split(",")));
return AjaxResult.success("批量删除成功!");
}
}

@ -0,0 +1,68 @@
package ${bussiPackage}.${entityPackage};
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.enjoy.common.core.web.domain.BaseEntity;
import com.enjoy.common.core.annotation.Excel;
import com.enjoy.common.core.utils.iqc.ExcelImport;
import com.enjoy.common.core.web.domain.BaseEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
* @Description: ${tableVo.ftlDescription}
* @Author: ${author}
* @Date: ${.now?string["yyyy-MM-dd"]}
* @Version: V1.0
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="${tableName}对象", description="${tableVo.ftlDescription}")
@TableName("${tableName}")
public class ${entityName} extends BaseEntity{
private static final long serialVersionUID = 1L;
<#list originalColumns as po>
/**${po.filedComment}*/
<#if po.fieldName == primaryKeyField>
@TableId(type = IdType.ASSIGN_ID)
<#else>
<#if po.fieldType =='Date'>
<#if po.fieldDbType =='date'>
@Excel(name = "${po.filedComment}", width = 15)
@ExcelImport("${po.filedComment}")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern="yyyy-MM-dd")
<#elseif po.fieldDbType =='datetime'>
@Excel(name = "${po.filedComment}", width = 20)
@ExcelImport("${po.filedComment}")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
<#elseif po.fieldDbType =='timestamp'>
@Excel(name = "${po.filedComment}", width = 20)
@ExcelImport("${po.filedComment}")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
</#if>
<#else>
@Excel(name = "${po.filedComment}", width = 15)
@ExcelImport("${po.filedComment}")
</#if>
</#if>
@ApiModelProperty(value = "${po.filedComment}",example = "${po.filedComment}")
<#if po.fieldName == 'delFlag'>
@TableLogic
</#if>
private <#if po.fieldType=='java.sql.Blob'>byte[]<#else>${po.fieldType}</#if> ${po.fieldName};
</#list>
}

@ -0,0 +1,61 @@
package ${bussiPackage}.dto;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.enjoy.common.core.annotation.Excel;
import com.enjoy.common.core.utils.iqc.ExcelImport;
import com.enjoy.common.core.web.domain.BaseEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
* @Description: ${tableVo.ftlDescription}
* @Author: ${author}
* @Date: ${.now?string["yyyy-MM-dd"]}
* @Version: V1.0
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="${tableName}对象", description="${tableVo.ftlDescription}")
public class ${entityName}Dto{
private static final long serialVersionUID = 1L;
<#list originalColumns as po>
/**${po.filedComment}*/
<#if po.fieldName == primaryKeyField>
<#else>
<#if po.fieldType =='Date'>
<#if po.fieldDbType =='date'>
@Excel(name = "${po.filedComment}", width = 15)
@ExcelImport("${po.filedComment}")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern="yyyy-MM-dd")
<#elseif po.fieldDbType =='datetime'>
@Excel(name = "${po.filedComment}", width = 20)
@ExcelImport("${po.filedComment}")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
<#elseif po.fieldDbType =='timestamp'>
@Excel(name = "${po.filedComment}", width = 20)
@ExcelImport("${po.filedComment}")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
</#if>
<#else>
@Excel(name = "${po.filedComment}", width = 15)
@ExcelImport("${po.filedComment}")
</#if>
</#if>
@ApiModelProperty(value = "${po.filedComment}",example = "${po.filedComment}")
private <#if po.fieldType=='java.sql.Blob'>byte[]<#else>${po.fieldType}</#if> ${po.fieldName};
</#list>
}

@ -0,0 +1,61 @@
package ${bussiPackage}.vo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.enjoy.common.core.annotation.Excel;
import com.enjoy.common.core.utils.iqc.ExcelImport;
import com.enjoy.common.core.web.domain.BaseEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
* @Description: ${tableVo.ftlDescription}
* @Author: ${author}
* @Date: ${.now?string["yyyy-MM-dd"]}
* @Version: V1.0
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="${tableName}对象", description="${tableVo.ftlDescription}")
public class ${entityName}Vo{
private static final long serialVersionUID = 1L;
<#list originalColumns as po>
/**${po.filedComment}*/
<#if po.fieldName == primaryKeyField>
<#else>
<#if po.fieldType =='Date'>
<#if po.fieldDbType =='date'>
@Excel(name = "${po.filedComment}", width = 15)
@ExcelImport("${po.filedComment}")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern="yyyy-MM-dd")
<#elseif po.fieldDbType =='datetime'>
@Excel(name = "${po.filedComment}", width = 20)
@ExcelImport("${po.filedComment}")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
<#elseif po.fieldDbType =='timestamp'>
@Excel(name = "${po.filedComment}", width = 20)
@ExcelImport("${po.filedComment}")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
</#if>
<#else>
@Excel(name = "${po.filedComment}", width = 15)
@ExcelImport("${po.filedComment}")
</#if>
</#if>
@ApiModelProperty(value = "${po.filedComment}",example = "${po.filedComment}")
private <#if po.fieldType=='java.sql.Blob'>byte[]<#else>${po.fieldType}</#if> ${po.fieldName};
</#list>
}

@ -0,0 +1,16 @@
package ${bussiPackage}.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import ${bussiPackage}.${entityPackage}.${entityName};
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @Description: ${tableVo.ftlDescription}
* @Author: ${author}
* @Date: ${.now?string["yyyy-MM-dd"]}
* @Version: V1.0
*/
public interface ${entityName}Mapper extends BaseMapper<${entityName}> {
}

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${bussiPackage}.mapper.${entityName}Mapper">
</mapper>

@ -0,0 +1,14 @@
package ${bussiPackage}.service;
import ${bussiPackage}.${entityPackage}.${entityName};
import com.baomidou.mybatisplus.extension.service.IService;
/**
* @Description: ${tableVo.ftlDescription}
* @Author: ${author}
* @Date: ${.now?string["yyyy-MM-dd"]}
* @Version: V1.0
*/
public interface I${entityName}Service extends IService<${entityName}> {
}

@ -0,0 +1,19 @@
package ${bussiPackage}.service.impl;
import ${bussiPackage}.${entityPackage}.${entityName};
import ${bussiPackage}.mapper.${entityName}Mapper;
import ${bussiPackage}.service.I${entityName}Service;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
/**
* @Description: ${tableVo.ftlDescription}
* @Author: ${author}
* @Date: ${.now?string["yyyy-MM-dd"]}
* @Version: V1.0
*/
@Service
public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, ${entityName}> implements I${entityName}Service {
}
Loading…
Cancel
Save