From e181c084902aee7d7701865bd86cc6fc54e28e2f Mon Sep 17 00:00:00 2001 From: liyj <1003249715@qq.com> Date: Thu, 05 Sep 2024 11:06:20 +0800 Subject: [PATCH] 1、新增一期综治中心数据对接微服务 --- dyh-service/dyh-ssim/src/main/java/cn/huge/module/buildcode/controller/BuildCodeController.java | 62 + dyh-service/dyh-ssim/src/main/java/cn/huge/module/config/MybatisPlusConfig.java | 49 + dyh-service/dyh-ssim/src/main/java/cn/huge/module/buildcode/service/BuildCodeService.java | 683 +++++++++++++++++ dyh-service/dyh-ssim/src/test/java/cn/huge/module/DyhSsimApplicationTest.java | 17 dyh-service/dyh-ssim/src/main/java/cn/huge/module/client/api/UtilsClient.java | 25 dyh-service/dyh-ssim/src/test/java/cn/huge/base/common/base/BaseServiceTest.java | 30 dyh-service/dyh-ssim/src/main/java/cn/huge/module/client/api/CustClient.java | 46 + dyh-service/dyh-ssim/src/main/java/cn/huge/module/buildcode/domain/bo/UserTabColsBO.java | 218 +++++ dyh-service/dyh-ssim/src/main/java/cn/huge/module/buildcode/dao/mapper/BuildCodeMapper.java | 48 + dyh-service/dyh-ssim/src/main/java/cn/huge/module/client/api/impl/CustClientImpl.java | 102 ++ dyh-service/dyh-ssim/src/test/java/cn/huge/module/BuildCodeServiceTest.java | 79 + dyh-service/dyh-ssim/src/main/java/cn/huge/module/DyhSsimApplication.java | 21 dyh-service/dyh-ssim/src/main/java/cn/huge/module/client/api/impl/UtilsClientImpl.java | 53 + dyh-service/dyh-ssim/src/main/resources/config/application-dev.yml | 96 ++ dyh-service/dyh-ssim/src/main/java/cn/huge/module/utils/ConfigUtils.java | 35 dyh-service/dyh-ssim/src/main/resources/config/application.yml | 63 + dyh-service/dyh-ssim/src/main/resources/logback-spring.xml | 149 +++ dyh-service/dyh-ssim/src/main/java/cn/huge/module/buildcode/dao/mapper/xml/BuildCodeMapper.xml | 32 dyh-service/dyh-ssim/src/main/java/cn/huge/module/constant/CacheConsts.java | 35 dyh-service/dyh-ssim/src/main/resources/config/application-prod.yml | 96 ++ dyh-service/dyh-ssim/src/main/java/cn/huge/module/buildcode/utils/DbDataTypeToJavaType.java | 71 + dyh-service/dyh-ssim/src/main/assembly/assembly.xml | 68 + dyh-service/dyh-ssim/src/main/resources/config/application-test.yml | 96 ++ dyh-service/dyh-ssim/pom.xml | 224 +++++ 24 files changed, 2,398 insertions(+), 0 deletions(-) diff --git a/dyh-service/dyh-ssim/pom.xml b/dyh-service/dyh-ssim/pom.xml new file mode 100644 index 0000000..5ba9793 --- /dev/null +++ b/dyh-service/dyh-ssim/pom.xml @@ -0,0 +1,224 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>cn.huge</groupId> + <artifactId>dyh-ssim</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>jar</packaging> + + <name>dyh-ssim</name> + <description>广州市综治中心应用平台矛调模块-一期综治中心数据对接微服务</description> + + <parent> + <groupId>cn.huge</groupId> + <artifactId>dyh-service</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + <properties> + + </properties> + + <dependencies> + <!-- 公共框架mybatisPlus版 --> + <dependency> + <groupId>cn.huge</groupId> + <artifactId>dyh-base</artifactId> + <version>1.0.0-SNAPSHOT</version> + </dependency> + <!-- 公共框架mybatisPlus版 end --> + + <!-- springboot test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + <!-- springboot test end --> + + <!-- lombok --> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + </dependency> + <!-- lombok end --> + + <!-- junit --> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <!-- junit end --> + </dependencies> + + <build> + <finalName>dyh-ssim</finalName> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <configuration> + <!--重写包含依赖,包含不存在的依赖,jar里没有pom里的依赖 --> + <includes> + <include> + <groupId>null</groupId> + <artifactId>null</artifactId> + </include> + </includes> + <layout>ZIP</layout> + <!--使用外部配置文件,jar包里没有资源文件 --> + <addResources>true</addResources> + <outputDirectory>${project.build.directory}</outputDirectory> + </configuration> + <executions> + <execution> + <goals> + <goal>repackage</goal> + </goals> + <configuration> + <!--配置jar包特殊标识 配置后,保留原文件,生成新文件 *-run.jar --> + <!--配置jar包特殊标识 不配置,原文件命名为 *.jar.original,生成新文件 *.jar --> + <!--<classifier>run</classifier> --> + </configuration> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <configuration> + <!--不打包资源文件 注意这玩意从编译结果目录开始算目录结构 --> + <excludes> + <!-- 选择性过滤 --> + <exclude>/**/*.yml</exclude> + <exclude>/src/main/resources/*.xml</exclude> + <exclude>/src/main/resources/config/*.xml</exclude> + <exclude>/**/*.properties</exclude> + <exclude>/**/*.conf</exclude> + </excludes> + <includes> + <!-- 只打包指定目录的文件 --> + <include>cn/huge/**</include> + </includes> + <archive> + <manifest> + <addClasspath>true</addClasspath> + <classpathPrefix>lib/</classpathPrefix> + <useUniqueVersions>false</useUniqueVersions> + <mainClass>cn.huge.module.DyhSsimApplication</mainClass> + </manifest> + <manifestEntries> + <!--MANIFEST.MF 中 Class-Path 加入资源文件目录 --> + <Class-Path>./config/</Class-Path> + </manifestEntries> + </archive> + <outputDirectory>${project.build.directory}</outputDirectory> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <id>copy-dependencies</id> + <phase>prepare-package</phase> + <goals> + <goal>copy-dependencies</goal> + </goals> + <configuration> + <outputDirectory>${project.build.directory}/lib</outputDirectory> + </configuration> + </execution> + </executions> + </plugin> + + <!--拷贝资源文件 copy-resources --> + <plugin> + <artifactId>maven-resources-plugin</artifactId> + <executions> + <execution> + <id>copy-resources</id> + <phase>package</phase> + <goals> + <goal>copy-resources</goal> + </goals> + <configuration> + <resources> + <resource> + <directory>src/main/resources</directory> + <filtering>true</filtering> + <includes> + <include>*.xml</include> + <include>*.yml</include> + <include>*.properties</include> + <include>*.conf</include> + </includes> + </resource> + <resource> + <directory>src/main/resources/config</directory> + <filtering>true</filtering> + <includes> + <include>*.xml</include> + <include>*.yml</include> + <include>*.properties</include> + <include>*.conf</include> + </includes> + </resource> + </resources> + <outputDirectory>${project.build.directory}/config</outputDirectory> + </configuration> + </execution> + </executions> + </plugin> + + <!-- 打包时跳过测试 --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <skipTests>true</skipTests> + </configuration> + </plugin> + + <!-- 打包插件 --> + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <configuration> + <!--<finalName>${project.artifactId}</finalName>--> + <!-- 只使用finalName作为名字,不追加AssemblyId --> + <appendAssemblyId>false</appendAssemblyId> + <descriptors> + <descriptor>src/main/assembly/assembly.xml</descriptor> + </descriptors> + <!-- 打包后输出目录 --> + <!--<outputDirectory>/Users/wangminzhao/tmp/lisp-install-pkg</outputDirectory>--> + </configuration> + <executions> + <execution> + <id>make-assembly</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + + <resources> + <resource> + <directory>${basedir}/src/main/java</directory> + <includes> + <include>**/*.xml</include> + </includes> + </resource> + </resources> + </build> + + +</project> diff --git a/dyh-service/dyh-ssim/src/main/assembly/assembly.xml b/dyh-service/dyh-ssim/src/main/assembly/assembly.xml new file mode 100644 index 0000000..221909b --- /dev/null +++ b/dyh-service/dyh-ssim/src/main/assembly/assembly.xml @@ -0,0 +1,68 @@ +<?xml version="1.0" encoding="UTF-8"?> +<assembly> + <!-- 可自定义,这里指定的是项目环境 --> + <!-- spring-boot-assembly-local-1.0.RELEASE.tar.gz --> + <id>${project.version}</id> + + <!-- 打包的类型,如果有N个,将会打N个类型的包 --> + <formats> + <format>tar.gz</format> + <format>zip</format> + </formats> + + <!-- 需要根目录 --> + <includeBaseDirectory>true</includeBaseDirectory> + + <fileSets> + <!-- + 0755->即用户具有读/写/执行权限,组用户和其它用户具有读写权限; + 0644->即用户具有读写权限,组用户和其它用户具有只读权限; + --> + + <!-- 指定输出target中的配置文件到config目录中 --> + <fileSet> + <directory>${project.build.directory}/config</directory> + <outputDirectory>config</outputDirectory> + <fileMode>0644</fileMode> + </fileSet> + + <!-- 将第三方依赖打包到lib目录中 --> + <fileSet> + <directory>${project.build.directory}/lib</directory> + <outputDirectory>lib</outputDirectory> + <fileMode>0755</fileMode> + </fileSet> + + <!-- 指定输出static中的文件到static目录中 --> + <fileSet> + <directory>${project.basedir}/src/main/resources/static</directory> + <outputDirectory>static</outputDirectory> + <fileMode>0755</fileMode> + </fileSet> + + <!-- 指定输出processes中的文件到processes目录中 --> + <fileSet> + <directory>${project.basedir}/src/main/resources/processes</directory> + <outputDirectory>processes</outputDirectory> + <fileMode>0755</fileMode> + </fileSet> + + <!-- 指定输出templates中的文件到templates目录中 --> + <fileSet> + <directory>${project.basedir}/src/main/resources/templates</directory> + <outputDirectory>templates</outputDirectory> + <fileMode>0755</fileMode> + </fileSet> + + <!-- 将项目启动jar打包到/目录中 --> + <fileSet> + <directory>${project.build.directory}</directory> + <outputDirectory></outputDirectory> + <fileMode>0755</fileMode> + <includes> + <include>${project.build.finalName}.jar</include> + </includes> + </fileSet> + </fileSets> + +</assembly> \ No newline at end of file diff --git a/dyh-service/dyh-ssim/src/main/java/cn/huge/module/DyhSsimApplication.java b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/DyhSsimApplication.java new file mode 100644 index 0000000..cd6d508 --- /dev/null +++ b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/DyhSsimApplication.java @@ -0,0 +1,21 @@ +package cn.huge.module; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.eureka.EnableEurekaClient; +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.scheduling.annotation.EnableScheduling; + +@SpringBootApplication(scanBasePackages = {"cn.huge"}) +@EnableFeignClients +@EnableEurekaClient +@EnableScheduling +@MapperScan("cn.huge.*.*.dao.mapper") +public class DyhSsimApplication { + + public static void main(String[] args) { + SpringApplication.run(DyhSsimApplication.class, args); + } + +} diff --git a/dyh-service/dyh-ssim/src/main/java/cn/huge/module/buildcode/controller/BuildCodeController.java b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/buildcode/controller/BuildCodeController.java new file mode 100644 index 0000000..ff1368c --- /dev/null +++ b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/buildcode/controller/BuildCodeController.java @@ -0,0 +1,62 @@ +package cn.huge.module.buildcode.controller; + + +import cn.huge.module.buildcode.service.BuildCodeService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.PostConstruct; + +/** + * @title: 控代码生成器控制器类 + * @description: 控代码生成器控制器类 + * @company: hugeinfo + * @author: liyj + * @time: 2021-11-05 16:51:48 + * @version: 1.0.0 + */ +@Slf4j +@RestController +@RequestMapping("/buildcode") +public class BuildCodeController { + + @Autowired + private BuildCodeService buildCodeService; + + + @GetMapping("/buildAll") + public Object buildAll(String moduleName, String className, String tableName, String author) { + return null; + } + + @PostConstruct + public void init() { + log.debug("==================== BuildCodeController initi.............. ==================="); + } + +} +/** + * -------------------_ooOoo_------------------- + * ------------------o8888888o------------------ + * ------------------88" . "88------------------ + * ------------------(| -_- |)------------------ + * ------------------O\ = /O------------------ + * ---------------____/`---'\____--------------- + * -------------.' \\| |// `.------------- + * ------------/ \\||| : |||// \------------ + * -----------/ _||||| -:- |||||- \----------- + * -----------| | \\\ - /// | |----------- + * -----------| \_| ''\---/'' | |----------- + * -----------\ .-\__ `-` ___/-. /----------- + * ---------___`. .' /--.--\ `. . __---------- + * ------."" '< `.___\_<|>_/___.' >'"".------- + * -----| | : `- \`.;`\ _ /`;.`/ - ` : | |----- + * -----\ \ `-. \_ __\ /__ _/ .-` / /----- + * ======`-.____`-.___\_____/___.-`____.-'====== + * -------------------`=---=' + * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + * ---------佛祖保佑---hugeinfo---永无BUG---------- + */ diff --git a/dyh-service/dyh-ssim/src/main/java/cn/huge/module/buildcode/dao/mapper/BuildCodeMapper.java b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/buildcode/dao/mapper/BuildCodeMapper.java new file mode 100644 index 0000000..a217005 --- /dev/null +++ b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/buildcode/dao/mapper/BuildCodeMapper.java @@ -0,0 +1,48 @@ +package cn.huge.module.buildcode.dao.mapper; + +import cn.huge.module.buildcode.domain.bo.UserTabColsBO; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @title: 代码生成器mybatis接口 + * @description: 代码生成器mybatis接口 + * @company: hugeinfo + * @author: liyj + * @time: 2021-11-05 16:51:48 + * @version: 1.0.0 + */ +@Repository +public interface BuildCodeMapper { + /** + * 获取表的基本信息 + * + * @param tableName + * @return + */ + List<UserTabColsBO> getTabInfo(@Param("tableSchema") String tableSchema, @Param("tableName") String tableName); +} +/** + * -------------------_ooOoo_------------------- + * ------------------o8888888o------------------ + * ------------------88" . "88------------------ + * ------------------(| -_- |)------------------ + * ------------------O\ = /O------------------ + * ---------------____/`---'\____--------------- + * -------------.' \\| |// `.------------- + * ------------/ \\||| : |||// \------------ + * -----------/ _||||| -:- |||||- \----------- + * -----------| | \\\ - /// | |----------- + * -----------| \_| ''\---/'' | |----------- + * -----------\ .-\__ `-` ___/-. /----------- + * ---------___`. .' /--.--\ `. . __---------- + * ------."" '< `.___\_<|>_/___.' >'"".------- + * -----| | : `- \`.;`\ _ /`;.`/ - ` : | |----- + * -----\ \ `-. \_ __\ /__ _/ .-` / /----- + * ======`-.____`-.___\_____/___.-`____.-'====== + * -------------------`=---=' + * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + * ---------佛祖保佑---hugeinfo---永无BUG---------- + */ diff --git a/dyh-service/dyh-ssim/src/main/java/cn/huge/module/buildcode/dao/mapper/xml/BuildCodeMapper.xml b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/buildcode/dao/mapper/xml/BuildCodeMapper.xml new file mode 100644 index 0000000..3eeb159 --- /dev/null +++ b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/buildcode/dao/mapper/xml/BuildCodeMapper.xml @@ -0,0 +1,32 @@ +<?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"> + +<!--@title: 代码生成器mybatis接口 +@description: 代码生成器mybatis接口 +@company: hugeinfo +@author: liyj、wangwh +@time: 2024-7-25 16:51:48 +@version: 1.0.0--> +<mapper namespace="cn.huge.module.buildcode.dao.mapper.BuildCodeMapper"> + + <resultMap id="reslutMap" type="cn.huge.module.buildcode.domain.bo.UserTabColsBO"> + <result property="tableName" column="tableName"/> + <result property="tableComments" column="tableComments"/> + <result property="name" column="name"/> + <result property="comments" column="comments"/> + <result property="dataType" column="dataType"/> + </resultMap> + <!--自定义查询--> + <select id="getTabInfo" parameterType="String" resultMap="reslutMap"> + SELECT t1.table_name AS "tableName", t2.comments AS "tableComments", t1.column_name AS "name", + t1.data_type AS "dataType", t3.comments AS "comments" + FROM all_tab_columns t1 + LEFT JOIN all_tab_comments t2 ON t1.table_name = t2.table_name + LEFT JOIN user_col_comments t3 ON t1.table_name = t3.table_name AND t1.column_name = t3.column_name + WHERE t1.table_name = #{tableName} + AND t1.OWNER = #{tableSchema} + AND t2.OWNER = #{tableSchema} + AND t3.OWNER = #{tableSchema} + </select> + +</mapper> \ No newline at end of file diff --git a/dyh-service/dyh-ssim/src/main/java/cn/huge/module/buildcode/domain/bo/UserTabColsBO.java b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/buildcode/domain/bo/UserTabColsBO.java new file mode 100644 index 0000000..1fa3227 --- /dev/null +++ b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/buildcode/domain/bo/UserTabColsBO.java @@ -0,0 +1,218 @@ +package cn.huge.module.buildcode.domain.bo; + +import cn.huge.base.common.utils.StringUtils; +import cn.huge.module.buildcode.utils.DbDataTypeToJavaType; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * @title: 控代码生成器业务对象 + * @description: 控代码生成器业务对象 + * @company: hugeinfo + * @author: liyj + * @time: 2021-11-05 16:51:48 + * @version: 1.0.0 + */ +public class UserTabColsBO { + /** + * 表名 + */ + private String tableName; + + /** + * 表名中文 + */ + private String tableComments; + + /** + * 表字段名 + */ + private String name; + + /** + * 表字段名中文 + */ + private String comments; + + /** + * 表字段类型 + */ + private String dataType; + + /** + * 表字段java类型 + */ + private String javaDataType; + + /** + * 表字段默认值 + */ + private Integer dataScale; + + /** + * 实体类属性 + */ + private String fieldName; + + /** + * 实体类属性字段名 + */ + private String fieldUpperName; + + /** + * 是否有数据 + */ + private Integer hasDate; + + /** + * 是否有Clob + */ + private Integer hasClob; + + /** + * 是否有Blob + */ + private Integer hasBlob; + + /** + * 构造函数 + */ + public UserTabColsBO() { + this.hasDate = 0; + this.hasClob = 0; + this.hasBlob = 0; + } + + public String getTableName() { + return tableName; + } + + public void setTableName(String tableName) { + this.tableName = tableName.toLowerCase(); + } + + public String getTableComments() { + return tableComments; + } + + public void setTableComments(String tableComments) { + this.tableComments = tableComments.toLowerCase(); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name.toLowerCase(); + this.fieldName = StringUtils.lineToHump(name); + this.fieldUpperName = StringUtils.toUpperFirstLetter(this.fieldName); + + } + + public String getDataType() { + return dataType; + } + + public void setDataType(String dataType) { + this.dataType = dataType.toLowerCase(); + this.javaDataType = DbDataTypeToJavaType.getJavaType(dataType); + this.hasDate = 0; + + if (DbDataTypeToJavaType.DATA_TYPE_DATE.equals(this.javaDataType)) { + this.hasDate = 1; + } + + } + + public String getComments() { + return comments; + } + + public void setComments(String comments) { + this.comments = comments; + } + + public String getFieldName() { + return fieldName; + } + + public void setFieldName(String fieldName) { + this.fieldName = fieldName; + } + + public String getFieldUpperName() { + return fieldUpperName; + } + + public void setFieldUpperName(String fieldUpperName) { + this.fieldUpperName = fieldUpperName; + } + + public String getJavaDataType() { + return javaDataType; + } + + public void setJavaDataType(String javaDataType) { + this.javaDataType = javaDataType; + } + + public Integer getDataScale() { + return dataScale; + } + + public void setDataScale(Integer dataScale) { + this.dataScale = dataScale; + } + + public int getHasDate() { + return hasDate; + } + + public void setHasDate(Integer hasDate) { + this.hasDate = hasDate; + } + + public int getHasClob() { + return hasClob; + } + + public void setHasClob(Integer hasClob) { + this.hasClob = hasClob; + } + + public int getHasBlob() { + return hasBlob; + } + + public void setHasBlob(Integer hasBlob) { + this.hasBlob = hasBlob; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); + } +} +/** + * -------------------_ooOoo_------------------- + * ------------------o8888888o------------------ + * ------------------88" . "88------------------ + * ------------------(| -_- |)------------------ + * ------------------O\ = /O------------------ + * ---------------____/`---'\____--------------- + * -------------.' \\| |// `.------------- + * ------------/ \\||| : |||// \------------ + * -----------/ _||||| -:- |||||- \----------- + * -----------| | \\\ - /// | |----------- + * -----------| \_| ''\---/'' | |----------- + * -----------\ .-\__ `-` ___/-. /----------- + * ---------___`. .' /--.--\ `. . __---------- + * ------."" '< `.___\_<|>_/___.' >'"".------- + * -----| | : `- \`.;`\ _ /`;.`/ - ` : | |----- + * -----\ \ `-. \_ __\ /__ _/ .-` / /----- + * ======`-.____`-.___\_____/___.-`____.-'====== + * -------------------`=---=' + * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + * ---------佛祖保佑---hugeinfo---永无BUG---------- + */ diff --git a/dyh-service/dyh-ssim/src/main/java/cn/huge/module/buildcode/service/BuildCodeService.java b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/buildcode/service/BuildCodeService.java new file mode 100644 index 0000000..c16edbd --- /dev/null +++ b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/buildcode/service/BuildCodeService.java @@ -0,0 +1,683 @@ +package cn.huge.module.buildcode.service; + +import cn.huge.module.buildcode.domain.bo.UserTabColsBO; +import cn.huge.module.buildcode.dao.mapper.BuildCodeMapper; +import com.google.common.collect.Maps; +import freemarker.core.ParseException; +import freemarker.template.*; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import javax.annotation.PostConstruct; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.net.MalformedURLException; +import java.net.URISyntaxException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @title: 代码生成器服务层基类 + * @description: 使用单元测试直接对buildAll执行测试完成代码生成 + * @company: hugeinfo + * @author: liyj + * @time: 2021-11-05 16:51:48 + * @version: 1.0.0 + */ +@Slf4j +@Service +public class BuildCodeService { + + public static void main(String[] args) throws MalformedURLException, URISyntaxException { + + } + + @Autowired + private BuildCodeMapper buildCodeMapper; + + private Configuration cfg; + private static StringBuffer ROOT_MAIN_PATH = new StringBuffer(System.getProperty("user.dir")).append(("/src/main/java/")); + private static StringBuffer ROOT_TEST_PATH = new StringBuffer(System.getProperty("user.dir")).append(("/src/test/java/")); + + @PostConstruct + private void init() throws IOException { + try { + Configuration configuration = new Configuration(Configuration.getVersion()); + configuration.setClassForTemplateLoading(BuildCodeService.class, "/template"); + configuration.setDefaultEncoding("UTF-8"); + this.cfg = configuration; + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 获取表数据属性 + * @param packagePath 包路径 + * @param packageName 包名 + * @param className 类名 + * @param tableName 表名 + * @param author 作者 + * @param version 版本 + * @return Map + */ + private Map getTplData(String packagePath, String packageName, String className, String tableSchema, String tableName, String author, String version) { + Map tplData = Maps.newHashMap(); + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + tplData.put("packageName", packageName); + tplData.put("className", className); + tplData.put("author", author); + tplData.put("version", version); + tplData.put("createTime", format.format(new Date())); + tplData.put("basePackage", packagePath); + tplData.put("basePackagePath", packagePath.replace(".", "/") + "/"); + List<UserTabColsBO> list = buildCodeMapper.getTabInfo(tableSchema, tableName); + if (!CollectionUtils.isEmpty(list)) { + UserTabColsBO vo = list.get(0); + tplData.put("tableName", vo.getTableName()); + tplData.put("tableComments", vo.getTableComments()); + tplData.put("cols", list); + tplData.put("hasDate", 0); + tplData.put("hasClob", 0); + tplData.put("hasBlob", 0); + for (UserTabColsBO bo : list) { + if (bo.getHasDate() > 0) { + tplData.put("hasDate", 1); + } + } + } + return tplData; + } + + /** + * 生成所有层的代码 + * @param basePackage 包路径 + * @param packageName 包名 + * @param className 类名 + * @param tableName 表名 + * @param author 作者 + * @param version 版本 + */ + public void buildAll(String basePackage, String packageName, String className, String tableSchema, String tableName, String author, String version) { + Map tplData = this.getTplData(basePackage, packageName, className, tableSchema, tableName, author, version); + try { + // 必须 + this.buildPo(tplData); + this.buildBo(tplData); + this.buildDaoMapper(tplData); + this.buildDaoMapperXml(tplData); + this.buildService(tplData); + this.buildWebController(tplData); + // 可选 +// this.buildWechatController(tplData); +// this.buildJson(tplData); +// this.buildJsForm(tplData); + } catch (TemplateNotFoundException e) { + log.error("TemplateNotFoundException"); + } catch (TemplateException e) { + log.error("TemplateException"); + } catch (MalformedTemplateNameException e) { + log.error("MalformedTemplateNameException"); + } catch (ParseException e) { + log.error("ParseException"); + } catch (IOException e) { + log.error("IOException"); + } + } + + /** + * 生成PO层的代码 + * @param basePackage 包路径 + * @param packageName 包名 + * @param className 类名 + * @param tableName 表名 + * @param author 作者 + * @param version 版本 + */ + public void buildPo(String basePackage, String packageName, String className, String tableSchema, String tableName, String author, String version) { + Map tplData = this.getTplData(basePackage, packageName, className, tableSchema, tableName, author, version); + try { + this.buildPo(tplData); + } catch (TemplateNotFoundException e) { + log.error("TemplateNotFoundException"); + } catch (TemplateException e) { + log.error("TemplateException"); + } catch (MalformedTemplateNameException e) { + log.error("MalformedTemplateNameException"); + } catch (ParseException e) { + log.error("ParseException"); + } catch (IOException e) { + log.error("IOException"); + } + } + + /** + * 生成BO层的代码 + * @param basePackage 包路径 + * @param packageName 包名 + * @param className 类名 + * @param tableName 表名 + * @param author 作者 + * @param version 版本 + */ + public void buildBo(String basePackage, String packageName, String className, String tableSchema, String tableName, String author, String version) { + Map tplData = this.getTplData(basePackage, packageName, className, tableSchema, tableName, author, version); + try { + this.buildBo(tplData); + } catch (TemplateNotFoundException e) { + log.error("TemplateNotFoundException"); + } catch (TemplateException e) { + log.error("TemplateException"); + } catch (MalformedTemplateNameException e) { + log.error("MalformedTemplateNameException"); + } catch (ParseException e) { + log.error("ParseException"); + } catch (IOException e) { + log.error("IOException"); + } + } + + /** + * 生成Mapper的代码 + * @param basePackage 包路径 + * @param packageName 包名 + * @param className 类名 + * @param tableName 表名 + * @param author 作者 + * @param version 版本 + */ + public void buildDaoMapper(String basePackage, String packageName, String className, String tableSchema, String tableName, String author, String version) { + Map tplData = this.getTplData(basePackage, packageName, className, tableSchema, tableName, author, version); + try { + this.buildDaoMapper(tplData); + } catch (TemplateNotFoundException e) { + log.error("TemplateNotFoundException"); + } catch (TemplateException e) { + log.error("TemplateException"); + } catch (MalformedTemplateNameException e) { + log.error("MalformedTemplateNameException"); + } catch (ParseException e) { + log.error("ParseException"); + } catch (IOException e) { + log.error("IOException"); + } + } + + /** + * 生成MapperXml的代码 + * @param basePackage 包路径 + * @param packageName 包名 + * @param className 类名 + * @param tableName 表名 + * @param author 作者 + * @param version 版本 + */ + public void buildDaoMapperXml(String basePackage, String packageName, String className, String tableSchema, String tableName, String author, String version) { + Map tplData = this.getTplData(basePackage, packageName, className, tableSchema, tableName, author, version); + try { + this.buildDaoMapperXml(tplData); + } catch (TemplateNotFoundException e) { + log.error("TemplateNotFoundException"); + } catch (TemplateException e) { + log.error("TemplateException"); + } catch (MalformedTemplateNameException e) { + log.error("MalformedTemplateNameException"); + } catch (ParseException e) { + log.error("ParseException"); + } catch (IOException e) { + log.error("IOException"); + } + } + + /** + * 生成service层的代码 + * @param basePackage 包路径 + * @param packageName 包名 + * @param className 类名 + * @param tableName 表名 + * @param author 作者 + * @param version 版本 + */ + public void buildService(String basePackage, String packageName, String className, String tableSchema, String tableName, String author, String version) { + Map tplData = this.getTplData(basePackage, packageName, className, tableSchema, tableName, author, version); + try { + this.buildService(tplData); + } catch (TemplateNotFoundException e) { + log.error("TemplateNotFoundException"); + } catch (TemplateException e) { + log.error("TemplateException"); + } catch (MalformedTemplateNameException e) { + log.error("MalformedTemplateNameException"); + } catch (ParseException e) { + log.error("ParseException"); + } catch (IOException e) { + log.error("IOException"); + } + } + + /** + * 生成webController层的代码 + * @param basePackage 包路径 + * @param packageName 包名 + * @param className 类名 + * @param tableName 表名 + * @param author 作者 + * @param version 版本 + */ + public void buildWebController(String basePackage, String packageName, String className, String tableSchema, String tableName, String author, String version) { + Map tplData = this.getTplData(basePackage, packageName, className, tableSchema, tableName, author, version); + try { + this.buildWebController(tplData); + } catch (TemplateNotFoundException e) { + log.error("TemplateNotFoundException"); + } catch (TemplateException e) { + log.error("TemplateException"); + } catch (MalformedTemplateNameException e) { + log.error("MalformedTemplateNameException"); + } catch (ParseException e) { + log.error("ParseException"); + } catch (IOException e) { + log.error("IOException"); + } + } + + /** + * 生成wechatController层的代码 + * @param basePackage 包路径 + * @param packageName 包名 + * @param className 类名 + * @param tableName 表名 + * @param author 作者 + * @param version 版本 + */ + public void buildWechatController(String basePackage, String packageName, String className, String tableSchema, String tableName, String author, String version) { + Map tplData = this.getTplData(basePackage, packageName, className, tableSchema, tableName, author, version); + try { + this.buildWechatController(tplData); + } catch (TemplateNotFoundException e) { + log.error("TemplateNotFoundException"); + } catch (TemplateException e) { + log.error("TemplateException"); + } catch (MalformedTemplateNameException e) { + log.error("MalformedTemplateNameException"); + } catch (ParseException e) { + log.error("ParseException"); + } catch (IOException e) { + log.error("IOException"); + } + } + + /** + * 生成Controller层测试的代码 + * @param basePackage 包路径 + * @param packageName 包名 + * @param className 类名 + * @param tableName 表名 + * @param author 作者 + * @param version 版本 + */ + public void buildControllerTest(String basePackage, String packageName, String className, String tableSchema, String tableName, String author, String version) { + Map tplData = this.getTplData(basePackage, packageName, className, tableSchema, tableName, author, version); + try { + this.buildControllerTest(tplData); + + } catch (TemplateNotFoundException e) { + log.error("TemplateNotFoundException"); + } catch (TemplateException e) { + log.error("TemplateException"); + } catch (MalformedTemplateNameException e) { + log.error("MalformedTemplateNameException"); + } catch (ParseException e) { + log.error("ParseException"); + } catch (IOException e) { + log.error("IOException"); + } + } + + /** + * 生成service层测试的代码 + * @param basePackage 包路径 + * @param packageName 包名 + * @param className 类名 + * @param tableName 表名 + * @param author 作者 + * @param version 版本 + */ + public void buildServiceTest(String basePackage, String packageName, String className, String tableSchema, String tableName, String author, String version) { + Map tplData = this.getTplData(basePackage, packageName, className, tableSchema, tableName, author, version); + try { + this.buildServiceTest(tplData); + } catch (TemplateNotFoundException e) { + log.error("TemplateNotFoundException"); + } catch (TemplateException e) { + log.error("TemplateException"); + } catch (MalformedTemplateNameException e) { + log.error("MalformedTemplateNameException"); + } catch (ParseException e) { + log.error("ParseException"); + } catch (IOException e) { + log.error("IOException"); + } + } + + /** + * 生成实体json的代码 + * @param basePackage 包路径 + * @param packageName 包名 + * @param className 类名 + * @param tableName 表名 + * @param author 作者 + * @param version 版本 + */ + public void buildJson(String basePackage, String packageName, String className, String tableSchema, String tableName, String author, String version) { + Map tplData = this.getTplData(basePackage, packageName, className, tableSchema, tableName, author, version); + try { + this.buildJson(tplData); + } catch (TemplateNotFoundException e) { + log.error("TemplateNotFoundException"); + } catch (TemplateException e) { + log.error("TemplateException"); + } catch (MalformedTemplateNameException e) { + log.error("MalformedTemplateNameException"); + } catch (ParseException e) { + log.error("ParseException"); + } catch (IOException e) { + log.error("IOException"); + } + } + + /** + * 生成实体js的代码 + * @param basePackage 包路径 + * @param packageName 包名 + * @param className 类名 + + * @param tableName 表名 + * @param author 作者 + * @param version 版本 + */ + public void buildJsForm(String basePackage, String packageName, String className, String tableSchema, String tableName, String author, String version) { + Map tplData = this.getTplData(basePackage, packageName, className, tableSchema, tableName, author, version); + try { + this.buildJsForm(tplData); + } catch (TemplateNotFoundException e) { + log.error("TemplateNotFoundException"); + } catch (TemplateException e) { + log.error("TemplateException"); + } catch (MalformedTemplateNameException e) { + log.error("MalformedTemplateNameException"); + } catch (ParseException e) { + log.error("ParseException"); + } catch (IOException e) { + log.error("IOException"); + } + } + + + private void buildFile(Template template, Map tplData, String path) throws IOException, TemplateException { + File file = new File(path); + File dir = new File(file.getParent()); + if (!dir.exists()) { + dir.mkdirs(); + } + if (!file.exists()) { + file.createNewFile(); + } else { //文件存在就做备份 + int i = 1; + File bakFile = new File(path + i + ".bak"); + while (bakFile.exists()) { + i++; + bakFile = new File(path + i + ".bak"); + } + file.renameTo(bakFile); + } + + FileOutputStream fos = new FileOutputStream(new File(path)); + template.process(tplData, new OutputStreamWriter(fos, "utf-8")); + fos.flush(); + fos.close(); + } + + /** + * 创建持久化对象 + * + * @param tplData + */ + private void buildPo(Map tplData) throws TemplateException, IOException { + Template template = cfg.getTemplate("po.ftl"); + StringBuffer path = new StringBuffer(ROOT_MAIN_PATH) + .append(tplData.get("basePackagePath")) + .append(tplData.get("packageName")).append("/domain/po/") + .append(tplData.get("className")) + .append(".java"); + this.buildFile(template, tplData, path.toString()); + } + + /** + * 创建业务对象 + * + * @param tplData + */ + private void buildBo(Map tplData) throws TemplateException, IOException { + Template template = cfg.getTemplate("bo.ftl"); + StringBuffer path = new StringBuffer(ROOT_MAIN_PATH) + .append(tplData.get("basePackagePath")) + .append(tplData.get("packageName")).append("/domain/bo/") + .append(tplData.get("className")).append("BO") + .append(".java"); + this.buildFile(template, tplData, path.toString()); + } + + /** + * 创建Mybatis持久层接口 + * + * @param tplData + */ + private void buildDaoMapper(Map tplData) throws TemplateException, IOException { + Template template = cfg.getTemplate("dao.mapper.ftl"); + StringBuffer path = new StringBuffer(ROOT_MAIN_PATH) + .append(tplData.get("basePackagePath")) + .append(tplData.get("packageName")).append("/dao/mapper/") + .append(tplData.get("className")).append("Mapper") + .append(".java"); + this.buildFile(template, tplData, path.toString()); + } + + /** + * 创建Mybatis Mapper.xml文件 + * + * @param tplData + */ + private void buildDaoMapperXml(Map tplData) throws TemplateException, IOException { + Template template = cfg.getTemplate("dao.mapperXml.ftl"); + StringBuffer path = new StringBuffer(ROOT_MAIN_PATH) + .append(tplData.get("basePackagePath")) + .append(tplData.get("packageName")).append("/dao/mapper/xml/") + .append(tplData.get("className")).append("Mapper") + .append(".xml"); + this.buildFile(template, tplData, path.toString()); + } + + /** + * 创建服务层 + * + * @param tplData + */ + private void buildService(Map tplData) throws TemplateException, IOException { + String className = (String) tplData.get("className"); + if (Character.isLowerCase(className.charAt(0))){ + tplData.put("lowerName", className); + }else{ + String lowerName = (new StringBuilder()).append(Character.toLowerCase(className.charAt(0))).append(className.substring(1)).toString(); + tplData.put("lowerName", lowerName); + } + + Template template = cfg.getTemplate("service.ftl"); + StringBuffer path = new StringBuffer(ROOT_MAIN_PATH) + .append(tplData.get("basePackagePath")) + .append(tplData.get("packageName")).append("/service/") + .append(tplData.get("className")).append("Service") + .append(".java"); + this.buildFile(template, tplData, path.toString()); + } + + /** + * 创建web控制层 + * + * @param tplData + */ + private void buildWebController(Map tplData) throws TemplateException, IOException { + tplData.put("packagePath", ((String) tplData.get("packageName")).toLowerCase()); + String className = (String) tplData.get("className"); + if (Character.isLowerCase(className.charAt(0))){ + tplData.put("classPath", className); + tplData.put("lowerName", className); + }else{ + String lowerName = (new StringBuilder()).append(Character.toLowerCase(className.charAt(0))).append(className.substring(1)).toString(); + tplData.put("classPath", lowerName); + tplData.put("lowerName", lowerName); + } + + Template template = cfg.getTemplate("webController.ftl"); + StringBuffer path = new StringBuffer(ROOT_MAIN_PATH) + .append(tplData.get("basePackagePath")) + .append(tplData.get("packageName")).append("/controller/web/") + .append(tplData.get("className")).append("WebController") + .append(".java"); + this.buildFile(template, tplData, path.toString()); + } + + /** + * 创建wechat控制层 + * + * @param tplData + */ + private void buildWechatController(Map tplData) throws TemplateException, IOException { + tplData.put("packagePath", ((String) tplData.get("packageName")).toLowerCase()); + String className = (String) tplData.get("className"); + if (Character.isLowerCase(className.charAt(0))){ + tplData.put("classPath", className); + tplData.put("lowerName", className); + }else{ + String lowerName = (new StringBuilder()).append(Character.toLowerCase(className.charAt(0))).append(className.substring(1)).toString(); + tplData.put("classPath", lowerName); + tplData.put("lowerName", lowerName); + } + + Template template = cfg.getTemplate("wechatController.ftl"); + StringBuffer path = new StringBuffer(ROOT_MAIN_PATH) + .append(tplData.get("basePackagePath")) + .append(tplData.get("packageName")).append("/controller/wechat/") + .append(tplData.get("className")).append("WechatController") + .append(".java"); + this.buildFile(template, tplData, path.toString()); + } + + /** + * 创建服务层单元测试 + * + * @param tplData + */ + private void buildServiceTest(Map tplData) throws TemplateException, IOException { + String className = (String) tplData.get("className"); + if (Character.isLowerCase(className.charAt(0))){ + tplData.put("lowerName", className); + }else{ + String lowerName = (new StringBuilder()).append(Character.toLowerCase(className.charAt(0))).append(className.substring(1)).toString(); + tplData.put("lowerName", lowerName); + } + + Template template = cfg.getTemplate("serviceTest.ftl"); + StringBuffer path = new StringBuffer(ROOT_TEST_PATH) + .append(tplData.get("basePackagePath")) + .append(tplData.get("packageName")).append("/") + .append(tplData.get("className")).append("ServiceTest") + .append(".java"); + this.buildFile(template, tplData, path.toString()); + } + + /** + * 创建控制层单元测试 + * + * @param tplData + */ + private void buildControllerTest(Map tplData) throws TemplateException, IOException { + tplData.put("packagePath", ((String) tplData.get("packageName")).toLowerCase()); + String className = (String) tplData.get("className"); + if (Character.isLowerCase(className.charAt(0))){ + tplData.put("classPath", className); + tplData.put("lowerName", className); + }else{ + String lowerName = (new StringBuilder()).append(Character.toLowerCase(className.charAt(0))).append(className.substring(1)).toString(); + tplData.put("classPath", lowerName); + tplData.put("lowerName", lowerName); + } + + Template template = cfg.getTemplate("controllerTest.ftl"); + StringBuffer path = new StringBuffer(ROOT_TEST_PATH) + .append(tplData.get("basePackagePath")) + .append(tplData.get("packageName")).append("/") + .append(tplData.get("className")).append("ControllerTest") + .append(".java"); + this.buildFile(template, tplData, path.toString()); + } + + /** + * 创建Json代码 + * + * @param tplData + */ + private void buildJson(Map tplData) throws TemplateException, IOException { + Template template = cfg.getTemplate("json.ftl"); + StringBuffer path = new StringBuffer(ROOT_MAIN_PATH) + .append(tplData.get("basePackagePath")) + .append(tplData.get("packageName")).append("/domain/json/") + .append(tplData.get("className")) + .append(".json"); + this.buildFile(template, tplData, path.toString()); + } + + /** + * 创建界面React JS代码 + * + * @param tplData + */ + private void buildJsForm(Map tplData) throws TemplateException, IOException { + Template template = cfg.getTemplate("jsform.ftl"); + StringBuffer path = new StringBuffer(ROOT_MAIN_PATH) + .append(tplData.get("basePackagePath")) + .append(tplData.get("packageName")).append("/domain/js/") + .append(tplData.get("className")) + .append(".js"); + this.buildFile(template, tplData, path.toString()); + } +} +/** + * -------------------_ooOoo_------------------- + * ------------------o8888888o------------------ + * ------------------88" . "88------------------ + * ------------------(| -_- |)------------------ + * ------------------O\ = /O------------------ + * ---------------____/`---'\____--------------- + * -------------.' \\| |// `.------------- + * ------------/ \\||| : |||// \------------ + * -----------/ _||||| -:- |||||- \----------- + * -----------| | \\\ - /// | |----------- + * -----------| \_| ''\---/'' | |----------- + * -----------\ .-\__ `-` ___/-. /----------- + * ---------___`. .' /--.--\ `. . __---------- + * ------."" '< `.___\_<|>_/___.' >'"".------- + * -----| | : `- \`.;`\ _ /`;.`/ - ` : | |----- + * -----\ \ `-. \_ __\ /__ _/ .-` / /----- + * ======`-.____`-.___\_____/___.-`____.-'====== + * -------------------`=---=' + * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + * ---------佛祖保佑---hugeinfo---永无BUG---------- + */ diff --git a/dyh-service/dyh-ssim/src/main/java/cn/huge/module/buildcode/utils/DbDataTypeToJavaType.java b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/buildcode/utils/DbDataTypeToJavaType.java new file mode 100644 index 0000000..a81ff7c --- /dev/null +++ b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/buildcode/utils/DbDataTypeToJavaType.java @@ -0,0 +1,71 @@ +package cn.huge.module.buildcode.utils; + +import java.util.HashMap; +import java.util.Map; + +/** + * @title: 代码生成器:数据库类型转java类型-mysql + * @description: 代码生成器:数据库类型转java类型-mysql + * @company: hugeinfo + * @author: liyj + * @time: 2021-11-05 16:51:48 + * @version: 1.0.0 + */ +public class DbDataTypeToJavaType { + + private static Map<String, String> map = new HashMap(16); + public static String DATA_TYPE_DATE = "Date"; + + static { + map.put("int", "Integer"); + + map.put("double", "Double"); + + map.put("float", "Float"); + + map.put("fbooleanloat", "Boolean"); + + map.put("varchar", "String"); + map.put("char", "String"); + map.put("text", "String"); + map.put("longtext", "String"); + map.put("mediumtext", "String"); + + map.put("data", "Date"); + map.put("datetime", "Date"); + map.put("time", "Date"); + map.put("timestamp", "Date"); + } + + /** + * 转换java'类型 + * @param dataType 数据库类型 + * @return String + */ + public static String getJavaType(String dataType) { + return map.get(dataType.toLowerCase()); + } + +} +/** + * -------------------_ooOoo_------------------- + * ------------------o8888888o------------------ + * ------------------88" . "88------------------ + * ------------------(| -_- |)------------------ + * ------------------O\ = /O------------------ + * ---------------____/`---'\____--------------- + * -------------.' \\| |// `.------------- + * ------------/ \\||| : |||// \------------ + * -----------/ _||||| -:- |||||- \----------- + * -----------| | \\\ - /// | |----------- + * -----------| \_| ''\---/'' | |----------- + * -----------\ .-\__ `-` ___/-. /----------- + * ---------___`. .' /--.--\ `. . __---------- + * ------."" '< `.___\_<|>_/___.' >'"".------- + * -----| | : `- \`.;`\ _ /`;.`/ - ` : | |----- + * -----\ \ `-. \_ __\ /__ _/ .-` / /----- + * ======`-.____`-.___\_____/___.-`____.-'====== + * -------------------`=---=' + * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + * ---------佛祖保佑---hugeinfo---永无BUG---------- + */ diff --git a/dyh-service/dyh-ssim/src/main/java/cn/huge/module/client/api/CustClient.java b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/client/api/CustClient.java new file mode 100644 index 0000000..e3380e9 --- /dev/null +++ b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/client/api/CustClient.java @@ -0,0 +1,46 @@ +package cn.huge.module.client.api; + +import cn.huge.base.common.bo.ReturnBO; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * @title: 客户用户中心微服务调用接口 + * @description: 客户用户中心微服务调用接口 + * @company: hugeinfo + * @author: liyj + * @time: 2021-11-05 16:51:48 + * @version: 1.0.0 + */ +@FeignClient(name = "dyh-cust") +public interface CustClient { + + /** + * 内部用户-获取登录用户 + * @url {ctx}/api/client/ctUser/clientGetUser?userId= + * @param userId 登录用户编号 + * @return ReturnBO + */ + @GetMapping("/api/client/ctUser/clientGetUser") + ReturnBO clientGetUser(@RequestParam("userId") String userId); + + /** + * 内部用户-获取登录用户-所有信息 + * @url {ctx}/api/client/ctUser/clientGetUserAll?userId= + * @param userId 登录用户编号 + * @return + */ + @GetMapping("/api/client/ctUser/clientGetUserAll") + ReturnBO clientGetUserAll(@RequestParam("userId") String userId); + + /** + * 当事人-获取登录用户-所有信息 + * @url {ctx}/api/client/paUser/clientGetUserAll?userId= + * @param userId 登录用户编号 + * @return ReturnBO + */ + @GetMapping("/api/client/paUser/clientGetUserAll") + ReturnBO paclientGetUser(@RequestParam("userId") String userId); + +} diff --git a/dyh-service/dyh-ssim/src/main/java/cn/huge/module/client/api/UtilsClient.java b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/client/api/UtilsClient.java new file mode 100644 index 0000000..51df0f7 --- /dev/null +++ b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/client/api/UtilsClient.java @@ -0,0 +1,25 @@ +package cn.huge.module.client.api; + +import cn.huge.base.common.bo.ReturnBO; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; + +/** + * @title: 公共工具微服务调用接口 + * @description: 公共工具微服务调用接口 + * @company: hugeinfo + * @author: liyj + * @time: 2021-11-05 16:51:48 + * @version: 1.0.0 + */ +@FeignClient(name = "dyh-utils") +public interface UtilsClient { + + /** + * 公共id-获取时间Id,后四位常量 + * @url {ctx}/api/client/dispUtils/getNewTimeId + * @return Object + */ + @GetMapping("/api/client/dispUtils/getNewTimeId") + ReturnBO getNewTimeId(); +} diff --git a/dyh-service/dyh-ssim/src/main/java/cn/huge/module/client/api/impl/CustClientImpl.java b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/client/api/impl/CustClientImpl.java new file mode 100644 index 0000000..5f5609c --- /dev/null +++ b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/client/api/impl/CustClientImpl.java @@ -0,0 +1,102 @@ +package cn.huge.module.client.api.impl; + +import cn.huge.base.common.bo.ReturnBO; +import cn.huge.base.common.constant.ReturnConsts; +import cn.huge.base.common.exception.ClientException; +import cn.huge.base.common.exception.ServiceException; +import cn.huge.module.client.api.CustClient; +import cn.huge.module.cust.dto.CtUserDTO; +import cn.huge.module.cust.dto.PaUserDTO; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * @title: 客户用户中心微服务调用接口实现 + * @description: 客户用户中心微服务调用接口实现 + * @company: hugeinfo + * @author: liyj + * @time: 2021-11-05 16:51:48 + * @version: 1.0.0 + */ +@Slf4j +@Component +public class CustClientImpl { + + private CustClient custClient; + + @Autowired + public CustClientImpl(CustClient custClient) { + this.custClient = custClient; + } + + /** + * ObjectMapper工具类 + */ + private ObjectMapper objectMapper = new ObjectMapper(); + + /** + * 内部用户-获取登录用户 + * @param userId 用户编号 + * @return CtUserDTO + */ + public CtUserDTO clientGetUser(String userId){ + try{ + ReturnBO returnBo = custClient.clientGetUser(userId); + if (ReturnConsts.OK == returnBo.getCode()){ + CtUserDTO loginUser = objectMapper.convertValue(returnBo.getData(), CtUserDTO.class); + return loginUser; + }else{ + log.error("Client外服务接口[CustClientImpl.clientGetUser]请求异常:" + returnBo.getMsg(), returnBo.getMsg()); + throw new ClientException("CustClientImpl.clientGetUser", returnBo.getMsg()); + } + }catch (Exception e){ + log.error("service方法[CustClientImpl.clientGetUser]调用异常:"+e, e); + throw new ServiceException("CustClientImpl.clientGetUser", e); + } + } + + /** + * 内部用户-获取登录用户-所有信息 + * @param userId + * @return + */ + public CtUserDTO clientGetUserAll(String userId){ + try{ + ReturnBO returnBo = custClient.clientGetUserAll(userId); + if (ReturnConsts.OK == returnBo.getCode()){ + CtUserDTO loginUser = objectMapper.convertValue(returnBo.getData(), CtUserDTO.class); + return loginUser; + }else{ + log.error("Client外服务接口[CustClientImpl.clientGetUserAll]请求异常:" + returnBo.getMsg(), returnBo.getMsg()); + throw new ClientException("CustClientImpl.clientGetUserAll", returnBo.getMsg()); + } + }catch (Exception e){ + log.error("service方法[CustClientImpl.clientGetUserAll]调用异常:"+e, e); + throw new ServiceException("CustClientImpl.clientGetUserAll", e); + } + } + + /** + * 当事人-获取登录用户-所有信息 + * @param userId 用户编号 + * @return + */ + public PaUserDTO paclientGetUser(String userId){ + try{ + ReturnBO returnBo = custClient.paclientGetUser(userId); + if (ReturnConsts.OK == returnBo.getCode()){ + PaUserDTO loginUser = objectMapper.convertValue(returnBo.getData(), PaUserDTO.class); + return loginUser; + }else{ + log.error("Client外服务接口[CustClientImpl.paclientGetUser]请求异常:" + returnBo.getMsg(), returnBo.getMsg()); + throw new ClientException("CustClientImpl.paclientGetUser", returnBo.getMsg()); + } + }catch (Exception e){ + log.error("service方法[CustClientImpl.paclientGetUser]调用异常:"+e, e); + throw new ServiceException("CustClientImpl.paclientGetUser", e); + } + } + +} diff --git a/dyh-service/dyh-ssim/src/main/java/cn/huge/module/client/api/impl/UtilsClientImpl.java b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/client/api/impl/UtilsClientImpl.java new file mode 100644 index 0000000..e973ce7 --- /dev/null +++ b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/client/api/impl/UtilsClientImpl.java @@ -0,0 +1,53 @@ +package cn.huge.module.client.api.impl; + +import cn.huge.base.common.bo.ReturnBO; +import cn.huge.base.common.constant.ReturnConsts; +import cn.huge.base.common.exception.ClientException; +import cn.huge.base.common.exception.ServiceException; +import cn.huge.module.client.api.UtilsClient; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + + +/** + * @title: 公共工具微服务调用接口 + * @description: 公共工具微服务调用接口 + * @company: hugeinfo + * @author: liyj + * @time: 2021-11-05 16:51:48 + * @version: 1.0.0 + */ +@Slf4j +@Component +public class UtilsClientImpl { + + private UtilsClient utilsClient; + + @Autowired + public UtilsClientImpl(UtilsClient utilsClient) { + this.utilsClient = utilsClient; + } + + /** + * 公共id-获取时间Id,后四位常量 + * @url {ctx}/api/client/dispUtils/getNewTimeId + * @return Object + */ + public String getNewTimeId(){ + try{ + ReturnBO returnBo = utilsClient.getNewTimeId(); + if (ReturnConsts.OK == returnBo.getCode()){ + String id = (String) returnBo.getData(); + return id; + }else{ + log.error("Client外服务接口[UtilsClientImpl.getNewTimeId]请求异常:" + returnBo.getMsg(), returnBo.getMsg()); + throw new ClientException("UtilsClientImpl.getNewTimeId", returnBo.getMsg()); + } + }catch (Exception e){ + log.error("service方法[UtilsClientImpl.getNewTimeId]请求成功,处理异常:"+e, e); + throw new ServiceException("UtilsClientImpl.getNewTimeId", e); + } + } + +} diff --git a/dyh-service/dyh-ssim/src/main/java/cn/huge/module/config/MybatisPlusConfig.java b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/config/MybatisPlusConfig.java new file mode 100644 index 0000000..9990856 --- /dev/null +++ b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/config/MybatisPlusConfig.java @@ -0,0 +1,49 @@ +package cn.huge.module.config; + +import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @title: MybatisPlus配置 + * @description: MybatisPlus配置 + * @company: hugeinfo + * @author: liyj + * @time: 2021-11-05 16:51:48 + * @version: 1.0.0 + */ +@Configuration +public class MybatisPlusConfig { + + @Bean + public PaginationInterceptor paginationInterceptor() { + PaginationInterceptor paginationInterceptor = new PaginationInterceptor(); + // 设置请求的页面大于最大页后操作, true调回到首页,false 继续请求 默认false + // paginationInterceptor.setOverflow(false); + // 设置最大单页限制数量,默认 500 条,-1 不受限制 + // paginationInterceptor.setLimit(500); + return paginationInterceptor; + } +} +/** + * -------------------_ooOoo_------------------- + * ------------------o8888888o------------------ + * ------------------88" . "88------------------ + * ------------------(| -_- |)------------------ + * ------------------O\ = /O------------------ + * ---------------____/`---'\____--------------- + * -------------.' \\| |// `.------------- + * ------------/ \\||| : |||// \------------ + * -----------/ _||||| -:- |||||- \----------- + * -----------| | \\\ - /// | |----------- + * -----------| \_| ''\---/'' | |----------- + * -----------\ .-\__ `-` ___/-. /----------- + * ---------___`. .' /--.--\ `. . __---------- + * ------."" '< `.___\_<|>_/___.' >'"".------- + * -----| | : `- \`.;`\ _ /`;.`/ - ` : | |----- + * -----\ \ `-. \_ __\ /__ _/ .-` / /----- + * ======`-.____`-.___\_____/___.-`____.-'====== + * -------------------`=---=' + * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + * ---------佛祖保佑---hugeinfo---永无BUG---------- + */ diff --git a/dyh-service/dyh-ssim/src/main/java/cn/huge/module/constant/CacheConsts.java b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/constant/CacheConsts.java new file mode 100644 index 0000000..d7d44a1 --- /dev/null +++ b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/constant/CacheConsts.java @@ -0,0 +1,35 @@ +package cn.huge.module.constant; + +/** + * @title: 缓存相关常量类 + * @description: 存放缓存相关常量 + * @company: hugeinfo + * @author: liyj + * @time: 2021-11-05 16:51:48 + * @version: 1.0.0 + */ +public class CacheConsts { + +} +/** + * -------------------_ooOoo_------------------- + * ------------------o8888888o------------------ + * ------------------88" . "88------------------ + * ------------------(| -_- |)------------------ + * ------------------O\ = /O------------------ + * ---------------____/`---'\____--------------- + * -------------.' \\| |// `.------------- + * ------------/ \\||| : |||// \------------ + * -----------/ _||||| -:- |||||- \----------- + * -----------| | \\\ - /// | |----------- + * -----------| \_| ''\---/'' | |----------- + * -----------\ .-\__ `-` ___/-. /----------- + * ---------___`. .' /--.--\ `. . __---------- + * ------."" '< `.___\_<|>_/___.' >'"".------- + * -----| | : `- \`.;`\ _ /`;.`/ - ` : | |----- + * -----\ \ `-. \_ __\ /__ _/ .-` / /----- + * ======`-.____`-.___\_____/___.-`____.-'====== + * -------------------`=---=' + * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + * ---------佛祖保佑---hugeinfo---永无BUG---------- + */ diff --git a/dyh-service/dyh-ssim/src/main/java/cn/huge/module/utils/ConfigUtils.java b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/utils/ConfigUtils.java new file mode 100644 index 0000000..aadf7f9 --- /dev/null +++ b/dyh-service/dyh-ssim/src/main/java/cn/huge/module/utils/ConfigUtils.java @@ -0,0 +1,35 @@ +package cn.huge.module.utils; + +/** + * @title: 系统配置相关工具类 + * @description: 存放系统配置相关工具方法 + * @company: hugeinfo + * @author: liyj + * @time: 2021-11-05 16:51:48 + * @version: 1.0.0 + */ +public class ConfigUtils { + +} +/** + * -------------------_ooOoo_------------------- + * ------------------o8888888o------------------ + * ------------------88" . "88------------------ + * ------------------(| -_- |)------------------ + * ------------------O\ = /O------------------ + * ---------------____/`---'\____--------------- + * -------------.' \\| |// `.------------- + * ------------/ \\||| : |||// \------------ + * -----------/ _||||| -:- |||||- \----------- + * -----------| | \\\ - /// | |----------- + * -----------| \_| ''\---/'' | |----------- + * -----------\ .-\__ `-` ___/-. /----------- + * ---------___`. .' /--.--\ `. . __---------- + * ------."" '< `.___\_<|>_/___.' >'"".------- + * -----| | : `- \`.;`\ _ /`;.`/ - ` : | |----- + * -----\ \ `-. \_ __\ /__ _/ .-` / /----- + * ======`-.____`-.___\_____/___.-`____.-'====== + * -------------------`=---=' + * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + * ---------佛祖保佑---hugeinfo---永无BUG---------- + */ diff --git a/dyh-service/dyh-ssim/src/main/resources/config/application-dev.yml b/dyh-service/dyh-ssim/src/main/resources/config/application-dev.yml new file mode 100644 index 0000000..68753a3 --- /dev/null +++ b/dyh-service/dyh-ssim/src/main/resources/config/application-dev.yml @@ -0,0 +1,96 @@ +#server配置 +server: + #端口 + port: 9008 + +#Spring配置 +spring: + #服务名 + application: + name: dyh-ssim + #数据源配置 + datasource: + url: jdbc:dm://192.168.3.51:5236?schema=gzdyh_ssim_dev + username: SYSDBA + password: hugeinfo123 + driver-class-name: dm.jdbc.driver.DmDriver + type: com.alibaba.druid.pool.DruidDataSource + druid: + stat-view-servlet: + # 关闭 Druid 的统计视图 + enabled: false + # 定期检查空闲连接的有效性 + test-while-idle: true + # 用来验证数据库连接是否仍然可用的 SQL 查询 + validation-query: SELECT 1 + + # redis配置,单机版,集群另外配置 + redis: + host: 183.2.142.21 + port: 9017 + password: hugeinfo123 + # 使用的Redis数据库索引(默认为0) + database: 0 + # 连接超时时间(毫秒) + timeout: 5000 + lettuce: + pool: + # 连接池最大连接数 + max-active: 100 + # 连接池最大阻塞等待时间 + max-wait: 100000 + # 连接池中的最大空闲连接 + max-idle: 10 + # 连接池中的最小空闲连接 + min-idle: 0 + +#注册中心配置 +eureka: + client: + service-url: + #注册中心单机 + defaultZone: http://localhost:9001/eureka + #注册中心集群 + #defaultZone: http://localhost:8761/eureka,http://localhost:8762/eureka + #是否注册到注册中心 + register-with-eureka: true + #是否从注册中心拉取注册服务列表 + fetch-registry: true + #首次注册时间 + initial-instance-info-replication-interval-seconds: 2 + #客户端定时刷新本地缓存时间 + registry-fetch-interval-seconds: 5 + instance: + prefer-ip-address: true + instance-id: ${spring.cloud.client.ip-address}:${server.port} + #心跳时间,即服务续约间隔时间(缺省为30s) + lease-renewal-interval-in-seconds: 10 + #发呆时间,即服务续约到期时间(缺省为90s) + lease-expiration-duration-in-seconds: 30 + +#hystrix配置 +hystrix: + command: + default: + execution: + timeout: + enabled: true + isolation: + thread: + timeoutInMilliseconds: 30000 + +#健康检查-按需配置 +management: + endpoint: + health: + show-details: always + endpoints: + web: + exposure: + include: "*" + server: + #port: 9021 + servlet: + context-path: / + ssl: + enabled: false \ No newline at end of file diff --git a/dyh-service/dyh-ssim/src/main/resources/config/application-prod.yml b/dyh-service/dyh-ssim/src/main/resources/config/application-prod.yml new file mode 100644 index 0000000..68753a3 --- /dev/null +++ b/dyh-service/dyh-ssim/src/main/resources/config/application-prod.yml @@ -0,0 +1,96 @@ +#server配置 +server: + #端口 + port: 9008 + +#Spring配置 +spring: + #服务名 + application: + name: dyh-ssim + #数据源配置 + datasource: + url: jdbc:dm://192.168.3.51:5236?schema=gzdyh_ssim_dev + username: SYSDBA + password: hugeinfo123 + driver-class-name: dm.jdbc.driver.DmDriver + type: com.alibaba.druid.pool.DruidDataSource + druid: + stat-view-servlet: + # 关闭 Druid 的统计视图 + enabled: false + # 定期检查空闲连接的有效性 + test-while-idle: true + # 用来验证数据库连接是否仍然可用的 SQL 查询 + validation-query: SELECT 1 + + # redis配置,单机版,集群另外配置 + redis: + host: 183.2.142.21 + port: 9017 + password: hugeinfo123 + # 使用的Redis数据库索引(默认为0) + database: 0 + # 连接超时时间(毫秒) + timeout: 5000 + lettuce: + pool: + # 连接池最大连接数 + max-active: 100 + # 连接池最大阻塞等待时间 + max-wait: 100000 + # 连接池中的最大空闲连接 + max-idle: 10 + # 连接池中的最小空闲连接 + min-idle: 0 + +#注册中心配置 +eureka: + client: + service-url: + #注册中心单机 + defaultZone: http://localhost:9001/eureka + #注册中心集群 + #defaultZone: http://localhost:8761/eureka,http://localhost:8762/eureka + #是否注册到注册中心 + register-with-eureka: true + #是否从注册中心拉取注册服务列表 + fetch-registry: true + #首次注册时间 + initial-instance-info-replication-interval-seconds: 2 + #客户端定时刷新本地缓存时间 + registry-fetch-interval-seconds: 5 + instance: + prefer-ip-address: true + instance-id: ${spring.cloud.client.ip-address}:${server.port} + #心跳时间,即服务续约间隔时间(缺省为30s) + lease-renewal-interval-in-seconds: 10 + #发呆时间,即服务续约到期时间(缺省为90s) + lease-expiration-duration-in-seconds: 30 + +#hystrix配置 +hystrix: + command: + default: + execution: + timeout: + enabled: true + isolation: + thread: + timeoutInMilliseconds: 30000 + +#健康检查-按需配置 +management: + endpoint: + health: + show-details: always + endpoints: + web: + exposure: + include: "*" + server: + #port: 9021 + servlet: + context-path: / + ssl: + enabled: false \ No newline at end of file diff --git a/dyh-service/dyh-ssim/src/main/resources/config/application-test.yml b/dyh-service/dyh-ssim/src/main/resources/config/application-test.yml new file mode 100644 index 0000000..68753a3 --- /dev/null +++ b/dyh-service/dyh-ssim/src/main/resources/config/application-test.yml @@ -0,0 +1,96 @@ +#server配置 +server: + #端口 + port: 9008 + +#Spring配置 +spring: + #服务名 + application: + name: dyh-ssim + #数据源配置 + datasource: + url: jdbc:dm://192.168.3.51:5236?schema=gzdyh_ssim_dev + username: SYSDBA + password: hugeinfo123 + driver-class-name: dm.jdbc.driver.DmDriver + type: com.alibaba.druid.pool.DruidDataSource + druid: + stat-view-servlet: + # 关闭 Druid 的统计视图 + enabled: false + # 定期检查空闲连接的有效性 + test-while-idle: true + # 用来验证数据库连接是否仍然可用的 SQL 查询 + validation-query: SELECT 1 + + # redis配置,单机版,集群另外配置 + redis: + host: 183.2.142.21 + port: 9017 + password: hugeinfo123 + # 使用的Redis数据库索引(默认为0) + database: 0 + # 连接超时时间(毫秒) + timeout: 5000 + lettuce: + pool: + # 连接池最大连接数 + max-active: 100 + # 连接池最大阻塞等待时间 + max-wait: 100000 + # 连接池中的最大空闲连接 + max-idle: 10 + # 连接池中的最小空闲连接 + min-idle: 0 + +#注册中心配置 +eureka: + client: + service-url: + #注册中心单机 + defaultZone: http://localhost:9001/eureka + #注册中心集群 + #defaultZone: http://localhost:8761/eureka,http://localhost:8762/eureka + #是否注册到注册中心 + register-with-eureka: true + #是否从注册中心拉取注册服务列表 + fetch-registry: true + #首次注册时间 + initial-instance-info-replication-interval-seconds: 2 + #客户端定时刷新本地缓存时间 + registry-fetch-interval-seconds: 5 + instance: + prefer-ip-address: true + instance-id: ${spring.cloud.client.ip-address}:${server.port} + #心跳时间,即服务续约间隔时间(缺省为30s) + lease-renewal-interval-in-seconds: 10 + #发呆时间,即服务续约到期时间(缺省为90s) + lease-expiration-duration-in-seconds: 30 + +#hystrix配置 +hystrix: + command: + default: + execution: + timeout: + enabled: true + isolation: + thread: + timeoutInMilliseconds: 30000 + +#健康检查-按需配置 +management: + endpoint: + health: + show-details: always + endpoints: + web: + exposure: + include: "*" + server: + #port: 9021 + servlet: + context-path: / + ssl: + enabled: false \ No newline at end of file diff --git a/dyh-service/dyh-ssim/src/main/resources/config/application.yml b/dyh-service/dyh-ssim/src/main/resources/config/application.yml new file mode 100644 index 0000000..f2b985a --- /dev/null +++ b/dyh-service/dyh-ssim/src/main/resources/config/application.yml @@ -0,0 +1,63 @@ +#Spring配置 +spring: + profiles: + active: + - dev + # - test + # - prod + + devtools: + restart: + enabled: true + servlet: + multipart: + max-file-size: -1 + max-request-size: -1 + main: + #可以重复命名配置 + allow-bean-definition-overriding: true + allow-circular-references: true + +#server配置 +server: + #服务时限配置 + tomcat: + min-spare-threads: 100 + max-threads: 256 + connection-timeout: 8000 + main: + #可以重复命名配置 + allow-bean-definition-overriding: true + +#ribbon配置 +ribbon: + #服务之间调用,请求处理超时时间 + ReadTimeout: 120000 + #服务之间调用,请求连接的超时时间 + ConnectTimeout: 30000 + +#mybatis-plus配置 +mybatis-plus: + configuration: + #控制台输出sql语句 + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + # log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl + #配置返回数据库(column下划线命名&&返回java实体是驼峰命名),自动匹配无需as(没开启这个,SQL需要写as) + ap-underscore-to-camel-case: true + #如何自动映射列到字段或属性,NONE:表示取消自动映射;PARTIAL:只会自动映射没有定义嵌套结果集映射的结果集。FULL:会自动映射任意复杂的结果集(无论是否嵌套)。默认是partial,这是一种全局设置 + auto-mapping-behavior: full + global-config: + db-config: + #驼峰下划线转换 + column-underline: false + #数据库大写下划线转换 + capital-mode: true + #全局逻辑删除的实体字段名 + #logic-delete-field: flag + #逻辑未删除值(默认为 0),实体类字段需要加上@TableLogic + logic-not-delete-value: 0 + #逻辑已删除值(默认为 1) + logic-delete-value: 1 + #字段策略,IGNORED:忽略判断,NOT_NULL:非null判断,NOT_EMPTY:非空判断,DEFAULT:默认,NEVER:不加入sql + update-strategy: IGNORED + mapper-locations: classpath*:/cn/huge/*/*/dao/mapper/xml/*Mapper.xml \ No newline at end of file diff --git a/dyh-service/dyh-ssim/src/main/resources/logback-spring.xml b/dyh-service/dyh-ssim/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..7610225 --- /dev/null +++ b/dyh-service/dyh-ssim/src/main/resources/logback-spring.xml @@ -0,0 +1,149 @@ +<?xml version="1.0" encoding="UTF-8"?> +<configuration> + <!-- 配置一天一个日志文件,INFO信息存在一个文件中,ERROR信息存在一个文件中 --> + <!-- 日志级别从低到高 TRACE < DEBUG < INFO < WARN < ERROR --> + + <!-- 文件输出格式 --> + <property name="PATTERN" value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%-5level] [%thread] [%logger{36}] - %msg%n" /> + <property name="CT_PATTERN" value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%-5level] [%logger{36}] - %msg%n" /> + <!-- 日志文件目录 --> + <property name="LOG_HOME" value="logs/ssim/service" /> + <property name="CT_LOG_HOME" value="logs/ssim/business" /> + <!-- 日志文件名称 --> + <property name="LOG_NAME" value="ssim" /> + + <!-- 开发环境日志配置 --> + <springProfile name="dev"> + <!-- 配置控制台打印信息 --> + <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> + <encoder charset="UTF-8"> + <!-- 文件输出格式 --> + <pattern>${PATTERN}</pattern> + </encoder> + </appender> + + <!-- 设置根日志级别,如果日志级别低于设置的级别,则该日志不会被记录。如果日志级别高于设置的级别,那么这条日志将会被记录 --> + <root level="INFO"> + <appender-ref ref="CONSOLE" /> + </root> + + <logger name="cn.huge" level="DEBUG" additivity="true"/> + <logger name="org.hibernate.SQL" level="DEBUG" additivity="true"/> + <!-- 为 MyBatis 设置 DEBUG 级别的日志 --> + <logger name="com.baomidou.mybatisplus" level="INFO" additivity="false"> + <appender-ref ref="CONSOLE" /> + </logger> + </springProfile> + + <!-- 测试环境+生产环境,多个使用逗号隔开 --> + <springProfile name="test,prod"> + <!-- 配置DEBUG文件 --> + <appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> + <!-- 日志文件名称 --> + <fileNamePattern>${LOG_HOME}/${LOG_NAME}.debug.%d{yyyyMMdd}.%i.log</fileNamePattern> + <!-- 日志保留31天 --> + <maxHistory>31</maxHistory> + <!-- 所有日志大小不超过30GB --> + <totalSizeCap>30GB</totalSizeCap> + <!-- 单个日志文件大小不超过10MB --> + <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> + <maxFileSize>10MB</maxFileSize> + </timeBasedFileNamingAndTriggeringPolicy> + </rollingPolicy> + + <encoder charset="UTF-8"> + <!-- 文件输出格式 --> + <pattern>${PATTERN}</pattern> + </encoder> + + <!-- 只打印 DEBUG 日志 --> + <filter class="ch.qos.logback.classic.filter.LevelFilter"> + <level>DEBUG</level> + <!-- 命中就接受 --> + <onMatch>ACCEPT</onMatch> + <!-- 没有命中就过滤掉 --> + <onMismatch>DENY</onMismatch> + </filter> + </appender> + + <!-- 配置INFO文件 --> + <appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> + <!-- 日志文件名称 --> + <fileNamePattern>${LOG_HOME}/${LOG_NAME}.info.%d{yyyyMMdd}.%i.log</fileNamePattern> + <!-- 日志保留31天 --> + <maxHistory>31</maxHistory> + <!-- 所有日志大小不超过30GB --> + <totalSizeCap>30GB</totalSizeCap> + <!-- 单个日志文件大小不超过10MB --> + <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> + <maxFileSize>10MB</maxFileSize> + </timeBasedFileNamingAndTriggeringPolicy> + </rollingPolicy> + + <encoder charset="UTF-8"> + <!-- 文件输出格式 --> + <pattern>${PATTERN}</pattern> + </encoder> + + <!-- 只打印 INFO 日志 --> + <filter class="ch.qos.logback.classic.filter.LevelFilter"> + <level>INFO</level> + <!-- 命中就过滤掉 --> + <onMatch>ACCEPT</onMatch> + <!-- 没有命中就接受 --> + <onMismatch>DENY</onMismatch> + </filter> + </appender> + + <!-- 配置ERROR文件 --> + <appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> + !-- 日志文件名称 --> + <fileNamePattern>${LOG_HOME}/${LOG_NAME}.error.%d{yyyyMMdd}.%i.log</fileNamePattern> + <!-- 日志保留31天 --> + <maxHistory>31</maxHistory> + <!-- 所有日志大小不超过30GB --> + <totalSizeCap>30GB</totalSizeCap> + <!-- 单个日志文件大小不超过10MB --> + <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> + <maxFileSize>10MB</maxFileSize> + </timeBasedFileNamingAndTriggeringPolicy> + </rollingPolicy> + + <encoder charset="UTF-8"> + <!-- 文件输出格式 --> + <pattern>${PATTERN}</pattern> + </encoder> + + <!-- 只打印 ERROR 日志 --> + <filter class="ch.qos.logback.classic.filter.LevelFilter"> + <level>ERROR</level> + <!-- 命中就过滤掉 --> + <onMatch>ACCEPT</onMatch> + <!-- 没有命中就接受 --> + <onMismatch>DENY</onMismatch> + </filter> + </appender> + + <!-- 为 MyBatis 设置 DEBUG 级别的日志 --> + <logger name="org.apache.ibatis" level="DEBUG"/> + <!-- 输出 SQL 语句和参数 --> + <logger name="org.apache.ibatis.binding" level="DEBUG"/> + <!-- 输出 SQL 语句执行情况 --> + <logger name="org.apache.ibatis.session" level="DEBUG"/> + <!-- 输出 SQL 语句执行结果 --> + <logger name="org.apache.ibatis.executor" level="DEBUG"/> + <!-- 输出 SQL 语句 --> + <logger name="org.apache.ibatis.scripting" level="DEBUG"/> + + <!-- 设置根日志级别,如果日志级别低于设置的级别,则该日志不会被记录。如果日志级别高于设置的级别,那么这条日志将会被记录 --> + <root level="DEBUG"> + <appender-ref ref="DEBUG_FILE" /> + <appender-ref ref="INFO_FILE" /> + <appender-ref ref="ERROR_FILE" /> + </root> + + </springProfile> +</configuration> \ No newline at end of file diff --git a/dyh-service/dyh-ssim/src/test/java/cn/huge/base/common/base/BaseServiceTest.java b/dyh-service/dyh-ssim/src/test/java/cn/huge/base/common/base/BaseServiceTest.java new file mode 100644 index 0000000..8a8f662 --- /dev/null +++ b/dyh-service/dyh-ssim/src/test/java/cn/huge/base/common/base/BaseServiceTest.java @@ -0,0 +1,30 @@ +package cn.huge.base.common.base; + +import lombok.extern.slf4j.Slf4j; +import org.junit.After; +import org.junit.Before; +import org.junit.runner.RunWith; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; + +@Slf4j +@RunWith(SpringRunner.class) +@SpringBootTest +@WebAppConfiguration +public class BaseServiceTest { + + private MockMvc mockMvc; + + @Before + public void init() { + log.info("开始测试..."); + } + + @After + public void after() { + log.info("测试结束..."); + } +} \ No newline at end of file diff --git a/dyh-service/dyh-ssim/src/test/java/cn/huge/module/BuildCodeServiceTest.java b/dyh-service/dyh-ssim/src/test/java/cn/huge/module/BuildCodeServiceTest.java new file mode 100644 index 0000000..8b4448a --- /dev/null +++ b/dyh-service/dyh-ssim/src/test/java/cn/huge/module/BuildCodeServiceTest.java @@ -0,0 +1,79 @@ +package cn.huge.module; + +import cn.huge.base.common.base.BaseServiceTest; +import cn.huge.module.buildcode.service.BuildCodeService; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +public class BuildCodeServiceTest extends BaseServiceTest { + + @Autowired + private BuildCodeService service; + + //数据库为jdbc连接url中设置的默认库 + private String basePackage = "cn.huge.module"; + private String packageName = "ctuser"; + private String className = "CtUnit"; + private String tableSchema = "gzdyh_ssim_dev"; + private String tableName = "dyh_ct_unit"; + private String author = "liyj"; + private String version = "1.0.0"; + + @Test + public void buildAllTest() { + service.buildAll(basePackage, packageName, className, tableSchema, tableName, author, version); + + } + + /******************************************************** + * 下面单独执行 * + ******************************************************** + */ + @Test + public void buildPoTest() { + service.buildPo(basePackage, packageName, className, tableSchema, tableName, author, version); + } + + @Test + public void buildBoTest() { + service.buildBo(basePackage, packageName, className, tableSchema, tableName, author, version); + } + + @Test + public void buildServiceTest() { + service.buildService(basePackage, packageName, className, tableSchema, tableName, author, version); + } + + @Test + public void buildWebControllerTest() { + service.buildWebController(basePackage, packageName, className, tableSchema, tableName, author, version); + } + + @Test + public void buildWechatControllerTest() { + service.buildWechatController(basePackage, packageName, className, tableSchema, tableName, author, version); + } + + @Test + public void buildJsonTest() { + service.buildJson(basePackage, packageName, className, tableSchema, tableName, author, version); + + } + + @Test + public void buildJsFormTest() { + service.buildJsForm(basePackage, packageName, className, tableSchema, tableName, author, version); + } + + @Test + public void buildServiceTestTest() { + service.buildServiceTest(basePackage, packageName, className, tableSchema, tableName, author, version); + } + + @Test + public void buildControllerTestTest() { + service.buildControllerTest(basePackage, packageName, className, tableSchema, tableName, author, version); + } + + +} diff --git a/dyh-service/dyh-ssim/src/test/java/cn/huge/module/DyhSsimApplicationTest.java b/dyh-service/dyh-ssim/src/test/java/cn/huge/module/DyhSsimApplicationTest.java new file mode 100644 index 0000000..baea555 --- /dev/null +++ b/dyh-service/dyh-ssim/src/test/java/cn/huge/module/DyhSsimApplicationTest.java @@ -0,0 +1,17 @@ +package cn.huge.module; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class DyhSsimApplicationTest { + + @Test + public void contextLoads() { + + } + +} -- Gitblit v1.8.0