Compare commits
26 Commits
dev-gatewa
...
hzm-gatewa
| Author | SHA1 | Date | |
|---|---|---|---|
| 01d67d2af5 | |||
|
|
9c162e611c | ||
|
|
6d39805d17 | ||
|
|
92b772373b | ||
|
|
8f433a2594 | ||
|
|
e0db7a251c | ||
|
|
84bb7410cf | ||
|
|
2d75478bb7 | ||
|
|
5e47425ab5 | ||
|
|
a4d6306259 | ||
|
|
852eb05cbf | ||
|
|
90f98d66cc | ||
|
|
bf6e0dd952 | ||
|
|
04da9f9c02 | ||
|
|
b4525cd1a6 | ||
|
|
b51f113053 | ||
|
|
685cc3d92c | ||
|
|
e512fc29e0 | ||
|
|
5d19f5589a | ||
|
|
d6be017f37 | ||
|
|
db5bda1bba | ||
|
|
c9929c84d2 | ||
|
|
f91ecee6cc | ||
|
|
142c24ca90 | ||
|
|
a59dd25156 | ||
|
|
a3ec97fec1 |
@@ -9,11 +9,6 @@
|
||||
<artifactId>agileboot-boot-start</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.agileboot</groupId>
|
||||
<artifactId>wol-common-web</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.agileboot</groupId>
|
||||
<artifactId>agileboot-system-base</artifactId>
|
||||
@@ -26,8 +21,32 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.agileboot</groupId>
|
||||
<artifactId>wol-common-satoken</artifactId>
|
||||
<artifactId>wol-auth</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.agileboot</groupId>
|
||||
<artifactId>wol-codegenerator</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${spring.boot.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
* @Author cuiJiaWang
|
||||
* @Create 2025-08-12 18:07
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@SpringBootApplication(scanBasePackages = "com.agileboot.*")
|
||||
public class AgilebootBootApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -59,12 +59,21 @@ spring:
|
||||
host: 121.41.64.98
|
||||
port: 6379
|
||||
password: 'Wyy123123'
|
||||
|
||||
|
||||
sa-token:
|
||||
# 是否输出操作日志
|
||||
is-log: true
|
||||
token-name: Authorization
|
||||
jasypt:
|
||||
encryptor:
|
||||
password: ${JASYPT_ENCRYPTOR_PASSWORD:}
|
||||
|
||||
# Sa-Token配置
|
||||
sa-token:
|
||||
# token名称 (同时也是cookie名称)
|
||||
token-name: Authorization
|
||||
# 开启内网服务调用鉴权(不允许越过gateway访问内网服务 保障服务安全)
|
||||
check-same-token: false
|
||||
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
|
||||
is-concurrent: true
|
||||
# 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token)
|
||||
is-share: true
|
||||
# 是否输出操作日志
|
||||
is-log: true
|
||||
# jwt秘钥
|
||||
jwt-secret-key: abcdefghijklmnopqrstuvwxyz
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
server:
|
||||
port: 8088
|
||||
port: 18080
|
||||
servlet:
|
||||
context-path: /api
|
||||
context-path: /
|
||||
tomcat:
|
||||
uri-encoding: UTF-8 # tomcat的URI编码
|
||||
accept-count: 1000 # 连接数满后的排队数,默认为100
|
||||
@@ -10,4 +10,4 @@ server:
|
||||
min-spare: 100 # Tomcat启动初始化的线程数,默认值10
|
||||
spring:
|
||||
profiles:
|
||||
active: dev
|
||||
active: dev
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>agileboot-cloud-start</module>
|
||||
<module>wol-gateway</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
server:
|
||||
port: 8080
|
||||
servlet:
|
||||
context-path: /
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: wol-gateway
|
||||
@@ -18,6 +18,7 @@
|
||||
<module>wol-common-redis</module>
|
||||
<module>wol-common-json</module>
|
||||
<module>wol-common-satoken</module>
|
||||
<module>wol-common-naocs</module>
|
||||
</modules>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
|
||||
39
agileboot-common/wol-common-naocs/pom.xml
Normal file
39
agileboot-common/wol-common-naocs/pom.xml
Normal file
@@ -0,0 +1,39 @@
|
||||
<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>
|
||||
<parent>
|
||||
<groupId>com.agileboot</groupId>
|
||||
<artifactId>agileboot-common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>wol-common-naocs</artifactId>
|
||||
|
||||
<name>wol-common-naocs</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 服务发现 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,14 @@
|
||||
spring:
|
||||
cloud:
|
||||
nacos:
|
||||
config:
|
||||
server-addr: http://192.168.12.168:8848 # 指定 Nacos 配置中心的服务器地址
|
||||
group: DEFAULT_GROUP # 所属组
|
||||
namespace: public # 命名空间
|
||||
file-extension: yaml # 配置文件格式
|
||||
refresh-enabled: true # 是否开启动态刷新
|
||||
discovery:
|
||||
enabled: true # 启用服务发现
|
||||
group: DEFAULT_GROUP # 所属组
|
||||
namespace: public # 命名空间
|
||||
server-addr: http://192.168.12.168:8848 # 指定 Nacos 配置中心的服务器地址
|
||||
@@ -9,6 +9,7 @@ import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.dev33.satoken.util.SaResult;
|
||||
import com.agileboot.common.core.constant.HttpStatus;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -21,6 +22,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
* @author Lion Li
|
||||
*/
|
||||
@AutoConfiguration
|
||||
@ConditionalOnClass(WebMvcConfigurer.class)
|
||||
public class SaTokenMvcConfiguration implements WebMvcConfigurer {
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
<modules>
|
||||
<module>wol-auth</module>
|
||||
<module>agileboot-system-base</module>
|
||||
<module>wol-gateway</module>
|
||||
<module>wol-codegenerator</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.agileboot.auth.config;
|
||||
|
||||
import com.agileboot.common.core.factory.YmlPropertySourceFactory;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
/**
|
||||
* @Author cuiJiaWang
|
||||
* @Create 2025-09-30 14:29
|
||||
*/
|
||||
@Configuration
|
||||
@PropertySource(value = "classpath:auth.yml", factory = YmlPropertySourceFactory.class)
|
||||
public class AuthConfig {
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.agileboot.auth.service.strategy;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.dev33.satoken.stp.parameter.SaLoginParameter;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.crypto.digest.BCrypt;
|
||||
import com.agileboot.auth.pojo.form.PasswordLoginBody;
|
||||
import com.agileboot.auth.pojo.vo.CurrentLoginUserVO;
|
||||
import com.agileboot.auth.pojo.vo.LoginVO;
|
||||
@@ -61,7 +62,7 @@ public class PasswordAuthStrategy implements IAuthStrategy {
|
||||
if (!Objects.equals(loginUser.getClientId(), clientId)) {
|
||||
throw new BizException("client.not.match");
|
||||
}
|
||||
loginService.checkLogin(LoginType.PASSWORD, null, loginUser.getUsername(), () -> false);
|
||||
loginService.checkLogin(LoginType.PASSWORD, null, loginUser.getUsername(), () -> !BCrypt.checkpw(password, loginUser.getPassword()));
|
||||
|
||||
loginUser.setClientKey(client.getClientKey());
|
||||
loginUser.setDeviceType(client.getDeviceType());
|
||||
|
||||
@@ -62,33 +62,6 @@ jasypt:
|
||||
encryptor:
|
||||
password: ${JASYPT_ENCRYPTOR_PASSWORD:}
|
||||
|
||||
user:
|
||||
password:
|
||||
# 密码最大错误次数
|
||||
maxRetryCount: 5
|
||||
# 密码锁定时间(默认10分钟)
|
||||
lockTime: 10
|
||||
|
||||
# 安全配置
|
||||
security:
|
||||
clientId: 1
|
||||
# 验证码
|
||||
captcha:
|
||||
# 是否开启验证码
|
||||
enabled: false
|
||||
# 验证码类型 math 数组计算 char 字符验证
|
||||
type: CHAR
|
||||
# line 线段干扰 circle 圆圈干扰 shear 扭曲干扰
|
||||
category: CIRCLE
|
||||
# 数字验证码位数
|
||||
numberLength: 0
|
||||
# 字符验证码长度
|
||||
charLength: 5
|
||||
# 注册
|
||||
register:
|
||||
phoneEnabled: false
|
||||
|
||||
|
||||
# redisson 配置
|
||||
#redisson:
|
||||
# # redis key前缀
|
||||
|
||||
25
agileboot-system/wol-auth/src/main/resources/auth.yml
Normal file
25
agileboot-system/wol-auth/src/main/resources/auth.yml
Normal file
@@ -0,0 +1,25 @@
|
||||
user:
|
||||
password:
|
||||
# 密码最大错误次数
|
||||
maxRetryCount: 5
|
||||
# 密码锁定时间(默认10分钟)
|
||||
lockTime: 10
|
||||
|
||||
# 安全配置
|
||||
security:
|
||||
clientId: 1
|
||||
# 验证码
|
||||
captcha:
|
||||
# 是否开启验证码
|
||||
enabled: false
|
||||
# 验证码类型 math 数组计算 char 字符验证
|
||||
type: CHAR
|
||||
# line 线段干扰 circle 圆圈干扰 shear 扭曲干扰
|
||||
category: CIRCLE
|
||||
# 数字验证码位数
|
||||
numberLength: 0
|
||||
# 字符验证码长度
|
||||
charLength: 5
|
||||
# 注册
|
||||
register:
|
||||
phoneEnabled: false
|
||||
36
agileboot-system/wol-codegenerator/pom.xml
Normal file
36
agileboot-system/wol-codegenerator/pom.xml
Normal file
@@ -0,0 +1,36 @@
|
||||
<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>
|
||||
<parent>
|
||||
<groupId>com.agileboot</groupId>
|
||||
<artifactId>agileboot-system</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>wol-codegenerator</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>wol-codegenerator</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.agileboot</groupId>
|
||||
<artifactId>wol-common-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.agileboot</groupId>
|
||||
<artifactId>wol-common-mybatis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Freemarker模板引擎 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-freemarker</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.agileboot.codegen;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @Author cuiJiaWang
|
||||
* @Create 2025-08-12 18:07
|
||||
*/
|
||||
@SpringBootApplication(scanBasePackages = "com.agileboot.*")
|
||||
public class CodeGenApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CodeGenApplication.class, args);
|
||||
String successMsg = " ____ _ _ __ _ _ \n"
|
||||
+ " / ___| | |_ __ _ _ __ | |_ _ _ _ __ ___ _ _ ___ ___ ___ ___ ___ / _| _ _ | || |\n"
|
||||
+ " \\___ \\ | __|/ _` || '__|| __| | | | || '_ \\ / __|| | | | / __|/ __|/ _ \\/ __|/ __|| |_ | | | || || |\n"
|
||||
+ " ___) || |_| (_| || | | |_ | |_| || |_) | \\__ \\| |_| || (__| (__| __/\\__ \\\\__ \\| _|| |_| || ||_|\n"
|
||||
+ " |____/ \\__|\\__,_||_| \\__| \\__,_|| .__/ |___/ \\__,_| \\___|\\___|\\___||___/|___/|_| \\__,_||_|(_)\n"
|
||||
+ " |_| ";
|
||||
|
||||
System.out.println(successMsg);
|
||||
System.out.println("(♥◠‿◠)ノ゙ 代码生成器启动成功 ლ(´ڡ`ლ)゙ ");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
package com.agileboot.codegen.controller;
|
||||
|
||||
import com.agileboot.codegen.dto.CodegenRequest;
|
||||
import com.agileboot.codegen.dto.TemplatePreviewRequest;
|
||||
import com.agileboot.codegen.service.IGeneratorService;
|
||||
import com.agileboot.codegen.service.ITemplateRepositoryService;
|
||||
import com.agileboot.codegen.service.ITemplateUsageLogService;
|
||||
import com.agileboot.common.core.core.R;
|
||||
import com.agileboot.common.satoken.utils.LoginHelper;
|
||||
import com.agileboot.common.core.utils.ServletHolderUtil;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author cuiJiaWang
|
||||
* @Create 2025-09-24 14:24
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/codegen")
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class GeneratorController {
|
||||
|
||||
private final IGeneratorService generatorService;
|
||||
private final ITemplateRepositoryService templateRepositoryService;
|
||||
private final ITemplateUsageLogService templateUsageLogService;
|
||||
|
||||
@GetMapping("/template/all")
|
||||
public R<?> getAllTemplates() {
|
||||
try {
|
||||
Long userId = LoginHelper.getUserId();
|
||||
JSONArray templates = templateRepositoryService.getUserTemplateConfig(userId);
|
||||
return R.ok(templates);
|
||||
} catch (Exception e) {
|
||||
log.warn("获取用户模板配置失败,使用系统默认配置", e);
|
||||
// 降级到系统默认模板
|
||||
String templates = generatorService.getTemplateConfig();
|
||||
JSONArray jsonArray = JSONArray.parseArray(templates);
|
||||
return R.ok(jsonArray);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/code/generate")
|
||||
public R<?> generateCode(@RequestBody CodegenRequest request) {
|
||||
try {
|
||||
log.info("开始生成代码,表SQL: {}", request.getTableSql());
|
||||
|
||||
// 合并请求参数
|
||||
Map<String, Object> options = new HashMap<>();
|
||||
if (request.getOptions() != null) {
|
||||
options.putAll(request.getOptions());
|
||||
}
|
||||
options.put("tableSql", request.getTableSql());
|
||||
|
||||
// 获取用户的模板配置
|
||||
Long userId = LoginHelper.getUserId();
|
||||
JSONArray userTemplateConfig = templateRepositoryService.getUserTemplateConfig(userId);
|
||||
|
||||
// 调用服务生成代码
|
||||
Map<String, String> result = generatorService.getResultByParams(options, userTemplateConfig.toJSONString());
|
||||
|
||||
// 检查是否有错误
|
||||
if (result.containsKey("error")) {
|
||||
String errorMsg = result.get("error");
|
||||
log.warn("代码生成失败: {}", errorMsg);
|
||||
return R.fail(errorMsg);
|
||||
}
|
||||
|
||||
// 记录模板使用日志
|
||||
try {
|
||||
String ipAddress = ServletHolderUtil.getClientIp();
|
||||
|
||||
// 从请求参数中获取使用的模板信息
|
||||
if (options.containsKey("selectedTemplates")) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> selectedTemplates = (Map<String, Object>) options.get("selectedTemplates");
|
||||
for (Map.Entry<String, Object> entry : selectedTemplates.entrySet()) {
|
||||
String templateId = entry.getKey();
|
||||
String templateName = entry.getValue().toString();
|
||||
|
||||
// 判断模板来源
|
||||
String templateSource = templateId.matches("\\d+") ? "system" : "user";
|
||||
|
||||
templateUsageLogService.logTemplateUsage(userId, templateSource, templateId,
|
||||
templateName, "unknown", ipAddress);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("记录模板使用日志失败", e);
|
||||
}
|
||||
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("outputJson", result);
|
||||
response.put("tableName", result.get("tableName"));
|
||||
|
||||
log.info("代码生成完成,表名: {}", result.get("tableName"));
|
||||
return R.ok(response);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("生成代码失败", e);
|
||||
return R.fail("生成代码失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/template/content")
|
||||
public R<String> getTemplateContent(@RequestParam("templateSource") String templateSource,
|
||||
@RequestParam("templateId") String templateId) {
|
||||
try {
|
||||
String content = generatorService.getTemplateContentBySource(templateSource, templateId);
|
||||
return R.ok("获取成功", content);
|
||||
} catch (Exception e) {
|
||||
log.error("获取模板内容失败", e);
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/template/preview")
|
||||
public R<?> previewTemplateGet(@RequestParam("templateSource") String templateSource,
|
||||
@RequestParam("templateId") String templateId,
|
||||
@RequestParam(value = "tableSql", required = false) String tableSql,
|
||||
@RequestParam(value = "templateContent", required = false) String templateContent,
|
||||
@RequestParam(value = "authorName", required = false) String authorName) {
|
||||
try {
|
||||
log.info("开始预览模板(GET),模板来源: {}, 模板ID: {}", templateSource, templateId);
|
||||
|
||||
// 参数验证
|
||||
if (templateSource == null || templateId == null) {
|
||||
return R.fail("模板来源和模板ID不能为空");
|
||||
}
|
||||
|
||||
// 如果没有提供tableSql,使用默认的示例SQL
|
||||
if (tableSql == null || tableSql.trim().isEmpty()) {
|
||||
tableSql = "CREATE TABLE `user` (\n" +
|
||||
" `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',\n" +
|
||||
" `username` varchar(50) NOT NULL COMMENT '用户名',\n" +
|
||||
" `password` varchar(100) NOT NULL COMMENT '密码',\n" +
|
||||
" `email` varchar(100) DEFAULT NULL COMMENT '邮箱',\n" +
|
||||
" `phone` varchar(20) DEFAULT NULL COMMENT '手机号',\n" +
|
||||
" `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态(0-禁用 1-启用)',\n" +
|
||||
" `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',\n" +
|
||||
" `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',\n" +
|
||||
" PRIMARY KEY (`id`),\n" +
|
||||
" UNIQUE KEY `uk_username` (`username`)\n" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户表';";
|
||||
log.info("使用默认示例SQL进行模板预览");
|
||||
}
|
||||
|
||||
// 构建选项参数
|
||||
Map<String, Object> options = new HashMap<>();
|
||||
options.put("tableSql", tableSql);
|
||||
if (authorName != null && !authorName.trim().isEmpty()) {
|
||||
options.put("authorName", authorName);
|
||||
}
|
||||
|
||||
// 调用生成服务预览单个模板
|
||||
String previewResult = generatorService.previewSingleTemplate(
|
||||
templateSource,
|
||||
templateId,
|
||||
templateContent,
|
||||
options);
|
||||
|
||||
log.info("模板预览完成(GET),模板来源: {}, 模板ID: {}", templateSource, templateId);
|
||||
return R.ok("预览成功", previewResult);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("预览模板失败(GET)", e);
|
||||
return R.fail("预览模板失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/template/preview")
|
||||
public R<?> previewTemplate(@RequestBody TemplatePreviewRequest request) {
|
||||
try {
|
||||
log.info("开始预览模板,模板来源: {}, 模板ID: {}", request.getTemplateSource(), request.getTemplateId());
|
||||
|
||||
// 参数验证
|
||||
if (request.getTemplateSource() == null || request.getTemplateId() == null) {
|
||||
return R.fail("模板来源和模板ID不能为空");
|
||||
}
|
||||
|
||||
if (request.getTableSql() == null || request.getTableSql().trim().isEmpty()) {
|
||||
return R.fail("表SQL语句不能为空");
|
||||
}
|
||||
|
||||
// 合并请求参数
|
||||
Map<String, Object> options = new HashMap<>();
|
||||
if (request.getOptions() != null) {
|
||||
options.putAll(request.getOptions());
|
||||
}
|
||||
options.put("tableSql", request.getTableSql());
|
||||
|
||||
// 调用生成服务预览单个模板
|
||||
String previewResult = generatorService.previewSingleTemplate(
|
||||
request.getTemplateSource(),
|
||||
request.getTemplateId(),
|
||||
request.getTemplateContent(),
|
||||
options);
|
||||
|
||||
log.info("模板预览完成,模板来源: {}, 模板ID: {}", request.getTemplateSource(), request.getTemplateId());
|
||||
return R.ok("预览成功", previewResult);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("预览模板失败", e);
|
||||
return R.fail("预览模板失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package com.agileboot.codegen.controller;
|
||||
|
||||
import com.agileboot.codegen.dto.TemplateRepositoryDTO;
|
||||
import com.agileboot.codegen.entity.UserTemplateRepository;
|
||||
import com.agileboot.codegen.service.ITemplateRepositoryService;
|
||||
import com.agileboot.common.core.core.R;
|
||||
import com.agileboot.common.satoken.utils.LoginHelper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 模板仓库管理 Controller
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-09-26
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/codegen/repository")
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class TemplateRepositoryController {
|
||||
|
||||
private final ITemplateRepositoryService templateRepositoryService;
|
||||
|
||||
/**
|
||||
* 获取用户的模板仓库列表(用于仓库管理界面)
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public R<List<UserTemplateRepository>> getUserRepositoryList() {
|
||||
Long userId = LoginHelper.getUserId();
|
||||
List<UserTemplateRepository> result = templateRepositoryService.getUserRepositoryList(userId);
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有可用模板(系统模板+公开用户模板)
|
||||
*/
|
||||
@GetMapping("/available")
|
||||
public R<List<TemplateRepositoryDTO>> getAvailableTemplates() {
|
||||
Long userId = LoginHelper.getUserId();
|
||||
List<TemplateRepositoryDTO> result = templateRepositoryService.getAvailableTemplates(userId);
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加模板到用户仓库
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public R<Void> addTemplateToRepository(@RequestBody TemplateRepositoryDTO dto) {
|
||||
try {
|
||||
Long userId = LoginHelper.getUserId();
|
||||
boolean success = templateRepositoryService.addTemplateToRepository(
|
||||
userId, dto.getTemplateSource(), dto.getTemplateId(),
|
||||
dto.getTemplateName(), dto.getTemplateGroup());
|
||||
|
||||
return success ? R.ok() : R.fail("添加模板到仓库失败");
|
||||
} catch (Exception e) {
|
||||
log.error("添加模板到仓库失败", e);
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 切换模板启用状态
|
||||
*/
|
||||
@PostMapping("/toggle")
|
||||
public R<Void> toggleTemplateStatus(@RequestBody Map<String, Object> params) {
|
||||
try {
|
||||
String templateSource = params.get("templateSource").toString();
|
||||
String templateId = params.get("templateId").toString();
|
||||
Integer isEnabled = Integer.parseInt(params.get("isEnabled").toString());
|
||||
Long userId = LoginHelper.getUserId();
|
||||
boolean success = templateRepositoryService.toggleTemplateStatus(userId, templateSource, templateId, isEnabled);
|
||||
|
||||
return success ? R.ok() : R.fail("切换模板状态失败");
|
||||
} catch (Exception e) {
|
||||
log.error("切换模板状态失败", e);
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新模板排序
|
||||
*/
|
||||
@PostMapping("/sort")
|
||||
public R<Void> updateTemplateSort(@RequestBody List<TemplateRepositoryDTO> templates) {
|
||||
try {
|
||||
Long userId = LoginHelper.getUserId();
|
||||
boolean success = templateRepositoryService.updateTemplateSort(userId, templates);
|
||||
|
||||
return success ? R.ok() : R.fail("更新模板排序失败");
|
||||
} catch (Exception e) {
|
||||
log.error("更新模板排序失败", e);
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化用户模板仓库
|
||||
*/
|
||||
@PostMapping("/init")
|
||||
public R<Void> initUserRepository() {
|
||||
try {
|
||||
Long userId = LoginHelper.getUserId();
|
||||
boolean success = templateRepositoryService.initUserRepository(userId);
|
||||
|
||||
return success ? R.ok() : R.fail("初始化用户模板仓库失败");
|
||||
} catch (Exception e) {
|
||||
log.error("初始化用户模板仓库失败", e);
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查模板是否已添加到用户仓库
|
||||
*/
|
||||
@GetMapping("/check")
|
||||
public R<Boolean> checkTemplateExists(@RequestParam String templateSource,
|
||||
@RequestParam String templateId) {
|
||||
Long userId = LoginHelper.getUserId();
|
||||
boolean exists = templateRepositoryService.checkTemplateExists(userId, templateSource, templateId);
|
||||
return R.ok(exists);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
package com.agileboot.codegen.controller;
|
||||
|
||||
import com.agileboot.codegen.dto.UserTemplateDTO;
|
||||
import com.agileboot.codegen.entity.UserTemplate;
|
||||
import com.agileboot.codegen.service.IUserTemplateService;
|
||||
import com.agileboot.codegen.vo.UserTemplateVO;
|
||||
import com.agileboot.common.core.core.R;
|
||||
import com.agileboot.common.satoken.utils.LoginHelper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 用户模板管理 Controller
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-09-26
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/codegen/user-template")
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class UserTemplateController {
|
||||
|
||||
private final IUserTemplateService userTemplateService;
|
||||
|
||||
/**
|
||||
* 分页查询用户模板列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public R<Page<UserTemplateVO>> list(
|
||||
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
|
||||
@RequestParam(value = "templateGroup", required = false) String templateGroup,
|
||||
@RequestParam(value = "isPublic", required = false) Integer isPublic) {
|
||||
|
||||
Long userId = LoginHelper.getUserId();
|
||||
Page<UserTemplate> page = new Page<>(pageNum, pageSize);
|
||||
Page<UserTemplateVO> result = userTemplateService.selectUserTemplateList(page, userId, templateGroup, isPublic);
|
||||
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询公开模板列表
|
||||
*/
|
||||
@GetMapping("/public")
|
||||
public R<List<UserTemplateVO>> getPublicTemplates(
|
||||
@RequestParam(value = "templateGroup", required = false) String templateGroup) {
|
||||
|
||||
Long currentUserId = LoginHelper.getUserId();
|
||||
List<UserTemplateVO> result = userTemplateService.selectPublicTemplates(templateGroup, currentUserId);
|
||||
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询用户模板详情
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public R<UserTemplateVO> getById(@PathVariable Long id) {
|
||||
UserTemplateVO template = userTemplateService.selectUserTemplateById(id);
|
||||
if (template == null) {
|
||||
return R.fail("模板不存在");
|
||||
}
|
||||
|
||||
// 检查权限:只能查看公开模板或自己的模板
|
||||
Long currentUserId = LoginHelper.getUserId();
|
||||
if (template.getIsPublic() != 1 && !currentUserId.equals(template.getUserId())) {
|
||||
return R.fail("无权限查看此模板");
|
||||
}
|
||||
|
||||
return R.ok(template);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增用户模板
|
||||
*/
|
||||
@PostMapping
|
||||
public R<Void> add(@Validated @RequestBody UserTemplateDTO dto) {
|
||||
try {
|
||||
boolean success = userTemplateService.insertUserTemplate(dto);
|
||||
return success ? R.ok() : R.fail("新增模板失败");
|
||||
} catch (Exception e) {
|
||||
log.error("新增用户模板失败", e);
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户模板
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
public R<Void> update(@Validated @RequestBody UserTemplateDTO dto) {
|
||||
try {
|
||||
boolean success = userTemplateService.updateUserTemplate(dto);
|
||||
return success ? R.ok() : R.fail("修改模板失败");
|
||||
} catch (Exception e) {
|
||||
log.error("修改用户模板失败", e);
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户模板
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public R<Void> remove(@RequestBody Map<String, Object> params) {
|
||||
try {
|
||||
Long id = Long.parseLong(params.get("id").toString());
|
||||
boolean success = userTemplateService.deleteUserTemplateById(id);
|
||||
return success ? R.ok() : R.fail("删除模板失败");
|
||||
} catch (Exception e) {
|
||||
log.error("删除用户模板失败", e);
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除用户模板
|
||||
*/
|
||||
@PostMapping("/delete/batch")
|
||||
public R<Void> removeBatch(@RequestBody Map<String, Object> params) {
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> idsObj = (List<Object>) params.get("ids");
|
||||
Long[] ids = idsObj.stream()
|
||||
.map(obj -> {
|
||||
if (obj instanceof Integer) {
|
||||
return ((Integer) obj).longValue();
|
||||
} else if (obj instanceof Long) {
|
||||
return (Long) obj;
|
||||
} else if (obj instanceof String) {
|
||||
return Long.parseLong((String) obj);
|
||||
} else {
|
||||
throw new RuntimeException("不支持的ID类型: " + obj.getClass());
|
||||
}
|
||||
})
|
||||
.toArray(Long[]::new);
|
||||
boolean success = userTemplateService.deleteUserTemplateByIds(ids);
|
||||
return success ? R.ok() : R.fail("批量删除模板失败");
|
||||
} catch (Exception e) {
|
||||
log.error("批量删除用户模板失败", e);
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制模板
|
||||
*/
|
||||
@PostMapping("/copy")
|
||||
public R<Void> copyTemplate(@RequestBody Map<String, Object> params) {
|
||||
try {
|
||||
Long templateId = Long.parseLong(params.get("templateId").toString());
|
||||
String newName = params.get("newName").toString();
|
||||
boolean success = userTemplateService.copyTemplate(templateId, newName);
|
||||
return success ? R.ok() : R.fail("复制模板失败");
|
||||
} catch (Exception e) {
|
||||
log.error("复制模板失败", e);
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证模板语法
|
||||
*/
|
||||
@PostMapping("/validate")
|
||||
public R<String> validateTemplate(@RequestBody String templateContent) {
|
||||
String result = userTemplateService.validateTemplate(templateContent);
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查模板名称是否存在
|
||||
*/
|
||||
@GetMapping("/check-name")
|
||||
public R<Boolean> checkTemplateName(@RequestParam(value = "templateName") String templateName,
|
||||
@RequestParam(value = "excludeId", required = false) Long excludeId) {
|
||||
Long userId = LoginHelper.getUserId();
|
||||
boolean exists = userTemplateService.checkTemplateNameExists(userId, templateName, excludeId);
|
||||
return R.ok(exists);
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换用户模板显示状态
|
||||
*/
|
||||
@PostMapping("/toggle-visibility")
|
||||
public R<Void> toggleTemplateVisibility(@RequestBody Map<String, Object> params) {
|
||||
try {
|
||||
Long id = Long.parseLong(params.get("id").toString());
|
||||
Integer isEnabled = Integer.parseInt(params.get("isEnabled").toString());
|
||||
boolean success = userTemplateService.toggleTemplateVisibility(id, isEnabled);
|
||||
return success ? R.ok() : R.fail("切换显示状态失败");
|
||||
} catch (Exception e) {
|
||||
log.error("切换用户模板显示状态失败", e);
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模板内容
|
||||
*/
|
||||
@GetMapping("/content/{id}")
|
||||
public R<String> getTemplateContent(@PathVariable("id") Long id) {
|
||||
try {
|
||||
String content = userTemplateService.getTemplateContent(id);
|
||||
return R.ok("获取成功", content);
|
||||
} catch (Exception e) {
|
||||
log.error("获取模板内容失败", e);
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.agileboot.codegen.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 代码生成请求DTO
|
||||
*/
|
||||
@Data
|
||||
public class CodegenRequest {
|
||||
|
||||
/**
|
||||
* 表SQL语句
|
||||
*/
|
||||
private String tableSql;
|
||||
|
||||
/**
|
||||
* 生成选项
|
||||
*/
|
||||
private Map<String, Object> options;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.agileboot.codegen.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 模板预览请求DTO
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-09-27
|
||||
*/
|
||||
@Data
|
||||
public class TemplatePreviewRequest {
|
||||
|
||||
/**
|
||||
* 模板来源(system-系统模板, user-用户模板)
|
||||
*/
|
||||
private String templateSource;
|
||||
|
||||
/**
|
||||
* 模板ID
|
||||
*/
|
||||
private String templateId;
|
||||
|
||||
/**
|
||||
* 表SQL语句
|
||||
*/
|
||||
private String tableSql;
|
||||
|
||||
/**
|
||||
* 生成选项
|
||||
*/
|
||||
private Map<String, Object> options;
|
||||
|
||||
/**
|
||||
* 模板内容(当templateSource为content时使用)
|
||||
*/
|
||||
private String templateContent;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.agileboot.codegen.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 模板仓库数据传输对象
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-09-26
|
||||
*/
|
||||
@Data
|
||||
public class TemplateRepositoryDTO {
|
||||
|
||||
/**
|
||||
* 模板来源(system-系统模板 user-用户模板)
|
||||
*/
|
||||
private String templateSource;
|
||||
|
||||
/**
|
||||
* 模板ID
|
||||
*/
|
||||
private String templateId;
|
||||
|
||||
/**
|
||||
* 模板名称
|
||||
*/
|
||||
private String templateName;
|
||||
|
||||
/**
|
||||
* 模板分组
|
||||
*/
|
||||
private String templateGroup;
|
||||
|
||||
/**
|
||||
* 模板描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 是否启用显示(0-隐藏 1-显示)
|
||||
*/
|
||||
private Integer isEnabled;
|
||||
|
||||
/**
|
||||
* 显示排序
|
||||
*/
|
||||
private Integer sortOrder;
|
||||
|
||||
/**
|
||||
* 批量操作的模板列表
|
||||
*/
|
||||
private List<TemplateRepositoryDTO> templates;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.agileboot.codegen.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 用户模板数据传输对象
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-09-26
|
||||
*/
|
||||
@Data
|
||||
public class UserTemplateDTO {
|
||||
|
||||
/**
|
||||
* 模板ID(更新时使用)
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 模板名称
|
||||
*/
|
||||
private String templateName;
|
||||
|
||||
/**
|
||||
* 模板分组
|
||||
*/
|
||||
private String templateGroup;
|
||||
|
||||
/**
|
||||
* 模板内容
|
||||
*/
|
||||
private String templateContent;
|
||||
|
||||
/**
|
||||
* 模板描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 是否公开(0-私有 1-公开)
|
||||
*/
|
||||
private Integer isPublic;
|
||||
|
||||
/**
|
||||
* 模板版本
|
||||
*/
|
||||
private String version;
|
||||
|
||||
/**
|
||||
* 状态(0-草稿 1-发布 2-禁用)
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 是否启用显示(0-隐藏 1-显示)
|
||||
*/
|
||||
private Integer isEnabled;
|
||||
|
||||
/**
|
||||
* 模板内容是否公开(0-不公开 1-公开)
|
||||
*/
|
||||
private Integer isContentPublic;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.agileboot.codegen.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 类信息实体
|
||||
*/
|
||||
@Data
|
||||
public class ClassInfo {
|
||||
|
||||
/**
|
||||
* 表名
|
||||
*/
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 原始表名
|
||||
*/
|
||||
private String originTableName;
|
||||
|
||||
/**
|
||||
* 类名
|
||||
*/
|
||||
private String className;
|
||||
|
||||
/**
|
||||
* 类注释
|
||||
*/
|
||||
private String classComment;
|
||||
|
||||
/**
|
||||
* 字段列表
|
||||
*/
|
||||
private List<FieldInfo> fieldList;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.agileboot.codegen.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 字段信息实体
|
||||
*/
|
||||
@Data
|
||||
public class FieldInfo {
|
||||
|
||||
/**
|
||||
* 数据库列名
|
||||
*/
|
||||
private String columnName;
|
||||
|
||||
/**
|
||||
* Java字段名
|
||||
*/
|
||||
private String fieldName;
|
||||
|
||||
/**
|
||||
* Java字段类型
|
||||
*/
|
||||
private String fieldClass;
|
||||
|
||||
/**
|
||||
* Swagger类型
|
||||
*/
|
||||
private String swaggerClass;
|
||||
|
||||
/**
|
||||
* 字段注释
|
||||
*/
|
||||
private String fieldComment;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.agileboot.codegen.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 参数信息实体
|
||||
*/
|
||||
@Data
|
||||
public class ParamInfo {
|
||||
|
||||
/**
|
||||
* 表SQL语句
|
||||
*/
|
||||
private String tableSql;
|
||||
|
||||
/**
|
||||
* 生成选项
|
||||
*/
|
||||
private Map<String, Object> options;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.agileboot.codegen.entity;
|
||||
|
||||
import com.agileboot.common.mybatis.core.domain.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 模板使用日志实体类
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-09-26
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("template_usage_log")
|
||||
public class TemplateUsageLog extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 使用者ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 模板来源(system-系统模板 user-用户模板)
|
||||
*/
|
||||
private String templateSource;
|
||||
|
||||
/**
|
||||
* 模板ID
|
||||
*/
|
||||
private String templateId;
|
||||
|
||||
/**
|
||||
* 模板名称
|
||||
*/
|
||||
private String templateName;
|
||||
|
||||
/**
|
||||
* 模板分组
|
||||
*/
|
||||
private String templateGroup;
|
||||
|
||||
/**
|
||||
* IP地址
|
||||
*/
|
||||
private String ipAddress;
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.agileboot.codegen.entity;
|
||||
|
||||
import com.agileboot.common.mybatis.core.domain.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 用户自定义模板实体类
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-09-26
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("user_template")
|
||||
public class UserTemplate extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 模板名称
|
||||
*/
|
||||
private String templateName;
|
||||
|
||||
/**
|
||||
* 模板分组
|
||||
*/
|
||||
private String templateGroup;
|
||||
|
||||
/**
|
||||
* 模板内容(FreeMarker模板)
|
||||
*/
|
||||
private String templateContent;
|
||||
|
||||
/**
|
||||
* 模板描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 是否公开(0-私有 1-公开)
|
||||
*/
|
||||
private Integer isPublic;
|
||||
|
||||
/**
|
||||
* 模板版本
|
||||
*/
|
||||
private String version;
|
||||
|
||||
/**
|
||||
* 使用次数统计
|
||||
*/
|
||||
private Integer useCount;
|
||||
|
||||
/**
|
||||
* 状态(0-草稿 1-发布 2-禁用)
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 是否启用显示(0-隐藏 1-显示)
|
||||
*/
|
||||
private Integer isEnabled;
|
||||
|
||||
/**
|
||||
* 模板内容是否公开(0-不公开 1-公开)
|
||||
*/
|
||||
private Integer isContentPublic;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.agileboot.codegen.entity;
|
||||
|
||||
import com.agileboot.common.mybatis.core.domain.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 用户模板仓库配置实体类
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-09-26
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("user_template_repository")
|
||||
public class UserTemplateRepository extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 模板来源(system-系统模板 user-用户模板)
|
||||
*/
|
||||
private String templateSource;
|
||||
|
||||
/**
|
||||
* 模板ID(系统模板用template.json中的id,用户模板用user_template.id)
|
||||
*/
|
||||
private String templateId;
|
||||
|
||||
/**
|
||||
* 模板名称(冗余字段便于查询)
|
||||
*/
|
||||
private String templateName;
|
||||
|
||||
/**
|
||||
* 模板分组(冗余字段便于查询)
|
||||
*/
|
||||
private String templateGroup;
|
||||
|
||||
/**
|
||||
* 是否启用显示(0-隐藏 1-显示)
|
||||
*/
|
||||
private Integer isEnabled;
|
||||
|
||||
/**
|
||||
* 显示排序(数字越小越靠前)
|
||||
*/
|
||||
private Integer sortOrder;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.agileboot.codegen.mapper;
|
||||
|
||||
import com.agileboot.codegen.entity.TemplateUsageLog;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 模板使用日志 Mapper接口
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-09-26
|
||||
*/
|
||||
@Mapper
|
||||
public interface TemplateUsageLogMapper extends BaseMapper<TemplateUsageLog> {
|
||||
|
||||
/**
|
||||
* 查询用户的模板使用历史
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @param limit 限制数量
|
||||
* @return 使用日志列表
|
||||
*/
|
||||
@Select("SELECT * FROM template_usage_log WHERE user_id = #{userId} ORDER BY create_time DESC LIMIT 100")
|
||||
List<TemplateUsageLog> selectUserUsageHistory(@Param("userId") Long userId,
|
||||
@Param("startTime") LocalDateTime startTime,
|
||||
@Param("endTime") LocalDateTime endTime,
|
||||
@Param("limit") Integer limit);
|
||||
|
||||
/**
|
||||
* 查询模板使用统计
|
||||
*
|
||||
* @param templateSource 模板来源
|
||||
* @param templateId 模板ID
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @return 使用次数
|
||||
*/
|
||||
@Select("SELECT COUNT(*) FROM template_usage_log WHERE template_source = #{templateSource} AND template_id = #{templateId}")
|
||||
int countTemplateUsage(@Param("templateSource") String templateSource,
|
||||
@Param("templateId") String templateId,
|
||||
@Param("startTime") LocalDateTime startTime,
|
||||
@Param("endTime") LocalDateTime endTime);
|
||||
|
||||
/**
|
||||
* 查询热门模板统计
|
||||
*
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @param limit 限制数量
|
||||
* @return 模板使用统计列表
|
||||
*/
|
||||
@Select("SELECT template_source, template_id, template_name, template_group, COUNT(*) as use_count " +
|
||||
"FROM template_usage_log " +
|
||||
"GROUP BY template_source, template_id, template_name, template_group " +
|
||||
"ORDER BY use_count DESC LIMIT 10")
|
||||
List<TemplateUsageLog> selectPopularTemplates(@Param("startTime") LocalDateTime startTime,
|
||||
@Param("endTime") LocalDateTime endTime,
|
||||
@Param("limit") Integer limit);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.agileboot.codegen.mapper;
|
||||
|
||||
import com.agileboot.codegen.entity.UserTemplate;
|
||||
import com.agileboot.common.mybatis.mapper.BaseMapperDelete;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户模板 Mapper接口
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-09-26
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserTemplateMapper extends BaseMapperDelete<UserTemplate> {
|
||||
|
||||
/**
|
||||
* 查询公开模板列表
|
||||
*
|
||||
* @param templateGroup 模板分组(可选)
|
||||
* @return 公开模板列表
|
||||
*/
|
||||
@Select("SELECT * FROM user_template WHERE is_public = 1 AND status = 1 AND deleted = 0 ORDER BY use_count DESC, create_time DESC")
|
||||
List<UserTemplate> selectPublicTemplates(@Param("templateGroup") String templateGroup);
|
||||
|
||||
/**
|
||||
* 检查模板名称是否存在(同一用户下)
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param templateName 模板名称
|
||||
* @param excludeId 排除的模板ID(更新时使用)
|
||||
* @return 存在的数量
|
||||
*/
|
||||
@Select("SELECT COUNT(*) FROM user_template WHERE user_id = #{userId} AND template_name = #{templateName} AND deleted = 0 AND (#{excludeId} IS NULL OR id != #{excludeId})")
|
||||
int checkTemplateNameExists(@Param("userId") Long userId,
|
||||
@Param("templateName") String templateName,
|
||||
@Param("excludeId") Long excludeId);
|
||||
|
||||
/**
|
||||
* 增加模板使用次数
|
||||
*
|
||||
* @param id 模板ID
|
||||
* @return 更新行数
|
||||
*/
|
||||
@Update("UPDATE user_template SET use_count = use_count + 1 WHERE id = #{id}")
|
||||
int increaseUseCount(@Param("id") Long id);
|
||||
|
||||
/**
|
||||
* 根据用户ID和状态查询模板数量
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param status 状态
|
||||
* @return 模板数量
|
||||
*/
|
||||
@Select("SELECT COUNT(*) FROM user_template WHERE user_id = #{userId} AND status = #{status} AND deleted = 0")
|
||||
int countByUserIdAndStatus(@Param("userId") Long userId, @Param("status") Integer status);
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package com.agileboot.codegen.mapper;
|
||||
|
||||
import com.agileboot.codegen.entity.UserTemplateRepository;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户模板仓库 Mapper接口
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-09-26
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserTemplateRepositoryMapper extends BaseMapper<UserTemplateRepository> {
|
||||
|
||||
/**
|
||||
* 查询用户的模板仓库配置
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 模板仓库配置列表
|
||||
*/
|
||||
@Select("SELECT r.* FROM user_template_repository r " +
|
||||
"LEFT JOIN user_template ut ON r.template_source = 'user' AND r.template_id = CAST(ut.id AS CHAR) COLLATE utf8mb4_unicode_ci " +
|
||||
"WHERE r.user_id = #{userId} AND r.is_enabled = 1 " +
|
||||
"AND (r.template_source != 'user' OR (ut.id IS NOT NULL AND ut.deleted = 0)) " +
|
||||
"ORDER BY r.sort_order ASC, r.create_time ASC")
|
||||
List<UserTemplateRepository> selectEnabledByUserId(@Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 查询用户的所有模板仓库配置(包括禁用的)
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 模板仓库配置列表
|
||||
*/
|
||||
@Select("SELECT r.* FROM user_template_repository r " +
|
||||
"LEFT JOIN user_template ut ON r.template_source = 'user' AND r.template_id = CAST(ut.id AS CHAR) COLLATE utf8mb4_unicode_ci " +
|
||||
"WHERE r.user_id = #{userId} " +
|
||||
"AND (r.template_source != 'user' OR (ut.id IS NOT NULL AND ut.deleted = 0)) " +
|
||||
"ORDER BY r.sort_order ASC, r.create_time ASC")
|
||||
List<UserTemplateRepository> selectAllByUserId(@Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 根据模板信息查询用户仓库配置
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param templateSource 模板来源
|
||||
* @param templateId 模板ID
|
||||
* @return 模板仓库配置
|
||||
*/
|
||||
@Select("SELECT * FROM user_template_repository " +
|
||||
"WHERE user_id = #{userId} AND template_source = #{templateSource} AND template_id = #{templateId}")
|
||||
UserTemplateRepository selectByTemplate(@Param("userId") Long userId,
|
||||
@Param("templateSource") String templateSource,
|
||||
@Param("templateId") String templateId);
|
||||
|
||||
/**
|
||||
* 检查模板是否已添加到用户仓库
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param templateSource 模板来源
|
||||
* @param templateId 模板ID
|
||||
* @return 存在的数量
|
||||
*/
|
||||
@Select("SELECT COUNT(*) FROM user_template_repository " +
|
||||
"WHERE user_id = #{userId} AND template_source = #{templateSource} AND template_id = #{templateId}")
|
||||
int checkTemplateExists(@Param("userId") Long userId,
|
||||
@Param("templateSource") String templateSource,
|
||||
@Param("templateId") String templateId);
|
||||
|
||||
/**
|
||||
* 切换模板启用状态
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param templateSource 模板来源
|
||||
* @param templateId 模板ID
|
||||
* @param isEnabled 是否启用
|
||||
* @return 更新行数
|
||||
*/
|
||||
@Update("UPDATE user_template_repository SET is_enabled = #{isEnabled} " +
|
||||
"WHERE user_id = #{userId} AND template_source = #{templateSource} AND template_id = #{templateId}")
|
||||
int toggleTemplateStatus(@Param("userId") Long userId,
|
||||
@Param("templateSource") String templateSource,
|
||||
@Param("templateId") String templateId,
|
||||
@Param("isEnabled") Integer isEnabled);
|
||||
|
||||
/**
|
||||
* 批量更新模板排序
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param templateSource 模板来源
|
||||
* @param templateId 模板ID
|
||||
* @param sortOrder 排序值
|
||||
* @return 更新行数
|
||||
*/
|
||||
@Update("UPDATE user_template_repository SET sort_order = #{sortOrder} " +
|
||||
"WHERE user_id = #{userId} AND template_source = #{templateSource} AND template_id = #{templateId}")
|
||||
int updateSortOrder(@Param("userId") Long userId,
|
||||
@Param("templateSource") String templateSource,
|
||||
@Param("templateId") String templateId,
|
||||
@Param("sortOrder") Integer sortOrder);
|
||||
|
||||
/**
|
||||
* 删除用户模板仓库配置
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param templateSource 模板来源
|
||||
* @param templateId 模板ID
|
||||
* @return 删除行数
|
||||
*/
|
||||
@Delete("DELETE FROM user_template_repository " +
|
||||
"WHERE user_id = #{userId} AND template_source = #{templateSource} AND template_id = #{templateId}")
|
||||
int deleteByTemplate(@Param("userId") Long userId,
|
||||
@Param("templateSource") String templateSource,
|
||||
@Param("templateId") String templateId);
|
||||
|
||||
/**
|
||||
* 获取模板的最大排序值
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 最大排序值
|
||||
*/
|
||||
@Select("SELECT COALESCE(MAX(sort_order), 0) FROM user_template_repository WHERE user_id = #{userId}")
|
||||
int getMaxSortOrder(@Param("userId") Long userId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,373 @@
|
||||
package com.agileboot.codegen.service;
|
||||
|
||||
import com.agileboot.codegen.entity.ClassInfo;
|
||||
import com.agileboot.codegen.entity.UserTemplate;
|
||||
import com.agileboot.codegen.mapper.UserTemplateMapper;
|
||||
import com.agileboot.codegen.util.FreemarkerUtil;
|
||||
import com.agileboot.codegen.util.MapUtil;
|
||||
import com.agileboot.codegen.util.TableParseUtil;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Author cuiJiaWang
|
||||
* @Create 2025-09-24 14:31
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class GeneratorServiceImpl implements IGeneratorService {
|
||||
|
||||
private final UserTemplateMapper userTemplateMapper;
|
||||
private final IUserTemplateService userTemplateService;
|
||||
|
||||
@Override
|
||||
public String getTemplateConfig() {
|
||||
String templateConfig = "";
|
||||
try {
|
||||
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("template.json");
|
||||
if (inputStream != null) {
|
||||
templateConfig = new BufferedReader(new InputStreamReader(inputStream)).lines().collect(Collectors.joining(System.lineSeparator()));
|
||||
inputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("读取模板配置失败", e);
|
||||
}
|
||||
return templateConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getResultByParams(Map<String, Object> options) {
|
||||
// 使用默认的系统模板配置
|
||||
return getResultByParams(options, getTemplateConfig());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getResultByParams(Map<String, Object> options, String templateConfig) {
|
||||
Map<String, String> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
// 1. 解析SQL获取表结构信息
|
||||
String tableSql = MapUtil.getString(options, "tableSql");
|
||||
String ignorePrefix = MapUtil.getString(options, "ignorePrefix", "");
|
||||
String dataType = MapUtil.getString(options, "dataType", "sql");
|
||||
|
||||
if (StringUtils.isBlank(tableSql)) {
|
||||
log.error("SQL语句为空");
|
||||
result.put("error", "SQL语句不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
// 根据解析引擎类型选择不同的解析方法
|
||||
ClassInfo classInfo = null;
|
||||
try {
|
||||
switch (dataType) {
|
||||
case "sql":
|
||||
classInfo = TableParseUtil.parseTableSql(tableSql, ignorePrefix);
|
||||
break;
|
||||
case "select-sql":
|
||||
log.warn("SELECT SQL解析引擎暂未实现,使用DDL引擎降级处理");
|
||||
result.put("error", "SELECT SQL解析引擎暂未实现,请使用DDL SQL引擎或提供CREATE TABLE语句");
|
||||
return result;
|
||||
case "create-sql":
|
||||
log.warn("CREATE SQL@JSqlParser引擎暂未实现,使用DDL引擎降级处理");
|
||||
result.put("error", "CREATE SQL@JSqlParser引擎暂未实现,请使用DDL SQL@自研引擎");
|
||||
return result;
|
||||
case "json":
|
||||
log.warn("JSON解析引擎暂未实现,使用DDL引擎降级处理");
|
||||
result.put("error", "JSON解析引擎暂未实现,请使用DDL SQL引擎或提供CREATE TABLE语句");
|
||||
return result;
|
||||
case "insert-sql":
|
||||
log.warn("INSERT SQL解析引擎暂未实现,使用DDL引擎降级处理");
|
||||
result.put("error", "INSERT SQL解析引擎暂未实现,请使用DDL SQL引擎或提供CREATE TABLE语句");
|
||||
return result;
|
||||
default:
|
||||
log.warn("未知的解析引擎类型: {}", dataType);
|
||||
classInfo = TableParseUtil.parseTableSql(tableSql, ignorePrefix);
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("解析SQL失败,引擎类型: {}", dataType, e);
|
||||
result.put("error", "解析SQL失败: " + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
|
||||
if (classInfo == null) {
|
||||
log.error("解析SQL失败,无法获取表结构信息");
|
||||
result.put("error", "解析SQL失败,请检查SQL语句格式是否正确");
|
||||
return result;
|
||||
}
|
||||
|
||||
// 确保classComment不为空,提供默认值
|
||||
if (StringUtils.isBlank(classInfo.getClassComment())) {
|
||||
classInfo.setClassComment("数据表");
|
||||
log.info("表注释为空,使用默认值: 数据表");
|
||||
}
|
||||
|
||||
// 2. 设置生成参数
|
||||
options.put("classInfo", classInfo);
|
||||
options.put("tableName", classInfo.getTableName());
|
||||
options.put("authorName", MapUtil.getString(options, "authorName", "Wol"));
|
||||
|
||||
// 3. 根据模板配置生成代码
|
||||
JSONArray templateGroups = JSONArray.parseArray(templateConfig);
|
||||
|
||||
for (Object groupObj : templateGroups) {
|
||||
JSONObject group = (JSONObject) groupObj;
|
||||
String groupName = group.getString("group");
|
||||
JSONArray templates = group.getJSONArray("templates");
|
||||
|
||||
for (Object templateObj : templates) {
|
||||
JSONObject template = (JSONObject) templateObj;
|
||||
String templateId = template.getString("id");
|
||||
String templateName = template.getString("name");
|
||||
String templateSource = template.getString("source");
|
||||
|
||||
// 生成代码
|
||||
String generatedCode = generateCodeByTemplate(templateId, templateName, templateSource, groupName, options);
|
||||
result.put(templateName, generatedCode);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加表名信息
|
||||
result.put("tableName", classInfo.getTableName());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("生成代码失败", e);
|
||||
result.put("error", "生成代码失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据模板生成代码
|
||||
*/
|
||||
private String generateCodeByTemplate(String templateId, String templateName, String templateSource,
|
||||
String groupName, Map<String, Object> options) {
|
||||
try {
|
||||
if ("user".equals(templateSource)) {
|
||||
// 用户自定义模板:从数据库获取模板内容
|
||||
UserTemplate userTemplate = userTemplateMapper.selectById(Long.valueOf(templateId));
|
||||
if (userTemplate != null && StringUtils.isNotBlank(userTemplate.getTemplateContent())) {
|
||||
// 增加使用次数
|
||||
userTemplateService.increaseUseCount(Long.valueOf(templateId));
|
||||
return FreemarkerUtil.generateByContent(userTemplate.getTemplateContent(), options);
|
||||
} else {
|
||||
log.warn("用户模板不存在或内容为空: templateId={}", templateId);
|
||||
return "// 用户模板不存在或内容为空: " + templateId;
|
||||
}
|
||||
} else {
|
||||
// 系统模板:从文件系统获取
|
||||
String templatePath = groupName + "/" + templateName + ".ftl";
|
||||
if (FreemarkerUtil.templateExists(templatePath)) {
|
||||
return FreemarkerUtil.generateByTemplate(templatePath, options);
|
||||
} else {
|
||||
log.warn("系统模板文件不存在: {}", templatePath);
|
||||
return "// 系统模板文件不存在: " + templatePath;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("生成代码失败: templateId={}, templateName={}", templateId, templateName, e);
|
||||
return "// 生成失败: " + e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateContentBySource(String templateSource, String templateId) {
|
||||
try {
|
||||
if ("user".equals(templateSource)) {
|
||||
// 用户模板:从数据库获取
|
||||
return userTemplateService.getTemplateContent(Long.valueOf(templateId));
|
||||
} else if ("system".equals(templateSource)) {
|
||||
// 系统模板:从文件系统获取
|
||||
return getSystemTemplateContent(templateId);
|
||||
} else {
|
||||
throw new RuntimeException("不支持的模板来源: " + templateSource);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取模板内容失败: templateSource={}, templateId={}", templateSource, templateId, e);
|
||||
throw new RuntimeException("获取模板内容失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统模板内容
|
||||
*/
|
||||
private String getSystemTemplateContent(String templateId) {
|
||||
try {
|
||||
// 从template.json配置中找到对应模板的文件路径
|
||||
JSONArray allTemplates = JSONArray.parseArray(getTemplateConfig());
|
||||
for (Object groupObj : allTemplates) {
|
||||
JSONObject group = (JSONObject) groupObj;
|
||||
String groupName = group.getString("group");
|
||||
JSONArray templates = group.getJSONArray("templates");
|
||||
|
||||
for (Object templateObj : templates) {
|
||||
JSONObject template = (JSONObject) templateObj;
|
||||
if (templateId.equals(template.getString("id"))) {
|
||||
String templateName = template.getString("name");
|
||||
String templatePath = groupName + "/" + templateName + ".ftl";
|
||||
|
||||
// 读取模板文件内容
|
||||
return FreemarkerUtil.getTemplateContent(templatePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
return "// 系统模板不存在: " + templateId;
|
||||
} catch (Exception e) {
|
||||
log.error("获取系统模板内容失败", e);
|
||||
return "// 获取系统模板内容失败: " + e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String previewSingleTemplate(String templateSource, String templateId, String templateContent, Map<String, Object> options) {
|
||||
try {
|
||||
// 1. 解析SQL获取表结构信息
|
||||
String tableSql = MapUtil.getString(options, "tableSql");
|
||||
String ignorePrefix = MapUtil.getString(options, "ignorePrefix", "");
|
||||
String dataType = MapUtil.getString(options, "dataType", "sql");
|
||||
|
||||
if (StringUtils.isBlank(tableSql)) {
|
||||
log.error("SQL语句为空");
|
||||
return "// 错误: SQL语句不能为空";
|
||||
}
|
||||
|
||||
// 根据解析引擎类型选择不同的解析方法
|
||||
ClassInfo classInfo = null;
|
||||
try {
|
||||
switch (dataType) {
|
||||
case "sql":
|
||||
classInfo = TableParseUtil.parseTableSql(tableSql, ignorePrefix);
|
||||
break;
|
||||
case "select-sql":
|
||||
return "// 错误: SELECT SQL解析引擎暂未实现,请使用DDL SQL引擎或提供CREATE TABLE语句";
|
||||
case "create-sql":
|
||||
return "// 错误: CREATE SQL@JSqlParser引擎暂未实现,请使用DDL SQL@自研引擎";
|
||||
case "json":
|
||||
return "// 错误: JSON解析引擎暂未实现,请使用DDL SQL引擎或提供CREATE TABLE语句";
|
||||
case "insert-sql":
|
||||
return "// 错误: INSERT SQL解析引擎暂未实现,请使用DDL SQL引擎或提供CREATE TABLE语句";
|
||||
default:
|
||||
log.warn("未知的解析引擎类型: {}, 使用默认DDL引擎", dataType);
|
||||
classInfo = TableParseUtil.parseTableSql(tableSql, ignorePrefix);
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("解析SQL失败,引擎类型: {}", dataType, e);
|
||||
return "// 错误: 解析SQL失败: " + e.getMessage();
|
||||
}
|
||||
|
||||
if (classInfo == null) {
|
||||
log.error("解析SQL失败,无法获取表结构信息");
|
||||
return "// 错误: 解析SQL失败,请检查SQL语句格式是否正确";
|
||||
}
|
||||
|
||||
// 确保classComment不为空,提供默认值
|
||||
if (StringUtils.isBlank(classInfo.getClassComment())) {
|
||||
classInfo.setClassComment("数据表");
|
||||
log.info("表注释为空,使用默认值: 数据表");
|
||||
}
|
||||
|
||||
// 2. 设置生成参数
|
||||
options.put("classInfo", classInfo);
|
||||
options.put("tableName", classInfo.getTableName());
|
||||
options.put("authorName", MapUtil.getString(options, "authorName", "Wol"));
|
||||
|
||||
// 3. 根据模板来源生成代码
|
||||
String generatedCode;
|
||||
|
||||
switch (templateSource.toLowerCase()) {
|
||||
case "user":
|
||||
// 用户自定义模板:从数据库获取模板内容
|
||||
UserTemplate userTemplate = userTemplateMapper.selectById(Long.valueOf(templateId));
|
||||
if (userTemplate != null && StringUtils.isNotBlank(userTemplate.getTemplateContent())) {
|
||||
// 增加使用次数
|
||||
userTemplateService.increaseUseCount(Long.valueOf(templateId));
|
||||
generatedCode = FreemarkerUtil.generateByContent(userTemplate.getTemplateContent(), options);
|
||||
} else {
|
||||
log.warn("用户模板不存在或内容为空: templateId={}", templateId);
|
||||
generatedCode = "// 用户模板不存在或内容为空: " + templateId;
|
||||
}
|
||||
break;
|
||||
|
||||
case "system":
|
||||
// 系统模板:需要根据templateId查找对应的模板文件
|
||||
generatedCode = generateSystemTemplate(templateId, options);
|
||||
break;
|
||||
|
||||
case "content":
|
||||
// 直接使用提供的模板内容
|
||||
if (StringUtils.isNotBlank(templateContent)) {
|
||||
generatedCode = FreemarkerUtil.generateByContent(templateContent, options);
|
||||
} else {
|
||||
generatedCode = "// 错误: 模板内容为空";
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
generatedCode = "// 错误: 不支持的模板来源: " + templateSource;
|
||||
break;
|
||||
}
|
||||
|
||||
return generatedCode;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("预览模板失败: templateSource={}, templateId={}", templateSource, templateId, e);
|
||||
return "// 预览失败: " + e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成系统模板代码
|
||||
*/
|
||||
private String generateSystemTemplate(String templateId, Map<String, Object> options) {
|
||||
try {
|
||||
// 从系统模板配置中查找对应的模板信息
|
||||
String templateConfig = getTemplateConfig();
|
||||
JSONArray templateGroups = JSONArray.parseArray(templateConfig);
|
||||
|
||||
for (Object groupObj : templateGroups) {
|
||||
JSONObject group = (JSONObject) groupObj;
|
||||
String groupName = group.getString("group");
|
||||
JSONArray templates = group.getJSONArray("templates");
|
||||
|
||||
for (Object templateObj : templates) {
|
||||
JSONObject template = (JSONObject) templateObj;
|
||||
String id = template.getString("id");
|
||||
String name = template.getString("name");
|
||||
|
||||
if (templateId.equals(id)) {
|
||||
// 找到对应的模板,生成代码
|
||||
String templatePath = groupName + "/" + name + ".ftl";
|
||||
if (FreemarkerUtil.templateExists(templatePath)) {
|
||||
return FreemarkerUtil.generateByTemplate(templatePath, options);
|
||||
} else {
|
||||
log.warn("系统模板文件不存在: {}", templatePath);
|
||||
return "// 系统模板文件不存在: " + templatePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "// 系统模板不存在: " + templateId;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("生成系统模板失败: templateId={}", templateId, e);
|
||||
return "// 生成系统模板失败: " + e.getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.agileboot.codegen.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author cuiJiaWang
|
||||
* @Create 2025-09-24 14:31
|
||||
*/
|
||||
public interface IGeneratorService {
|
||||
String getTemplateConfig();
|
||||
|
||||
/**
|
||||
* 根据参数生成代码
|
||||
*
|
||||
* @param options 生成参数
|
||||
* @return 生成的代码Map
|
||||
*/
|
||||
Map<String, String> getResultByParams(Map<String, Object> options);
|
||||
|
||||
/**
|
||||
* 根据参数和自定义模板配置生成代码
|
||||
*
|
||||
* @param options 生成参数
|
||||
* @param templateConfig 自定义模板配置
|
||||
* @return 生成的代码Map
|
||||
*/
|
||||
Map<String, String> getResultByParams(Map<String, Object> options, String templateConfig);
|
||||
|
||||
/**
|
||||
* 预览单个模板
|
||||
*
|
||||
* @param templateSource 模板来源(system/user/content)
|
||||
* @param templateId 模板ID
|
||||
* @param templateContent 模板内容(当templateSource为content时使用)
|
||||
* @param options 生成参数
|
||||
* @return 生成的代码内容
|
||||
*/
|
||||
String previewSingleTemplate(String templateSource, String templateId, String templateContent, Map<String, Object> options);
|
||||
|
||||
/**
|
||||
* 根据模板来源和ID获取模板原始内容
|
||||
*
|
||||
* @param templateSource 模板来源(system/user)
|
||||
* @param templateId 模板ID
|
||||
* @return 模板原始内容
|
||||
*/
|
||||
String getTemplateContentBySource(String templateSource, String templateId);
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.agileboot.codegen.service;
|
||||
|
||||
import com.agileboot.codegen.dto.TemplateRepositoryDTO;
|
||||
import com.agileboot.codegen.entity.UserTemplateRepository;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 模板仓库 Service接口
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-09-26
|
||||
*/
|
||||
public interface ITemplateRepositoryService {
|
||||
|
||||
/**
|
||||
* 获取用户的模板仓库配置(用于代码生成界面显示)
|
||||
* 返回格式与原有template.json格式兼容
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 模板配置JSON
|
||||
*/
|
||||
JSONArray getUserTemplateConfig(Long userId);
|
||||
|
||||
/**
|
||||
* 获取用户的模板仓库列表(用于仓库管理界面)
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 模板仓库配置列表
|
||||
*/
|
||||
List<UserTemplateRepository> getUserRepositoryList(Long userId);
|
||||
|
||||
/**
|
||||
* 获取所有可用模板(系统模板+公开用户模板)
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 可用模板列表
|
||||
*/
|
||||
List<TemplateRepositoryDTO> getAvailableTemplates(Long userId);
|
||||
|
||||
/**
|
||||
* 添加模板到用户仓库
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param templateSource 模板来源
|
||||
* @param templateId 模板ID
|
||||
* @param templateName 模板名称
|
||||
* @param templateGroup 模板分组
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean addTemplateToRepository(Long userId, String templateSource, String templateId,
|
||||
String templateName, String templateGroup);
|
||||
|
||||
/**
|
||||
* 从用户仓库移除模板
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param templateSource 模板来源
|
||||
* @param templateId 模板ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean removeTemplateFromRepository(Long userId, String templateSource, String templateId);
|
||||
|
||||
/**
|
||||
* 切换模板启用状态
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param templateSource 模板来源
|
||||
* @param templateId 模板ID
|
||||
* @param isEnabled 是否启用
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean toggleTemplateStatus(Long userId, String templateSource, String templateId, Integer isEnabled);
|
||||
|
||||
/**
|
||||
* 批量更新模板排序
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param templates 模板排序信息列表
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean updateTemplateSort(Long userId, List<TemplateRepositoryDTO> templates);
|
||||
|
||||
/**
|
||||
* 初始化用户模板仓库(将系统默认模板添加到新用户仓库)
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean initUserRepository(Long userId);
|
||||
|
||||
/**
|
||||
* 检查模板是否已添加到用户仓库
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param templateSource 模板来源
|
||||
* @param templateId 模板ID
|
||||
* @return 是否已存在
|
||||
*/
|
||||
boolean checkTemplateExists(Long userId, String templateSource, String templateId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.agileboot.codegen.service;
|
||||
|
||||
import com.agileboot.codegen.entity.TemplateUsageLog;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 模板使用日志 Service接口
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-09-26
|
||||
*/
|
||||
public interface ITemplateUsageLogService {
|
||||
|
||||
/**
|
||||
* 记录模板使用日志
|
||||
*
|
||||
* @param userId 使用者ID
|
||||
* @param templateSource 模板来源
|
||||
* @param templateId 模板ID
|
||||
* @param templateName 模板名称
|
||||
* @param templateGroup 模板分组
|
||||
* @param ipAddress IP地址
|
||||
*/
|
||||
void logTemplateUsage(Long userId, String templateSource, String templateId,
|
||||
String templateName, String templateGroup, String ipAddress);
|
||||
|
||||
/**
|
||||
* 查询用户的模板使用历史
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @param limit 限制数量
|
||||
* @return 使用日志列表
|
||||
*/
|
||||
List<TemplateUsageLog> getUserUsageHistory(Long userId, Date startTime, Date endTime, Integer limit);
|
||||
|
||||
/**
|
||||
* 查询模板使用统计
|
||||
*
|
||||
* @param templateSource 模板来源
|
||||
* @param templateId 模板ID
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @return 使用次数
|
||||
*/
|
||||
int getTemplateUsageCount(String templateSource, String templateId, Date startTime, Date endTime);
|
||||
|
||||
/**
|
||||
* 查询热门模板统计
|
||||
*
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @param limit 限制数量
|
||||
* @return 热门模板列表
|
||||
*/
|
||||
List<TemplateUsageLog> getPopularTemplates(Date startTime, Date endTime, Integer limit);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
package com.agileboot.codegen.service;
|
||||
|
||||
import com.agileboot.codegen.dto.UserTemplateDTO;
|
||||
import com.agileboot.codegen.entity.UserTemplate;
|
||||
import com.agileboot.codegen.vo.UserTemplateVO;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户模板 Service接口
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-09-26
|
||||
*/
|
||||
public interface IUserTemplateService {
|
||||
|
||||
/**
|
||||
* 分页查询用户模板列表
|
||||
*
|
||||
* @param page 分页参数
|
||||
* @param userId 用户ID
|
||||
* @param templateGroup 模板分组(可选)
|
||||
* @param isPublic 是否公开(可选)
|
||||
* @return 用户模板列表
|
||||
*/
|
||||
Page<UserTemplateVO> selectUserTemplateList(Page<UserTemplate> page, Long userId, String templateGroup, Integer isPublic);
|
||||
|
||||
/**
|
||||
* 查询公开模板列表
|
||||
*
|
||||
* @param templateGroup 模板分组(可选)
|
||||
* @param currentUserId 当前用户ID
|
||||
* @return 公开模板列表
|
||||
*/
|
||||
List<UserTemplateVO> selectPublicTemplates(String templateGroup, Long currentUserId);
|
||||
|
||||
/**
|
||||
* 根据ID查询用户模板
|
||||
*
|
||||
* @param id 模板ID
|
||||
* @return 用户模板
|
||||
*/
|
||||
UserTemplateVO selectUserTemplateById(Long id);
|
||||
|
||||
/**
|
||||
* 新增用户模板
|
||||
*
|
||||
* @param dto 用户模板信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean insertUserTemplate(UserTemplateDTO dto);
|
||||
|
||||
/**
|
||||
* 修改用户模板
|
||||
*
|
||||
* @param dto 用户模板信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean updateUserTemplate(UserTemplateDTO dto);
|
||||
|
||||
/**
|
||||
* 删除用户模板
|
||||
*
|
||||
* @param id 模板ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean deleteUserTemplateById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除用户模板
|
||||
*
|
||||
* @param ids 模板ID数组
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean deleteUserTemplateByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 复制模板(复制他人的公开模板到自己的模板库)
|
||||
*
|
||||
* @param templateId 要复制的模板ID
|
||||
* @param newName 新模板名称
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean copyTemplate(Long templateId, String newName);
|
||||
|
||||
/**
|
||||
* 验证模板语法
|
||||
*
|
||||
* @param templateContent 模板内容
|
||||
* @return 验证结果信息
|
||||
*/
|
||||
String validateTemplate(String templateContent);
|
||||
|
||||
/**
|
||||
* 检查模板名称是否存在
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param templateName 模板名称
|
||||
* @param excludeId 排除的模板ID(更新时使用)
|
||||
* @return 是否存在
|
||||
*/
|
||||
boolean checkTemplateNameExists(Long userId, String templateName, Long excludeId);
|
||||
|
||||
/**
|
||||
* 增加模板使用次数
|
||||
*
|
||||
* @param id 模板ID
|
||||
*/
|
||||
void increaseUseCount(Long id);
|
||||
|
||||
/**
|
||||
* 切换用户模板显示状态
|
||||
*
|
||||
* @param id 模板ID
|
||||
* @param isEnabled 是否启用显示
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean toggleTemplateVisibility(Long id, Integer isEnabled);
|
||||
|
||||
/**
|
||||
* 获取模板内容(考虑权限控制)
|
||||
*
|
||||
* @param id 模板ID
|
||||
* @return 模板内容或权限提示
|
||||
*/
|
||||
String getTemplateContent(Long id);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,388 @@
|
||||
package com.agileboot.codegen.service.impl;
|
||||
|
||||
import com.agileboot.codegen.dto.TemplateRepositoryDTO;
|
||||
import com.agileboot.codegen.entity.UserTemplate;
|
||||
import com.agileboot.codegen.entity.UserTemplateRepository;
|
||||
import com.agileboot.codegen.mapper.UserTemplateMapper;
|
||||
import com.agileboot.codegen.mapper.UserTemplateRepositoryMapper;
|
||||
import com.agileboot.codegen.service.IGeneratorService;
|
||||
import com.agileboot.codegen.service.ITemplateRepositoryService;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 模板仓库 Service实现类
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-09-26
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TemplateRepositoryServiceImpl implements ITemplateRepositoryService {
|
||||
|
||||
private final UserTemplateRepositoryMapper repositoryMapper;
|
||||
private final UserTemplateMapper userTemplateMapper;
|
||||
private final IGeneratorService generatorService;
|
||||
|
||||
@Override
|
||||
public JSONArray getUserTemplateConfig(Long userId) {
|
||||
// 获取用户启用的模板仓库配置(公开模板)
|
||||
List<UserTemplateRepository> repositories = repositoryMapper.selectEnabledByUserId(userId);
|
||||
|
||||
// 按分组组织模板
|
||||
Map<String, List<JSONObject>> groupedTemplates = new HashMap<>();
|
||||
|
||||
for (UserTemplateRepository repo : repositories) {
|
||||
String group = repo.getTemplateGroup();
|
||||
|
||||
JSONObject template = new JSONObject();
|
||||
template.put("id", repo.getTemplateId());
|
||||
template.put("name", repo.getTemplateName());
|
||||
template.put("description", repo.getTemplateName());
|
||||
template.put("source", repo.getTemplateSource()); // 添加来源标识
|
||||
|
||||
groupedTemplates.computeIfAbsent(group, k -> new ArrayList<>()).add(template);
|
||||
}
|
||||
|
||||
// 添加用户自己的启用模板(包括私有模板)
|
||||
List<UserTemplate> userEnabledTemplates = userTemplateMapper.selectList(
|
||||
new LambdaQueryWrapper<UserTemplate>()
|
||||
.eq(UserTemplate::getUserId, userId)
|
||||
.eq(UserTemplate::getIsEnabled, 1)
|
||||
.eq(UserTemplate::getStatus, 1) // 只包含发布状态的模板
|
||||
);
|
||||
|
||||
for (UserTemplate userTemplate : userEnabledTemplates) {
|
||||
// 如果是公开模板且已经在仓库配置中,跳过(避免重复)
|
||||
if (userTemplate.getIsPublic() == 1) {
|
||||
boolean alreadyInRepo = repositories.stream()
|
||||
.anyMatch(repo -> "user".equals(repo.getTemplateSource()) &&
|
||||
userTemplate.getId().toString().equals(repo.getTemplateId()));
|
||||
if (alreadyInRepo) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
String group = userTemplate.getTemplateGroup();
|
||||
JSONObject template = new JSONObject();
|
||||
template.put("id", userTemplate.getId().toString());
|
||||
template.put("name", userTemplate.getTemplateName());
|
||||
template.put("description", userTemplate.getTemplateName());
|
||||
template.put("source", "user");
|
||||
|
||||
groupedTemplates.computeIfAbsent(group, k -> new ArrayList<>()).add(template);
|
||||
}
|
||||
|
||||
// 如果用户没有配置任何模板,先初始化用户仓库,然后重新获取
|
||||
if (groupedTemplates.isEmpty()) {
|
||||
log.info("用户 {} 没有模板配置,自动初始化用户仓库", userId);
|
||||
boolean initSuccess = initUserRepository(userId);
|
||||
if (initSuccess) {
|
||||
// 重新获取用户启用的模板仓库配置
|
||||
repositories = repositoryMapper.selectEnabledByUserId(userId);
|
||||
for (UserTemplateRepository repo : repositories) {
|
||||
String group = repo.getTemplateGroup();
|
||||
|
||||
JSONObject template = new JSONObject();
|
||||
template.put("id", repo.getTemplateId());
|
||||
template.put("name", repo.getTemplateName());
|
||||
template.put("description", repo.getTemplateName());
|
||||
template.put("source", repo.getTemplateSource());
|
||||
|
||||
groupedTemplates.computeIfAbsent(group, k -> new ArrayList<>()).add(template);
|
||||
}
|
||||
} else {
|
||||
// 初始化失败,返回系统默认模板
|
||||
return JSONArray.parseArray(generatorService.getTemplateConfig());
|
||||
}
|
||||
}
|
||||
|
||||
// 转换为JSONArray格式
|
||||
JSONArray result = new JSONArray();
|
||||
for (Map.Entry<String, List<JSONObject>> entry : groupedTemplates.entrySet()) {
|
||||
JSONObject group = new JSONObject();
|
||||
group.put("group", entry.getKey());
|
||||
group.put("templates", entry.getValue());
|
||||
result.add(group);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserTemplateRepository> getUserRepositoryList(Long userId) {
|
||||
return repositoryMapper.selectAllByUserId(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TemplateRepositoryDTO> getAvailableTemplates(Long userId) {
|
||||
List<TemplateRepositoryDTO> result = new ArrayList<>();
|
||||
|
||||
// 一次性获取用户的所有仓库配置,避免N+1查询
|
||||
List<UserTemplateRepository> userRepositories = repositoryMapper.selectAllByUserId(userId);
|
||||
|
||||
// 如果用户没有任何仓库配置,才进行初始化
|
||||
if (userRepositories.isEmpty()) {
|
||||
initUserRepository(userId);
|
||||
// 重新获取初始化后的配置
|
||||
userRepositories = repositoryMapper.selectAllByUserId(userId);
|
||||
}
|
||||
|
||||
Map<String, UserTemplateRepository> repoMap = userRepositories.stream()
|
||||
.collect(Collectors.toMap(
|
||||
repo -> repo.getTemplateSource() + ":" + repo.getTemplateId(),
|
||||
repo -> repo
|
||||
));
|
||||
|
||||
// 1. 添加系统模板
|
||||
try {
|
||||
JSONArray systemTemplates = JSONArray.parseArray(generatorService.getTemplateConfig());
|
||||
for (Object groupObj : systemTemplates) {
|
||||
JSONObject group = (JSONObject) groupObj;
|
||||
String groupName = group.getString("group");
|
||||
JSONArray templates = group.getJSONArray("templates");
|
||||
|
||||
for (Object templateObj : templates) {
|
||||
JSONObject template = (JSONObject) templateObj;
|
||||
TemplateRepositoryDTO dto = new TemplateRepositoryDTO();
|
||||
dto.setTemplateSource("system");
|
||||
dto.setTemplateId(template.getString("id"));
|
||||
dto.setTemplateName(template.getString("name"));
|
||||
dto.setTemplateGroup(groupName);
|
||||
dto.setDescription(template.getString("description")); // 系统模板描述
|
||||
|
||||
// 从内存中获取显示状态,避免数据库查询
|
||||
String key = "system:" + template.getString("id");
|
||||
UserTemplateRepository userRepo = repoMap.get(key);
|
||||
dto.setIsEnabled(userRepo != null ? userRepo.getIsEnabled() : 0); // 默认显示
|
||||
|
||||
result.add(dto);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("解析系统模板配置失败", e);
|
||||
}
|
||||
|
||||
// 2. 添加公开的用户模板
|
||||
List<UserTemplate> publicTemplates = userTemplateMapper.selectPublicTemplates(null);
|
||||
for (UserTemplate template : publicTemplates) {
|
||||
TemplateRepositoryDTO dto = new TemplateRepositoryDTO();
|
||||
dto.setTemplateSource("user");
|
||||
dto.setTemplateId(template.getId().toString());
|
||||
dto.setTemplateName(template.getTemplateName());
|
||||
dto.setTemplateGroup(template.getTemplateGroup());
|
||||
dto.setDescription(template.getDescription()); // 用户模板描述
|
||||
|
||||
// 从内存中获取显示状态,避免数据库查询
|
||||
String key = "user:" + template.getId().toString();
|
||||
UserTemplateRepository userRepo = repoMap.get(key);
|
||||
dto.setIsEnabled(userRepo != null ? userRepo.getIsEnabled() : 0); // 默认显示
|
||||
|
||||
result.add(dto);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean addTemplateToRepository(Long userId, String templateSource, String templateId,
|
||||
String templateName, String templateGroup) {
|
||||
// 检查是否已存在
|
||||
if (repositoryMapper.checkTemplateExists(userId, templateSource, templateId) > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
UserTemplateRepository repository = new UserTemplateRepository();
|
||||
repository.setUserId(userId);
|
||||
repository.setTemplateSource(templateSource);
|
||||
repository.setTemplateId(templateId);
|
||||
repository.setTemplateName(templateName);
|
||||
repository.setTemplateGroup(templateGroup);
|
||||
repository.setIsEnabled(1);
|
||||
repository.setSortOrder(repositoryMapper.getMaxSortOrder(userId) + 1);
|
||||
|
||||
return repositoryMapper.insert(repository) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean removeTemplateFromRepository(Long userId, String templateSource, String templateId) {
|
||||
return repositoryMapper.deleteByTemplate(userId, templateSource, templateId) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean toggleTemplateStatus(Long userId, String templateSource, String templateId, Integer isEnabled) {
|
||||
// 先检查记录是否存在
|
||||
if (repositoryMapper.checkTemplateExists(userId, templateSource, templateId) == 0) {
|
||||
// 记录不存在,需要先创建
|
||||
log.info("模板记录不存在,先创建记录: userId={}, templateSource={}, templateId={}", userId, templateSource, templateId);
|
||||
|
||||
// 获取模板信息
|
||||
String templateName = "";
|
||||
String templateGroup = "";
|
||||
|
||||
if ("system".equals(templateSource)) {
|
||||
// 系统模板,从配置中获取信息
|
||||
try {
|
||||
JSONArray systemTemplates = JSONArray.parseArray(generatorService.getTemplateConfig());
|
||||
for (Object groupObj : systemTemplates) {
|
||||
JSONObject group = (JSONObject) groupObj;
|
||||
String groupName = group.getString("group");
|
||||
JSONArray templates = group.getJSONArray("templates");
|
||||
|
||||
for (Object templateObj : templates) {
|
||||
JSONObject template = (JSONObject) templateObj;
|
||||
if (templateId.equals(template.getString("id"))) {
|
||||
templateName = template.getString("name");
|
||||
templateGroup = groupName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!templateName.isEmpty()) break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取系统模板信息失败", e);
|
||||
return false;
|
||||
}
|
||||
} else if ("user".equals(templateSource)) {
|
||||
// 用户模板,从数据库获取信息
|
||||
try {
|
||||
UserTemplate userTemplate = userTemplateMapper.selectById(Long.parseLong(templateId));
|
||||
if (userTemplate != null) {
|
||||
templateName = userTemplate.getTemplateName();
|
||||
templateGroup = userTemplate.getTemplateGroup();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取用户模板信息失败", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (templateName.isEmpty()) {
|
||||
log.error("无法获取模板信息: templateSource={}, templateId={}", templateSource, templateId);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 创建记录
|
||||
UserTemplateRepository repository = new UserTemplateRepository();
|
||||
repository.setUserId(userId);
|
||||
repository.setTemplateSource(templateSource);
|
||||
repository.setTemplateId(templateId);
|
||||
repository.setTemplateName(templateName);
|
||||
repository.setTemplateGroup(templateGroup);
|
||||
repository.setIsEnabled(isEnabled);
|
||||
repository.setSortOrder(repositoryMapper.getMaxSortOrder(userId) + 1);
|
||||
|
||||
return repositoryMapper.insert(repository) > 0;
|
||||
} else {
|
||||
// 记录存在,直接更新状态
|
||||
return repositoryMapper.toggleTemplateStatus(userId, templateSource, templateId, isEnabled) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updateTemplateSort(Long userId, List<TemplateRepositoryDTO> templates) {
|
||||
try {
|
||||
for (int i = 0; i < templates.size(); i++) {
|
||||
TemplateRepositoryDTO dto = templates.get(i);
|
||||
repositoryMapper.updateSortOrder(userId, dto.getTemplateSource(), dto.getTemplateId(), i + 1);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
log.error("更新模板排序失败", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean initUserRepository(Long userId) {
|
||||
try {
|
||||
// 先获取用户已有的仓库配置
|
||||
List<UserTemplateRepository> existingRepos = repositoryMapper.selectAllByUserId(userId);
|
||||
Set<String> existingKeys = existingRepos.stream()
|
||||
.map(repo -> repo.getTemplateSource() + ":" + repo.getTemplateId())
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
int sortOrder = repositoryMapper.getMaxSortOrder(userId) + 1;
|
||||
List<UserTemplateRepository> toInsert = new ArrayList<>();
|
||||
|
||||
// 1. 将系统默认模板添加到用户仓库(如果不存在)
|
||||
JSONArray systemTemplates = JSONArray.parseArray(generatorService.getTemplateConfig());
|
||||
|
||||
for (Object groupObj : systemTemplates) {
|
||||
JSONObject group = (JSONObject) groupObj;
|
||||
String groupName = group.getString("group");
|
||||
JSONArray templates = group.getJSONArray("templates");
|
||||
|
||||
for (Object templateObj : templates) {
|
||||
JSONObject template = (JSONObject) templateObj;
|
||||
String templateId = template.getString("id");
|
||||
String key = "system:" + templateId;
|
||||
|
||||
// 从内存中检查是否已存在,避免数据库查询
|
||||
if (!existingKeys.contains(key)) {
|
||||
UserTemplateRepository repository = new UserTemplateRepository();
|
||||
repository.setUserId(userId);
|
||||
repository.setTemplateSource("system");
|
||||
repository.setTemplateId(templateId);
|
||||
repository.setTemplateName(template.getString("name"));
|
||||
repository.setTemplateGroup(groupName);
|
||||
repository.setIsEnabled(0); // 系统模板默认启用
|
||||
repository.setSortOrder(sortOrder++);
|
||||
|
||||
toInsert.add(repository);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 批量插入,减少数据库交互
|
||||
for (UserTemplateRepository repo : toInsert) {
|
||||
repositoryMapper.insert(repo);
|
||||
}
|
||||
|
||||
// 2. 将公开的用户模板添加到用户仓库(如果不存在)
|
||||
List<UserTemplate> publicTemplates = userTemplateMapper.selectPublicTemplates(null);
|
||||
for (UserTemplate template : publicTemplates) {
|
||||
String templateId = template.getId().toString();
|
||||
|
||||
// 检查是否已存在
|
||||
if (repositoryMapper.checkTemplateExists(userId, "user", templateId) == 0) {
|
||||
UserTemplateRepository repository = new UserTemplateRepository();
|
||||
repository.setUserId(userId);
|
||||
repository.setTemplateSource("user");
|
||||
repository.setTemplateId(templateId);
|
||||
repository.setTemplateName(template.getTemplateName());
|
||||
repository.setTemplateGroup(template.getTemplateGroup());
|
||||
repository.setIsEnabled(1); // 公开模板默认启用
|
||||
repository.setSortOrder(sortOrder++);
|
||||
|
||||
repositoryMapper.insert(repository);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
log.error("初始化用户模板仓库失败", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTemplateExists(Long userId, String templateSource, String templateId) {
|
||||
return repositoryMapper.checkTemplateExists(userId, templateSource, templateId) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.agileboot.codegen.service.impl;
|
||||
|
||||
import com.agileboot.codegen.entity.TemplateUsageLog;
|
||||
import com.agileboot.codegen.mapper.TemplateUsageLogMapper;
|
||||
import com.agileboot.codegen.service.ITemplateUsageLogService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 模板使用日志 Service实现类
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-09-26
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TemplateUsageLogServiceImpl implements ITemplateUsageLogService {
|
||||
|
||||
private final TemplateUsageLogMapper usageLogMapper;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void logTemplateUsage(Long userId, String templateSource, String templateId,
|
||||
String templateName, String templateGroup, String ipAddress) {
|
||||
try {
|
||||
TemplateUsageLog log = new TemplateUsageLog();
|
||||
log.setUserId(userId);
|
||||
log.setTemplateSource(templateSource);
|
||||
log.setTemplateId(templateId);
|
||||
log.setTemplateName(templateName);
|
||||
log.setTemplateGroup(templateGroup);
|
||||
log.setIpAddress(ipAddress);
|
||||
|
||||
usageLogMapper.insert(log);
|
||||
} catch (Exception e) {
|
||||
// 使用日志记录不应该影响主业务流程
|
||||
log.error("记录模板使用日志失败: userId={}, templateId={}", userId, templateId, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TemplateUsageLog> getUserUsageHistory(Long userId, Date startTime, Date endTime, Integer limit) {
|
||||
return usageLogMapper.selectUserUsageHistory(userId,
|
||||
toLocalDateTime(startTime),
|
||||
toLocalDateTime(endTime),
|
||||
limit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTemplateUsageCount(String templateSource, String templateId, Date startTime, Date endTime) {
|
||||
return usageLogMapper.countTemplateUsage(templateSource, templateId,
|
||||
toLocalDateTime(startTime),
|
||||
toLocalDateTime(endTime));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TemplateUsageLog> getPopularTemplates(Date startTime, Date endTime, Integer limit) {
|
||||
return usageLogMapper.selectPopularTemplates(
|
||||
toLocalDateTime(startTime),
|
||||
toLocalDateTime(endTime),
|
||||
limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Date转LocalDateTime
|
||||
*/
|
||||
private LocalDateTime toLocalDateTime(Date date) {
|
||||
return date == null ? null : date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,343 @@
|
||||
package com.agileboot.codegen.service.impl;
|
||||
|
||||
import com.agileboot.codegen.dto.UserTemplateDTO;
|
||||
import com.agileboot.codegen.entity.UserTemplate;
|
||||
import com.agileboot.codegen.mapper.UserTemplateMapper;
|
||||
import com.agileboot.codegen.service.IUserTemplateService;
|
||||
import com.agileboot.codegen.vo.UserTemplateVO;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.agileboot.common.satoken.utils.LoginHelper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import java.util.Arrays;
|
||||
import com.agileboot.codegen.mapper.UserTemplateRepositoryMapper;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 用户模板 Service实现类
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-09-26
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class UserTemplateServiceImpl implements IUserTemplateService {
|
||||
|
||||
private final UserTemplateMapper userTemplateMapper;
|
||||
private final UserTemplateRepositoryMapper repositoryMapper;
|
||||
|
||||
@Override
|
||||
public Page<UserTemplateVO> selectUserTemplateList(Page<UserTemplate> page, Long userId, String templateGroup, Integer isPublic) {
|
||||
LambdaQueryWrapper<UserTemplate> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(userId != null, UserTemplate::getUserId, userId)
|
||||
.eq(StringUtils.isNotBlank(templateGroup), UserTemplate::getTemplateGroup, templateGroup)
|
||||
.eq(isPublic != null, UserTemplate::getIsPublic, isPublic)
|
||||
.orderByDesc(UserTemplate::getCreateTime);
|
||||
|
||||
Page<UserTemplate> templatePage = userTemplateMapper.selectPage(page, wrapper);
|
||||
|
||||
// 转换为VO
|
||||
Page<UserTemplateVO> voPage = new Page<>(templatePage.getCurrent(), templatePage.getSize(), templatePage.getTotal());
|
||||
List<UserTemplateVO> voList = templatePage.getRecords().stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
voPage.setRecords(voList);
|
||||
|
||||
return voPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserTemplateVO> selectPublicTemplates(String templateGroup, Long currentUserId) {
|
||||
List<UserTemplate> templates = userTemplateMapper.selectPublicTemplates(templateGroup);
|
||||
return templates.stream()
|
||||
.map(template -> {
|
||||
UserTemplateVO vo = convertToVO(template);
|
||||
vo.setIsOwner(currentUserId != null && currentUserId.equals(template.getUserId()));
|
||||
return vo;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserTemplateVO selectUserTemplateById(Long id) {
|
||||
UserTemplate template = userTemplateMapper.selectById(id);
|
||||
return template != null ? convertToVO(template) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean insertUserTemplate(UserTemplateDTO dto) {
|
||||
Long currentUserId = LoginHelper.getUserId();
|
||||
|
||||
// 检查模板名称是否存在
|
||||
if (checkTemplateNameExists(currentUserId, dto.getTemplateName(), null)) {
|
||||
throw new RuntimeException("模板名称已存在");
|
||||
}
|
||||
|
||||
UserTemplate template = new UserTemplate();
|
||||
BeanUtil.copyProperties(dto, template);
|
||||
template.setUserId(currentUserId);
|
||||
template.setUseCount(0);
|
||||
template.setStatus(dto.getStatus() != null ? dto.getStatus() : 1);
|
||||
template.setVersion(StringUtils.isNotBlank(dto.getVersion()) ? dto.getVersion() : "1.0.0");
|
||||
template.setIsEnabled(dto.getIsEnabled() != null ? dto.getIsEnabled() : 1); // 默认显示
|
||||
template.setIsContentPublic(dto.getIsContentPublic() != null ? dto.getIsContentPublic() : 0); // 默认不公开内容
|
||||
|
||||
return userTemplateMapper.insert(template) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updateUserTemplate(UserTemplateDTO dto) {
|
||||
if (dto.getId() == null) {
|
||||
throw new RuntimeException("模板ID不能为空");
|
||||
}
|
||||
|
||||
UserTemplate existTemplate = userTemplateMapper.selectById(dto.getId());
|
||||
if (existTemplate == null) {
|
||||
throw new RuntimeException("模板不存在");
|
||||
}
|
||||
|
||||
Long currentUserId = LoginHelper.getUserId();
|
||||
// 只能修改自己的模板
|
||||
if (!currentUserId.equals(existTemplate.getUserId())) {
|
||||
throw new RuntimeException("无权限修改此模板");
|
||||
}
|
||||
|
||||
// 检查模板名称是否存在(只在名称发生变化时才检查)
|
||||
if (!existTemplate.getTemplateName().equals(dto.getTemplateName()) &&
|
||||
checkTemplateNameExists(currentUserId, dto.getTemplateName(), dto.getId())) {
|
||||
throw new RuntimeException("模板名称已存在");
|
||||
}
|
||||
|
||||
UserTemplate template = new UserTemplate();
|
||||
BeanUtil.copyProperties(dto, template);
|
||||
template.setUserId(currentUserId);
|
||||
|
||||
return userTemplateMapper.updateById(template) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean deleteUserTemplateById(Long id) {
|
||||
if (id == null) {
|
||||
throw new RuntimeException("模板ID不能为空");
|
||||
}
|
||||
|
||||
UserTemplate template = userTemplateMapper.selectById(id);
|
||||
if (template == null) {
|
||||
throw new RuntimeException("模板不存在或已被删除");
|
||||
}
|
||||
|
||||
Long currentUserId = LoginHelper.getUserId();
|
||||
// 只能删除自己的模板
|
||||
if (!currentUserId.equals(template.getUserId())) {
|
||||
throw new RuntimeException("无权限删除此模板");
|
||||
}
|
||||
|
||||
int result = userTemplateMapper.deleteById(id);
|
||||
if (result <= 0) {
|
||||
throw new RuntimeException("删除操作失败");
|
||||
}
|
||||
|
||||
// 清理模板仓库中的相关记录
|
||||
repositoryMapper.deleteByTemplate(currentUserId, "user", id.toString());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean deleteUserTemplateByIds(Long[] ids) {
|
||||
if (ids == null || ids.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Long currentUserId = LoginHelper.getUserId();
|
||||
|
||||
// 检查所有模板是否属于当前用户
|
||||
for (Long id : ids) {
|
||||
UserTemplate template = userTemplateMapper.selectById(id);
|
||||
if (template == null || !currentUserId.equals(template.getUserId())) {
|
||||
throw new RuntimeException("无权限删除模板ID: " + id);
|
||||
}
|
||||
}
|
||||
|
||||
boolean deleteResult = userTemplateMapper.deleteByIds(Arrays.asList(ids)) > 0;
|
||||
|
||||
// 清理模板仓库中的相关记录
|
||||
for (Long id : ids) {
|
||||
repositoryMapper.deleteByTemplate(currentUserId, "user", id.toString());
|
||||
}
|
||||
|
||||
return deleteResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean copyTemplate(Long templateId, String newName) {
|
||||
UserTemplate sourceTemplate = userTemplateMapper.selectById(templateId);
|
||||
if (sourceTemplate == null) {
|
||||
throw new RuntimeException("源模板不存在");
|
||||
}
|
||||
|
||||
Long currentUserId = LoginHelper.getUserId();
|
||||
|
||||
// 权限检查:只能复制自己的模板或公开模板
|
||||
if (sourceTemplate.getIsPublic() != 1 && !currentUserId.equals(sourceTemplate.getUserId())) {
|
||||
throw new RuntimeException("无权限复制此模板");
|
||||
}
|
||||
|
||||
// 检查新模板名称是否存在
|
||||
if (checkTemplateNameExists(currentUserId, newName, null)) {
|
||||
throw new RuntimeException("模板名称已存在");
|
||||
}
|
||||
|
||||
UserTemplate newTemplate = new UserTemplate();
|
||||
BeanUtil.copyProperties(sourceTemplate, newTemplate);
|
||||
newTemplate.setId(null);
|
||||
newTemplate.setUserId(currentUserId);
|
||||
newTemplate.setTemplateName(newName);
|
||||
newTemplate.setIsPublic(0); // 复制的模板默认为私有
|
||||
newTemplate.setUseCount(0);
|
||||
// 清除时间字段,让自动填充功能设置当前时间
|
||||
newTemplate.setCreateTime(null);
|
||||
newTemplate.setUpdateTime(null);
|
||||
newTemplate.setCreateBy(null);
|
||||
newTemplate.setUpdateBy(null);
|
||||
|
||||
return userTemplateMapper.insert(newTemplate) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String validateTemplate(String templateContent) {
|
||||
try {
|
||||
Configuration cfg = new Configuration(Configuration.VERSION_2_3_31);
|
||||
cfg.setDefaultEncoding("UTF-8");
|
||||
|
||||
// 创建模板对象
|
||||
Template template = new Template("validate", new StringReader(templateContent), cfg);
|
||||
|
||||
// 使用测试数据验证模板
|
||||
StringWriter writer = new StringWriter();
|
||||
HashMap<String, Object> testData = new HashMap<>();
|
||||
testData.put("className", "TestClass");
|
||||
testData.put("tableName", "test_table");
|
||||
|
||||
template.process(testData, writer);
|
||||
|
||||
return "模板语法验证通过";
|
||||
} catch (Exception e) {
|
||||
return "模板语法错误: " + e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTemplateNameExists(Long userId, String templateName, Long excludeId) {
|
||||
return userTemplateMapper.checkTemplateNameExists(userId, templateName, excludeId) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void increaseUseCount(Long id) {
|
||||
userTemplateMapper.increaseUseCount(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean toggleTemplateVisibility(Long id, Integer isEnabled) {
|
||||
UserTemplate template = userTemplateMapper.selectById(id);
|
||||
if (template == null) {
|
||||
throw new RuntimeException("模板不存在");
|
||||
}
|
||||
Long currentUserId = LoginHelper.getUserId();
|
||||
// 只能修改自己的模板
|
||||
if (!currentUserId.equals(template.getUserId())) {
|
||||
throw new RuntimeException("无权限修改此模板");
|
||||
}
|
||||
|
||||
// 更新模板的显示状态
|
||||
template.setIsEnabled(isEnabled);
|
||||
boolean updateResult = userTemplateMapper.updateById(template) > 0;
|
||||
|
||||
// 如果是公开模板,同时更新模板仓库中的状态(如果存在的话)
|
||||
if (template.getIsPublic() == 1) {
|
||||
try {
|
||||
repositoryMapper.toggleTemplateStatus(currentUserId, "user", id.toString(), isEnabled);
|
||||
} catch (Exception e) {
|
||||
// 如果模板仓库中不存在该记录,忽略错误
|
||||
log.debug("更新模板仓库状态时出错,可能记录不存在: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return updateResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateContent(Long id) {
|
||||
UserTemplate template = userTemplateMapper.selectById(id);
|
||||
if (template == null) {
|
||||
throw new RuntimeException("模板不存在或已被删除");
|
||||
}
|
||||
|
||||
Long currentUserId = LoginHelper.getUserId();
|
||||
|
||||
// 权限检查:只能查看自己的模板或内容公开的模板
|
||||
if (!currentUserId.equals(template.getUserId())) {
|
||||
// 检查内容是否公开,如果字段不存在则默认为不公开
|
||||
Integer isContentPublic = template.getIsContentPublic();
|
||||
if (isContentPublic == null || isContentPublic != 1) {
|
||||
return "// 模板内容未公开,无法预览";
|
||||
}
|
||||
}
|
||||
|
||||
return template.getTemplateContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换实体为VO
|
||||
*/
|
||||
private UserTemplateVO convertToVO(UserTemplate template) {
|
||||
UserTemplateVO vo = new UserTemplateVO();
|
||||
BeanUtil.copyProperties(template, vo);
|
||||
|
||||
// 设置文本描述
|
||||
vo.setIsPublicText(template.getIsPublic() == 1 ? "公开" : "私有");
|
||||
|
||||
String statusText;
|
||||
switch (template.getStatus()) {
|
||||
case 0:
|
||||
statusText = "草稿";
|
||||
break;
|
||||
case 1:
|
||||
statusText = "发布";
|
||||
break;
|
||||
case 2:
|
||||
statusText = "禁用";
|
||||
break;
|
||||
default:
|
||||
statusText = "未知";
|
||||
}
|
||||
vo.setStatusText(statusText);
|
||||
|
||||
// 判断是否为当前用户创建
|
||||
Long currentUserId = LoginHelper.getUserId();
|
||||
vo.setIsOwner(currentUserId != null && currentUserId.equals(template.getUserId()));
|
||||
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
package com.agileboot.codegen.util;
|
||||
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Freemarker工具类
|
||||
*/
|
||||
@Slf4j
|
||||
public class FreemarkerUtil {
|
||||
|
||||
private static Configuration configuration;
|
||||
|
||||
static {
|
||||
configuration = new Configuration(Configuration.VERSION_2_3_31);
|
||||
configuration.setClassForTemplateLoading(FreemarkerUtil.class, "/templates/code-generator");
|
||||
configuration.setDefaultEncoding("UTF-8");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据模板生成代码
|
||||
*
|
||||
* @param templateName 模板名称
|
||||
* @param dataModel 数据模型
|
||||
* @return 生成的代码
|
||||
*/
|
||||
public static String generateByTemplate(String templateName, Map<String, Object> dataModel) {
|
||||
try {
|
||||
Template template = configuration.getTemplate(templateName);
|
||||
StringWriter writer = new StringWriter();
|
||||
template.process(dataModel, writer);
|
||||
return writer.toString();
|
||||
} catch (IOException | TemplateException e) {
|
||||
log.error("生成代码失败,模板: {}, 错误: {}", templateName, e.getMessage(), e);
|
||||
return "// 生成失败: " + e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据模板内容生成代码
|
||||
*
|
||||
* @param templateContent 模板内容字符串
|
||||
* @param dataModel 数据模型
|
||||
* @return 生成的代码
|
||||
*/
|
||||
public static String generateByContent(String templateContent, Map<String, Object> dataModel) {
|
||||
try {
|
||||
// 创建一个临时的Configuration用于处理字符串模板
|
||||
Configuration tempConfig = new Configuration(Configuration.VERSION_2_3_31);
|
||||
tempConfig.setDefaultEncoding("UTF-8");
|
||||
|
||||
// 从字符串创建模板
|
||||
Template template = new Template("userTemplate", new StringReader(templateContent), tempConfig);
|
||||
StringWriter writer = new StringWriter();
|
||||
template.process(dataModel, writer);
|
||||
return writer.toString();
|
||||
} catch (IOException | TemplateException e) {
|
||||
log.error("使用模板内容生成代码失败,错误: {}", e.getMessage(), e);
|
||||
return "// 生成失败: " + e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查模板是否存在
|
||||
*
|
||||
* @param templateName 模板名称
|
||||
* @return 是否存在
|
||||
*/
|
||||
public static boolean templateExists(String templateName) {
|
||||
try {
|
||||
configuration.getTemplate(templateName);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模板文件的原始内容
|
||||
*
|
||||
* @param templateName 模板名称
|
||||
* @return 模板原始内容
|
||||
*/
|
||||
public static String getTemplateContent(String templateName) {
|
||||
try {
|
||||
Template template = configuration.getTemplate(templateName);
|
||||
// 通过反射或其他方式获取模板源内容
|
||||
// 这里使用简单的方法:读取模板文件
|
||||
return readTemplateFile(templateName);
|
||||
} catch (IOException e) {
|
||||
log.error("获取模板内容失败: {}", templateName, e);
|
||||
return "// 模板文件不存在或读取失败: " + templateName;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取模板文件内容
|
||||
*/
|
||||
private static String readTemplateFile(String templatePath) {
|
||||
try {
|
||||
java.io.InputStream inputStream = FreemarkerUtil.class.getResourceAsStream("/templates/code-generator/" + templatePath);
|
||||
if (inputStream != null) {
|
||||
return new String(inputStream.readAllBytes(), "UTF-8");
|
||||
} else {
|
||||
return "// 模板文件不存在: " + templatePath;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("读取模板文件失败: {}", templatePath, e);
|
||||
return "// 读取模板文件失败: " + e.getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.agileboot.codegen.util;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Map工具类
|
||||
*/
|
||||
public class MapUtil {
|
||||
|
||||
/**
|
||||
* 从Map中获取String值
|
||||
*
|
||||
* @param map Map对象
|
||||
* @param key 键
|
||||
* @return String值
|
||||
*/
|
||||
public static String getString(Map<String, Object> map, String key) {
|
||||
if (map == null || key == null) {
|
||||
return null;
|
||||
}
|
||||
Object value = map.get(key);
|
||||
return value != null ? value.toString() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从Map中获取String值,带默认值
|
||||
*
|
||||
* @param map Map对象
|
||||
* @param key 键
|
||||
* @param defaultValue 默认值
|
||||
* @return String值
|
||||
*/
|
||||
public static String getString(Map<String, Object> map, String key, String defaultValue) {
|
||||
String value = getString(map, key);
|
||||
return value != null ? value : defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从Map中获取Boolean值
|
||||
*
|
||||
* @param map Map对象
|
||||
* @param key 键
|
||||
* @return Boolean值
|
||||
*/
|
||||
public static Boolean getBoolean(Map<String, Object> map, String key) {
|
||||
if (map == null || key == null) {
|
||||
return null;
|
||||
}
|
||||
Object value = map.get(key);
|
||||
if (value instanceof Boolean) {
|
||||
return (Boolean) value;
|
||||
}
|
||||
if (value instanceof String) {
|
||||
return Boolean.parseBoolean((String) value);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从Map中获取Boolean值,带默认值
|
||||
*
|
||||
* @param map Map对象
|
||||
* @param key 键
|
||||
* @param defaultValue 默认值
|
||||
* @return Boolean值
|
||||
*/
|
||||
public static Boolean getBoolean(Map<String, Object> map, String key, Boolean defaultValue) {
|
||||
Boolean value = getBoolean(map, key);
|
||||
return value != null ? value : defaultValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
package com.agileboot.codegen.util;
|
||||
|
||||
import com.agileboot.codegen.entity.ClassInfo;
|
||||
import com.agileboot.codegen.entity.FieldInfo;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 表解析工具类
|
||||
*/
|
||||
public class TableParseUtil {
|
||||
|
||||
/**
|
||||
* 解析DDL SQL语句获取ClassInfo
|
||||
*
|
||||
* @param sql DDL SQL语句
|
||||
* @param ignorePrefix 忽略前缀
|
||||
* @return ClassInfo对象
|
||||
*/
|
||||
public static ClassInfo parseTableSql(String sql, String ignorePrefix) {
|
||||
if (StringUtils.isBlank(sql)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
ClassInfo classInfo = new ClassInfo();
|
||||
List<FieldInfo> fieldList = new ArrayList<>();
|
||||
|
||||
// 解析表名和注释
|
||||
parseTableInfo(sql, classInfo, ignorePrefix);
|
||||
|
||||
// 解析字段信息
|
||||
parseFieldInfo(sql, fieldList);
|
||||
|
||||
classInfo.setFieldList(fieldList);
|
||||
|
||||
// 验证解析结果
|
||||
if (StringUtils.isBlank(classInfo.getTableName())) {
|
||||
throw new RuntimeException("无法解析表名,请检查SQL语句格式");
|
||||
}
|
||||
|
||||
if (fieldList.isEmpty()) {
|
||||
throw new RuntimeException("无法解析字段信息,请检查SQL语句格式");
|
||||
}
|
||||
|
||||
return classInfo;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("解析DDL SQL失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析表信息
|
||||
*/
|
||||
private static void parseTableInfo(String sql, ClassInfo classInfo, String ignorePrefix) {
|
||||
// 匹配表名的正则表达式
|
||||
Pattern tablePattern = Pattern.compile("CREATE\\s+TABLE\\s+[`'\"]*([\\w_]+)[`'\"]*", Pattern.CASE_INSENSITIVE);
|
||||
Matcher tableMatcher = tablePattern.matcher(sql);
|
||||
|
||||
if (tableMatcher.find()) {
|
||||
String tableName = tableMatcher.group(1);
|
||||
classInfo.setOriginTableName(tableName);
|
||||
|
||||
// 去掉前缀
|
||||
String processedTableName = tableName;
|
||||
if (StringUtils.isNotBlank(ignorePrefix) && tableName.startsWith(ignorePrefix)) {
|
||||
processedTableName = tableName.substring(ignorePrefix.length());
|
||||
}
|
||||
|
||||
classInfo.setTableName(processedTableName);
|
||||
classInfo.setClassName(toCamelCase(processedTableName, true));
|
||||
}
|
||||
|
||||
// 匹配表注释
|
||||
Pattern commentPattern = Pattern.compile("COMMENT\\s*=\\s*['\"]([^'\"]*)['\"]", Pattern.CASE_INSENSITIVE);
|
||||
Matcher commentMatcher = commentPattern.matcher(sql);
|
||||
if (commentMatcher.find()) {
|
||||
classInfo.setClassComment(commentMatcher.group(1));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析字段信息
|
||||
*/
|
||||
private static void parseFieldInfo(String sql, List<FieldInfo> fieldList) {
|
||||
// 匹配字段定义的正则表达式
|
||||
Pattern fieldPattern = Pattern.compile(
|
||||
"[`'\"]*([\\w_]+)[`'\"]*\\s+([\\w()]+).*?(?:COMMENT\\s*['\"]([^'\"]*)['\"])?",
|
||||
Pattern.CASE_INSENSITIVE
|
||||
);
|
||||
|
||||
String[] lines = sql.split("\n");
|
||||
for (String line : lines) {
|
||||
line = line.trim();
|
||||
// 跳过非字段行
|
||||
if (line.startsWith("CREATE") || line.startsWith("PRIMARY") ||
|
||||
line.startsWith("KEY") || line.startsWith("INDEX") ||
|
||||
line.startsWith(")") || line.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Matcher fieldMatcher = fieldPattern.matcher(line);
|
||||
if (fieldMatcher.find()) {
|
||||
FieldInfo fieldInfo = new FieldInfo();
|
||||
String columnName = fieldMatcher.group(1);
|
||||
String columnType = fieldMatcher.group(2);
|
||||
String comment = fieldMatcher.group(3);
|
||||
|
||||
fieldInfo.setColumnName(columnName);
|
||||
fieldInfo.setFieldName(toCamelCase(columnName, false));
|
||||
fieldInfo.setFieldClass(getJavaType(columnType));
|
||||
fieldInfo.setSwaggerClass(getSwaggerType(columnType));
|
||||
fieldInfo.setFieldComment(comment != null ? comment : "");
|
||||
|
||||
fieldList.add(fieldInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为驼峰命名
|
||||
*
|
||||
* @param str 原字符串
|
||||
* @param firstUpper 首字母是否大写
|
||||
* @return 驼峰命名字符串
|
||||
*/
|
||||
private static String toCamelCase(String str, boolean firstUpper) {
|
||||
if (StringUtils.isBlank(str)) {
|
||||
return str;
|
||||
}
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
String[] parts = str.toLowerCase().split("_");
|
||||
|
||||
for (int i = 0; i < parts.length; i++) {
|
||||
String part = parts[i];
|
||||
if (StringUtils.isNotBlank(part)) {
|
||||
if (i == 0 && !firstUpper) {
|
||||
result.append(part);
|
||||
} else {
|
||||
result.append(part.substring(0, 1).toUpperCase())
|
||||
.append(part.substring(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Java类型
|
||||
*/
|
||||
private static String getJavaType(String mysqlType) {
|
||||
String lowerType = mysqlType.toLowerCase();
|
||||
if (lowerType.contains("bigint")) {
|
||||
return "Long";
|
||||
} else if (lowerType.contains("int") || lowerType.contains("tinyint")) {
|
||||
return "Integer";
|
||||
} else if (lowerType.contains("varchar") || lowerType.contains("text") || lowerType.contains("char")) {
|
||||
return "String";
|
||||
} else if (lowerType.contains("decimal") || lowerType.contains("double")) {
|
||||
return "Double";
|
||||
} else if (lowerType.contains("float")) {
|
||||
return "Float";
|
||||
} else if (lowerType.contains("date") || lowerType.contains("time")) {
|
||||
return "Date";
|
||||
} else {
|
||||
return "String";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Swagger类型
|
||||
*/
|
||||
private static String getSwaggerType(String mysqlType) {
|
||||
String lowerType = mysqlType.toLowerCase();
|
||||
if (lowerType.contains("int") || lowerType.contains("tinyint")) {
|
||||
return "integer";
|
||||
} else if (lowerType.contains("varchar") || lowerType.contains("text") || lowerType.contains("char")) {
|
||||
return "string";
|
||||
} else if (lowerType.contains("decimal") || lowerType.contains("double") || lowerType.contains("float")) {
|
||||
return "number";
|
||||
} else if (lowerType.contains("date") || lowerType.contains("time")) {
|
||||
return "string";
|
||||
} else {
|
||||
return "string";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.agileboot.codegen.util;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @author lvyanpu
|
||||
*/
|
||||
public final class mysqlJavaTypeUtil {
|
||||
|
||||
@Getter
|
||||
public static final HashMap<String, String> mysqlJavaTypeMap = new HashMap<>();
|
||||
@Getter
|
||||
public static final HashMap<String, String> mysqlSwaggerTypeMap = new HashMap<>();
|
||||
|
||||
static {
|
||||
mysqlJavaTypeMap.put("bigint", "Long");
|
||||
mysqlJavaTypeMap.put("int", "Integer");
|
||||
mysqlJavaTypeMap.put("tinyint", "Integer");
|
||||
mysqlJavaTypeMap.put("smallint", "Integer");
|
||||
mysqlJavaTypeMap.put("mediumint", "Integer");
|
||||
mysqlJavaTypeMap.put("integer", "Integer");
|
||||
//小数
|
||||
mysqlJavaTypeMap.put("float", "Float");
|
||||
mysqlJavaTypeMap.put("double", "Double");
|
||||
mysqlJavaTypeMap.put("decimal", "Double");
|
||||
//bool
|
||||
mysqlJavaTypeMap.put("bit", "Boolean");
|
||||
//字符串
|
||||
mysqlJavaTypeMap.put("char", "String");
|
||||
mysqlJavaTypeMap.put("varchar", "String");
|
||||
mysqlJavaTypeMap.put("tinytext", "String");
|
||||
mysqlJavaTypeMap.put("text", "String");
|
||||
mysqlJavaTypeMap.put("mediumtext", "String");
|
||||
mysqlJavaTypeMap.put("longtext", "String");
|
||||
//日期
|
||||
mysqlJavaTypeMap.put("date", "Date");
|
||||
mysqlJavaTypeMap.put("datetime", "Date");
|
||||
mysqlJavaTypeMap.put("timestamp", "Date");
|
||||
|
||||
|
||||
mysqlSwaggerTypeMap.put("bigint", "integer");
|
||||
mysqlSwaggerTypeMap.put("int", "integer");
|
||||
mysqlSwaggerTypeMap.put("tinyint", "integer");
|
||||
mysqlSwaggerTypeMap.put("smallint", "integer");
|
||||
mysqlSwaggerTypeMap.put("mediumint", "integer");
|
||||
mysqlSwaggerTypeMap.put("integer", "integer");
|
||||
mysqlSwaggerTypeMap.put("boolean", "boolean");
|
||||
mysqlSwaggerTypeMap.put("float", "number");
|
||||
mysqlSwaggerTypeMap.put("double", "number");
|
||||
mysqlSwaggerTypeMap.put("decimal", "Double");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package com.agileboot.codegen.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 用户模板视图对象
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-09-26
|
||||
*/
|
||||
@Data
|
||||
public class UserTemplateVO {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 模板名称
|
||||
*/
|
||||
private String templateName;
|
||||
|
||||
/**
|
||||
* 模板分组
|
||||
*/
|
||||
private String templateGroup;
|
||||
|
||||
/**
|
||||
* 模板内容(FreeMarker模板)
|
||||
*/
|
||||
private String templateContent;
|
||||
|
||||
/**
|
||||
* 模板描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 是否公开(0-私有 1-公开)
|
||||
*/
|
||||
private Integer isPublic;
|
||||
|
||||
/**
|
||||
* 是否公开文本
|
||||
*/
|
||||
private String isPublicText;
|
||||
|
||||
/**
|
||||
* 模板版本
|
||||
*/
|
||||
private String version;
|
||||
|
||||
/**
|
||||
* 使用次数统计
|
||||
*/
|
||||
private Integer useCount;
|
||||
|
||||
/**
|
||||
* 状态(0-草稿 1-发布 2-禁用)
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 状态文本
|
||||
*/
|
||||
private String statusText;
|
||||
|
||||
/**
|
||||
* 是否启用显示(0-隐藏 1-显示)
|
||||
*/
|
||||
private Integer isEnabled;
|
||||
|
||||
/**
|
||||
* 模板内容是否公开(0-不公开 1-公开)
|
||||
*/
|
||||
private Integer isContentPublic;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 是否为当前用户创建
|
||||
*/
|
||||
private Boolean isOwner;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
server:
|
||||
port: 9211
|
||||
spring:
|
||||
application:
|
||||
name: wol-codegen
|
||||
profiles:
|
||||
active: dev
|
||||
@@ -0,0 +1,295 @@
|
||||
[{
|
||||
"group": "ui",
|
||||
"templates": [{
|
||||
"id": "10",
|
||||
"name": "swagger-ui",
|
||||
"description": "swagger-ui"
|
||||
},
|
||||
{
|
||||
"id": "11",
|
||||
"name": "element-ui",
|
||||
"description": "element-ui"
|
||||
},
|
||||
{
|
||||
"id": "12",
|
||||
"name": "bootstrap-ui",
|
||||
"description": "bootstrap-ui"
|
||||
},
|
||||
{
|
||||
"id": "13",
|
||||
"name": "layui-edit",
|
||||
"description": "layui-edit"
|
||||
},
|
||||
{
|
||||
"id": "14",
|
||||
"name": "layui-list",
|
||||
"description": "layui-list"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "mybatis",
|
||||
"templates": [{
|
||||
"id": "20",
|
||||
"name": "controller",
|
||||
"description": "controller"
|
||||
},
|
||||
{
|
||||
"id": "21",
|
||||
"name": "service",
|
||||
"description": "service"
|
||||
},
|
||||
{
|
||||
"id": "22",
|
||||
"name": "service_impl",
|
||||
"description": "service_impl"
|
||||
},
|
||||
{
|
||||
"id": "23",
|
||||
"name": "mapper",
|
||||
"description": "mapper"
|
||||
},
|
||||
{
|
||||
"id": "24",
|
||||
"name": "mybatis",
|
||||
"description": "mybatis"
|
||||
},
|
||||
{
|
||||
"id": "25",
|
||||
"name": "model",
|
||||
"description": "model"
|
||||
},
|
||||
{
|
||||
"id": "26",
|
||||
"name": "mapper2",
|
||||
"description": "mapper annotation"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "jpa",
|
||||
"templates": [{
|
||||
"id": "30",
|
||||
"name": "entity",
|
||||
"description": "entity"
|
||||
},
|
||||
{
|
||||
"id": "31",
|
||||
"name": "repository",
|
||||
"description": "repository"
|
||||
},
|
||||
{
|
||||
"id": "32",
|
||||
"name": "jpacontroller",
|
||||
"description": "jpacontroller"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"group": "jdbc-template",
|
||||
"templates": [{
|
||||
"id": "40",
|
||||
"name": "jtdao",
|
||||
"description": "jtdao"
|
||||
},
|
||||
{
|
||||
"id": "41",
|
||||
"name": "jtdaoimpl",
|
||||
"description": "jtdaoimpl"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"group": "beetlsql",
|
||||
"templates": [{
|
||||
"id": "50",
|
||||
"name": "beetlmd",
|
||||
"description": "beetlmd"
|
||||
},
|
||||
{
|
||||
"id": "51",
|
||||
"name": "beetlentity",
|
||||
"description": "beetlentity"
|
||||
},
|
||||
{
|
||||
"id": "52",
|
||||
"name": "beetlcontroller",
|
||||
"description": "beetlcontroller"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"group": "mybatis-plus",
|
||||
"templates": [{
|
||||
"id": "60",
|
||||
"name": "pluscontroller",
|
||||
"description": "pluscontroller"
|
||||
},
|
||||
{
|
||||
"id": "61",
|
||||
"name": "plusservice",
|
||||
"description": "plusservice"
|
||||
},
|
||||
{
|
||||
"id": "62",
|
||||
"name": "plusmapper",
|
||||
"description": "plusmapper"
|
||||
},
|
||||
{
|
||||
"id": "63",
|
||||
"name": "plusentity",
|
||||
"description": "plusentity"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"group": "util",
|
||||
"templates": [{
|
||||
"id": "70",
|
||||
"name": "beanutil",
|
||||
"description": "beanutil"
|
||||
},
|
||||
{
|
||||
"id": "71",
|
||||
"name": "json",
|
||||
"description": "json"
|
||||
},
|
||||
{
|
||||
"id": "72",
|
||||
"name": "xml",
|
||||
"description": "xml"
|
||||
},
|
||||
{
|
||||
"id": "73",
|
||||
"name": "sql",
|
||||
"description": "sql"
|
||||
},
|
||||
{
|
||||
"id": "74",
|
||||
"name": "swagger-yml",
|
||||
"description": "swagger-yml"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"group": "common-mapper",
|
||||
"templates": [{
|
||||
"id": "81",
|
||||
"name": "tkentity",
|
||||
"description": "tkentity"
|
||||
},
|
||||
{
|
||||
"id": "82",
|
||||
"name": "tkmapper",
|
||||
"description": "tkmapper"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"group": "renren-fast",
|
||||
"templates": [{
|
||||
"id": "91",
|
||||
"name": "menu-sql",
|
||||
"description": "menu-sql"
|
||||
},
|
||||
{
|
||||
"id": "92",
|
||||
"name": "vue-list",
|
||||
"description": "vue-list"
|
||||
},
|
||||
{
|
||||
"id": "93",
|
||||
"name": "vue-edit",
|
||||
"description": "vue-edit"
|
||||
},
|
||||
{
|
||||
"id": "94",
|
||||
"name": "rr-controller",
|
||||
"description": "rr-controller"
|
||||
},
|
||||
{
|
||||
"id": "95",
|
||||
"name": "rr-dao",
|
||||
"description": "rr-dao"
|
||||
},
|
||||
{
|
||||
"id": "96",
|
||||
"name": "rr-daoxml",
|
||||
"description": "rr-daoxml"
|
||||
},
|
||||
{
|
||||
"id": "97",
|
||||
"name": "rr-service",
|
||||
"description": "rr-service"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "jpa-starp",
|
||||
"templates": [{
|
||||
"id": "101",
|
||||
"name": "starp-entity",
|
||||
"description": "entity"
|
||||
},
|
||||
{
|
||||
"id": "102",
|
||||
"name": "starp-repository",
|
||||
"description": "repository"
|
||||
},
|
||||
{
|
||||
"id": "103",
|
||||
"name": "starp-jpa-controller",
|
||||
"description": "jpacontroller"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "bi",
|
||||
"templates": [{
|
||||
"id": "201",
|
||||
"name": "qliksense",
|
||||
"description": "qlik sense"
|
||||
}]
|
||||
},
|
||||
{
|
||||
"group": "cloud",
|
||||
"templates": [
|
||||
{
|
||||
"id": "301",
|
||||
"name": "bigquery",
|
||||
"description": "GCP BigQuery"
|
||||
},
|
||||
{
|
||||
"id": "302",
|
||||
"name": "dataflowjjs",
|
||||
"description": "GCP Dataflow JJS"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "tk-mybatis",
|
||||
"templates": [
|
||||
{
|
||||
"id": "401",
|
||||
"name": "tk-entity",
|
||||
"description": "tk-entity"
|
||||
},
|
||||
{
|
||||
"id": "402",
|
||||
"name": "tk-mapper",
|
||||
"description": "tk-mapper"
|
||||
},
|
||||
{
|
||||
"id": "403",
|
||||
"name": "tk-controller",
|
||||
"description": "tk-controller"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,295 @@
|
||||
[{
|
||||
"group": "ui",
|
||||
"templates": [{
|
||||
"id": "10",
|
||||
"name": "swagger-ui",
|
||||
"description": "swagger-ui"
|
||||
},
|
||||
{
|
||||
"id": "11",
|
||||
"name": "element-ui",
|
||||
"description": "element-ui"
|
||||
},
|
||||
{
|
||||
"id": "12",
|
||||
"name": "bootstrap-ui",
|
||||
"description": "bootstrap-ui"
|
||||
},
|
||||
{
|
||||
"id": "13",
|
||||
"name": "layui-edit",
|
||||
"description": "layui-edit"
|
||||
},
|
||||
{
|
||||
"id": "14",
|
||||
"name": "layui-list",
|
||||
"description": "layui-list"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "mybatis",
|
||||
"templates": [{
|
||||
"id": "20",
|
||||
"name": "controller",
|
||||
"description": "controller"
|
||||
},
|
||||
{
|
||||
"id": "21",
|
||||
"name": "service",
|
||||
"description": "service"
|
||||
},
|
||||
{
|
||||
"id": "22",
|
||||
"name": "service_impl",
|
||||
"description": "service_impl"
|
||||
},
|
||||
{
|
||||
"id": "23",
|
||||
"name": "mapper",
|
||||
"description": "mapper"
|
||||
},
|
||||
{
|
||||
"id": "24",
|
||||
"name": "mybatis",
|
||||
"description": "mybatis"
|
||||
},
|
||||
{
|
||||
"id": "25",
|
||||
"name": "model",
|
||||
"description": "model"
|
||||
},
|
||||
{
|
||||
"id": "26",
|
||||
"name": "mapper2",
|
||||
"description": "mapper annotation"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "jpa",
|
||||
"templates": [{
|
||||
"id": "30",
|
||||
"name": "entity",
|
||||
"description": "entity"
|
||||
},
|
||||
{
|
||||
"id": "31",
|
||||
"name": "repository",
|
||||
"description": "repository"
|
||||
},
|
||||
{
|
||||
"id": "32",
|
||||
"name": "jpacontroller",
|
||||
"description": "jpacontroller"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"group": "jdbc-template",
|
||||
"templates": [{
|
||||
"id": "40",
|
||||
"name": "jtdao",
|
||||
"description": "jtdao"
|
||||
},
|
||||
{
|
||||
"id": "41",
|
||||
"name": "jtdaoimpl",
|
||||
"description": "jtdaoimpl"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"group": "beetlsql",
|
||||
"templates": [{
|
||||
"id": "50",
|
||||
"name": "beetlmd",
|
||||
"description": "beetlmd"
|
||||
},
|
||||
{
|
||||
"id": "51",
|
||||
"name": "beetlentity",
|
||||
"description": "beetlentity"
|
||||
},
|
||||
{
|
||||
"id": "52",
|
||||
"name": "beetlcontroller",
|
||||
"description": "beetlcontroller"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"group": "mybatis-plus",
|
||||
"templates": [{
|
||||
"id": "60",
|
||||
"name": "pluscontroller",
|
||||
"description": "pluscontroller"
|
||||
},
|
||||
{
|
||||
"id": "61",
|
||||
"name": "plusservice",
|
||||
"description": "plusservice"
|
||||
},
|
||||
{
|
||||
"id": "62",
|
||||
"name": "plusmapper",
|
||||
"description": "plusmapper"
|
||||
},
|
||||
{
|
||||
"id": "63",
|
||||
"name": "plusentity",
|
||||
"description": "plusentity"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"group": "util",
|
||||
"templates": [{
|
||||
"id": "70",
|
||||
"name": "beanutil",
|
||||
"description": "beanutil"
|
||||
},
|
||||
{
|
||||
"id": "71",
|
||||
"name": "json",
|
||||
"description": "json"
|
||||
},
|
||||
{
|
||||
"id": "72",
|
||||
"name": "xml",
|
||||
"description": "xml"
|
||||
},
|
||||
{
|
||||
"id": "73",
|
||||
"name": "sql",
|
||||
"description": "sql"
|
||||
},
|
||||
{
|
||||
"id": "74",
|
||||
"name": "swagger-yml",
|
||||
"description": "swagger-yml"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"group": "common-mapper",
|
||||
"templates": [{
|
||||
"id": "81",
|
||||
"name": "tkentity",
|
||||
"description": "tkentity"
|
||||
},
|
||||
{
|
||||
"id": "82",
|
||||
"name": "tkmapper",
|
||||
"description": "tkmapper"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"group": "renren-fast",
|
||||
"templates": [{
|
||||
"id": "91",
|
||||
"name": "menu-sql",
|
||||
"description": "menu-sql"
|
||||
},
|
||||
{
|
||||
"id": "92",
|
||||
"name": "vue-list",
|
||||
"description": "vue-list"
|
||||
},
|
||||
{
|
||||
"id": "93",
|
||||
"name": "vue-edit",
|
||||
"description": "vue-edit"
|
||||
},
|
||||
{
|
||||
"id": "94",
|
||||
"name": "rr-controller",
|
||||
"description": "rr-controller"
|
||||
},
|
||||
{
|
||||
"id": "95",
|
||||
"name": "rr-dao",
|
||||
"description": "rr-dao"
|
||||
},
|
||||
{
|
||||
"id": "96",
|
||||
"name": "rr-daoxml",
|
||||
"description": "rr-daoxml"
|
||||
},
|
||||
{
|
||||
"id": "97",
|
||||
"name": "rr-service",
|
||||
"description": "rr-service"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "jpa-starp",
|
||||
"templates": [{
|
||||
"id": "101",
|
||||
"name": "starp-entity",
|
||||
"description": "entity"
|
||||
},
|
||||
{
|
||||
"id": "102",
|
||||
"name": "starp-repository",
|
||||
"description": "repository"
|
||||
},
|
||||
{
|
||||
"id": "103",
|
||||
"name": "starp-jpa-controller",
|
||||
"description": "jpacontroller"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "bi",
|
||||
"templates": [{
|
||||
"id": "201",
|
||||
"name": "qliksense",
|
||||
"description": "qlik sense"
|
||||
}]
|
||||
},
|
||||
{
|
||||
"group": "cloud",
|
||||
"templates": [
|
||||
{
|
||||
"id": "301",
|
||||
"name": "bigquery",
|
||||
"description": "GCP BigQuery"
|
||||
},
|
||||
{
|
||||
"id": "302",
|
||||
"name": "dataflowjjs",
|
||||
"description": "GCP Dataflow JJS"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "tk-mybatis",
|
||||
"templates": [
|
||||
{
|
||||
"id": "401",
|
||||
"name": "tk-entity",
|
||||
"description": "tk-entity"
|
||||
},
|
||||
{
|
||||
"id": "402",
|
||||
"name": "tk-mapper",
|
||||
"description": "tk-mapper"
|
||||
},
|
||||
{
|
||||
"id": "403",
|
||||
"name": "tk-controller",
|
||||
"description": "tk-controller"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,75 @@
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
</#if>
|
||||
/**
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/${classInfo.className?uncap_first}")
|
||||
public class ${classInfo.className}Controller {
|
||||
|
||||
@Autowired
|
||||
private SQLManager sqlManager;
|
||||
|
||||
/**
|
||||
* 新增或编辑
|
||||
*/
|
||||
@PostMapping("/save")
|
||||
public Object save(${classInfo.className} ${classInfo.className?uncap_first}){
|
||||
${classInfo.className} ${classInfo.className?uncap_first}=sqlManager.unique(${classInfo.className}.class,${classInfo.className?uncap_first}.getId());
|
||||
if(${classInfo.className?uncap_first}!=null){
|
||||
sqlManager.updateById(${classInfo.className?uncap_first});
|
||||
return ${returnUtilSuccess}("编辑成功");
|
||||
}else{
|
||||
sqlManager.insert(${classInfo.className?uncap_first});
|
||||
return ${returnUtilFailure}("保存成功");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public Object delete(int id){
|
||||
${classInfo.className} ${classInfo.className?uncap_first}=sqlManager.unique(${classInfo.className}.class,id);
|
||||
if(${classInfo.className?uncap_first}!=null){
|
||||
sqlManager.deleteById(id);
|
||||
return ${returnUtilSuccess}("删除成功");
|
||||
}else{
|
||||
return ${returnUtilFailure}("没有找到该对象");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询
|
||||
*/
|
||||
@PostMapping("/find")
|
||||
public Object find(int id){
|
||||
${classInfo.className} ${classInfo.className?uncap_first}=sqlManager.unique(${classInfo.className}.class,id);
|
||||
if(${classInfo.className?uncap_first}!=null){
|
||||
return ${returnUtilSuccess}(${classInfo.className?uncap_first});
|
||||
}else{
|
||||
return ${returnUtilFailure}("没有找到该对象");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
public Object list(${classInfo.className} ${classInfo.className?uncap_first},
|
||||
@RequestParam(required = false, defaultValue = "0") int pageNumber,
|
||||
@RequestParam(required = false, defaultValue = "10") int pageSize) {
|
||||
List<${classInfo.className}> list = sqlManager.query(${classInfo.className}.class).select();
|
||||
return ${returnUtilSuccess}(list);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
</#if>
|
||||
/**
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
@Data<#if isSwagger?exists && isSwagger==true>
|
||||
@Schema"${classInfo.classComment}")</#if>
|
||||
public class ${classInfo.className} implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<#if isComment?exists && isComment==true>/**
|
||||
* ${fieldItem.fieldComment}
|
||||
*/</#if><#if isSwagger?exists && isSwagger==true>
|
||||
@Schema(description = "${fieldItem.fieldComment}")</#if>
|
||||
private ${fieldItem.fieldClass} ${fieldItem.fieldName};
|
||||
|
||||
</#list>
|
||||
public ${classInfo.className}() {
|
||||
}
|
||||
</#if>
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
sample
|
||||
===
|
||||
|
||||
select #use("cols")# from ${classInfo.tableName} where #use("condition")#
|
||||
|
||||
cols
|
||||
===
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
`${fieldItem.columnName}`<#if fieldItem_has_next>,</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
|
||||
updateSample
|
||||
===
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
`${fieldItem.columnName}=#${fieldItem.fieldName}#`<#if fieldItem_has_next>,</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
|
||||
condition
|
||||
===
|
||||
1 = 1
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
@if(!isEmpty(${fieldItem.fieldName})){
|
||||
and `${fieldItem.columnName}`=#${fieldItem.fieldName}#
|
||||
@}
|
||||
</#list>
|
||||
</#if>
|
||||
@@ -0,0 +1,94 @@
|
||||
//***************************
|
||||
//[${classInfo.classComment} - ${classInfo.tableName}]
|
||||
//AUTHOR ${authorName}
|
||||
//HISTORY ${.now?string('yyyy-MM-dd')}
|
||||
//***************************
|
||||
|
||||
//***************************
|
||||
//load all
|
||||
[${classInfo.tableName}]:
|
||||
LOAD * FROM ['LIB://QVD/${classInfo.className}.qvd'](qvd);
|
||||
|
||||
//***************************
|
||||
//load columns
|
||||
[${classInfo.tableName}]:
|
||||
LOAD
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
"${fieldItem.columnName}" as "${fieldItem.fieldName}"<#if fieldItem_has_next>,</#if>
|
||||
</#list>
|
||||
FROM
|
||||
['LIB://QVD/${classInfo.className}.qvd'](qvd);
|
||||
;
|
||||
|
||||
//load inline
|
||||
[${classInfo.tableName}]:
|
||||
LOAD * INLINE
|
||||
[
|
||||
<#list classInfo.fieldList as fieldItem >${fieldItem.columnName} <#if fieldItem_has_next>,</#if></#list>
|
||||
<#list classInfo.fieldList as fieldItem >${fieldItem.fieldName} <#if fieldItem_has_next>,</#if></#list>
|
||||
<#list classInfo.fieldList as fieldItem >${fieldItem.fieldComment} <#if fieldItem_has_next>,</#if></#list>
|
||||
];
|
||||
|
||||
//***************************
|
||||
//load from api data connection (wrap on)
|
||||
LIB CONNECT TO '${classInfo.tableName}_api';
|
||||
|
||||
RestConnectorMasterTable:
|
||||
SQL SELECT
|
||||
"__KEY_root",
|
||||
(SELECT
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
"${fieldItem.columnName}"
|
||||
</#list>
|
||||
"__FK_object"
|
||||
FROM "object" FK "__FK_object")
|
||||
FROM JSON (wrap on) "root" PK "__KEY_root"
|
||||
// WITH CONNECTION (
|
||||
// Url "https://localhost:8080/${classInfo.tableName}_api",
|
||||
// QUERY "page" "1",
|
||||
// QUERY "size" "100",
|
||||
// HTTPHEADER "token" "123456",
|
||||
// BODY "Post body here")
|
||||
;
|
||||
|
||||
[${classInfo.className}]:
|
||||
LOAD
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
[${fieldItem.columnName}] as [${fieldItem.fieldName}]
|
||||
</#list>
|
||||
[__FK_object] AS [__KEY_root]
|
||||
RESIDENT RestConnectorMasterTable
|
||||
WHERE NOT IsNull([__FK_stores]);
|
||||
|
||||
DROP TABLE [${classInfo.className}];
|
||||
DROP TABLE RestConnectorMasterTable;
|
||||
|
||||
//***************************
|
||||
//load from api data connection (wrap off)
|
||||
LIB CONNECT TO '${classInfo.tableName}_api';
|
||||
[${classInfo.className}]:
|
||||
SQL SELECT
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
[${fieldItem.fieldName}] as [${fieldItem.fieldName}]<#if fieldItem_has_next>,</#if>
|
||||
</#list>
|
||||
FROM JSON(wrap off) "${classInfo.className}"
|
||||
// WITH CONNECTION (
|
||||
// Url "https://localhost:8080/${classInfo.tableName}_api",
|
||||
// QUERY "page" "1",
|
||||
// QUERY "size" "100",
|
||||
// HTTPHEADER "token" "123456",
|
||||
// BODY "Post body here")
|
||||
;
|
||||
|
||||
//***************************
|
||||
//load from sql data connection
|
||||
LIB CONNECT TO '${classInfo.tableName}_db';
|
||||
|
||||
SQL SELECT
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
[${fieldItem.columnName}] as [${fieldItem.fieldName}]<#if fieldItem_has_next>,</#if>
|
||||
</#list>
|
||||
FROM
|
||||
${classInfo.tableName}
|
||||
WHERE
|
||||
Create_Time > '2023-01-01 00:00:00';
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
SELECT * FROM 'your_project.your_dataset.${tableName}' t
|
||||
order by t.id desc
|
||||
LIMIT 100
|
||||
;
|
||||
|
||||
SELECT * FROM 'your_project.your_dataset.${tableName}_error_records' t
|
||||
order by t.timestamp desc
|
||||
LIMIT 100
|
||||
;
|
||||
|
||||
bigquery table -> SCHEMA -> Edit as text , then input below text:
|
||||
[
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
{"name":"${fieldItem.columnName}",type:"STRING","mode":"NULLABLE","description": "${fieldItem.fieldName} - ${fieldItem.fieldComment}"}<#if fieldItem_has_next>,</#if>
|
||||
</#list>
|
||||
]
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* GCP - dataflow job jjs for [${classInfo.classComment} - ${classInfo.tableName}]
|
||||
* AUTHOR ${authorName}
|
||||
*
|
||||
* User-defined function (UDF) to transform events as part of a Dataflow template job.
|
||||
* upload to GCS and create dataflow job with this js file and method as 'process'
|
||||
* @param {string} inJson input Pub/Sub JSON message (stringified)
|
||||
* @return {string} outJson output JSON message (stringified)
|
||||
*/
|
||||
function process(inJson) {
|
||||
//for local js debug
|
||||
//var obj = JSON.parse(JSON.stringify(inJson));
|
||||
//for online jjs
|
||||
var obj = JSON.parse(inJson);
|
||||
var includePubsubMessage = obj.data && obj.attributes;
|
||||
var data = includePubsubMessage ? obj.data : obj;
|
||||
//debug and show error if you need special logic
|
||||
if(data.hasOwnProperty('show_error')){
|
||||
throw new ERROR("show_error:"+JSON.stringify(data))
|
||||
}
|
||||
// INSERT CUSTOM TRANSFORMATION LOGIC HERE
|
||||
var tableObj= {};
|
||||
tableObj.insert_time=new Date().toUTCString()
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
tableObj.${fieldItem.columnName}=data.${fieldItem.fieldName}
|
||||
</#list>
|
||||
return JSON.stringify(tableObj);
|
||||
}
|
||||
|
||||
//field name = field name
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
tableObj.${fieldItem.fieldName}=data.${fieldItem.fieldName}
|
||||
</#list>
|
||||
|
||||
//column name = column name
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
tableObj.${fieldItem.columnName}=data.${fieldItem.columnName}
|
||||
</#list>
|
||||
@@ -0,0 +1,49 @@
|
||||
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.entity;</#if>
|
||||
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
<#if isLombok?exists && isLombok==true>import lombok.Data;</#if>
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.*;
|
||||
<#if isSwagger?exists && isSwagger==true>
|
||||
import io.swagger.v3.oas.annotations.media.Schema;</#if>
|
||||
</#if>
|
||||
/**
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
<#if isLombok?exists && isLombok==true>@Data</#if>
|
||||
<#if isComment?exists && isComment==true>@Table(name="${classInfo.originTableName}")</#if><#if isSwagger?exists && isSwagger==true>
|
||||
@Schema"${classInfo.classComment}")</#if>
|
||||
public class ${classInfo.className} implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<#if isComment?exists && isComment==true>/**
|
||||
* ${fieldItem.fieldComment}
|
||||
*/</#if><#if isSwagger?exists && isSwagger==true>
|
||||
@Schema(description = "${fieldItem.fieldComment}")</#if>
|
||||
<#if isComment?exists && isComment==true>@Column(name="${fieldItem.columnName}")</#if>
|
||||
private ${fieldItem.fieldClass} ${fieldItem.fieldName};
|
||||
|
||||
</#list>
|
||||
public ${classInfo.className}() {
|
||||
}
|
||||
</#if>
|
||||
|
||||
<#if isLombok?exists && isLombok==false>
|
||||
public ${fieldItem.fieldClass} get${fieldItem.fieldName?cap_first}() {
|
||||
return ${fieldItem.fieldName};
|
||||
}
|
||||
|
||||
public void set${fieldItem.fieldName?cap_first}(${fieldItem.fieldClass} ${fieldItem.fieldName}) {
|
||||
this.${fieldItem.fieldName} = ${fieldItem.fieldName};
|
||||
}
|
||||
</#if>
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.mapper;</#if>
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
import tk.mybatis.mapper.common.Mapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import ${packageName}.entity.${classInfo.className};
|
||||
</#if>
|
||||
/**
|
||||
* @description ${classInfo.classComment}Mapper
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
@Mapper
|
||||
public interface ${classInfo.className}Mapper extends Mapper<${classInfo.className}> {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
import java.util.List;
|
||||
</#if>
|
||||
/**
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
public interface I${classInfo.className}DAO {
|
||||
|
||||
int add(${classInfo.className} ${classInfo.className?uncap_first});
|
||||
|
||||
int update(${classInfo.className} ${classInfo.className?uncap_first});
|
||||
|
||||
int delete(int id);
|
||||
|
||||
${classInfo.className} findById(int id);
|
||||
|
||||
List<${classInfo.className}> findAllList(Map<String,Object> param);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import java.util.List;
|
||||
</#if>
|
||||
|
||||
/**
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
@Repository
|
||||
public class ${classInfo.className}DaoImpl implements I${classInfo.className}Dao{
|
||||
|
||||
@Autowired
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Override
|
||||
public int add(${classInfo.className} ${classInfo.className?uncap_first}) {
|
||||
return jdbcTemplate.update("insert into ${classInfo.originTableName} (<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0><#list classInfo.fieldList as fieldItem >${fieldItem.columnName}<#if fieldItem_has_next>,</#if></#list></#if> ) values (<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0><#list classInfo.fieldList as fieldItem >?<#if fieldItem_has_next>,</#if></#list></#if> )",
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0><#list classInfo.fieldList as fieldItem >${classInfo.className?uncap_first}.get${fieldItem.fieldName?cap_first}()<#if fieldItem_has_next>,</#if></#list></#if>);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(${classInfo.className} ${classInfo.className?uncap_first}) {
|
||||
return jdbcTemplate.update("UPDATE ${classInfo.originTableName} SET <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0><#list classInfo.fieldList as fieldItem ><#if fieldItem_index gt 0 >${fieldItem.columnName}=?<#if fieldItem_has_next>,</#if></#if></#list></#if>"
|
||||
+" where <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0><#list classInfo.fieldList as fieldItem ><#if fieldItem_index = 0>${fieldItem.columnName}=?<#break ></#if></#list></#if>",
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem ><#if fieldItem_index gt 0 >${classInfo.className?uncap_first}.get${fieldItem.fieldName?cap_first}(),</#if></#list>
|
||||
<#list classInfo.fieldList as fieldItem ><#if fieldItem_index = 0 >${classInfo.className?uncap_first}.get${fieldItem.fieldName?cap_first}()</#if></#list>
|
||||
</#if>);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(int id) {
|
||||
return jdbcTemplate.update("DELETE from ${classInfo.originTableName} where <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0><#list classInfo.fieldList as fieldItem ><#if fieldItem_index = 0>${fieldItem.columnName}=?<#break ></#if></#list></#if>",id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ${classInfo.className} findById(int id) {
|
||||
List<${classInfo.className}> list = jdbcTemplate.query("select * from ${classInfo.originTableName} where <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0><#list classInfo.fieldList as fieldItem ><#if fieldItem_index = 0>${fieldItem.columnName}=?<#break ></#if></#list></#if>", new Object[]{id}, new BeanPropertyRowMapper<${classInfo.className}>(${classInfo.className}.class));
|
||||
if(list!=null && !list.isEmpty() ){
|
||||
return list.get(0);
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<${classInfo.className}> findAllList(Map<String,Object> params) {
|
||||
List<${classInfo.className}> list = jdbcTemplate.query("select * from ${classInfo.originTableName}", new Object[]{}, new BeanPropertyRowMapper<${classInfo.className}>(${classInfo.className}.class));
|
||||
if(list!=null && !list.isEmpty() ){
|
||||
return list;
|
||||
}else{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.entity;</#if>
|
||||
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
<#if isLombok?exists && isLombok==true>import lombok.Data;</#if>
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.GeneratedValue;
|
||||
<#if isSwagger?exists && isSwagger==true>
|
||||
import io.swagger.v3.oas.annotations.media.Schema;</#if>
|
||||
</#if>
|
||||
/**
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
@Entity
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
<#if isLombok?exists && isLombok==true>@Data</#if>
|
||||
<#if isComment?exists && isComment==true>@Table(name="${classInfo.originTableName}")</#if><#if isSwagger?exists && isSwagger==true>
|
||||
@Schema"${classInfo.classComment}")</#if>
|
||||
public class ${classInfo.className} implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@Schema(description = "id")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<#if isComment?exists && isComment==true>/**
|
||||
* ${fieldItem.fieldComment}
|
||||
*/</#if><#if isSwagger?exists && isSwagger==true>
|
||||
@Schema(description = "${fieldItem.fieldComment}")</#if>
|
||||
<#if isComment?exists && isComment==true>@Column(name="${fieldItem.columnName}")</#if>
|
||||
private ${fieldItem.fieldClass} ${fieldItem.fieldName};
|
||||
|
||||
</#list>
|
||||
public ${classInfo.className}() {
|
||||
}
|
||||
</#if>
|
||||
|
||||
<#if isLombok?exists && isLombok==false>
|
||||
public ${fieldItem.fieldClass} get${fieldItem.fieldName?cap_first}() {
|
||||
return ${fieldItem.fieldName};
|
||||
}
|
||||
|
||||
public void set${fieldItem.fieldName?cap_first}(${fieldItem.fieldClass} ${fieldItem.fieldName}) {
|
||||
this.${fieldItem.fieldName} = ${fieldItem.fieldName};
|
||||
}
|
||||
</#if>
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.controller;</#if>
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
import ${packageName}.entity.${classInfo.className};
|
||||
import ${packageName}.repository.${classInfo.className}Repository;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.data.domain.ExampleMatcher;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
</#if>
|
||||
/**
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Api(tags = "${classInfo.className?uncap_first}")
|
||||
@CrossOrigin
|
||||
@RestController
|
||||
@RequestMapping("/${classInfo.className?uncap_first}")
|
||||
public class ${classInfo.className}Controller {
|
||||
|
||||
@Autowired
|
||||
private ${classInfo.className}Repository ${classInfo.className?uncap_first}Repository;
|
||||
|
||||
/**
|
||||
* 新增或编辑
|
||||
*/
|
||||
@PostMapping("/save")
|
||||
@ApiOperation(value = "save ${classInfo.className}", notes = "save ${classInfo.className}")
|
||||
public Object save(@RequestBody ${classInfo.className} ${classInfo.className?uncap_first}){
|
||||
try {
|
||||
return ReturnT.success(${classInfo.className?uncap_first}Repository.save(${classInfo.className?uncap_first}));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ReturnT.error("保存失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation(value = "delete ${classInfo.className}", notes = "delete ${classInfo.className}")
|
||||
public Object delete(int id){
|
||||
Optional<${classInfo.className}> ${classInfo.className?uncap_first}=${classInfo.className?uncap_first}Repository.findById(id);
|
||||
if(${classInfo.className?uncap_first}.isPresent()){
|
||||
${classInfo.className?uncap_first}Repository.deleteById(id);
|
||||
return ${returnUtilSuccess}("删除成功");
|
||||
}else{
|
||||
return ${returnUtilFailure}("没有找到该对象");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询
|
||||
*/
|
||||
@PostMapping("/find")
|
||||
@ApiOperation(value = "find ${classInfo.className} by id", notes = "find ${classInfo.className} by id")
|
||||
public Object find(int id){
|
||||
Optional<${classInfo.className}> ${classInfo.className?uncap_first}=${classInfo.className?uncap_first}Repository.findById(id);
|
||||
if(${classInfo.className?uncap_first}.isPresent()){
|
||||
return ${returnUtilSuccess}(${classInfo.className?uncap_first}.get());
|
||||
}else{
|
||||
return ${returnUtilFailure}("没有找到该对象");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
@ApiOperation(value = "list ${classInfo.className}", notes = "list ${classInfo.className}")
|
||||
public Object list(@RequestBody ${classInfo.className} ${classInfo.className?uncap_first},
|
||||
@RequestParam(required = false, defaultValue = "0") int pageNumber,
|
||||
@RequestParam(required = false, defaultValue = "10") int pageSize) {
|
||||
|
||||
try {
|
||||
//创建匹配器,需要查询条件请修改此处代码
|
||||
ExampleMatcher matcher = ExampleMatcher.matchingAll();
|
||||
|
||||
//创建实例
|
||||
Example<${classInfo.className}> example = Example.of(${classInfo.className?uncap_first}, matcher);
|
||||
//分页构造
|
||||
Pageable pageable = PageRequest.of(pageNumber,pageSize);
|
||||
|
||||
return ReturnT.success(${classInfo.className?uncap_first}Repository.findAll(example, pageable));
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ReturnT.error(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.repository;</#if>
|
||||
<#if isAutoImport?exists && isAutoImport==true>import ${packageName}.entity.${classInfo.className};
|
||||
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<#if fieldItem.fieldClass == "Date">
|
||||
<#assign importDdate = true />
|
||||
</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
<#if importDdate?exists && importDdate==true>import java.util.Date;</#if>
|
||||
import java.util.List;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
</#if>
|
||||
/**
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
@Repository
|
||||
public interface ${classInfo.className}Repository extends JpaRepository<${classInfo.className},Integer> {
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.entity;</#if>
|
||||
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
<#if isLombok?exists && isLombok==true>import lombok.Data;</#if>
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.GeneratedValue;
|
||||
<#if isSwagger?exists && isSwagger==true>
|
||||
import io.swagger.v3.oas.annotations.media.Schema;</#if>
|
||||
</#if>
|
||||
/**
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
@Entity
|
||||
<#if isLombok?exists && isLombok==true>@Data</#if>
|
||||
<#if isComment?exists && isComment==true>@Table(name="${classInfo.originTableName}")</#if><#if isSwagger?exists && isSwagger==true>
|
||||
@Schema"${classInfo.classComment}")</#if>
|
||||
public class ${classInfo.className} implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<#if isComment?exists && isComment==true>/**
|
||||
* ${fieldItem.fieldComment}
|
||||
*/</#if><#if isSwagger?exists && isSwagger==true>
|
||||
@Schema(description = "${fieldItem.fieldComment}")</#if>
|
||||
<#if isComment?exists && isComment==true>@Column(name="${fieldItem.columnName}")</#if>
|
||||
private ${fieldItem.fieldClass} ${fieldItem.fieldName};
|
||||
|
||||
</#list>
|
||||
public ${classInfo.className}() {
|
||||
}
|
||||
|
||||
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<#if isLombok?exists && isLombok==false>
|
||||
public ${fieldItem.fieldClass} get${fieldItem.fieldName?cap_first}() {
|
||||
return ${fieldItem.fieldName};
|
||||
}
|
||||
|
||||
public void set${fieldItem.fieldName?cap_first}(${fieldItem.fieldClass} ${fieldItem.fieldName}) {
|
||||
this.${fieldItem.fieldName} = ${fieldItem.fieldName};
|
||||
}
|
||||
</#if>
|
||||
</#list>
|
||||
}
|
||||
</#if></#if>
|
||||
@@ -0,0 +1,85 @@
|
||||
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.controller;</#if>
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
import ${packageName}.entity.${classInfo.className};
|
||||
import ${packageName}.repository.${classInfo.className}Repository;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.data.domain.ExampleMatcher;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
</#if>
|
||||
/**
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/${classInfo.className?uncap_first}")
|
||||
public class ${classInfo.className}Controller {
|
||||
|
||||
@Autowired
|
||||
private ${classInfo.className}Repository ${classInfo.className?uncap_first}Repository;
|
||||
|
||||
/**
|
||||
* 新增或编辑
|
||||
*/
|
||||
@PostMapping("/save")
|
||||
public Object save(${classInfo.className} ${classInfo.className?uncap_first}){
|
||||
return ${classInfo.className?uncap_first}Repository.save(${classInfo.className?uncap_first});
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public Object delete(int id){
|
||||
Optional<${classInfo.className}> ${classInfo.className?uncap_first}=${classInfo.className?uncap_first}Repository.findById(id);
|
||||
if(${classInfo.className?uncap_first}.isPresent()){
|
||||
${classInfo.className?uncap_first}Repository.deleteById(id);
|
||||
return ${returnUtilSuccess}("删除成功");
|
||||
}else{
|
||||
return ${returnUtilFailure}("没有找到该对象");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询
|
||||
*/
|
||||
@PostMapping("/find")
|
||||
public Object find(int id){
|
||||
Optional<${classInfo.className}> ${classInfo.className?uncap_first}=${classInfo.className?uncap_first}Repository.findById(id);
|
||||
if(${classInfo.className?uncap_first}.isPresent()){
|
||||
return ${returnUtilSuccess}(${classInfo.className?uncap_first}.get());
|
||||
}else{
|
||||
return ${returnUtilFailure}("没有找到该对象");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
public Object list(${classInfo.className} ${classInfo.className?uncap_first},
|
||||
@RequestParam(required = false, defaultValue = "0") int pageNumber,
|
||||
@RequestParam(required = false, defaultValue = "10") int pageSize) {
|
||||
|
||||
//创建匹配器,需要查询条件请修改此处代码
|
||||
ExampleMatcher matcher = ExampleMatcher.matchingAll();
|
||||
|
||||
//创建实例
|
||||
Example<${classInfo.className}> example = Example.of(${classInfo.className?uncap_first}, matcher);
|
||||
//分页构造
|
||||
Pageable pageable = PageRequest.of(pageNumber,pageSize);
|
||||
|
||||
return ${classInfo.className?uncap_first}Repository.findAll(example, pageable);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.repository;</#if>
|
||||
<#if isAutoImport?exists && isAutoImport==true>import ${packageName}.entity.${classInfo.className};
|
||||
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<#if fieldItem.fieldClass == "Date">
|
||||
<#assign importDdate = true />
|
||||
</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
<#if importDdate?exists && importDdate==true>import java.util.Date;</#if>
|
||||
import java.util.List;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
</#if>
|
||||
/**
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
@Repository
|
||||
public interface ${classInfo.className}Repository extends JpaRepository<${classInfo.className},Integer> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.controller;</#if>
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import ${packageName}.entity.${classInfo.className};
|
||||
import ${packageName}.mapper.${classInfo.className}Mapper;
|
||||
import ${packageName}.util.ReturnT;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
<#if isSwagger?exists && isSwagger==true>import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;</#if>
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
</#if>
|
||||
/**
|
||||
* @description ${classInfo.classComment}控制器
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/${classInfo.className?uncap_first}")
|
||||
<#if isSwagger?exists && isSwagger==true>@Tag(name = "${classInfo.className}",description = "${classInfo.classComment}控制器")</#if>
|
||||
public class ${classInfo.className}Controller {
|
||||
|
||||
@Autowired
|
||||
private ${classInfo.className}Mapper ${classInfo.className?uncap_first}Mapper;
|
||||
|
||||
/**
|
||||
* 新增或编辑
|
||||
*/
|
||||
@PostMapping("/save")
|
||||
public Object save(@RequestBody ${classInfo.className} ${classInfo.className?uncap_first}){
|
||||
log.info("${classInfo.className?uncap_first}:"+JSON.toJSONString(${classInfo.className?uncap_first}));
|
||||
${classInfo.className} old${classInfo.className} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("${classInfo.className?uncap_first}_id",${classInfo.className?uncap_first}.get${classInfo.className}Id()));
|
||||
${classInfo.className?uncap_first}.setUpdateTime(new Date());
|
||||
if(old${classInfo.className}!=null){
|
||||
${classInfo.className?uncap_first}Mapper.updateById(${classInfo.className?uncap_first});
|
||||
}else{
|
||||
if(${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("${classInfo.className?uncap_first}_name",${classInfo.className?uncap_first}.get${classInfo.className}Name()))!=null){
|
||||
return ${returnUtilFailure}("保存失败,名字重复");
|
||||
}
|
||||
${classInfo.className?uncap_first}.setCreateTime(new Date());
|
||||
${classInfo.className?uncap_first}Mapper.insert(${classInfo.className?uncap_first});
|
||||
}
|
||||
return ${returnUtilSuccess}("保存成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public Object delete(int id){
|
||||
${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("${classInfo.className?uncap_first}_id",id));
|
||||
if(${classInfo.className?uncap_first}!=null){
|
||||
${classInfo.className?uncap_first}Mapper.deleteById(id);
|
||||
return ${returnUtilSuccess}("删除成功");
|
||||
}else{
|
||||
return ${returnUtilFailure}("没有找到该对象");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询
|
||||
*/
|
||||
@PostMapping("/find")
|
||||
public Object find(int id){
|
||||
${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("${classInfo.className?uncap_first}_id",id));
|
||||
if(${classInfo.className?uncap_first}!=null){
|
||||
return ${returnUtilSuccess}(${classInfo.className?uncap_first});
|
||||
}else{
|
||||
return ${returnUtilFailure}("没有找到该对象");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动分页查询
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
public Object list(String searchParams,
|
||||
@RequestParam(required = false, defaultValue = "0") int page,
|
||||
@RequestParam(required = false, defaultValue = "10") int limit) {
|
||||
log.info("page:"+page+"-limit:"+limit+"-json:"+ JSON.toJSONString(searchParams));
|
||||
//分页构造器
|
||||
Page<${classInfo.className}> buildPage = new Page<${classInfo.className}>(page,limit);
|
||||
//条件构造器
|
||||
QueryWrapper<${classInfo.className}> queryWrapper = new QueryWrapper<${classInfo.className}>();
|
||||
if(StringUtils.isNotEmpty(searchParams)&&JSON.isValid(searchParams)) {
|
||||
${classInfo.className} ${classInfo.className?uncap_first} = JSON.parseObject(searchParams, ${classInfo.className}.class);
|
||||
queryWrapper.eq(StringUtils.isNoneEmpty(${classInfo.className?uncap_first}.get${classInfo.className}Name()), "${classInfo.className?uncap_first}_name", ${classInfo.className?uncap_first}.get${classInfo.className}Name());
|
||||
}
|
||||
//执行分页
|
||||
IPage<${classInfo.className}> pageList = ${classInfo.className?uncap_first}Mapper.selectPage(buildPage, queryWrapper);
|
||||
//返回结果
|
||||
return ${returnUtil}.PAGE(pageList.getRecords(),pageList.getTotal());
|
||||
}
|
||||
/**
|
||||
* 手工分页查询(按需使用)
|
||||
*/
|
||||
/*@PostMapping("/list2")
|
||||
public Object list2(String searchParams,
|
||||
@RequestParam(required = false, defaultValue = "0") int page,
|
||||
@RequestParam(required = false, defaultValue = "10") int limit) {
|
||||
log.info("searchParams:"+ JSON.toJSONString(searchParams));
|
||||
//通用模式
|
||||
${classInfo.className} queryParamDTO = JSON.parseObject(searchParams, ${classInfo.className}.class);
|
||||
//专用DTO模式
|
||||
//QueryParamDTO queryParamDTO = JSON.parseObject(searchParams, QueryParamDTO.class);
|
||||
//queryParamDTO.setPage((page - 1)* limit);
|
||||
//queryParamDTO.setLimit(limit);
|
||||
//(page - 1) * limit, limit
|
||||
List<${classInfo.className}> itemList = ${classInfo.className?uncap_first}Mapper.pageAll(queryParamDTO,(page - 1)* limit,limit);
|
||||
Integer itemCount = ${classInfo.className?uncap_first}Mapper.countAll(queryParamDTO);
|
||||
//返回结果
|
||||
return ${returnUtilSuccess}.PAGE(itemList,itemCount);
|
||||
}*/
|
||||
@GetMapping("/list")
|
||||
public ModelAndView listPage(){
|
||||
return new ModelAndView("${classInfo.className?uncap_first}-list");
|
||||
}
|
||||
|
||||
@GetMapping("/edit")
|
||||
public ModelAndView editPage(int id){
|
||||
${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("${classInfo.className?uncap_first}_id",id));
|
||||
return new ModelAndView("${classInfo.className?uncap_first}-edit","${classInfo.className?uncap_first}",${classInfo.className?uncap_first});
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布/暂停(如不需要请屏蔽)
|
||||
*/
|
||||
@PostMapping("/publish")
|
||||
public Object publish(int id,Integer status){
|
||||
${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("${classInfo.className?uncap_first}_id",id));
|
||||
if(${classInfo.className?uncap_first}!=null){
|
||||
${classInfo.className?uncap_first}.setUpdateTime(new Date());
|
||||
${classInfo.className?uncap_first}.setStatus(status);
|
||||
${classInfo.className?uncap_first}Mapper.updateById(${classInfo.className?uncap_first});
|
||||
return ${returnUtilSuccess}((status==1)?"已发布":"已暂停");
|
||||
}else if(status.equals(${classInfo.className?uncap_first}.getStatus())){
|
||||
return ${returnUtilFailure}("状态不正确");
|
||||
}else{
|
||||
return ${returnUtilFailure}();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行(如不需要请屏蔽)
|
||||
*/
|
||||
@PostMapping("/execute")
|
||||
public Object execute(){
|
||||
return ${returnUtilSuccess};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.entity;</#if>
|
||||
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
<#if isLombok?exists && isLombok==true>import lombok.Data;</#if>
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.io.Serializable;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
<#if isSwagger?exists && isSwagger==true>
|
||||
import io.swagger.v3.oas.annotations.media.Schema;</#if>
|
||||
</#if>
|
||||
/**
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
<#if isLombok?exists && isLombok==true>@Data</#if><#if isSwagger?exists && isSwagger==true>
|
||||
@Schema"${classInfo.classComment}")</#if>
|
||||
public class ${classInfo.className} implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<#if isComment?exists && isComment==true>/**
|
||||
* ${fieldItem.fieldComment}
|
||||
*/</#if><#if isSwagger?exists && isSwagger==true>
|
||||
@Schema(description = "${fieldItem.fieldComment}")</#if>
|
||||
private ${fieldItem.fieldClass} ${fieldItem.fieldName};
|
||||
|
||||
<#if isLombok?exists && isLombok==false>
|
||||
public ${fieldItem.fieldClass} get${fieldItem.fieldName?cap_first}() {
|
||||
return ${fieldItem.fieldName};
|
||||
}
|
||||
|
||||
public void set${fieldItem.fieldName?cap_first}(${fieldItem.fieldClass} ${fieldItem.fieldName}) {
|
||||
this.${fieldItem.fieldName} = ${fieldItem.fieldName};
|
||||
}
|
||||
</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
public ${classInfo.className}() {}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.mapper;</#if>
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import ${packageName}.entity.${classInfo.className};
|
||||
import java.util.List;
|
||||
</#if>
|
||||
/**
|
||||
* @description ${classInfo.classComment}Mapper
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
@Mapper
|
||||
public interface ${classInfo.className}Mapper extends BaseMapper<${classInfo.className}> {
|
||||
|
||||
@Select(
|
||||
"<script>select t0.* from ${classInfo.tableName} t0 " +
|
||||
//add here if need left join
|
||||
"where 1=1" +
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
"<when test='${fieldItem.fieldName}!=null and ${fieldItem.fieldName}!='' '> and t0.${fieldItem.columnName}=井{${fieldItem.fieldName}}</when> " +
|
||||
</#list>
|
||||
//add here if need page limit
|
||||
//" limit ¥{page},¥{limit} " +
|
||||
" </script>")
|
||||
List<${classInfo.className}> pageAll(${classInfo.className} queryParamDTO,int page,int limit);
|
||||
|
||||
@Select("<script>select count(1) from ${classInfo.tableName} t0 " +
|
||||
//add here if need left join
|
||||
"where 1=1" +
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
"<when test='${fieldItem.fieldName}!=null and ${fieldItem.fieldName}!='' '> and t0.${fieldItem.columnName}=井{${fieldItem.fieldName}}</when> " +
|
||||
</#list>
|
||||
" </script>")
|
||||
int countAll(${classInfo.className} queryParamDTO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.service;</#if>
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
</#if>
|
||||
/**
|
||||
* @description ${classInfo.classComment}服务层
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
@Service
|
||||
public interface ${classInfo.className}Service extends IService<${classInfo.className}> {
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
</#if>
|
||||
|
||||
/**
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(value = "/${classInfo.className?uncap_first}")
|
||||
public class ${classInfo.className}Controller {
|
||||
|
||||
@Resource
|
||||
private ${classInfo.className}Service ${classInfo.className?uncap_first}Service;
|
||||
|
||||
/**
|
||||
* 新增
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
@RequestMapping("/insert")
|
||||
public Object insert(${classInfo.className} ${classInfo.className?uncap_first}){
|
||||
return ${classInfo.className?uncap_first}Service.insert(${classInfo.className?uncap_first});
|
||||
}
|
||||
|
||||
/**
|
||||
* 刪除
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
@RequestMapping("/delete")
|
||||
public Object delete(int id){
|
||||
return ${classInfo.className?uncap_first}Service.delete(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
@RequestMapping("/update")
|
||||
public Object update(${classInfo.className} ${classInfo.className?uncap_first}){
|
||||
return ${classInfo.className?uncap_first}Service.update(${classInfo.className?uncap_first});
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询 根据主键 id 查询
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
@RequestMapping("/load")
|
||||
public Object load(int id){
|
||||
return ${classInfo.className?uncap_first}Service.load(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询 分页查询
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
@RequestMapping("/pageList")
|
||||
public Map<String, Object> pageList(@RequestParam(required = false, defaultValue = "0") int offset,
|
||||
@RequestParam(required = false, defaultValue = "10") int pagesize) {
|
||||
return ${classInfo.className?uncap_first}Service.pageList(offset, pagesize);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import java.util.List;
|
||||
</#if>
|
||||
|
||||
/**
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface ${classInfo.className}Mapper {
|
||||
|
||||
/**
|
||||
* 新增
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
int insert(${classInfo.className} ${classInfo.className?uncap_first});
|
||||
|
||||
/**
|
||||
* 刪除
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
int delete(int id);
|
||||
|
||||
/**
|
||||
* 更新
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
int update(${classInfo.className} ${classInfo.className?uncap_first});
|
||||
|
||||
/**
|
||||
* 查询 根据主键 id 查询
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
${classInfo.className} load(int id);
|
||||
|
||||
/**
|
||||
* 查询 分页查询
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
List<${classInfo.className}> pageList(int offset,int pagesize);
|
||||
|
||||
/**
|
||||
* 查询 分页查询 count
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
int pageListCount(int offset,int pagesize);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.mapper;</#if>
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
import org.apache.ibatis.annotations.*;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import java.util.List;
|
||||
</#if>
|
||||
/**
|
||||
* @description ${classInfo.classComment}Mapper
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface ${classInfo.className}Mapper {
|
||||
|
||||
@Select("select * from ${classInfo.tableName} where ${classInfo.tableName}_id=井{id}")
|
||||
public ${classInfo.className} getById(Integer id);
|
||||
|
||||
@Options(useGeneratedKeys=true,keyProperty="${classInfo.className?uncap_first}Id")
|
||||
@Insert("insert into ${classInfo.tableName}" +
|
||||
" (<#list classInfo.fieldList as fieldItem >${fieldItem.columnName}<#if fieldItem_has_next>,</#if></#list>)" +
|
||||
" values(<#list classInfo.fieldList as fieldItem >${fieldItem.fieldName}<#if fieldItem_has_next>,<#else>)</#if></#list>")
|
||||
public Integer insert(${classInfo.className} ${classInfo.className?uncap_first});
|
||||
|
||||
@Delete(value = "delete from ${classInfo.tableName} where ${classInfo.tableName}_id=井{${classInfo.className?uncap_first}Id}")
|
||||
boolean delete(Integer id);
|
||||
|
||||
@Update(value = "update ${classInfo.tableName} set "
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<#if fieldItem.columnName != "id">+" ${fieldItem.columnName}=井{${fieldItem.fieldName}}<#if fieldItem_has_next>,</#if>"</#if>
|
||||
</#list>
|
||||
+" where ${classInfo.tableName}_id=井{${classInfo.className?uncap_first}Id} ")
|
||||
boolean update(${classInfo.className} ${classInfo.className?uncap_first});
|
||||
|
||||
|
||||
@Results(value = {
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
@Result(property = "${fieldItem.fieldName}", column = "${fieldItem.columnName}")<#if fieldItem_has_next>,</#if>
|
||||
</#list>
|
||||
})
|
||||
@Select(value = "select * from ${classInfo.tableName} where ${classInfo.tableName}_id=井{queryParam}")
|
||||
${classInfo.className} selectOne(String queryParam);
|
||||
|
||||
@Results(value = {
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
@Result(property = "${fieldItem.fieldName}", column = "${fieldItem.columnName}")<#if fieldItem_has_next>,</#if>
|
||||
</#list>
|
||||
})
|
||||
@Select(value = "select * from ${classInfo.tableName} where "
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
+" ${fieldItem.columnName}=井{${fieldItem.fieldName}}<#if fieldItem_has_next> or </#if>"
|
||||
</#list>
|
||||
)
|
||||
List<${classInfo.className}> selectList(${classInfo.className} ${classInfo.className?uncap_first});
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
</#if>
|
||||
/**
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
public class ${classInfo.className} implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<#if isComment?exists && isComment==true>/**
|
||||
* ${fieldItem.fieldComment}
|
||||
*/</#if>
|
||||
private ${fieldItem.fieldClass} ${fieldItem.fieldName};
|
||||
|
||||
</#list>
|
||||
</#if>
|
||||
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
public ${classInfo.className}() {
|
||||
}
|
||||
|
||||
<#list classInfo.fieldList as fieldItem>
|
||||
public ${fieldItem.fieldClass} get${fieldItem.fieldName?cap_first}() {
|
||||
return ${fieldItem.fieldName};
|
||||
}
|
||||
|
||||
public void set${fieldItem.fieldName?cap_first}(${fieldItem.fieldClass} ${fieldItem.fieldName}) {
|
||||
this.${fieldItem.fieldName} = ${fieldItem.fieldName};
|
||||
}
|
||||
|
||||
</#list>
|
||||
</#if>
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?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="${packageName}.dao.${classInfo.className}Mapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="${packageName}.entity.${classInfo.className}" >
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<result column="${fieldItem.columnName}" property="${fieldItem.fieldName}" />
|
||||
</#list>
|
||||
</#if>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
${fieldItem.columnName}<#if fieldItem_has_next>,</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
</sql>
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyColumn="id" keyProperty="id" parameterType="${packageName}.entity.${classInfo.className}">
|
||||
INSERT INTO ${classInfo.originTableName}
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<#if fieldItem.columnName != "id" >
|
||||
<if test="null != ${fieldItem.fieldName} <#if fieldItem.fieldClass ="String">and '' != ${fieldItem.fieldName}</#if>">
|
||||
${fieldItem.columnName}<#if fieldItem_has_next>,</#if>
|
||||
${r"</if>"}
|
||||
</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<#if fieldItem.columnName != "id" >
|
||||
<#--<#if fieldItem.columnName="addtime" || fieldItem.columnName="updatetime" >
|
||||
${r"<if test ='null != "}${fieldItem.fieldName}${r"'>"}
|
||||
NOW()<#if fieldItem_has_next>,</#if>
|
||||
${r"</if>"}
|
||||
<#else>-->
|
||||
<if test="null != ${fieldItem.fieldName} <#if fieldItem.fieldClass ="String">and '' != ${fieldItem.fieldName}</#if>">
|
||||
${r"#{"}${fieldItem.fieldName}${r"}"}<#if fieldItem_has_next>,</#if>
|
||||
${r"</if>"}
|
||||
<#--</#if>-->
|
||||
</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<delete id="delete" >
|
||||
DELETE FROM ${classInfo.originTableName}
|
||||
WHERE id = ${r"#{id}"}
|
||||
</delete>
|
||||
|
||||
<update id="update" parameterType="${packageName}.entity.${classInfo.className}">
|
||||
UPDATE ${classInfo.originTableName}
|
||||
<set>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<#if fieldItem.columnName != "id" && fieldItem.columnName != "AddTime" && fieldItem.columnName != "UpdateTime" >
|
||||
<if test="null != ${fieldItem.fieldName} <#if fieldItem.fieldClass ="String">and '' != ${fieldItem.fieldName}</#if>">${fieldItem.columnName} = ${r"#{"}${fieldItem.fieldName}${r"}"}<#if fieldItem_has_next>,</#if>${r"</if>"}
|
||||
</#if>
|
||||
</#list>
|
||||
</set>
|
||||
WHERE id = ${r"#{"}id${r"}"}
|
||||
</update>
|
||||
|
||||
|
||||
<select id="load" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List" />
|
||||
FROM ${classInfo.originTableName}
|
||||
WHERE id = ${r"#{id}"}
|
||||
</select>
|
||||
|
||||
<select id="pageList" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List" />
|
||||
FROM ${classInfo.originTableName}
|
||||
LIMIT ${r"#{offset}"}, ${r"#{pageSize}"}
|
||||
</select>
|
||||
|
||||
<select id="pageListCount" resultType="java.lang.Integer">
|
||||
SELECT count(1)
|
||||
FROM ${classInfo.originTableName}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,36 @@
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
import java.util.Map;
|
||||
</#if>
|
||||
/**
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
public interface ${classInfo.className}Service {
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public Object insert(${classInfo.className} ${classInfo.className?uncap_first});
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public Object delete(int id);
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*/
|
||||
public Object update(${classInfo.className} ${classInfo.className?uncap_first});
|
||||
|
||||
/**
|
||||
* 根据主键 id 查询
|
||||
*/
|
||||
public ${classInfo.className} load(int id);
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
public Map<String,Object> pageList(int offset, int pagesize);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
</#if>
|
||||
/**
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
@Service
|
||||
public class ${classInfo.className}ServiceImpl implements ${classInfo.className}Service {
|
||||
|
||||
@Resource
|
||||
private ${classInfo.className}Mapper ${classInfo.className?uncap_first}Mapper;
|
||||
|
||||
|
||||
@Override
|
||||
public Object insert(${classInfo.className} ${classInfo.className?uncap_first}) {
|
||||
|
||||
// valid
|
||||
if (${classInfo.className?uncap_first} == null) {
|
||||
return ${returnUtilFailure}("必要参数缺失");
|
||||
}
|
||||
|
||||
${classInfo.className?uncap_first}Mapper.insert(${classInfo.className?uncap_first});
|
||||
return ${returnUtilSuccess}();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object delete(int id) {
|
||||
int ret = ${classInfo.className?uncap_first}Mapper.delete(id);
|
||||
return ret>0?${returnUtilSuccess}():${returnUtilFailure}();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object update(${classInfo.className} ${classInfo.className?uncap_first}) {
|
||||
int ret = ${classInfo.className?uncap_first}Mapper.update(${classInfo.className?uncap_first});
|
||||
return ret>0?${returnUtilSuccess}():${returnUtilFailure}();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ${classInfo.className} load(int id) {
|
||||
return ${classInfo.className?uncap_first}Mapper.load(id);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String,Object> pageList(int offset, int pagesize) {
|
||||
|
||||
List<${classInfo.className}> pageList = ${classInfo.className?uncap_first}Mapper.pageList(offset, pagesize);
|
||||
int totalCount = ${classInfo.className?uncap_first}Mapper.pageListCount(offset, pagesize);
|
||||
|
||||
// result
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
result.put("pageList", pageList);
|
||||
result.put("totalCount", totalCount);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
-- 菜单SQL
|
||||
INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
|
||||
VALUES ('1', '${classInfo.classComment}', 'generator/${classInfo.className?uncap_first}', NULL, '1', 'config', '6');
|
||||
|
||||
-- 按钮父菜单ID
|
||||
set @parentId = @@identity;
|
||||
|
||||
-- 菜单对应按钮SQL
|
||||
INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
|
||||
SELECT @parentId, '查看', null, 'generator:${classInfo.className?uncap_first}:list,generator:${classInfo.className?uncap_first}:info', '2', null, '6';
|
||||
INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
|
||||
SELECT @parentId, '新增', null, 'generator:${classInfo.className?uncap_first}:save', '2', null, '6';
|
||||
INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
|
||||
SELECT @parentId, '修改', null, 'generator:${classInfo.className?uncap_first}:update', '2', null, '6';
|
||||
INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
|
||||
SELECT @parentId, '删除', null, 'generator:${classInfo.className?uncap_first}:delete', '2', null, '6';
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.controller;</#if>
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import ${packageName}.entity.${classInfo.className}Entity;
|
||||
import ${packageName}.service.${classInfo.className}Service;
|
||||
import ${packageName}.common.utils.PageUtils;
|
||||
import ${packageName}.common.utils.R;
|
||||
</#if>
|
||||
|
||||
|
||||
/**
|
||||
* @description ${classInfo.classComment}控制器
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("generator/${classInfo.className?uncap_first}")
|
||||
public class ${classInfo.className}Controller {
|
||||
|
||||
@Autowired
|
||||
private ${classInfo.className}Service ${classInfo.className?uncap_first}Service;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@RequestMapping("/list")
|
||||
@RequiresPermissions("generator:${classInfo.className?uncap_first}:list")
|
||||
public R list(@RequestParam Map<String, Object> params){
|
||||
PageUtils page = ${classInfo.className?uncap_first}Service.queryPage(params);
|
||||
|
||||
return R.ok().put("page", page);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*/
|
||||
@RequestMapping("/info/{${classInfo.className?uncap_first}Id}")
|
||||
@RequiresPermissions("generator:${classInfo.className?uncap_first}:info")
|
||||
public R info(@PathVariable("${classInfo.className?uncap_first}Id") int ${classInfo.className?uncap_first}Id){
|
||||
${classInfo.className}Entity ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Service.getById(${classInfo.className?uncap_first}Id);
|
||||
|
||||
return R.ok().put("${classInfo.className?uncap_first}", ${classInfo.className?uncap_first});
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
@RequestMapping("/save")
|
||||
@RequiresPermissions("generator:${classInfo.className?uncap_first}:save")
|
||||
public R save(@RequestBody ${classInfo.className}Entity ${classInfo.className?uncap_first}){
|
||||
${classInfo.className?uncap_first}Service.save(${classInfo.className?uncap_first});
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
@RequiresPermissions("generator:${classInfo.className?uncap_first}:update")
|
||||
public R update(@RequestBody ${classInfo.className}Entity ${classInfo.className?uncap_first}){
|
||||
${classInfo.className?uncap_first}Service.updateById(${classInfo.className?uncap_first});
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@RequestMapping("/delete")
|
||||
@RequiresPermissions("generator:${classInfo.className?uncap_first}:delete")
|
||||
public R delete(@RequestBody int[] ${classInfo.className?uncap_first}Ids){
|
||||
${classInfo.className?uncap_first}Service.removeByIds(Arrays.asList(${classInfo.className?uncap_first}Ids));
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.mapper;</#if>
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
import ${packageName}.entity.${classInfo.className}Entity;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
</#if>
|
||||
/**
|
||||
* @description ${classInfo.classComment}Mapper
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
@Mapper
|
||||
public interface ${classInfo.className}Dao extends BaseMapper<${classInfo.className}Entity> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?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="${packageName}.dao.${classInfo.className}Dao">
|
||||
|
||||
<!-- 可根据自己的需求,是否要使用 -->
|
||||
<resultMap type="${packageName}.entity.${classInfo.className}Entity" id="${classInfo.className}Map">
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<result property="${fieldItem.fieldName}" column="${fieldItem.fieldName}"/>
|
||||
</#list>
|
||||
</#if>
|
||||
</resultMap>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,28 @@
|
||||
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.service;</#if>
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.Map;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import ${packageName}.common.utils.PageUtils;
|
||||
import ${packageName}.common.utils.Query;
|
||||
|
||||
import ${packageName}.dao.${classInfo.className}Dao;
|
||||
import ${packageName}.entity.${classInfo.className}Entity;
|
||||
</#if>
|
||||
|
||||
@Service("${classInfo.className?uncap_first}Service")
|
||||
public class ${classInfo.className}Service extends ServiceImpl<${classInfo.className}Dao, ${classInfo.className}Entity> {
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
IPage<${classInfo.className}Entity> page = this.page(
|
||||
new Query<${classInfo.className}Entity>().getPage(params),
|
||||
new QueryWrapper<${classInfo.className}Entity>()
|
||||
);
|
||||
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
:title="!dataForm.${classInfo.className?uncap_first}Id ? '新增' : '修改'"
|
||||
:close-on-click-modal="false"
|
||||
:visible.sync="visible">
|
||||
<el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<el-form-item label="${fieldItem.fieldComment}" prop="${fieldItem.fieldName}">
|
||||
<el-input v-model="dataForm.${fieldItem.fieldName}" placeholder="${fieldItem.fieldComment}"></el-input>
|
||||
</el-form-item>
|
||||
</#list>
|
||||
</#if>
|
||||
</el-form>
|
||||
<span slot="footer" class="dialog-footer">
|
||||
<el-button @click="visible = false">取消</el-button>
|
||||
<el-button type="primary" @click="dataFormSubmit()">确定</el-button>
|
||||
</span>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
visible: false,
|
||||
dataForm: {
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
${fieldItem.fieldName}: ''<#if fieldItem_has_next>,</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
},
|
||||
dataRule: {
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
${fieldItem.fieldName}: [{ required: true, message: '${fieldItem.fieldComment}不能为空', trigger: 'blur' }]<#if fieldItem_has_next>,</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
init (id) {
|
||||
this.dataForm.${classInfo.className?uncap_first}Id = id || 0
|
||||
this.visible = true
|
||||
this.¥nextTick(() => {
|
||||
this.¥refs['dataForm'].resetFields()
|
||||
// <!-- 请把 ${classInfo.className?uncap_first}Id 替换成正确的ID -->
|
||||
if (this.dataForm.${classInfo.className?uncap_first}Id) {
|
||||
this.¥http({
|
||||
url: this.¥http.adornUrl(`/generator/${classInfo.className?uncap_first}/info/¥{this.dataForm.${classInfo.className?uncap_first}Id}`),
|
||||
method: 'get',
|
||||
params: this.¥http.adornParams()
|
||||
}).then(({data}) => {
|
||||
if (data && data.code === 0) {
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
this.dataForm.${fieldItem.fieldName} = data.${classInfo.className?uncap_first}.${fieldItem.fieldName}
|
||||
</#list>
|
||||
</#if>
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
// 表单提交
|
||||
dataFormSubmit () {
|
||||
this.¥refs['dataForm'].validate((valid) => {
|
||||
if (valid) {
|
||||
this.¥http({
|
||||
url: this.¥http.adornUrl(`/generator/${classInfo.className?uncap_first}/¥{this.dataForm.${classInfo.className?uncap_first}Id? 'save' : 'update'}`),
|
||||
method: 'post',
|
||||
data: this.¥http.adornData({
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
'${fieldItem.fieldName}': '${fieldItem.fieldName}' || undefined<#if fieldItem_has_next>,</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
})
|
||||
}).then(({data}) => {
|
||||
if (data && data.code === 0) {
|
||||
this.¥message({
|
||||
message: '操作成功',
|
||||
type: 'success',
|
||||
duration: 1500,
|
||||
onClose: () => {
|
||||
this.visible = false
|
||||
this.¥emit('refreshDataList')
|
||||
}
|
||||
})
|
||||
} else {
|
||||
this.¥message.error(data.msg)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,162 @@
|
||||
<template>
|
||||
<div class="mod-config">
|
||||
<el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
|
||||
<el-form-item>
|
||||
<el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button @click="getDataList()">查询</el-button>
|
||||
<el-button v-if="isAuth('generator:${classInfo.className?uncap_first}:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
|
||||
<el-button v-if="isAuth('generator:${classInfo.className?uncap_first}:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<el-table
|
||||
:data="dataList"
|
||||
border
|
||||
v-loading="dataListLoading"
|
||||
@selection-change="selectionChangeHandle"
|
||||
style="width: 100%;">
|
||||
<el-table-column
|
||||
type="selection"
|
||||
header-align="center"
|
||||
align="center"
|
||||
width="50">
|
||||
</el-table-column>
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<el-table-column
|
||||
prop="${fieldItem.fieldName}"
|
||||
header-align="center"
|
||||
align="center"
|
||||
label="${fieldItem.fieldComment}">
|
||||
</el-table-column>
|
||||
</#list>
|
||||
</#if>
|
||||
<el-table-column
|
||||
fixed="right"
|
||||
header-align="center"
|
||||
align="center"
|
||||
width="150"
|
||||
label="操作">
|
||||
<template slot-scope="scope">
|
||||
<!-- 请把 ${classInfo.className?uncap_first}Id 替换成正确的ID -->
|
||||
<el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.${classInfo.className?uncap_first}Id)">修改</el-button>
|
||||
<el-button type="text" size="small" @click="deleteHandle(scope.row.${classInfo.className?uncap_first}Id)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-pagination
|
||||
@size-change="sizeChangeHandle"
|
||||
@current-change="currentChangeHandle"
|
||||
:current-page="pageIndex"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
:page-size="pageSize"
|
||||
:total="totalPage"
|
||||
layout="total, sizes, prev, pager, next, jumper">
|
||||
</el-pagination>
|
||||
<!-- 弹窗, 新增 / 修改 -->
|
||||
<add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import AddOrUpdate from './${classInfo.className?uncap_first}-add-or-update'
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
dataForm: {
|
||||
key: ''
|
||||
},
|
||||
dataList: [],
|
||||
pageIndex: 1,
|
||||
pageSize: 10,
|
||||
totalPage: 0,
|
||||
dataListLoading: false,
|
||||
dataListSelections: [],
|
||||
addOrUpdateVisible: false
|
||||
}
|
||||
},
|
||||
components: {
|
||||
AddOrUpdate
|
||||
},
|
||||
activated () {
|
||||
this.getDataList()
|
||||
},
|
||||
methods: {
|
||||
// 获取数据列表
|
||||
getDataList () {
|
||||
this.dataListLoading = true
|
||||
this.¥http({
|
||||
url: this.¥http.adornUrl('/generator/${classInfo.className?uncap_first}/list'),
|
||||
method: 'get',
|
||||
params: this.¥http.adornParams({
|
||||
'page': this.pageIndex,
|
||||
'limit': this.pageSize,
|
||||
'key': this.dataForm.key
|
||||
})
|
||||
}).then(({data}) => {
|
||||
if (data && data.code === 0) {
|
||||
this.dataList = data.page.list
|
||||
this.totalPage = data.page.totalCount
|
||||
} else {
|
||||
this.dataList = []
|
||||
this.totalPage = 0
|
||||
}
|
||||
this.dataListLoading = false
|
||||
})
|
||||
},
|
||||
// 每页数
|
||||
sizeChangeHandle (val) {
|
||||
this.pageSize = val
|
||||
this.pageIndex = 1
|
||||
this.getDataList()
|
||||
},
|
||||
// 当前页
|
||||
currentChangeHandle (val) {
|
||||
this.pageIndex = val
|
||||
this.getDataList()
|
||||
},
|
||||
// 多选
|
||||
selectionChangeHandle (val) {
|
||||
this.dataListSelections = val
|
||||
},
|
||||
// 新增 / 修改
|
||||
addOrUpdateHandle (id) {
|
||||
this.addOrUpdateVisible = true
|
||||
this.¥nextTick(() => {
|
||||
this.¥refs.addOrUpdate.init(id)
|
||||
})
|
||||
},
|
||||
// 删除
|
||||
deleteHandle (id) {
|
||||
var ids = id ? [id] : this.dataListSelections.map(item => {
|
||||
return item.${classInfo.className?uncap_first}Id
|
||||
})
|
||||
this.¥confirm(`确定对[id=¥{ids.join(',')}]进行[¥{id ? '删除' : '批量删除'}]操作?`, '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
this.¥http({
|
||||
url: this.¥http.adornUrl('/generator/${classInfo.className?uncap_first}/delete'),
|
||||
method: 'post',
|
||||
data: this.¥http.adornData(ids, false)
|
||||
}).then(({data}) => {
|
||||
if (data && data.code === 0) {
|
||||
this.¥message({
|
||||
message: '操作成功',
|
||||
type: 'success',
|
||||
duration: 1500,
|
||||
onClose: () => {
|
||||
this.getDataList()
|
||||
}
|
||||
})
|
||||
} else {
|
||||
this.¥message.error(data.msg)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,79 @@
|
||||
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.controller;</#if>
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
import ${packageName}.entity.${classInfo.className};
|
||||
import ${packageName}.mapper.${classInfo.className}Mapper;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
</#if>
|
||||
/**
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/${classInfo.className?uncap_first}")
|
||||
public class ${classInfo.className}Controller {
|
||||
|
||||
@Autowired
|
||||
private ${classInfo.className}Mapper ${classInfo.className?uncap_first}Mapper;
|
||||
|
||||
/**
|
||||
* 新增或编辑
|
||||
*/
|
||||
@PostMapping("/save")
|
||||
public Object save(${classInfo.className} ${classInfo.className?uncap_first}){
|
||||
if(${classInfo.className?uncap_first}Mapper.selectCount(${classInfo.className?uncap_first})>0){
|
||||
${classInfo.className?uncap_first}Mapper.insert(${classInfo.className?uncap_first});
|
||||
}else{
|
||||
${classInfo.className?uncap_first}Mapper.updateByPrimaryKeySelective(${classInfo.className?uncap_first});
|
||||
}
|
||||
return ${returnUtilSuccess}("新增或编辑成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public Object delete(int id){
|
||||
if(${classInfo.className?uncap_first}Mapper.selectCount(${classInfo.className?uncap_first})>0){
|
||||
${classInfo.className?uncap_first}Mapper.deleteByPrimaryKey(id);
|
||||
return ${returnUtilSuccess}("删除成功");
|
||||
}else{
|
||||
return ${returnUtilFailure}("没有找到该对象");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询
|
||||
*/
|
||||
@PostMapping("/find")
|
||||
public Object find(int id){
|
||||
Optional<${classInfo.className}> ${classInfo.className?uncap_first}=${classInfo.className?uncap_first}Mapper.selectOne(id);
|
||||
if(${classInfo.className?uncap_first}.isPresent()){
|
||||
return ${returnUtilSuccess}(${classInfo.className?uncap_first}.get());
|
||||
}else{
|
||||
return ${returnUtilFailure}("没有找到该对象");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
public Object list(${classInfo.className} ${classInfo.className?uncap_first},
|
||||
@RequestParam(required = false, defaultValue = "0") int pageNumber,
|
||||
@RequestParam(required = false, defaultValue = "10") int pageSize) {
|
||||
//TBC
|
||||
return ${classInfo.className?uncap_first}Mapper.selectList(${classInfo.className?uncap_first});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.entity;</#if>
|
||||
|
||||
<#if isAutoImport?exists && isAutoImport==true>
|
||||
<#if isLombok?exists && isLombok==true>import lombok.Data;</#if>
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.io.Serializable;
|
||||
import io.mybatis.provider.Entity;
|
||||
<#if isSwagger?exists && isSwagger==true>
|
||||
import io.swagger.v3.oas.annotations.media.Schema;</#if>
|
||||
</#if>
|
||||
/**
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
<#if isLombok?exists && isLombok==true>@Data</#if>
|
||||
<#if isComment?exists && isComment==true>@Entity.Table("${classInfo.originTableName}")</#if><#if isSwagger?exists && isSwagger==true>
|
||||
@Schema"${classInfo.classComment}")</#if>
|
||||
public class ${classInfo.className} implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
//@Entity.Column(id = true)
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<#if isComment?exists && isComment==true>/**
|
||||
* ${fieldItem.fieldComment}
|
||||
*/</#if><#if isSwagger?exists && isSwagger==true>
|
||||
@Schema(description = "${fieldItem.fieldComment}")</#if>
|
||||
<#if isComment?exists && isComment==true>@Entity.Column("${fieldItem.columnName}")</#if>
|
||||
private ${fieldItem.fieldClass} ${fieldItem.fieldName};
|
||||
|
||||
</#list>
|
||||
public ${classInfo.className}() {
|
||||
}
|
||||
</#if>
|
||||
|
||||
<#if isLombok?exists && isLombok==false>
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
public ${fieldItem.fieldClass} get${fieldItem.fieldName?cap_first}() {
|
||||
return ${fieldItem.fieldName};
|
||||
}
|
||||
|
||||
public void set${fieldItem.fieldName?cap_first}(${fieldItem.fieldClass} ${fieldItem.fieldName}) {
|
||||
this.${fieldItem.fieldName} = ${fieldItem.fieldName};
|
||||
}
|
||||
</#list>
|
||||
</#if>
|
||||
</#if>
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.mapper;</#if>
|
||||
<#if isAutoImport?exists && isAutoImport==true>import ${packageName}.entity.${classInfo.className};
|
||||
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<#if fieldItem.fieldClass == "Date">
|
||||
<#assign importDdate = true />
|
||||
</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
<#if importDdate?exists && importDdate==true>import java.util.Date;</#if>
|
||||
import java.util.List;
|
||||
import io.mybatis.mapper.Mapper;
|
||||
</#if>
|
||||
/**
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
@org.apache.ibatis.annotations.Mapper
|
||||
public interface ${classInfo.className}Mapper extends Mapper<${classInfo.className},Integer> {
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<form action="/${classInfo.className?uncap_first}/save">
|
||||
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<div class="form-group">
|
||||
<label for="${fieldItem.fieldName}Label">${fieldItem.fieldComment}</label>
|
||||
<input type="input" class="form-control" id="${fieldItem.fieldName}" name="${fieldItem.fieldName}" placeholder="请输入${fieldItem.fieldComment}">
|
||||
</div>
|
||||
</#list>
|
||||
</#if>
|
||||
|
||||
<button type="submit" class="btn btn-primary">保存</button>
|
||||
</form>
|
||||
@@ -0,0 +1,16 @@
|
||||
<el-form :inline="true" :model="submitData" class="demo-form-inline" :rules="rules" ref="ruleForm">
|
||||
<el-card class="box-card">
|
||||
<div slot="header" class="header clearfix">
|
||||
<span>${classInfo.classComment!'数据管理'}</span>
|
||||
<el-button v-if="!ischeck && !isFind" class="fr" type="primary" @click="validate('ruleForm')">提交</el-button>
|
||||
<el-button v-else class="fr" type="primary" @click="goBack">返回</el-button>
|
||||
</div>
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<el-form-item label="${fieldItem.fieldComment}" prop="${fieldItem.fieldName}">
|
||||
<el-input placeholder="请输入${fieldItem.fieldComment}" v-model="formData.${fieldItem.fieldName}"></el-input>
|
||||
</el-form-item>
|
||||
</#list>
|
||||
</#if>
|
||||
</el-card>
|
||||
</el-form>
|
||||
@@ -0,0 +1,64 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<div class="layui-form layuimini-form">
|
||||
<input type="hidden" name="${classInfo.className?uncap_first}Id" value="" class="layui-input">
|
||||
|
||||
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required">${fieldItem.fieldComment}</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="${fieldItem.fieldName}" lay-verify="required" lay-reqtext="${fieldItem.fieldComment}不能为空" placeholder="请输入${fieldItem.fieldComment}" value="¥{(${classInfo.className?uncap_first}.${fieldItem.fieldName})!!}" class="layui-input">
|
||||
<#--<tip>${fieldItem.fieldComment}</tip>-->
|
||||
</div>
|
||||
</div>
|
||||
</#list>
|
||||
</#if>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block">
|
||||
<button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="¥{request.contextPath}/static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
|
||||
<script>
|
||||
layui.use(['form'], function () {
|
||||
var form = layui.form,
|
||||
layer = layui.layer,
|
||||
$ = layui.$;
|
||||
|
||||
//监听提交
|
||||
form.on('submit(saveBtn)', function (data) {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: "¥{request.contextPath}/${classInfo.className?uncap_first}/save",
|
||||
data:JSON.stringify(data.field),
|
||||
dataType: "json",
|
||||
contentType: "application/json",
|
||||
success: function (responseData) {
|
||||
if (responseData.code === 200) {
|
||||
layer.msg(responseData.msg, function () {
|
||||
// 关闭弹出层
|
||||
//layer.close(index);
|
||||
var iframeIndex = parent.layer.getFrameIndex(window.name);
|
||||
parent.layer.close(iframeIndex);
|
||||
parent.searchBtn.click();
|
||||
});
|
||||
} else {
|
||||
layer.msg(responseData.msg, function () {
|
||||
//window.location = '/index.html';
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,221 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<div class="layuimini-container">
|
||||
<div class="layuimini-main">
|
||||
|
||||
<fieldset class="table-search-fieldset">
|
||||
<legend>搜索信息</legend>
|
||||
<div style="margin: 10px 10px 10px 10px">
|
||||
<form class="layui-form layui-form-pane" action="">
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-inline">
|
||||
<label class="layui-form-label">${classInfo.classComment!'数据'}Id</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="${classInfo.className?uncap_first}Id" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-inline">
|
||||
<label class="layui-form-label">${classInfo.classComment!'数据'}名称</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="${classInfo.className?uncap_first}Name" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-inline">
|
||||
<button id="searchBtn" type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<script type="text/html" id="toolbarDemo">
|
||||
<div class="layui-btn-container">
|
||||
<button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> <i class="layui-icon layui-icon-addition"></i>${classInfo.classComment!'数据'} </button>
|
||||
<#-- <button class="layui-btn layui-btn-normal layui-btn-sm layui-btn-danger data-delete-btn" lay-event="del"> 删除${classInfo.classComment!'数据'} </button>-->
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
|
||||
|
||||
<script type="text/html" id="currentTableBar">
|
||||
<a class="layui-btn layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
|
||||
<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="typeTemplate">
|
||||
{{# if(d.type == '1'){ }}
|
||||
常规
|
||||
{{# } else if(d.type =='2') { }}
|
||||
专项
|
||||
{{# } else { }}
|
||||
其它
|
||||
{{# } }}
|
||||
</script>
|
||||
<script type="text/html" id="statusTemplate">
|
||||
{{# if(d.status == '1' ){ }}
|
||||
<i class="layui-icon layui-icon-ok"></i>已发布
|
||||
{{# } else { }}
|
||||
- 未发布
|
||||
{{# } }}
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
<script src="¥{request.contextPath}/static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
|
||||
<script>
|
||||
layui.use(['form', 'table'], function () {
|
||||
var $ = layui.jquery,
|
||||
form = layui.form,
|
||||
table = layui.table;
|
||||
|
||||
table.render({
|
||||
elem: '#currentTableId',
|
||||
method: 'post',
|
||||
url: '¥{request.contextPath}/${classInfo.className?uncap_first}/list',
|
||||
toolbar: '#toolbarDemo',
|
||||
defaultToolbar: ['filter', 'exports', 'print', {
|
||||
title: '提示',
|
||||
layEvent: 'LAYTABLE_TIPS',
|
||||
icon: 'layui-icon-tips'
|
||||
}],
|
||||
cols: [[
|
||||
{type: "checkbox", width: 50, fixed: "left"},
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
{field: '${fieldItem.fieldName}', title: '${fieldItem.fieldComment}', sort: true}, <#if fieldItem_has_next> </#if>
|
||||
</#list>
|
||||
</#if>
|
||||
/* 需要时间请自行解封
|
||||
{title: '创建时间', sort: true,templet: "<div>{{layui.util.toDateString(d.createTime, 'yyyy-MM-dd')}}</div>"},
|
||||
{title: '修改时间', sort: true,templet: "<div>{{layui.util.toDateString(d.updateTime, 'yyyy-MM-dd')}}</div>"},
|
||||
*/
|
||||
{title: '操作', minWidth: 400, templet: '#currentTableBar', fixed: "right", align: "center"}
|
||||
]],
|
||||
limits: [20 , 50 , 100],
|
||||
limit: 20,
|
||||
page: true
|
||||
});
|
||||
|
||||
var result;
|
||||
/**
|
||||
* submit(data-search-btn):监听搜索操作
|
||||
*/
|
||||
form.on('submit(data-search-btn)', function (data) {
|
||||
result = JSON.stringify(data.field);
|
||||
|
||||
//执行搜索重载
|
||||
table.reload('currentTableId', {
|
||||
page: {
|
||||
curr: 1
|
||||
}
|
||||
, where: {
|
||||
searchParams: result
|
||||
}
|
||||
}, 'data');
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
var searchBtn = $("#searchBtn");
|
||||
/**
|
||||
* toolbar监听事件:表格添加按钮
|
||||
*/
|
||||
table.on('toolbar(currentTableFilter)', function (obj) {
|
||||
if (obj.event === 'add') {
|
||||
var index = layer.open({
|
||||
title: '添加',
|
||||
type: 2,
|
||||
shade: 0.2,
|
||||
maxmin:true,
|
||||
shadeClose: true,
|
||||
area: ['1000px', '700px'],
|
||||
content: '¥{request.contextPath}/${classInfo.className?uncap_first}/edit?id=0',
|
||||
});
|
||||
return false;
|
||||
}else if(obj.event === 'del') {
|
||||
var checkStatus = table.checkStatus('currentTableId')
|
||||
, data = checkStatus.data;
|
||||
layer.alert(JSON.stringify(data));
|
||||
}
|
||||
});
|
||||
/**
|
||||
* checkbox(currentTableFilter):表格复选框选择
|
||||
*/
|
||||
table.on('checkbox(currentTableFilter)', function (obj) {
|
||||
//console.log(obj)
|
||||
});
|
||||
|
||||
/**
|
||||
* tool监听事件:表格编辑删除等功能按钮
|
||||
*/
|
||||
table.on('tool(currentTableFilter)', function (obj) {
|
||||
var data = obj.data;
|
||||
if (obj.event === 'edit') {
|
||||
var index = layer.open({
|
||||
title: '编辑',
|
||||
type: 2,
|
||||
shade: 0.2,
|
||||
maxmin:true,
|
||||
shadeClose: true,
|
||||
area: ['1000px', '700px'],
|
||||
content: '¥{request.contextPath}/${classInfo.className?uncap_first}/edit?id='+obj.data.${classInfo.className?uncap_first}Id,
|
||||
});
|
||||
return false;
|
||||
} else if (obj.event === 'delete') {
|
||||
layer.confirm('确认删除该记录吗?', function (index) {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: "¥{request.contextPath}/${classInfo.className?uncap_first}/delete",
|
||||
data:{"id":obj.data.${classInfo.className?uncap_first}Id},
|
||||
success: function (responseData) {
|
||||
if (responseData.code === 200) {
|
||||
layer.msg(responseData.msg, function () {
|
||||
obj.del();
|
||||
});
|
||||
} else {
|
||||
layer.msg(responseData.msg, function () {
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
layer.close(index);
|
||||
});
|
||||
}else if (obj.event === 'publish') {
|
||||
layer.confirm('确定要发布吗?', function (index) {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: "¥{request.contextPath}/${classInfo.className?uncap_first}/publish",
|
||||
data:{"id":obj.data.${classInfo.className?uncap_first}Id,"status":"1"},
|
||||
success: function (responseData) {
|
||||
searchBtn.click();
|
||||
layer.msg(responseData.msg, function () {
|
||||
});
|
||||
}
|
||||
});
|
||||
layer.close(index);
|
||||
});
|
||||
}else if (obj.event === 'unpublish') {
|
||||
layer.confirm('确定要停止吗?', function (index) {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: "¥{request.contextPath}/${classInfo.className?uncap_first}/publish",
|
||||
data:{"id":obj.data.${classInfo.className?uncap_first}Id,"status":"0"},
|
||||
success: function (responseData) {
|
||||
searchBtn.click();
|
||||
layer.msg(responseData.msg, function () {
|
||||
});
|
||||
}
|
||||
});
|
||||
layer.close(index);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,9 @@
|
||||
@ApiOperation(value = "${classInfo.classComment!'API接口'}", notes = "${classInfo.classComment!'API接口说明'}")
|
||||
@ApiImplicitParams({
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
@ApiImplicitParam(name = "${fieldItem.fieldName}", value = "${fieldItem.fieldComment!''}", required = false, dataType = "${fieldItem.fieldClass}")<#if fieldItem_has_next>,</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
}
|
||||
)
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* ${classInfo.classComment!'数据'}对象Get Set
|
||||
* @author ${authorName} ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem>
|
||||
// ${fieldItem.fieldComment}
|
||||
${fieldItem.fieldClass} ${fieldItem.fieldName} = ${classInfo.className?uncap_first}.get${fieldItem.fieldName?cap_first}();
|
||||
</#list>
|
||||
|
||||
<#list classInfo.fieldList as fieldItem>
|
||||
// ${fieldItem.fieldComment}
|
||||
${classInfo.className?uncap_first}.set${fieldItem.fieldName?cap_first}();
|
||||
</#list>
|
||||
|
||||
<#list classInfo.fieldList as fieldItem>
|
||||
// ${fieldItem.fieldComment}
|
||||
${classInfo.className?uncap_first}.set${fieldItem.fieldName?cap_first}(${classInfo.className?uncap_first}2.get${fieldItem.fieldName?cap_first}());
|
||||
</#list>
|
||||
|
||||
<#list classInfo.fieldList as fieldItem>
|
||||
// ${fieldItem.fieldComment}
|
||||
map.put("${fieldItem.fieldName?uncap_first}",${classInfo.className?uncap_first}.get${fieldItem.fieldName?cap_first}());
|
||||
</#list>
|
||||
|
||||
<#list classInfo.fieldList as fieldItem>
|
||||
// ${fieldItem.fieldComment}
|
||||
map.put("${fieldItem.columnName}",${classInfo.className?uncap_first}.get${fieldItem.fieldName?cap_first}());
|
||||
</#list>
|
||||
|
||||
<#list classInfo.fieldList as fieldItem>
|
||||
map.put("${fieldItem.fieldComment}",${classInfo.className?uncap_first}.get${fieldItem.fieldName?cap_first}());
|
||||
</#list>
|
||||
|
||||
<#list classInfo.fieldList as fieldItem>
|
||||
// ${fieldItem.fieldComment}
|
||||
map.put("${fieldItem.fieldName?uncap_first}",${classInfo.className?uncap_first}.get${fieldItem.fieldName?cap_first}());
|
||||
</#list>
|
||||
|
||||
</#if>
|
||||
@@ -0,0 +1,13 @@
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
{
|
||||
<#list classInfo.fieldList as fieldItem>
|
||||
"${fieldItem.fieldName}":"${fieldItem.fieldComment}"<#if fieldItem_has_next>,</#if>
|
||||
</#list>
|
||||
}
|
||||
|
||||
{
|
||||
<#list classInfo.fieldList as fieldItem>
|
||||
"${fieldItem.fieldName}":""<#if fieldItem_has_next>,</#if>
|
||||
</#list>
|
||||
}
|
||||
</#if>
|
||||
@@ -0,0 +1,74 @@
|
||||
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
#SQL横向select
|
||||
SELECT <#list classInfo.fieldList as fieldItem >t.${fieldItem.columnName}<#if fieldItem_has_next>,</#if></#list>
|
||||
FROM ${classInfo.tableName} t;
|
||||
|
||||
#CSV横向字段名
|
||||
<#list classInfo.fieldList as fieldItem >${fieldItem.columnName}<#if fieldItem_has_next>,</#if></#list>
|
||||
</#if>
|
||||
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
#LEFT JOIN
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
${classInfo.tableName} a
|
||||
LEFT JOIN ${classInfo.tableName} b
|
||||
ON a.${classInfo.tableName}_id=b.${classInfo.tableName}_id
|
||||
WHERE 1=1;
|
||||
</#if>
|
||||
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
#INSERT INTO
|
||||
INSERT INTO ${classInfo.tableName} ( <#list classInfo.fieldList as fieldItem >${fieldItem.columnName}<#if fieldItem_has_next>,</#if></#list> )
|
||||
VALUES
|
||||
(
|
||||
<#list classInfo.fieldList as fieldItem >''<#if fieldItem_has_next>,</#if></#list>
|
||||
);
|
||||
</#if>
|
||||
|
||||
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
#关联更新
|
||||
UPDATE ${classInfo.tableName} a
|
||||
JOIN ${classInfo.tableName}_join b ON a.${classInfo.tableName}_id = b.${classInfo.tableName}_id
|
||||
SET <#list classInfo.fieldList as fieldItem > a.${fieldItem.columnName} = b.${fieldItem.columnName}<#if fieldItem_has_next>,</#if> </#list>
|
||||
WHERE
|
||||
b.${classInfo.tableName}_id IS NOT NULL;
|
||||
|
||||
UPDATE ${classInfo.tableName} a,${classInfo.tableName}_join b
|
||||
SET <#list classInfo.fieldList as fieldItem > a.${fieldItem.columnName} = b.${fieldItem.columnName}<#if fieldItem_has_next>,</#if> </#list>
|
||||
WHERE a.${classInfo.tableName}_id = b.${classInfo.tableName}_id;
|
||||
|
||||
#普通update
|
||||
UPDATE ${classInfo.tableName}
|
||||
SET
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
${fieldItem.columnName} = ''<#if fieldItem_has_next>,</#if>
|
||||
</#list>
|
||||
WHERE
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
${fieldItem.columnName} = ''<#if fieldItem_has_next>,</#if>
|
||||
</#list>;
|
||||
</#if>
|
||||
|
||||
|
||||
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
#关联删除
|
||||
delete a from ${classInfo.tableName}_del as a inner join ${classInfo.tableName} as b
|
||||
where a.${classInfo.tableName}_id=b.${classInfo.tableName}_id;
|
||||
|
||||
#普通删除
|
||||
DELETE
|
||||
FROM
|
||||
${classInfo.tableName}
|
||||
WHERE
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
${fieldItem.columnName} = ''<#if fieldItem_has_next>,</#if>
|
||||
</#list>;
|
||||
|
||||
</#if>
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
${classInfo.className}:
|
||||
type: "object"
|
||||
properties:
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
${fieldItem.fieldName}:
|
||||
type: ${fieldItem.swaggerClass}
|
||||
description: <#if isComment?exists && isComment==true>"${fieldItem.fieldComment}"</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<!--
|
||||
${classInfo.classComment!'数据'}对象Get Set
|
||||
@author ${authorName} ${.now?string('yyyy-MM-dd')}
|
||||
-->
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<${classInfo.className}>
|
||||
<#list classInfo.fieldList as fieldItem>
|
||||
<${fieldItem.fieldName}>${fieldItem.fieldComment}</${fieldItem.fieldName}>
|
||||
</#list>
|
||||
</${classInfo.className}>
|
||||
</#if>
|
||||
@@ -5,7 +5,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.agileboot</groupId>
|
||||
<artifactId>agileboot-cloud</artifactId>
|
||||
<artifactId>agileboot-system</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
@@ -38,5 +38,14 @@
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.agileboot</groupId>
|
||||
<artifactId>wol-common-naocs</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user