mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-17 20:45:06 +08:00
增加 service 模板
This commit is contained in:
@ -8,11 +8,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
@EnableAdminServer // TODO 芋艿:需要迁移出去
|
||||
public class DashboardApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 设置读取的配置文件
|
||||
System.setProperty("spring.config.name", "application,db");
|
||||
// static {
|
||||
// // 设置读取的配置文件
|
||||
// System.setProperty("spring.config.name", "application,db");
|
||||
// }
|
||||
|
||||
// 启动 Spring Boot
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DashboardApplication.class, args);
|
||||
}
|
||||
|
||||
|
@ -3,9 +3,11 @@ package cn.iocoder.dashboard.modules.system.controller.dept.vo.dept;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
@ApiModel("部门创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class SysDeptCreateReqVO extends SysDeptBaseVO {
|
||||
}
|
||||
|
@ -10,14 +10,16 @@ import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolCodegenColumnDO;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolCodegenTableDO;
|
||||
import cn.iocoder.dashboard.util.collection.CollectionUtils;
|
||||
import cn.iocoder.dashboard.util.date.DateUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.hutool.core.text.CharSequenceUtil.*;
|
||||
|
||||
/**
|
||||
* 代码生成的引擎,用于具体生成代码
|
||||
* 目前基于 {@link org.apache.velocity.app.Velocity} 模板引擎实现
|
||||
@ -49,7 +51,7 @@ public class ToolCodegenEngine {
|
||||
|
||||
private void initGlobalBindingMap() {
|
||||
// 全局配置
|
||||
globalBindingMap.put("basePackage", "cn.iocoder.dashboard.modules"); // TODO 基础包
|
||||
globalBindingMap.put("basePackage", "cn.iocoder.dashboard.modules"); // TODO 基础包, 抽成参数
|
||||
// 全局 Java Bean
|
||||
globalBindingMap.put("PageResultClassName", PageResult.class.getName());
|
||||
globalBindingMap.put("DateUtilsClassName", DateUtils.class.getName());
|
||||
@ -64,16 +66,21 @@ public class ToolCodegenEngine {
|
||||
|
||||
public void execute(ToolCodegenTableDO table, List<ToolCodegenColumnDO> columns) {
|
||||
// 创建 bindingMap
|
||||
Map<String, Object> bindingMap = new HashMap<>();
|
||||
Map<String, Object> bindingMap = new HashMap<>(globalBindingMap);
|
||||
bindingMap.put("table", table);
|
||||
bindingMap.put("columns", columns);
|
||||
bindingMap.put("hasDateColumn", columns.stream().anyMatch(codegenColumnDO ->
|
||||
codegenColumnDO.getJavaType().equals(Date.class.getSimpleName())));
|
||||
bindingMap.putAll(globalBindingMap);
|
||||
bindingMap.put("primaryColumn", CollectionUtils.findFirst(columns, ToolCodegenColumnDO::getPrimaryKey));
|
||||
bindingMap.put("simpleClassName", upperFirst(toCamelCase(subAfter( // 去掉第一个驼峰,例如说 SysUser 去掉后是 User
|
||||
toUnderlineCase(table.getClassName()), '_', false))));
|
||||
// 执行生成
|
||||
// String result = templateEngine.getTemplate("codegen/dal/do.vm").render(bindingMap);
|
||||
// String result = templateEngine.getTemplate("codegen/dal/mapper.vm").render(bindingMap);
|
||||
String result = templateEngine.getTemplate("codegen/controller/vo/pageReqVO.vm").render(bindingMap);
|
||||
// String result = templateEngine.getTemplate("codegen/controller/vo/pageReqVO.vm").render(bindingMap);
|
||||
// String result = templateEngine.getTemplate("codegen/controller/vo/baseVO.vm").render(bindingMap);
|
||||
// String result = templateEngine.getTemplate("codegen/controller/vo/createReqVO.vm").render(bindingMap);
|
||||
// String result = templateEngine.getTemplate("codegen/controller/vo/updateReqVO.vm").render(bindingMap);
|
||||
// String result = templateEngine.getTemplate("codegen/controller/vo/respVO.vm").render(bindingMap);
|
||||
String result = templateEngine.getTemplate("codegen/service/service.vm").render(bindingMap);
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
|
@ -86,6 +86,13 @@ public class CollectionUtils {
|
||||
return !CollectionUtil.isEmpty(from) ? from.get(0) : null;
|
||||
}
|
||||
|
||||
public static <T> T findFirst(List<T> from, Predicate<T> predicate) {
|
||||
if (CollUtil.isEmpty(from)) {
|
||||
return null;
|
||||
}
|
||||
return from.stream().filter(predicate).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public static <T> void addIfNotNull(Collection<T> coll, T item) {
|
||||
if (item == null) {
|
||||
return;
|
||||
|
Reference in New Issue
Block a user