diff --git a/db/2pigxx.sql b/db/2pigxx.sql index fdbc10b06..99627ca75 100644 --- a/db/2pigxx.sql +++ b/db/2pigxx.sql @@ -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 -- ---------------------------- diff --git a/db/8pigxx_codegen.sql b/db/8pigxx_codegen.sql new file mode 100644 index 000000000..ab9875fcd --- /dev/null +++ b/db/8pigxx_codegen.sql @@ -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; \ No newline at end of file diff --git a/db/Dockerfile b/db/Dockerfile index 2a5c36622..3118c351d 100644 --- a/db/Dockerfile +++ b/db/Dockerfile @@ -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 \ No newline at end of file +COPY ./db/7pigxx_pay.sql /docker-entrypoint-initdb.d + +COPY ./db/8pigxx_codegen.sql /docker-entrypoint-initdb.d \ No newline at end of file diff --git a/pigx-common/pigx-common-gateway/src/main/java/com/pig4cloud/pigx/common/gateway/support/RedisRouteDefinitionWriter.java b/pigx-common/pigx-common-gateway/src/main/java/com/pig4cloud/pigx/common/gateway/support/RedisRouteDefinitionWriter.java index 2fb7e06bc..f759ec9b9 100644 --- a/pigx-common/pigx-common-gateway/src/main/java/com/pig4cloud/pigx/common/gateway/support/RedisRouteDefinitionWriter.java +++ b/pigx-common/pigx-common-gateway/src/main/java/com/pig4cloud/pigx/common/gateway/support/RedisRouteDefinitionWriter.java @@ -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(); } diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysLogController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysLogController.java index 9bbf16ebd..048294763 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysLogController.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysLogController.java @@ -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)); } diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRouteConfServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRouteConfServiceImpl.java index d73e26ffe..84f2defee 100755 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRouteConfServiceImpl.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRouteConfServiceImpl.java @@ -156,7 +156,7 @@ public class SysRouteConfServiceImpl extends ServiceImpl { @TableId @ApiModelProperty(value = "ID") private Integer id; - /** - * 所属数据源 - */ - @ApiModelProperty(value = "所属数据源") - private String dsName; /** * 表名称 */ diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenFormConfService.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenFormConfService.java index f62efcde6..a26d1f951 100755 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenFormConfService.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenFormConfService.java @@ -31,8 +31,10 @@ public interface GenFormConfService extends IService { /** * 获取表单信息 * - * @param tableName + * @param dsId 数据源ID + * @param tableName 表名称 * @return */ - GenFormConf getForm(String tableName); + String getForm(Integer dsId, String tableName); + } diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenFormConfServiceImpl.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenFormConfServiceImpl.java index 9ea91edf1..48c36d38b 100755 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenFormConfServiceImpl.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenFormConfServiceImpl.java @@ -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 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.lambdaQuery() + @SneakyThrows + public String getForm(Integer dsId, String tableName) { + DynamicDataSourceContextHolder.setDataSourceType(dsId); + GenFormConf form = getOne(Wrappers.lambdaQuery() .eq(GenFormConf::getTableName, tableName) .orderByDesc(GenFormConf::getCreateTime), false); + + if (form != null) { + return form.getFormInfo(); + } + + List> 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 columnList = new ArrayList<>(); + for (Map 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)); } + } diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GeneratorServiceImpl.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GeneratorServiceImpl.java index 939b6fd48..581b1b10c 100755 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GeneratorServiceImpl.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GeneratorServiceImpl.java @@ -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 formConfList = genFormConfMapper.selectList(Wrappers.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 table = queryTable(tableName); //查询列信息 List> columns = queryColumns(tableName); - //根据tableName 查询最新的表单配置 - GenFormConf record = genRecordMapper.selectOne(Wrappers.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(); diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/GenUtils.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/GenUtils.java index 50364c51b..26a55a4bf 100644 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/GenUtils.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/GenUtils.java @@ -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 table, - List> columns, ZipOutputStream zip, GenFormConf record) { + List> columns, ZipOutputStream zip, GenFormConf formConf) { //配置信息 Configuration config = getConfig(); boolean hasBigDecimal = false; @@ -202,11 +202,11 @@ public class GenUtils { List 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("_", ""); } diff --git a/pigx-visual/pigx-codegen/src/main/resources/bootstrap.yml b/pigx-visual/pigx-codegen/src/main/resources/bootstrap.yml index 8d8a9b22c..504fa7130 100644 --- a/pigx-visual/pigx-codegen/src/main/resources/bootstrap.yml +++ b/pigx-visual/pigx-codegen/src/main/resources/bootstrap.yml @@ -1,7 +1,7 @@ server: port: 5003 -spring: +spring:r application: name: @artifactId@ cloud: diff --git a/pigx-visual/pigx-codegen/src/main/resources/mapper/GenFormConfMapper.xml b/pigx-visual/pigx-codegen/src/main/resources/mapper/GenFormConfMapper.xml index 661bb3a78..5e1439fd8 100755 --- a/pigx-visual/pigx-codegen/src/main/resources/mapper/GenFormConfMapper.xml +++ b/pigx-visual/pigx-codegen/src/main/resources/mapper/GenFormConfMapper.xml @@ -23,7 +23,6 @@ - diff --git a/pigx-visual/pigx-codegen/src/main/resources/template/crud.js.vm b/pigx-visual/pigx-codegen/src/main/resources/template/crud.js.vm index 887df0b8a..0c9e51fa2 100644 --- a/pigx-visual/pigx-codegen/src/main/resources/template/crud.js.vm +++ b/pigx-visual/pigx-codegen/src/main/resources/template/crud.js.vm @@ -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 ] }