✨ 添加新特性。支持路由信息的二级缓存
This commit is contained in:
1 parent
12277fb0a7
commit
6f51054330
18 files changed
+171
-80
No files matched your search
+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