mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 02:08:43 +08:00 
			
		
		
		
	增加 service 模板
This commit is contained in:
		| @@ -1,31 +0,0 @@ | |||||||
| package com.ruoyi.generator.util; |  | ||||||
|  |  | ||||||
| import java.util.Properties; |  | ||||||
|  |  | ||||||
| import org.apache.velocity.app.Velocity; |  | ||||||
| import com.ruoyi.common.constant.Constants; |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * VelocityEngine工厂 |  | ||||||
|  * |  | ||||||
|  * @author RuoYi |  | ||||||
|  */ |  | ||||||
| public class VelocityInitializer { |  | ||||||
|     /** |  | ||||||
|      * 初始化vm方法 |  | ||||||
|      */ |  | ||||||
|     public static void initVelocity() { |  | ||||||
|         Properties p = new Properties(); |  | ||||||
|         try { |  | ||||||
|             // 加载classpath目录下的vm文件 |  | ||||||
|             p.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); |  | ||||||
|             // 定义字符集 |  | ||||||
|             p.setProperty(Velocity.ENCODING_DEFAULT, Constants.UTF8); |  | ||||||
|             p.setProperty(Velocity.OUTPUT_ENCODING, Constants.UTF8); |  | ||||||
|             // 初始化Velocity引擎,指定配置Properties |  | ||||||
|             Velocity.init(p); |  | ||||||
|         } catch (Exception e) { |  | ||||||
|             throw new RuntimeException(e); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,85 +0,0 @@ | |||||||
| package ${packageName}.domain; |  | ||||||
|  |  | ||||||
| #foreach ($import in $importList) |  | ||||||
| import ${import}; |  | ||||||
| #end |  | ||||||
| import org.apache.commons.lang3.builder.ToStringBuilder; |  | ||||||
| import org.apache.commons.lang3.builder.ToStringStyle; |  | ||||||
| import com.ruoyi.common.annotation.Excel; |  | ||||||
| #if($table.crud) |  | ||||||
| import com.ruoyi.common.core.domain.BaseEntity; |  | ||||||
| #elseif($table.tree) |  | ||||||
| import com.ruoyi.common.core.domain.TreeEntity; |  | ||||||
| #end |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * ${functionName}对象 ${tableName} |  | ||||||
|  *  |  | ||||||
|  * @author ${author} |  | ||||||
|  * @date ${datetime} |  | ||||||
|  */ |  | ||||||
| #if($table.crud) |  | ||||||
| #set($Entity="BaseEntity") |  | ||||||
| #elseif($table.tree) |  | ||||||
| #set($Entity="TreeEntity") |  | ||||||
| #end |  | ||||||
| public class ${ClassName} extends ${Entity} |  | ||||||
| { |  | ||||||
|     private static final long serialVersionUID = 1L; |  | ||||||
|  |  | ||||||
| #foreach ($column in $columns) |  | ||||||
| #if(!$table.isSuperColumn($column.javaField)) |  | ||||||
|     /** $column.columnComment */ |  | ||||||
| #if($column.list) |  | ||||||
| #set($parentheseIndex=$column.columnComment.indexOf("(")) |  | ||||||
| #if($parentheseIndex != -1) |  | ||||||
| #set($comment=$column.columnComment.substring(0, $parentheseIndex)) |  | ||||||
| #else |  | ||||||
| #set($comment=$column.columnComment) |  | ||||||
| #end |  | ||||||
| #if($parentheseIndex != -1) |  | ||||||
|     @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") |  | ||||||
| #elseif($column.javaType == 'Date') |  | ||||||
|     @JsonFormat(pattern = "yyyy-MM-dd") |  | ||||||
|     @Excel(name = "${comment}", width = 30, dateFormat = "yyyy-MM-dd") |  | ||||||
| #else |  | ||||||
|     @Excel(name = "${comment}") |  | ||||||
| #end |  | ||||||
| #end |  | ||||||
|     private $column.javaType $column.javaField; |  | ||||||
|  |  | ||||||
| #end |  | ||||||
| #end |  | ||||||
| #foreach ($column in $columns) |  | ||||||
| #if(!$table.isSuperColumn($column.javaField)) |  | ||||||
| #if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]")) |  | ||||||
| #set($AttrName=$column.javaField) |  | ||||||
| #else |  | ||||||
| #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) |  | ||||||
| #end |  | ||||||
|     public void set${AttrName}($column.javaType $column.javaField)  |  | ||||||
|     { |  | ||||||
|         this.$column.javaField = $column.javaField; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public $column.javaType get${AttrName}()  |  | ||||||
|     { |  | ||||||
|         return $column.javaField; |  | ||||||
|     } |  | ||||||
| #end |  | ||||||
| #end |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     public String toString() { |  | ||||||
|         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) |  | ||||||
| #foreach ($column in $columns) |  | ||||||
| #if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]")) |  | ||||||
| #set($AttrName=$column.javaField) |  | ||||||
| #else |  | ||||||
| #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) |  | ||||||
| #end |  | ||||||
|             .append("${column.javaField}", get${AttrName}()) |  | ||||||
| #end |  | ||||||
|             .toString(); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,61 +0,0 @@ | |||||||
| package ${packageName}.mapper; |  | ||||||
|  |  | ||||||
| import java.util.List; |  | ||||||
| import ${packageName}.domain.${ClassName}; |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * ${functionName}Mapper接口 |  | ||||||
|  *  |  | ||||||
|  * @author ${author} |  | ||||||
|  * @date ${datetime} |  | ||||||
|  */ |  | ||||||
| public interface ${ClassName}Mapper  |  | ||||||
| { |  | ||||||
|     /** |  | ||||||
|      * 查询${functionName} |  | ||||||
|      *  |  | ||||||
|      * @param ${pkColumn.javaField} ${functionName}ID |  | ||||||
|      * @return ${functionName} |  | ||||||
|      */ |  | ||||||
|     public ${ClassName} select${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}); |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 查询${functionName}列表 |  | ||||||
|      *  |  | ||||||
|      * @param ${className} ${functionName} |  | ||||||
|      * @return ${functionName}集合 |  | ||||||
|      */ |  | ||||||
|     public List<${ClassName}> select${ClassName}List(${ClassName} ${className}); |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 新增${functionName} |  | ||||||
|      *  |  | ||||||
|      * @param ${className} ${functionName} |  | ||||||
|      * @return 结果 |  | ||||||
|      */ |  | ||||||
|     public int insert${ClassName}(${ClassName} ${className}); |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 修改${functionName} |  | ||||||
|      *  |  | ||||||
|      * @param ${className} ${functionName} |  | ||||||
|      * @return 结果 |  | ||||||
|      */ |  | ||||||
|     public int update${ClassName}(${ClassName} ${className}); |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 删除${functionName} |  | ||||||
|      *  |  | ||||||
|      * @param ${pkColumn.javaField} ${functionName}ID |  | ||||||
|      * @return 结果 |  | ||||||
|      */ |  | ||||||
|     public int delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}); |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 批量删除${functionName} |  | ||||||
|      *  |  | ||||||
|      * @param ${pkColumn.javaField}s 需要删除的数据ID |  | ||||||
|      * @return 结果 |  | ||||||
|      */ |  | ||||||
|     public int delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s); |  | ||||||
| } |  | ||||||
| @@ -8,11 +8,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; | |||||||
| @EnableAdminServer // TODO 芋艿:需要迁移出去 | @EnableAdminServer // TODO 芋艿:需要迁移出去 | ||||||
| public class DashboardApplication { | public class DashboardApplication { | ||||||
|  |  | ||||||
|     public static void main(String[] args) { | //    static { | ||||||
|         // 设置读取的配置文件 | //        // 设置读取的配置文件 | ||||||
|         System.setProperty("spring.config.name", "application,db"); | //        System.setProperty("spring.config.name", "application,db"); | ||||||
|  | //    } | ||||||
|  |  | ||||||
|         // 启动 Spring Boot |     public static void main(String[] args) { | ||||||
|         SpringApplication.run(DashboardApplication.class, 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 io.swagger.annotations.ApiModel; | ||||||
| import lombok.Data; | import lombok.Data; | ||||||
| import lombok.EqualsAndHashCode; | import lombok.EqualsAndHashCode; | ||||||
|  | import lombok.ToString; | ||||||
|  |  | ||||||
| @ApiModel("部门创建 Request VO") | @ApiModel("部门创建 Request VO") | ||||||
| @Data | @Data | ||||||
| @EqualsAndHashCode(callSuper = true) | @EqualsAndHashCode(callSuper = true) | ||||||
|  | @ToString(callSuper = true) | ||||||
| public class SysDeptCreateReqVO extends SysDeptBaseVO { | 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.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.ToolCodegenColumnDO; | ||||||
| import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolCodegenTableDO; | 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 cn.iocoder.dashboard.util.date.DateUtils; | ||||||
| import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||||
|  |  | ||||||
| import java.util.Date; |  | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
|  |  | ||||||
|  | import static cn.hutool.core.text.CharSequenceUtil.*; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * 代码生成的引擎,用于具体生成代码 |  * 代码生成的引擎,用于具体生成代码 | ||||||
|  * 目前基于 {@link org.apache.velocity.app.Velocity} 模板引擎实现 |  * 目前基于 {@link org.apache.velocity.app.Velocity} 模板引擎实现 | ||||||
| @@ -49,7 +51,7 @@ public class ToolCodegenEngine { | |||||||
|  |  | ||||||
|     private void initGlobalBindingMap() { |     private void initGlobalBindingMap() { | ||||||
|         // 全局配置 |         // 全局配置 | ||||||
|         globalBindingMap.put("basePackage", "cn.iocoder.dashboard.modules"); // TODO 基础包 |         globalBindingMap.put("basePackage", "cn.iocoder.dashboard.modules"); // TODO 基础包, 抽成参数 | ||||||
|         // 全局 Java Bean |         // 全局 Java Bean | ||||||
|         globalBindingMap.put("PageResultClassName", PageResult.class.getName()); |         globalBindingMap.put("PageResultClassName", PageResult.class.getName()); | ||||||
|         globalBindingMap.put("DateUtilsClassName", DateUtils.class.getName()); |         globalBindingMap.put("DateUtilsClassName", DateUtils.class.getName()); | ||||||
| @@ -64,16 +66,21 @@ public class ToolCodegenEngine { | |||||||
|  |  | ||||||
|     public void execute(ToolCodegenTableDO table, List<ToolCodegenColumnDO> columns) { |     public void execute(ToolCodegenTableDO table, List<ToolCodegenColumnDO> columns) { | ||||||
|         // 创建 bindingMap |         // 创建 bindingMap | ||||||
|         Map<String, Object> bindingMap = new HashMap<>(); |         Map<String, Object> bindingMap = new HashMap<>(globalBindingMap); | ||||||
|         bindingMap.put("table", table); |         bindingMap.put("table", table); | ||||||
|         bindingMap.put("columns", columns); |         bindingMap.put("columns", columns); | ||||||
|         bindingMap.put("hasDateColumn", columns.stream().anyMatch(codegenColumnDO -> |         bindingMap.put("primaryColumn", CollectionUtils.findFirst(columns, ToolCodegenColumnDO::getPrimaryKey)); | ||||||
|                 codegenColumnDO.getJavaType().equals(Date.class.getSimpleName()))); |         bindingMap.put("simpleClassName", upperFirst(toCamelCase(subAfter( // 去掉第一个驼峰,例如说 SysUser 去掉后是 User | ||||||
|         bindingMap.putAll(globalBindingMap); |                 toUnderlineCase(table.getClassName()), '_', false)))); | ||||||
|         // 执行生成 |         // 执行生成 | ||||||
| //        String result = templateEngine.getTemplate("codegen/dal/do.vm").render(bindingMap); | //        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/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); |         System.out.println(result); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -86,6 +86,13 @@ public class CollectionUtils { | |||||||
|         return !CollectionUtil.isEmpty(from) ? from.get(0) : null; |         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) { |     public static <T> void addIfNotNull(Collection<T> coll, T item) { | ||||||
|         if (item == null) { |         if (item == null) { | ||||||
|             return; |             return; | ||||||
|   | |||||||
| @@ -2,6 +2,13 @@ spring: | |||||||
|   application: |   application: | ||||||
|     name: dashboard |     name: dashboard | ||||||
|  |  | ||||||
|  |   # 数据源配置项 TODO 多数据源;TODO 监控配置 | ||||||
|  |   datasource: | ||||||
|  |     url: jdbc:mysql://127.0.1:33061/ruoyi-vue-pro?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT | ||||||
|  |     driver-class-name: com.mysql.jdbc.Driver | ||||||
|  |     username: root | ||||||
|  |     password: 123456 | ||||||
|  |  | ||||||
|   # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 |   # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 | ||||||
|   redis: |   redis: | ||||||
|     host: 127.0.0.1 # 地址 |     host: 127.0.0.1 # 地址 | ||||||
|   | |||||||
							
								
								
									
										62
									
								
								src/main/resources/codegen/service/service.vm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								src/main/resources/codegen/service/service.vm
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,62 @@ | |||||||
|  | package ${basePackage}.${table.moduleName}.service.${table.businessName}; | ||||||
|  |  | ||||||
|  | import java.util.*; | ||||||
|  | import javax.validation.*; | ||||||
|  | import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.*; | ||||||
|  | import ${basePackage}.${table.moduleName}.dal.mysql.dataobject.${table.businessName}.${table.className}DO; | ||||||
|  | import ${PageResultClassName}; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  | * ${table.classComment} Service 接口 | ||||||
|  | * | ||||||
|  | * @author ${table.author} | ||||||
|  | */ | ||||||
|  | public interface ${table.className}Service { | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 创建${table.classComment} | ||||||
|  |      * | ||||||
|  |      * @param createReqVO 创建信息 | ||||||
|  |      * @return ${class.description} | ||||||
|  |      */ | ||||||
|  |     ${primaryColumn.javaType} create${simpleClassName}(@Valid ${table.className}CreateReqVO createReqVO); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 更新${table.classComment} | ||||||
|  |      * | ||||||
|  |      * @param updateReqVO 更新信息 | ||||||
|  |      */ | ||||||
|  |     void update${simpleClassName}(@Valid ${table.className}UpdateReqVO updateReqVO); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 删除${table.classComment} | ||||||
|  |      * | ||||||
|  |      * @param id 编号 | ||||||
|  |      */ | ||||||
|  |     void delete${simpleClassName}(${primaryColumn.javaType} id); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 获得${table.classComment} | ||||||
|  |      * | ||||||
|  |      * @param id 编号 | ||||||
|  |      * @return ${class.description} | ||||||
|  |      */ | ||||||
|  |     ${table.className}DO get${simpleClassName}(${primaryColumn.javaType} id); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 获得${table.classComment}列表 | ||||||
|  |      * | ||||||
|  |      * @param ids 编号 | ||||||
|  |      * @return ${class.classComment}列表 | ||||||
|  |      */ | ||||||
|  |     List<${table.className}DO> get${simpleClassName}List(Collection<${primaryColumn.javaType}> ids); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 获得${table.classComment}分页 | ||||||
|  |      * | ||||||
|  |      * @param pageReqVO 分页查询 | ||||||
|  |      * @return ${class.classComment}分页 | ||||||
|  |      */ | ||||||
|  | 	PageResult<${table.className}DO> get${simpleClassName}Page(${table.className}PageReqVO pageReqVO); | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -1,7 +0,0 @@ | |||||||
| spring: |  | ||||||
|   # 数据源配置项 TODO 多数据源;TODO 监控配置 |  | ||||||
|   datasource: |  | ||||||
|     url: jdbc:mysql://127.0.1:33061/ruoyi-vue-pro?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT |  | ||||||
|     driver-class-name: com.mysql.jdbc.Driver |  | ||||||
|     username: root |  | ||||||
|     password: 123456 |  | ||||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV