mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 20:49:00 +08:00
✨ 添加新特性。支持路由信息的二级缓存
This commit is contained in:
1 parent
12277fb0a7
commit
6f51054330
18 files changed
+171
-80
No files matched your search
@@ -3,35 +3,6 @@ USE pigxx;
|
||||
SET NAMES utf8mb4;
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for sys_datasource_conf
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `sys_datasource_conf`;
|
||||
CREATE TABLE `sys_datasource_conf` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`name` varchar(255) DEFAULT NULL COMMENT '名称',
|
||||
`url` varchar(255) DEFAULT NULL,
|
||||
`username` varchar(255) DEFAULT NULL,
|
||||
`password` varchar(255) DEFAULT NULL,
|
||||
`create_date` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_date` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新',
|
||||
`del_flag` char(50) DEFAULT '0' COMMENT '删除标记',
|
||||
`tenant_id` int(11) DEFAULT NULL COMMENT '租户ID',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='数据源表';
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of sys_datasource_conf
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
INSERT INTO `sys_datasource_conf` VALUES (1, 'pigxx', 'jdbc:mysql://pigx-mysql:3306/pigxx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true', 'root', 'Cx+ocw0iFCpae4Qo4IoFmQ==', '2019-03-31 16:40:43', '2019-06-13 03:07:24', '0', 1);
|
||||
INSERT INTO `sys_datasource_conf` VALUES (2, 'pigxx_ac', 'jdbc:mysql://pigx-mysql:3306/pigxx_ac?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8', 'root', 'Cx+ocw0iFCpae4Qo4IoFmQ==', '2019-03-31 17:53:25', '2019-06-13 03:07:25', '0', 1);
|
||||
INSERT INTO `sys_datasource_conf` VALUES (3, 'pigxx_job', 'jdbc:mysql://pigx-mysql:3306/pigxx_job?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8', 'root', 'Cx+ocw0iFCpae4Qo4IoFmQ==', '2019-03-31 17:53:25', '2019-06-13 03:07:26', '0', 1);
|
||||
INSERT INTO `sys_datasource_conf` VALUES (4, 'pigxx_zipkin', 'jdbc:mysql://pigx-mysql:3306/pigxx_zipkin?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8', 'root', 'Cx+ocw0iFCpae4Qo4IoFmQ==', '2019-03-31 17:53:25', '2019-06-13 03:07:27', '0', 1);
|
||||
INSERT INTO `sys_datasource_conf` VALUES (5, 'pigxx_mp', 'jdbc:mysql://pigx-mysql:3306/pigxx_mp?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8', 'root', 'Cx+ocw0iFCpae4Qo4IoFmQ==', '2019-03-31 17:53:25', '2019-06-13 03:07:28', '0', 1);
|
||||
INSERT INTO `sys_datasource_conf` VALUES (6, 'pigxx_pay', 'jdbc:mysql://pigx-mysql:3306/pigxx_pay?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8', 'root', 'Cx+ocw0iFCpae4Qo4IoFmQ==', '2019-03-31 17:53:25', '2019-06-13 03:07:30', '0', 1);
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for sys_dept
|
||||
-- ----------------------------
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
USE pigxx_codegen;
|
||||
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for gen_datasource_conf
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `gen_datasource_conf`;
|
||||
CREATE TABLE `gen_datasource_conf` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '名称',
|
||||
`url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
|
||||
`username` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
|
||||
`password` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
|
||||
`create_date` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_date` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新',
|
||||
`del_flag` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '0' COMMENT '删除标记',
|
||||
`tenant_id` int(11) DEFAULT NULL COMMENT '租户ID',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='数据源表';
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of gen_datasource_conf
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
INSERT INTO `gen_datasource_conf` VALUES (1, 'pigxx', 'jdbc:mysql://pigx-mysql:3306/pigxx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true', 'root', 'Cx+ocw0iFCpae4Qo4IoFmQ==', '2019-03-31 16:40:43', '2019-06-13 03:07:24', '0', 1);
|
||||
INSERT INTO `gen_datasource_conf` VALUES (2, 'pigxx_ac', 'jdbc:mysql://pigx-mysql:3306/pigxx_ac?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8', 'root', 'Cx+ocw0iFCpae4Qo4IoFmQ==', '2019-03-31 17:53:25', '2019-06-13 03:07:25', '0', 1);
|
||||
INSERT INTO `gen_datasource_conf` VALUES (3, 'pigxx_job', 'jdbc:mysql://pigx-mysql:3306/pigxx_job?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8', 'root', 'Cx+ocw0iFCpae4Qo4IoFmQ==', '2019-03-31 17:53:25', '2019-06-13 03:07:26', '0', 1);
|
||||
INSERT INTO `gen_datasource_conf` VALUES (4, 'pigxx_zipkin', 'jdbc:mysql://pigx-mysql:3306/pigxx_zipkin?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8', 'root', 'Cx+ocw0iFCpae4Qo4IoFmQ==', '2019-03-31 17:53:25', '2019-06-13 03:07:27', '0', 1);
|
||||
INSERT INTO `gen_datasource_conf` VALUES (5, 'pigxx_mp', 'jdbc:mysql://pigx-mysql:3306/pigxx_mp?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8', 'root', 'Cx+ocw0iFCpae4Qo4IoFmQ==', '2019-03-31 17:53:25', '2019-06-13 03:07:28', '0', 1);
|
||||
INSERT INTO `gen_datasource_conf` VALUES (6, 'pigxx_pay', 'jdbc:mysql://pigx-mysql:3306/pigxx_pay?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8', 'root', 'Cx+ocw0iFCpae4Qo4IoFmQ==', '2019-03-31 17:53:25', '2019-06-13 03:07:30', '0', 1);
|
||||
INSERT INTO `gen_datasource_conf` VALUES (7, 'pigxx_codegen', 'jdbc:mysql://pigx-mysql:3306/pigxx_codegen?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true', 'root', 'hyxlg2iaqpDLOe9qEcv2xQ==', '2019-08-12 15:47:39', '2019-08-12 15:47:39', '0', 1);
|
||||
INSERT INTO `gen_datasource_conf` VALUES (8, 'pigxx_demo', 'jdbc:mysql://pigx-mysql:3306/pigxx_demo?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8', 'root', '+tGzf9gpWcieCuou7rNMnw==', '2019-08-17 06:17:56', '2019-08-17 06:21:45', '1', 1);
|
||||
INSERT INTO `gen_datasource_conf` VALUES (9, 'pigxx_demo', 'jdbc:mysql://pigx-mysql:3306/pigxx_demo?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true', 'root', 'mex49WI97SlllRVJc8qOPw==', '2019-08-17 06:20:12', '2019-08-17 06:23:30', '1', 1);
|
||||
INSERT INTO `gen_datasource_conf` VALUES (10, 'pigxx_demo', 'jdbc:mysql://pigx-mysql:3306/pigxx_demo?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true', 'root', 'sAyIVHbSdsBuL+rHA76new==', '2019-08-17 06:27:01', '2019-08-17 06:27:01', '0', 1);
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for gen_form_conf
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `gen_form_conf`;
|
||||
CREATE TABLE `gen_form_conf` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
|
||||
`table_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL COMMENT '表名称',
|
||||
`form_info` json NOT NULL COMMENT '表单信息',
|
||||
`create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
|
||||
`del_flag` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT '0' COMMENT '删除标记',
|
||||
`tenant_id` int(11) DEFAULT NULL COMMENT '所属租户',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
KEY `table_name` (`table_name`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='表单配置';
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
+3
-1
@@ -16,4 +16,6 @@ COPY ./db/5pigxx_mp.sql /docker-entrypoint-initdb.d
|
||||
|
||||
COPY ./db/6pigxx_config.sql /docker-entrypoint-initdb.d
|
||||
|
||||
COPY ./db/7pigxx_pay.sql /docker-entrypoint-initdb.d
|
||||
COPY ./db/7pigxx_pay.sql /docker-entrypoint-initdb.d
|
||||
|
||||
COPY ./db/8pigxx_codegen.sql /docker-entrypoint-initdb.d
|
||||
+2
@@ -55,6 +55,7 @@ public class RedisRouteDefinitionWriter implements RouteDefinitionRepository {
|
||||
log.info("保存路由信息{}", vo);
|
||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
redisTemplate.opsForHash().put(CacheConstants.ROUTE_KEY, r.getId(), vo);
|
||||
redisTemplate.convertAndSend(CacheConstants.ROUTE_KEY, "新增路由信息,网关缓存更新");
|
||||
return Mono.empty();
|
||||
});
|
||||
}
|
||||
@@ -66,6 +67,7 @@ public class RedisRouteDefinitionWriter implements RouteDefinitionRepository {
|
||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
redisTemplate.opsForHash().delete(CacheConstants.ROUTE_KEY, id);
|
||||
});
|
||||
redisTemplate.convertAndSend(CacheConstants.ROUTE_KEY, "删除路由信息,网关缓存更新");
|
||||
return Mono.empty();
|
||||
}
|
||||
|
||||
|
||||
-2
@@ -51,7 +51,6 @@ import java.util.List;
|
||||
@Api(value = "log", tags = "日志管理模块")
|
||||
public class SysLogController {
|
||||
private final SysLogService sysLogService;
|
||||
private final RedisTemplate redisTemplate;
|
||||
|
||||
/**
|
||||
* 简单分页查询
|
||||
@@ -74,7 +73,6 @@ public class SysLogController {
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("@pms.hasPermission('sys_log_del')")
|
||||
public R removeById(@PathVariable Long id) {
|
||||
redisTemplate.convertAndSend(CacheConstants.ROUTE_KEY, id);
|
||||
return R.ok(sysLogService.removeById(id));
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -156,7 +156,7 @@ public class SysRouteConfServiceImpl extends ServiceImpl<SysRouteConfMapper, Sys
|
||||
log.debug("更新网关路由结束 ");
|
||||
|
||||
this.applicationEventPublisher.publishEvent(new RefreshRoutesEvent(this));
|
||||
|
||||
redisTemplate.convertAndSend(CacheConstants.ROUTE_KEY, "UPMS路由信息,网关缓存更新");
|
||||
} catch (Exception e) {
|
||||
log.error("路由配置解析失败", e);
|
||||
// 回滚路由,重新加载即可
|
||||
|
||||
@@ -8,6 +8,7 @@ spring:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: ${NACOS-HOST:pigx-register}:${NACOS-PORT:8848}
|
||||
network-interface: ppp0
|
||||
config:
|
||||
server-addr: ${spring.cloud.nacos.discovery.server-addr}
|
||||
file-extension: yml
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping("/dsconf")
|
||||
public class SysDsConfController {
|
||||
public class GenDsConfController {
|
||||
private final GenDatasourceConfService datasourceConfService;
|
||||
|
||||
/**
|
||||
+14
-13
@@ -46,14 +46,14 @@ public class GenFormConfController {
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param genRecord 生成记录
|
||||
* @param page 分页对象
|
||||
* @param formConf 生成记录
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "分页查询", notes = "分页查询")
|
||||
@GetMapping("/page")
|
||||
public R getGenFormConfPage(Page page, GenFormConf genRecord) {
|
||||
return R.ok(genRecordService.page(page, Wrappers.query(genRecord)));
|
||||
public R getGenFormConfPage(Page page, GenFormConf formConf) {
|
||||
return R.ok(genRecordService.page(page, Wrappers.query(formConf)));
|
||||
}
|
||||
|
||||
|
||||
@@ -72,41 +72,42 @@ public class GenFormConfController {
|
||||
/**
|
||||
* 通过id查询生成记录
|
||||
*
|
||||
* @param dsId 数据源ID
|
||||
* @param tableName tableName
|
||||
* @return R
|
||||
*/
|
||||
@ApiOperation(value = "通过tableName查询表单信息")
|
||||
@GetMapping("/info/{tableName}")
|
||||
public R form(@PathVariable String tableName) {
|
||||
return R.ok(genRecordService.getForm(tableName));
|
||||
@GetMapping("/info")
|
||||
public R form(Integer dsId, String tableName) {
|
||||
return R.ok(genRecordService.getForm(dsId, tableName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增生成记录
|
||||
*
|
||||
* @param genRecord 生成记录
|
||||
* @param formConf 生成记录
|
||||
* @return R
|
||||
*/
|
||||
@ApiOperation(value = "新增生成记录", notes = "新增生成记录")
|
||||
@SysLog("新增生成记录")
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('gen_form_add')")
|
||||
public R save(@RequestBody GenFormConf genRecord) {
|
||||
return R.ok(genRecordService.save(genRecord));
|
||||
public R save(@RequestBody GenFormConf formConf) {
|
||||
return R.ok(genRecordService.save(formConf));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改生成记录
|
||||
*
|
||||
* @param genRecord 生成记录
|
||||
* @param formConf 生成记录
|
||||
* @return R
|
||||
*/
|
||||
@ApiOperation(value = "修改生成记录", notes = "修改生成记录")
|
||||
@SysLog("修改生成记录")
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('gen_form_edit')")
|
||||
public R updateById(@RequestBody GenFormConf genRecord) {
|
||||
return R.ok(genRecordService.updateById(genRecord));
|
||||
public R updateById(@RequestBody GenFormConf formConf) {
|
||||
return R.ok(genRecordService.updateById(formConf));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping("/generator")
|
||||
public class SysGeneratorController {
|
||||
public class GeneratorController {
|
||||
private final GeneratorService GeneratorService;
|
||||
|
||||
/**
|
||||
-5
@@ -46,11 +46,6 @@ public class GenFormConf extends Model<GenFormConf> {
|
||||
@TableId
|
||||
@ApiModelProperty(value = "ID")
|
||||
private Integer id;
|
||||
/**
|
||||
* 所属数据源
|
||||
*/
|
||||
@ApiModelProperty(value = "所属数据源")
|
||||
private String dsName;
|
||||
/**
|
||||
* 表名称
|
||||
*/
|
||||
|
||||
+4
-2
@@ -31,8 +31,10 @@ public interface GenFormConfService extends IService<GenFormConf> {
|
||||
/**
|
||||
* 获取表单信息
|
||||
*
|
||||
* @param tableName
|
||||
* @param dsId 数据源ID
|
||||
* @param tableName 表名称
|
||||
* @return
|
||||
*/
|
||||
GenFormConf getForm(String tableName);
|
||||
String getForm(Integer dsId, String tableName);
|
||||
|
||||
}
|
||||
+59
-2
@@ -16,13 +16,32 @@
|
||||
*/
|
||||
package com.pig4cloud.pigx.codegen.service.impl;
|
||||
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.pig4cloud.pigx.codegen.entity.ColumnEntity;
|
||||
import com.pig4cloud.pigx.codegen.entity.GenFormConf;
|
||||
import com.pig4cloud.pigx.codegen.mapper.GenFormConfMapper;
|
||||
import com.pig4cloud.pigx.codegen.mapper.GeneratorMapper;
|
||||
import com.pig4cloud.pigx.codegen.service.GenFormConfService;
|
||||
import com.pig4cloud.pigx.codegen.util.GenUtils;
|
||||
import com.pig4cloud.pigx.common.datasource.config.DynamicDataSource;
|
||||
import com.pig4cloud.pigx.common.datasource.support.DynamicDataSourceContextHolder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.apache.velocity.app.Velocity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* 表单管理
|
||||
*
|
||||
@@ -30,12 +49,50 @@ import org.springframework.stereotype.Service;
|
||||
* @date 2019-08-12 15:55:35
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class GenFormConfServiceImpl extends ServiceImpl<GenFormConfMapper, GenFormConf> implements GenFormConfService {
|
||||
private final GeneratorMapper generatorMapper;
|
||||
private final DynamicDataSource dynamicDataSource;
|
||||
|
||||
/**
|
||||
* 1. 根据数据源、表名称,查询已配置表单信息
|
||||
* 2. 不存在调用模板生成
|
||||
*
|
||||
* @param dsId 数据源ID
|
||||
* @param tableName 表名称
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public GenFormConf getForm(String tableName) {
|
||||
return getOne(Wrappers.<GenFormConf>lambdaQuery()
|
||||
@SneakyThrows
|
||||
public String getForm(Integer dsId, String tableName) {
|
||||
DynamicDataSourceContextHolder.setDataSourceType(dsId);
|
||||
GenFormConf form = getOne(Wrappers.<GenFormConf>lambdaQuery()
|
||||
.eq(GenFormConf::getTableName, tableName)
|
||||
.orderByDesc(GenFormConf::getCreateTime), false);
|
||||
|
||||
if (form != null) {
|
||||
return form.getFormInfo();
|
||||
}
|
||||
|
||||
List<Map<String, String>> columns = generatorMapper.queryColumns(tableName);
|
||||
//设置velocity资源加载器
|
||||
Properties prop = new Properties();
|
||||
prop.put("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
|
||||
Velocity.init(prop);
|
||||
Template template = Velocity.getTemplate("template/crud.js.vm", CharsetUtil.UTF_8);
|
||||
VelocityContext context = new VelocityContext();
|
||||
|
||||
List<ColumnEntity> columnList = new ArrayList<>();
|
||||
for (Map<String, String> column : columns) {
|
||||
ColumnEntity columnEntity = new ColumnEntity();
|
||||
columnEntity.setComments(column.get("columnComment"));
|
||||
columnEntity.setLowerAttrName(StringUtils.uncapitalize(GenUtils.columnToJava(column.get("columnName"))));
|
||||
columnList.add(columnEntity);
|
||||
}
|
||||
context.put("columns", columnList);
|
||||
StringWriter writer = new StringWriter();
|
||||
template.merge(context, writer);
|
||||
return StrUtil.trim(StrUtil.removePrefix(writer.toString(), GenUtils.CRUD_PREFIX));
|
||||
}
|
||||
|
||||
}
|
||||
+12
-6
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.pig4cloud.pigx.codegen.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@@ -47,7 +48,7 @@ import java.util.zip.ZipOutputStream;
|
||||
@AllArgsConstructor
|
||||
public class GeneratorServiceImpl implements GeneratorService {
|
||||
private final GeneratorMapper generatorMapper;
|
||||
private final GenFormConfMapper genRecordMapper;
|
||||
private final GenFormConfMapper genFormConfMapper;
|
||||
|
||||
/**
|
||||
* 分页查询表
|
||||
@@ -70,6 +71,11 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
*/
|
||||
@Override
|
||||
public byte[] generatorCode(GenConfig genConfig) {
|
||||
//根据tableName 查询最新的表单配置
|
||||
List<GenFormConf> formConfList = genFormConfMapper.selectList(Wrappers.<GenFormConf>lambdaQuery()
|
||||
.eq(GenFormConf::getTableName, genConfig.getTableName())
|
||||
.orderByDesc(GenFormConf::getCreateTime));
|
||||
|
||||
DynamicDataSourceContextHolder.setDataSourceType(genConfig.getId());
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
||||
@@ -80,12 +86,12 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
Map<String, String> table = queryTable(tableName);
|
||||
//查询列信息
|
||||
List<Map<String, String>> columns = queryColumns(tableName);
|
||||
//根据tableName 查询最新的表单配置
|
||||
GenFormConf record = genRecordMapper.selectOne(Wrappers.<GenFormConf>lambdaQuery()
|
||||
.eq(GenFormConf::getTableName, tableName)
|
||||
.orderByDesc(GenFormConf::getCreateTime));
|
||||
//生成代码
|
||||
GenUtils.generatorCode(genConfig, table, columns, zip, record);
|
||||
if (CollUtil.isNotEmpty(formConfList)) {
|
||||
GenUtils.generatorCode(genConfig, table, columns, zip, formConfList.get(0));
|
||||
} else {
|
||||
GenUtils.generatorCode(genConfig, table, columns, zip, null);
|
||||
}
|
||||
}
|
||||
IoUtil.close(zip);
|
||||
return outputStream.toByteArray();
|
||||
|
||||
+5
-5
@@ -55,7 +55,7 @@ import java.util.zip.ZipOutputStream;
|
||||
@Slf4j
|
||||
@UtilityClass
|
||||
public class GenUtils {
|
||||
|
||||
public final String CRUD_PREFIX = "export const tableOption =";
|
||||
private final String ENTITY_JAVA_VM = "Entity.java.vm";
|
||||
private final String MAPPER_JAVA_VM = "Mapper.java.vm";
|
||||
private final String SERVICE_JAVA_VM = "Service.java.vm";
|
||||
@@ -88,7 +88,7 @@ public class GenUtils {
|
||||
*/
|
||||
@SneakyThrows
|
||||
public void generatorCode(GenConfig genConfig, Map<String, String> table,
|
||||
List<Map<String, String>> columns, ZipOutputStream zip, GenFormConf record) {
|
||||
List<Map<String, String>> columns, ZipOutputStream zip, GenFormConf formConf) {
|
||||
//配置信息
|
||||
Configuration config = getConfig();
|
||||
boolean hasBigDecimal = false;
|
||||
@@ -202,11 +202,11 @@ public class GenUtils {
|
||||
List<String> templates = getTemplates();
|
||||
for (String template : templates) {
|
||||
// 如果是crud
|
||||
if (template.contains(CRUD_JS_VM) && record != null) {
|
||||
if (template.contains(CRUD_JS_VM) && formConf != null) {
|
||||
zip.putNextEntry(new ZipEntry(Objects
|
||||
.requireNonNull(getFileName(template, tableEntity.getCaseClassName()
|
||||
, map.get("package").toString(), map.get("moduleName").toString()))));
|
||||
IoUtil.write(zip, StandardCharsets.UTF_8, false, record.getFormInfo());
|
||||
IoUtil.write(zip, StandardCharsets.UTF_8, false, CRUD_PREFIX + formConf.getFormInfo());
|
||||
zip.closeEntry();
|
||||
continue;
|
||||
}
|
||||
@@ -231,7 +231,7 @@ public class GenUtils {
|
||||
/**
|
||||
* 列名转换成Java属性名
|
||||
*/
|
||||
private String columnToJava(String columnName) {
|
||||
public String columnToJava(String columnName) {
|
||||
return WordUtils.capitalizeFully(columnName, new char[]{'_'}).replace("_", "");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
server:
|
||||
port: 5003
|
||||
|
||||
spring:
|
||||
spring:r
|
||||
application:
|
||||
name: @artifactId@
|
||||
cloud:
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
<resultMap id="genRecordMap" type="com.pig4cloud.pigx.codegen.entity.GenFormConf">
|
||||
<id property="id" column="id"/>
|
||||
<result property="dsName" column="ds_name"/>
|
||||
<result property="tableName" column="table_name"/>
|
||||
<result property="formInfo" column="form_info"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
export const tableOption = {
|
||||
border: true,
|
||||
index: true,
|
||||
indexLabel: '序号',
|
||||
stripe: true,
|
||||
menuAlign: 'center',
|
||||
align: 'center',
|
||||
column: [
|
||||
"border": true,
|
||||
"index": true,
|
||||
"indexLabel": "序号",
|
||||
"stripe": true,
|
||||
"menuAlign": "center",
|
||||
"align": "center",
|
||||
"column": [
|
||||
#foreach ($column in $columns)
|
||||
{
|
||||
label: '$column.comments',
|
||||
prop: '$column.lowerAttrName'
|
||||
},
|
||||
"type": "input",
|
||||
"label": "$column.comments",
|
||||
"prop": "$column.lowerAttrName"
|
||||
}#if($foreach.hasNext),#end
|
||||
#end
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user