master
parent
edc8729732
commit
450bca1ad8
|
|
@ -1,15 +1,24 @@
|
||||||
package com.njzscloud.common.gen;
|
package com.njzscloud.common.gen;
|
||||||
|
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.date.DateTime;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.core.util.ZipUtil;
|
||||||
import com.njzscloud.common.core.tuple.Tuple3;
|
import com.njzscloud.common.core.tuple.Tuple3;
|
||||||
|
import com.njzscloud.common.core.utils.Mime;
|
||||||
import com.njzscloud.common.core.utils.R;
|
import com.njzscloud.common.core.utils.R;
|
||||||
import com.njzscloud.common.gen.support.Generator;
|
import com.njzscloud.common.gen.support.Generator;
|
||||||
import com.njzscloud.common.mp.support.PageParam;
|
import com.njzscloud.common.mp.support.PageParam;
|
||||||
import com.njzscloud.common.mp.support.PageResult;
|
import com.njzscloud.common.mp.support.PageResult;
|
||||||
|
import com.njzscloud.common.mvc.util.ServletUtil;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -52,22 +61,39 @@ public class TplController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/generate")
|
@PostMapping("/generate")
|
||||||
public R<?> generate(@RequestParam("tplName") String tplName,
|
public void generate(@RequestParam("tplNames") String[] tplNames,
|
||||||
@RequestParam("tableName") String tableName,
|
@RequestParam("tableName") String tableName,
|
||||||
@RequestBody(required = false) Map<String, Object> data) {
|
@RequestBody(required = false) Map<String, Object> data,
|
||||||
Tuple3<String, String, String> res = Generator.generate(tplName, tableName, data);
|
HttpServletResponse response) {
|
||||||
return R.success(MapUtil.builder()
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
.put("dir", res.get_0())
|
String[] paths = new String[tplNames.length];
|
||||||
.put("filename", res.get_1())
|
InputStream[] ins = new InputStream[tplNames.length];
|
||||||
.put("content", res.get_2())
|
for (int i = 0; i < tplNames.length; i++) {
|
||||||
.build());
|
String tplName = tplNames[i];
|
||||||
|
Tuple3<String, String, String> res = Generator.generate(tplName, tableName, data);
|
||||||
|
String res0 = res.get_0();
|
||||||
|
String res1 = res.get_1();
|
||||||
|
String res2 = res.get_2();
|
||||||
|
StringBuilder pathBuilder = new StringBuilder();
|
||||||
|
if (StrUtil.isNotBlank(res0)) {
|
||||||
|
pathBuilder.append(res0);
|
||||||
|
if (!res0.endsWith("/")) pathBuilder.append("/");
|
||||||
|
}
|
||||||
|
if (StrUtil.isNotBlank(res1)) pathBuilder.append(res1);
|
||||||
|
else pathBuilder.append(IdUtil.fastSimpleUUID()).append(".txt");
|
||||||
|
paths[i] = pathBuilder.toString();
|
||||||
|
ins[i] = new ByteArrayInputStream(res2.getBytes());
|
||||||
|
}
|
||||||
|
ZipUtil.zip(out, paths, ins);
|
||||||
|
|
||||||
|
ServletUtil.download(response, out.toByteArray(), Mime.ZIP, DateTime.now() + ".zip");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 详情
|
* 详情
|
||||||
*/
|
*/
|
||||||
@GetMapping("/detail")
|
@GetMapping("/detail")
|
||||||
public R<TplEntity> detail(@RequestParam Long id) {
|
public R<TplEntity> detail(@RequestParam("id") Long id) {
|
||||||
return R.success(tplService.detail(id));
|
return R.success(tplService.detail(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -80,23 +106,6 @@ public class TplController {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
站点
|
|
||||||
{
|
|
||||||
strategy:all、specify,
|
|
||||||
objs:【】
|
|
||||||
}
|
|
||||||
产品
|
|
||||||
{
|
|
||||||
strategy:all、specify,
|
|
||||||
objs:【】
|
|
||||||
}
|
|
||||||
用户
|
|
||||||
{
|
|
||||||
strategy: None | All | Specify,
|
|
||||||
objs: long[]
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.njzscloud.common.gen.contant.TplCategory;
|
|
||||||
import com.njzscloud.common.gen.support.Tpl;
|
import com.njzscloud.common.gen.support.Tpl;
|
||||||
import com.njzscloud.common.mp.support.handler.j.JsonTypeHandler;
|
import com.njzscloud.common.mp.support.handler.j.JsonTypeHandler;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
@ -35,11 +34,6 @@ public class TplEntity {
|
||||||
*/
|
*/
|
||||||
private String tplName;
|
private String tplName;
|
||||||
|
|
||||||
/**
|
|
||||||
* 模板类型; 字典编码:tpl_category
|
|
||||||
*/
|
|
||||||
private TplCategory tplCategory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 模板内容
|
* 模板内容
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.njzscloud.common.core.ex.Exceptions;
|
import com.njzscloud.common.core.ex.Exceptions;
|
||||||
import com.njzscloud.common.gen.contant.TplCategory;
|
|
||||||
import com.njzscloud.common.gen.support.TemplateEngine;
|
import com.njzscloud.common.gen.support.TemplateEngine;
|
||||||
import com.njzscloud.common.gen.support.Tpl;
|
import com.njzscloud.common.gen.support.Tpl;
|
||||||
import com.njzscloud.common.mp.support.PageParam;
|
import com.njzscloud.common.mp.support.PageParam;
|
||||||
|
|
@ -34,8 +33,6 @@ public class TplService extends ServiceImpl<TplMapper, TplEntity> implements ISe
|
||||||
public void add(TplEntity tplEntity) {
|
public void add(TplEntity tplEntity) {
|
||||||
String tplName = tplEntity.getTplName();
|
String tplName = tplEntity.getTplName();
|
||||||
Assert.notBlank(tplName, () -> Exceptions.clierr("模板名称不能为空"));
|
Assert.notBlank(tplName, () -> Exceptions.clierr("模板名称不能为空"));
|
||||||
TplCategory tplCategory = tplEntity.getTplCategory();
|
|
||||||
Assert.notNull(tplCategory, () -> Exceptions.clierr("模板类型不能为空"));
|
|
||||||
boolean exists = this.exists(Wrappers.lambdaQuery(TplEntity.class).eq(TplEntity::getTplName, tplName));
|
boolean exists = this.exists(Wrappers.lambdaQuery(TplEntity.class).eq(TplEntity::getTplName, tplName));
|
||||||
Assert.isFalse(exists, () -> Exceptions.clierr("模板:{} 已存在", tplName));
|
Assert.isFalse(exists, () -> Exceptions.clierr("模板:{} 已存在", tplName));
|
||||||
Tpl tpl = tplEntity.getTpl();
|
Tpl tpl = tplEntity.getTpl();
|
||||||
|
|
@ -59,8 +56,6 @@ public class TplService extends ServiceImpl<TplMapper, TplEntity> implements ISe
|
||||||
public void modify(TplEntity tplEntity) {
|
public void modify(TplEntity tplEntity) {
|
||||||
String tplName = tplEntity.getTplName();
|
String tplName = tplEntity.getTplName();
|
||||||
Assert.notBlank(tplName, () -> Exceptions.clierr("模板名称不能为空"));
|
Assert.notBlank(tplName, () -> Exceptions.clierr("模板名称不能为空"));
|
||||||
TplCategory tplCategory = tplEntity.getTplCategory();
|
|
||||||
Assert.notNull(tplCategory, () -> Exceptions.clierr("模板类型不能为空"));
|
|
||||||
Long id = tplEntity.getId();
|
Long id = tplEntity.getId();
|
||||||
boolean exists = this.exists(Wrappers.lambdaQuery(TplEntity.class)
|
boolean exists = this.exists(Wrappers.lambdaQuery(TplEntity.class)
|
||||||
.eq(TplEntity::getTplName, tplName)
|
.eq(TplEntity::getTplName, tplName)
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,11 @@ import java.util.Map;
|
||||||
|
|
||||||
public final class Btl {
|
public final class Btl {
|
||||||
public static final Function toCamelCase = (Object[] paras, Context ctx) -> StrUtil.toCamelCase(paras[0].toString());
|
public static final Function toCamelCase = (Object[] paras, Context ctx) -> StrUtil.toCamelCase(paras[0].toString());
|
||||||
|
public static final Function toDashCase = (Object[] paras, Context ctx) -> StrUtil.toSymbolCase(paras[0].toString(), '-');
|
||||||
public static final Function upperFirst = (Object[] paras, Context ctx) -> StrUtil.upperFirst(paras[0].toString());
|
public static final Function upperFirst = (Object[] paras, Context ctx) -> StrUtil.upperFirst(paras[0].toString());
|
||||||
public static final Function isBlank = (Object[] paras, Context ctx) -> StrUtil.isBlank(paras[0].toString());
|
public static final Function isBlank = (Object[] paras, Context ctx) -> StrUtil.isBlank(paras[0].toString());
|
||||||
public static final Function subAfter = (Object[] paras, Context ctx) -> StrUtil.subAfter(paras[0].toString(), paras[1].toString(), false);
|
public static final Function subAfter = (Object[] paras, Context ctx) -> StrUtil.subAfter(paras[0].toString(), paras[1].toString(), false);
|
||||||
public static final Function sqlDataTypeMap = new Function() {
|
public static final Function javaType = new Function() {
|
||||||
private final Map<String, Map<String, String>> map = MapUtil.<String, Map<String, String>>builder()
|
private final Map<String, Map<String, String>> map = MapUtil.<String, Map<String, String>>builder()
|
||||||
.put("DEFAULT", MapUtil.<String, String>builder().put("importStatement", "").put("dataType", "").build())
|
.put("DEFAULT", MapUtil.<String, String>builder().put("importStatement", "").put("dataType", "").build())
|
||||||
.put("VARCHAR", MapUtil.<String, String>builder().put("importStatement", "").put("dataType", "String").build())
|
.put("VARCHAR", MapUtil.<String, String>builder().put("importStatement", "").put("dataType", "String").build())
|
||||||
|
|
@ -25,7 +26,7 @@ public final class Btl {
|
||||||
.put("MEDIUMINT", MapUtil.<String, String>builder().put("importStatement", "").put("dataType", "Integer").build())
|
.put("MEDIUMINT", MapUtil.<String, String>builder().put("importStatement", "").put("dataType", "Integer").build())
|
||||||
.put("INT", MapUtil.<String, String>builder().put("importStatement", "").put("dataType", "Integer").build())
|
.put("INT", MapUtil.<String, String>builder().put("importStatement", "").put("dataType", "Integer").build())
|
||||||
.put("BIGINT", MapUtil.<String, String>builder().put("importStatement", "").put("dataType", "Long").build())
|
.put("BIGINT", MapUtil.<String, String>builder().put("importStatement", "").put("dataType", "Long").build())
|
||||||
.put("DOUBLE", MapUtil.<String, String>builder().put("importStatement", "").put("dataType", "DOUBLE").build())
|
.put("DOUBLE", MapUtil.<String, String>builder().put("importStatement", "").put("dataType", "Double").build())
|
||||||
.put("DECIMAL", MapUtil.<String, String>builder().put("importStatement", "import java.math.BigDecimal;").put("dataType", "BigDecimal").build())
|
.put("DECIMAL", MapUtil.<String, String>builder().put("importStatement", "import java.math.BigDecimal;").put("dataType", "BigDecimal").build())
|
||||||
.put("DATE", MapUtil.<String, String>builder().put("importStatement", "import java.time.LocalDate;").put("dataType", "LocalDate").build())
|
.put("DATE", MapUtil.<String, String>builder().put("importStatement", "import java.time.LocalDate;").put("dataType", "LocalDate").build())
|
||||||
.put("TIME", MapUtil.<String, String>builder().put("importStatement", "import java.time.LocalTime;").put("dataType", "LocalTime").build())
|
.put("TIME", MapUtil.<String, String>builder().put("importStatement", "import java.time.LocalTime;").put("dataType", "LocalTime").build())
|
||||||
|
|
@ -37,4 +38,30 @@ public final class Btl {
|
||||||
return map.getOrDefault(paras[0].toString().toUpperCase(), map.get("DEFAULT"));
|
return map.getOrDefault(paras[0].toString().toUpperCase(), map.get("DEFAULT"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public static final Function tsType = new Function() {
|
||||||
|
private final Map<String, Map<String, String>> map = MapUtil.<String, Map<String, String>>builder()
|
||||||
|
.put("DEFAULT", MapUtil.<String, String>builder().put("dataType", "").build())
|
||||||
|
.put("VARCHAR", MapUtil.<String, String>builder().put("dataType", "string").build())
|
||||||
|
.put("CHAR", MapUtil.<String, String>builder().put("dataType", "string").build())
|
||||||
|
.put("LONGTEXT", MapUtil.<String, String>builder().put("dataType", "string").build())
|
||||||
|
.put("TEXT", MapUtil.<String, String>builder().put("dataType", "string").build())
|
||||||
|
.put("BIT", MapUtil.<String, String>builder().put("dataType", "boolean").build())
|
||||||
|
.put("TINYINT", MapUtil.<String, String>builder().put("dataType", "number").build())
|
||||||
|
.put("SMALLINT", MapUtil.<String, String>builder().put("dataType", "number").build())
|
||||||
|
.put("MEDIUMINT", MapUtil.<String, String>builder().put("dataType", "number").build())
|
||||||
|
.put("INT", MapUtil.<String, String>builder().put("dataType", "number").build())
|
||||||
|
.put("BIGINT", MapUtil.<String, String>builder().put("dataType", "string").build())
|
||||||
|
.put("DOUBLE", MapUtil.<String, String>builder().put("dataType", "number").build())
|
||||||
|
.put("DECIMAL", MapUtil.<String, String>builder().put("dataType", "string").build())
|
||||||
|
.put("DATE", MapUtil.<String, String>builder().put("dataType", "string").build())
|
||||||
|
.put("TIME", MapUtil.<String, String>builder().put("dataType", "string").build())
|
||||||
|
.put("DATETIME", MapUtil.<String, String>builder().put("dataType", "string").build())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object call(Object[] paras, Context ctx) {
|
||||||
|
return map.getOrDefault(paras[0].toString().toUpperCase(), map.get("DEFAULT"));
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,12 @@ public class TemplateEngine {
|
||||||
Configuration cfg = Configuration.defaultConfiguration();
|
Configuration cfg = Configuration.defaultConfiguration();
|
||||||
getTemplate_ = new GroupTemplate(LOADER, cfg);
|
getTemplate_ = new GroupTemplate(LOADER, cfg);
|
||||||
getTemplate_.registerFunction("toCamelCase", Btl.toCamelCase);
|
getTemplate_.registerFunction("toCamelCase", Btl.toCamelCase);
|
||||||
|
getTemplate_.registerFunction("toDashCase", Btl.toDashCase);
|
||||||
getTemplate_.registerFunction("upperFirst", Btl.upperFirst);
|
getTemplate_.registerFunction("upperFirst", Btl.upperFirst);
|
||||||
getTemplate_.registerFunction("isBlank", Btl.isBlank);
|
getTemplate_.registerFunction("isBlank", Btl.isBlank);
|
||||||
getTemplate_.registerFunction("subAfter", Btl.subAfter);
|
getTemplate_.registerFunction("subAfter", Btl.subAfter);
|
||||||
getTemplate_.registerFunction("sqlDataTypeMap", Btl.sqlDataTypeMap);
|
getTemplate_.registerFunction("javaType", Btl.javaType);
|
||||||
|
getTemplate_.registerFunction("tsType", Btl.tsType);
|
||||||
getTemplate_.setErrorHandler(TemplateEngine::processException);
|
getTemplate_.setErrorHandler(TemplateEngine::processException);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
getTemplate_ = null;
|
getTemplate_ = null;
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ var entityInstance = entityName + "Entity";
|
||||||
var serviceClass = upperFirst(entityName) + "Service";
|
var serviceClass = upperFirst(entityName) + "Service";
|
||||||
var serviceInstance = entityName + "Service";
|
var serviceInstance = entityName + "Service";
|
||||||
var mapperClass = upperFirst(entityName) + "Mapper";
|
var mapperClass = upperFirst(entityName) + "Mapper";
|
||||||
var baseUrl = table.name;
|
var baseUrl = isBlank(prefix) ? table.name : subAfter(table.name, prefix);
|
||||||
%>
|
%>
|
||||||
package ${basePackage}.controller;
|
package ${basePackage}.${moduleName}.controller;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
@ -16,8 +16,8 @@ import org.springframework.web.bind.annotation.*;
|
||||||
import com.njzscloud.common.core.utils.R;
|
import com.njzscloud.common.core.utils.R;
|
||||||
import com.njzscloud.common.mp.support.PageParam;
|
import com.njzscloud.common.mp.support.PageParam;
|
||||||
import com.njzscloud.common.mp.support.PageResult;
|
import com.njzscloud.common.mp.support.PageResult;
|
||||||
import ${basePackage}.entity.${entityClass};
|
import ${basePackage}.${moduleName}.pojo.entity.${entityClass};
|
||||||
import ${basePackage}.service.${serviceClass};
|
import ${basePackage}.${moduleName}.service.${serviceClass};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${table.comment}
|
* ${table.comment}
|
||||||
|
|
@ -6,9 +6,9 @@ var entityInstance = entityName + "Entity";
|
||||||
var serviceClass = upperFirst(entityName) + "Service";
|
var serviceClass = upperFirst(entityName) + "Service";
|
||||||
var serviceInstance = entityName + "Service";
|
var serviceInstance = entityName + "Service";
|
||||||
var mapperClass = upperFirst(entityName) + "Mapper";
|
var mapperClass = upperFirst(entityName) + "Mapper";
|
||||||
var baseUrl = table.name;
|
var baseUrl = isBlank(prefix) ? table.name : subAfter(table.name, prefix);
|
||||||
%>
|
%>
|
||||||
package ${basePackage}.entity;
|
package ${basePackage}.${moduleName}.entity;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
@ -34,8 +34,8 @@ ${map.importStatement}
|
||||||
public class ${entityClass} {
|
public class ${entityClass} {
|
||||||
|
|
||||||
<%
|
<%
|
||||||
for(column in table.columns){
|
for(column in table.columns) {
|
||||||
var map = sqlDataTypeMap(column.dataType);
|
var map = javaType(column.dataType);
|
||||||
%>
|
%>
|
||||||
/**
|
/**
|
||||||
* ${column.comment}
|
* ${column.comment}
|
||||||
|
|
@ -44,7 +44,7 @@ for(column in table.columns){
|
||||||
@TableId(type = IdType.ASSIGN_ID)
|
@TableId(type = IdType.ASSIGN_ID)
|
||||||
<%}%>
|
<%}%>
|
||||||
<%if(column.name == "creator_id" || column.name == "create_time"){%>
|
<%if(column.name == "creator_id" || column.name == "create_time"){%>
|
||||||
@TableId(type = IdType.ASSIGN_ID)
|
@TableId(fill = FieldFill.INSERT)
|
||||||
<%}else if(column.name == "modifier_id" || column.name == "modify_time"){%>
|
<%}else if(column.name == "modifier_id" || column.name == "modify_time"){%>
|
||||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||||
<%}else if(column.name == "deleted"){%>
|
<%}else if(column.name == "deleted"){%>
|
||||||
|
|
@ -6,13 +6,13 @@ var entityInstance = entityName + "Entity";
|
||||||
var serviceClass = upperFirst(entityName) + "Service";
|
var serviceClass = upperFirst(entityName) + "Service";
|
||||||
var serviceInstance = entityName + "Service";
|
var serviceInstance = entityName + "Service";
|
||||||
var mapperClass = upperFirst(entityName) + "Mapper";
|
var mapperClass = upperFirst(entityName) + "Mapper";
|
||||||
var baseUrl = table.name;
|
var baseUrl = isBlank(prefix) ? table.name : subAfter(table.name, prefix);
|
||||||
%>
|
%>
|
||||||
package ${basePackage}.mapper;
|
package ${basePackage}.${moduleName}.mapper;
|
||||||
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import ${basePackage}.entity.${entityClass};
|
import ${basePackage}.${moduleName}.pojo.entity.${entityClass};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${table.comment}
|
* ${table.comment}
|
||||||
|
|
@ -6,9 +6,9 @@ var entityInstance = entityName + "Entity";
|
||||||
var serviceClass = upperFirst(entityName) + "Service";
|
var serviceClass = upperFirst(entityName) + "Service";
|
||||||
var serviceInstance = entityName + "Service";
|
var serviceInstance = entityName + "Service";
|
||||||
var mapperClass = upperFirst(entityName) + "Mapper";
|
var mapperClass = upperFirst(entityName) + "Mapper";
|
||||||
var baseUrl = table.name;
|
var baseUrl = isBlank(prefix) ? table.name : subAfter(table.name, prefix);
|
||||||
%>
|
%>
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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">
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="${basePackage}.entity.${entityClass}">
|
<mapper namespace="${basePackage}.${moduleName}.pojo.entity.${entityClass}">
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
@ -6,9 +6,9 @@ var entityInstance = entityName + "Entity";
|
||||||
var serviceClass = upperFirst(entityName) + "Service";
|
var serviceClass = upperFirst(entityName) + "Service";
|
||||||
var serviceInstance = entityName + "Service";
|
var serviceInstance = entityName + "Service";
|
||||||
var mapperClass = upperFirst(entityName) + "Mapper";
|
var mapperClass = upperFirst(entityName) + "Mapper";
|
||||||
var baseUrl = table.name;
|
var baseUrl = isBlank(prefix) ? table.name : subAfter(table.name, prefix);
|
||||||
%>
|
%>
|
||||||
package ${basePackage}.service;
|
package ${basePackage}.${moduleName}.service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
@ -20,8 +20,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.njzscloud.common.mp.support.PageParam;
|
import com.njzscloud.common.mp.support.PageParam;
|
||||||
import com.njzscloud.common.mp.support.PageResult;
|
import com.njzscloud.common.mp.support.PageResult;
|
||||||
import ${basePackage}.entity.${entityClass};
|
import ${basePackage}.${moduleName}.pojo.entity.${entityClass};
|
||||||
import ${basePackage}.mapper.${mapperClass};
|
import ${basePackage}.${moduleName}.mapper.${mapperClass};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${table.comment}
|
* ${table.comment}
|
||||||
|
|
@ -1,10 +1,114 @@
|
||||||
{
|
{
|
||||||
"tplName": "Service",
|
"ts": [
|
||||||
"tplCategory": "Service",
|
{
|
||||||
"tpl": {
|
"modelData": {
|
||||||
"dir": "",
|
"moduleName": "",
|
||||||
"filename": "",
|
"subModuleName": ""
|
||||||
"content": "<%\nvar entityName = toCamelCase(isBlank(prefix) ? table.name : subAfter(table.name, prefix));\nvar controllerClass = upperFirst(entityName) + \"Controller\";\nvar entityClass = upperFirst(entityName) + \"Entity\";\nvar entityInstance = entityName + \"Entity\";\nvar serviceClass = upperFirst(entityName) + \"Service\";\nvar serviceInstance = entityName + \"Service\";\nvar mapperClass = upperFirst(entityName) + \"Mapper\";\nvar baseUrl = entityName + \"Service\";\n%>\npackage ${basePackage}.service;\n\nimport lombok.extern.slf4j.Slf4j;\nimport lombok.RequiredArgsConstructor;\nimport org.springframework.stereotype.Service;\nimport com.baomidou.mybatisplus.extension.service.IService;\nimport com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;\nimport com.baomidou.mybatisplus.core.toolkit.Wrappers;\nimport com.njzscloud.common.mp.support.PageParam;\nimport com.njzscloud.common.mp.support.PageResult;\nimport java.util.List;\nimport org.springframework.transaction.annotation.Transactional;\nimport ${basePackage}.entity.${entityClass};\nimport ${basePackage}.mapper.${mapperClass};\n\n/**\n * ${table.comment}\n */\n@Slf4j\n@Service\n@RequiredArgsConstructor\npublic class ${serviceClass} extends ServiceImpl<${mapperClass}, ${entityClass}> implements IService<${entityClass}> {\n\n /**\n * 新增\n */\n public void add(${entityClass} ${entityInstance}) {\n this.save(${entityInstance});\n }\n\n /**\n * 修改\n */\n public void modify(${entityClass} ${entityInstance}) {\n this.updateById(${entityInstance});\n }\n\n /**\n * 删除\n */\n @Transactional(rollbackFor = Exception.class)\n public void del(List<Long> ids) {\n this.removeBatchByIds(ids);\n }\n\n /**\n * 详情\n */\n public ${entityClass} detail(Long id) {\n return this.getById(id);\n }\n\n /**\n * 分页查询\n */\n public PageResult<${entityClass}> paging(PageParam pageParam, ${entityClass} ${entityInstance}) {\n return PageResult.of(this.page(pageParam.toPage(), Wrappers.<${entityClass}>query(${entityInstance})));\n }\n}\n"
|
},
|
||||||
},
|
"tplName": "page.vue",
|
||||||
"modelData": {}
|
"tpl": {
|
||||||
|
"dir": "${moduleName}<%if(subModuleName != null){%>/${subModuleName}<%}%>",
|
||||||
|
"filename": "${pageVueName}",
|
||||||
|
"content": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"modelData": {
|
||||||
|
"moduleName": "",
|
||||||
|
"subModuleName": ""
|
||||||
|
},
|
||||||
|
"tplName": "form.vue",
|
||||||
|
"tpl": {
|
||||||
|
"dir": "${moduleName}<%if(subModuleName != null){%>/${subModuleName}<%}%>",
|
||||||
|
"filename": "${formVueName}",
|
||||||
|
"content": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"modelData": {
|
||||||
|
"moduleName": "",
|
||||||
|
"subModuleName": ""
|
||||||
|
},
|
||||||
|
"tplName": "page.ts",
|
||||||
|
"tpl": {
|
||||||
|
"dir": "${moduleName}<%if(subModuleName != null){%>/${subModuleName}<%}%>",
|
||||||
|
"filename": "${pageTsName}",
|
||||||
|
"content": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"modelData": {
|
||||||
|
"moduleName": "",
|
||||||
|
"subModuleName": ""
|
||||||
|
},
|
||||||
|
"tplName": "api.ts",
|
||||||
|
"tpl": {
|
||||||
|
"dir": "${moduleName}<%if(subModuleName != null){%>/${subModuleName}<%}%>",
|
||||||
|
"filename": "${apiTsName}",
|
||||||
|
"content": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"modelData": {
|
||||||
|
"moduleName": "",
|
||||||
|
"subModuleName": ""
|
||||||
|
},
|
||||||
|
"tplName": "d.ts",
|
||||||
|
"tpl": {
|
||||||
|
"dir": "${moduleName}<%if(subModuleName != null){%>/${subModuleName}<%}%>",
|
||||||
|
"filename": "${dTsName}",
|
||||||
|
"content": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"java": [
|
||||||
|
{
|
||||||
|
"modelData": {
|
||||||
|
"basePackage": "",
|
||||||
|
"moduleName": ""
|
||||||
|
},
|
||||||
|
"tplName": "entity.java",
|
||||||
|
"tpl": {
|
||||||
|
"dir": "pojo/entity",
|
||||||
|
"filename": "${upperFirst(toCamelCase(isBlank(prefix) ? table.name : subAfter(table.name, prefix)))}Entity.java",
|
||||||
|
"content": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"modelData": {},
|
||||||
|
"tplName": "mapper.java",
|
||||||
|
"tpl": {
|
||||||
|
"dir": "mapper",
|
||||||
|
"filename": "${upperFirst(toCamelCase(isBlank(prefix) ? table.name : subAfter(table.name, prefix)))}Mapper.java",
|
||||||
|
"content": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"modelData": {},
|
||||||
|
"tplName": "mapper.xml",
|
||||||
|
"tpl": {
|
||||||
|
"dir": "",
|
||||||
|
"filename": "${upperFirst(toCamelCase(isBlank(prefix) ? table.name : subAfter(table.name, prefix)))}Mapper.xml",
|
||||||
|
"content": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"modelData": {},
|
||||||
|
"tplName": "service.java",
|
||||||
|
"tpl": {
|
||||||
|
"dir": "service",
|
||||||
|
"filename": "${upperFirst(toCamelCase(isBlank(prefix) ? table.name : subAfter(table.name, prefix)))}Service.java",
|
||||||
|
"content": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"modelData": {},
|
||||||
|
"tplName": "controller.java",
|
||||||
|
"tpl": {
|
||||||
|
"dir": "controller",
|
||||||
|
"filename": "${upperFirst(toCamelCase(isBlank(prefix) ? table.name : subAfter(table.name, prefix)))}Controller.java",
|
||||||
|
"content": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
{
|
|
||||||
"id": "1947531036271337474",
|
|
||||||
"tpl": {
|
|
||||||
"dir": "",
|
|
||||||
"filename": "",
|
|
||||||
"content": "<%\nvar entityName = toCamelCase(isBlank(prefix) ? table.name : subAfter(table.name, prefix));\nvar controllerClass = upperFirst(entityName) + \"Controller\";\nvar entityClass = upperFirst(entityName) + \"Entity\";\nvar entityInstance = entityName + \"Entity\";\nvar serviceClass = upperFirst(entityName) + \"Service\";\nvar serviceInstance = entityName + \"Service\";\nvar baseUrl = entityName + \"Service\";\n%>\npackage ${basePackage}.entity;\n\nimport lombok.Getter;\nimport lombok.Setter;\nimport lombok.experimental.Accessors;\nimport com.baomidou.mybatisplus.annotation.*;\nimport lombok.ToString;\n<%for(column in table.columns) {\n var map = sqlDataTypeMap(column.dataType);\n%>\n<%if(!isBlank(map.importStatement)){%>\n${map.importStatement}\n<%}%>\n<%}%>\n\n/**\n * ${table.comment}\n */\n@Getter\n@Setter\n@ToString\n@Accessors(chain = true)\n@TableName(\"${table.name}\")\npublic class ${entityClass} {\n\n<%\nfor(column in table.columns){\n var map = sqlDataTypeMap(column.dataType);\n%>\n /**\n * ${column.comment}\n */\n <%if(column.primaryKey){%>\n @TableId(type = IdType.ASSIGN_ID)\n <%}%>\n <%if(column.name == \"creator_id\" || column.name == \"create_time\"){%>\n @TableId(type = IdType.ASSIGN_ID)\n <%}else if(column.name == \"modifier_id\" || column.name == \"modify_time\"){%>\n @TableField(fill = FieldFill.INSERT_UPDATE)\n <%}else if(column.name == \"deleted\"){%>\n @TableLogic\n <%}%>\n private ${map.dataType} ${toCamelCase(column.name)};\n\n<%}%>\n}\n"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
<%
|
||||||
|
var ulc = isBlank(prefix) ? table.name : subAfter(table.name, prefix);
|
||||||
|
var lcc = toCamelCase(ulc);
|
||||||
|
var ucc = upperFirst(lcc);
|
||||||
|
var dc = toDashCase(lcc);
|
||||||
|
|
||||||
|
var pageVueName = ucc + "vue";
|
||||||
|
var formVueName = ucc + "Form.vue";
|
||||||
|
var pageTsName = dc + ".ts";
|
||||||
|
var apiTsName = dc + "-api.ts";
|
||||||
|
var dTsName = dc + ".d.ts";
|
||||||
|
%>
|
||||||
|
import {
|
||||||
|
get,
|
||||||
|
post
|
||||||
|
} from '@/common/utils/http-util.ts'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
paging(data: ${ucc}Types.Search${ucc}Param) {
|
||||||
|
return get<G.PageResult<${ucc}Types.Search${ucc}Result>>('/${ulc}/paging', data)
|
||||||
|
},
|
||||||
|
detail(id: string) {
|
||||||
|
return get<${ucc}Types.Search${ucc}Result>('/${ulc}/detail', {id})
|
||||||
|
},
|
||||||
|
add(data: ${ucc}Types.Add${ucc}Param) {
|
||||||
|
return post('/${ulc}/add', data)
|
||||||
|
},
|
||||||
|
modify(data: ${ucc}Types.Modify${ucc}Param) {
|
||||||
|
return post('/${ulc}/modify', data)
|
||||||
|
},
|
||||||
|
del(ids: string[]) {
|
||||||
|
return post('/${ulc}/del', ids)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
<%
|
||||||
|
var ulc = isBlank(prefix) ? table.name : subAfter(table.name, prefix);
|
||||||
|
var lcc = toCamelCase(ulc);
|
||||||
|
var ucc = upperFirst(lcc);
|
||||||
|
var dc = toDashCase(lcc);
|
||||||
|
|
||||||
|
var pageVueName = ucc + "vue";
|
||||||
|
var formVueName = ucc + "Form.vue";
|
||||||
|
var pageTsName = dc + ".ts";
|
||||||
|
var apiTsName = dc + "-api.ts";
|
||||||
|
var dTsName = dc + ".d.ts";
|
||||||
|
%>
|
||||||
|
export {}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
namespace ${ucc}Types {
|
||||||
|
interface Search${ucc}Param extends G.PageParam {
|
||||||
|
<%
|
||||||
|
for(column in table.columns) {
|
||||||
|
var map = tsType(column.dataType);
|
||||||
|
%>
|
||||||
|
// ${column.comment}
|
||||||
|
${toCamelCase(column.name)}?: ${map.dataType}
|
||||||
|
<%}%>
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Search${ucc}Result {
|
||||||
|
<%
|
||||||
|
for(column in table.columns) {
|
||||||
|
var map = tsType(column.dataType);
|
||||||
|
%>
|
||||||
|
// ${column.comment}
|
||||||
|
${toCamelCase(column.name)}?: ${map.dataType}
|
||||||
|
<%}%>
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Add${ucc}Param {
|
||||||
|
<%
|
||||||
|
for(column in table.columns) {
|
||||||
|
var map = tsType(column.dataType);
|
||||||
|
%>
|
||||||
|
// ${column.comment}
|
||||||
|
${toCamelCase(column.name)}?: ${map.dataType}
|
||||||
|
<%}%>
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Modify${ucc}Param {
|
||||||
|
<%
|
||||||
|
for(column in table.columns) {
|
||||||
|
var map = tsType(column.dataType);
|
||||||
|
%>
|
||||||
|
// ${column.comment}
|
||||||
|
${toCamelCase(column.name)}?: ${map.dataType}
|
||||||
|
<%}%>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,100 @@
|
||||||
|
<%
|
||||||
|
var ulc = isBlank(prefix) ? table.name : subAfter(table.name, prefix);
|
||||||
|
var lcc = toCamelCase(ulc);
|
||||||
|
var ucc = upperFirst(lcc);
|
||||||
|
var dc = toDashCase(lcc);
|
||||||
|
|
||||||
|
var pageVueName = ucc + "vue";
|
||||||
|
var formVueName = ucc + "Form.vue";
|
||||||
|
var pageTsName = dc + ".ts";
|
||||||
|
var apiTsName = dc + "-api.ts";
|
||||||
|
var dTsName = dc + ".d.ts";
|
||||||
|
%>
|
||||||
|
<template>
|
||||||
|
<ElDialog v-model="showDialog"
|
||||||
|
:close-on-click-modal="false"
|
||||||
|
destroy-on-close
|
||||||
|
width="25vw">
|
||||||
|
<ElForm :model="${lcc}FormData"
|
||||||
|
class="${dc}-form"
|
||||||
|
label-width="auto">
|
||||||
|
<%
|
||||||
|
for(column in table.columns) {
|
||||||
|
var map = tsType(column.dataType);
|
||||||
|
%>
|
||||||
|
<ElFormItem label="${column.comment}">
|
||||||
|
<ElInput
|
||||||
|
v-model="${lcc}FormData.${toCamelCase(column.name)}"
|
||||||
|
:disabled="status === 'view'"
|
||||||
|
placeholder="${column.comment}"/>
|
||||||
|
</ElFormItem>
|
||||||
|
<%}%>
|
||||||
|
</ElForm>
|
||||||
|
<template #footer>
|
||||||
|
<ElButton @click="showDialog = false">{{ status === 'view' ? '关闭' : '取消' }}</ElButton>
|
||||||
|
<ElButton v-if="status !== 'view'" :loading="submiting" type="primary" @click="submitHandler">提交</ElButton>
|
||||||
|
</template>
|
||||||
|
</ElDialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import ${ucc}Api from '@/pages/${moduleName}<%if(subModuleName != null){%>/${subModuleName}<%}%>/${apiTsName}'
|
||||||
|
import Strings from '@/common/utils/strings.ts'
|
||||||
|
import { ElMessage } from 'element-plus'
|
||||||
|
|
||||||
|
const emits = defineEmits(['editSucc'])
|
||||||
|
const showDialog = ref(false)
|
||||||
|
const submiting = ref(false)
|
||||||
|
const status = ref<'add' | 'view' | 'modify'>('add')
|
||||||
|
|
||||||
|
|
||||||
|
const ${lcc}FormData = reactive<${ucc}Types.Search${ucc}Result>({})
|
||||||
|
|
||||||
|
function submitHandler() {
|
||||||
|
if (status.value === 'view') return
|
||||||
|
submiting.value = true
|
||||||
|
if (${lcc}FormData.id != null) {
|
||||||
|
${ucc}Api.modify(${lcc}FormData)
|
||||||
|
.then(() => {
|
||||||
|
ElMessage.success('修改成功')
|
||||||
|
emits('editSucc')
|
||||||
|
showDialog.value = false
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
submiting.value = false
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
${ucc}Api.add(${lcc}FormData)
|
||||||
|
.then(() => {
|
||||||
|
ElMessage.success('添加成功')
|
||||||
|
emits('editSucc')
|
||||||
|
showDialog.value = false
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
submiting.value = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
open(data: ${ucc}Types.Search${ucc}Result = {}) {
|
||||||
|
showDialog.value = true
|
||||||
|
if (!Strings.isBlank(data.id)) {
|
||||||
|
status.value = 'modify'
|
||||||
|
${ucc}Api.detail(data.id!)
|
||||||
|
.then(res => {
|
||||||
|
Object.assign(${lcc}FormData, res.data)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
status.value = 'add'
|
||||||
|
Object.assign(${lcc}FormData, {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="stylus" scoped>
|
||||||
|
.${dc}-form {
|
||||||
|
padding 20px
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
<%
|
||||||
|
var ulc = isBlank(prefix) ? table.name : subAfter(table.name, prefix);
|
||||||
|
var lcc = toCamelCase(ulc);
|
||||||
|
var ucc = upperFirst(lcc);
|
||||||
|
var dc = toDashCase(lcc);
|
||||||
|
|
||||||
|
var pageVueName = ucc + "vue";
|
||||||
|
var formVueName = ucc + "Form.vue";
|
||||||
|
var pageTsName = dc + ".ts";
|
||||||
|
var apiTsName = dc + "-api.ts";
|
||||||
|
var dTsName = dc + ".d.ts";
|
||||||
|
%>
|
||||||
|
export default {
|
||||||
|
component: () => import('@/pages/${moduleName}<%if(subModuleName != null){%>/${subModuleName}<%}%>/${pageVueName}'),
|
||||||
|
} as RouterTypes.RouteConfig
|
||||||
|
|
@ -0,0 +1,207 @@
|
||||||
|
<%
|
||||||
|
var ulc = isBlank(prefix) ? table.name : subAfter(table.name, prefix);
|
||||||
|
var lcc = toCamelCase(ulc);
|
||||||
|
var ucc = upperFirst(lcc);
|
||||||
|
var dc = toDashCase(lcc);
|
||||||
|
|
||||||
|
var pageVueName = ucc + "vue";
|
||||||
|
var formVueName = ucc + "Form.vue";
|
||||||
|
var pageTsName = dc + ".ts";
|
||||||
|
var apiTsName = dc + "-api.ts";
|
||||||
|
var dTsName = dc + ".d.ts";
|
||||||
|
%>
|
||||||
|
<template>
|
||||||
|
<Page>
|
||||||
|
<ElForm v-show="showSearchForm" inline @submit.prevent="paging">
|
||||||
|
<%
|
||||||
|
for(column in table.columns) {
|
||||||
|
var map = tsType(column.dataType);
|
||||||
|
%>
|
||||||
|
<ElFormItem label="${column.comment}">
|
||||||
|
<ElInput
|
||||||
|
v-model="searchForm.${toCamelCase(column.name)}"
|
||||||
|
placeholder="${column.comment}"/>
|
||||||
|
</ElFormItem>
|
||||||
|
<%}%>
|
||||||
|
<ElFormItem>
|
||||||
|
<ElButton :icon="elIcons.Search" :loading="searching" native-type="submit" type="primary">搜索</ElButton>
|
||||||
|
<ElButton :icon="elIcons.Refresh" :loading="searching" @click="reset">重置</ElButton>
|
||||||
|
</ElFormItem>
|
||||||
|
</ElForm>
|
||||||
|
|
||||||
|
<div class="tool-bar">
|
||||||
|
<ElButton :icon="elIcons.Plus" type="primary" @click="addHandler">新建</ElButton>
|
||||||
|
<ElButton :icon="elIcons.Filter" type="default" @click="showSearchForm = !showSearchForm"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ElTable v-loading="searching" :data="tableData"
|
||||||
|
cell-class-name="table-cell"
|
||||||
|
class="table-list"
|
||||||
|
empty-text="暂无数据"
|
||||||
|
header-row-class-name="table-header"
|
||||||
|
row-key="id">
|
||||||
|
<%
|
||||||
|
for(column in table.columns) {
|
||||||
|
var map = tsType(column.dataType);
|
||||||
|
%>
|
||||||
|
<ElTableColumn label="${column.comment}" prop="${toCamelCase(column.name)}"/>
|
||||||
|
<%}%>
|
||||||
|
<ElTableColumn label="操作" width="180">
|
||||||
|
<template #default="scope">
|
||||||
|
<div class="action-btn">
|
||||||
|
<ElPopconfirm
|
||||||
|
confirm-button-text="是"
|
||||||
|
cancel-button-text="否"
|
||||||
|
confirm-button-type="danger"
|
||||||
|
cancel-button-type="primary"
|
||||||
|
placement="top"
|
||||||
|
title="是否删除当前数据?"
|
||||||
|
width="180"
|
||||||
|
@confirm="delHandler(scope)">
|
||||||
|
<template #reference>
|
||||||
|
<ElButton text type="danger" :loading="deling">删除</ElButton>
|
||||||
|
</template>
|
||||||
|
</ElPopconfirm>
|
||||||
|
<ElButton text type="primary" @click="modifyHandler(scope)">修改</ElButton>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</ElTableColumn>
|
||||||
|
</ElTable>
|
||||||
|
<ElPagination
|
||||||
|
class="pagination"
|
||||||
|
layout="prev, pager, next"
|
||||||
|
:page-size="pagination.size"
|
||||||
|
:total="pagination.total"
|
||||||
|
@change="pageChangeHandler"/>
|
||||||
|
<${ucc}Form ref="${lcc}Form" @edit-succ="paging"/>
|
||||||
|
|
||||||
|
</Page>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import ${ucc}Api from '@/pages/${moduleName}<%if(subModuleName != null){%>/${subModuleName}<%}%>/${apiTsName}'
|
||||||
|
import ${ucc}Form from '@/pages/${moduleName}<%if(subModuleName != null){%>/${subModuleName}<%}%>/${formVueName}'
|
||||||
|
import Page from '@/components/page/Page.vue'
|
||||||
|
import { elIcons } from '@/common/element/element.ts'
|
||||||
|
|
||||||
|
const tableData = ref<${ucc}Types.Search${ucc}Result[]>([])
|
||||||
|
const searchForm = reactive<${ucc}Types.Search${ucc}Param>({
|
||||||
|
current: 1,
|
||||||
|
size: 20,
|
||||||
|
})
|
||||||
|
const searching = ref(false)
|
||||||
|
const deling = ref(false)
|
||||||
|
const showSearchForm = ref(true)
|
||||||
|
const ${lcc}FormIns = useTemplateRef<InstanceType<typeof ${ucc}Form>>('${lcc}Form')
|
||||||
|
const pagination = reactive<G.Pagination>({
|
||||||
|
total: 0,
|
||||||
|
current: 1,
|
||||||
|
size: 1,
|
||||||
|
})
|
||||||
|
function pageChangeHandler(currentPage: number, pageSize: number) {
|
||||||
|
searchForm.current = currentPage
|
||||||
|
searchForm.size = pageSize
|
||||||
|
paging()
|
||||||
|
}
|
||||||
|
function showDialog(data?: ${ucc}Types.Search${ucc}Result) {
|
||||||
|
${lcc}FormIns.value?.open(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
function delHandler({row}: { row: ${ucc}Types.Search${ucc}Result }) {
|
||||||
|
deling.value = true
|
||||||
|
${ucc}Api.del([ row.id! ])
|
||||||
|
.then(() => {
|
||||||
|
ElMessage.success('删除成功')
|
||||||
|
paging()
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
deling.value = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function modifyHandler({row}: { row: ${ucc}Types.Search${ucc}Result }) {
|
||||||
|
showDialog(row)
|
||||||
|
}
|
||||||
|
|
||||||
|
function addHandler() {
|
||||||
|
showDialog()
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
Object.assign(searchForm, {})
|
||||||
|
paging()
|
||||||
|
}
|
||||||
|
|
||||||
|
function paging() {
|
||||||
|
searching.value = true
|
||||||
|
${ucc}Api.paging(searchForm)
|
||||||
|
.then(res => {
|
||||||
|
tableData.value = res.data?.records ?? []
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
searching.value = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
onMounted(() => {
|
||||||
|
paging()
|
||||||
|
})
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="stylus" scoped>
|
||||||
|
.table-list {
|
||||||
|
flex 1;
|
||||||
|
width 100%
|
||||||
|
|
||||||
|
:deep(.table-header) {
|
||||||
|
color #454C59
|
||||||
|
|
||||||
|
th {
|
||||||
|
background-color #EDF1F7
|
||||||
|
font-weight 500
|
||||||
|
position relative
|
||||||
|
|
||||||
|
& > div {
|
||||||
|
display flex
|
||||||
|
gap 5px
|
||||||
|
align-items center
|
||||||
|
}
|
||||||
|
|
||||||
|
&:not(:first-child) > div::before {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 1px;
|
||||||
|
width: 1px;
|
||||||
|
background-color: #D3D7DE;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
content: "";
|
||||||
|
height 50%
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.table-cell) {
|
||||||
|
color #2F3540
|
||||||
|
}
|
||||||
|
.action-btn {
|
||||||
|
width 100%
|
||||||
|
display flex
|
||||||
|
flex-wrap wrap
|
||||||
|
|
||||||
|
& > button {
|
||||||
|
margin 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.tool-bar {
|
||||||
|
display flex
|
||||||
|
justify-content space-between
|
||||||
|
margin 0 0 20px 0
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination {
|
||||||
|
justify-content: end;
|
||||||
|
margin: 8px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
@ -140,6 +140,7 @@ public class TaskHandle implements Runnable {
|
||||||
taskStatus = TaskStatus.Error;
|
taskStatus = TaskStatus.Error;
|
||||||
taskScheduleRecodeService.end(this);
|
taskScheduleRecodeService.end(this);
|
||||||
log.error("任务执行失败:{},任务处理函数不存在:{}", taskName, fn);
|
log.error("任务执行失败:{},任务处理函数不存在:{}", taskName, fn);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
this.logInfo("开始执行");
|
this.logInfo("开始执行");
|
||||||
boolean exec = fnHandle.exec();
|
boolean exec = fnHandle.exec();
|
||||||
|
|
@ -147,6 +148,8 @@ public class TaskHandle implements Runnable {
|
||||||
taskStatus = exec ? TaskStatus.Completed : TaskStatus.Error;
|
taskStatus = exec ? TaskStatus.Completed : TaskStatus.Error;
|
||||||
taskScheduleRecodeService.end(this);
|
taskScheduleRecodeService.end(this);
|
||||||
this.logInfo("执行完成");
|
this.logInfo("执行完成");
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("错误:任务执行失败", e);
|
||||||
} finally {
|
} finally {
|
||||||
ThreadContext.remove("CURRENT_TASK");
|
ThreadContext.remove("CURRENT_TASK");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue