init
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<artifactId>codegen-service-parent</artifactId>
|
||||
<groupId>com.platform</groupId>
|
||||
<version>0.4.x</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>0.4.x</version>
|
||||
<artifactId>codegen-service-api</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-micro-spring-boot-starter</artifactId>
|
||||
<version>${knife4j.version}</version>
|
||||
</dependency>
|
||||
<!--feign 依赖-->
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-okhttp</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.platform</groupId>
|
||||
<artifactId>common-core</artifactId>
|
||||
<version>0.4.x</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-web</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,66 @@
|
||||
package cn.datax.service.codegen.api.dto;
|
||||
|
||||
import cn.datax.common.validate.ValidationGroups;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class GenColumnDto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "列名称")
|
||||
@NotBlank(message = "列名称不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String columnName;
|
||||
@ApiModelProperty(value = "列描述")
|
||||
@NotBlank(message = "列描述不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String columnComment;
|
||||
@ApiModelProperty(value = "列类型")
|
||||
@NotBlank(message = "列类型不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String columnType;
|
||||
@ApiModelProperty(value = "JAVA类型")
|
||||
@NotBlank(message = "JAVA类型不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String javaType;
|
||||
@ApiModelProperty(value = "JAVA字段名")
|
||||
@NotBlank(message = "JAVA字段名不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String javaField;
|
||||
@ApiModelProperty(value = "列长度")
|
||||
private String columnLength;
|
||||
@ApiModelProperty(value = "列小数位数")
|
||||
private String columnScale;
|
||||
@ApiModelProperty(value = "是否主键(0否1是)")
|
||||
@NotNull(message = "是否主键不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String isPk;
|
||||
@ApiModelProperty(value = "是否自增(0否1是)")
|
||||
@NotNull(message = "是否自增不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String isIncrement;
|
||||
@ApiModelProperty(value = "是否必填(0否1是)")
|
||||
@NotNull(message = "是否必填不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String isRequired;
|
||||
@ApiModelProperty(value = "是否为插入字段(0否1是)")
|
||||
@NotNull(message = "是否为插入字段不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String isInsert;
|
||||
@ApiModelProperty(value = "是否编辑字段(0否1是)")
|
||||
@NotNull(message = "是否编辑字段不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String isEdit;
|
||||
@ApiModelProperty(value = "是否列表字段(0否1是)")
|
||||
@NotNull(message = "是否列表字段不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String isList;
|
||||
@ApiModelProperty(value = "是否查询字段(0否1是)")
|
||||
@NotNull(message = "是否查询字段不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String isQuery;
|
||||
@ApiModelProperty(value = "查询方式(EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围)")
|
||||
@NotBlank(message = "查询方式不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String queryType;
|
||||
@ApiModelProperty(value = "显示类型(input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件)")
|
||||
@NotBlank(message = "显示类型不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String htmlType;
|
||||
@ApiModelProperty(value = "字典类型")
|
||||
private String dictType;
|
||||
@ApiModelProperty(value = "排序")
|
||||
private Integer sort;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package cn.datax.service.codegen.api.dto;
|
||||
|
||||
import cn.datax.common.validate.ValidationGroups;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 代码生成信息表 实体DTO
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-19
|
||||
*/
|
||||
@ApiModel(value = "代码生成信息表Model")
|
||||
@Data
|
||||
public class GenTableDto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "主键ID")
|
||||
@NotBlank(message = "主键ID不能为空", groups = {ValidationGroups.Update.class})
|
||||
private String id;
|
||||
@ApiModelProperty(value = "表名称")
|
||||
@NotBlank(message = "表名称不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String tableName;
|
||||
@ApiModelProperty(value = "表描述")
|
||||
@NotBlank(message = "表描述不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String tableComment;
|
||||
@ApiModelProperty(value = "实体类名称")
|
||||
@NotBlank(message = "实体类名称不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String className;
|
||||
@ApiModelProperty(value = "生成包路径")
|
||||
@NotBlank(message = "生成包路径不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String packageName;
|
||||
@ApiModelProperty(value = "生成模块名")
|
||||
@NotBlank(message = "生成模块名不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String moduleName;
|
||||
@ApiModelProperty(value = "生成业务名")
|
||||
@NotBlank(message = "生成业务名不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String businessName;
|
||||
@ApiModelProperty(value = "生成功能名")
|
||||
@NotBlank(message = "生成功能名不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String functionName;
|
||||
@ApiModelProperty(value = "生成功能作者")
|
||||
@NotBlank(message = "生成功能作者不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String functionAuthor;
|
||||
@ApiModelProperty(value = "主键信息")
|
||||
private GenColumnDto pkColumn;
|
||||
@Valid
|
||||
@NotEmpty(message = "表字段不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
@Size(min = 1, message="表字段长度不能少于{min}位")
|
||||
private List<GenColumnDto> columns;
|
||||
@ApiModelProperty(value = "状态")
|
||||
@NotNull(message = "状态不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String status;
|
||||
@ApiModelProperty(value = "备注")
|
||||
private String remark;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package cn.datax.service.codegen.api.entity;
|
||||
|
||||
import cn.datax.common.base.BaseEntity;
|
||||
import cn.datax.service.codegen.api.dto.GenColumnDto;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 代码生成信息表
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-19
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
@TableName("gen_table")
|
||||
public class GenTableEntity extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
/**
|
||||
* 表名称
|
||||
*/
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 表描述
|
||||
*/
|
||||
private String tableComment;
|
||||
|
||||
/**
|
||||
* 实体类名称
|
||||
*/
|
||||
private String className;
|
||||
|
||||
/**
|
||||
* 生成包路径
|
||||
*/
|
||||
private String packageName;
|
||||
|
||||
/**
|
||||
* 生成模块名
|
||||
*/
|
||||
private String moduleName;
|
||||
|
||||
/**
|
||||
* 生成业务名
|
||||
*/
|
||||
private String businessName;
|
||||
|
||||
/**
|
||||
* 生成功能名
|
||||
*/
|
||||
private String functionName;
|
||||
|
||||
/**
|
||||
* 生成功能作者
|
||||
*/
|
||||
private String functionAuthor;
|
||||
|
||||
/**
|
||||
* 表字段
|
||||
*/
|
||||
@TableField(value = "column_json", typeHandler = JacksonTypeHandler.class)
|
||||
private List<GenColumnDto> columns;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.datax.service.codegen.api.query;
|
||||
|
||||
import cn.datax.common.base.BaseQueryParams;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 代码生成信息表 查询实体
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-19
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class GenTableQuery extends BaseQueryParams {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package cn.datax.service.codegen.api.vo;
|
||||
|
||||
import cn.datax.service.codegen.api.dto.GenColumnDto;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 代码生成信息表 实体VO
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-19
|
||||
*/
|
||||
@Data
|
||||
public class GenTableVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
private String id;
|
||||
private String status;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime createTime;
|
||||
private String remark;
|
||||
private String tableName;
|
||||
private String tableComment;
|
||||
private String className;
|
||||
private String packageName;
|
||||
private String moduleName;
|
||||
private String businessName;
|
||||
private String functionName;
|
||||
private String functionAuthor;
|
||||
private List<GenColumnDto> columns;
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<artifactId>codegen-service-parent</artifactId>
|
||||
<groupId>com.platform</groupId>
|
||||
<version>0.4.x</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>0.4.x</version>
|
||||
<artifactId>codegen-service</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!--web 模块-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-undertow</artifactId>
|
||||
</dependency>
|
||||
<!--配置中心客户端 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct</artifactId>
|
||||
<version>1.4.2.Final</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct-processor</artifactId>
|
||||
<version>1.4.2.Final</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.platform</groupId>
|
||||
<artifactId>common-mybatis</artifactId>
|
||||
<version>0.4.x</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.platform</groupId>
|
||||
<artifactId>common-redis</artifactId>
|
||||
<version>0.4.x</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.platform</groupId>
|
||||
<artifactId>common-security</artifactId>
|
||||
<version>0.4.x</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.platform</groupId>
|
||||
<artifactId>common-log</artifactId>
|
||||
<version>0.4.x</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.platform</groupId>
|
||||
<artifactId>codegen-service-api</artifactId>
|
||||
<version>0.4.x</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
<version>3.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-engine-core</artifactId>
|
||||
<version>2.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,17 @@
|
||||
package cn.datax.service.codegen;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.cloud.client.SpringCloudApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
@EnableFeignClients(basePackages = {"cn.datax.service.system.api.feign"})
|
||||
@SpringBootApplication
|
||||
public class DataxCodeGenApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DataxCodeGenApplication.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package cn.datax.service.codegen.config;
|
||||
|
||||
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
|
||||
import com.baomidou.dynamic.datasource.aop.DynamicDataSourceAnnotationAdvisor;
|
||||
import com.baomidou.dynamic.datasource.aop.DynamicDataSourceAnnotationInterceptor;
|
||||
import com.baomidou.dynamic.datasource.processor.DsProcessor;
|
||||
import com.baomidou.dynamic.datasource.provider.DynamicDataSourceProvider;
|
||||
import com.baomidou.dynamic.datasource.provider.YmlDynamicDataSourceProvider;
|
||||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty;
|
||||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceCreatorAutoConfiguration;
|
||||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties;
|
||||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.druid.DruidDynamicDataSourceConfiguration;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.Role;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 动态数据源核心自动配置类
|
||||
* @author AllDataDC
|
||||
* @date 2023/03/17
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@AllArgsConstructor
|
||||
@EnableConfigurationProperties(DynamicDataSourceProperties.class)
|
||||
@AutoConfigureBefore(DataSourceAutoConfiguration.class)
|
||||
@Import(value = {DruidDynamicDataSourceConfiguration.class, DynamicDataSourceCreatorAutoConfiguration.class})
|
||||
@ConditionalOnProperty(prefix = DynamicDataSourceProperties.PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
public class DynamicDSConfiguration {
|
||||
|
||||
private final DynamicDataSourceProperties properties;
|
||||
|
||||
//读取多数据源配置,注入到spring容器中
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public DynamicDataSourceProvider dynamicDataSourceProvider() {
|
||||
Map<String, DataSourceProperty> datasourceMap = properties.getDatasource();
|
||||
return new YmlDynamicDataSourceProvider(datasourceMap);
|
||||
}
|
||||
|
||||
//注册自己的动态多数据源DataSource
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public DataSource dataSource(DynamicDataSourceProvider dynamicDataSourceProvider) {
|
||||
DynamicRoutingDataSource dataSource = new DynamicRoutingDataSource();
|
||||
dataSource.setPrimary(properties.getPrimary());
|
||||
dataSource.setStrict(properties.getStrict());
|
||||
dataSource.setStrategy(properties.getStrategy());
|
||||
dataSource.setProvider(dynamicDataSourceProvider);
|
||||
dataSource.setP6spy(properties.getP6spy());
|
||||
dataSource.setSeata(properties.getSeata());
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
//AOP切面,对DS注解过的方法进行增强,达到切换数据源的目的
|
||||
@Role(value = BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public DynamicDataSourceAnnotationAdvisor dynamicDatasourceAnnotationAdvisor(DsProcessor dsProcessor) {
|
||||
DynamicDataSourceAnnotationInterceptor interceptor = new DynamicDataSourceAnnotationInterceptor(properties.isAllowedPublicOnly(), dsProcessor);
|
||||
DynamicDataSourceAnnotationAdvisor advisor = new DynamicDataSourceAnnotationAdvisor(interceptor);
|
||||
advisor.setOrder(properties.getOrder());
|
||||
return advisor;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package cn.datax.service.codegen.config;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class StartedUpRunner implements ApplicationRunner {
|
||||
|
||||
private final ConfigurableApplicationContext context;
|
||||
private final Environment environment;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
if (context.isActive()) {
|
||||
String banner = "-----------------------------------------\n" +
|
||||
"服务启动成功,时间:" + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now()) + "\n" +
|
||||
"服务名称:" + environment.getProperty("spring.application.name") + "\n" +
|
||||
"端口号:" + environment.getProperty("server.port") + "\n" +
|
||||
"-----------------------------------------";
|
||||
System.out.println(banner);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package cn.datax.service.codegen.config;
|
||||
|
||||
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
|
||||
import springfox.documentation.builders.*;
|
||||
import springfox.documentation.schema.ModelRef;
|
||||
import springfox.documentation.service.*;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnProperty(prefix = "swagger", name = "enable", havingValue = "true")
|
||||
@EnableConfigurationProperties(SwaggerProperties.class)
|
||||
@EnableSwagger2
|
||||
@EnableKnife4j
|
||||
@Import(BeanValidatorPluginsConfiguration.class)
|
||||
public class SwaggerConfig {
|
||||
|
||||
@Autowired
|
||||
private SwaggerProperties swaggerProperties;
|
||||
|
||||
/**
|
||||
* 创建API应用
|
||||
* apiInfo() 增加API相关信息
|
||||
* 通过select()函数返回一个ApiSelectorBuilder实例,用来控制哪些接口暴露给Swagger来展现,
|
||||
* 本例采用指定扫描的包路径来定义指定要建立API的目录。
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Docket createRestApi(){
|
||||
//版本类型是swagger2
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
//通过调用自定义方法apiInfo,获得文档的主要信息
|
||||
.apiInfo(apiInfo())
|
||||
//设置全局参数
|
||||
.globalOperationParameters(globalParamBuilder())
|
||||
//设置全局响应参数
|
||||
.globalResponseMessage(RequestMethod.GET,responseBuilder())
|
||||
.globalResponseMessage(RequestMethod.POST,responseBuilder())
|
||||
.globalResponseMessage(RequestMethod.PUT,responseBuilder())
|
||||
.globalResponseMessage(RequestMethod.DELETE,responseBuilder())
|
||||
.select()
|
||||
//扫描该包下面的API注解
|
||||
.apis(RequestHandlerSelectors.basePackage(swaggerProperties.getBasePackage()))
|
||||
.paths(PathSelectors.any())
|
||||
.build()
|
||||
//设置安全认证
|
||||
;
|
||||
}
|
||||
/**
|
||||
* 创建该API的基本信息(这些基本信息会展现在文档页面中)
|
||||
* 访问地址:http://项目实际地址/swagger-ui.html
|
||||
* @return
|
||||
*/
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title(swaggerProperties.getTitle())
|
||||
.description(swaggerProperties.getDescription())
|
||||
.termsOfServiceUrl(swaggerProperties.getTermsOfServiceUrl())
|
||||
.version(swaggerProperties.getVersion())
|
||||
.contact(new Contact(swaggerProperties.getContact().getName(), swaggerProperties.getContact().getUrl(), swaggerProperties.getContact().getEmail()))
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全认证参数
|
||||
* @return
|
||||
*/
|
||||
private List<ApiKey> security() {
|
||||
List<ApiKey> apiKeys = new ArrayList<>();
|
||||
apiKeys.add(new ApiKey("Authorization", "Authorization", "header"));
|
||||
return apiKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建全局参数列表
|
||||
* @return
|
||||
*/
|
||||
private List<Parameter> globalParamBuilder(){
|
||||
List<Parameter> pars = new ArrayList<>();
|
||||
pars.add(parameterBuilder("Authorization","令牌","string","header",false).build());
|
||||
return pars;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建参数
|
||||
* @return
|
||||
*/
|
||||
private ParameterBuilder parameterBuilder(String name, String desc, String type, String parameterType, boolean required) {
|
||||
ParameterBuilder tokenPar = new ParameterBuilder();
|
||||
tokenPar.name(name).description(desc).modelRef(new ModelRef(type)).parameterType(parameterType).required(required).build();
|
||||
return tokenPar;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建全局响应值
|
||||
* @return
|
||||
*/
|
||||
private List<ResponseMessage> responseBuilder() {
|
||||
List<ResponseMessage> responseMessageList = new ArrayList<>();
|
||||
responseMessageList.add(new ResponseMessageBuilder().code(200).message("响应成功").build());
|
||||
responseMessageList.add(new ResponseMessageBuilder().code(500).message("服务器内部错误").build());
|
||||
return responseMessageList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package cn.datax.service.codegen.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties(ignoreUnknownFields = false, prefix = "swagger")
|
||||
public class SwaggerProperties {
|
||||
|
||||
private Boolean enable;
|
||||
private String title;
|
||||
private String description;
|
||||
private String version;
|
||||
private String termsOfServiceUrl;
|
||||
private String basePackage;
|
||||
private Contact contact;
|
||||
|
||||
public Boolean getEnable() {
|
||||
return enable;
|
||||
}
|
||||
|
||||
public void setEnable(Boolean enable) {
|
||||
this.enable = enable;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getTermsOfServiceUrl() {
|
||||
return termsOfServiceUrl;
|
||||
}
|
||||
|
||||
public void setTermsOfServiceUrl(String termsOfServiceUrl) {
|
||||
this.termsOfServiceUrl = termsOfServiceUrl;
|
||||
}
|
||||
|
||||
public String getBasePackage() {
|
||||
return basePackage;
|
||||
}
|
||||
|
||||
public void setBasePackage(String basePackage) {
|
||||
this.basePackage = basePackage;
|
||||
}
|
||||
|
||||
public Contact getContact() {
|
||||
return contact;
|
||||
}
|
||||
|
||||
public void setContact(Contact contact) {
|
||||
this.contact = contact;
|
||||
}
|
||||
|
||||
public static class Contact {
|
||||
private String name;
|
||||
private String url;
|
||||
private String email;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package cn.datax.service.codegen.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity(debug = false)
|
||||
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http.csrf().disable().authorizeRequests().anyRequest().permitAll().and().logout().permitAll();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package cn.datax.service.codegen.controller;
|
||||
|
||||
import cn.datax.common.base.BaseController;
|
||||
import cn.datax.common.core.JsonPage;
|
||||
import cn.datax.common.core.R;
|
||||
import cn.datax.common.validate.ValidationGroups;
|
||||
import cn.datax.service.codegen.api.dto.GenTableDto;
|
||||
import cn.datax.service.codegen.api.entity.GenTableEntity;
|
||||
import cn.datax.service.codegen.mapstruct.GenTableMapper;
|
||||
import cn.datax.service.codegen.api.query.GenTableQuery;
|
||||
import cn.datax.service.codegen.service.GenTableService;
|
||||
import cn.datax.service.codegen.api.vo.GenTableVo;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 代码生成信息表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-19
|
||||
*/
|
||||
@Api(tags = {"代码生成信息表"})
|
||||
@RestController
|
||||
@RequestMapping("/codegen/genTable")
|
||||
public class GenTableController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private GenTableService genTableService;
|
||||
|
||||
@Autowired
|
||||
private GenTableMapper genTableMapper;
|
||||
|
||||
/**
|
||||
* 通过ID查询信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "获取详细信息", notes = "根据url的id来获取详细信息")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@GetMapping("/{id}")
|
||||
public R getGenTableById(@PathVariable String id) {
|
||||
GenTableEntity genTableEntity = genTableService.getGenTableById(id);
|
||||
return R.ok().setData(genTableMapper.toVO(genTableEntity));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询信息
|
||||
*
|
||||
* @param genTableQuery
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "分页查询", notes = "")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "genTableQuery", value = "查询实体genTableQuery", required = true, dataTypeClass = GenTableQuery.class)
|
||||
})
|
||||
@GetMapping("/page")
|
||||
public R getGenTablePage(GenTableQuery genTableQuery) {
|
||||
QueryWrapper<GenTableEntity> queryWrapper = new QueryWrapper<>();
|
||||
IPage<GenTableEntity> page = genTableService.page(new Page<>(genTableQuery.getPageNum(), genTableQuery.getPageSize()), queryWrapper);
|
||||
List<GenTableVo> collect = page.getRecords().stream().map(genTableMapper::toVO).collect(Collectors.toList());
|
||||
JsonPage<GenTableVo> jsonPage = new JsonPage<>(page.getCurrent(), page.getSize(), page.getTotal(), collect);
|
||||
return R.ok().setData(jsonPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param genTable
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "添加信息", notes = "根据genTable对象添加信息")
|
||||
@ApiImplicitParam(name = "genTable", value = "详细实体genTable", required = true, dataType = "GenTableDto")
|
||||
@PostMapping()
|
||||
public R saveGenTable(@RequestBody @Validated({ValidationGroups.Insert.class}) GenTableDto genTable) {
|
||||
genTableService.saveGenTable(genTable);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param genTable
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "修改信息", notes = "根据url的id来指定修改对象,并根据传过来的信息来修改详细信息")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path"),
|
||||
@ApiImplicitParam(name = "genTable", value = "详细实体genTable", required = true, dataType = "GenTableDto")
|
||||
})
|
||||
@PutMapping("/{id}")
|
||||
public R updateGenTable(@PathVariable String id, @RequestBody @Validated({ValidationGroups.Update.class}) GenTableDto genTable) {
|
||||
genTableService.updateGenTable(genTable);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "删除", notes = "根据url的id来指定删除对象")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@DeleteMapping("/{id}")
|
||||
public R deleteGenTableById(@PathVariable String id) {
|
||||
genTableService.deleteGenTableById(id);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package cn.datax.service.codegen.controller;
|
||||
|
||||
import cn.datax.common.base.BaseController;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/inner")
|
||||
public class InnerController extends BaseController {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package cn.datax.service.codegen.dao;
|
||||
|
||||
import cn.datax.common.base.BaseDao;
|
||||
import cn.datax.service.codegen.api.entity.GenTableEntity;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 代码生成信息表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-19
|
||||
*/
|
||||
@Mapper
|
||||
public interface GenTableDao extends BaseDao<GenTableEntity> {
|
||||
|
||||
@Override
|
||||
GenTableEntity selectById(Serializable id);
|
||||
|
||||
@Override
|
||||
<E extends IPage<GenTableEntity>> E selectPage(E page, @Param(Constants.WRAPPER) Wrapper<GenTableEntity> queryWrapper);
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package cn.datax.service.codegen.engine;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.generator.config.ConstVal;
|
||||
import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
|
||||
import com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine;
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.apache.velocity.app.VelocityEngine;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
public class VelocityTemplateEngine extends AbstractTemplateEngine {
|
||||
private static final String DOT_VM = ".vm";
|
||||
private VelocityEngine velocityEngine;
|
||||
|
||||
public VelocityTemplateEngine() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public VelocityTemplateEngine init(ConfigBuilder configBuilder) {
|
||||
super.init(configBuilder);
|
||||
if (null == this.velocityEngine) {
|
||||
Properties p = new Properties();
|
||||
p.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
|
||||
p.setProperty("file.resource.loader.path", "");
|
||||
p.setProperty("UTF-8", ConstVal.UTF8);
|
||||
p.setProperty("input.encoding", ConstVal.UTF8);
|
||||
p.setProperty("file.resource.loader.unicode", "true");
|
||||
this.velocityEngine = new VelocityEngine(p);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writer(Map<String, Object> objectMap, String templatePath, String outputFile) throws Exception {
|
||||
if (!StringUtils.isBlank(templatePath)) {
|
||||
Template template = this.velocityEngine.getTemplate(templatePath, ConstVal.UTF8);
|
||||
FileOutputStream fos = new FileOutputStream(outputFile);
|
||||
Throwable var6 = null;
|
||||
|
||||
String entity = objectMap.get("entity").toString();
|
||||
objectMap.put("className", entity.replace("Entity", ""));
|
||||
objectMap.put("classNameLower", StrUtil.lowerFirst(entity.replace("Entity", "")));
|
||||
try {
|
||||
OutputStreamWriter ow = new OutputStreamWriter(fos, ConstVal.UTF8);
|
||||
Throwable var8 = null;
|
||||
|
||||
try {
|
||||
BufferedWriter writer = new BufferedWriter(ow);
|
||||
Throwable var10 = null;
|
||||
|
||||
try {
|
||||
template.merge(new VelocityContext(objectMap), writer);
|
||||
} catch (Throwable var54) {
|
||||
var10 = var54;
|
||||
throw var54;
|
||||
} finally {
|
||||
if (writer != null) {
|
||||
if (var10 != null) {
|
||||
try {
|
||||
writer.close();
|
||||
} catch (Throwable var53) {
|
||||
var10.addSuppressed(var53);
|
||||
}
|
||||
} else {
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Throwable var56) {
|
||||
var8 = var56;
|
||||
throw var56;
|
||||
} finally {
|
||||
if (ow != null) {
|
||||
if (var8 != null) {
|
||||
try {
|
||||
ow.close();
|
||||
} catch (Throwable var52) {
|
||||
var8.addSuppressed(var52);
|
||||
}
|
||||
} else {
|
||||
ow.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Throwable var58) {
|
||||
var6 = var58;
|
||||
throw var58;
|
||||
} finally {
|
||||
if (fos != null) {
|
||||
if (var6 != null) {
|
||||
try {
|
||||
fos.close();
|
||||
} catch (Throwable var51) {
|
||||
var6.addSuppressed(var51);
|
||||
}
|
||||
} else {
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
logger.debug("模板:" + templatePath + "; 文件:" + outputFile);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String templateFilePath(String filePath) {
|
||||
return null != filePath && !filePath.contains(".vm") ? filePath + ".vm" : filePath;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.datax.service.codegen.mapstruct;
|
||||
|
||||
import cn.datax.common.mapstruct.EntityMapper;
|
||||
import cn.datax.service.codegen.api.dto.GenTableDto;
|
||||
import cn.datax.service.codegen.api.entity.GenTableEntity;
|
||||
import cn.datax.service.codegen.api.vo.GenTableVo;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 代码生成信息表 Mapper 实体映射
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-19
|
||||
*/
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface GenTableMapper extends EntityMapper<GenTableDto, GenTableEntity, GenTableVo> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package cn.datax.service.codegen.service;
|
||||
|
||||
import cn.datax.common.base.BaseService;
|
||||
import cn.datax.service.codegen.api.dto.GenTableDto;
|
||||
import cn.datax.service.codegen.api.entity.GenTableEntity;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 代码生成信息表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-19
|
||||
*/
|
||||
public interface GenTableService extends BaseService<GenTableEntity> {
|
||||
|
||||
void saveGenTable(GenTableDto genTable);
|
||||
|
||||
void updateGenTable(GenTableDto genTable);
|
||||
|
||||
GenTableEntity getGenTableById(String id);
|
||||
|
||||
void deleteGenTableById(String id);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package cn.datax.service.codegen.service.impl;
|
||||
|
||||
import cn.datax.common.base.BaseServiceImpl;
|
||||
import cn.datax.service.codegen.dao.GenTableDao;
|
||||
import cn.datax.service.codegen.api.dto.GenTableDto;
|
||||
import cn.datax.service.codegen.api.entity.GenTableEntity;
|
||||
import cn.datax.service.codegen.mapstruct.GenTableMapper;
|
||||
import cn.datax.service.codegen.service.GenTableService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 代码生成信息表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-19
|
||||
*/
|
||||
@Service
|
||||
public class GenTableServiceImpl extends BaseServiceImpl<GenTableDao, GenTableEntity> implements GenTableService {
|
||||
|
||||
@Autowired
|
||||
private GenTableDao genTableDao;
|
||||
|
||||
@Autowired
|
||||
private GenTableMapper genTableMapper;
|
||||
|
||||
@Override
|
||||
public void saveGenTable(GenTableDto genTableDto) {
|
||||
GenTableEntity genTable = genTableMapper.toEntity(genTableDto);
|
||||
genTableDao.insert(genTable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateGenTable(GenTableDto genTableDto) {
|
||||
GenTableEntity genTable = genTableMapper.toEntity(genTableDto);
|
||||
genTableDao.updateById(genTable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenTableEntity getGenTableById(String id) {
|
||||
GenTableEntity genTableEntity = super.getById(id);
|
||||
return genTableEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteGenTableById(String id) {
|
||||
genTableDao.deleteById(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
package cn.datax.service.codegen.utils;
|
||||
|
||||
import cn.datax.service.codegen.engine.VelocityTemplateEngine;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.generator.AutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.InjectionConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.*;
|
||||
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public class Generate {
|
||||
|
||||
// public static void main(String[] args) throws InterruptedException {
|
||||
//// DefaultIdentifierGenerator generator = new DefaultIdentifierGenerator();
|
||||
//// for (int i = 0; i < 10; i++) {
|
||||
//// Thread.sleep(new Random().nextInt(1000 - 500 + 1) + 500);
|
||||
//// System.out.println(generator.nextId(null));
|
||||
//// }
|
||||
// generateByTables("F://code", "visual", "cn.datax.service.data", "visual_", new String[]{"visual_board_chart"});
|
||||
// }
|
||||
|
||||
/**
|
||||
* 根据表自动生成
|
||||
*
|
||||
* @param moduleName 模块名
|
||||
* @param parentName 包名
|
||||
* @param tableNames 表名
|
||||
*/
|
||||
private static void generateByTables(String projectPath, String moduleName, String parentName, String tablePrefix, String[] tableNames) {
|
||||
//配置数据源
|
||||
DataSourceConfig dataSourceConfig = getDataSourceConfig();
|
||||
//全局变量配置
|
||||
GlobalConfig globalConfig = getGlobalConfig(projectPath);
|
||||
//包名配置
|
||||
PackageConfig packageConfig = getPackageConfig(moduleName, parentName);
|
||||
// 策略配置
|
||||
StrategyConfig strategyConfig = getStrategyConfig(tablePrefix, tableNames);
|
||||
//自定义配置
|
||||
InjectionConfig injectionConfig = getInjectionConfig(projectPath, moduleName, parentName);
|
||||
//配置模板
|
||||
TemplateConfig templateConfig = getTemplateConfig();
|
||||
//自动生成
|
||||
atuoGenerator(dataSourceConfig, strategyConfig, globalConfig, packageConfig, injectionConfig, templateConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 集成
|
||||
*
|
||||
* @param dataSourceConfig 数据源配置
|
||||
* @param strategyConfig 策略配置
|
||||
* @param globalConfig 全局变量配置
|
||||
* @param packageConfig 包名配置
|
||||
* @param injectionConfig 自定义配置
|
||||
* @param templateConfig 模板配置
|
||||
*/
|
||||
private static void atuoGenerator(DataSourceConfig dataSourceConfig, StrategyConfig strategyConfig, GlobalConfig globalConfig, PackageConfig packageConfig,
|
||||
InjectionConfig injectionConfig, TemplateConfig templateConfig) {
|
||||
new AutoGenerator()
|
||||
.setGlobalConfig(globalConfig)
|
||||
.setDataSource(dataSourceConfig)
|
||||
.setStrategy(strategyConfig)
|
||||
.setPackageInfo(packageConfig)
|
||||
.setCfg(injectionConfig)
|
||||
.setTemplate(templateConfig)
|
||||
.setTemplateEngine(new VelocityTemplateEngine())
|
||||
.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义配置 可以在 VM 中使用 cfg.abc
|
||||
*
|
||||
* @return templateConfig
|
||||
*/
|
||||
private static InjectionConfig getInjectionConfig(String projectPath, String moduleName, String parentName) {
|
||||
InjectionConfig cfg = new InjectionConfig() {
|
||||
@Override
|
||||
public void initMap() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("PackageParent", parentName);
|
||||
this.setMap(map);
|
||||
}
|
||||
};
|
||||
List<FileOutConfig> focList = new ArrayList<>();
|
||||
focList.add(new FileOutConfig("/templates/mapper.xml.vm") {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return projectPath + "/src/main/resources/mapper/" + tableInfo.getEntityName().replace("Entity", "Mapper") + StringPool.DOT_XML;
|
||||
}
|
||||
});
|
||||
focList.add(new FileOutConfig("/templates/entity.java.vm") {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return projectPath + "/src/main/java/"+ parentName.replace(".", File.separator) + File.separator + moduleName + "/api/entity/" + tableInfo.getEntityName() + StringPool.DOT_JAVA;
|
||||
}
|
||||
});
|
||||
focList.add(new FileOutConfig("/templates/mapstruct.java.vm") {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return projectPath + "/src/main/java/"+ parentName.replace(".", File.separator) + File.separator + moduleName + "/mapstruct/" + tableInfo.getEntityName().replace("Entity", "Mapper") + StringPool.DOT_JAVA;
|
||||
}
|
||||
});
|
||||
focList.add(new FileOutConfig("/templates/dto.java.vm") {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return projectPath + "/src/main/java/"+ parentName.replace(".", File.separator) + File.separator + moduleName + "/api/dto/" + tableInfo.getEntityName().replace("Entity", "Dto") + StringPool.DOT_JAVA;
|
||||
}
|
||||
});
|
||||
focList.add(new FileOutConfig("/templates/vo.java.vm") {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return projectPath + "/src/main/java/"+ parentName.replace(".", File.separator) + File.separator + moduleName + "/api/vo/" + tableInfo.getEntityName().replace("Entity", "Vo") + StringPool.DOT_JAVA;
|
||||
}
|
||||
});
|
||||
focList.add(new FileOutConfig("/templates/query.java.vm") {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return projectPath + "/src/main/java/"+ parentName.replace(".", File.separator) + File.separator + moduleName + "/api/query/" + tableInfo.getEntityName().replace("Entity", "Query") + StringPool.DOT_JAVA;
|
||||
}
|
||||
});
|
||||
cfg.setFileOutConfigList(focList);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
/**
|
||||
* 模板配置
|
||||
*
|
||||
* @return templateConfig
|
||||
*/
|
||||
private static TemplateConfig getTemplateConfig() {
|
||||
return new TemplateConfig()
|
||||
.setEntity(null)
|
||||
.setController("templates/controller.java")
|
||||
.setService("templates/service.java")
|
||||
.setServiceImpl("templates/serviceImpl.java")
|
||||
.setMapper("templates/mapper.java")
|
||||
.setXml(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置包名
|
||||
*
|
||||
* @param moduleName 模块名 如:system
|
||||
* @param parentName 父路径包名 如:cn.datax.service
|
||||
* @return PackageConfig 包名配置
|
||||
*/
|
||||
private static PackageConfig getPackageConfig(String moduleName, String parentName) {
|
||||
return new PackageConfig()
|
||||
.setModuleName(moduleName)
|
||||
.setParent(parentName)
|
||||
.setXml("mapper")
|
||||
.setMapper("dao")
|
||||
.setController("controller")
|
||||
.setService("service")
|
||||
.setServiceImpl("service.impl")
|
||||
.setEntity("entity");
|
||||
}
|
||||
|
||||
/**
|
||||
* 全局配置
|
||||
*
|
||||
* @return GlobalConfig
|
||||
*/
|
||||
private static GlobalConfig getGlobalConfig(String projectPath) {
|
||||
return new GlobalConfig()
|
||||
//是否打开输出目录
|
||||
.setOpen(true)
|
||||
//开启 baseColumnList
|
||||
.setBaseColumnList(true)
|
||||
//开启 BaseResultMap
|
||||
.setBaseResultMap(true)
|
||||
//开启 ActiveRecord 模式
|
||||
.setActiveRecord(false)
|
||||
//是否覆盖已有文件
|
||||
.setFileOverride(true)
|
||||
//实体属性 Swagger2 注解
|
||||
.setSwagger2(false)
|
||||
.setAuthor("yuwei")
|
||||
//指定生成的主键的ID类型
|
||||
.setIdType(IdType.ASSIGN_ID)
|
||||
//设置输出路径
|
||||
.setOutputDir(projectPath + "/src/main/java/")
|
||||
.setEntityName("%sEntity")
|
||||
.setMapperName("%sDao")
|
||||
.setXmlName("%sMapper")
|
||||
.setServiceName("%sService")
|
||||
.setServiceImplName("%sServiceImpl")
|
||||
.setControllerName("%sController");
|
||||
}
|
||||
|
||||
/**
|
||||
* 策略配置
|
||||
*
|
||||
* @param tableNames 表名
|
||||
* @return StrategyConfig
|
||||
*/
|
||||
private static StrategyConfig getStrategyConfig(String tablePrefix, String[] tableNames) {
|
||||
StrategyConfig strategyConfig = new StrategyConfig()
|
||||
//从数据库表到文件的命名策略
|
||||
.setNaming(NamingStrategy.underline_to_camel)
|
||||
.setColumnNaming(NamingStrategy.underline_to_camel)
|
||||
.setEntityLombokModel(true)
|
||||
.setRestControllerStyle(true)
|
||||
.setControllerMappingHyphenStyle(true)
|
||||
//表前缀
|
||||
.setTablePrefix(tablePrefix)
|
||||
//写于父类中的公共字段
|
||||
.setSuperEntityColumns(new String[]{"id", "create_time", "create_by", "create_dept", "update_time", "update_by", "status", "remark"})
|
||||
.setInclude(tableNames)
|
||||
//公共父类
|
||||
.setSuperEntityClass("cn.datax.common.base.BaseEntity")
|
||||
.setSuperServiceClass("cn.datax.common.base.BaseService")
|
||||
.setSuperServiceImplClass("cn.datax.common.base.BaseServiceImpl")
|
||||
.setSuperMapperClass("cn.datax.common.base.BaseDao");
|
||||
strategyConfig.setSuperControllerClass("cn.datax.common.base.BaseController");
|
||||
return strategyConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置数据源
|
||||
*
|
||||
* @return 数据源配置 DataSourceConfig
|
||||
*/
|
||||
private static DataSourceConfig getDataSourceConfig() {
|
||||
return new DataSourceConfig()
|
||||
.setUrl("jdbc:mysql://localhost:3306/studio?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8")
|
||||
.setDriverName("com.mysql.cj.jdbc.Driver")
|
||||
.setUsername("root")
|
||||
.setPassword("1234@abcd");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
server:
|
||||
port: 8830
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: service-codegen
|
||||
profiles:
|
||||
active: dev
|
||||
cloud:
|
||||
config:
|
||||
label: master
|
||||
name: ${spring.application.name}
|
||||
profile: ${spring.profiles.active}
|
||||
discovery:
|
||||
enabled: true
|
||||
service-id: config
|
||||
|
||||
# 注册中心配置
|
||||
eureka:
|
||||
instance:
|
||||
lease-renewal-interval-in-seconds: 20
|
||||
prefer-ip-address: true
|
||||
ip-address: 192.168.1.169
|
||||
client:
|
||||
register-with-eureka: true
|
||||
fetch-registry: true
|
||||
instance-info-replication-interval-seconds: 30
|
||||
registry-fetch-interval-seconds: 3
|
||||
service-url:
|
||||
defaultZone: http://192.168.1.169:8610/eureka
|
||||
@@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<springProperty scope="context" name="springAppName" source="spring.application.name"/>
|
||||
<property name="log.path" value="logs/service-codegen"/>
|
||||
<property name="log.maxHistory" value="15"/>
|
||||
<property name="log.totalSizeCap" value="500MB"/>
|
||||
<property name="log.maxFileSize" value="10MB"/>
|
||||
<property name="log.colorPattern"
|
||||
value="%magenta(%d{yyyy-MM-dd HH:mm:ss}) %highlight(%-5level) %boldCyan(${springAppName:-}) %yellow(%thread) %green(%logger) %msg%n"/>
|
||||
<property name="log.pattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5level ${springAppName:-} %thread %logger %msg%n"/>
|
||||
|
||||
<!--输出到控制台-->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.colorPattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!--输出到文件-->
|
||||
<!-- RollingFileAppender:滚动记录文件,先将日志记录到指定文件,当符合某个条件时,将日志记录到其他文件 -->
|
||||
<!-- 以下的大概意思是:1.先按日期存日志,日期变了,将前一天的日志文件名重命名为XXX%日期%索引,新的日志仍然是project_info.log -->
|
||||
<!-- 2.如果日期没有发生变化,但是当前日志的文件大小超过10MB时,对当前日志进行分割 重命名-->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<!--日志文件路径和名称-->
|
||||
<File>${log.path}/info/info.log</File>
|
||||
<!--是否追加到文件末尾,默认为true-->
|
||||
<append>true</append>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<!-- 日志文件的名字会根据fileNamePattern的值,每隔一段时间改变一次 -->
|
||||
<!-- 文件名:logs/project_info.2017-12-05.0.log -->
|
||||
<!-- 注意:SizeAndTimeBasedRollingPolicy中 %i和%d令牌都是强制性的,必须存在,要不会报错 -->
|
||||
<fileNamePattern>${log.path}/info/info.%d.%i.log</fileNamePattern>
|
||||
<!-- 每产生一个日志文件,该日志文件的保存期限为30天, ps:maxHistory的单位是根据fileNamePattern中的翻转策略自动推算出来的,例如上面选用了yyyy-MM-dd,则单位为天
|
||||
如果上面选用了yyyy-MM,则单位为月,另外上面的单位默认为yyyy-MM-dd-->
|
||||
<MaxHistory>${log.maxHistory}</MaxHistory>
|
||||
<!-- 每个日志文件到2mb的时候开始切分,最多保留30天,但最大到500MB,哪怕没到30天也要删除多余的日志 -->
|
||||
<totalSizeCap>${log.totalSizeCap}</totalSizeCap>
|
||||
<!-- maxFileSize:这是活动文件的大小,默认值是10MB,测试时可改成5KB看效果 -->
|
||||
<maxFileSize>${log.maxFileSize}</maxFileSize>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>INFO</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<File>${log.path}/error/error.log</File>
|
||||
<append>true</append>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.path}/error/error.%d.%i.log</fileNamePattern>
|
||||
<MaxHistory>${log.maxHistory}</MaxHistory>
|
||||
<totalSizeCap>${log.totalSizeCap}</totalSizeCap>
|
||||
<maxFileSize>${log.maxFileSize}</maxFileSize>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>ERROR</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<root level="debug">
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="file_info"/>
|
||||
<appender-ref ref="file_error"/>
|
||||
</root>
|
||||
</configuration>
|
||||
@@ -0,0 +1,63 @@
|
||||
<?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="cn.datax.service.codegen.dao.GenTableDao">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="cn.datax.service.codegen.api.entity.GenTableEntity">
|
||||
<result column="id" property="id" />
|
||||
<result column="status" property="status" />
|
||||
<result column="create_by" property="createBy" />
|
||||
<result column="create_time" property="createTime" />
|
||||
<result column="update_by" property="updateBy" />
|
||||
<result column="update_time" property="updateTime" />
|
||||
<result column="remark" property="remark" />
|
||||
<result column="table_name" property="tableName" />
|
||||
<result column="table_comment" property="tableComment" />
|
||||
<result column="class_name" property="className" />
|
||||
<result column="package_name" property="packageName" />
|
||||
<result column="module_name" property="moduleName" />
|
||||
<result column="business_name" property="businessName" />
|
||||
<result column="function_name" property="functionName" />
|
||||
<result column="function_author" property="functionAuthor" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="ExtendResultMap" type="cn.datax.service.codegen.api.entity.GenTableEntity" extends="BaseResultMap">
|
||||
<result column="column_json" property="columns" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler" />
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id,
|
||||
status,
|
||||
create_by,
|
||||
create_time,
|
||||
update_by,
|
||||
update_time,
|
||||
remark, table_name, table_comment, class_name, package_name, module_name, business_name, function_name, function_author
|
||||
</sql>
|
||||
|
||||
<sql id="Extend_Column_List">
|
||||
id,
|
||||
status,
|
||||
create_by,
|
||||
create_time,
|
||||
update_by,
|
||||
update_time,
|
||||
remark, table_name, table_comment, class_name, package_name, module_name, business_name, function_name, function_author, column_json
|
||||
</sql>
|
||||
|
||||
<select id="selectById" resultMap="ExtendResultMap">
|
||||
SELECT
|
||||
<include refid="Extend_Column_List"></include>
|
||||
FROM gen_table
|
||||
WHERE 1=1 AND id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="selectPage" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"></include>
|
||||
FROM gen_table
|
||||
${ew.customSqlSegment}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,144 @@
|
||||
package ${package.Controller};
|
||||
|
||||
import cn.datax.common.core.JsonPage;
|
||||
import cn.datax.common.core.R;
|
||||
import cn.datax.common.validate.ValidationGroups;
|
||||
import ${cfg.PackageParent}#if(${package.ModuleName}).${package.ModuleName}#end.api.dto.${className}Dto;
|
||||
import ${cfg.PackageParent}#if(${package.ModuleName}).${package.ModuleName}#end.api.entity.${entity};
|
||||
import ${cfg.PackageParent}#if(${package.ModuleName}).${package.ModuleName}#end.api.vo.${className}Vo;
|
||||
import ${cfg.PackageParent}#if(${package.ModuleName}).${package.ModuleName}#end.api.query.${className}Query;
|
||||
import ${cfg.PackageParent}#if(${package.ModuleName}).${package.ModuleName}#end.mapstruct.${className}Mapper;
|
||||
import ${package.Service}.${table.serviceName};
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
#if(${superControllerClassPackage})
|
||||
import ${superControllerClassPackage};
|
||||
#end
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* $!{table.comment} 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
#if(${table.comment})
|
||||
@Api(tags = {"${table.comment}"})
|
||||
#else
|
||||
@Api(tags = {"${className}"})
|
||||
#end
|
||||
@RestController
|
||||
@RequestMapping("#if(${package.ModuleName})/${package.ModuleName}#end/${classNameLower}")
|
||||
#if(${superControllerClass})
|
||||
public class ${table.controllerName} extends ${superControllerClass} {
|
||||
#else
|
||||
public class ${table.controllerName} {
|
||||
#end
|
||||
|
||||
@Autowired
|
||||
private ${table.serviceName} ${classNameLower}Service;
|
||||
|
||||
@Autowired
|
||||
private ${className}Mapper ${classNameLower}Mapper;
|
||||
|
||||
/**
|
||||
* 通过ID查询信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "获取详细信息", notes = "根据url的id来获取详细信息")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@GetMapping("/{id}")
|
||||
public R get${className}ById(@PathVariable String id) {
|
||||
${entity} ${classNameLower}Entity = ${classNameLower}Service.get${className}ById(id);
|
||||
return R.ok().setData(${classNameLower}Mapper.toVO(${classNameLower}Entity));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询信息
|
||||
*
|
||||
* @param ${classNameLower}Query
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "分页查询", notes = "")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "${classNameLower}Query", value = "查询实体${classNameLower}Query", required = true, dataTypeClass = ${className}Query.class)
|
||||
})
|
||||
@GetMapping("/page")
|
||||
public R get${className}Page(${className}Query ${classNameLower}Query) {
|
||||
QueryWrapper<${entity}> queryWrapper = new QueryWrapper<>();
|
||||
IPage<${entity}> page = ${classNameLower}Service.page(new Page<>(${classNameLower}Query.getPageNum(), ${classNameLower}Query.getPageSize()), queryWrapper);
|
||||
List<${className}Vo> collect = page.getRecords().stream().map(${classNameLower}Mapper::toVO).collect(Collectors.toList());
|
||||
JsonPage<${className}Vo> jsonPage = new JsonPage<>(page.getCurrent(), page.getSize(), page.getTotal(), collect);
|
||||
return R.ok().setData(jsonPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param ${classNameLower}
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "添加信息", notes = "根据${classNameLower}对象添加信息")
|
||||
@ApiImplicitParam(name = "${classNameLower}", value = "详细实体${classNameLower}", required = true, dataType = "${className}Dto")
|
||||
@PostMapping()
|
||||
public R save${className}(@RequestBody @Validated({ValidationGroups.Insert.class}) ${className}Dto ${classNameLower}) {
|
||||
${entity} ${classNameLower}Entity = ${classNameLower}Service.save${className}(${classNameLower});
|
||||
return R.ok().setData(${classNameLower}Mapper.toVO(${classNameLower}Entity));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param ${classNameLower}
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "修改信息", notes = "根据url的id来指定修改对象,并根据传过来的信息来修改详细信息")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path"),
|
||||
@ApiImplicitParam(name = "${classNameLower}", value = "详细实体${classNameLower}", required = true, dataType = "${className}Dto")
|
||||
})
|
||||
@PutMapping("/{id}")
|
||||
public R update${className}(@PathVariable String id, @RequestBody @Validated({ValidationGroups.Update.class}) ${className}Dto ${classNameLower}) {
|
||||
${entity} ${classNameLower}Entity = ${classNameLower}Service.update${className}(${classNameLower});
|
||||
return R.ok().setData(${classNameLower}Mapper.toVO(${classNameLower}Entity));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "删除", notes = "根据url的id来指定删除对象")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@DeleteMapping("/{id}")
|
||||
public R delete${className}ById(@PathVariable String id) {
|
||||
${classNameLower}Service.delete${className}ById(id);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "批量删除", notes = "根据url的ids来批量删除对象")
|
||||
@ApiImplicitParam(name = "ids", value = "ID集合", required = true, dataType = "List", paramType = "path")
|
||||
@DeleteMapping("/batch/{ids}")
|
||||
public R delete${className}Batch(@PathVariable List<String> ids) {
|
||||
${classNameLower}Service.delete${className}Batch(ids);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package ${package.Controller};
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
#if(${restControllerStyle})
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
#else
|
||||
import org.springframework.stereotype.Controller;
|
||||
#end
|
||||
#if(${superControllerClassPackage})
|
||||
import ${superControllerClassPackage};
|
||||
#end
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* $!{table.comment} 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
#if(${restControllerStyle})
|
||||
@RestController
|
||||
#else
|
||||
@Controller
|
||||
#end
|
||||
@RequestMapping("#if(${package.ModuleName})/${package.ModuleName}#end/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end")
|
||||
#if(${kotlin})
|
||||
class ${table.controllerName}#if(${superControllerClass}) : ${superControllerClass}()#end
|
||||
|
||||
#else
|
||||
#if(${superControllerClass})
|
||||
public class ${table.controllerName} extends ${superControllerClass} {
|
||||
#else
|
||||
public class ${table.controllerName} {
|
||||
#end
|
||||
|
||||
}
|
||||
|
||||
#end
|
||||
@@ -0,0 +1,34 @@
|
||||
package ${cfg.PackageParent}#if(${package.ModuleName}).${package.ModuleName}#end.api.dto;
|
||||
|
||||
import cn.datax.common.validate.ValidationGroups;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
/**
|
||||
* <p>
|
||||
* $!{table.comment} 实体DTO
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@ApiModel(value = "$!{table.comment}Model")
|
||||
@Data
|
||||
public class ${className}Dto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "主键ID")
|
||||
@NotBlank(message = "主键ID不能为空", groups = {ValidationGroups.Update.class})
|
||||
private String id;
|
||||
|
||||
## ---------- BEGIN 字段循环遍历 ----------
|
||||
#foreach($field in ${table.fields})
|
||||
@ApiModelProperty(value = "${field.comment}")
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
## ---------- END 字段循环遍历 ----------
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
package ${cfg.PackageParent}#if(${package.ModuleName}).${package.ModuleName}#end.api.entity;
|
||||
|
||||
#foreach($pkg in ${table.importPackages})
|
||||
import ${pkg};
|
||||
#end
|
||||
#if(${swagger2})
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
#end
|
||||
#if(${entityLombokModel})
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
#end
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* $!{table.comment}
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
#if(${entityLombokModel})
|
||||
@Data
|
||||
#if(${superEntityClass})
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
#else
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
#end
|
||||
@Accessors(chain = true)
|
||||
#end
|
||||
#if(${table.convert})
|
||||
@TableName("${table.name}")
|
||||
#end
|
||||
#if(${swagger2})
|
||||
@ApiModel(value="${entity}对象", description="$!{table.comment}")
|
||||
#end
|
||||
#if(${superEntityClass})
|
||||
public class ${entity} extends ${superEntityClass}#if(${activeRecord})<${entity}>#end {
|
||||
#elseif(${activeRecord})
|
||||
public class ${entity} extends Model<${entity}> {
|
||||
#else
|
||||
public class ${entity} implements Serializable {
|
||||
#end
|
||||
|
||||
#if(${entitySerialVersionUID})
|
||||
private static final long serialVersionUID=1L;
|
||||
#end
|
||||
## ---------- BEGIN 字段循环遍历 ----------
|
||||
#foreach($field in ${table.fields})
|
||||
|
||||
#if(${field.keyFlag})
|
||||
#set($keyPropertyName=${field.propertyName})
|
||||
#end
|
||||
#if("$!field.comment" != "")
|
||||
#if(${swagger2})
|
||||
@ApiModelProperty(value = "${field.comment}")
|
||||
#else
|
||||
/**
|
||||
* ${field.comment}
|
||||
*/
|
||||
#end
|
||||
#end
|
||||
#if(${field.keyFlag})
|
||||
## 主键
|
||||
#if(${field.keyIdentityFlag})
|
||||
@TableId(value = "${field.name}", type = IdType.AUTO)
|
||||
#elseif(!$null.isNull(${idType}) && "$!idType" != "")
|
||||
@TableId(value = "${field.name}", type = IdType.${idType})
|
||||
#elseif(${field.convert})
|
||||
@TableId("${field.name}")
|
||||
#end
|
||||
## 普通字段
|
||||
#elseif(${field.fill})
|
||||
## ----- 存在字段填充设置 -----
|
||||
#if(${field.convert})
|
||||
@TableField(value = "${field.name}", fill = FieldFill.${field.fill})
|
||||
#else
|
||||
@TableField(fill = FieldFill.${field.fill})
|
||||
#end
|
||||
#elseif(${field.convert})
|
||||
@TableField("${field.name}")
|
||||
#end
|
||||
## 乐观锁注解
|
||||
#if(${versionFieldName}==${field.name})
|
||||
@Version
|
||||
#end
|
||||
## 逻辑删除注解
|
||||
#if(${logicDeleteFieldName}==${field.name})
|
||||
@TableLogic
|
||||
#end
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
## ---------- END 字段循环遍历 ----------
|
||||
|
||||
#if(!${entityLombokModel})
|
||||
#foreach($field in ${table.fields})
|
||||
#if(${field.propertyType.equals("boolean")})
|
||||
#set($getprefix="is")
|
||||
#else
|
||||
#set($getprefix="get")
|
||||
#end
|
||||
|
||||
public ${field.propertyType} ${getprefix}${field.capitalName}() {
|
||||
return ${field.propertyName};
|
||||
}
|
||||
|
||||
#if(${entityBuilderModel})
|
||||
public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
|
||||
#else
|
||||
public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
|
||||
#end
|
||||
this.${field.propertyName} = ${field.propertyName};
|
||||
#if(${entityBuilderModel})
|
||||
return this;
|
||||
#end
|
||||
}
|
||||
#end
|
||||
#end
|
||||
|
||||
#if(${entityColumnConstant})
|
||||
#foreach($field in ${table.fields})
|
||||
public static final String ${field.name.toUpperCase()} = "${field.name}";
|
||||
|
||||
#end
|
||||
#end
|
||||
#if(${activeRecord})
|
||||
@Override
|
||||
protected Serializable pkVal() {
|
||||
#if(${keyPropertyName})
|
||||
return this.${keyPropertyName};
|
||||
#else
|
||||
return null;
|
||||
#end
|
||||
}
|
||||
|
||||
#end
|
||||
#if(!${entityLombokModel})
|
||||
@Override
|
||||
public String toString() {
|
||||
return "${entity}{" +
|
||||
#foreach($field in ${table.fields})
|
||||
#if($!{foreach.index}==0)
|
||||
"${field.propertyName}=" + ${field.propertyName} +
|
||||
#else
|
||||
", ${field.propertyName}=" + ${field.propertyName} +
|
||||
#end
|
||||
#end
|
||||
"}";
|
||||
}
|
||||
#end
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
package ${package.Entity};
|
||||
|
||||
#foreach($pkg in ${table.importPackages})
|
||||
import ${pkg};
|
||||
#end
|
||||
#if(${swagger2})
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
#end
|
||||
#if(${entityLombokModel})
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
#end
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* $!{table.comment}
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
#if(${entityLombokModel})
|
||||
@Data
|
||||
#if(${superEntityClass})
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
#else
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
#end
|
||||
@Accessors(chain = true)
|
||||
#end
|
||||
#if(${table.convert})
|
||||
@TableName("${table.name}")
|
||||
#end
|
||||
#if(${swagger2})
|
||||
@ApiModel(value="${entity}对象", description="$!{table.comment}")
|
||||
#end
|
||||
#if(${superEntityClass})
|
||||
public class ${entity} extends ${superEntityClass}#if(${activeRecord})<${entity}>#end {
|
||||
#elseif(${activeRecord})
|
||||
public class ${entity} extends Model<${entity}> {
|
||||
#else
|
||||
public class ${entity} implements Serializable {
|
||||
#end
|
||||
|
||||
#if(${entitySerialVersionUID})
|
||||
private static final long serialVersionUID=1L;
|
||||
#end
|
||||
## ---------- BEGIN 字段循环遍历 ----------
|
||||
#foreach($field in ${table.fields})
|
||||
|
||||
#if(${field.keyFlag})
|
||||
#set($keyPropertyName=${field.propertyName})
|
||||
#end
|
||||
#if("$!field.comment" != "")
|
||||
#if(${swagger2})
|
||||
@ApiModelProperty(value = "${field.comment}")
|
||||
#else
|
||||
/**
|
||||
* ${field.comment}
|
||||
*/
|
||||
#end
|
||||
#end
|
||||
#if(${field.keyFlag})
|
||||
## 主键
|
||||
#if(${field.keyIdentityFlag})
|
||||
@TableId(value = "${field.name}", type = IdType.AUTO)
|
||||
#elseif(!$null.isNull(${idType}) && "$!idType" != "")
|
||||
@TableId(value = "${field.name}", type = IdType.${idType})
|
||||
#elseif(${field.convert})
|
||||
@TableId("${field.name}")
|
||||
#end
|
||||
## 普通字段
|
||||
#elseif(${field.fill})
|
||||
## ----- 存在字段填充设置 -----
|
||||
#if(${field.convert})
|
||||
@TableField(value = "${field.name}", fill = FieldFill.${field.fill})
|
||||
#else
|
||||
@TableField(fill = FieldFill.${field.fill})
|
||||
#end
|
||||
#elseif(${field.convert})
|
||||
@TableField("${field.name}")
|
||||
#end
|
||||
## 乐观锁注解
|
||||
#if(${versionFieldName}==${field.name})
|
||||
@Version
|
||||
#end
|
||||
## 逻辑删除注解
|
||||
#if(${logicDeleteFieldName}==${field.name})
|
||||
@TableLogic
|
||||
#end
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
## ---------- END 字段循环遍历 ----------
|
||||
|
||||
#if(!${entityLombokModel})
|
||||
#foreach($field in ${table.fields})
|
||||
#if(${field.propertyType.equals("boolean")})
|
||||
#set($getprefix="is")
|
||||
#else
|
||||
#set($getprefix="get")
|
||||
#end
|
||||
|
||||
public ${field.propertyType} ${getprefix}${field.capitalName}() {
|
||||
return ${field.propertyName};
|
||||
}
|
||||
|
||||
#if(${entityBuilderModel})
|
||||
public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
|
||||
#else
|
||||
public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
|
||||
#end
|
||||
this.${field.propertyName} = ${field.propertyName};
|
||||
#if(${entityBuilderModel})
|
||||
return this;
|
||||
#end
|
||||
}
|
||||
#end
|
||||
#end
|
||||
|
||||
#if(${entityColumnConstant})
|
||||
#foreach($field in ${table.fields})
|
||||
public static final String ${field.name.toUpperCase()} = "${field.name}";
|
||||
|
||||
#end
|
||||
#end
|
||||
#if(${activeRecord})
|
||||
@Override
|
||||
protected Serializable pkVal() {
|
||||
#if(${keyPropertyName})
|
||||
return this.${keyPropertyName};
|
||||
#else
|
||||
return null;
|
||||
#end
|
||||
}
|
||||
|
||||
#end
|
||||
#if(!${entityLombokModel})
|
||||
@Override
|
||||
public String toString() {
|
||||
return "${entity}{" +
|
||||
#foreach($field in ${table.fields})
|
||||
#if($!{foreach.index}==0)
|
||||
"${field.propertyName}=" + ${field.propertyName} +
|
||||
#else
|
||||
", ${field.propertyName}=" + ${field.propertyName} +
|
||||
#end
|
||||
#end
|
||||
"}";
|
||||
}
|
||||
#end
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package ${package.Entity};
|
||||
|
||||
#foreach($pkg in ${table.importPackages})
|
||||
import ${pkg};
|
||||
#end
|
||||
#if(${swagger2})
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
#end
|
||||
/**
|
||||
* <p>
|
||||
* $!{table.comment}
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
#if(${table.convert})
|
||||
@TableName("${table.name}")
|
||||
#end
|
||||
#if(${swagger2})
|
||||
@ApiModel(value="${entity}对象", description="$!{table.comment}")
|
||||
#end
|
||||
#if(${superEntityClass})
|
||||
class ${entity} : ${superEntityClass}#if(${activeRecord})<${entity}>#end() {
|
||||
#elseif(${activeRecord})
|
||||
class ${entity} : Model<${entity}>() {
|
||||
#else
|
||||
class ${entity} : Serializable {
|
||||
#end
|
||||
|
||||
## ---------- BEGIN 字段循环遍历 ----------
|
||||
#foreach($field in ${table.fields})
|
||||
#if(${field.keyFlag})
|
||||
#set($keyPropertyName=${field.propertyName})
|
||||
#end
|
||||
#if("$!field.comment" != "")
|
||||
#if(${swagger2})
|
||||
@ApiModelProperty(value = "${field.comment}")
|
||||
#else
|
||||
/**
|
||||
* ${field.comment}
|
||||
*/
|
||||
#end
|
||||
#end
|
||||
#if(${field.keyFlag})
|
||||
## 主键
|
||||
#if(${field.keyIdentityFlag})
|
||||
@TableId(value = "${field.name}", type = IdType.AUTO)
|
||||
#elseif(!$null.isNull(${idType}) && "$!idType" != "")
|
||||
@TableId(value = "${field.name}", type = IdType.${idType})
|
||||
#elseif(${field.convert})
|
||||
@TableId("${field.name}")
|
||||
#end
|
||||
## 普通字段
|
||||
#elseif(${field.fill})
|
||||
## ----- 存在字段填充设置 -----
|
||||
#if(${field.convert})
|
||||
@TableField(value = "${field.name}", fill = FieldFill.${field.fill})
|
||||
#else
|
||||
@TableField(fill = FieldFill.${field.fill})
|
||||
#end
|
||||
#elseif(${field.convert})
|
||||
@TableField("${field.name}")
|
||||
#end
|
||||
## 乐观锁注解
|
||||
#if(${versionFieldName}==${field.name})
|
||||
@Version
|
||||
#end
|
||||
## 逻辑删除注解
|
||||
#if(${logicDeleteFieldName}==${field.name})
|
||||
@TableLogic
|
||||
#end
|
||||
#if(${field.propertyType} == "Integer")
|
||||
var ${field.propertyName}: Int? = null
|
||||
#else
|
||||
var ${field.propertyName}: ${field.propertyType}? = null
|
||||
#end
|
||||
#end
|
||||
## ---------- END 字段循环遍历 ----------
|
||||
|
||||
|
||||
#if(${entityColumnConstant})
|
||||
companion object {
|
||||
#foreach($field in ${table.fields})
|
||||
|
||||
const val ${field.name.toUpperCase()} : String = "${field.name}"
|
||||
|
||||
#end
|
||||
}
|
||||
|
||||
#end
|
||||
#if(${activeRecord})
|
||||
override fun pkVal(): Serializable? {
|
||||
#if(${keyPropertyName})
|
||||
return ${keyPropertyName}
|
||||
#else
|
||||
return null
|
||||
#end
|
||||
}
|
||||
|
||||
#end
|
||||
override fun toString(): String {
|
||||
return "${entity}{" +
|
||||
#foreach($field in ${table.fields})
|
||||
#if($!{foreach.index}==0)
|
||||
"${field.propertyName}=" + ${field.propertyName} +
|
||||
#else
|
||||
", ${field.propertyName}=" + ${field.propertyName} +
|
||||
#end
|
||||
#end
|
||||
"}"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package ${package.Mapper};
|
||||
|
||||
import ${superMapperClassPackage};
|
||||
import ${cfg.PackageParent}#if(${package.ModuleName}).${package.ModuleName}#end.api.entity.${entity};
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* $!{table.comment} Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Mapper
|
||||
public interface ${table.mapperName} extends ${superMapperClass}<${entity}> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package ${package.Mapper};
|
||||
|
||||
import ${package.Entity}.${entity};
|
||||
import ${superMapperClassPackage};
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* $!{table.comment} Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
#if(${kotlin})
|
||||
interface ${table.mapperName} : ${superMapperClass}<${entity}>
|
||||
#else
|
||||
public interface ${table.mapperName} extends ${superMapperClass}<${entity}> {
|
||||
|
||||
}
|
||||
#end
|
||||
@@ -0,0 +1,39 @@
|
||||
<?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="${package.Mapper}.${table.mapperName}">
|
||||
|
||||
#if(${enableCache})
|
||||
<!-- 开启二级缓存 -->
|
||||
<cache type="org.mybatis.caches.ehcache.LoggingEhcache"/>
|
||||
|
||||
#end
|
||||
#if(${baseResultMap})
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="${cfg.PackageParent}#if(${package.ModuleName}).${package.ModuleName}#end.api.entity.${entity}">
|
||||
#foreach($field in ${table.fields})
|
||||
#if(${field.keyFlag})##生成主键排在第一位
|
||||
<id column="${field.name}" property="${field.propertyName}" />
|
||||
#end
|
||||
#end
|
||||
#foreach($field in ${table.commonFields})##生成公共字段
|
||||
<result column="${field.name}" property="${field.propertyName}" />
|
||||
#end
|
||||
#foreach($field in ${table.fields})
|
||||
#if(!${field.keyFlag})##生成普通字段
|
||||
<result column="${field.name}" property="${field.propertyName}" />
|
||||
#end
|
||||
#end
|
||||
</resultMap>
|
||||
|
||||
#end
|
||||
#if(${baseColumnList})
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
#foreach($field in ${table.commonFields})
|
||||
${field.name},
|
||||
#end
|
||||
${table.fieldNames}
|
||||
</sql>
|
||||
|
||||
#end
|
||||
</mapper>
|
||||
@@ -0,0 +1,39 @@
|
||||
<?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="${package.Mapper}.${table.mapperName}">
|
||||
|
||||
#if(${enableCache})
|
||||
<!-- 开启二级缓存 -->
|
||||
<cache type="org.mybatis.caches.ehcache.LoggingEhcache"/>
|
||||
|
||||
#end
|
||||
#if(${baseResultMap})
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="${package.Entity}.${entity}">
|
||||
#foreach($field in ${table.fields})
|
||||
#if(${field.keyFlag})##生成主键排在第一位
|
||||
<id column="${field.name}" property="${field.propertyName}" />
|
||||
#end
|
||||
#end
|
||||
#foreach($field in ${table.commonFields})##生成公共字段
|
||||
<result column="${field.name}" property="${field.propertyName}" />
|
||||
#end
|
||||
#foreach($field in ${table.fields})
|
||||
#if(!${field.keyFlag})##生成普通字段
|
||||
<result column="${field.name}" property="${field.propertyName}" />
|
||||
#end
|
||||
#end
|
||||
</resultMap>
|
||||
|
||||
#end
|
||||
#if(${baseColumnList})
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
#foreach($field in ${table.commonFields})
|
||||
${field.name},
|
||||
#end
|
||||
${table.fieldNames}
|
||||
</sql>
|
||||
|
||||
#end
|
||||
</mapper>
|
||||
@@ -0,0 +1,20 @@
|
||||
package ${cfg.PackageParent}#if(${package.ModuleName}).${package.ModuleName}#end.mapstruct;
|
||||
|
||||
import cn.datax.common.mapstruct.EntityMapper;
|
||||
import ${cfg.PackageParent}#if(${package.ModuleName}).${package.ModuleName}#end.api.dto.${className}Dto;
|
||||
import ${cfg.PackageParent}#if(${package.ModuleName}).${package.ModuleName}#end.api.entity.${entity};
|
||||
import ${cfg.PackageParent}#if(${package.ModuleName}).${package.ModuleName}#end.api.vo.${className}Vo;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* $!{table.comment} Mapper 实体映射
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface ${className}Mapper extends EntityMapper<${className}Dto, ${entity}, ${className}Vo> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package ${cfg.PackageParent}#if(${package.ModuleName}).${package.ModuleName}#end.api.query;
|
||||
|
||||
import cn.datax.common.base.BaseQueryParams;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* $!{table.comment} 查询实体
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ${className}Query extends BaseQueryParams {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package ${package.Service};
|
||||
|
||||
import ${cfg.PackageParent}#if(${package.ModuleName}).${package.ModuleName}#end.api.entity.${entity};
|
||||
import ${cfg.PackageParent}#if(${package.ModuleName}).${package.ModuleName}#end.api.dto.${className}Dto;
|
||||
import ${superServiceClassPackage};
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* $!{table.comment} 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
public interface ${table.serviceName} extends ${superServiceClass}<${entity}> {
|
||||
|
||||
${entity} save${className}(${className}Dto ${classNameLower});
|
||||
|
||||
${entity} update${className}(${className}Dto ${classNameLower});
|
||||
|
||||
${entity} get${className}ById(String id);
|
||||
|
||||
void delete${className}ById(String id);
|
||||
|
||||
void delete${className}Batch(List<String> ids);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package ${package.Service};
|
||||
|
||||
import ${package.Entity}.${entity};
|
||||
import ${superServiceClassPackage};
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* $!{table.comment} 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
#if(${kotlin})
|
||||
interface ${table.serviceName} : ${superServiceClass}<${entity}>
|
||||
#else
|
||||
public interface ${table.serviceName} extends ${superServiceClass}<${entity}> {
|
||||
|
||||
}
|
||||
#end
|
||||
@@ -0,0 +1,67 @@
|
||||
package ${package.ServiceImpl};
|
||||
|
||||
import ${cfg.PackageParent}#if(${package.ModuleName}).${package.ModuleName}#end.api.entity.${entity};
|
||||
import ${cfg.PackageParent}#if(${package.ModuleName}).${package.ModuleName}#end.api.dto.${className}Dto;
|
||||
import ${package.Service}.${table.serviceName};
|
||||
import ${cfg.PackageParent}#if(${package.ModuleName}).${package.ModuleName}#end.mapstruct.${className}Mapper;
|
||||
import ${cfg.PackageParent}#if(${package.ModuleName}).${package.ModuleName}#end.dao.${className}Dao;
|
||||
import ${superServiceImplClassPackage};
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* $!{table.comment} 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Service
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {
|
||||
|
||||
@Autowired
|
||||
private ${className}Dao ${classNameLower}Dao;
|
||||
|
||||
@Autowired
|
||||
private ${className}Mapper ${classNameLower}Mapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ${entity} save${className}(${className}Dto ${classNameLower}Dto) {
|
||||
${entity} ${classNameLower} = ${classNameLower}Mapper.toEntity(${classNameLower}Dto);
|
||||
${classNameLower}Dao.insert(${classNameLower});
|
||||
return ${classNameLower};
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ${entity} update${className}(${className}Dto ${classNameLower}Dto) {
|
||||
${entity} ${classNameLower} = ${classNameLower}Mapper.toEntity(${classNameLower}Dto);
|
||||
${classNameLower}Dao.updateById(${classNameLower});
|
||||
return ${classNameLower};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ${entity} get${className}ById(String id) {
|
||||
${entity} ${classNameLower}Entity = super.getById(id);
|
||||
return ${classNameLower}Entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete${className}ById(String id) {
|
||||
${classNameLower}Dao.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete${className}Batch(List<String> ids) {
|
||||
${classNameLower}Dao.deleteBatchIds(ids);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package ${package.ServiceImpl};
|
||||
|
||||
import ${package.Entity}.${entity};
|
||||
import ${package.Mapper}.${table.mapperName};
|
||||
import ${package.Service}.${table.serviceName};
|
||||
import ${superServiceImplClassPackage};
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* $!{table.comment} 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Service
|
||||
#if(${kotlin})
|
||||
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} {
|
||||
|
||||
}
|
||||
#else
|
||||
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {
|
||||
|
||||
}
|
||||
#end
|
||||
@@ -0,0 +1,32 @@
|
||||
package ${cfg.PackageParent}#if(${package.ModuleName}).${package.ModuleName}#end.api.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* $!{table.comment} 实体VO
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Data
|
||||
public class ${className}Vo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
private String id;
|
||||
private Integer status;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
## ---------- BEGIN 字段循环遍历 ----------
|
||||
#foreach($field in ${table.fields})
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
## ---------- END 字段循环遍历 ----------
|
||||
}
|
||||
19
studio/modules/codegen-service-parent/pom.xml
Normal file
19
studio/modules/codegen-service-parent/pom.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<artifactId>modules</artifactId>
|
||||
<groupId>com.platform</groupId>
|
||||
<version>0.4.x</version>
|
||||
</parent>
|
||||
<packaging>pom</packaging>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>0.4.x</version>
|
||||
<artifactId>codegen-service-parent</artifactId>
|
||||
|
||||
<modules>
|
||||
<module>codegen-service</module>
|
||||
<module>codegen-service-api</module>
|
||||
</modules>
|
||||
</project>
|
||||
Reference in New Issue
Block a user