From 5203f988a5c3fdcfdfe3df2c147dea7f60ba0494 Mon Sep 17 00:00:00 2001 From: kuanghua <35098590+jzfai@users.noreply.github.com> Date: Fri, 10 Sep 2021 22:36:03 +0800 Subject: [PATCH 01/36] Update pom.xml --- pom.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 81763e7..916bd07 100644 --- a/pom.xml +++ b/pom.xml @@ -96,8 +96,8 @@ 127.0.0.1 df87d91b-b1ab-4720-8e1c-5a147edc6ddc nacos-group-${activatedProperties} - jzfai - kuhu8866 + admin + 123456 @@ -113,9 +113,9 @@ 127.0.0.1 df87d91b-b1ab-4720-8e1c-5a147edc6ddc nacos-group-${activatedProperties} - jzfai - kuhu8866 + admin + 123456 - \ No newline at end of file + From eab6764f6d3f3bfbd0f8793b58a97e07061608d4 Mon Sep 17 00:00:00 2001 From: kuanghua <35098590+jzfai@users.noreply.github.com> Date: Fri, 10 Sep 2021 22:43:37 +0800 Subject: [PATCH 02/36] Update pom.xml --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 916bd07..ee3bcb9 100644 --- a/pom.xml +++ b/pom.xml @@ -96,7 +96,7 @@ 127.0.0.1 df87d91b-b1ab-4720-8e1c-5a147edc6ddc nacos-group-${activatedProperties} - admin + jzfai 123456 @@ -113,7 +113,7 @@ 127.0.0.1 df87d91b-b1ab-4720-8e1c-5a147edc6ddc nacos-group-${activatedProperties} - admin + jzfai 123456 From 70cb9ada7e8be45e89fb838eeeb0f6e3ce27d54c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=9D=E5=8D=8E?= Date: Wed, 15 Sep 2021 17:45:28 +0800 Subject: [PATCH 03/36] add env modal ty-upload --- README.md | 104 ++- controller.mv | 136 ++++ element-form.mv | 302 +++++++++ element-table.mv | 295 +++++++++ entity.mv | 46 ++ mapper.mv | 19 + nacos_config_export_20210915163624.zip | Bin 0 -> 9322 bytes oldElementDemo.mv | 512 +++++++++++++++ pom.xml | 18 + service.mv | 54 ++ .../tyauth/config/Swagger2Config.java | 4 +- .../kuanghua/tyauth/utils/JwtUtilsSelf.java | 8 +- ty-auth/src/main/resources/application.yml | 17 +- .../gatewaytwo/config/SwaggerDocConfig.java | 21 + .../gatewaytwo/config/SwaggerProvider.java | 23 +- .../src/main/resources/application.yml | 49 +- ty-upload/pom.xml | 50 ++ .../kuanghua/tyupload/UploadApplication.java | 18 + .../kuanghua/tyupload/config/BaseConfig.java | 21 + .../tyupload/config/Swagger2Config.java | 52 ++ .../tyupload/controller/NacosTestDemo.java | 44 ++ .../tyupload/controller/UploadController.java | 83 +++ .../tyupload/service/UploadService.java | 90 +++ ty-upload/src/main/javabrandE/BrandE.vue | 266 ++++++++ ty-upload/src/main/javabrandE/BrandEForm.vue | 227 +++++++ ty-upload/src/main/main11.iml | 13 + ty-upload/src/main/resources/application.yml | 0 ty-upload/src/main/resources/bootstrap.yml | 35 + .../controller/UploadControllerTest.java | 28 + ty-upload/src/test/test2.iml | 11 + ty-upload/ty-upload.iml | 230 +++++++ .../tyuser/controller/BrandController.java | 129 ++++ .../tyuser/controller/UserController.java | 31 +- .../top/kuanghua/tyuser/element/Access.vue | 536 --------------- .../java/top/kuanghua/tyuser/element/User.vue | 617 ------------------ .../top/kuanghua/tyuser/entity/Brand.java | 50 ++ .../java/top/kuanghua/tyuser/entity/Role.java | 1 - .../kuanghua/tyuser/mapper/BrandMapper.java | 8 + .../kuanghua/tyuser/service/BrandService.java | 51 ++ .../java/top/kuanghua/tyuserbrand/Brand.vue | 276 ++++++++ .../top/kuanghua/tyuserbrand/BrandForm.vue | 227 +++++++ .../java/top/kuanghua/tyuserbrandE/BrandE.vue | 266 ++++++++ .../top/kuanghua/tyuserbrandE/BrandEForm.vue | 227 +++++++ 43 files changed, 3976 insertions(+), 1219 deletions(-) create mode 100644 controller.mv create mode 100644 element-form.mv create mode 100644 element-table.mv create mode 100644 entity.mv create mode 100644 mapper.mv create mode 100644 nacos_config_export_20210915163624.zip create mode 100644 oldElementDemo.mv create mode 100644 service.mv create mode 100644 ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/config/SwaggerDocConfig.java create mode 100644 ty-upload/pom.xml create mode 100644 ty-upload/src/main/java/top/kuanghua/tyupload/UploadApplication.java create mode 100644 ty-upload/src/main/java/top/kuanghua/tyupload/config/BaseConfig.java create mode 100644 ty-upload/src/main/java/top/kuanghua/tyupload/config/Swagger2Config.java create mode 100644 ty-upload/src/main/java/top/kuanghua/tyupload/controller/NacosTestDemo.java create mode 100644 ty-upload/src/main/java/top/kuanghua/tyupload/controller/UploadController.java create mode 100644 ty-upload/src/main/java/top/kuanghua/tyupload/service/UploadService.java create mode 100644 ty-upload/src/main/javabrandE/BrandE.vue create mode 100644 ty-upload/src/main/javabrandE/BrandEForm.vue create mode 100644 ty-upload/src/main/main11.iml create mode 100644 ty-upload/src/main/resources/application.yml create mode 100644 ty-upload/src/main/resources/bootstrap.yml create mode 100644 ty-upload/src/test/java/top/kuanghua/tyupload/controller/UploadControllerTest.java create mode 100644 ty-upload/src/test/test2.iml create mode 100644 ty-upload/ty-upload.iml create mode 100644 ty-user/src/main/java/top/kuanghua/tyuser/controller/BrandController.java delete mode 100644 ty-user/src/main/java/top/kuanghua/tyuser/element/Access.vue delete mode 100644 ty-user/src/main/java/top/kuanghua/tyuser/element/User.vue create mode 100644 ty-user/src/main/java/top/kuanghua/tyuser/entity/Brand.java create mode 100644 ty-user/src/main/java/top/kuanghua/tyuser/mapper/BrandMapper.java create mode 100644 ty-user/src/main/java/top/kuanghua/tyuser/service/BrandService.java create mode 100644 ty-user/src/main/java/top/kuanghua/tyuserbrand/Brand.vue create mode 100644 ty-user/src/main/java/top/kuanghua/tyuserbrand/BrandForm.vue create mode 100644 ty-user/src/main/java/top/kuanghua/tyuserbrandE/BrandE.vue create mode 100644 ty-user/src/main/java/top/kuanghua/tyuserbrandE/BrandEForm.vue diff --git a/README.md b/README.md index 1b4dfb3..7bb514f 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,108 @@ -### 简介: - +#### 更新日志 ``` -vue3-admin-template 的数据来源 -涉及到的功能:jwt 权限校验,token过期,续约(有效期为3天,少于一天自动更新token),文件导入和上传, -用户相关操作等,多环境切换(dev,prod)等 +// 2021-09-15 +1.增加了文件上传下载,为vue3-element-plus提供例子数据 ``` -##### 使用的技术: - +### 前言 ``` +本架构使用的技术为: spring-boot:2.1.4.RELEASE spring-cloud:Greenwich.SR1 spring-cloud-starter-gateway:2.1.1.RELEASE nacos:2.1.3.RELEASE mybatis-plus: 3.3.2 -rabbitmq 等 +rabbitmq:3.7-management +redis: 3.2.9 +mysql:5.7 +``` + +#### swager文档地址: + +http://8.135.1.141/micro-service-doc/swagger-ui.html + +#### nacos地址(naocs配置请不要删除): + +http://8.135.1.141:8848/nacos/ + +用户名:jzfai +密码:123456 + +#### 微服务(后续还会新增新的微服务) + +``` +ty-common: 统一依赖,统一配置管理,feign接口整合等 +本架构的微服务有: +ty-gateway:网关微服务。使用的是spring-cloud-starter-gateway,先对于zull网关来说性能更好。主要实现了,权限控制和拦截,jwt token解析和校验,swagger文件整合,使用令牌技术请求限流等 +ty-auth:权限服务。jwt token生成,解析,校验等,默认配置3天有效期,少于一天自动续约(此处感兴趣的可以查看下源码) +ty-user:用户服务。用户的登录,注册,查看用户信息等一系列功能 +ty-upload:文件上传服务。使用的技术为fastDFS技术,此服务主要用于文件的上传和下载 +``` + +#### 亮点: + +``` +1.在网关中将jwt token和解析后的token信息已经设置在请求头中,在后续转发的微服务可以在请求头中轻松的拿到token和token解析后的数据,不用再通过feign去调用ty-auth获取token信息 +``` + +![1631692199271](http://8.135.1.141/file/images/1631692199271.png) + +``` +2.此时微服务已经可以在请求通中获取到token和信息,但是feign调用其他微服务的时候却出现了token丢失的情况,此时需要在feign调用服务时将请求头一起转发,那么微服务之前调用时也能获取都token和信息 +``` + +![1631692308212](http://8.135.1.141/file/images/1631692308212.png) + +``` +3.少于1天时间自动更新token,主要通过gateway的两个拦截器来完成 +AuthorizeFilterBefore:请求前拦截。解析token的有效性和是否过期,和配置了白名单的请求方法进行放行 +AuthorizeFilterAfter:请求后拦截。主要用于token更新校验,和生产新的token,通过isNeedUpdateToken字段告诉前端要更新token +如果想知道前端如何更新token可查看: +https://github.com/jzfai/vue3-admin-template +``` + +![1631693000767](http://8.135.1.141/file/images/1631693000767.png) + +``` +4.多环境和nacos: +开发人员可以快速的切换环境以达到开发的目的 +目前为止只添加了 +dev:开发时使用的分支 +prod:发布是切换的分支 +注:配置环境时请在nacos上添加相应的配置文件,不然会报错 +nacos: +注册中心: +通过discovery进行配置,具体可查看源码 +配置中心: +加载顺序:naocs默认加载的config配置文件-> shared-configs->extension-configs +优先级:naocs默认加载的config配置文件->extension-configs-> shared-configs +``` + +![1631693866876](http://8.135.1.141/file/images/1631693866876.png) + +![1631694125676](http://8.135.1.141/file/images/1631694125676.png) ``` -#### swagger文档 http://8.135.1.141:30156/swagger-ui.html -#### 感兴趣可以看下 +5.easycode模板配置: +本架构提供了基本的版本生成,可以快速生成,实现前后端的增删改查,前端的easycode生成的模板适配vue-element-template架构,可以把模板直接复制到easycode中生成相应的代码 +不会使用easycode可以查看这里 +https://www.jianshu.com/p/e4192d7c6844 +``` + +![1631695768271](http://8.135.1.141/file/images/1631695768271.png) + +### 如何运行 + +```javascript +克隆项目 +git clone https://github.com/jzfai/micro-service-plus.git +用idea打开项目,加载下载依赖即可运行 +``` + +>注:本项目加入了热更新:运行项目后,使用ctrl+F9快捷键或rebuild下就行直接更新服务 +#### 如果需要实时交流的可以加入wx群(有vue3+ts视频教程) + ![http://8.135.1.141/file/images/wx-groud.png](http://8.135.1.141/file/images/wx-groud.png) +大家的支持是我前进的动力 欢迎加入一起开发 diff --git a/controller.mv b/controller.mv new file mode 100644 index 0000000..8b019d4 --- /dev/null +++ b/controller.mv @@ -0,0 +1,136 @@ +##导入宏定义 +$!init +$!define + +##设置表后缀(宏定义) +#setTableSuffix("Controller") + +##保存文件(宏定义) +#save("/controller", "Controller.java") + +##包路径(宏定义) +#setPackageSuffix("controller") + +##定义服务名 +#set($serviceName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), "Service")) + +##定义实体对象名 +#set($entityName = $!tool.firstLowerCase($!tableInfo.name)) + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.api.ApiController; +import com.baomidou.mybatisplus.extension.api.R; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +##import $!{tableInfo.savePackageName}api.entity.$!tableInfo.name; +import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.io.Serializable; +import java.util.*; + +##表注释(宏定义) +@Api(tags = "$!{tableInfo.comment}($!{tableInfo.name})") +@RestController +@RequestMapping("$!tool.firstLowerCase($!tableInfo.name)") +public class $!{tableInfo.name}Controller { + +@Resource +private $!{tableInfo.name}Service $!{serviceName}; + +/** +* 分页查询所有数据 +* @param $!entityName 查询实体 +* @return 所有数据 +*/ +@GetMapping("selectPage") +@ApiOperation(value = "分页查询所有数据") +public ResResult selectPage($!{tableInfo.name} $!entityName, KHCommonParams khCommonParams) { +QueryWrapper<$!{tableInfo.name}> queryWrapper = new QueryWrapper<>(); +#foreach($column in $tableInfo.fullColumn) + #if( $!column.comment ) + if(ObjectUtils.isNotEmpty($!{entityName}.get$!{tool.firstUpperCase($column.name)}())) { + queryWrapper.or().like("$!{column.name}",$!{entityName}.get$!{tool.firstUpperCase($column.name)}()); + } + #end +#end + +#set($StringBj="") +#foreach($column in $tableInfo.fullColumn) + #if( $!column.comment ) + #set($StringBj=$!{StringBj}+$!{tool.hump2Underline($column.name)}+",") + #end +#end + + +queryWrapper.or().orderByDesc("create_time"); +if(StringUtils.isNotEmpty(commonParams.getStartTime())) { + queryWrapper.or().between("create_time",commonParams.getStartTime(),commonParams.getEndTime()); +} +queryWrapper.select("$StringBj.substring(0,$StringBj.lastIndexOf(','))"); +Page<$!{tableInfo.name}> $!{entityName}Page = this.$!{entityName}Service.selectPage(khCommonParams.getPageNum(), khCommonParams.getPageSize(), queryWrapper); +return new ResResult().success($!{entityName}Page); +} + +/** +* 通过主键查询单条数据 +* @param id 主键 +* @return 单条数据 +*/ +@GetMapping("selectById") +@ApiOperation(value = "通过id主键查询单条数据") +public ResResult selectById(@RequestParam("id") Integer id) { +return new ResResult().success(this.$!{serviceName}.selectById(id)); +} + +/** +* @Description: 根据id数组查询品牌列表 +* @Param: idList id数组 +* @return: ids列表数据 +*/ +@ApiOperation(value = "根据id数组查询品牌列表") +@PostMapping("selectBatchIds") +public ResResult selectBatchIds(@RequestParam("idList") List + idList) { + return new ResResult().success(this.$!{serviceName}.selectBatchIds(idList)); + } + /** + * 新增数据 + * @param $!entityName 实体对象 + * @return 新增结果 + */ + @ApiOperation(value = "新增数据") + @PostMapping("insert") + public ResResult insert(@RequestBody $!{tableInfo.name} $!entityName) { + return new ResResult().success(this.$!{serviceName}.insert($!entityName)); + } + + /** + * 修改数据 + * @param $!entityName 实体对象 + * @return 修改结果 + */ + @ApiOperation(value = "根据id修改数据") + @PutMapping("updateById") + public ResResult updateById(@RequestBody $!{tableInfo.name} $!entityName) { + return new ResResult().success(this.$!{serviceName}.updateById($!entityName)); + } + + /** + * 删除数据 + * @param idList 主键结合 + * @return 删除结果 + */ + @ApiOperation(value = "根据id数组删除数据") + @DeleteMapping("deleteBatchIds") + public ResResult deleteBatchIds(@RequestBody List + idList) { + return new ResResult().success(this.$!{serviceName}.deleteBatchIds(idList)); + } + + @DeleteMapping("deleteById") + @ApiOperation(value = "根据id数组删除数据") + public ResResult deleteById(@RequestParam("id") Integer id) { + return new ResResult().success(this.$!{serviceName}.deleteById(id)); + } + } \ No newline at end of file diff --git a/element-form.mv b/element-form.mv new file mode 100644 index 0000000..01d87bb --- /dev/null +++ b/element-form.mv @@ -0,0 +1,302 @@ +##导入宏定义 +$!init +$!define +##定义实体对象名 +#set($entityName = $!tool.firstLowerCase($!tableInfo.name)) +#set($serviceName = 'ty-user') + +##保存文件(宏定义) +#save($!{entityName}, "Form.vue") + + + + #foreach($column in $tableInfo.otherColumn) + #if(${column.comment}) + ##date + #if( $column.comment.indexOf("date") != -1) + + + + ##datetimerange + #elseif( $column.comment.indexOf("timerange") != -1) + + + + ##select + #elseif( $column.comment.indexOf("select") != -1) + + + #set($lable= $!{column.comment.split(';')[1]}) + #set($indexFirst=$lable.indexOf('(')+1) + #set($selectLableArr=$lable.substring($indexFirst,$lable.indexOf(")")).split(',')) + #foreach($item in $selectLableArr) + #if($item) + + #end + #end + + + ##cascader + #elseif( $column.comment.indexOf("cascader") != -1) + + + + ##upload + #elseif( $column.comment.indexOf("uploadImage") != -1) + + + + + + 上传 + + + {{chooseFileNameMixin}} + + + + ##input + #else + + + + #end + #end + #end + + + + 取 消 + 确 定 + + + + + + + + diff --git a/element-table.mv b/element-table.mv new file mode 100644 index 0000000..69f97a5 --- /dev/null +++ b/element-table.mv @@ -0,0 +1,295 @@ +##导入宏定义 +$!init +$!define +##定义实体对象名 +#set($entityName = $!tool.firstLowerCase($!tableInfo.name)) +#set($serviceName = 'ty-user') + +##保存文件(宏定义) +#save($!{entityName}, ".vue") + + + + 新增 + 删除 + + + #foreach($column in $tableInfo.otherColumn) + #if(${column.comment}) + + + + #end + #end + + + + + 搜索 + + + + + + #foreach($column in $tableInfo.otherColumn) + #if(${column.comment}) + #if( $column.comment.indexOf("select") != -1) + + + #set($lable= $!{column.comment.split(';')[1]}) + #set($indexFirst=$lable.indexOf('(')+1) + #set($selectLableArr=$lable.substring($indexFirst,$lable.indexOf(")")).split(',')) + #foreach($item in $selectLableArr) + #if($item) + $item.split("\.")[1] + #end + #end + + + #else + + #end + #end + #end + + + + 编辑 + 详情 + 删除 + + + + + + + + + + #foreach($column in $tableInfo.otherColumn) + #if(${column.comment}) + + ${column.comment.split(';')[0]}:{{ detailData.$!{column.name} }} + + #end + #end + + + 确 定 + + + + <$!{tableInfo.name}Form ref="ref$!{tableInfo.name}Form"/> + + + + + diff --git a/entity.mv b/entity.mv new file mode 100644 index 0000000..50c90eb --- /dev/null +++ b/entity.mv @@ -0,0 +1,46 @@ +##导入宏定义 +$!init +$!define + +##保存文件(宏定义) +#save("/entity", ".java") + +##包路径(宏定义) +#setPackageSuffix("entity") + +##自动导入包(全局变量) +##$!autoImport +import com.baomidou.mybatisplus.extension.activerecord.Model; +import java.io.Serializable; + +##表注释(宏定义) +#tableComment("表实体类") +@Data +@ApiModel("$!tableInfo.comment") +@TableName(value = "tb_$!{tool.firstLowerCase($tableInfo.name)}") +public class $!{tableInfo.name} extends Model<$!{tableInfo.name}> { +#foreach($column in $tableInfo.fullColumn) + #if( $!column.comment ) + #set($listSize=$!{column.comment.split(';')}) + #if( $!listSize.size() > 0 ) + @ApiModelProperty(value="$!listSize[0]") + #end + #end +private $!{tool.getClsNameByFullName($column.type)} $!{column.name}; +#end +###foreach($column in $tableInfo.fullColumn) +###getSetMethod($column) +###end +#foreach($column in $tableInfo.pkColumn) + /** + * 获取主键值 + * + * @return 主键值 + */ + @Override + protected Serializable pkVal() { + return this.$!column.name; + } + #break +#end +} \ No newline at end of file diff --git a/mapper.mv b/mapper.mv new file mode 100644 index 0000000..ec158b1 --- /dev/null +++ b/mapper.mv @@ -0,0 +1,19 @@ +##导入宏定义 +$!init +$!define + +##设置表后缀(宏定义) +#setTableSuffix("Mapper") + +##保存文件(宏定义) +#save("/mapper", "Mapper.java") + +##包路径(宏定义) +#setPackageSuffix("mapper") + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +##表注释(宏定义) +public interface $!{tableName} extends BaseMapper<$!tableInfo.name> { + +} \ No newline at end of file diff --git a/nacos_config_export_20210915163624.zip b/nacos_config_export_20210915163624.zip new file mode 100644 index 0000000000000000000000000000000000000000..9c9820fd9dd360042a70a6fa890b9834d6db4696 GIT binary patch literal 9322 zcmeHMWmJ`0x29W>Zlu}L-7Q@L8w5nULt@h{UD6;Wn=WaPlrHH8=@bx98j-%>J!c4< z@96jaxntaW&)nl3W3PAY@$5C{TI-q5oJ&Cl8U_;r0RaKxl`kU@;)ao5eYe!rx3Z-- z23gr#(;FB%FzQ-cTbSzW+L>BeUXK}^Us$*Ud*r8uFlWhkQOSoi4dVbSE1EdDBmo}<}l)L?47oe6O)lHHLY+wzjrvw8sb^mQcRKXV&9qG@(G1n z(os?Wc`Rk9>;rnhSGasXHJUlwvD}c?Tw8kN(e|aeYpFdk>WMv~L>kzol$q$0eGoO2 z&(yz}33?ZbU5+?zFR^k#JY`!AZhn?P00J_?#OlFW@(0KMeah|!6o~f+BG!Z1RU!Krr zzBAZ1KN(9I%n`SNC){CJOKmIRSyqh`hV)o^TgJUQVMk+`sJFqxF**$w#pb}CQ{fYo zOcqRVPmVx1kOkO!se|A}HWAS!^?Aj5qidpbAE(u^ReqdGtv;?9zS%BWkz9;Dlm+UA zDjteGV}TQ3A&aZpxq=u>`2BdqD6jXcF9&B)w}<=Kz(Y{?EFQpZe{vF0J8$ zy$v6~#QRXxYG+qMWRzOrBg>c&JsbV0a|`@+OI`8{7e>X9n%G-7x|nn&Tr>*NWN9Qw z4_R9WPSrENhEw6U%8ZFgUmDij!TTQk+f&(Mp|9NbU_@wECyc_fB6hG)u#+iXXPQh@ zQbKQviX)9+tg27VI@&ZGVV$Rv!1CX#8bO(7^Pg7JkO!05{ZN=zE zGyBlUQbNywIv-Jn&=*+iX|gmSnBL>!BdQGzyN{Y#Y81^SK=Nv@6n8nY&zB-6K1;lE zuHmBdO%}#Px{dIIVH^2jlSFI$)YJat%_l9W6&d1%gSmyL@G@IIDprfs#b?TVGqx#p z=KaKk<1$<0{zpqgy60QE=M9%d2o8PU~M#nv76hkzx4vqX(byR@fsTJ5tm@5@yjYsnmlCB6)`r=OGv;?22g z_s$$3SBdXs%-_p+Bzx=>0b$EE0g3c+Qk}z(id5yza9}7KkMQ7n*hK#Ffpg$;J-)*1 z5M?y8T-iE1pbbaC3*dNkST6noh-vjb7Jsx^lP)k8XLrcraJ!`sfTfuGa2&@aI^b}A z2HyPQfN_B~xLDL3t~WUusl2ngh0rI1HMbbqJxr2E4)Z=ahh@^JLdEy$%}+tm)CX=z zwq`Qfs}s68b{2_D)%d`seiVXLj(A;+{el?`qHk~T5HB&fHIYfark9OQxPFuYks0Ij719Nu4hUz6v#F6{H;$p?XxX;0& z4o~eQfXh9IlEXLe{hWpHTw92w5Yvc9B>}n&$soa7>Xq;gd_N>xMk(evg&&@2Vi0_} zW=!R5jadx-UVhbCp}Lj5RBv&+w7mOg)IjkURq91f#g6U6{Jv2j4Rc?AxO3i3J?Fea zg2V0?5$`poz8yUbS=t!X(Qr(ep$ax%vKNl2()k2DHLHRHu)s3`}-!#QfUaq=Jp_Ig2&GDO!rl{_v@P{4uoM zI)8452hXCKUS56)QYPK~@t23Di=RL>3TE^mHIJ=n_V{HroCi^&p)X$%D4AU|nSZW)p zM>|+h^sTE-jl@V#%S6efEqSrB=Fdm#{I;Yi*yZzB>Vd zoGyu_YkKuY7yV4>K^9I7+y0azs9IG8wuYH7XrZ;rk|Fs_VXcGtO=q2Km*r#8$_TaR z0*4|M&E=1Wf%2SB6nn}oMu1c;5Z?Rn*FNP1E|a~ynsNKp^Y?5|`8%Hs4NPsXU7}?G zboa_sEv+ai0Ho!*=-|pRFDoGPothu3!ASS}f{mEChQ*W!)&82qfgnBNZemSTRWN6V}S*g71D> zu26rk#W*?5q)ZfKDNfsbbZdHhse&FdC@5Y9Xq$J{zEMWAZc-VAR^k@n}$R_ z@w6;i^pf26yiK8u(*{GeM0X*K_{^|kBx7uLY_^>)2|r=NfCxx_A&g+2$o;4jhQM2T zcr^7s`@QBjB$aYwf#HPHl%>{A@74yuFw^k5_MCu}ite0?xZ@qiuK5YGBF}|DRqdS( z;NpyFzT3={X2_nFzTuk$&b7P=Qjw{5_9zuAx`=r(sc%gTM2GEznEOGw^1fBskOBg7 z^)6hvWAhma2`G(_Gm6ZiYQvNBw20vIZRb`J z8tZZ+5z}E;l6A6hW!hbf@a>1tKWJJQlrdl*^4TS@$k-<2>i3XU`YMyX$0Ml{%a_qQ zmnf-O@I2W{_Jo6P3SPB%q*iGCxQL)V^;vgQA+^oLc=nEUZH;D)r5ghs$N>d$musLJMh|9d71E1H6nbq4tdmD4t_nkUOj5vyCT6k6uik zCVG6OKFCv_f`hLMQ3o&=$emVDD!fdoero~d=ICpe1IlWC@OK#zis~p@edowj%AH<4 zG&ntY(?H*^1(+Uuk^O zw*0VAVe2sAs~A4EEW0;a57VetCl9W!8n#38eZsjD-Zo{?V^^9K)v0Bwx%+1 zWyGw~j?N#9LxdfV^Ls6Jw?g^LxiI)gjQu0V{t;vUh_U~7VvPEZaQO>0{%=%ccNOMe zo%$b6%niEJo@ZkI|NT)`LrNEqIOSl$0+a#4o?-e zMoxJ$jT*cN@4TDseD79oH*6^c87GfOV5?tmW0%x3n2hXhdMn^F=EB_O!av$?F*p&Q=g2V)dI(4v`7q)F>O?`{zL`Ouj#)q}7y@{Y<#2iTs`9E~9v8fVFUem&P8J{Y@_scIgoh_csZ2thF0Qos zYE@vIus_+jJLd%V`s?5a|loJPI4$a`PwzbGwq@3Ocs^X$gM@7ETpsc+S<8<`3UR&ysRfDr)V4CDJG}v*73Q{zSfSL@nHBf>|&Ez2xyD0 z+?CZpOyW0-F#a8|taw|HQlVM>-wnz5Ah3N-v+W!Cg^;Hv0Q2y_XcXUFg3sD9Ii;95;v4^fwmD5 zMdjB;#(Aw_cuvnwog&rI+eq}~kydr~F(;P}X?6E0FohFXHVLH=EpX+6K{kpZJa1^t z9uPrAU{Tf(b)_%Y1T()&P~@{oUGO8(pz(%Nij+t=g=q1(-18 zSA=?lFYD|sHQn9O#DaL6PdD^peCu%aMp!sD=*~WS(Hid>0t#25MwUri$jTYTm{iVKF-;7c&pG47_V8#NXs=QLb zhU`-;a<}f$4lk9C^#TVhi`K=0DlYdBZ#iUa++9*FFOi2@cGa7RfkY3CHeVYzF+V1X z_~yV$w|-)@X2Q-jLqrthAYVF4h zvIA2AqWy&~=+q)<6K{B8eZKBuxN9=B;TK9l-Wxmm}aOUUcGkOMBDxEvY+ zf(Y?fb>Y8Mp8tvi=KtUTPqj>uXBi=1*!o(9Qx}4jHby%fz|x5M?}tpg*1y$O8LQ(8 zR-0~6OpGGh5C*_-E?~zhaQjhVJ78Y2)DV--NBC0jMrSQ$GQt$3+H zrah5=ummEt-|NEXqAjWeI5($)AYULujprCQRI_k1b1&9-bH4_0T5Kh4;E-N{W>P+< z3_4Nc7*LvCXxW^K@ZMD4`V_x{OoQimq9DTHmI6*ZSrloEjG#cYv|^(jvtFafy%;JW zOK6}-0zTBlX8A)l&|hQovV_)F&4ex zP-CBe*38tGvAnaL@+?UMml1Uow)2}Xj&%#|myCE&=}E6=8x&cA{rD6b76 z&SaTH;4`|_00A9Xd}^AYY<8$VZ&??VOi2P0`fSdk!1$O?+6V!`BGat=M_Q+M_4q2N*|++QZr4uYpCkV zD(=lKYP$2sc(omp+^5&cXJ`o*Z~~!eb9_KTfsQcXvu&M?D?Cr$8G~yc3e~UDnzfvJ zTLC_M=IM%kR`$eNXWZO4G+@OEyu{b5INB?gXT_kPdrvMaNnseqX(o(8FiNt>y=%rQ z?cD@NA?p1a01?Dow(L z8%Sa6pmD8(xdIzCYm;%fa@GNIAX=HG)7T1_F?B7F=|hP-1`mq85dLWeAZz-4UwPlo zfi;M%=#5^UGw~Q+PQ7a8YgjTvP^*mCi!uc4{Xro8Dwh_)BUCKobSc&zIZ4D766r@8 zS9CBJ_oz-=sB`lz=d#3J(t=6R0s~aREFu&kfI*^@ef7JdmNA1in5wI~g|&GxWpQqE zd`__W+%?o^-sk;vD2_yP^777*43_-4SP;8;uDV~FY7rB3k)kTKxy`dF{&2q!tr%qW zXM9eTagz3mW3GV#;T)Se#hYWUhn$U+WKQRT*KE*xstvBcVgu%1vcX+la`&dp-rB-S z_eX<9Mn;OZ@<)@X|08`@uUsD^eW?-?8#|M-!c(Wx!o$gf7eWW16YPknPiJ*?qo2@y zc~}F>&iBEG^kS;dqZAX9GLsUL;=yLH$_H)(-D|)&f#iBrikwshaDq}4Bnw1KpJbox z0KjWkCKx@s92jC}%Mv0Z(e0AnvyH}(fqJP2DVA3O=kM?TquurH!+`1Ol`>_8 z{1v(WR=fTa&;KZ%1b1qI>+N}!t90${On$U3<>_f;=*xcW%1%a_QYD2v`94}&zz}WM zfSf!XB1AAOX4W`9Eii|(kN(_Uyqm50Yij*zObEZm`&rc9#k|>Qzi#UPG?*)D z|J58pf7Xc@nao>(4Ams@hdM6Luo!w2KYufy2 gW5l + + + + + + 新增 + 批量删除 + + + + + #foreach($column in $tableInfo.otherColumn) + #if(${column.comment}) + + + + #end + #end + + 搜索 + + + + + + + + #foreach($column in $tableInfo.otherColumn) + #if(${column.comment}) + + #end + #end + + + + + 编辑 + + + 删除 + + + + + + + + + + + + #foreach($column in $tableInfo.otherColumn) + #if(${column.comment}) + #if( $column.comment.indexOf("time") != -1 || $column.name.indexOf("Time") != -1 ) + + + + + #elseif( $column.comment.indexOf("upload") != -1 || $column.name.indexOf("image") != -1) + + + + + + 将文件拖到此处,或点击上传 + 只能上传jpg/png文件,且不超过2M + + 上传 + + #elseif( $column.comment.indexOf("option") != -1 ) + + + + + + + #elseif( $column.comment.indexOf("checkbox") != -1 ) + + + {{item.name}} + + + + #elseif( $column.comment.indexOf("radio") != -1 ) + + + 昨日 + 今日 + + + #else + + + + #end + #end + #end + + + 取 消 + 确 定 + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index ee3bcb9..b3cec92 100644 --- a/pom.xml +++ b/pom.xml @@ -13,6 +13,7 @@ ty-gateway ty-auth ty-user + ty-upload @@ -117,5 +118,22 @@ 123456 + + + + + + + + + + + + + + + + + diff --git a/service.mv b/service.mv new file mode 100644 index 0000000..4658d24 --- /dev/null +++ b/service.mv @@ -0,0 +1,54 @@ +##导入宏定义 +$!init +$!define + +##设置表后缀(宏定义) +#setTableSuffix("Service") + +##保存文件(宏定义) +#save("/service", "Service.java") +##定义服务名 +##定义实体对象名 +#set($entityName = $!tool.firstLowerCase($!tableInfo.name)) +##包路径(宏定义) +#setPackageSuffix("service") +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +/** +* ($!{tableInfo.name}) +* @author kuanghua +* @since $time.currTime() +*/ +@Service +public class $!{tableInfo.name}Service{ + + @Resource + private $!{tableInfo.name}Mapper $!{entityName}Mapper; + + public Page<$!{tableInfo.name}> selectPage(Integer pageNum, Integer pageSize, QueryWrapper<$!{tableInfo.name}> queryWrapper) { + return this.$!{entityName}Mapper.selectPage(new Page<$!{tableInfo.name}>(pageNum, pageSize),queryWrapper); + } + + public $!{tableInfo.name} selectById(Integer id) { + return this.$!{entityName}Mapper.selectById(id); + } + + public List<$!{tableInfo.name}> selectBatchIds(List idList) { + return this.$!{entityName}Mapper.selectBatchIds(idList); + } + + public int insert($!{tableInfo.name} $!{entityName}) { + return this.$!{entityName}Mapper.insert($!{entityName}); + } + + public int updateById($!{tableInfo.name} $!{entityName}) { + return this.$!{entityName}Mapper.updateById($!{entityName}); + } + + public int deleteById(Integer id) { + return this.$!{entityName}Mapper.deleteById(id); + } + + public int deleteBatchIds(List idList) { + return this.$!{entityName}Mapper.deleteBatchIds(idList); + } +} \ No newline at end of file diff --git a/ty-auth/src/main/java/top/kuanghua/tyauth/config/Swagger2Config.java b/ty-auth/src/main/java/top/kuanghua/tyauth/config/Swagger2Config.java index 24084cd..a7913b0 100644 --- a/ty-auth/src/main/java/top/kuanghua/tyauth/config/Swagger2Config.java +++ b/ty-auth/src/main/java/top/kuanghua/tyauth/config/Swagger2Config.java @@ -43,9 +43,9 @@ public Docket api() { private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("标题:kuanghua") - .description("描述:自定义的一个项目") + .description("描述:新一代的前端架构") .contact(new Contact("jzfai", null, "869653722@qq.com")) - .version("版本号:2.8") + .version("版本号:2.9") .build(); } /** diff --git a/ty-auth/src/main/java/top/kuanghua/tyauth/utils/JwtUtilsSelf.java b/ty-auth/src/main/java/top/kuanghua/tyauth/utils/JwtUtilsSelf.java index 09ed103..bd38ef3 100644 --- a/ty-auth/src/main/java/top/kuanghua/tyauth/utils/JwtUtilsSelf.java +++ b/ty-auth/src/main/java/top/kuanghua/tyauth/utils/JwtUtilsSelf.java @@ -20,12 +20,12 @@ * @since 1.0 */ public class JwtUtilsSelf { - //有效期为 - public static final Long JWT_TTL = 3600000L;// 60 * 60 *1000 一个小时 + //https://www.cnblogs.com/passedbylove/p/11207827.html + //有效期为 + public static final Long JWT_TTL = 259200000L;//60 * 60 * 1000 * 24 * 3 三天 //Jwt令牌信息 - public static final String JWT_KEY = "@Kuanghua8866"; - + public static final String JWT_KEY = "kh@Login(Auth}*^31)&kuanghua%"; /** * 生成令牌 //* @param id diff --git a/ty-auth/src/main/resources/application.yml b/ty-auth/src/main/resources/application.yml index 665ff63..8290243 100644 --- a/ty-auth/src/main/resources/application.yml +++ b/ty-auth/src/main/resources/application.yml @@ -1,10 +1,9 @@ -server: - port: ${envpt.tomcatPortPre}0131 - -#jwt相关 -jwt-properties: - secret: ruixiude@Login(Auth}*^31)&kuanghua% # 登录校验的密钥(盐) - expire: 4320 # 过期时间,单位分钟 - cookieName: KH_TOKEN - cookieMaxAge: 1800 +#server: +# port: ${envpt.tomcatPortPre}0131 +# +##jwt相关 +#jwt-properties: +# secret: kh@Login(Auth}*^31)&kuanghua% # 登录校验的密钥(盐) +# # 60 * 60 * 1000 * 24 * 3 三天 +# expire: 259200000L; diff --git a/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/config/SwaggerDocConfig.java b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/config/SwaggerDocConfig.java new file mode 100644 index 0000000..6a125b4 --- /dev/null +++ b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/config/SwaggerDocConfig.java @@ -0,0 +1,21 @@ +package top.kuanghua.gatewaytwo.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; + +import java.util.*; +/** + * @Title: SwaggerDocConfig + * @Description: + * @Auther: kuanghua + * @create 2021/9/14 13:36 + */ + +@Component +@ConfigurationProperties(prefix = "swagger-doc") +@Data +public class SwaggerDocConfig { + private Map serviceMap; +} diff --git a/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/config/SwaggerProvider.java b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/config/SwaggerProvider.java index 81f200b..6cee91e 100644 --- a/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/config/SwaggerProvider.java +++ b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/config/SwaggerProvider.java @@ -21,9 +21,12 @@ @AllArgsConstructor public class SwaggerProvider implements SwaggerResourcesProvider { - public static final String API_URI = "/v2/api-docs"; + static final String API_URI = "/v2/api-docs"; private final RouteLocator routeLocator; private final GatewayProperties gatewayProperties; + + + private SwaggerDocConfig swaggerDocConfig; /** * @return */ @@ -31,16 +34,22 @@ public class SwaggerProvider implements SwaggerResourcesProvider { public List get() { List resources = new ArrayList<>(); //List routes = new ArrayList<>(); - routeLocator.getRoutes().subscribe(route -> { + swaggerDocConfig.getServiceMap().entrySet().stream().forEach(mapEntry -> { + /*设置swagger服务路径*/ + resources.add(createResource(mapEntry.getValue().toString(), mapEntry.getKey(), "2.9")); + }); + +// routeLocator.getRoutes().subscribe(route -> { // System.out.println("routeLocator"); // System.out.println(route); - }); - gatewayProperties.getRoutes().stream().forEach(item -> { +// route.getId(); +// }); +// gatewayProperties.getRoutes().stream().forEach(item -> { // System.out.println("gatewayProperties"); +// item.getId(); // System.out.println(item); - }); - /*设置swagger服务路径*/ - resources.add(createResource("用户模块", "ty-user", "2.9")); +// }); + return resources; } diff --git a/ty-gateway/ty-gateway-one/src/main/resources/application.yml b/ty-gateway/ty-gateway-one/src/main/resources/application.yml index 9492c9a..bb642e0 100644 --- a/ty-gateway/ty-gateway-one/src/main/resources/application.yml +++ b/ty-gateway/ty-gateway-one/src/main/resources/application.yml @@ -4,24 +4,24 @@ #spring: # cloud: # gateway: -## globalcors: -## corsConfigurations: -## '[/**]': -## # 允许携带认证信息 -## # 允许跨域的源(网站域名/ip),设置*为全部 -## # 允许跨域请求里的head字段,设置*为全部 -## # 允许跨域的method, 默认为GET和OPTIONS,设置*为全部 -## # 跨域允许的有效期 -## allow-credentials: true -## allowed-origins: "*" -## allowed-headers: "*" -## allowed-methods: -## - OPTIONS -## - GET -## - POST -## - PUT -## - DELETE -## #max-age: 3600 +# globalcors: +# corsConfigurations: +# '[/**]': +# # 允许携带认证信息 +# # 允许跨域的源(网站域名/ip),设置*为全部 +# # 允许跨域请求里的head字段,设置*为全部 +# # 允许跨域的method, 默认为GET和OPTIONS,设置*为全部 +# # 跨域允许的有效期 +# allow-credentials: true +# allowed-origins: "*" +# allowed-headers: "*" +# allowed-methods: +# - OPTIONS +# - GET +# - POST +# - PUT +# - DELETE +# #max-age: 3600 # routes: # - id: ty-auth # uri: lb://ty-auth @@ -51,6 +51,13 @@ # filters: # - StripPrefix=2 # +# - id: ty-upload +# uri: lb://ty-upload +# predicates: +# - Path=/api/ty-upload/** +# filters: +# - StripPrefix=2 +# ## - id: fai_search_route ## uri: lb://search ## predicates: @@ -81,3 +88,9 @@ # #token-properties: # renewTokenMinute: 1440 #默认1天时间告知前端刷新token +# +#swagger-doc: +# serviceMap: { +# ty-user: "用户模块", +# ty-upload: "文件上传" +# } \ No newline at end of file diff --git a/ty-upload/pom.xml b/ty-upload/pom.xml new file mode 100644 index 0000000..cf71082 --- /dev/null +++ b/ty-upload/pom.xml @@ -0,0 +1,50 @@ + + + + micro-service-plus + top.kuanghua + 1.0-SNAPSHOT + + 4.0.0 + + ty-upload + + + top.kuanghua + ty-common + 1.0-SNAPSHOT + + + com.github.tobato + fastdfs-client + 1.27.2 + + + + + ${project.artifactId} + + + src/main/resources + true + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.1 + + true + + + + + + \ No newline at end of file diff --git a/ty-upload/src/main/java/top/kuanghua/tyupload/UploadApplication.java b/ty-upload/src/main/java/top/kuanghua/tyupload/UploadApplication.java new file mode 100644 index 0000000..cb54be9 --- /dev/null +++ b/ty-upload/src/main/java/top/kuanghua/tyupload/UploadApplication.java @@ -0,0 +1,18 @@ +package top.kuanghua.tyupload; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; + +/** + * @Title: SmsApplication + * @Description: + * @Auther: + * @create 2020/8/20 10:46 + */ +@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) +public class UploadApplication { + public static void main(String[] args) { + SpringApplication.run(UploadApplication.class, args); + } +} diff --git a/ty-upload/src/main/java/top/kuanghua/tyupload/config/BaseConfig.java b/ty-upload/src/main/java/top/kuanghua/tyupload/config/BaseConfig.java new file mode 100644 index 0000000..d8d6063 --- /dev/null +++ b/ty-upload/src/main/java/top/kuanghua/tyupload/config/BaseConfig.java @@ -0,0 +1,21 @@ +package top.kuanghua.tyupload.config; + +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +/** + * @Title: BaseConfig + * @Description: + * @Auther: kuanghua + * @create 2020/8/23 21:52 + */ +/* + * 总结:1.@Configuration 下的@ComponentScan回将包下带有@Component扫描变成配置类, + * 而@SpringBootApplication扫描的只会变成普通类 + * */ +@Configuration +//dao包扫描 +@ComponentScan(basePackages = {"top.kuanghua.khcomomon"}) +@EnableFeignClients(basePackages = {"top.kuanghua.feign"}) +public class BaseConfig {} diff --git a/ty-upload/src/main/java/top/kuanghua/tyupload/config/Swagger2Config.java b/ty-upload/src/main/java/top/kuanghua/tyupload/config/Swagger2Config.java new file mode 100644 index 0000000..106aedf --- /dev/null +++ b/ty-upload/src/main/java/top/kuanghua/tyupload/config/Swagger2Config.java @@ -0,0 +1,52 @@ +package top.kuanghua.tyupload.config; + +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.stereotype.Component; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Component +@EnableSwagger2 //开启在线接口文档 +//配置包扫描 +public class Swagger2Config { + private boolean swagger_is_enable = true; + +// @Value("${.ipAddr}") +// private String ipAddr; + @Value("${server.port}") + private String port; + + @Bean + public Docket api() { + return new Docket(DocumentationType.SWAGGER_2) + .enable(swagger_is_enable) + //.host(this.ipAddr + ":" + this.port) + .apiInfo(apiInfo()) + .select() + .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) + //.apis(basePackage("top.kuanghua.swagger.controller")) + .paths(PathSelectors.any()) + .build(); + } + + /** + * 构建 api文档的详细信息函数 + * @return + */ + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("标题:kuanghua") + .description("描述:新一代的前端架构") + .contact(new Contact("jzfai", null, "869653722@qq.com")) + .version("版本号:2.9") + .build(); + } +} diff --git a/ty-upload/src/main/java/top/kuanghua/tyupload/controller/NacosTestDemo.java b/ty-upload/src/main/java/top/kuanghua/tyupload/controller/NacosTestDemo.java new file mode 100644 index 0000000..61a872d --- /dev/null +++ b/ty-upload/src/main/java/top/kuanghua/tyupload/controller/NacosTestDemo.java @@ -0,0 +1,44 @@ +package top.kuanghua.tyupload.controller; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +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 top.kuanghua.feign.tyauth.feign.TokenFeign; +import top.kuanghua.khcomomon.entity.ResResult; + +import java.util.HashMap; + +/** + * @Title: NacosTestDemo + * @Description: + * @Auther: kuanghua + * @create 2021/5/12 11:16 + */ + +@Api("nacos测试") +@RequestMapping("NacosTestDemo") +@RestController +public class NacosTestDemo { + @Autowired + private TokenFeign tokenFeign; + @ApiOperation("第一个") + @GetMapping("test") + public ResResult test(){ + HashMap hashMap = new HashMap(); + hashMap.put("username","邝华"); + ResResult resResult = tokenFeign.generateToken(hashMap); + System.out.println(resResult); + return resResult; + } + + @ApiOperation("第二个") + @GetMapping("test2") + public ResResult test2(String token){ + ResResult resResult = tokenFeign.parseToken(token); + System.out.println(resResult); + return resResult; + } +} diff --git a/ty-upload/src/main/java/top/kuanghua/tyupload/controller/UploadController.java b/ty-upload/src/main/java/top/kuanghua/tyupload/controller/UploadController.java new file mode 100644 index 0000000..86d6752 --- /dev/null +++ b/ty-upload/src/main/java/top/kuanghua/tyupload/controller/UploadController.java @@ -0,0 +1,83 @@ +package top.kuanghua.tyupload.controller; + +import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; +import top.kuanghua.khcomomon.entity.ResResult; +import top.kuanghua.tyupload.service.UploadService; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; + +/** + * @Title: UploadController @Description: @Auther:jzfai @Version: 1.0 + * @create 2020/3/4 21:58 + */ +@RestController +@RequestMapping("upload") +@Api(tags = "图片上传") +@DefaultProperties(defaultFallback = "fallBackMethod") // 指定一个类的全局熔断方法 + +@RefreshScope +public class UploadController { + + @Autowired + private UploadService uploadService; + + @ApiOperation(value = "上传图片", notes = "上传图片接口") + @PostMapping("image") + public ResResult uploadImage(@RequestParam("file") MultipartFile file) + throws IOException, InterruptedException { + String url = this.uploadService.upload(file); + // Thread.sleep(5000); + HashMap map = new HashMap<>(); + map.put("shortPath",url); + return new ResResult().success(map); + } +// +// @ApiOperation(value = "上传图片(多张)") +// @PostMapping("uploadGetMetaData") +// public ResResult uploadGetMetaData(@RequestParam("files") MultipartFile[] files) +// throws IOException, InterruptedException { +// ArrayList strings = new ArrayList<>(); +// for (MultipartFile file : files) { +// Map stringStringMap = this.uploadService.uploadGetMetaData(file); +// strings.add(stringStringMap); +// } +// //Thread.sleep(5000); +// return new ResResult().success(strings); +// } + @ApiOperation(value = "批量上传文件") + @PostMapping("files") + public ResResult uploadFileList(@RequestParam("files") MultipartFile[] files) throws IOException { + ArrayList strings = new ArrayList<>(); + for (MultipartFile file : files) { + String url = this.uploadService.upload(file); + strings.add(url); + } + return new ResResult().success(strings); + } + + public String fallBackMethod() { + return "请求繁忙,请稍后再试!"; + } + +// @Value(value = "${demo.a}") +// private String data12; +// @Value(value = "${demo.b}") +// private String datas; +// @ApiOperation(value = "test") +// @GetMapping("test") +// public String test() { +// System.out.println("data :" + data12 + ",datas="+datas); +// return "data :" + data12 + ",datas="+datas; +// } +} diff --git a/ty-upload/src/main/java/top/kuanghua/tyupload/service/UploadService.java b/ty-upload/src/main/java/top/kuanghua/tyupload/service/UploadService.java new file mode 100644 index 0000000..78d580d --- /dev/null +++ b/ty-upload/src/main/java/top/kuanghua/tyupload/service/UploadService.java @@ -0,0 +1,90 @@ +package top.kuanghua.tyupload.service; + + +import com.alibaba.fastjson.JSON; +import com.github.tobato.fastdfs.domain.fdfs.MetaData; +import com.github.tobato.fastdfs.domain.fdfs.StorePath; +import com.github.tobato.fastdfs.service.FastFileStorageClient; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.util.*; + +/** + * @Title: UploadService + * @Description: + * @Auther:jzfai + * @Version: 1.0 + * @create 2020/3/4 21:58 + */ +@Service +@Slf4j +public class UploadService { + + @Autowired + private FastFileStorageClient storageClient; + + private static final List CONTENT_TYPES = Arrays.asList("image/jpeg", "image/gif"); + + public String upload(MultipartFile file) throws IOException { + String originalFilename = file.getOriginalFilename(); + //检验文件类型 + String contentType = file.getContentType(); + if (!CONTENT_TYPES.contains(contentType)) { + //文件类型不合法 + log.info("文件类型不合法:{}", originalFilename); + } + //检验文件内容 + BufferedImage bufferedImage = ImageIO.read(file.getInputStream()); + if (bufferedImage == null) { + log.info("文件内容不合法:{}", originalFilename); + } + //保存到服务器 + //file.transferTo(new File("D:\\java\\javaproject\\pinyou\\pinyou-upload\\src\\main\\resources\\static\\" + originalFilename)); + //上传到FastDfs + String ext = StringUtils.substringAfterLast(originalFilename, "."); + HashSet metaData = new HashSet<>(); + metaData.add(new MetaData("name", file.getOriginalFilename())); + metaData.add(new MetaData("createTime", JSON.toJSONString(new Date()))); + StorePath storePath = this.storageClient.uploadFile(file.getInputStream(), file.getSize(), ext, metaData); + return storePath.getFullPath(); + } + + public Map uploadGetMetaData(MultipartFile file) throws IOException { + String originalFilename = file.getOriginalFilename(); + //检验文件类型 + String contentType = file.getContentType(); + if (!CONTENT_TYPES.contains(contentType)) { + //文件类型不合法 + log.info("文件类型不合法:{}", originalFilename); + } + //检验文件内容 + BufferedImage bufferedImage = ImageIO.read(file.getInputStream()); + if (bufferedImage == null) { + log.info("文件内容不合法:{}", originalFilename); + } + //保存到服务器 + //file.transferTo(new File("D:\\java\\javaproject\\pinyou\\pinyou-upload\\src\\main\\resources\\static\\" + originalFilename)); + //上传到FastDfs + String ext = StringUtils.substringAfterLast(originalFilename, "."); + HashSet metaData = new HashSet<>(); + metaData.add(new MetaData("name", file.getOriginalFilename())); + StorePath storePath = this.storageClient.uploadFile(file.getInputStream(), file.getSize(), ext, metaData); + //获取数据源信息 + Set metadata = this.storageClient.getMetadata(storePath.getGroup(), storePath.getPath()); + ArrayList metaDataArrayList = new ArrayList<>(metadata); + String name = metaDataArrayList.get(0).getValue(); + //拼接name和url返回 + Map hashMap = new HashMap<>(); + hashMap.put("name", name); + hashMap.put("url", storePath.getFullPath()); + System.out.println(hashMap); + return hashMap; + } +} diff --git a/ty-upload/src/main/javabrandE/BrandE.vue b/ty-upload/src/main/javabrandE/BrandE.vue new file mode 100644 index 0000000..070a2e6 --- /dev/null +++ b/ty-upload/src/main/javabrandE/BrandE.vue @@ -0,0 +1,266 @@ + + + + 新增 + 删除 + + + + + + + + + + 查询 + + + + + + + + + + + + + 编辑 + 详情 + 删除 + + + + + + + + + + + DBC文件名:{{ detailData.username }} + + + 状态: 启用 + 状态: 停用 + + + 说明:{{ detailData.remark }} + + + + 确 定 + + + + + + + + + + diff --git a/ty-upload/src/main/javabrandE/BrandEForm.vue b/ty-upload/src/main/javabrandE/BrandEForm.vue new file mode 100644 index 0000000..b212c74 --- /dev/null +++ b/ty-upload/src/main/javabrandE/BrandEForm.vue @@ -0,0 +1,227 @@ + + + + + + + + + + + + + + + + + + + 取 消 + 确 定 + + + + + + + + + diff --git a/ty-upload/src/main/main11.iml b/ty-upload/src/main/main11.iml new file mode 100644 index 0000000..f608aea --- /dev/null +++ b/ty-upload/src/main/main11.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/ty-upload/src/main/resources/application.yml b/ty-upload/src/main/resources/application.yml new file mode 100644 index 0000000..e69de29 diff --git a/ty-upload/src/main/resources/bootstrap.yml b/ty-upload/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..19f67dc --- /dev/null +++ b/ty-upload/src/main/resources/bootstrap.yml @@ -0,0 +1,35 @@ +spring: + application: + name: @project.artifactId@ + profiles: + active: @activatedProperties@ + cloud: + nacos: + config: + enabled: true + namespace: @nacosNamespace@ + group: @nacosGroup@ + username: @nacosUsername@ + password: @nacosPassword@ + server-addr: @nacosIpPort@ + prefix: @project.artifactId@ + file-extension: yml + # 用于共享的配置文件 + shared-configs: + - data-id: application-@activatedProperties@.yml + group: @nacosGroup@ + refresh: true + extension-configs: + - data-id: @project.artifactId@.yml + group: @nacosGroup@ + refresh: true + - data-id: application-upload.yml + group: @nacosGroup@ + refresh: true + discovery: + namespace: @nacosNamespace@ + group: @nacosGroup@ + username: @nacosUsername@ + password: @nacosPassword@ + server-addr: @nacosIpPort@ + weight: @nacosWeight@ \ No newline at end of file diff --git a/ty-upload/src/test/java/top/kuanghua/tyupload/controller/UploadControllerTest.java b/ty-upload/src/test/java/top/kuanghua/tyupload/controller/UploadControllerTest.java new file mode 100644 index 0000000..9134a1d --- /dev/null +++ b/ty-upload/src/test/java/top/kuanghua/tyupload/controller/UploadControllerTest.java @@ -0,0 +1,28 @@ +package top.kuanghua.tyupload.controller; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.HashMap; +import java.util.Map; + +/** + * @Title: UploadControllerTest @Description: @Auther: kuanghua + * @create 2020/8/20 21:34 + */ +@SpringBootTest +@RunWith(SpringRunner.class) +class UploadControllerTest { + + @Autowired + private UploadControllerTest uploadControllerTest; + + @Test + void uploadImage() { + Map hashMap = new HashMap<>(); + hashMap.put("", ""); + } +} diff --git a/ty-upload/src/test/test2.iml b/ty-upload/src/test/test2.iml new file mode 100644 index 0000000..a0e49a3 --- /dev/null +++ b/ty-upload/src/test/test2.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/ty-upload/ty-upload.iml b/ty-upload/ty-upload.iml new file mode 100644 index 0000000..44ed24d --- /dev/null +++ b/ty-upload/ty-upload.iml @@ -0,0 +1,230 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/controller/BrandController.java b/ty-user/src/main/java/top/kuanghua/tyuser/controller/BrandController.java new file mode 100644 index 0000000..ab88940 --- /dev/null +++ b/ty-user/src/main/java/top/kuanghua/tyuser/controller/BrandController.java @@ -0,0 +1,129 @@ +package top.kuanghua.tyuser.controller; + + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.baomidou.mybatisplus.extension.api.ApiController; +import com.baomidou.mybatisplus.extension.api.R; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import top.kuanghua.khcomomon.entity.KHCommonParams; +import top.kuanghua.khcomomon.entity.ResResult; +import top.kuanghua.tyuser.entity.Brand; +import top.kuanghua.tyuser.service.BrandService; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.io.Serializable; +import java.util.*; + +@Api(tags = "品牌表(Brand)") +@RestController +@RequestMapping("brand") +public class BrandController { + + @Resource + private BrandService brandService; + + /** + * 分页查询所有数据 + * + * @param brand 查询实体 + * @return 所有数据 + */ + @GetMapping("selectPage") + @ApiOperation(value = "分页查询所有数据") + public ResResult selectPage(Brand brand, KHCommonParams commonParams) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (ObjectUtils.isNotEmpty(brand.getId())) { + queryWrapper.or().like("id", brand.getId()); + } + if (ObjectUtils.isNotEmpty(brand.getName())) { + queryWrapper.or().like("name", brand.getName()); + } + if (ObjectUtils.isNotEmpty(brand.getImage())) { + queryWrapper.or().like("image", brand.getImage()); + } + if (ObjectUtils.isNotEmpty(brand.getLetter())) { + queryWrapper.or().like("letter", brand.getLetter()); + } + if (ObjectUtils.isNotEmpty(brand.getSeq())) { + queryWrapper.or().like("seq", brand.getSeq()); + } + queryWrapper.or().orderByDesc("create_time"); + if(StringUtils.isNotEmpty(commonParams.getStartTime())) { + queryWrapper.or().between("create_time",commonParams.getStartTime(),commonParams.getEndTime()); + } + queryWrapper.select("id,name,image,letter,seq,create_time,update_time"); + Page brandPage = this.brandService.selectPage(commonParams.getPageNum(), commonParams.getPageSize(), queryWrapper); + return new ResResult().success(brandPage); + } + + /** + * 通过主键查询单条数据 + * + * @param id 主键 + * @return 单条数据 + */ + @GetMapping("selectById") + @ApiOperation(value = "通过id主键查询单条数据") + public ResResult selectById(@RequestParam("id") Integer id) { + return new ResResult().success(this.brandService.selectById(id)); + } + + /** + * @Description: 根据id数组查询品牌列表 + * @Param: idList id数组 + * @return: ids列表数据 + */ + @ApiOperation(value = "根据id数组查询品牌列表") + @PostMapping("selectBatchIds") + public ResResult selectBatchIds(@RequestParam("idList") List idList) { + return new ResResult().success(this.brandService.selectBatchIds(idList)); + } + + + /** + * 新增数据 + * + * @param brand 实体对象 + * @return 新增结果 + */ + @ApiOperation(value = "新增数据") + @PostMapping("insert") + public ResResult insert(@RequestBody Brand brand) { + return new ResResult().success(this.brandService.insert(brand)); + } + + /** + * 修改数据 + * + * @param brand 实体对象 + * @return 修改结果 + */ + @ApiOperation(value = "根据id修改数据") + @PutMapping("updateById") + public ResResult updateById(@RequestBody Brand brand) { + return new ResResult().success(this.brandService.updateById(brand)); + } + + /** + * 删除数据 + * + * @param idList 主键结合 + * @return 删除结果 + */ + @ApiOperation(value = "根据id数组删除数据") + @DeleteMapping("deleteBatchIds") + public ResResult deleteBatchIds(@RequestBody List idList) { + return new ResResult().success(this.brandService.deleteBatchIds(idList)); + } + + @DeleteMapping("deleteById") + @ApiOperation(value = "根据id数组删除数据") + public ResResult deleteById(@RequestParam("id") Integer id) { + return new ResResult().success(this.brandService.deleteById(id)); + } +} diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/controller/UserController.java b/ty-user/src/main/java/top/kuanghua/tyuser/controller/UserController.java index 23f7127..8194a24 100644 --- a/ty-user/src/main/java/top/kuanghua/tyuser/controller/UserController.java +++ b/ty-user/src/main/java/top/kuanghua/tyuser/controller/UserController.java @@ -24,6 +24,7 @@ import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.HashMap; +import java.util.List; import java.util.Map; @Api(tags = "用户相关") @@ -71,11 +72,11 @@ public ResResult selectPage(User user, KHCommonParams commonParams) { * @param id 主键 * @return 单条数据 */ -// @GetMapping("selectById") -// @ApiOperation(value = "通过id主键查询单条数据") -// public ResResult selectById(@RequestParam("id") Integer id) { -// return new ResResult().success(this.userMapper.selectById(id)); -// } + @GetMapping("selectById") + @ApiOperation(value = "通过id主键查询单条数据") + public ResResult selectById(@RequestParam("id") Integer id) { + return new ResResult().success(this.userMapper.selectById(id)); + } // // /** // * @Description: 根据id数组查询品牌列表 @@ -120,16 +121,16 @@ public ResResult insert(@Valid @RequestBody User user) { // * @param idList 主键结合 // * @return 删除结果 // */ -// @ApiOperation(value = "根据id数组删除数据") -// @DeleteMapping("deleteBatchIds") -// public ResResult deleteBatchIds(@RequestBody List idList) { -// return new ResResult().success(this.userMapper.deleteBatchIds(idList)); -// } -// @DeleteMapping("deleteById") -// @ApiOperation(value = "根据id删除数据") -// public ResResult deleteById(@RequestParam("id") Integer id) { -// return new ResResult().success(this.userMapper.deleteById(id)); -// } + @ApiOperation(value = "根据id数组删除数据") + @DeleteMapping("deleteBatchIds") + public ResResult deleteBatchIds(@RequestBody List idList) { + return new ResResult().success(this.userMapper.deleteBatchIds(idList)); + } + @DeleteMapping("deleteById") + @ApiOperation(value = "根据id删除数据") + public ResResult deleteById(@RequestParam("id") Integer id) { + return new ResResult().success(this.userMapper.deleteById(id)); + } @PostMapping("registry") @ApiOperation(value = "用户注册") diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/element/Access.vue b/ty-user/src/main/java/top/kuanghua/tyuser/element/Access.vue deleted file mode 100644 index b384c8d..0000000 --- a/ty-user/src/main/java/top/kuanghua/tyuser/element/Access.vue +++ /dev/null @@ -1,536 +0,0 @@ - - - - - - - 新增 - 删除 - - - - - - - - - - - - - - - - - - - - - - - 查询 - - - - - - - - - - - - - - - - 编辑 - 详情 - 删除 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 取 消 - 确 定 - - - - - 这里是标题 - - 权限名称:{{detailData.name}} - 是否删除:{{detailData.isDelete}} - 更新时间:{{detailData.updatedTime}} - 创建时间:{{detailData.createdTime}} - 父id:{{detailData.parentId}} - 是否是父类:{{detailData.isParent}} - - - 确 定 - - - - - - - - - - - \ No newline at end of file diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/element/User.vue b/ty-user/src/main/java/top/kuanghua/tyuser/element/User.vue deleted file mode 100644 index 0f5ecef..0000000 --- a/ty-user/src/main/java/top/kuanghua/tyuser/element/User.vue +++ /dev/null @@ -1,617 +0,0 @@ - - - - - - - 新增 - 删除 - - 上传 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 查询 - - - - - - - - - - - - - - 已删除 - 未删除 - - - - - - 编辑 - 详情 - 删除 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 取 消 - 确 定 - - - - - 这里是标题 - - 用户名:{{detailData.username}} - 密码:{{detailData.password}} - 电话:{{detailData.phone}} - 创建时间:{{detailData.createTime}} - 更新时间:{{detailData.updateTime}} - 是否删除:{{detailData.isDelete}} - - - 确 定 - - - - - - - - - - - \ No newline at end of file diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/entity/Brand.java b/ty-user/src/main/java/top/kuanghua/tyuser/entity/Brand.java new file mode 100644 index 0000000..272face --- /dev/null +++ b/ty-user/src/main/java/top/kuanghua/tyuser/entity/Brand.java @@ -0,0 +1,50 @@ +package top.kuanghua.tyuser.entity; + +import java.util.Date; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.activerecord.Model; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +/** + * 品牌表(Brand)表实体类 + * + * @author kuanghua + * @since 2021-09-15 11:54:49 + */ +@Data +@ApiModel("品牌表") +@TableName(value = "tb_brand") +public class Brand extends Model { + @ApiModelProperty(value = "品牌id") + private Integer id; + @ApiModelProperty(value = "品牌名称") + private String name; + @ApiModelProperty(value = "品牌图片地址") + private String image; + @ApiModelProperty(value = "品牌的首字母") + private String letter; + @ApiModelProperty(value = "排序") + private Integer seq; + @ApiModelProperty(value = "创建时间",hidden = true) + @TableField(fill = FieldFill.INSERT) + private Date createTime; + @ApiModelProperty(value = "更新时间",hidden = true) + @TableField(fill = FieldFill.UPDATE) + private Date updateTime; + /** + * 获取主键值 + * + * @return 主键值 + */ + @Override + protected Serializable pkVal() { + return this.id; + } +} diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/entity/Role.java b/ty-user/src/main/java/top/kuanghua/tyuser/entity/Role.java index aeaf470..6718ccc 100644 --- a/ty-user/src/main/java/top/kuanghua/tyuser/entity/Role.java +++ b/ty-user/src/main/java/top/kuanghua/tyuser/entity/Role.java @@ -7,7 +7,6 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; - import java.io.Serializable; import java.util.Date; diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/mapper/BrandMapper.java b/ty-user/src/main/java/top/kuanghua/tyuser/mapper/BrandMapper.java new file mode 100644 index 0000000..71a79d2 --- /dev/null +++ b/ty-user/src/main/java/top/kuanghua/tyuser/mapper/BrandMapper.java @@ -0,0 +1,8 @@ +package top.kuanghua.tyuser.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import top.kuanghua.tyuser.entity.Brand; + +public interface BrandMapper extends BaseMapper { + +} diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/service/BrandService.java b/ty-user/src/main/java/top/kuanghua/tyuser/service/BrandService.java new file mode 100644 index 0000000..8a0a519 --- /dev/null +++ b/ty-user/src/main/java/top/kuanghua/tyuser/service/BrandService.java @@ -0,0 +1,51 @@ +package top.kuanghua.tyuser.service; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import org.springframework.stereotype.Service; +import top.kuanghua.tyuser.entity.Brand; +import top.kuanghua.tyuser.mapper.BrandMapper; + +import javax.annotation.Resource; +import java.util.List; + +/** + * (Brand) + * + * @author kuanghua + * @since 2021-09-15 11:54:48 + */ +@Service +public class BrandService { + + @Resource + private BrandMapper brandMapper; + + public Page selectPage(Integer pageNum, Integer pageSize, QueryWrapper queryWrapper) { + return this.brandMapper.selectPage(new Page(pageNum, pageSize), queryWrapper); + } + + public Brand selectById(Integer id) { + return this.brandMapper.selectById(id); + } + + public List selectBatchIds(List idList) { + return this.brandMapper.selectBatchIds(idList); + } + + public int insert(Brand brand) { + return this.brandMapper.insert(brand); + } + + public int updateById(Brand brand) { + return this.brandMapper.updateById(brand); + } + + public int deleteById(Integer id) { + return this.brandMapper.deleteById(id); + } + + public int deleteBatchIds(List idList) { + return this.brandMapper.deleteBatchIds(idList); + } +} diff --git a/ty-user/src/main/java/top/kuanghua/tyuserbrand/Brand.vue b/ty-user/src/main/java/top/kuanghua/tyuserbrand/Brand.vue new file mode 100644 index 0000000..cd9d35a --- /dev/null +++ b/ty-user/src/main/java/top/kuanghua/tyuserbrand/Brand.vue @@ -0,0 +1,276 @@ + + + + 新增 + 删除 + + + + + + + + + + 查询 + + + + + + + + + + + + + 编辑 + 详情 + 删除 + + + + + + + + + + + DBC文件名:{{ detailData.username }} + + + 状态: 启用 + 状态: 停用 + + + 说明:{{ detailData.remark }} + + + + 确 定 + + + + + + + + + + diff --git a/ty-user/src/main/java/top/kuanghua/tyuserbrand/BrandForm.vue b/ty-user/src/main/java/top/kuanghua/tyuserbrand/BrandForm.vue new file mode 100644 index 0000000..f5c1f9b --- /dev/null +++ b/ty-user/src/main/java/top/kuanghua/tyuserbrand/BrandForm.vue @@ -0,0 +1,227 @@ + + + + + + + + + + + + + + + + + + + 取 消 + 确 定 + + + + + + + + + diff --git a/ty-user/src/main/java/top/kuanghua/tyuserbrandE/BrandE.vue b/ty-user/src/main/java/top/kuanghua/tyuserbrandE/BrandE.vue new file mode 100644 index 0000000..070a2e6 --- /dev/null +++ b/ty-user/src/main/java/top/kuanghua/tyuserbrandE/BrandE.vue @@ -0,0 +1,266 @@ + + + + 新增 + 删除 + + + + + + + + + + 查询 + + + + + + + + + + + + + 编辑 + 详情 + 删除 + + + + + + + + + + + DBC文件名:{{ detailData.username }} + + + 状态: 启用 + 状态: 停用 + + + 说明:{{ detailData.remark }} + + + + 确 定 + + + + + + + + + + diff --git a/ty-user/src/main/java/top/kuanghua/tyuserbrandE/BrandEForm.vue b/ty-user/src/main/java/top/kuanghua/tyuserbrandE/BrandEForm.vue new file mode 100644 index 0000000..b212c74 --- /dev/null +++ b/ty-user/src/main/java/top/kuanghua/tyuserbrandE/BrandEForm.vue @@ -0,0 +1,227 @@ + + + + + + + + + + + + + + + + + + + 取 消 + 确 定 + + + + + + + + + From eadd0c03d93f4be75f9ae386603646d1777c066e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=9D=E5=8D=8E?= Date: Thu, 16 Sep 2021 18:37:23 +0800 Subject: [PATCH 04/36] fix update_time issue --- ty-auth/ty-auth.iml | 5 - .../config/MetaObjectHandlerConfig.java | 3 +- ty-common/ty-common.iml | 5 - ty-gateway/ty-gateway-one/ty-gateway-one.iml | 5 - .../java/top/kuanghua/tyuserbrand/Brand.vue | 276 ------------------ .../top/kuanghua/tyuserbrand/BrandForm.vue | 227 -------------- .../java/top/kuanghua/tyuserbrandE/BrandE.vue | 266 ----------------- .../top/kuanghua/tyuserbrandE/BrandEForm.vue | 227 -------------- ty-user/ty-user.iml | 5 - 9 files changed, 1 insertion(+), 1018 deletions(-) delete mode 100644 ty-user/src/main/java/top/kuanghua/tyuserbrand/Brand.vue delete mode 100644 ty-user/src/main/java/top/kuanghua/tyuserbrand/BrandForm.vue delete mode 100644 ty-user/src/main/java/top/kuanghua/tyuserbrandE/BrandE.vue delete mode 100644 ty-user/src/main/java/top/kuanghua/tyuserbrandE/BrandEForm.vue diff --git a/ty-auth/ty-auth.iml b/ty-auth/ty-auth.iml index 72ba5d9..88dd7e7 100644 --- a/ty-auth/ty-auth.iml +++ b/ty-auth/ty-auth.iml @@ -7,10 +7,6 @@ - - - - @@ -20,7 +16,6 @@ - diff --git a/ty-common/src/main/java/top/kuanghua/khcomomon/config/MetaObjectHandlerConfig.java b/ty-common/src/main/java/top/kuanghua/khcomomon/config/MetaObjectHandlerConfig.java index fe9a86a..407c23e 100644 --- a/ty-common/src/main/java/top/kuanghua/khcomomon/config/MetaObjectHandlerConfig.java +++ b/ty-common/src/main/java/top/kuanghua/khcomomon/config/MetaObjectHandlerConfig.java @@ -20,7 +20,6 @@ public void insertFill(MetaObject metaObject) { @Override public void updateFill(MetaObject metaObject) { log.info("start update fill ...."); - this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now()); - this.strictUpdateFill(metaObject, "aaaa", LocalDateTime.class, LocalDateTime.now()); + this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date()); } } \ No newline at end of file diff --git a/ty-common/ty-common.iml b/ty-common/ty-common.iml index 039c62a..77de6d5 100644 --- a/ty-common/ty-common.iml +++ b/ty-common/ty-common.iml @@ -7,10 +7,6 @@ - - - - @@ -20,7 +16,6 @@ - diff --git a/ty-gateway/ty-gateway-one/ty-gateway-one.iml b/ty-gateway/ty-gateway-one/ty-gateway-one.iml index e71b88b..a0a458c 100644 --- a/ty-gateway/ty-gateway-one/ty-gateway-one.iml +++ b/ty-gateway/ty-gateway-one/ty-gateway-one.iml @@ -7,10 +7,6 @@ - - - - @@ -20,7 +16,6 @@ - diff --git a/ty-user/src/main/java/top/kuanghua/tyuserbrand/Brand.vue b/ty-user/src/main/java/top/kuanghua/tyuserbrand/Brand.vue deleted file mode 100644 index cd9d35a..0000000 --- a/ty-user/src/main/java/top/kuanghua/tyuserbrand/Brand.vue +++ /dev/null @@ -1,276 +0,0 @@ - - - - 新增 - 删除 - - - - - - - - - - 查询 - - - - - - - - - - - - - 编辑 - 详情 - 删除 - - - - - - - - - - - DBC文件名:{{ detailData.username }} - - - 状态: 启用 - 状态: 停用 - - - 说明:{{ detailData.remark }} - - - - 确 定 - - - - - - - - - - diff --git a/ty-user/src/main/java/top/kuanghua/tyuserbrand/BrandForm.vue b/ty-user/src/main/java/top/kuanghua/tyuserbrand/BrandForm.vue deleted file mode 100644 index f5c1f9b..0000000 --- a/ty-user/src/main/java/top/kuanghua/tyuserbrand/BrandForm.vue +++ /dev/null @@ -1,227 +0,0 @@ - - - - - - - - - - - - - - - - - - - 取 消 - 确 定 - - - - - - - - - diff --git a/ty-user/src/main/java/top/kuanghua/tyuserbrandE/BrandE.vue b/ty-user/src/main/java/top/kuanghua/tyuserbrandE/BrandE.vue deleted file mode 100644 index 070a2e6..0000000 --- a/ty-user/src/main/java/top/kuanghua/tyuserbrandE/BrandE.vue +++ /dev/null @@ -1,266 +0,0 @@ - - - - 新增 - 删除 - - - - - - - - - - 查询 - - - - - - - - - - - - - 编辑 - 详情 - 删除 - - - - - - - - - - - DBC文件名:{{ detailData.username }} - - - 状态: 启用 - 状态: 停用 - - - 说明:{{ detailData.remark }} - - - - 确 定 - - - - - - - - - - diff --git a/ty-user/src/main/java/top/kuanghua/tyuserbrandE/BrandEForm.vue b/ty-user/src/main/java/top/kuanghua/tyuserbrandE/BrandEForm.vue deleted file mode 100644 index b212c74..0000000 --- a/ty-user/src/main/java/top/kuanghua/tyuserbrandE/BrandEForm.vue +++ /dev/null @@ -1,227 +0,0 @@ - - - - - - - - - - - - - - - - - - - 取 消 - 确 定 - - - - - - - - - diff --git a/ty-user/ty-user.iml b/ty-user/ty-user.iml index 6d95e64..a0e988d 100644 --- a/ty-user/ty-user.iml +++ b/ty-user/ty-user.iml @@ -7,10 +7,6 @@ - - - - @@ -20,7 +16,6 @@ - From 0143789fb91ad3cd594d95837dfdb826ace4229c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=9D=E5=8D=8E?= Date: Fri, 8 Oct 2021 18:34:52 +0800 Subject: [PATCH 05/36] add error page func --- micro-service-plus.iml | 112 ++--- ty-auth/ty-auth.iml | 442 ++++++++--------- ty-common/ty-common.iml | 438 ++++++++-------- ty-gateway/ty-gateway-one/ty-gateway-one.iml | 468 +++++++++--------- ty-gateway/ty-gateway.iml | 444 ++++++++--------- .../tyupload/service/UploadService.java | 2 + ty-upload/ty-upload.iml | 458 ++++++++--------- .../controller/ErrorCollectionController.java | 124 +++++ .../tyuser/controller/UserController.java | 7 +- .../tyuser/entity/ErrorCollection.java | 34 ++ .../tyuser/mapper/ErrorCollectionMapper.java | 8 + .../service/ErrorCollectionService.java | 51 ++ ty-user/ty-user.iml | 440 ++++++++-------- 13 files changed, 1626 insertions(+), 1402 deletions(-) create mode 100644 ty-user/src/main/java/top/kuanghua/tyuser/controller/ErrorCollectionController.java create mode 100644 ty-user/src/main/java/top/kuanghua/tyuser/entity/ErrorCollection.java create mode 100644 ty-user/src/main/java/top/kuanghua/tyuser/mapper/ErrorCollectionMapper.java create mode 100644 ty-user/src/main/java/top/kuanghua/tyuser/service/ErrorCollectionService.java diff --git a/micro-service-plus.iml b/micro-service-plus.iml index 021af43..7f10b3d 100644 --- a/micro-service-plus.iml +++ b/micro-service-plus.iml @@ -1,57 +1,57 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ty-auth/ty-auth.iml b/ty-auth/ty-auth.iml index 88dd7e7..9447a05 100644 --- a/ty-auth/ty-auth.iml +++ b/ty-auth/ty-auth.iml @@ -1,222 +1,222 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ty-common/ty-common.iml b/ty-common/ty-common.iml index 77de6d5..3ffe7b5 100644 --- a/ty-common/ty-common.iml +++ b/ty-common/ty-common.iml @@ -1,220 +1,220 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ty-gateway/ty-gateway-one/ty-gateway-one.iml b/ty-gateway/ty-gateway-one/ty-gateway-one.iml index a0a458c..2e4a4dc 100644 --- a/ty-gateway/ty-gateway-one/ty-gateway-one.iml +++ b/ty-gateway/ty-gateway-one/ty-gateway-one.iml @@ -1,235 +1,235 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ty-gateway/ty-gateway.iml b/ty-gateway/ty-gateway.iml index 77d8bb2..e5e33c2 100644 --- a/ty-gateway/ty-gateway.iml +++ b/ty-gateway/ty-gateway.iml @@ -1,223 +1,223 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ty-upload/src/main/java/top/kuanghua/tyupload/service/UploadService.java b/ty-upload/src/main/java/top/kuanghua/tyupload/service/UploadService.java index 78d580d..d907045 100644 --- a/ty-upload/src/main/java/top/kuanghua/tyupload/service/UploadService.java +++ b/ty-upload/src/main/java/top/kuanghua/tyupload/service/UploadService.java @@ -39,11 +39,13 @@ public String upload(MultipartFile file) throws IOException { if (!CONTENT_TYPES.contains(contentType)) { //文件类型不合法 log.info("文件类型不合法:{}", originalFilename); + throw new RuntimeException("文件内容不合法"); } //检验文件内容 BufferedImage bufferedImage = ImageIO.read(file.getInputStream()); if (bufferedImage == null) { log.info("文件内容不合法:{}", originalFilename); + throw new RuntimeException("文件内容不合法"); } //保存到服务器 //file.transferTo(new File("D:\\java\\javaproject\\pinyou\\pinyou-upload\\src\\main\\resources\\static\\" + originalFilename)); diff --git a/ty-upload/ty-upload.iml b/ty-upload/ty-upload.iml index 44ed24d..39cc125 100644 --- a/ty-upload/ty-upload.iml +++ b/ty-upload/ty-upload.iml @@ -1,230 +1,230 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/controller/ErrorCollectionController.java b/ty-user/src/main/java/top/kuanghua/tyuser/controller/ErrorCollectionController.java new file mode 100644 index 0000000..3da6048 --- /dev/null +++ b/ty-user/src/main/java/top/kuanghua/tyuser/controller/ErrorCollectionController.java @@ -0,0 +1,124 @@ +package top.kuanghua.tyuser.controller; + + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.baomidou.mybatisplus.extension.api.ApiController; +import com.baomidou.mybatisplus.extension.api.R; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import top.kuanghua.khcomomon.entity.KHCommonParams; +import top.kuanghua.khcomomon.entity.ResResult; +import top.kuanghua.tyuser.entity.ErrorCollection; +import top.kuanghua.tyuser.service.ErrorCollectionService; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.io.Serializable; +import java.util.*; + +@Api(tags = "日志相关") +@RestController +@RequestMapping("errorCollection") +public class ErrorCollectionController { + + @Resource + private ErrorCollectionService errorCollectionService; + + /** + * 分页查询所有数据 + * + * @param errorCollection 查询实体 + * @return 所有数据 + */ + @GetMapping("selectPage") + @ApiOperation(value = "分页查询所有数据") + public ResResult selectPage(ErrorCollection errorCollection, KHCommonParams khCommonParams) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (ObjectUtils.isNotEmpty(errorCollection.getErrorLog())) { + queryWrapper.or().like("error_log", errorCollection.getErrorLog()); + } + if (ObjectUtils.isNotEmpty(errorCollection.getPageUrl())) { + queryWrapper.or().like("page_url", errorCollection.getPageUrl()); + } + if (ObjectUtils.isNotEmpty(errorCollection.getCreateTime())) { + queryWrapper.or().like("create_time", errorCollection.getCreateTime()); + } + + queryWrapper.select("error_log,page_url,create_time,id"); + queryWrapper.or().orderByDesc("create_time"); + if(StringUtils.isNotEmpty(khCommonParams.getStartTime())) { + queryWrapper.or().between("create_time",khCommonParams.getStartTime(),khCommonParams.getEndTime()); + } + Page errorCollectionPage = this.errorCollectionService.selectPage(khCommonParams.getPageNum(), khCommonParams.getPageSize(), queryWrapper); + return new ResResult().success(errorCollectionPage); + } + + /** + * 通过主键查询单条数据 + * + * @param id 主键 + * @return 单条数据 + */ + @GetMapping("selectById") + @ApiOperation(value = "通过id主键查询单条数据") + public ResResult selectById(@RequestParam("id") Integer id) { + return new ResResult().success(this.errorCollectionService.selectById(id)); + } + + /** + * @Description: 根据id数组查询品牌列表 + * @Param: idList id数组 + * @return: ids列表数据 + */ + @ApiOperation(value = "根据id数组查询品牌列表") + @PostMapping("selectBatchIds") + public ResResult selectBatchIds(@RequestParam("idList") List idList) { + return new ResResult().success(this.errorCollectionService.selectBatchIds(idList)); + } + + + /** + * 新增数据 + * + * @param errorCollection 实体对象 + * @return 新增结果 + */ + @ApiOperation(value = "新增数据") + @PostMapping("insert") + public ResResult insert(@RequestBody ErrorCollection errorCollection) { + return new ResResult().success(this.errorCollectionService.insert(errorCollection)); + } + + /** + * 修改数据 + * + * @param errorCollection 实体对象 + * @return 修改结果 + */ + @ApiOperation(value = "根据id修改数据") + @PutMapping("updateById") + public ResResult updateById(@RequestBody ErrorCollection errorCollection) { + return new ResResult().success(this.errorCollectionService.updateById(errorCollection)); + } + + /** + * 删除数据 + * + * @param idList 主键结合 + * @return 删除结果 + */ + @ApiOperation(value = "根据id数组删除数据") + @DeleteMapping("deleteBatchIds") + public ResResult deleteBatchIds(@RequestBody List idList) { + return new ResResult().success(this.errorCollectionService.deleteBatchIds(idList)); + } + + @DeleteMapping("deleteById") + @ApiOperation(value = "根据id数组删除数据") + public ResResult deleteById(@RequestParam("id") Integer id) { + return new ResResult().success(this.errorCollectionService.deleteById(id)); + } +} diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/controller/UserController.java b/ty-user/src/main/java/top/kuanghua/tyuser/controller/UserController.java index 8194a24..dfc01c4 100644 --- a/ty-user/src/main/java/top/kuanghua/tyuser/controller/UserController.java +++ b/ty-user/src/main/java/top/kuanghua/tyuser/controller/UserController.java @@ -176,7 +176,12 @@ public ResResult changePassword( this.userService.changePassword(tokenInfo.get("username").toString(),oldPassword,newPassword); return new ResResult().success(); } - + @PostMapping("getUserInfo") + @ApiOperation(value = "获取用户信息") + public ResResult changePassword(@ApiIgnore @RequestHeader("TOKEN_INFO") String TOKEN_INFO) throws UnsupportedEncodingException { + Map tokenInfo = JSON.parseObject(URLDecoder.decode(TOKEN_INFO, "utf-8")); + return new ResResult().success(tokenInfo); + } @PostMapping("insertUser") diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/entity/ErrorCollection.java b/ty-user/src/main/java/top/kuanghua/tyuser/entity/ErrorCollection.java new file mode 100644 index 0000000..d205c1f --- /dev/null +++ b/ty-user/src/main/java/top/kuanghua/tyuser/entity/ErrorCollection.java @@ -0,0 +1,34 @@ +package top.kuanghua.tyuser.entity; + +import java.util.Date; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.activerecord.Model; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +/** + * error_log_collection(ErrorCollection)表实体类 + * + * @author kuanghua + * @since 2021-10-08 11:37:25 + */ +@Data +@ApiModel("错误日志相关") +@TableName(value = "tb_error_collection") +public class ErrorCollection extends Model { + @ApiModelProperty(value = "错误日志") + private String errorLog; + @ApiModelProperty(value = "页面路径") + private String pageUrl; + @TableField(fill = FieldFill.INSERT) + @ApiModelProperty(value = "创建时间",hidden = true) + private Date createTime; + @ApiModelProperty(value = "id主键") + private Long id; +} diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/mapper/ErrorCollectionMapper.java b/ty-user/src/main/java/top/kuanghua/tyuser/mapper/ErrorCollectionMapper.java new file mode 100644 index 0000000..0038cef --- /dev/null +++ b/ty-user/src/main/java/top/kuanghua/tyuser/mapper/ErrorCollectionMapper.java @@ -0,0 +1,8 @@ +package top.kuanghua.tyuser.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import top.kuanghua.tyuser.entity.ErrorCollection; + +public interface ErrorCollectionMapper extends BaseMapper { + +} diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/service/ErrorCollectionService.java b/ty-user/src/main/java/top/kuanghua/tyuser/service/ErrorCollectionService.java new file mode 100644 index 0000000..8e6ae57 --- /dev/null +++ b/ty-user/src/main/java/top/kuanghua/tyuser/service/ErrorCollectionService.java @@ -0,0 +1,51 @@ +package top.kuanghua.tyuser.service; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import org.springframework.stereotype.Service; +import top.kuanghua.tyuser.entity.ErrorCollection; +import top.kuanghua.tyuser.mapper.ErrorCollectionMapper; + +import javax.annotation.Resource; +import java.util.List; + +/** + * (ErrorCollection) + * + * @author kuanghua + * @since 2021-10-08 11:37:24 + */ +@Service +public class ErrorCollectionService { + + @Resource + private ErrorCollectionMapper errorCollectionMapper; + + public Page selectPage(Integer pageNum, Integer pageSize, QueryWrapper queryWrapper) { + return this.errorCollectionMapper.selectPage(new Page(pageNum, pageSize), queryWrapper); + } + + public ErrorCollection selectById(Integer id) { + return this.errorCollectionMapper.selectById(id); + } + + public List selectBatchIds(List idList) { + return this.errorCollectionMapper.selectBatchIds(idList); + } + + public int insert(ErrorCollection errorCollection) { + return this.errorCollectionMapper.insert(errorCollection); + } + + public int updateById(ErrorCollection errorCollection) { + return this.errorCollectionMapper.updateById(errorCollection); + } + + public int deleteById(Integer id) { + return this.errorCollectionMapper.deleteById(id); + } + + public int deleteBatchIds(List idList) { + return this.errorCollectionMapper.deleteBatchIds(idList); + } +} diff --git a/ty-user/ty-user.iml b/ty-user/ty-user.iml index a0e988d..94b3e31 100644 --- a/ty-user/ty-user.iml +++ b/ty-user/ty-user.iml @@ -1,221 +1,221 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 8315239197a743830867e4eb46cb796707643f14 Mon Sep 17 00:00:00 2001 From: kuanghua <869653722@qq.com> Date: Thu, 11 Nov 2021 18:55:43 +0800 Subject: [PATCH 06/36] func of element-svg icon for side menu --- pom.xml | 1 + .../khcomomon/entity/CommonParamsSelf.java | 20 ++ .../khcomomon/utils/ObjectUtilsSelf.java | 30 ++- ty-excel/pom.xml | 51 ++++ .../kuanghua/tyexcel/ExcelApplication.java | 13 + .../kuanghua/tyexcel/bo/ComplexHeadData.java | 16 ++ .../bo/CustomStringStringConverter.java | 15 ++ .../top/kuanghua/tyexcel/bo/DemoData.java | 24 ++ .../kuanghua/tyexcel/bo/DemoExtraData.java | 11 + .../top/kuanghua/tyexcel/bo/RuiDeKqBo.java | 28 +++ .../kuanghua/tyexcel/config/BaseConfig.java | 25 ++ .../tyexcel/config/Swagger2Config.java | 56 +++++ .../tyexcel/controller/ExcelController.java | 81 ++++++ .../kuanghua/tyexcel/service/DaoService.java | 36 +++ .../tyexcel/service/ExcelService.java | 160 ++++++++++++ .../kuanghua/tyexcel/vo/ExcelCheckResult.java | 29 +++ ty-excel/src/main/resources/application.yml | 9 + ty-excel/src/main/resources/bootstrap.yml | 32 +++ ty-excel/ty-excel.iml | 238 ++++++++++++++++++ .../filter/AuthorizeFilterAfter.java | 135 +++++----- .../tyupload/controller/NacosTestDemo.java | 1 + .../tyupload/controller/TestController.java | 14 ++ ty-user/pom.xml | 5 + .../controller/ErrorCollectionController.java | 2 - .../tyuser/controller/VciController.java | 171 +++++++++++++ .../top/kuanghua/tyuser/entity/Admin.java | 37 +-- .../tyuser/entity/ErrorCollection.java | 6 +- .../java/top/kuanghua/tyuser/entity/Vci.java | 51 ++++ .../tyuser/excel/cv/VciStatusImpCv.java | 35 +++ .../kuanghua/tyuser/excel/cv/VciTimeCv.java | 28 +++ .../tyuser/excel/imp/VciExcelImp.java | 41 +++ .../top/kuanghua/tyuser/mapper/VciMapper.java | 8 + .../kuanghua/tyuser/service/VciService.java | 133 ++++++++++ .../kuanghua/tyuser/vo/ExcelCheckResult.java | 29 +++ ty-user/ty-user.iml | 20 +- 35 files changed, 1504 insertions(+), 87 deletions(-) create mode 100644 ty-common/src/main/java/top/kuanghua/khcomomon/entity/CommonParamsSelf.java create mode 100644 ty-excel/pom.xml create mode 100644 ty-excel/src/main/java/top/kuanghua/tyexcel/ExcelApplication.java create mode 100644 ty-excel/src/main/java/top/kuanghua/tyexcel/bo/ComplexHeadData.java create mode 100644 ty-excel/src/main/java/top/kuanghua/tyexcel/bo/CustomStringStringConverter.java create mode 100644 ty-excel/src/main/java/top/kuanghua/tyexcel/bo/DemoData.java create mode 100644 ty-excel/src/main/java/top/kuanghua/tyexcel/bo/DemoExtraData.java create mode 100644 ty-excel/src/main/java/top/kuanghua/tyexcel/bo/RuiDeKqBo.java create mode 100644 ty-excel/src/main/java/top/kuanghua/tyexcel/config/BaseConfig.java create mode 100644 ty-excel/src/main/java/top/kuanghua/tyexcel/config/Swagger2Config.java create mode 100644 ty-excel/src/main/java/top/kuanghua/tyexcel/controller/ExcelController.java create mode 100644 ty-excel/src/main/java/top/kuanghua/tyexcel/service/DaoService.java create mode 100644 ty-excel/src/main/java/top/kuanghua/tyexcel/service/ExcelService.java create mode 100644 ty-excel/src/main/java/top/kuanghua/tyexcel/vo/ExcelCheckResult.java create mode 100644 ty-excel/src/main/resources/application.yml create mode 100644 ty-excel/src/main/resources/bootstrap.yml create mode 100644 ty-excel/ty-excel.iml create mode 100644 ty-upload/src/main/java/top/kuanghua/tyupload/controller/TestController.java create mode 100644 ty-user/src/main/java/top/kuanghua/tyuser/controller/VciController.java create mode 100644 ty-user/src/main/java/top/kuanghua/tyuser/entity/Vci.java create mode 100644 ty-user/src/main/java/top/kuanghua/tyuser/excel/cv/VciStatusImpCv.java create mode 100644 ty-user/src/main/java/top/kuanghua/tyuser/excel/cv/VciTimeCv.java create mode 100644 ty-user/src/main/java/top/kuanghua/tyuser/excel/imp/VciExcelImp.java create mode 100644 ty-user/src/main/java/top/kuanghua/tyuser/mapper/VciMapper.java create mode 100644 ty-user/src/main/java/top/kuanghua/tyuser/service/VciService.java create mode 100644 ty-user/src/main/java/top/kuanghua/tyuser/vo/ExcelCheckResult.java diff --git a/pom.xml b/pom.xml index b3cec92..3a221f6 100644 --- a/pom.xml +++ b/pom.xml @@ -14,6 +14,7 @@ ty-auth ty-user ty-upload + ty-excel diff --git a/ty-common/src/main/java/top/kuanghua/khcomomon/entity/CommonParamsSelf.java b/ty-common/src/main/java/top/kuanghua/khcomomon/entity/CommonParamsSelf.java new file mode 100644 index 0000000..2d63707 --- /dev/null +++ b/ty-common/src/main/java/top/kuanghua/khcomomon/entity/CommonParamsSelf.java @@ -0,0 +1,20 @@ +package top.kuanghua.khcomomon.entity; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @Title: CommonParams + * @Description: + * @Auther: kuanghua + * @create 2020/12/15 12:01 + */ +@Data +@ApiModel +public class CommonParamsSelf extends KHCommonPageParams{ + @ApiModelProperty("开始时间") + private String startTime; + @ApiModelProperty("结束时间") + private String endTime; +} diff --git a/ty-common/src/main/java/top/kuanghua/khcomomon/utils/ObjectUtilsSelf.java b/ty-common/src/main/java/top/kuanghua/khcomomon/utils/ObjectUtilsSelf.java index d9abe9f..a9fb5ce 100644 --- a/ty-common/src/main/java/top/kuanghua/khcomomon/utils/ObjectUtilsSelf.java +++ b/ty-common/src/main/java/top/kuanghua/khcomomon/utils/ObjectUtilsSelf.java @@ -1,17 +1,15 @@ package top.kuanghua.khcomomon.utils; import com.alibaba.fastjson.JSON; -import com.baomidou.mybatisplus.extension.api.R; -import com.sun.javafx.collections.MappingChange; import org.apache.commons.lang3.StringUtils; import top.kuanghua.khcomomon.entity.ResResult; import java.lang.reflect.Array; +import java.text.SimpleDateFormat; import java.util.Collection; -import java.util.HashMap; +import java.util.Date; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; /** * 从jwt解析得到的数据是Object类型,转换为具体类型可能出现空指针, @@ -101,4 +99,28 @@ public static Map changeToMap(Object resResult){ return res; } + /** + * @return 时间年月日 + */ + public static String getCurrentDateTime(){ + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 + return df.format(new Date()); + } + + /** + * @return 当前年月 + */ + public static String getCurrentDate(){ + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式 + return df.format(new Date()); + } + + /** + * @param date + * @return + */ + public static String formatDateTime(Date date){ + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 + return df.format(date); + } } \ No newline at end of file diff --git a/ty-excel/pom.xml b/ty-excel/pom.xml new file mode 100644 index 0000000..83ad1ef --- /dev/null +++ b/ty-excel/pom.xml @@ -0,0 +1,51 @@ + + + + micro-service-plus + top.kuanghua + 1.0-SNAPSHOT + + 4.0.0 + ty-excel + + + + com.alibaba + easyexcel + 3.0.1 + + + top.kuanghua + ty-common + 1.0-SNAPSHOT + + + + + ${project.artifactId} + + + src/main/resources + + true + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.1 + + true + + + + + \ No newline at end of file diff --git a/ty-excel/src/main/java/top/kuanghua/tyexcel/ExcelApplication.java b/ty-excel/src/main/java/top/kuanghua/tyexcel/ExcelApplication.java new file mode 100644 index 0000000..900de90 --- /dev/null +++ b/ty-excel/src/main/java/top/kuanghua/tyexcel/ExcelApplication.java @@ -0,0 +1,13 @@ +package top.kuanghua.tyexcel; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; + +@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) +public class ExcelApplication { + public static void main(String[] args) { + SpringApplication.run(ExcelApplication.class,args); + } +} + diff --git a/ty-excel/src/main/java/top/kuanghua/tyexcel/bo/ComplexHeadData.java b/ty-excel/src/main/java/top/kuanghua/tyexcel/bo/ComplexHeadData.java new file mode 100644 index 0000000..c216b31 --- /dev/null +++ b/ty-excel/src/main/java/top/kuanghua/tyexcel/bo/ComplexHeadData.java @@ -0,0 +1,16 @@ +package top.kuanghua.tyexcel.bo; + +import com.alibaba.excel.annotation.ExcelProperty; +import lombok.Data; + +import java.util.Date; + +@Data +public class ComplexHeadData { + @ExcelProperty({"主标题", "字符串标题"}) + private String string; + @ExcelProperty({"主标题", "日期标题"}) + private Date date; + @ExcelProperty({"主标题", "数字标题"}) + private Double doubleData; +} \ No newline at end of file diff --git a/ty-excel/src/main/java/top/kuanghua/tyexcel/bo/CustomStringStringConverter.java b/ty-excel/src/main/java/top/kuanghua/tyexcel/bo/CustomStringStringConverter.java new file mode 100644 index 0000000..1b18c3c --- /dev/null +++ b/ty-excel/src/main/java/top/kuanghua/tyexcel/bo/CustomStringStringConverter.java @@ -0,0 +1,15 @@ +package top.kuanghua.tyexcel.bo; + +import com.alibaba.excel.converters.Converter; +import com.alibaba.excel.enums.CellDataTypeEnum; +import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.property.ExcelContentProperty; + + +public class CustomStringStringConverter implements Converter { + @Override + public String convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { + return "自定义:" + cellData.getStringValue(); + } +} \ No newline at end of file diff --git a/ty-excel/src/main/java/top/kuanghua/tyexcel/bo/DemoData.java b/ty-excel/src/main/java/top/kuanghua/tyexcel/bo/DemoData.java new file mode 100644 index 0000000..c047e4c --- /dev/null +++ b/ty-excel/src/main/java/top/kuanghua/tyexcel/bo/DemoData.java @@ -0,0 +1,24 @@ +package top.kuanghua.tyexcel.bo; + +import com.alibaba.excel.annotation.ExcelIgnore; +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.format.DateTimeFormat; +import lombok.Data; + +import java.util.Date; + +@Data +public class DemoData { + @ExcelProperty("字符串标题") + private String string; + @ExcelProperty("日期标题") + @DateTimeFormat("yyyy年MM月dd日HH时mm分ss秒") + private Date date; + @ExcelProperty(value="数字标题",index = 3) + private Double doubleData; + /** + * 忽略这个字段 + */ + @ExcelIgnore + private String ignore; +} \ No newline at end of file diff --git a/ty-excel/src/main/java/top/kuanghua/tyexcel/bo/DemoExtraData.java b/ty-excel/src/main/java/top/kuanghua/tyexcel/bo/DemoExtraData.java new file mode 100644 index 0000000..40726ca --- /dev/null +++ b/ty-excel/src/main/java/top/kuanghua/tyexcel/bo/DemoExtraData.java @@ -0,0 +1,11 @@ +package top.kuanghua.tyexcel.bo; + +import lombok.Data; + +@Data +public class DemoExtraData { + + private String row1; + + private String row2; +} \ No newline at end of file diff --git a/ty-excel/src/main/java/top/kuanghua/tyexcel/bo/RuiDeKqBo.java b/ty-excel/src/main/java/top/kuanghua/tyexcel/bo/RuiDeKqBo.java new file mode 100644 index 0000000..f0e6ba9 --- /dev/null +++ b/ty-excel/src/main/java/top/kuanghua/tyexcel/bo/RuiDeKqBo.java @@ -0,0 +1,28 @@ +package top.kuanghua.tyexcel.bo; + +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.format.DateTimeFormat; +import lombok.Data; + +import java.util.Date; + +/** + * @Title: RuiDeKqBo + * @Description: + * @Auther: kuanghua + * @create 2021/7/9 10:27 + */ +@Data +public class RuiDeKqBo { + @ExcelProperty(value = "部门",converter = CustomStringStringConverter.class) + private String department; + @ExcelProperty("姓名") + private String username; + @ExcelProperty("日期") + @DateTimeFormat("yyyy年") + private Date dateTime; + @ExcelProperty("签到时间") + private String checkInTime; + private String row1; + private String row2; +} diff --git a/ty-excel/src/main/java/top/kuanghua/tyexcel/config/BaseConfig.java b/ty-excel/src/main/java/top/kuanghua/tyexcel/config/BaseConfig.java new file mode 100644 index 0000000..db4a35f --- /dev/null +++ b/ty-excel/src/main/java/top/kuanghua/tyexcel/config/BaseConfig.java @@ -0,0 +1,25 @@ +package top.kuanghua.tyexcel.config; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +/** + * @Title: BaseConfig + * @Description: + * @Auther: kuanghua + * @create 2020/8/23 21:52 + */ +/* + * 总结:1.@Configuration 下的@ComponentScan回将包下带有@Component扫描变成配置类, + * 而@SpringBootApplication扫描的只会变成普通类 + * */ +@Configuration +//扫描公用包的配置和自身的配置类 +@ComponentScan(basePackages = {"top.kuanghua.khcomomon","top.kuanghua.tyexcel"}) +//feign扫描 +//@EnableFeignClients(basePackages = {"top.kuanghua.feign.tyexecl","top.kuanghua.feign.tyauth"}) +//mapper包扫描 +//@MapperScan(basePackages = {"top.kuanghua.tyuser.mapper"}) +public class BaseConfig {} diff --git a/ty-excel/src/main/java/top/kuanghua/tyexcel/config/Swagger2Config.java b/ty-excel/src/main/java/top/kuanghua/tyexcel/config/Swagger2Config.java new file mode 100644 index 0000000..cbccfd4 --- /dev/null +++ b/ty-excel/src/main/java/top/kuanghua/tyexcel/config/Swagger2Config.java @@ -0,0 +1,56 @@ +package top.kuanghua.tyexcel.config; + +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.stereotype.Component; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Component +@EnableSwagger2 //开启在线接口文档 +//配置包扫描 +public class Swagger2Config { + private boolean swagger_is_enable = true; +// @Value("${.ipAddr}") +// private String ipAddr; + @Value("${server.port}") + private String port; + + @Bean + public Docket api() { + return new Docket(DocumentationType.SWAGGER_2) + .enable(swagger_is_enable) + //.host(this.ipAddr + ":" + this.port) + .apiInfo(apiInfo()) + .select() + .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) + //.apis(basePackage("top.kuanghua.swagger.controller")) + .paths(PathSelectors.any()) + .build(); + } + + /** + * 构建 api文档的详细信息函数 + * + * @return + */ + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("标题:swagger文档") + .description("描述:新一代的微服务架构") + .contact(new Contact("jzfai", null, "869653722@qq.com")) + .version("版本号:2.8") + .build(); + } + + /** + * http://localhost:8080/swagger-ui.html + */ +} diff --git a/ty-excel/src/main/java/top/kuanghua/tyexcel/controller/ExcelController.java b/ty-excel/src/main/java/top/kuanghua/tyexcel/controller/ExcelController.java new file mode 100644 index 0000000..99e9669 --- /dev/null +++ b/ty-excel/src/main/java/top/kuanghua/tyexcel/controller/ExcelController.java @@ -0,0 +1,81 @@ +package top.kuanghua.tyexcel.controller; + +import com.alibaba.excel.EasyExcel; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import springfox.documentation.annotations.ApiIgnore; +import top.kuanghua.khcomomon.entity.ResResult; +import top.kuanghua.khcomomon.utils.ObjectUtilsSelf; +import top.kuanghua.tyexcel.bo.ComplexHeadData; +import top.kuanghua.tyexcel.bo.DemoData; +import top.kuanghua.tyexcel.bo.RuiDeKqBo; +import top.kuanghua.tyexcel.service.ExcelService; +import top.kuanghua.tyexcel.vo.ExcelCheckResult; + + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * @Title: ExcelController + * @Description: + * @Auther: kuanghua + * @create 2021/7/9 11:37 + */ +@RestController +@RequestMapping("excel") +@Api(tags="文档导入相关") +@Slf4j +public class ExcelController { + + @Autowired + private ExcelService excelService; + + @ApiOperation("导入excel") + @PostMapping("importExcel") + public ResResult importExcel(@RequestParam("file") MultipartFile file) throws IOException { + ExcelCheckResult excelCheckResult = excelService.importExcel(file.getInputStream()); + return new ResResult().success(excelCheckResult); + } + + private List data() { + List list = new ArrayList(); + for (int i = 0; i < 10; i++) { + DemoData data = new DemoData(); + data.setString("字符串" + i); + data.setDate(new Date()); + data.setDoubleData(0.56); + list.add(data); + } + return list; + } + + @ApiOperation("导出excel") + @PostMapping("exportExcel") + public void exportExcel(HttpServletResponse response) throws IOException { + + // 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 + String fileName = URLEncoder.encode("测试", "UTF-8").replaceAll("\\+", "%20"); + response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); + EasyExcel.write(response.getOutputStream(), ComplexHeadData.class).sheet("模板").doWrite(data()); + +// excelService.exportExcel(); +// return new ResResult().success(); + } +} diff --git a/ty-excel/src/main/java/top/kuanghua/tyexcel/service/DaoService.java b/ty-excel/src/main/java/top/kuanghua/tyexcel/service/DaoService.java new file mode 100644 index 0000000..90805f7 --- /dev/null +++ b/ty-excel/src/main/java/top/kuanghua/tyexcel/service/DaoService.java @@ -0,0 +1,36 @@ +package top.kuanghua.tyexcel.service; + +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.enums.CellExtraTypeEnum; +import com.alibaba.excel.exception.ExcelDataConvertException; +import com.alibaba.excel.metadata.CellExtra; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.read.listener.ReadListener; +import com.alibaba.fastjson.JSON; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import top.kuanghua.tyexcel.bo.RuiDeKqBo; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +; + +/** + * @Title: ExeclService + * @Description: + * @Auther: kuanghua + * @create 2021/7/9 11:35 + */ +@Service +@Slf4j +public class DaoService { + public void test(){ + log.info("testInfo"); + } + +} + diff --git a/ty-excel/src/main/java/top/kuanghua/tyexcel/service/ExcelService.java b/ty-excel/src/main/java/top/kuanghua/tyexcel/service/ExcelService.java new file mode 100644 index 0000000..82ec61b --- /dev/null +++ b/ty-excel/src/main/java/top/kuanghua/tyexcel/service/ExcelService.java @@ -0,0 +1,160 @@ +package top.kuanghua.tyexcel.service; + +import com.alibaba.excel.context.AnalysisContext; + +import com.alibaba.excel.enums.CellExtraTypeEnum; +import com.alibaba.excel.exception.ExcelDataConvertException; +import com.alibaba.excel.metadata.CellExtra; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.read.listener.ReadListener; +import com.alibaba.fastjson.JSON; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import top.kuanghua.tyexcel.bo.RuiDeKqBo; +import com.alibaba.excel.EasyExcel; +import org.springframework.stereotype.Service; +import top.kuanghua.tyexcel.vo.ExcelCheckResult; + + +import java.io.InputStream; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.*; + +; + +/** + * @Title: ExeclService + * @Description: + * @Auther: kuanghua + * @create 2021/7/9 11:35 + */ +@Service +@Slf4j +public class ExcelService { + + @Autowired + private DaoService daoService; + + public ExcelCheckResult importExcel(InputStream fileName) { + + List errLogList = new ArrayList<>(); + List successList = new ArrayList<>(); + + EasyExcel.read(fileName, RuiDeKqBo.class, new ReadListener() { + /** + * 单次缓存的数据量 + */ + public static final int BATCH_COUNT = 3000; + /** + *临时存储 + */ + private List cachedData = new ArrayList<>(BATCH_COUNT); + + @Override + public void onException(Exception exception, AnalysisContext context) throws Exception { + log.error("解析失败,但是继续解析下一行:{}", exception.getMessage()); + // 如果是某一个单元格的转换异常 能获取到具体行号 + // 如果要获取头的信息 配合invokeHeadMap使用 + if (exception instanceof ExcelDataConvertException) { + ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) exception; + + String formatString = MessageFormat.format("第{0}行,第{1}列解析异常", + excelDataConvertException.getRowIndex(), excelDataConvertException.getColumnIndex()); + + errLogList.add(formatString); + + } + } + + @Override + public void invokeHead(Map> headMap, AnalysisContext context) { +// System.out.println("头数据"); +// System.out.println(JSON.toJSONString(headMap)); + } + + @Override + public void invoke(RuiDeKqBo data, AnalysisContext context) { + successList.add(data); + cachedData.add(data); + if (cachedData.size() >= BATCH_COUNT) { + saveData(); + // 存储完成清理 list + cachedData = new ArrayList<>(BATCH_COUNT); + } + } + @Override + public void extra(CellExtra extra, AnalysisContext context) { + log.info("读取到了一条额外信息:{}", JSON.toJSONString(extra)); + switch (extra.getType()) { + case COMMENT: + log.info("额外信息是批注,在rowIndex:{},columnIndex;{},内容是:{}", extra.getRowIndex(), extra.getColumnIndex(), + extra.getText()); + break; + case HYPERLINK: + if ("Sheet1!A1".equals(extra.getText())) { + log.info("额外信息是超链接,在rowIndex:{},columnIndex;{},内容是:{}", extra.getRowIndex(), + extra.getColumnIndex(), extra.getText()); + } else if ("Sheet2!A1".equals(extra.getText())) { + log.info("额外信息是超链接,而且覆盖了一个区间,在firstRowIndex:{},firstColumnIndex;{},lastRowIndex:{},lastColumnIndex:{}," + + "内容是:{}", + extra.getFirstRowIndex(), extra.getFirstColumnIndex(), extra.getLastRowIndex(), + extra.getLastColumnIndex(), extra.getText()); + } else { + log.info("Unknown hyperlink!"); + } + break; + case MERGE: + log.info( + "额外信息是超链接,而且覆盖了一个区间,在firstRowIndex:{},firstColumnIndex;{},lastRowIndex:{},lastColumnIndex:{}", + extra.getFirstRowIndex(), extra.getFirstColumnIndex(), extra.getLastRowIndex(), + extra.getLastColumnIndex()); + break; + default: + } + + } + + @Override + public void doAfterAllAnalysed(AnalysisContext context) { +// daoService.test(); +// saveData(); +// log.info(excelCheckResult.toString()); + } + + /** + * 加上存储数据库 + */ + private void saveData() { + log.info("{}条数据,开始存储数据库!", cachedData.size()); + log.info("存储数据库成功!"); + + + } + + + //注:headRowNumber(1)如果不写会自动匹配 + })// 需要读取批注 默认不读取 + .extraRead(CellExtraTypeEnum.COMMENT) + // 需要读取超链接 默认不读取 + .extraRead(CellExtraTypeEnum.HYPERLINK) + // 需要读取合并单元格信息 默认不读取 + .extraRead(CellExtraTypeEnum.MERGE).sheet().headRowNumber(1).doRead(); + + return new ExcelCheckResult(errLogList, successList); + } + + /* + * 导出Excel + * */ +// public void exportExcel() { +// String fileName = "D:\\construct\\micro-service-plus\\ty-excel\\src\\main\\java\\top\\kuanghua\\tyexcel\\" + System.currentTimeMillis() + ".xlsx"; +// +// Set excludeColumnFiledNames = new HashSet(); +// excludeColumnFiledNames.add("date"); +// // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭 +// EasyExcel.write(fileName, ComplexHeadData.class).sheet("模板") +// .doWrite(data()); +// } +} + diff --git a/ty-excel/src/main/java/top/kuanghua/tyexcel/vo/ExcelCheckResult.java b/ty-excel/src/main/java/top/kuanghua/tyexcel/vo/ExcelCheckResult.java new file mode 100644 index 0000000..c1ae3e1 --- /dev/null +++ b/ty-excel/src/main/java/top/kuanghua/tyexcel/vo/ExcelCheckResult.java @@ -0,0 +1,29 @@ +package top.kuanghua.tyexcel.vo; + +import lombok.Data; + +import java.util.List; + +/** + * @Title: ExcelCheckResult + * @Description: + * @Auther: kuanghua + * @create 2021-11-02 11:33 + */ + +@Data +public class ExcelCheckResult { + private int errNum; + private int successNum; + private boolean checkResult; + private List errList; + private List successList; + + public ExcelCheckResult(List errList, List successList) { + this.errList = errList; + this.successList = successList; + this.errNum=errList.size(); + this.successNum=successList.size(); + this.checkResult=errList.size()==0; + } +} diff --git a/ty-excel/src/main/resources/application.yml b/ty-excel/src/main/resources/application.yml new file mode 100644 index 0000000..3cd6781 --- /dev/null +++ b/ty-excel/src/main/resources/application.yml @@ -0,0 +1,9 @@ +server: + port: ${envpt.tomcatPortPre}0135 + +#限制spring上传文件大小为20M +spring: + servlet: + multipart: + max-file-size: 20MB + max-request-size: 20MB \ No newline at end of file diff --git a/ty-excel/src/main/resources/bootstrap.yml b/ty-excel/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..97d7d53 --- /dev/null +++ b/ty-excel/src/main/resources/bootstrap.yml @@ -0,0 +1,32 @@ +spring: + application: + name: @project.artifactId@ + profiles: + active: @activatedProperties@ + cloud: + nacos: + config: + enabled: true + namespace: @nacosNamespace@ + group: @nacosGroup@ + username: @nacosUsername@ + password: @nacosPassword@ + server-addr: @nacosIpPort@ + prefix: @project.artifactId@ + file-extension: yml + # 用于共享的配置文件 + shared-configs: + - data-id: application-@activatedProperties@.yml + group: @nacosGroup@ + refresh: true + extension-configs: + - data-id: @project.artifactId@.yml + group: @nacosGroup@ + refresh: true + discovery: + namespace: @nacosNamespace@ + group: @nacosGroup@ + username: @nacosUsername@ + password: @nacosPassword@ + server-addr: @nacosIpPort@ + weight: @nacosWeight@ \ No newline at end of file diff --git a/ty-excel/ty-excel.iml b/ty-excel/ty-excel.iml new file mode 100644 index 0000000..ac0db2e --- /dev/null +++ b/ty-excel/ty-excel.iml @@ -0,0 +1,238 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/filter/AuthorizeFilterAfter.java b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/filter/AuthorizeFilterAfter.java index 5e9c191..1fdc000 100644 --- a/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/filter/AuthorizeFilterAfter.java +++ b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/filter/AuthorizeFilterAfter.java @@ -16,6 +16,7 @@ import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.core.io.buffer.DefaultDataBufferFactory; +import org.springframework.http.HttpHeaders; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.http.server.reactive.ServerHttpResponseDecorator; @@ -26,10 +27,12 @@ import top.kuanghua.feign.tyauth.feign.TokenFeign; import top.kuanghua.khcomomon.utils.ObjectUtilsSelf; +import javax.annotation.Resource; import java.net.URLDecoder; import java.net.URLEncoder; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; import java.util.List; import java.util.Map; /** @@ -45,9 +48,13 @@ public class AuthorizeFilterAfter implements GlobalFilter, Ordered { @Value("#{'${filter.allowPaths:}'.empty ? null : '${filter.allowPaths:}'.split(',')}") private List allowPaths; - @Autowired + + @Value("#{'${filter.notValidExpList:}'.empty ? null : '${filter.notValidExpList:}'.split(',')}") + private List notValidExpList; + + @Resource private TokenFeign tokenFeign; -// @Value("${jwt-properties.pubKeyPath}") + // @Value("${jwt-properties.pubKeyPath}") // private String pubKeyPath; @Value("${token-properties.renewTokenMinute}") private int renewTokenMinute; @@ -65,65 +72,79 @@ public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { return chain.filter(exchange); } } - ServerHttpResponseDecorator decoratedResponse = new ServerHttpResponseDecorator(response) { - @Override - public Mono writeWith(Publisher extends DataBuffer> body) { - if (body instanceof Flux) { - Flux extends DataBuffer> fluxBody = (Flux extends DataBuffer>) body; - return super.writeWith(fluxBody.buffer().map(dataBuffers -> { - DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory(); - DataBuffer join = dataBufferFactory.join(dataBuffers); - byte[] content = new byte[join.readableByteCount()]; - join.read(content); - // 释放掉内存 - DataBufferUtils.release(join); - String str = new String(content, Charset.forName("UTF-8")); -// log.info("返回体:{}", str); - //todo 拦截到的返回体内容,可以随意去操作了 - //2.1.2 如果小于一个小时 刷新token - //String jwtToken = request.getHeaders().getFirst("AUTHORIZE_TOKEN"); - Long expValue = null; - Map dataMap=null; - try { -// Object reqData=tokenFeign.parseToken(jwtToken); -// Map map = JSON.parseObject(JSON.toJSONString(reqData), Map.class); - String tokenInfo = request.getHeaders().getFirst("TOKEN_INFO"); - //System.out.println("获取到新的token"+tokenInfo); - dataMap = JSON.parseObject(URLDecoder.decode(tokenInfo, "utf-8"), Map.class); - expValue = ObjectUtilsSelf.toLong(ObjectUtilsSelf.toString(dataMap.get("exp"))+"000"); - } catch (Exception e) { - e.printStackTrace(); - } - Long currentData= DateTime.now().plusMinutes(renewTokenMinute).getMillis(); - Map strMap=JSON.parseObject(str, Map.class); - if(ObjectUtils.isNotEmpty(expValue)&&expValue < currentData){ - String generateToken=null; + + //不校验exp时间 + for (String allowPath : notValidExpList) { + if(StringUtils.contains(path,allowPath)){ + return chain.filter(exchange); + } + } + + //获取token信息比较exp和当前时间进行比较 + ServerHttpResponseDecorator decoratedResponse = null; + try { + decoratedResponse = new ServerHttpResponseDecorator(response) { + @Override + public Mono writeWith(Publisher extends DataBuffer> body) { + if (body instanceof Flux) { + Flux extends DataBuffer> fluxBody = (Flux extends DataBuffer>) body; + return super.writeWith(fluxBody.buffer().map(dataBuffers -> { + DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory(); + DataBuffer join = dataBufferFactory.join(dataBuffers); + byte[] content = new byte[join.readableByteCount()]; + join.read(content); + // 释放掉内存 + DataBufferUtils.release(join); + String str = new String(content, Charset.forName("UTF-8")); + // log.info("返回体:{}", str); + //todo 拦截到的返回体内容,可以随意去操作了 + //2.1.2 如果小于一个小时 刷新token + //String jwtToken = request.getHeaders().getFirst("AUTHORIZE_TOKEN"); + Long expValue = null; + Map dataMap=null; try { - //使用本地生成 - //generateToken = JwtUtilsKh.updateToken(dataMap, RsaUtils.getPrivateKey(priKeyPath), 62); - //调用ty-auth进行生成 - dataMap.remove("exp"); - dataMap.remove("iat"); - Object object = tokenFeign.updateToken(dataMap); - if(ObjectUtilsSelf.isEmpty(object)){ - return bufferFactory.wrap(str.getBytes()); - } - Map map = JSON.parseObject(JSON.toJSONString(object), Map.class); - generateToken = ObjectUtilsSelf.toString(map.get("data")); + // Object reqData=tokenFeign.parseToken(jwtToken); + // Map map = JSON.parseObject(JSON.toJSONString(reqData), Map.class); + String tokenInfo = request.getHeaders().getFirst("TOKEN_INFO"); + //System.out.println("获取到新的token"+tokenInfo); + dataMap = JSON.parseObject(URLDecoder.decode(tokenInfo, "utf-8"), Map.class); + expValue = ObjectUtilsSelf.toLong(ObjectUtilsSelf.toString(dataMap.get("exp"))+"000"); } catch (Exception e) { - //log.error(e.toString()); + e.printStackTrace(); + } + Long currentData= DateTime.now().plusMinutes(renewTokenMinute).getMillis(); + Map strMap=JSON.parseObject(str, Map.class); + if(ObjectUtils.isNotEmpty(expValue)&&expValue < currentData){ + String generateToken=null; + try { + //使用本地生成 + //generateToken = JwtUtilsKh.updateToken(dataMap, RsaUtils.getPrivateKey(priKeyPath), 62); + //调用ty-auth进行生成 + dataMap.remove("exp"); + dataMap.remove("iat"); + Object object = tokenFeign.updateToken(dataMap); + if(ObjectUtilsSelf.isEmpty(object)){ + return bufferFactory.wrap(str.getBytes()); + } + Map map = JSON.parseObject(JSON.toJSONString(object), Map.class); + generateToken = ObjectUtilsSelf.toString(map.get("data")); + } catch (Exception e) { + //log.error(e.toString()); + } + strMap.put("isNeedUpdateToken",true); + strMap.put("updateToken",generateToken); } - strMap.put("isNeedUpdateToken",true); - strMap.put("updateToken",generateToken); - } - response.getHeaders().setContentLength(JSON.toJSONString(strMap).getBytes().length); - return bufferFactory.wrap(JSON.toJSONString(strMap).getBytes()); - })); + response.getHeaders().setContentLength(JSON.toJSONString(strMap).getBytes().length); + return bufferFactory.wrap(JSON.toJSONString(strMap).getBytes()); + })); + } + // if body is not a flux. never got there. + return super.writeWith(body); } - // if body is not a flux. never got there. - return super.writeWith(body); - } - }; + }; + } catch (Exception e) { + return chain.filter(exchange); + } return chain.filter(exchange.mutate().response(decoratedResponse).build()); } diff --git a/ty-upload/src/main/java/top/kuanghua/tyupload/controller/NacosTestDemo.java b/ty-upload/src/main/java/top/kuanghua/tyupload/controller/NacosTestDemo.java index 61a872d..1abe74a 100644 --- a/ty-upload/src/main/java/top/kuanghua/tyupload/controller/NacosTestDemo.java +++ b/ty-upload/src/main/java/top/kuanghua/tyupload/controller/NacosTestDemo.java @@ -3,6 +3,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; diff --git a/ty-upload/src/main/java/top/kuanghua/tyupload/controller/TestController.java b/ty-upload/src/main/java/top/kuanghua/tyupload/controller/TestController.java new file mode 100644 index 0000000..89b5141 --- /dev/null +++ b/ty-upload/src/main/java/top/kuanghua/tyupload/controller/TestController.java @@ -0,0 +1,14 @@ +package top.kuanghua.tyupload.controller; + +import org.springframework.web.bind.annotation.CrossOrigin; + +/** + * @Title: TestController + * @Description: + * @Auther: kuanghua + * @create 2021-11-09 10:57 + */ +@CrossOrigin +public class TestController { + +} \ No newline at end of file diff --git a/ty-user/pom.xml b/ty-user/pom.xml index 21107c4..cb45de4 100644 --- a/ty-user/pom.xml +++ b/ty-user/pom.xml @@ -12,6 +12,11 @@ ty-user + + com.alibaba + easyexcel + 3.0.1 + top.kuanghua ty-common diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/controller/ErrorCollectionController.java b/ty-user/src/main/java/top/kuanghua/tyuser/controller/ErrorCollectionController.java index 3da6048..3d2fbb0 100644 --- a/ty-user/src/main/java/top/kuanghua/tyuser/controller/ErrorCollectionController.java +++ b/ty-user/src/main/java/top/kuanghua/tyuser/controller/ErrorCollectionController.java @@ -46,8 +46,6 @@ public ResResult selectPage(ErrorCollection errorCollection, KHCommonParams khCo if (ObjectUtils.isNotEmpty(errorCollection.getCreateTime())) { queryWrapper.or().like("create_time", errorCollection.getCreateTime()); } - - queryWrapper.select("error_log,page_url,create_time,id"); queryWrapper.or().orderByDesc("create_time"); if(StringUtils.isNotEmpty(khCommonParams.getStartTime())) { queryWrapper.or().between("create_time",khCommonParams.getStartTime(),khCommonParams.getEndTime()); diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/controller/VciController.java b/ty-user/src/main/java/top/kuanghua/tyuser/controller/VciController.java new file mode 100644 index 0000000..93a0285 --- /dev/null +++ b/ty-user/src/main/java/top/kuanghua/tyuser/controller/VciController.java @@ -0,0 +1,171 @@ +package top.kuanghua.tyuser.controller; + + +import com.alibaba.excel.EasyExcel; +import com.alibaba.nacos.api.naming.CommonParams; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.springframework.web.multipart.MultipartFile; +import top.kuanghua.khcomomon.entity.CommonParamsSelf; +import top.kuanghua.khcomomon.entity.ResResult; +import top.kuanghua.khcomomon.utils.ObjectUtilsSelf; +import top.kuanghua.tyuser.entity.Vci; +import top.kuanghua.tyuser.excel.imp.VciExcelImp; +import top.kuanghua.tyuser.service.VciService; +import org.springframework.web.bind.annotation.*; +import top.kuanghua.tyuser.vo.ExcelCheckResult; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.net.URLEncoder; +import java.util.*; + + +@Api(tags = "VCI设备表(Vci)") +@RestController +@RequestMapping("vci") +public class VciController { + + @Resource + private VciService vciService; + + /** + * 分页查询所有数据 + * @param vci 查询实体 + * @return 所有数据 + */ + @GetMapping("selectPage") + @ApiOperation(value = "分页查询所有数据") + public ResResult selectPage(Vci vci, CommonParamsSelf commonParams) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (ObjectUtils.isNotEmpty(vci.getSn())) { + queryWrapper.like("sn", vci.getSn()); + } + if (ObjectUtils.isNotEmpty(vci.getHardVersion())) { + queryWrapper.like("hard_version", vci.getHardVersion()); + } + if (ObjectUtils.isNotEmpty(vci.getStatus())) { + queryWrapper.like("status", vci.getStatus()); + } + //根据创建时间查询 + queryWrapper.orderByDesc("create_time"); + if(StringUtils.isNotEmpty(commonParams.getStartTime())) { + queryWrapper.between("create_time",commonParams.getStartTime(),commonParams.getEndTime()); + } + + queryWrapper.select("id,sn,hard_version,create_time,status,supplier,receipt_no,product_spec"); + Page vciPage = this.vciService.selectPage(commonParams.getPageNum(), commonParams.getPageSize(), queryWrapper); + return new ResResult().success(vciPage); + } + + /** + * 通过主键查询单条数据 + * + * @param id 主键 + * @return 单条数据 + */ + @GetMapping("selectById") + @ApiOperation(value = "通过id主键查询单条数据") + public ResResult selectById(@RequestParam("id") Integer id) { + return new ResResult().success(this.vciService.selectById(id)); + } + /** + * @Description: 根据id数组查询品牌列表 + * @Param: idList id数组 + * @return: ids列表数据 + */ + @ApiOperation(value = "根据id数组查询品牌列表") + @PostMapping("selectBatchIds") + public ResResult selectBatchIds(@RequestParam("idList") List idList) { + return new ResResult().success(this.vciService.selectBatchIds(idList)); + } + /** + * 新增数据 + * @param vci 实体对象 + * @return 新增结果 + */ + @ApiOperation(value = "新增数据") + @PostMapping("insert") + public ResResult insert(@RequestBody Vci vci) { + return new ResResult().success(this.vciService.insert(vci)); + } + + /** + * 修改数据 + * @param vci 实体对象 + * @return 修改结果 + */ + @ApiOperation(value = "根据id修改数据") + @PutMapping("updateById") + public ResResult updateById(@RequestBody Vci vci) { + return new ResResult().success(this.vciService.updateById(vci)); + } + + /** + * 删除数据 + * @param idList 主键结合 + * @return 删除结果 + */ + @ApiOperation(value = "根据id数组删除数据") + @DeleteMapping("deleteBatchIds") + public ResResult deleteBatchIds(@RequestBody List idList) { + return new ResResult().success(this.vciService.deleteBatchIds(idList)); + } + + @DeleteMapping("deleteById") + @ApiOperation(value = "根据id数组删除数据") + public ResResult deleteById(@RequestParam("id") Integer id) { + return new ResResult().success(this.vciService.deleteById(id)); + } + + @ApiOperation("检查excel") + @PostMapping("validExcel") + public ResResult validExcel(@RequestParam("file") MultipartFile file) throws IOException { + ExcelCheckResult checkResult = vciService.validExcel(file.getInputStream()); + return new ResResult().success(checkResult); + } + + @ApiOperation("导入excel") + @PostMapping("importExcel") + public ResResult importExcel(@RequestBody List vciExcelBo) { + vciService.importExcel(vciExcelBo); + return new ResResult().success(); + } + + @ApiOperation("导出excel") + @GetMapping("exportExcel") + public void exportExcel(HttpServletResponse response,Vci vci, CommonParamsSelf commonParams) throws IOException { + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (ObjectUtils.isNotEmpty(vci.getSn())) { + queryWrapper.like("sn", vci.getSn()); + } + if (ObjectUtils.isNotEmpty(vci.getHardVersion())) { + queryWrapper.like("hard_version", vci.getHardVersion()); + } + if (ObjectUtils.isNotEmpty(vci.getStatus())) { + queryWrapper.like("status", vci.getStatus()); + } + //根据创建时间查询 + queryWrapper.orderByDesc("create_time"); + if(StringUtils.isNotEmpty(commonParams.getStartTime())) { + queryWrapper.between("create_time",commonParams.getStartTime(),commonParams.getEndTime()); + } + + queryWrapper.select("sn,hard_version,create_time,status,supplier,receipt_no,product_spec"); + Page vciPage = this.vciService.selectPage(commonParams.getPageNum(), commonParams.getPageSize(), queryWrapper); + // 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + + String fileName = URLEncoder.encode("Vci导出数据", "UTF-8")+"-"+ ObjectUtilsSelf.getCurrentDateTime(); + response.setHeader("Access-Control-Expose-Headers", "exportFileName"); + response.setHeader("exportFileName", fileName + ".xlsx" ); + EasyExcel.write(response.getOutputStream(), VciExcelImp.class).sheet("模板").doWrite(vciPage.getRecords()); + } + +} diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/entity/Admin.java b/ty-user/src/main/java/top/kuanghua/tyuser/entity/Admin.java index ead9133..3ec4619 100644 --- a/ty-user/src/main/java/top/kuanghua/tyuser/entity/Admin.java +++ b/ty-user/src/main/java/top/kuanghua/tyuser/entity/Admin.java @@ -19,23 +19,24 @@ @ApiModel("用户列表") @TableName(value = "tb_admin") public class Admin extends Model { - private Integer id; - private String status; - private Date addTime; - @ApiModelProperty(value="超级管理员(0.不是,1.是)") - private String isSuper; - @ApiModelProperty(value="用户名") - private String username; - @ApiModelProperty(value="密码") - private String password; - @ApiModelProperty(value="是否删除") - private String isDelete; - @ApiModelProperty(value="手机号") - private String mobile; - @ApiModelProperty(value="邮箱") - private String email; - @ApiModelProperty(value="角色id") - private Integer roleId; + private Integer id; + private String status; + private Date addTime; + @ApiModelProperty(value = "超级管理员(0.不是,1.是)") + private String isSuper; + @ApiModelProperty(value = "用户名") + private String username; + @ApiModelProperty(value = "密码") + private String password; + @ApiModelProperty(value = "是否删除") + private String isDelete; + @ApiModelProperty(value = "手机号") + private String mobile; + @ApiModelProperty(value = "邮箱") + private String email; + @ApiModelProperty(value = "角色id") + private Integer roleId; + /** * 获取主键值 * @@ -45,4 +46,4 @@ public class Admin extends Model { protected Serializable pkVal() { return this.id; } - } +} diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/entity/ErrorCollection.java b/ty-user/src/main/java/top/kuanghua/tyuser/entity/ErrorCollection.java index d205c1f..85f0dc8 100644 --- a/ty-user/src/main/java/top/kuanghua/tyuser/entity/ErrorCollection.java +++ b/ty-user/src/main/java/top/kuanghua/tyuser/entity/ErrorCollection.java @@ -22,6 +22,8 @@ @ApiModel("错误日志相关") @TableName(value = "tb_error_collection") public class ErrorCollection extends Model { + @ApiModelProperty(value = "id主键") + private Long id; @ApiModelProperty(value = "错误日志") private String errorLog; @ApiModelProperty(value = "页面路径") @@ -29,6 +31,6 @@ public class ErrorCollection extends Model { @TableField(fill = FieldFill.INSERT) @ApiModelProperty(value = "创建时间",hidden = true) private Date createTime; - @ApiModelProperty(value = "id主键") - private Long id; + @ApiModelProperty(value = "浏览器类型",hidden = true) + private String browserType; } diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/entity/Vci.java b/ty-user/src/main/java/top/kuanghua/tyuser/entity/Vci.java new file mode 100644 index 0000000..b06117f --- /dev/null +++ b/ty-user/src/main/java/top/kuanghua/tyuser/entity/Vci.java @@ -0,0 +1,51 @@ +package top.kuanghua.tyuser.entity; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.activerecord.Model; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * VCI设备表(Vci)表实体类 + * + * @author kuanghua + * @since 2021-10-22 10:34:43 + */ +@Data +@ApiModel("VCI设备表") +@TableName(value = "tb_vci") +public class Vci extends Model { + @ApiModelProperty(value = "ID") + private Integer id; + @ApiModelProperty(value = "序列号,唯一") + private String sn; + @ApiModelProperty(value = "硬件版本") + private String hardVersion; + @ApiModelProperty(value = "状态:0:未出库、1:已入库") + private Integer status; + @ApiModelProperty(value = "供应商") + private String supplier; + @ApiModelProperty(value = "商品规格") + private String productSpec; + @ApiModelProperty(value = "入库单号") + private String receiptNo; + @ApiModelProperty(value = "入库时间") + @TableField(fill = FieldFill.INSERT) + private Date createTime; + /** + * 获取主键值 + * + * @return 主键值 + */ + @Override + protected Serializable pkVal() { + return this.id; + } +} + diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/excel/cv/VciStatusImpCv.java b/ty-user/src/main/java/top/kuanghua/tyuser/excel/cv/VciStatusImpCv.java new file mode 100644 index 0000000..309d6fb --- /dev/null +++ b/ty-user/src/main/java/top/kuanghua/tyuser/excel/cv/VciStatusImpCv.java @@ -0,0 +1,35 @@ +package top.kuanghua.tyuser.excel.cv; + +import com.alibaba.excel.converters.Converter; +import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; +import com.alibaba.excel.metadata.property.ExcelContentProperty; + +public class VciStatusImpCv implements Converter { + @Override + public Integer convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { + String stringValue = cellData.getStringValue(); + int csId; + if("未入库".equals(stringValue)){ + csId=0; + }else if("已入库".equals(stringValue)){ + csId=1; + }else{ + csId=2; + } + return csId; + } + + //将java的数据类型转为excel数据类型 + @Override + public WriteCellData convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { + String cv=""; + if(0==value){ + cv="未入库"; + }else{ + cv="已入库"; + } + return new WriteCellData<>(cv); + } +} \ No newline at end of file diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/excel/cv/VciTimeCv.java b/ty-user/src/main/java/top/kuanghua/tyuser/excel/cv/VciTimeCv.java new file mode 100644 index 0000000..e11f0ff --- /dev/null +++ b/ty-user/src/main/java/top/kuanghua/tyuser/excel/cv/VciTimeCv.java @@ -0,0 +1,28 @@ +package top.kuanghua.tyuser.excel.cv; + +import com.alibaba.excel.converters.Converter; +import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; +import com.alibaba.excel.metadata.property.ExcelContentProperty; +import top.kuanghua.khcomomon.utils.ObjectUtilsSelf; + +import java.text.SimpleDateFormat; +import java.util.Date; + +public class VciTimeCv implements Converter { + @Override + public Date convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { + String stringValue = cellData.getNumberValue().toString() ; + String DATE_FORMAT = "yyyyMMdd"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT); + Date parse = simpleDateFormat.parse(stringValue); + return parse; + } + + @Override + public WriteCellData convertToExcelData(Date value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { + return new WriteCellData<>(ObjectUtilsSelf.formatDateTime(value)); + } + +} \ No newline at end of file diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/excel/imp/VciExcelImp.java b/ty-user/src/main/java/top/kuanghua/tyuser/excel/imp/VciExcelImp.java new file mode 100644 index 0000000..b9a641d --- /dev/null +++ b/ty-user/src/main/java/top/kuanghua/tyuser/excel/imp/VciExcelImp.java @@ -0,0 +1,41 @@ +package top.kuanghua.tyuser.excel.imp; + +import com.alibaba.excel.annotation.ExcelProperty; +import lombok.Data; +import top.kuanghua.tyuser.excel.cv.VciStatusImpCv; +import top.kuanghua.tyuser.excel.cv.VciTimeCv; + +import java.util.Date; + +/** + * VCI设备表(Vci)表实体类 + * + * @author kuanghua + * @since 2021-10-22 10:34:43 + */ +@Data +public class VciExcelImp{ + //供应商 + @ExcelProperty(value = "供应商") + private String supplier; + // 商品名称 + // 设备号 + @ExcelProperty(value = "设备号") + private String sn; + // 硬件版本 + @ExcelProperty(value = "硬件版本") + private String hardVersion; + // 商品规格 + @ExcelProperty(value = "商品规格") + private String productSpec; + // 入库单号(批次号) + @ExcelProperty(value = "入库单号(批次号)") + private String receiptNo; + // 入库状态 + @ExcelProperty(value = "入库状态",converter = VciStatusImpCv.class) + private Integer status; + // 入库时间 + @ExcelProperty(value = "入库时间",converter = VciTimeCv.class) + private Date createTime; +} + diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/mapper/VciMapper.java b/ty-user/src/main/java/top/kuanghua/tyuser/mapper/VciMapper.java new file mode 100644 index 0000000..7f1e3c9 --- /dev/null +++ b/ty-user/src/main/java/top/kuanghua/tyuser/mapper/VciMapper.java @@ -0,0 +1,8 @@ +package top.kuanghua.tyuser.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import top.kuanghua.tyuser.entity.Vci; + +public interface VciMapper extends BaseMapper { + +} diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/service/VciService.java b/ty-user/src/main/java/top/kuanghua/tyuser/service/VciService.java new file mode 100644 index 0000000..80ba931 --- /dev/null +++ b/ty-user/src/main/java/top/kuanghua/tyuser/service/VciService.java @@ -0,0 +1,133 @@ +package top.kuanghua.tyuser.service; + +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.exception.ExcelDataConvertException; +import com.alibaba.excel.read.listener.ReadListener; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import org.springframework.stereotype.Service; +import top.kuanghua.tyuser.entity.Vci; +import top.kuanghua.tyuser.excel.imp.VciExcelImp; +import top.kuanghua.tyuser.mapper.VciMapper; +import top.kuanghua.tyuser.vo.ExcelCheckResult; + +import javax.annotation.Resource; +import java.io.InputStream; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; + +/** + * (Vci) + * + * @author kuanghua + * @since 2021-10-20 16:14:17 + */ +@Service +public class VciService { + + @Resource + private VciMapper vciMapper; + + public Page selectPage(Integer pageNum, Integer pageSize, QueryWrapper queryWrapper) { + return this.vciMapper.selectPage(new Page(pageNum, pageSize), queryWrapper); + } + + public Vci selectById(Integer id) { + return this.vciMapper.selectById(id); + } + + public List selectBatchIds(List idList) { + return this.vciMapper.selectBatchIds(idList); + } + + public int insert(Vci vci) { + return this.vciMapper.insert(vci); + } + + public int updateById(Vci vci) { + return this.vciMapper.updateById(vci); + } + + public int deleteById(Integer id) { + return this.vciMapper.deleteById(id); + } + + public int deleteBatchIds(List idList) { + return this.vciMapper.deleteBatchIds(idList); + } + + /** + * 导入文件校验 + * @param fileName + * @return + */ + public ExcelCheckResult validExcel(InputStream fileName) { + List errLogList = new ArrayList<>(); + List successList = new ArrayList<>(); + EasyExcel.read(fileName, VciExcelImp.class, new ReadListener() { + /** + * 单次缓存的数据量 + */ + static final int BATCH_COUNT = 3000; + /** + * 临时存储 + */ + private List cachedData = new ArrayList<>(BATCH_COUNT); + + @Override + public void onException(Exception exception, AnalysisContext context) throws Exception { + // 如果是某一个单元格的转换异常 能获取到具体行号 + // 如果要获取头的信息 配合invokeHeadMap使用 + if (exception instanceof ExcelDataConvertException) { + ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) exception; + + String formatString = MessageFormat.format("第{0}行,第{1}列解析异常", + excelDataConvertException.getRowIndex(), excelDataConvertException.getColumnIndex()); + + errLogList.add(formatString); + + } + } + + @Override + public void invoke(VciExcelImp data, AnalysisContext context) { + successList.add(data); + cachedData.add(data); + if (cachedData.size() >= BATCH_COUNT) { + saveData(); + // 存储完成清理 list + cachedData = new ArrayList<>(BATCH_COUNT); + } + } + + @Override + public void doAfterAllAnalysed(AnalysisContext context) { + + } + + /** + * 加上存储数据库 + */ + private void saveData() { + + + } + }).sheet().headRowNumber(1).doRead(); + return new ExcelCheckResult<>(errLogList, successList); + } + + /** + * 导入 + * @param listData + */ + public void importExcel(List listData){ + listData.forEach((item) -> { + //售后维修表 + Vci vci = JSON.parseObject(JSON.toJSONString(item), Vci.class); + vciMapper.insert(vci); + }); + } +} diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/vo/ExcelCheckResult.java b/ty-user/src/main/java/top/kuanghua/tyuser/vo/ExcelCheckResult.java new file mode 100644 index 0000000..483ecb6 --- /dev/null +++ b/ty-user/src/main/java/top/kuanghua/tyuser/vo/ExcelCheckResult.java @@ -0,0 +1,29 @@ +package top.kuanghua.tyuser.vo; + +import lombok.Data; + +import java.util.List; + +/** + * @Title: ExcelCheckResult + * @Description: + * @Auther: kuanghua + * @create 2021-11-02 11:33 + */ + +@Data +public class ExcelCheckResult { + private int errNum; + private int successNum; + private boolean checkResult; + private List errList; + private List successList; + + public ExcelCheckResult(List errList, List successList) { + this.errList = errList; + this.successList = successList; + this.errNum=errList.size(); + this.successNum=successList.size(); + this.checkResult=errList.size()==0; + } +} diff --git a/ty-user/ty-user.iml b/ty-user/ty-user.iml index 94b3e31..0ccd583 100644 --- a/ty-user/ty-user.iml +++ b/ty-user/ty-user.iml @@ -20,6 +20,22 @@ + + + + + + + + + + + + + + + + @@ -127,7 +143,6 @@ - @@ -148,7 +163,6 @@ - @@ -157,7 +171,6 @@ - @@ -178,7 +191,6 @@ - From 2582ec168029155c201a3543bdb35917ce08a514 Mon Sep 17 00:00:00 2001 From: kuanghua <869653722@qq.com> Date: Thu, 11 Nov 2021 18:57:18 +0800 Subject: [PATCH 07/36] func of element-svg icon for side menu --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7bb514f..f532b1f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -#### 更新日志 +``#### 更新日志 ``` // 2021-09-15 1.增加了文件上传下载,为vue3-element-plus提供例子数据 @@ -45,13 +45,13 @@ ty-upload:文件上传服务。使用的技术为fastDFS技术,此服务主 1.在网关中将jwt token和解析后的token信息已经设置在请求头中,在后续转发的微服务可以在请求头中轻松的拿到token和token解析后的数据,不用再通过feign去调用ty-auth获取token信息 ``` -![1631692199271](http://8.135.1.141/file/images/1631692199271.png) +![1631692199271](http://8.135.1.141/file/images/java1.png) ``` 2.此时微服务已经可以在请求通中获取到token和信息,但是feign调用其他微服务的时候却出现了token丢失的情况,此时需要在feign调用服务时将请求头一起转发,那么微服务之前调用时也能获取都token和信息 ``` -![1631692308212](http://8.135.1.141/file/images/1631692308212.png) +![1631692308212](http://8.135.1.141/file/images/java2.png) ``` 3.少于1天时间自动更新token,主要通过gateway的两个拦截器来完成 @@ -61,7 +61,7 @@ AuthorizeFilterAfter:请求后拦截。主要用于token更新校验,和生 https://github.com/jzfai/vue3-admin-template ``` -![1631693000767](http://8.135.1.141/file/images/1631693000767.png) +![1631693000767](http://8.135.1.141/file/images/java3.png) ``` 4.多环境和nacos: @@ -78,9 +78,9 @@ nacos: 优先级:naocs默认加载的config配置文件->extension-configs-> shared-configs ``` -![1631693866876](http://8.135.1.141/file/images/1631693866876.png) +![1631693866876](http://8.135.1.141/file/images/java4.png) -![1631694125676](http://8.135.1.141/file/images/1631694125676.png) +![1631694125676](http://8.135.1.141/file/images/java5.png) ``` 5.easycode模板配置: @@ -89,7 +89,7 @@ nacos: https://www.jianshu.com/p/e4192d7c6844 ``` -![1631695768271](http://8.135.1.141/file/images/1631695768271.png) +![1631695768271](http://8.135.1.141/file/images/java6.png) ### 如何运行 From 480b6a62b73bab6f997c1b44a05863aee3029514 Mon Sep 17 00:00:00 2001 From: jzfai <869653722@qq.com> Date: Thu, 23 Dec 2021 18:31:44 +0800 Subject: [PATCH 08/36] update some func --- README-zh_CN.md | 79 +++ README.md | 187 +++---- controller.mv | 20 +- element-form.mv | 175 +++--- element-table.mv | 127 ++--- entity.mv | 34 +- nacos_config_export_20210915163624.zip | Bin 9322 -> 0 bytes nacos_config_export_20211223172459.zip | Bin 0 -> 14041 bytes oldElementDemo.mv | 512 ------------------ pom.xml | 35 +- .../kuanghua/khcomomon/entity/ResResult.java | 2 +- .../gatewaytwo/GatewayOneApplication.java | 2 +- .../filter/AuthorizeFilterAfter.java | 6 +- .../filter/AuthorizeFilterBefore.java | 14 - .../gatewaytwo/filter/StringTest.java | 24 - .../controller/ErrorCollectionController.java | 6 +- .../tyuser/entity/ErrorCollection.java | 7 +- 17 files changed, 378 insertions(+), 852 deletions(-) create mode 100644 README-zh_CN.md delete mode 100644 nacos_config_export_20210915163624.zip create mode 100644 nacos_config_export_20211223172459.zip delete mode 100644 oldElementDemo.mv delete mode 100644 ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/filter/StringTest.java diff --git a/README-zh_CN.md b/README-zh_CN.md new file mode 100644 index 0000000..ff082aa --- /dev/null +++ b/README-zh_CN.md @@ -0,0 +1,79 @@ +### 前言 + +本架构为springCloud微服务架构,提供基本的jwt权限认证,token更新,以及各微服务之间调用等 +使用的技术如下: + +```json +spring-boot:2.1.4.RELEASE +spring-cloud:Greenwich.SR1 +spring-cloud-starter-gateway:2.1.1.RELEASE +nacos:2.1.3.RELEASE +mybatis-plus: 3.3.2 +rabbitmq:3.7-management +redis: 3.2.9 +mysql:5.7 +``` + +#### 更新日志: + +to look doc ---- +[真香定律!带你用springcloud微服务撸后台(系列文章入口)](https://juejin.cn/post/7036302298435289095) + +#### 线上文档: + +[真香定律!带你用springcloud微服务撸后台(系列文章入口)](https://juejin.cn/post/7036302298435289095) + +#### 开发接口和nacos地址 + +[swager文档地址](http://8.135.1.141/micro-service-doc/swagger-ui.html) + +[nacos地址](http://8.135.1.141:8848/nacos/) naocs: 用户名:jzfai; 密码:123456 + + +#### 线上体验地址: + +[github address](https://github.com/jzfai/micro-service-plus.git) + +[Access address](http://8.135.1.141/vue3-admin-plus) + +国内体验地址:http://8.135.1.141/vue3-admin-plus + +github 地址: https://github.com/jzfai/micro-service-plus.git + + + +#### 目前实现的微服务(后续还会新增新的微服务) + +``` +ty-common: 统一依赖,统一配置管理,feign接口整合等 +本架构的微服务有: +ty-gateway:网关微服务。使用的是spring-cloud-starter-gateway,先对于zull网关来说性能更好。主要实现了,权限控制和拦截,jwt token解析和校验,swagger文件整合,使用令牌技术请求限流等 +ty-auth:权限服务。jwt token生成,解析,校验等,默认配置3天有效期,少于一天自动续约(此处感兴趣的可以查看下源码) +ty-user:用户服务。用户的登录,注册,查看用户信息等一系列功能 +ty-excel:excel文件的读取和导出 +ty-upload:文件上传服务。使用的技术为fastDFS技术,此服务主要用于文件的上传和下载 +``` + + +#### 如何运行 + +```java +//git clone项目 +git clone https://github.com/jzfai/micro-service-plus.git + +//maven 下载依赖,即可运行 +``` + +>注:在Maven Projects->Profies 选择环境时,请不要选择prod环境。目前线上是prod环境下构建的包 + +#### 架构亮点 + +1.网关中将jwt token和解析后的token信息已经设置在请求头中,在后续转发的微服务可以在请求头中,轻松的拿到token和token解析后的数据。不用再通过feign去调用ty-auth,获取token信息。 + +2.各微服务在调用期间,会将请求头的token进行转发。所以在用feign调用微服务时token也不会丢失。 + +3.少于1天时间自动更新token,通过isNeedUpdateToken字段告诉前端需要更新token,实现了token续约的功能 + +4.多环境随意切换。在根目录下的pom.xml配置了profiles可以根据你的需要进行切换环境 + +5.提供了vue3+element-plus和mybits-plus相关的easycode模板。你可以一次性生成前后端模板,极大提高开发效率 \ No newline at end of file diff --git a/README.md b/README.md index f532b1f..ff082aa 100644 --- a/README.md +++ b/README.md @@ -1,108 +1,79 @@ -``#### 更新日志 -``` -// 2021-09-15 -1.增加了文件上传下载,为vue3-element-plus提供例子数据 -``` - -### 前言 -``` -本架构使用的技术为: -spring-boot:2.1.4.RELEASE -spring-cloud:Greenwich.SR1 -spring-cloud-starter-gateway:2.1.1.RELEASE -nacos:2.1.3.RELEASE -mybatis-plus: 3.3.2 -rabbitmq:3.7-management -redis: 3.2.9 -mysql:5.7 -``` - -#### swager文档地址: - -http://8.135.1.141/micro-service-doc/swagger-ui.html - -#### nacos地址(naocs配置请不要删除): - -http://8.135.1.141:8848/nacos/ - -用户名:jzfai -密码:123456 - -#### 微服务(后续还会新增新的微服务) - -``` -ty-common: 统一依赖,统一配置管理,feign接口整合等 -本架构的微服务有: -ty-gateway:网关微服务。使用的是spring-cloud-starter-gateway,先对于zull网关来说性能更好。主要实现了,权限控制和拦截,jwt token解析和校验,swagger文件整合,使用令牌技术请求限流等 -ty-auth:权限服务。jwt token生成,解析,校验等,默认配置3天有效期,少于一天自动续约(此处感兴趣的可以查看下源码) -ty-user:用户服务。用户的登录,注册,查看用户信息等一系列功能 -ty-upload:文件上传服务。使用的技术为fastDFS技术,此服务主要用于文件的上传和下载 -``` - -#### 亮点: - -``` -1.在网关中将jwt token和解析后的token信息已经设置在请求头中,在后续转发的微服务可以在请求头中轻松的拿到token和token解析后的数据,不用再通过feign去调用ty-auth获取token信息 -``` - -![1631692199271](http://8.135.1.141/file/images/java1.png) - -``` -2.此时微服务已经可以在请求通中获取到token和信息,但是feign调用其他微服务的时候却出现了token丢失的情况,此时需要在feign调用服务时将请求头一起转发,那么微服务之前调用时也能获取都token和信息 -``` - -![1631692308212](http://8.135.1.141/file/images/java2.png) - -``` -3.少于1天时间自动更新token,主要通过gateway的两个拦截器来完成 -AuthorizeFilterBefore:请求前拦截。解析token的有效性和是否过期,和配置了白名单的请求方法进行放行 -AuthorizeFilterAfter:请求后拦截。主要用于token更新校验,和生产新的token,通过isNeedUpdateToken字段告诉前端要更新token -如果想知道前端如何更新token可查看: -https://github.com/jzfai/vue3-admin-template -``` - -![1631693000767](http://8.135.1.141/file/images/java3.png) - -``` -4.多环境和nacos: -开发人员可以快速的切换环境以达到开发的目的 -目前为止只添加了 -dev:开发时使用的分支 -prod:发布是切换的分支 -注:配置环境时请在nacos上添加相应的配置文件,不然会报错 -nacos: -注册中心: -通过discovery进行配置,具体可查看源码 -配置中心: -加载顺序:naocs默认加载的config配置文件-> shared-configs->extension-configs -优先级:naocs默认加载的config配置文件->extension-configs-> shared-configs -``` - -![1631693866876](http://8.135.1.141/file/images/java4.png) - -![1631694125676](http://8.135.1.141/file/images/java5.png) - -``` -5.easycode模板配置: -本架构提供了基本的版本生成,可以快速生成,实现前后端的增删改查,前端的easycode生成的模板适配vue-element-template架构,可以把模板直接复制到easycode中生成相应的代码 -不会使用easycode可以查看这里 -https://www.jianshu.com/p/e4192d7c6844 -``` - -![1631695768271](http://8.135.1.141/file/images/java6.png) - -### 如何运行 - -```javascript -克隆项目 -git clone https://github.com/jzfai/micro-service-plus.git -用idea打开项目,加载下载依赖即可运行 -``` - ->注:本项目加入了热更新:运行项目后,使用ctrl+F9快捷键或rebuild下就行直接更新服务 - -#### 如果需要实时交流的可以加入wx群(有vue3+ts视频教程) - - ![http://8.135.1.141/file/images/wx-groud.png](http://8.135.1.141/file/images/wx-groud.png) - -大家的支持是我前进的动力 欢迎加入一起开发 +### 前言 + +本架构为springCloud微服务架构,提供基本的jwt权限认证,token更新,以及各微服务之间调用等 +使用的技术如下: + +```json +spring-boot:2.1.4.RELEASE +spring-cloud:Greenwich.SR1 +spring-cloud-starter-gateway:2.1.1.RELEASE +nacos:2.1.3.RELEASE +mybatis-plus: 3.3.2 +rabbitmq:3.7-management +redis: 3.2.9 +mysql:5.7 +``` + +#### 更新日志: + +to look doc ---- +[真香定律!带你用springcloud微服务撸后台(系列文章入口)](https://juejin.cn/post/7036302298435289095) + +#### 线上文档: + +[真香定律!带你用springcloud微服务撸后台(系列文章入口)](https://juejin.cn/post/7036302298435289095) + +#### 开发接口和nacos地址 + +[swager文档地址](http://8.135.1.141/micro-service-doc/swagger-ui.html) + +[nacos地址](http://8.135.1.141:8848/nacos/) naocs: 用户名:jzfai; 密码:123456 + + +#### 线上体验地址: + +[github address](https://github.com/jzfai/micro-service-plus.git) + +[Access address](http://8.135.1.141/vue3-admin-plus) + +国内体验地址:http://8.135.1.141/vue3-admin-plus + +github 地址: https://github.com/jzfai/micro-service-plus.git + + + +#### 目前实现的微服务(后续还会新增新的微服务) + +``` +ty-common: 统一依赖,统一配置管理,feign接口整合等 +本架构的微服务有: +ty-gateway:网关微服务。使用的是spring-cloud-starter-gateway,先对于zull网关来说性能更好。主要实现了,权限控制和拦截,jwt token解析和校验,swagger文件整合,使用令牌技术请求限流等 +ty-auth:权限服务。jwt token生成,解析,校验等,默认配置3天有效期,少于一天自动续约(此处感兴趣的可以查看下源码) +ty-user:用户服务。用户的登录,注册,查看用户信息等一系列功能 +ty-excel:excel文件的读取和导出 +ty-upload:文件上传服务。使用的技术为fastDFS技术,此服务主要用于文件的上传和下载 +``` + + +#### 如何运行 + +```java +//git clone项目 +git clone https://github.com/jzfai/micro-service-plus.git + +//maven 下载依赖,即可运行 +``` + +>注:在Maven Projects->Profies 选择环境时,请不要选择prod环境。目前线上是prod环境下构建的包 + +#### 架构亮点 + +1.网关中将jwt token和解析后的token信息已经设置在请求头中,在后续转发的微服务可以在请求头中,轻松的拿到token和token解析后的数据。不用再通过feign去调用ty-auth,获取token信息。 + +2.各微服务在调用期间,会将请求头的token进行转发。所以在用feign调用微服务时token也不会丢失。 + +3.少于1天时间自动更新token,通过isNeedUpdateToken字段告诉前端需要更新token,实现了token续约的功能 + +4.多环境随意切换。在根目录下的pom.xml配置了profiles可以根据你的需要进行切换环境 + +5.提供了vue3+element-plus和mybits-plus相关的easycode模板。你可以一次性生成前后端模板,极大提高开发效率 \ No newline at end of file diff --git a/controller.mv b/controller.mv index 8b019d4..48c3e1a 100644 --- a/controller.mv +++ b/controller.mv @@ -17,6 +17,9 @@ $!define ##定义实体对象名 #set($entityName = $!tool.firstLowerCase($!tableInfo.name)) + +import org.apache.commons.lang3.StringUtils; +import top.kuanghua.khcomomon.entity.CommonParams; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.api.ApiController; import com.baomidou.mybatisplus.extension.api.R; @@ -45,12 +48,12 @@ private $!{tableInfo.name}Service $!{serviceName}; */ @GetMapping("selectPage") @ApiOperation(value = "分页查询所有数据") -public ResResult selectPage($!{tableInfo.name} $!entityName, KHCommonParams khCommonParams) { +public ResResult selectPage($!{tableInfo.name} $!entityName, CommonParams commonParams) { QueryWrapper<$!{tableInfo.name}> queryWrapper = new QueryWrapper<>(); #foreach($column in $tableInfo.fullColumn) #if( $!column.comment ) if(ObjectUtils.isNotEmpty($!{entityName}.get$!{tool.firstUpperCase($column.name)}())) { - queryWrapper.or().like("$!{column.name}",$!{entityName}.get$!{tool.firstUpperCase($column.name)}()); + queryWrapper.like("$!{tool.hump2Underline($column.name)}",$!{entityName}.get$!{tool.firstUpperCase($column.name)}()); } #end #end @@ -63,12 +66,14 @@ QueryWrapper<$!{tableInfo.name}> queryWrapper = new QueryWrapper<>(); #end -queryWrapper.or().orderByDesc("create_time"); + if(StringUtils.isNotEmpty(commonParams.getStartTime())) { - queryWrapper.or().between("create_time",commonParams.getStartTime(),commonParams.getEndTime()); +queryWrapper.between("create_time",commonParams.getStartTime(),commonParams.getEndTime()); +queryWrapper.or().orderByDesc("create_time"); } + queryWrapper.select("$StringBj.substring(0,$StringBj.lastIndexOf(','))"); -Page<$!{tableInfo.name}> $!{entityName}Page = this.$!{entityName}Service.selectPage(khCommonParams.getPageNum(), khCommonParams.getPageSize(), queryWrapper); +Page<$!{tableInfo.name}> $!{entityName}Page = this.$!{entityName}Service.selectPage(commonParams.getPageNum(), commonParams.getPageSize(), queryWrapper); return new ResResult().success($!{entityName}Page); } @@ -127,10 +132,9 @@ public ResResult selectBatchIds(@RequestParam("idList") List idList) { return new ResResult().success(this.$!{serviceName}.deleteBatchIds(idList)); } - @DeleteMapping("deleteById") - @ApiOperation(value = "根据id数组删除数据") + @ApiOperation(value = "根据id删除数据") public ResResult deleteById(@RequestParam("id") Integer id) { return new ResResult().success(this.$!{serviceName}.deleteById(id)); } - } \ No newline at end of file + } \ No newline at end of file diff --git a/element-form.mv b/element-form.mv index 01d87bb..d76b914 100644 --- a/element-form.mv +++ b/element-form.mv @@ -3,36 +3,35 @@ $!init $!define ##定义实体对象名 #set($entityName = $!tool.firstLowerCase($!tableInfo.name)) -#set($serviceName = 'ty-user') +#set($serviceName = 'rbox-service') ##保存文件(宏定义) #save($!{entityName}, "Form.vue") + :before-close="closeFormModal"> #foreach($column in $tableInfo.otherColumn) #if(${column.comment}) ##date - #if( $column.comment.indexOf("date") != -1) + #if( $column.comment.indexOf("date") != -1 || $column.name.indexOf("time") != -1|| $column.name.indexOf("data") != -1) + ##cascader #elseif( $column.comment.indexOf("cascader") != -1) - - + 上传 - #end @@ -135,23 +135,31 @@ $!define - 取 消 + 取 消 确 定 + + + + + + + + - - - diff --git a/pom.xml b/pom.xml index 3a221f6..2206d2a 100644 --- a/pom.xml +++ b/pom.xml @@ -102,6 +102,24 @@ 123456 + + test + + true + + + test + 8.135.1.141 + ${baseLinuxIp}:8848 + 1000 + 127.0.0.1 + df87d91b-b1ab-4720-8e1c-5a147edc6ddc + nacos-group-${activatedProperties} + jzfai + 123456 + + + prod @@ -119,22 +137,5 @@ 123456 - - - - - - - - - - - - - - - - - diff --git a/ty-common/src/main/java/top/kuanghua/khcomomon/entity/ResResult.java b/ty-common/src/main/java/top/kuanghua/khcomomon/entity/ResResult.java index f8f8f84..f6686a7 100644 --- a/ty-common/src/main/java/top/kuanghua/khcomomon/entity/ResResult.java +++ b/ty-common/src/main/java/top/kuanghua/khcomomon/entity/ResResult.java @@ -8,7 +8,7 @@ /** * 描述 * - * @author 三国的包子 + * @author kuanghua * @version 1.0 * @package entity * * @since 1.0 diff --git a/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/GatewayOneApplication.java b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/GatewayOneApplication.java index b1a98e5..d767278 100644 --- a/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/GatewayOneApplication.java +++ b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/GatewayOneApplication.java @@ -29,7 +29,7 @@ public Mono resolve(ServerWebExchange exchange) { //1.获取请求request对象 ServerHttpRequest request = exchange.getRequest(); //2.从request中获取ip地址 - String hostString = request.getRemoteAddress().getHostString(); //Ip地址 + String hostString = request.getRemoteAddress().getHostString(); //3.返回 return Mono.just(hostString); } diff --git a/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/filter/AuthorizeFilterAfter.java b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/filter/AuthorizeFilterAfter.java index 1fdc000..f3ca5c0 100644 --- a/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/filter/AuthorizeFilterAfter.java +++ b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/filter/AuthorizeFilterAfter.java @@ -96,15 +96,15 @@ public Mono writeWith(Publisher extends DataBuffer> body) { // 释放掉内存 DataBufferUtils.release(join); String str = new String(content, Charset.forName("UTF-8")); - // log.info("返回体:{}", str); + // log.info("返回体:{}", str); //todo 拦截到的返回体内容,可以随意去操作了 //2.1.2 如果小于一个小时 刷新token //String jwtToken = request.getHeaders().getFirst("AUTHORIZE_TOKEN"); Long expValue = null; Map dataMap=null; try { - // Object reqData=tokenFeign.parseToken(jwtToken); - // Map map = JSON.parseObject(JSON.toJSONString(reqData), Map.class); + //Object reqData=tokenFeign.parseToken(jwtToken); + // Map map = JSON.parseObject(JSON.toJSONString(reqData), Map.class); String tokenInfo = request.getHeaders().getFirst("TOKEN_INFO"); //System.out.println("获取到新的token"+tokenInfo); dataMap = JSON.parseObject(URLDecoder.decode(tokenInfo, "utf-8"), Map.class); diff --git a/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/filter/AuthorizeFilterBefore.java b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/filter/AuthorizeFilterBefore.java index 8d49155..587a9a1 100644 --- a/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/filter/AuthorizeFilterBefore.java +++ b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/filter/AuthorizeFilterBefore.java @@ -103,22 +103,8 @@ public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { httpHeaders.add("TOKEN_INFO", decode); }).build(); //将信息设置到线程中 - //TokenParseInfo tokenParseInfo = new TokenParseInfo(claims); - ServerWebExchange build = exchange.mutate().request(httpRequest).build(); return chain.filter(build); - //2.1.1.将解析出来的jwt token存入请求头中供其他服务读取(转发过去的服务不能接收) - //2.1.2 如果小于一个小时 刷新token -// long expValue = claims.getExpiration().getTime(); -// Long currentData= DateTime.now().plusMinutes(40).getMillis(); -// if(expValue < currentData){ -// String generateToken = JwtUtilsKh.updateToken(claims, RsaUtils.getPrivateKey(priKeyPath), 62); -// JSONObject message = new JSONObject(); -// message.put("code",10000); -// message.put("data",generateToken); -// message.put("msg","更新token"); -// return response.writeWith(Mono.just(getDataBuffer(response,message))); -// } } catch (Exception e) { JSONObject message = new JSONObject(); message.put("code",403); diff --git a/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/filter/StringTest.java b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/filter/StringTest.java deleted file mode 100644 index 75787f0..0000000 --- a/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/filter/StringTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package top.kuanghua.gatewaytwo.filter; - -import org.apache.commons.lang3.StringUtils; - -/** - * @Title: StringTest - * @Description: - * @Auther: kuanghua - * @create 2021/3/15 10:48 - */ -public class StringTest { - public static void main(String[] args) { - String a="/api/doc/swagger"; - String b="doc,swagger"; - - - String[] split = b.split(","); - for (String s : split) { -// System.out.println(StringUtils.contains(a, s)); - } - - - } -} diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/controller/ErrorCollectionController.java b/ty-user/src/main/java/top/kuanghua/tyuser/controller/ErrorCollectionController.java index 3d2fbb0..c5a6512 100644 --- a/ty-user/src/main/java/top/kuanghua/tyuser/controller/ErrorCollectionController.java +++ b/ty-user/src/main/java/top/kuanghua/tyuser/controller/ErrorCollectionController.java @@ -43,13 +43,17 @@ public ResResult selectPage(ErrorCollection errorCollection, KHCommonParams khCo if (ObjectUtils.isNotEmpty(errorCollection.getPageUrl())) { queryWrapper.or().like("page_url", errorCollection.getPageUrl()); } + if (ObjectUtils.isNotEmpty(errorCollection.getVersion())) { + queryWrapper.or().like("version", errorCollection.getVersion()); + } if (ObjectUtils.isNotEmpty(errorCollection.getCreateTime())) { queryWrapper.or().like("create_time", errorCollection.getCreateTime()); } - queryWrapper.or().orderByDesc("create_time"); + if(StringUtils.isNotEmpty(khCommonParams.getStartTime())) { queryWrapper.or().between("create_time",khCommonParams.getStartTime(),khCommonParams.getEndTime()); } + queryWrapper.or().orderByDesc("create_time"); Page errorCollectionPage = this.errorCollectionService.selectPage(khCommonParams.getPageNum(), khCommonParams.getPageSize(), queryWrapper); return new ResResult().success(errorCollectionPage); } diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/entity/ErrorCollection.java b/ty-user/src/main/java/top/kuanghua/tyuser/entity/ErrorCollection.java index 85f0dc8..3372821 100644 --- a/ty-user/src/main/java/top/kuanghua/tyuser/entity/ErrorCollection.java +++ b/ty-user/src/main/java/top/kuanghua/tyuser/entity/ErrorCollection.java @@ -14,7 +14,6 @@ /** * error_log_collection(ErrorCollection)表实体类 - * * @author kuanghua * @since 2021-10-08 11:37:25 */ @@ -28,9 +27,11 @@ public class ErrorCollection extends Model { private String errorLog; @ApiModelProperty(value = "页面路径") private String pageUrl; + @ApiModelProperty(value = "当前版本") + private String version; + @ApiModelProperty(value = "浏览器类型",hidden = true) + private String browserType; @TableField(fill = FieldFill.INSERT) @ApiModelProperty(value = "创建时间",hidden = true) private Date createTime; - @ApiModelProperty(value = "浏览器类型",hidden = true) - private String browserType; } From ab5f66f4cefcaa9282d38a8f0936ef83459f6d07 Mon Sep 17 00:00:00 2001 From: jzfai <869653722@qq.com> Date: Thu, 23 Dec 2021 18:37:36 +0800 Subject: [PATCH 09/36] update some func --- README-zh_CN.md | 7 ++++--- README.md | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README-zh_CN.md b/README-zh_CN.md index ff082aa..19d331a 100644 --- a/README-zh_CN.md +++ b/README-zh_CN.md @@ -3,7 +3,7 @@ 本架构为springCloud微服务架构,提供基本的jwt权限认证,token更新,以及各微服务之间调用等 使用的技术如下: -```json +```java spring-boot:2.1.4.RELEASE spring-cloud:Greenwich.SR1 spring-cloud-starter-gateway:2.1.1.RELEASE @@ -17,11 +17,12 @@ mysql:5.7 #### 更新日志: to look doc ---- -[真香定律!带你用springcloud微服务撸后台(系列文章入口)](https://juejin.cn/post/7036302298435289095) + +[带你用springcloud微服务撸后台(系列文章入口)](https://juejin.cn/post/7044843310204059655) #### 线上文档: -[真香定律!带你用springcloud微服务撸后台(系列文章入口)](https://juejin.cn/post/7036302298435289095) +[带你用springcloud微服务撸后台(系列文章入口)](https://juejin.cn/post/7044843310204059655) #### 开发接口和nacos地址 diff --git a/README.md b/README.md index ff082aa..19d331a 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ 本架构为springCloud微服务架构,提供基本的jwt权限认证,token更新,以及各微服务之间调用等 使用的技术如下: -```json +```java spring-boot:2.1.4.RELEASE spring-cloud:Greenwich.SR1 spring-cloud-starter-gateway:2.1.1.RELEASE @@ -17,11 +17,12 @@ mysql:5.7 #### 更新日志: to look doc ---- -[真香定律!带你用springcloud微服务撸后台(系列文章入口)](https://juejin.cn/post/7036302298435289095) + +[带你用springcloud微服务撸后台(系列文章入口)](https://juejin.cn/post/7044843310204059655) #### 线上文档: -[真香定律!带你用springcloud微服务撸后台(系列文章入口)](https://juejin.cn/post/7036302298435289095) +[带你用springcloud微服务撸后台(系列文章入口)](https://juejin.cn/post/7044843310204059655) #### 开发接口和nacos地址 From c7cd7e728f39ecb6b72ae1579727fcff03de4b41 Mon Sep 17 00:00:00 2001 From: jzfai <869653722@qq.com> Date: Thu, 6 Jan 2022 18:28:53 +0800 Subject: [PATCH 10/36] add send email msg and delay queue --- README.md | 6 +- micro-service-plus.iml | 77 ++--- pom.xml | 5 +- springboot-cloud-mapping.json | 113 ++++++++ .../tyauth/config/Swagger2Config.java | 2 +- .../tyauth/controller/TokenController.java | 10 +- ty-auth/ty-auth.iml | 246 ++++++++-------- .../feign/config/FeignConfiguration.java | 5 +- .../feign/tyauth/feign/TokenFeign.java | 9 +- .../kuanghua/khcomomon/entity/IdWorker.java | 2 +- .../khcomomon/utils/ChineseUtils.java | 6 +- .../kuanghua/khcomomon/utils/IdWorker.java | 2 +- .../khcomomon/utils/ObjectUtilsSelf.java | 25 ++ .../src/main/resources/config/banner.txt | 2 +- ty-common/ty-common.iml | 244 ++++++++-------- ty-example/pom.xml | 60 ++++ .../tyexample/ExampleApplication.java | 15 + .../kuanghua/tyexample/config/BaseConfig.java | 21 ++ .../tyexample/config/RabbitDelayConfig.java | 67 +++++ .../tyexample/config/SmsProperties.java | 25 ++ .../tyexample/config/Swagger2Config.java | 54 ++++ .../controller/RabbitDelayController.java | 36 +++ .../controller/SendEmailController.java | 50 ++++ .../tyexample/controller/SmsController.java | 32 +++ .../listener/RabbitDelayListener.java | 29 ++ .../tyexample/listener/SmsListener.java | 50 ++++ .../tyexample/service/RabbitDelayService.java | 33 +++ .../tyexample/service/SendEmailService.java | 102 +++++++ .../tyexample/service/SendMsgService.java | 42 +++ .../tyexample/utils/SendSmsUtils.java | 54 ++++ ty-example/src/main/main12.iml | 13 + ty-example/src/main/resources/application.yml | 24 ++ ty-example/src/main/resources/bootstrap.yml | 40 +++ ty-example/ty-auth.iml | 222 ++++++++++++++ ty-example/ty-example.iml | 243 ++++++++++++++++ ty-excel/ty-excel.iml | 253 ++++++++-------- .../filter/AuthorizeFilterBefore.java | 2 +- ty-gateway/ty-gateway-one/ty-gateway-one.iml | 271 +++++++++--------- ty-gateway/ty-gateway.iml | 271 +++++++++--------- .../tyupload/config/Swagger2Config.java | 2 +- .../tyupload/controller/NacosTestDemo.java | 3 +- .../tyupload/service/UploadService.java | 1 - ty-upload/ty-upload.iml | 247 ++++++++-------- .../tyuser/controller/BrandController.java | 16 +- .../controller/ErrorCollectionController.java | 12 +- .../tyuser/controller/UserController.java | 8 +- .../tyuser/controller/VciController.java | 1 - .../tyuser/excel/imp/VciExcelImp.java | 1 - .../kuanghua/tyuser/service/UserService.java | 2 - ty-user/ty-user.iml | 253 ++++++++-------- 50 files changed, 2366 insertions(+), 943 deletions(-) create mode 100644 springboot-cloud-mapping.json create mode 100644 ty-example/pom.xml create mode 100644 ty-example/src/main/java/top/kuanghua/tyexample/ExampleApplication.java create mode 100644 ty-example/src/main/java/top/kuanghua/tyexample/config/BaseConfig.java create mode 100644 ty-example/src/main/java/top/kuanghua/tyexample/config/RabbitDelayConfig.java create mode 100644 ty-example/src/main/java/top/kuanghua/tyexample/config/SmsProperties.java create mode 100644 ty-example/src/main/java/top/kuanghua/tyexample/config/Swagger2Config.java create mode 100644 ty-example/src/main/java/top/kuanghua/tyexample/controller/RabbitDelayController.java create mode 100644 ty-example/src/main/java/top/kuanghua/tyexample/controller/SendEmailController.java create mode 100644 ty-example/src/main/java/top/kuanghua/tyexample/controller/SmsController.java create mode 100644 ty-example/src/main/java/top/kuanghua/tyexample/listener/RabbitDelayListener.java create mode 100644 ty-example/src/main/java/top/kuanghua/tyexample/listener/SmsListener.java create mode 100644 ty-example/src/main/java/top/kuanghua/tyexample/service/RabbitDelayService.java create mode 100644 ty-example/src/main/java/top/kuanghua/tyexample/service/SendEmailService.java create mode 100644 ty-example/src/main/java/top/kuanghua/tyexample/service/SendMsgService.java create mode 100644 ty-example/src/main/java/top/kuanghua/tyexample/utils/SendSmsUtils.java create mode 100644 ty-example/src/main/main12.iml create mode 100644 ty-example/src/main/resources/application.yml create mode 100644 ty-example/src/main/resources/bootstrap.yml create mode 100644 ty-example/ty-auth.iml create mode 100644 ty-example/ty-example.iml diff --git a/README.md b/README.md index 19d331a..48b11e6 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ 使用的技术如下: ```java -spring-boot:2.1.4.RELEASE -spring-cloud:Greenwich.SR1 -spring-cloud-starter-gateway:2.1.1.RELEASE +spring-boot:2.2.4.RELEASE +spring-cloud:Hoxton.SR12 +spring-cloud-starter-gateway:2.2.9.RELEASE nacos:2.1.3.RELEASE mybatis-plus: 3.3.2 rabbitmq:3.7-management diff --git a/micro-service-plus.iml b/micro-service-plus.iml index 7f10b3d..aad4444 100644 --- a/micro-service-plus.iml +++ b/micro-service-plus.iml @@ -8,50 +8,61 @@ - - - - - - - - - + + + + + + + + + - - - - - - - + + + + + + + - + + + + + + + + + + + + - - - - + + + + + + - - - - - - + + + + - - - - - - + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 2206d2a..715f5ce 100644 --- a/pom.xml +++ b/pom.xml @@ -15,17 +15,18 @@ ty-user ty-upload ty-excel + ty-example org.springframework.boot spring-boot-starter-parent - 2.1.4.RELEASE + 2.2.4.RELEASE - Greenwich.SR1 + Hoxton.SR12 diff --git a/springboot-cloud-mapping.json b/springboot-cloud-mapping.json new file mode 100644 index 0000000..c970a57 --- /dev/null +++ b/springboot-cloud-mapping.json @@ -0,0 +1,113 @@ +{ + "git": { + "branch": "dc8e0454e3d0299e7002610a3f82af001013e959", + "commit": { + "id": "dc8e045", + "time": "2022-01-02T10:10:06Z" + } + }, + "build": { + "version": "0.0.1-SNAPSHOT", + "artifact": "start-site", + "versions": { + "spring-boot": "2.6.2", + "initializr": "0.12.0-SNAPSHOT" + }, + "name": "start.spring.io website", + "time": "2022-01-02T10:11:21.501Z", + "group": "io.spring.start" + }, + "bom-ranges": { + "azure": { + "3.2.0": "Spring Boot >=2.3.0.M1 and <2.4.0-M1", + "3.5.0": "Spring Boot >=2.4.0.M1 and <2.5.0-M1", + "3.10.0": "Spring Boot >=2.5.0.M1 and <2.6.0-M1" + }, + "codecentric-spring-boot-admin": { + "2.4.3": "Spring Boot >=2.3.0.M1 and <2.5.0-M1", + "2.5.5": "Spring Boot >=2.5.0.M1 and <2.6.0-M1" + }, + "solace-spring-boot": { + "1.1.0": "Spring Boot >=2.3.0.M1 and <2.6.0-M1" + }, + "solace-spring-cloud": { + "1.1.1": "Spring Boot >=2.3.0.M1 and <2.4.0-M1", + "2.1.0": "Spring Boot >=2.4.0.M1 and <2.6.0-M1" + }, + "spring-cloud": { + "Hoxton.SR12": "Spring Boot >=2.2.0.RELEASE and <2.4.0.M1", + "2020.0.5": "Spring Boot >=2.4.0.M1 and <2.6.0-M1", + "2021.0.0-M1": "Spring Boot >=2.6.0-M1 and <2.6.0-M3", + "2021.0.0-M3": "Spring Boot >=2.6.0-M3 and <2.6.0-RC1", + "2021.0.0-RC1": "Spring Boot >=2.6.0-RC1 and <2.6.1", + "2021.0.0": "Spring Boot >=2.6.1 and <2.6.3-SNAPSHOT", + "2021.0.1-SNAPSHOT": "Spring Boot >=2.6.3-SNAPSHOT and <2.7.0-M1" + }, + "spring-cloud-gcp": { + "2.0.7": "Spring Boot >=2.4.0-M1 and <2.6.0-M1" + }, + "spring-cloud-services": { + "2.3.0.RELEASE": "Spring Boot >=2.3.0.RELEASE and <2.4.0-M1", + "2.4.1": "Spring Boot >=2.4.0-M1 and <2.5.0-M1", + "3.3.0": "Spring Boot >=2.5.0-M1 and <2.6.0-M1" + }, + "spring-geode": { + "1.3.12.RELEASE": "Spring Boot >=2.3.0.M1 and <2.4.0-M1", + "1.4.13": "Spring Boot >=2.4.0-M1 and <2.5.0-M1", + "1.5.7": "Spring Boot >=2.5.0-M1 and <2.6.0-M1", + "1.6.1": "Spring Boot >=2.6.0-M1 and <2.7.0-M1" + }, + "vaadin": { + "14.8.1": "Spring Boot >=2.1.0.RELEASE and <2.8.0-M1" + }, + "wavefront": { + "2.0.2": "Spring Boot >=2.1.0.RELEASE and <2.4.0-M1", + "2.1.1": "Spring Boot >=2.4.0-M1 and <2.5.0-M1", + "2.2.2": "Spring Boot >=2.5.0-M1 and <2.7.0-M1" + } + }, + "dependency-ranges": { + "native": { + "0.9.0": "Spring Boot >=2.4.3 and <2.4.4", + "0.9.1": "Spring Boot >=2.4.4 and <2.4.5", + "0.9.2": "Spring Boot >=2.4.5 and <2.5.0-M1", + "0.10.0": "Spring Boot >=2.5.0-M1 and <2.5.2", + "0.10.1": "Spring Boot >=2.5.2 and <2.5.3", + "0.10.2": "Spring Boot >=2.5.3 and <2.5.4", + "0.10.3": "Spring Boot >=2.5.4 and <2.5.5", + "0.10.4": "Spring Boot >=2.5.5 and <2.5.6", + "0.10.5": "Spring Boot >=2.5.6 and <2.5.9-SNAPSHOT", + "0.10.6-SNAPSHOT": "Spring Boot >=2.5.9-SNAPSHOT and <2.6.0-M1", + "0.11.0-M1": "Spring Boot >=2.6.0-M1 and <2.6.0-RC1", + "0.11.0-M2": "Spring Boot >=2.6.0-RC1 and <2.6.0", + "0.11.0-RC1": "Spring Boot >=2.6.0 and <2.6.1", + "0.11.0": "Spring Boot >=2.6.1 and <2.6.2", + "0.11.1": "Spring Boot >=2.6.2 and <2.6.3-SNAPSHOT", + "0.11.2-SNAPSHOT": "Spring Boot >=2.6.3-SNAPSHOT and <2.7.0-M1" + }, + "okta": { + "1.4.0": "Spring Boot >=2.2.0.RELEASE and <2.4.0-M1", + "1.5.1": "Spring Boot >=2.4.0-M1 and <2.4.1", + "2.0.1": "Spring Boot >=2.4.1 and <2.5.0-M1", + "2.1.4": "Spring Boot >=2.5.0-M1 and <2.6.0-M1" + }, + "mybatis": { + "2.1.4": "Spring Boot >=2.1.0.RELEASE and <2.5.0-M1", + "2.2.1": "Spring Boot >=2.5.0-M1" + }, + "camel": { + "3.5.0": "Spring Boot >=2.3.0.M1 and <2.4.0-M1", + "3.10.0": "Spring Boot >=2.4.0.M1 and <2.5.0-M1", + "3.13.0": "Spring Boot >=2.5.0.M1 and <2.6.0-M1", + "3.14.0": "Spring Boot >=2.6.0.M1 and <2.7.0-M1" + }, + "picocli": { + "4.6.2": "Spring Boot >=2.4.0.RELEASE and <2.6.0-M1" + }, + "open-service-broker": { + "3.2.0": "Spring Boot >=2.3.0.M1 and <2.4.0-M1", + "3.3.1": "Spring Boot >=2.4.0-M1 and <2.5.0-M1", + "3.4.0-M2": "Spring Boot >=2.5.0-M1 and <2.6.0-M1" + } + } +} \ No newline at end of file diff --git a/ty-auth/src/main/java/top/kuanghua/tyauth/config/Swagger2Config.java b/ty-auth/src/main/java/top/kuanghua/tyauth/config/Swagger2Config.java index a7913b0..fc50e49 100644 --- a/ty-auth/src/main/java/top/kuanghua/tyauth/config/Swagger2Config.java +++ b/ty-auth/src/main/java/top/kuanghua/tyauth/config/Swagger2Config.java @@ -43,7 +43,7 @@ public Docket api() { private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("标题:kuanghua") - .description("描述:新一代的前端架构") + .description("描述:新一代的微服务架构") .contact(new Contact("jzfai", null, "869653722@qq.com")) .version("版本号:2.9") .build(); diff --git a/ty-auth/src/main/java/top/kuanghua/tyauth/controller/TokenController.java b/ty-auth/src/main/java/top/kuanghua/tyauth/controller/TokenController.java index 1339dbc..19130a1 100644 --- a/ty-auth/src/main/java/top/kuanghua/tyauth/controller/TokenController.java +++ b/ty-auth/src/main/java/top/kuanghua/tyauth/controller/TokenController.java @@ -32,9 +32,7 @@ public class TokenController { @ApiOperation("获取token信息") @PostMapping("parseToken") public ResResult parseToken(@RequestParam("jwtToken") String jwtToken){ - System.out.println("解析出来token了"); Claims claims = this.tokenService.parseToken(jwtToken); - System.out.println(claims); return new ResResult().success(claims); } @@ -45,8 +43,8 @@ public ResResult parseToken(@RequestParam("jwtToken") String jwtToken){ @PostMapping("generateToken") //@RequestHeader("authorize_token") String authorize_token public ResResult generateToken(@RequestBody Map tokenMap){ - System.out.println("生成的代码信息"); - System.out.println(tokenMap); +// System.out.println("生成的代码信息"); +// System.out.println(tokenMap); // System.out.println("generateToken获得请求头的信息"); @@ -64,8 +62,8 @@ public ResResult generateToken(@RequestBody Map tokenMap){ @PostMapping("updateToken") public ResResult updateToken(@RequestBody Map map){ String updateToken = this.tokenService.updateToken(map); - System.out.println("生成信息的token"+updateToken); - System.out.println("生成信息的token"+map.toString()); +// System.out.println("生成信息的token"+updateToken); +// System.out.println("生成信息的token"+map.toString()); return new ResResult().success(updateToken); } } diff --git a/ty-auth/ty-auth.iml b/ty-auth/ty-auth.iml index 9447a05..7d21540 100644 --- a/ty-auth/ty-auth.iml +++ b/ty-auth/ty-auth.iml @@ -21,38 +21,39 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - + - - - + + + - + @@ -71,16 +72,7 @@ - - - - - - - - - - + @@ -89,134 +81,150 @@ - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - + + + - - - + + + + + + + + + - - - + + + - + - + - + - + - + - - - + + + - - - - - - - + + + + + + + + + + + + + + + + + + - - - - + + + + + + - - - - - - + + + + - - - - - + + + + + \ No newline at end of file diff --git a/ty-common/src/main/java/top/kuanghua/feign/config/FeignConfiguration.java b/ty-common/src/main/java/top/kuanghua/feign/config/FeignConfiguration.java index ca016ac..ba14433 100644 --- a/ty-common/src/main/java/top/kuanghua/feign/config/FeignConfiguration.java +++ b/ty-common/src/main/java/top/kuanghua/feign/config/FeignConfiguration.java @@ -2,6 +2,8 @@ import feign.RequestInterceptor; import feign.RequestTemplate; +import lombok.Data; +import lombok.extern.log4j.Log4j2; import org.springframework.context.annotation.Configuration; import org.springframework.util.ObjectUtils; import org.springframework.web.context.request.RequestContextHolder; @@ -13,6 +15,7 @@ /*feign转发时将请求的参数设转发到请求头上*/ @Configuration +@Log4j2 public class FeignConfiguration implements RequestInterceptor { @Override public void apply(RequestTemplate template) { @@ -25,7 +28,7 @@ public void apply(RequestTemplate template) { while (headerNames.hasMoreElements()) { String name = headerNames.nextElement(); String values = request.getHeader(name); - //System.out.println("等到的hearder头消息"+name+values); + template.header(name, values); } } diff --git a/ty-common/src/main/java/top/kuanghua/feign/tyauth/feign/TokenFeign.java b/ty-common/src/main/java/top/kuanghua/feign/tyauth/feign/TokenFeign.java index 104dea9..e58032b 100644 --- a/ty-common/src/main/java/top/kuanghua/feign/tyauth/feign/TokenFeign.java +++ b/ty-common/src/main/java/top/kuanghua/feign/tyauth/feign/TokenFeign.java @@ -17,23 +17,26 @@ * @create 2021/1/31 16:31 */ + +//FeignConfiguration.class -> forward req params of include the token @FeignClient(name="ty-auth",configuration = FeignConfiguration.class) @RequestMapping("token") public interface TokenFeign { + /* - * 解析token + * parse token * */ @PostMapping("parseToken") ResResult parseToken(@RequestParam("jwtToken") String jwtToken); /* - * 生成token + * create token * */ @PostMapping("generateToken") ResResult generateToken(@RequestBody Map map); /* - * 更新token + * update token * */ @PostMapping("updateToken") ResResult updateToken(@RequestBody Map map); diff --git a/ty-common/src/main/java/top/kuanghua/khcomomon/entity/IdWorker.java b/ty-common/src/main/java/top/kuanghua/khcomomon/entity/IdWorker.java index 3956250..f39e9ea 100644 --- a/ty-common/src/main/java/top/kuanghua/khcomomon/entity/IdWorker.java +++ b/ty-common/src/main/java/top/kuanghua/khcomomon/entity/IdWorker.java @@ -154,7 +154,7 @@ protected static long getDatacenterId(long maxDatacenterId) { id = id % (maxDatacenterId + 1); } } catch (Exception e) { - System.out.println(" getDatacenterId: " + e.getMessage()); + // System.out.println(" getDatacenterId: " + e.getMessage()); } return id; } diff --git a/ty-common/src/main/java/top/kuanghua/khcomomon/utils/ChineseUtils.java b/ty-common/src/main/java/top/kuanghua/khcomomon/utils/ChineseUtils.java index ac135d7..48f83b7 100644 --- a/ty-common/src/main/java/top/kuanghua/khcomomon/utils/ChineseUtils.java +++ b/ty-common/src/main/java/top/kuanghua/khcomomon/utils/ChineseUtils.java @@ -58,8 +58,8 @@ public static String getRandomLengthChiness(int start, int end) { } public static void main(String args[]) { - System.out.println(ChineseUtils.getChinese()); - System.out.println(ChineseUtils.getFixedLengthChinese(20)); - System.out.println(ChineseUtils.getRandomLengthChiness(2, 5)); +// System.out.println(ChineseUtils.getChinese()); +// System.out.println(ChineseUtils.getFixedLengthChinese(20)); +// System.out.println(ChineseUtils.getRandomLengthChiness(2, 5)); } } diff --git a/ty-common/src/main/java/top/kuanghua/khcomomon/utils/IdWorker.java b/ty-common/src/main/java/top/kuanghua/khcomomon/utils/IdWorker.java index b498e94..520a05f 100644 --- a/ty-common/src/main/java/top/kuanghua/khcomomon/utils/IdWorker.java +++ b/ty-common/src/main/java/top/kuanghua/khcomomon/utils/IdWorker.java @@ -154,7 +154,7 @@ protected static long getDatacenterId(long maxDatacenterId) { id = id % (maxDatacenterId + 1); } } catch (Exception e) { - System.out.println(" getDatacenterId: " + e.getMessage()); + //System.out.println(" getDatacenterId: " + e.getMessage()); } return id; } diff --git a/ty-common/src/main/java/top/kuanghua/khcomomon/utils/ObjectUtilsSelf.java b/ty-common/src/main/java/top/kuanghua/khcomomon/utils/ObjectUtilsSelf.java index a9fb5ce..b8422c0 100644 --- a/ty-common/src/main/java/top/kuanghua/khcomomon/utils/ObjectUtilsSelf.java +++ b/ty-common/src/main/java/top/kuanghua/khcomomon/utils/ObjectUtilsSelf.java @@ -2,8 +2,10 @@ import com.alibaba.fastjson.JSON; import org.apache.commons.lang3.StringUtils; +import org.springframework.web.multipart.MultipartFile; import top.kuanghua.khcomomon.entity.ResResult; +import java.io.File; import java.lang.reflect.Array; import java.text.SimpleDateFormat; import java.util.Collection; @@ -123,4 +125,27 @@ public static String formatDateTime(Date date){ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 return df.format(date); } + + + /** + * MultipartFile change to file + * @param multiFile + * @return + */ + public static File MultipartFileToFile(MultipartFile multiFile) { + // 获取文件名 + String fileName = multiFile.getOriginalFilename(); + // 获取文件后缀 + String prefix = fileName.substring(fileName.lastIndexOf(".")); + // 若须要防止生成的临时文件重复,能够在文件名后添加随机码 + + try { + File file = File.createTempFile(fileName, prefix); + multiFile.transferTo(file); + return file; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } } \ No newline at end of file diff --git a/ty-common/src/main/resources/config/banner.txt b/ty-common/src/main/resources/config/banner.txt index 4b6d321..1a1dcb9 100644 --- a/ty-common/src/main/resources/config/banner.txt +++ b/ty-common/src/main/resources/config/banner.txt @@ -4,4 +4,4 @@ \\/ ___)| |_)| | | | | || (_| | ) ) ) )----☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ - :: jzfai好嗨喔框架:: (v2.1.4RELEASE) \ No newline at end of file + :: new general micro service construct:: (v2.2.4RELEASE) \ No newline at end of file diff --git a/ty-common/ty-common.iml b/ty-common/ty-common.iml index 3ffe7b5..e823a48 100644 --- a/ty-common/ty-common.iml +++ b/ty-common/ty-common.iml @@ -20,48 +20,49 @@ - - - + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - + - + - - - + + + - + @@ -81,15 +82,13 @@ - - - - - - - - - + + + + + + + @@ -98,123 +97,132 @@ - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - + + + - - - + + + + + + + + + - - - + + + - + - + - + - + - - - - + + + + + + + + + - - - - + + + + + - - - - - - + + + + - - - - + + + + \ No newline at end of file diff --git a/ty-example/pom.xml b/ty-example/pom.xml new file mode 100644 index 0000000..f809565 --- /dev/null +++ b/ty-example/pom.xml @@ -0,0 +1,60 @@ + + + + micro-service-plus + top.kuanghua + 1.0-SNAPSHOT + + 4.0.0 + + ty-example + + + top.kuanghua + ty-common + 1.0-SNAPSHOT + + + top.kuanghua + user-api + 1.0-SNAPSHOT + + + + com.aliyun + aliyun-java-sdk-core + 4.5.3 + + + + org.springframework.boot + spring-boot-starter-mail + + + + + ${project.artifactId} + + + src/main/resources + true + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.1 + + true + + + + + \ No newline at end of file diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/ExampleApplication.java b/ty-example/src/main/java/top/kuanghua/tyexample/ExampleApplication.java new file mode 100644 index 0000000..003fdb0 --- /dev/null +++ b/ty-example/src/main/java/top/kuanghua/tyexample/ExampleApplication.java @@ -0,0 +1,15 @@ +package top.kuanghua.tyexample; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; + +@SpringBootApplication +@EnableScheduling +@EnableAsync +public class ExampleApplication { + public static void main(String[] args) { + SpringApplication.run(ExampleApplication.class,args); + } +} diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/config/BaseConfig.java b/ty-example/src/main/java/top/kuanghua/tyexample/config/BaseConfig.java new file mode 100644 index 0000000..9c668a7 --- /dev/null +++ b/ty-example/src/main/java/top/kuanghua/tyexample/config/BaseConfig.java @@ -0,0 +1,21 @@ +package top.kuanghua.tyexample.config; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +/** + * @Title: BaseConfig + * @Description: + * @Auther: kuanghua + * @create 2020/8/23 21:52 + */ +/* + * 总结:1.@Configuration 下的@ComponentScan回将包下带有@Component扫描变成配置类, + * 而@SpringBootApplication扫描的只会变成普通类 + * */ +@Configuration +//扫描公用包的配置和自身的配置类 +@ComponentScan(basePackages = {"top.kuanghua.khcomomon"}) +public class BaseConfig { + +} diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/config/RabbitDelayConfig.java b/ty-example/src/main/java/top/kuanghua/tyexample/config/RabbitDelayConfig.java new file mode 100644 index 0000000..1959f7f --- /dev/null +++ b/ty-example/src/main/java/top/kuanghua/tyexample/config/RabbitDelayConfig.java @@ -0,0 +1,67 @@ +package top.kuanghua.tyexample.config; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.amqp.core.*; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.HashMap; +import java.util.Map; + +/** + * @Title: Configuration + * @Description: + * @Auther: kuanghua + * @create 2022/1/05 10:04 + */ +@Configuration +@Slf4j +public class RabbitDelayConfig { + + /*死信部分*/ + public static final String ORDER_DELAY_QUEUE = "queue.delay.user.order"; + public static final String ORDER_DELAY_EXCHANGE = "exchange.delay.user.order"; + public static final String ORDER_DELAY_ROUTING_KEY = "delay_order"; + /*普通交换机*/ + public static final String ORDER_QUEUE_NAME = "queue.user.order"; + public static final String ORDER_EXCHANGE_NAME = "exchange.user.order"; + public static final String ORDER_ROUTING_KEY = "order"; + + /* + * DELAY_EXCHANGE + * 死信交换机原理:发送到死信交换机(在有效期时间内接收信息不进行转发,超时则进行转发到其他队列) + * */ + @Bean + public Queue delayOrderQueue() { + Map params = new HashMap<>(); + // 转发的队列交换机的名称 + params.put("x-dead-letter-exchange", ORDER_EXCHANGE_NAME); + // 转发的队列队列的路由名称 + params.put("x-dead-letter-routing-key", ORDER_ROUTING_KEY); + return new Queue(ORDER_DELAY_QUEUE, true, false, false, params); + } + @Bean + public DirectExchange orderDelayExchange() { + return new DirectExchange(ORDER_DELAY_EXCHANGE); + } + + + @Bean + public Binding dlxBinding() { + return BindingBuilder.bind(delayOrderQueue()).to(orderDelayExchange()).with(ORDER_DELAY_ROUTING_KEY); + } + + /*普通交换机*/ + @Bean + public Queue orderQueue() { + return new Queue(ORDER_QUEUE_NAME, true); + } + @Bean + public TopicExchange orderTopicExchange() { + return new TopicExchange(ORDER_EXCHANGE_NAME); + } + @Bean + public Binding orderBinding() { + return BindingBuilder.bind(orderQueue()).to(orderTopicExchange()).with(ORDER_ROUTING_KEY); + } +} diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/config/SmsProperties.java b/ty-example/src/main/java/top/kuanghua/tyexample/config/SmsProperties.java new file mode 100644 index 0000000..ab4ad5e --- /dev/null +++ b/ty-example/src/main/java/top/kuanghua/tyexample/config/SmsProperties.java @@ -0,0 +1,25 @@ +package top.kuanghua.tyexample.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +/** + * @Title: SmsProperties + * @Description: + * @Auther:jzfai + * @Version: 1.0 + * @create 2020/3/13 18:19 + */ +@Component +@ConfigurationProperties(prefix = "kuanghua.sms") +@Data +public class SmsProperties { + String accessKeyId; + + String accessKeySecret; + + String signName; + + String verifyCodeTemplate; +} diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/config/Swagger2Config.java b/ty-example/src/main/java/top/kuanghua/tyexample/config/Swagger2Config.java new file mode 100644 index 0000000..4e14a84 --- /dev/null +++ b/ty-example/src/main/java/top/kuanghua/tyexample/config/Swagger2Config.java @@ -0,0 +1,54 @@ +package top.kuanghua.tyexample.config; + +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.stereotype.Component; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Component +@EnableSwagger2 //开启在线接口文档 +//配置包扫描 +public class Swagger2Config { + private boolean swagger_is_enable = true; + + @Value("${server.port}") + private String port; + + @Bean + public Docket api() { + return new Docket(DocumentationType.SWAGGER_2) + .enable(swagger_is_enable) + //.host(this.ipAddr + ":" + this.port) + .apiInfo(apiInfo()) + .select() + .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) + //.apis(basePackage("top.kuanghua.swagger.controller")) + .paths(PathSelectors.any()) + .build(); + } + + /** + * 构建 api文档的详细信息函数 + * @return + */ + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("标题:kuanghua") + .description("描述:新一代的微服务架构") + .contact(new Contact("jzfai", null, "869653722@qq.com")) + .version("版本号:2.9") + .build(); + } + + /** + * http://localhost:8080/swagger-ui.html + */ +} diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/controller/RabbitDelayController.java b/ty-example/src/main/java/top/kuanghua/tyexample/controller/RabbitDelayController.java new file mode 100644 index 0000000..8c4f6f0 --- /dev/null +++ b/ty-example/src/main/java/top/kuanghua/tyexample/controller/RabbitDelayController.java @@ -0,0 +1,36 @@ +package top.kuanghua.tyexample.controller; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +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.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import top.kuanghua.khcomomon.entity.ResResult; +import top.kuanghua.tyexample.service.RabbitDelayService; + +import javax.annotation.Resource; + +/** + * @Title: RabbitDelayController + * @Description: + * @Auther: kuanghua + * @create 2022-01-06 17:23 + */ +@Api(tags = "延时队列") +@RestController +@RequestMapping("delayQueue") +public class RabbitDelayController { + + @Resource + private RabbitDelayService rabbitDelayService; + + @ApiOperation(value = "测试延时队列") + @GetMapping("convertAndSend") + public ResResult convertAndSend(@ApiParam("延时时间(s)") @RequestParam("time") Integer time) { + rabbitDelayService.convertAndSend(time); + return new ResResult().success(); + } +} diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/controller/SendEmailController.java b/ty-example/src/main/java/top/kuanghua/tyexample/controller/SendEmailController.java new file mode 100644 index 0000000..7762880 --- /dev/null +++ b/ty-example/src/main/java/top/kuanghua/tyexample/controller/SendEmailController.java @@ -0,0 +1,50 @@ +package top.kuanghua.tyexample.controller; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import top.kuanghua.khcomomon.entity.ResResult; +import top.kuanghua.tyexample.service.SendEmailService; + +import javax.mail.MessagingException; +import java.io.IOException; + +/** + * @Title: SendEmailController + * @Description: + * @Auther: kuanghua + * @create 2020/8/20 22:41 + */ +@Api(tags = "发送邮件") +@RestController +@RequestMapping("email") +public class SendEmailController { + + @Autowired + private SendEmailService sendEmailService; + + @ApiOperation(value = "发送普通文本邮件") + @GetMapping("sendEmailText") + public ResResult sendEmailText(@RequestParam(name = "subject",defaultValue = "这是主题") String subject, + @RequestParam(name = "text",defaultValue = "发送的文本(这是测试文本)") String text, + @RequestParam(name = "sendTo",defaultValue = "1319404169@qq.com") String sendTo) { + sendEmailService.sendEmailText(subject, text, sendTo); + return new ResResult().success("发送邮件成功"); + } + + @ApiOperation(value = "发送文本邮件(可以带附件)", notes = "可以带附件 ") + @PostMapping("sendMimeMail") + public ResResult sendMimeMail(@RequestParam(name = "subject",defaultValue = "这是主题") String subject, + @RequestParam(name = "text",defaultValue = "发送的文本(这是测试文本)") String text, + @RequestParam(name = "sendTo",defaultValue = "1319404169@qq.com") String sendTo, + MultipartFile file) + throws IOException, MessagingException, InterruptedException { + if (file.getOriginalFilename().isEmpty()) { + return new ResResult().error("文件上传空"); + } + sendEmailService.sendMimeMail(subject, text, sendTo, file); + return new ResResult().success("发送邮件成功"); + } +} diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/controller/SmsController.java b/ty-example/src/main/java/top/kuanghua/tyexample/controller/SmsController.java new file mode 100644 index 0000000..d986fc0 --- /dev/null +++ b/ty-example/src/main/java/top/kuanghua/tyexample/controller/SmsController.java @@ -0,0 +1,32 @@ +package top.kuanghua.tyexample.controller; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import top.kuanghua.khcomomon.entity.ResResult; +import top.kuanghua.tyexample.service.SendMsgService; + +/** + * @Title: SmsController @Description: @Auther: + * + * @create 2020/8/20 11:33 + */ +@Api(tags = "短信") +@RestController +@RequestMapping("sms") +public class SmsController { + + @Autowired + private SendMsgService sendMsgService; + @ApiOperation(value = "发送短信") + @PostMapping("sendSms") + public ResResult sendSms(@ApiParam("手机号") @RequestParam("phone") String phone) { + sendMsgService.sendMsg(phone); + return new ResResult().success("短信发送成功"); + } +} diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/listener/RabbitDelayListener.java b/ty-example/src/main/java/top/kuanghua/tyexample/listener/RabbitDelayListener.java new file mode 100644 index 0000000..de4130d --- /dev/null +++ b/ty-example/src/main/java/top/kuanghua/tyexample/listener/RabbitDelayListener.java @@ -0,0 +1,29 @@ +package top.kuanghua.tyexample.listener; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.stereotype.Component; +import top.kuanghua.tyexample.config.RabbitDelayConfig; + +/** + * @Title: orderDelayQueue + * @Description: + * @Auther: kuanghua + * @create 2021/1/18 10:27 + */ +@Component +@Slf4j +public class RabbitDelayListener { + @RabbitListener(queues = {RabbitDelayConfig.ORDER_QUEUE_NAME}) + public void ORDER_QUEUE_NAME( String outTradeno) { + /* + * 微信服务器查询订单,并更新订单状态 + * */ + log.info("receive the Delay info "+outTradeno); + } + // note: not dill the msg will re to redirect ORDER_QUEUE_NAME + // @RabbitListener(queues = {RabbitDelayConfig.ORDER_DELAY_QUEUE}) + // public void ORDER_DELAY_QUEUE( String outTradeno) { + // log.info("ORDER_DELAY_QUEUE"+outTradeno); + // } +} diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/listener/SmsListener.java b/ty-example/src/main/java/top/kuanghua/tyexample/listener/SmsListener.java new file mode 100644 index 0000000..317bb47 --- /dev/null +++ b/ty-example/src/main/java/top/kuanghua/tyexample/listener/SmsListener.java @@ -0,0 +1,50 @@ +package top.kuanghua.tyexample.listener; + + +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; +import org.springframework.amqp.rabbit.annotation.Exchange; +import org.springframework.amqp.rabbit.annotation.Queue; +import org.springframework.amqp.rabbit.annotation.QueueBinding; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.stereotype.Component; +import top.kuanghua.tyexample.config.SmsProperties; +import top.kuanghua.tyexample.utils.SendSmsUtils; + + +import java.util.Map; + +@Component +@EnableConfigurationProperties(SmsProperties.class) +@Slf4j +public class SmsListener { + + @Autowired + private SendSmsUtils smsUtils; + + @Autowired + private SmsProperties smsProperties; + + @RabbitListener( + bindings = @QueueBinding(value = @Queue(value = "kuanghua.sms.queue", durable = "true"), + exchange = @Exchange(value = "kuanghua.sms.exchange", ignoreDeclarationExceptions = "true",durable = "true"), + key = {"sms.verify.code"}) + ) + public void listenSms(Map msg) throws Exception { + if (msg == null || msg.size() <= 0) { + // 放弃处理 + return; + } + String phone = msg.get("phone"); + String code = msg.get("code"); + if (StringUtils.isBlank(phone) || StringUtils.isBlank(code)) { + // 放弃处理 + log.error("发送短信mq phone或code字段为空"); + return; + } + // 发送短信 + this.smsUtils.sendMsg(phone,code,smsProperties.getSignName(),smsProperties.getVerifyCodeTemplate()); + } +} \ No newline at end of file diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/service/RabbitDelayService.java b/ty-example/src/main/java/top/kuanghua/tyexample/service/RabbitDelayService.java new file mode 100644 index 0000000..084da36 --- /dev/null +++ b/ty-example/src/main/java/top/kuanghua/tyexample/service/RabbitDelayService.java @@ -0,0 +1,33 @@ +package top.kuanghua.tyexample.service; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import top.kuanghua.tyexample.config.RabbitDelayConfig; + +/** + * @Title: RabbitDelayService + * @Description: + * @Auther: kuanghua + * @create 2022-01-06 17:18 + */ +@Service +public class RabbitDelayService { + + @Autowired + private RabbitTemplate rabbitTemplate; + + /** + * @param time 延时的时间 + * 死信延时转发队列 + */ + public void convertAndSend(Integer time){ + rabbitTemplate.convertAndSend(RabbitDelayConfig.ORDER_DELAY_EXCHANGE, RabbitDelayConfig.ORDER_DELAY_ROUTING_KEY, "发送的数据", message -> { + // 如果配置了 params.put("x-message-ttl", 5 * 1000); 那么这一句也可以省略,具体根据业务需要是声明 Queue 的时候就指定好延迟时间还是在发送自己控制时间 + message.getMessageProperties().setExpiration(time * 1000 + ""); + return message; + }); + } +} + diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/service/SendEmailService.java b/ty-example/src/main/java/top/kuanghua/tyexample/service/SendEmailService.java new file mode 100644 index 0000000..afcfba6 --- /dev/null +++ b/ty-example/src/main/java/top/kuanghua/tyexample/service/SendEmailService.java @@ -0,0 +1,102 @@ +package top.kuanghua.tyexample.service; + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.mail.SimpleMailMessage; +import org.springframework.mail.javamail.JavaMailSenderImpl; +import org.springframework.mail.javamail.MimeMessageHelper; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; +import org.springframework.util.ResourceUtils; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.multipart.MultipartFile; +import top.kuanghua.khcomomon.utils.ObjectUtilsSelf; + +import javax.mail.MessagingException; +import javax.mail.internet.MimeMessage; +import java.io.File; +import java.io.IOException; +import java.util.List; + +/** + * @Title: SendEmailService + * @Description: + * @Auther: kuanghua + * @create 2020/8/20 22:09 + */ +@Service +public class SendEmailService { + + @Autowired + private JavaMailSenderImpl javaMailSender; + + @Value("${spring.mail.username}") + private String sendForm; + + /** + * @Description: 发送文本邮件 + * @Param: subject 主题 + * @Param: text 发送的文本 + * @Param: sendForm 发送人 + * @Param: sendTo 发送给谁 + * @return: + * @Date: 2020-08-20 + */ + @Async + public void sendEmailText(String subject, String text, String sendTo) { + //封装简单的邮件内容 + SimpleMailMessage simpleMailMessage = new SimpleMailMessage(); + //邮件主题 + simpleMailMessage.setSubject(subject); + simpleMailMessage.setText(text); + //发件人和收件人 + simpleMailMessage.setFrom(sendForm); + simpleMailMessage.setTo(sendTo); + //发送 + javaMailSender.send(simpleMailMessage); + //demo + //sendEmailText("邮件主题测试setSubject","邮件主题测试setText","869653722@qq.com","1319404169@qq.com") + } + + /** + * @Description: 发送附件邮件 + * @Param: * @param null + * @return: + * @Date: 2020-08-20 + */ + @Async + public void sendMimeMail(String subject, String text, String sendTo,MultipartFile file) + throws MessagingException, IOException { + // String path = ResourceUtils.getURL("classpath:").getPath(); + // System.out.println(path + file.getOriginalFilename()); + //先将文件保存在本地 + //file.transferTo(filePath); + + File toFile = ObjectUtilsSelf.MultipartFileToFile(file); + //创建一个发送复杂消息对象 + MimeMessage mimeMessage = javaMailSender.createMimeMessage(); + //通过消息帮助对象,来设置发送的内容 + MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true, "UTF-8"); + //邮件主题 + messageHelper.setSubject(subject); + //第2个参数为true表示是html + messageHelper.setText(text, true); + //上传文件 (文件名,File或IO对象) + String filename = file.getOriginalFilename(); + + messageHelper.addAttachment(filename, toFile); + //发件人和收件人 + messageHelper.setFrom(sendForm); + messageHelper.setTo(sendTo); + //发送 + javaMailSender.send(mimeMessage); + //发完后清空文件 + //filePath.delete(); + } + //@Scheduled(cron = "*/1 * * * * *") + //public void scheduled() { + //this.sendEmailText("邮件主题测试setSubject", "邮件主题测试setText", "869653722@qq.com", "1319404169@qq.com"); + //System.out.println("邮件发送了好烦啊"); + // } +} diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/service/SendMsgService.java b/ty-example/src/main/java/top/kuanghua/tyexample/service/SendMsgService.java new file mode 100644 index 0000000..2a00645 --- /dev/null +++ b/ty-example/src/main/java/top/kuanghua/tyexample/service/SendMsgService.java @@ -0,0 +1,42 @@ +package top.kuanghua.tyexample.service; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.amqp.core.AmqpTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Service; +import top.kuanghua.khcomomon.utils.NumberUtilsSelf; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +/** + * @Title: SendMsgService + * @Description: + * @Auther: + * @create 2020/8/20 11:26 + */ +@Service +@Slf4j +public class SendMsgService { + + @Autowired + protected AmqpTemplate amqpTemplate; + + @Autowired + private StringRedisTemplate stringRedisTemplate; + + public void sendMsg(String phone) { + String code = NumberUtilsSelf.generateCode(6); + Map smsMap = new HashMap(); + smsMap.put("phone",phone); + smsMap.put("code",code); + amqpTemplate.convertAndSend("kuanghua.sms.exchange", "sms.verify.code",smsMap); + stringRedisTemplate.opsForValue().set("user:code:phone:"+phone,code,60, TimeUnit.SECONDS); + log.info("发送短信的code"+code); + } +} + + + diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/utils/SendSmsUtils.java b/ty-example/src/main/java/top/kuanghua/tyexample/utils/SendSmsUtils.java new file mode 100644 index 0000000..876ab4f --- /dev/null +++ b/ty-example/src/main/java/top/kuanghua/tyexample/utils/SendSmsUtils.java @@ -0,0 +1,54 @@ +package top.kuanghua.tyexample.utils; + +import com.alibaba.fastjson.JSON; +import com.aliyuncs.CommonRequest; +import com.aliyuncs.CommonResponse; +import com.aliyuncs.DefaultAcsClient; +import com.aliyuncs.IAcsClient; +import com.aliyuncs.http.MethodType; +import com.aliyuncs.profile.DefaultProfile; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import top.kuanghua.tyexample.config.SmsProperties; + +import java.util.Map; + + +@Component +@Slf4j +public class SendSmsUtils { + + @Autowired + private SmsProperties smsProperties; + + public void sendMsg(String phone, String code, String signName, String codeTemplate){ + DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", smsProperties.getAccessKeyId(), smsProperties.getAccessKeySecret()); + IAcsClient client = new DefaultAcsClient(profile); + CommonRequest request = new CommonRequest(); + request.setSysMethod(MethodType.POST); + request.setSysDomain("dysmsapi.aliyuncs.com"); + request.setSysVersion("2017-05-25"); + request.setSysAction("SendSms"); + request.putQueryParameter("RegionId", "cn-hangzhou"); + request.putQueryParameter("PhoneNumbers", phone); + request.putQueryParameter("SignName", signName); + request.putQueryParameter("TemplateCode", codeTemplate); + request.putQueryParameter("TemplateParam", "{\"code\":\""+code+"\"}"); + try { + CommonResponse response = client.getCommonResponse(request); + String data = response.getData(); + Map map = JSON.parseObject(data, Map.class); + if (map.get("Code").equals("OK")){ + log.warn("发送短信成功 "+data); + }else{ + // 记录失败日志 + log.error("发送短信失败 "+data); + } + } catch (Exception e) { + // 记录失败日志 + log.error("发送短信失败 "+e.getMessage()); + throw new RuntimeException("发送短信失败 "+e.getMessage()); + } + } +} diff --git a/ty-example/src/main/main12.iml b/ty-example/src/main/main12.iml new file mode 100644 index 0000000..f608aea --- /dev/null +++ b/ty-example/src/main/main12.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/ty-example/src/main/resources/application.yml b/ty-example/src/main/resources/application.yml new file mode 100644 index 0000000..1b3189a --- /dev/null +++ b/ty-example/src/main/resources/application.yml @@ -0,0 +1,24 @@ +#msg config, place change to you sms config +kuanghua: + sms: + accessKeyId: LTAI4FrD2voTK2wTgRCPwT6d + accessKeySecret: Zj07thnb2jiBkl4wtqgvPeuSzkJRJ3 + signName: 品优商城 # 签名名称 + verifyCodeTemplate: SMS_189216068 # 模板名称 + + + + +#email config, place change to you email +spring: + mail: + username: 869653722@qq.com + password: xbthzedhnxatbcab + host: smtp.qq.com + properties: + mail.smtp.starttls.enable: true + + + +server: + port: ${envpt.tomcatPortPre}0121 \ No newline at end of file diff --git a/ty-example/src/main/resources/bootstrap.yml b/ty-example/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..c1b6427 --- /dev/null +++ b/ty-example/src/main/resources/bootstrap.yml @@ -0,0 +1,40 @@ +spring: + application: + name: @project.artifactId@ + profiles: + active: @activatedProperties@ + cloud: + nacos: + config: + enabled: true + namespace: @nacosNamespace@ + group: @nacosGroup@ + username: @nacosUsername@ + password: @nacosPassword@ + server-addr: @nacosIpPort@ + prefix: @project.artifactId@ + file-extension: yml + # 用于共享的配置文件 + shared-configs: + - data-id: application-@activatedProperties@.yml + group: @nacosGroup@ + refresh: true + # 额外的配置文件 + extension-configs: + - data-id: application-db.yml + group: @nacosGroup@ + refresh: true + - data-id: application-rabbit.yml + group: @nacosGroup@ + refresh: true + - data-id: application-redis.yml + group: @nacosGroup@ + refresh: true + discovery: + namespace: @nacosNamespace@ + group: @nacosGroup@ + username: @nacosUsername@ + password: @nacosPassword@ + server-addr: @nacosIpPort@ + weight: @nacosWeight@ + ip: @nacosDiscoveryIp@ \ No newline at end of file diff --git a/ty-example/ty-auth.iml b/ty-example/ty-auth.iml new file mode 100644 index 0000000..9447a05 --- /dev/null +++ b/ty-example/ty-auth.iml @@ -0,0 +1,222 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ty-example/ty-example.iml b/ty-example/ty-example.iml new file mode 100644 index 0000000..866c9e1 --- /dev/null +++ b/ty-example/ty-example.iml @@ -0,0 +1,243 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ty-excel/ty-excel.iml b/ty-excel/ty-excel.iml index ac0db2e..a9383d1 100644 --- a/ty-excel/ty-excel.iml +++ b/ty-excel/ty-excel.iml @@ -27,7 +27,7 @@ - + @@ -39,41 +39,47 @@ - - + + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - + - - - + + + - + @@ -92,16 +98,7 @@ - - - - - - - - - - + @@ -110,129 +107,145 @@ - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - + + - - + + + + + + + + - - - + + + - + - + - + - + - - - - + + + + - - - - - - - + + + + + + + + + + + + + + + + + + - - - - + + + + + + - - - - - - + + + + - - - - - + + + + + \ No newline at end of file diff --git a/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/filter/AuthorizeFilterBefore.java b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/filter/AuthorizeFilterBefore.java index 587a9a1..d99b2f2 100644 --- a/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/filter/AuthorizeFilterBefore.java +++ b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/filter/AuthorizeFilterBefore.java @@ -82,7 +82,7 @@ public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { DataBuffer buffer = getDataBuffer(response,message); return response.writeWith(Mono.just(buffer)); } - //2.1 将解析到的jwt数据保存到线程中(转发过去的服务都能接收)(但是服务必须部署到同一台机器上) + //2.1 将解析到的jwt数据保存到线程中(转发过去的服务都能接收) try { //本地文件解析 //Claims claims = JwtUtilsKh.parserTokenGetBody(jwtToken, RsaUtils.getPublicKey(pubKeyPath)); diff --git a/ty-gateway/ty-gateway-one/ty-gateway-one.iml b/ty-gateway/ty-gateway-one/ty-gateway-one.iml index 2e4a4dc..a5b16e9 100644 --- a/ty-gateway/ty-gateway-one/ty-gateway-one.iml +++ b/ty-gateway/ty-gateway-one/ty-gateway-one.iml @@ -27,14 +27,14 @@ - + - - - + + + - + @@ -53,16 +53,7 @@ - - - - - - - - - - + @@ -71,165 +62,183 @@ - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - + + + - - - + + + + + + + + + - - - + + + - + - - + + - + - + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - + + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + - - - - - - + + + + - - - - - + + + + + \ No newline at end of file diff --git a/ty-gateway/ty-gateway.iml b/ty-gateway/ty-gateway.iml index e5e33c2..b92bf04 100644 --- a/ty-gateway/ty-gateway.iml +++ b/ty-gateway/ty-gateway.iml @@ -15,14 +15,14 @@ - + - - - + + + - + @@ -41,16 +41,7 @@ - - - - - - - - - - + @@ -59,165 +50,183 @@ - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - + + + - - - + + + + + + + + + - - - + + + - + - - + + - + - + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - + + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + - - - - - - + + + + - - - - - + + + + + \ No newline at end of file diff --git a/ty-upload/src/main/java/top/kuanghua/tyupload/config/Swagger2Config.java b/ty-upload/src/main/java/top/kuanghua/tyupload/config/Swagger2Config.java index 106aedf..731ecc1 100644 --- a/ty-upload/src/main/java/top/kuanghua/tyupload/config/Swagger2Config.java +++ b/ty-upload/src/main/java/top/kuanghua/tyupload/config/Swagger2Config.java @@ -44,7 +44,7 @@ public Docket api() { private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("标题:kuanghua") - .description("描述:新一代的前端架构") + .description("描述:新一代的微服务架构") .contact(new Contact("jzfai", null, "869653722@qq.com")) .version("版本号:2.9") .build(); diff --git a/ty-upload/src/main/java/top/kuanghua/tyupload/controller/NacosTestDemo.java b/ty-upload/src/main/java/top/kuanghua/tyupload/controller/NacosTestDemo.java index 1abe74a..17b6a68 100644 --- a/ty-upload/src/main/java/top/kuanghua/tyupload/controller/NacosTestDemo.java +++ b/ty-upload/src/main/java/top/kuanghua/tyupload/controller/NacosTestDemo.java @@ -31,7 +31,7 @@ public ResResult test(){ HashMap hashMap = new HashMap(); hashMap.put("username","邝华"); ResResult resResult = tokenFeign.generateToken(hashMap); - System.out.println(resResult); + //System.out.println(resResult); return resResult; } @@ -39,7 +39,6 @@ public ResResult test(){ @GetMapping("test2") public ResResult test2(String token){ ResResult resResult = tokenFeign.parseToken(token); - System.out.println(resResult); return resResult; } } diff --git a/ty-upload/src/main/java/top/kuanghua/tyupload/service/UploadService.java b/ty-upload/src/main/java/top/kuanghua/tyupload/service/UploadService.java index d907045..782685f 100644 --- a/ty-upload/src/main/java/top/kuanghua/tyupload/service/UploadService.java +++ b/ty-upload/src/main/java/top/kuanghua/tyupload/service/UploadService.java @@ -86,7 +86,6 @@ public Map uploadGetMetaData(MultipartFile file) throws IOExcept Map hashMap = new HashMap<>(); hashMap.put("name", name); hashMap.put("url", storePath.getFullPath()); - System.out.println(hashMap); return hashMap; } } diff --git a/ty-upload/ty-upload.iml b/ty-upload/ty-upload.iml index 39cc125..fa94c36 100644 --- a/ty-upload/ty-upload.iml +++ b/ty-upload/ty-upload.iml @@ -26,30 +26,32 @@ - - - - - - - - - - - + + + + + + + + + + + + + - + - - - + + + - + @@ -67,16 +69,7 @@ - - - - - - - - - - + @@ -85,146 +78,162 @@ - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - + + + - - + + + + + + + + - - - + + + - + - + - + - + - - + + - - - - + + + + - - - - - - + + + + + + - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + - - - - + + - - - - - + + + + + \ No newline at end of file diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/controller/BrandController.java b/ty-user/src/main/java/top/kuanghua/tyuser/controller/BrandController.java index ab88940..ebddde9 100644 --- a/ty-user/src/main/java/top/kuanghua/tyuser/controller/BrandController.java +++ b/ty-user/src/main/java/top/kuanghua/tyuser/controller/BrandController.java @@ -37,24 +37,18 @@ public class BrandController { @ApiOperation(value = "分页查询所有数据") public ResResult selectPage(Brand brand, KHCommonParams commonParams) { QueryWrapper queryWrapper = new QueryWrapper<>(); - if (ObjectUtils.isNotEmpty(brand.getId())) { - queryWrapper.or().like("id", brand.getId()); - } if (ObjectUtils.isNotEmpty(brand.getName())) { - queryWrapper.or().like("name", brand.getName()); + queryWrapper.like("name", brand.getName()); } if (ObjectUtils.isNotEmpty(brand.getImage())) { - queryWrapper.or().like("image", brand.getImage()); + queryWrapper.like("image", brand.getImage()); } if (ObjectUtils.isNotEmpty(brand.getLetter())) { - queryWrapper.or().like("letter", brand.getLetter()); - } - if (ObjectUtils.isNotEmpty(brand.getSeq())) { - queryWrapper.or().like("seq", brand.getSeq()); + queryWrapper.like("letter", brand.getLetter()); } - queryWrapper.or().orderByDesc("create_time"); + queryWrapper.orderByDesc("create_time"); if(StringUtils.isNotEmpty(commonParams.getStartTime())) { - queryWrapper.or().between("create_time",commonParams.getStartTime(),commonParams.getEndTime()); + queryWrapper.between("create_time",commonParams.getStartTime(),commonParams.getEndTime()); } queryWrapper.select("id,name,image,letter,seq,create_time,update_time"); Page brandPage = this.brandService.selectPage(commonParams.getPageNum(), commonParams.getPageSize(), queryWrapper); diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/controller/ErrorCollectionController.java b/ty-user/src/main/java/top/kuanghua/tyuser/controller/ErrorCollectionController.java index c5a6512..04c8696 100644 --- a/ty-user/src/main/java/top/kuanghua/tyuser/controller/ErrorCollectionController.java +++ b/ty-user/src/main/java/top/kuanghua/tyuser/controller/ErrorCollectionController.java @@ -38,22 +38,22 @@ public class ErrorCollectionController { public ResResult selectPage(ErrorCollection errorCollection, KHCommonParams khCommonParams) { QueryWrapper queryWrapper = new QueryWrapper<>(); if (ObjectUtils.isNotEmpty(errorCollection.getErrorLog())) { - queryWrapper.or().like("error_log", errorCollection.getErrorLog()); + queryWrapper.like("error_log", errorCollection.getErrorLog()); } if (ObjectUtils.isNotEmpty(errorCollection.getPageUrl())) { - queryWrapper.or().like("page_url", errorCollection.getPageUrl()); + queryWrapper.like("page_url", errorCollection.getPageUrl()); } if (ObjectUtils.isNotEmpty(errorCollection.getVersion())) { - queryWrapper.or().like("version", errorCollection.getVersion()); + queryWrapper.like("version", errorCollection.getVersion()); } if (ObjectUtils.isNotEmpty(errorCollection.getCreateTime())) { - queryWrapper.or().like("create_time", errorCollection.getCreateTime()); + queryWrapper.like("create_time", errorCollection.getCreateTime()); } if(StringUtils.isNotEmpty(khCommonParams.getStartTime())) { - queryWrapper.or().between("create_time",khCommonParams.getStartTime(),khCommonParams.getEndTime()); + queryWrapper.between("create_time",khCommonParams.getStartTime(),khCommonParams.getEndTime()); } - queryWrapper.or().orderByDesc("create_time"); + queryWrapper.orderByDesc("create_time"); Page errorCollectionPage = this.errorCollectionService.selectPage(khCommonParams.getPageNum(), khCommonParams.getPageSize(), queryWrapper); return new ResResult().success(errorCollectionPage); } diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/controller/UserController.java b/ty-user/src/main/java/top/kuanghua/tyuser/controller/UserController.java index dfc01c4..123f073 100644 --- a/ty-user/src/main/java/top/kuanghua/tyuser/controller/UserController.java +++ b/ty-user/src/main/java/top/kuanghua/tyuser/controller/UserController.java @@ -53,13 +53,13 @@ public class UserController { public ResResult selectPage(User user, KHCommonParams commonParams) { QueryWrapper queryWrapper = new QueryWrapper<>(); if(StringUtils.isNotEmpty(user.getUsername())) { - queryWrapper.or().like("username",user.getUsername()); + queryWrapper.like("username",user.getUsername()); } if(StringUtils.isNotEmpty(user.getPhone())) { - queryWrapper.or().like("phone",user.getPhone()); + queryWrapper.like("phone",user.getPhone()); } if(StringUtils.isNotEmpty(commonParams.getStartTime())) { - queryWrapper.or().between("create_time",commonParams.getStartTime(),commonParams.getEndTime()); + queryWrapper.between("create_time",commonParams.getStartTime(),commonParams.getEndTime()); } queryWrapper.select("username","phone","create_time"); Page userPage = this.userMapper.selectPage(new Page<>(commonParams.getPageNum(), commonParams.getPageSize()), queryWrapper); @@ -100,7 +100,7 @@ public ResResult selectById(@RequestParam("id") Integer id) { public ResResult insert(@Valid @RequestBody User user) { //List userInfos = userInfoMapper.selectList(new EntityWrapper<>(userInfo).like("firstname", name) - // .or().like("lastname", name));52 + // .like("lastname", name));52 return new ResResult().success(this.userService.insert(user)); } /** diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/controller/VciController.java b/ty-user/src/main/java/top/kuanghua/tyuser/controller/VciController.java index 93a0285..c258672 100644 --- a/ty-user/src/main/java/top/kuanghua/tyuser/controller/VciController.java +++ b/ty-user/src/main/java/top/kuanghua/tyuser/controller/VciController.java @@ -33,7 +33,6 @@ public class VciController { @Resource private VciService vciService; - /** * 分页查询所有数据 * @param vci 查询实体 diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/excel/imp/VciExcelImp.java b/ty-user/src/main/java/top/kuanghua/tyuser/excel/imp/VciExcelImp.java index b9a641d..9fd85f9 100644 --- a/ty-user/src/main/java/top/kuanghua/tyuser/excel/imp/VciExcelImp.java +++ b/ty-user/src/main/java/top/kuanghua/tyuser/excel/imp/VciExcelImp.java @@ -9,7 +9,6 @@ /** * VCI设备表(Vci)表实体类 - * * @author kuanghua * @since 2021-10-22 10:34:43 */ diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/service/UserService.java b/ty-user/src/main/java/top/kuanghua/tyuser/service/UserService.java index a3060ce..3169080 100644 --- a/ty-user/src/main/java/top/kuanghua/tyuser/service/UserService.java +++ b/ty-user/src/main/java/top/kuanghua/tyuser/service/UserService.java @@ -155,7 +155,6 @@ public HashMap loginValid(User user) { throw new RuntimeException("用户不存在"); } - System.out.println(CodecUtils.md5Hex(user.getPassword(), resUser.getSalt())); if(!resUser.getPassword().equals(CodecUtils.md5Hex(user.getPassword(),resUser.getSalt()))){ throw new RuntimeException("用户名或密码错误"); } @@ -178,7 +177,6 @@ public void changePassword(String username,String oldPassword,String newPassword if (ObjectUtilsSelf.isEmpty(resUser)) { throw new RuntimeException("用户不存在"); } - System.out.println(CodecUtils.md5Hex(resUser.getPassword(), resUser.getSalt())); if(!resUser.getPassword().equals(CodecUtils.md5Hex(oldPassword,resUser.getSalt()))){ throw new RuntimeException("密码错误"); } diff --git a/ty-user/ty-user.iml b/ty-user/ty-user.iml index 0ccd583..bb1bebe 100644 --- a/ty-user/ty-user.iml +++ b/ty-user/ty-user.iml @@ -22,7 +22,7 @@ - + @@ -34,41 +34,47 @@ - - + + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - + - - - + + + - + @@ -87,16 +93,7 @@ - - - - - - - - - - + @@ -105,129 +102,145 @@ - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - + + - - + + + + + + + + - - - + + + - + - + - + - + - - - - + + + + - - - - - - - + + + + + + + + + + + + + + + + + + - - - - + + + + + + - - - - - - + + + + - - - - - + + + + + \ No newline at end of file From 9b85ba3f477973e775cc93a89a33a70b02e18f73 Mon Sep 17 00:00:00 2001 From: jzfai <869653722@qq.com> Date: Thu, 6 Jan 2022 18:52:06 +0800 Subject: [PATCH 11/36] add send email msg and delay queue --- ty-example/src/main/resources/application.yml | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/ty-example/src/main/resources/application.yml b/ty-example/src/main/resources/application.yml index 1b3189a..e69de29 100644 --- a/ty-example/src/main/resources/application.yml +++ b/ty-example/src/main/resources/application.yml @@ -1,24 +0,0 @@ -#msg config, place change to you sms config -kuanghua: - sms: - accessKeyId: LTAI4FrD2voTK2wTgRCPwT6d - accessKeySecret: Zj07thnb2jiBkl4wtqgvPeuSzkJRJ3 - signName: 品优商城 # 签名名称 - verifyCodeTemplate: SMS_189216068 # 模板名称 - - - - -#email config, place change to you email -spring: - mail: - username: 869653722@qq.com - password: xbthzedhnxatbcab - host: smtp.qq.com - properties: - mail.smtp.starttls.enable: true - - - -server: - port: ${envpt.tomcatPortPre}0121 \ No newline at end of file From 87fdfc0b59fdaa44584341cf9c36bc207e1c1178 Mon Sep 17 00:00:00 2001 From: jzfai <869653722@qq.com> Date: Sat, 8 Jan 2022 23:23:02 +0800 Subject: [PATCH 12/36] hystix and fix some demo --- .gitignore | 3 +- README.md | 9 +- micro-service-plus.iml | 77 +++-- pom.xml | 44 ++- ty-auth/src/main/resources/bootstrap.yml | 22 +- ty-common/ty-common.iml | 244 ++++++++-------- ty-example/pom.xml | 7 + .../controller/HystrixRibbonController.java | 31 ++ .../tyexample/controller/SmsController.java | 32 --- .../controller/UploadController.java | 84 ++++++ .../tyexample/service/UploadService.java | 92 ++++++ ty-example/src/main/resources/bootstrap.yml | 8 +- ty-example/ty-auth.iml | 222 -------------- ty-example/ty-example.iml | 262 +++++++++-------- ty-excel/src/main/resources/bootstrap.yml | 2 +- ty-excel/ty-excel.iml | 253 ++++++++-------- .../gatewaytwo/GatewayOneApplication.java | 8 +- .../gatewaytwo/config/BaseConfig.java | 4 +- .../gatewaytwo/config/JwtProperties.java | 4 +- .../SpecialHystrixGatewayFilterFactory.java | 241 ++++++++++++++++ .../controller/HstrixController.java | 26 ++ .../filter/AuthorizeFilterBefore.java | 34 ++- .../src/main/resources/application.yml | 205 ++++++------- .../src/main/resources/bootstrap.yml | 5 +- ty-gateway/ty-gateway-one/ty-gateway-one.iml | 271 +++++++++--------- ty-gateway/ty-gateway.iml | 271 +++++++++--------- ty-upload/src/main/resources/bootstrap.yml | 2 +- ty-upload/ty-upload.iml | 247 ++++++++-------- .../tyuser/controller/BrandController.java | 20 +- .../controller/ErrorCollectionController.java | 11 +- .../tyuser/controller/VciController.java | 1 + ty-user/src/main/resources/bootstrap.yml | 2 +- 32 files changed, 1465 insertions(+), 1279 deletions(-) create mode 100644 ty-example/src/main/java/top/kuanghua/tyexample/controller/HystrixRibbonController.java delete mode 100644 ty-example/src/main/java/top/kuanghua/tyexample/controller/SmsController.java create mode 100644 ty-example/src/main/java/top/kuanghua/tyexample/controller/UploadController.java create mode 100644 ty-example/src/main/java/top/kuanghua/tyexample/service/UploadService.java delete mode 100644 ty-example/ty-auth.iml create mode 100644 ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/config/SpecialHystrixGatewayFilterFactory.java create mode 100644 ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/controller/HstrixController.java diff --git a/.gitignore b/.gitignore index 0ad508a..67f963d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ node_modules dist dist-ssr *.local -target \ No newline at end of file +target +*.iml \ No newline at end of file diff --git a/README.md b/README.md index 48b11e6..1a0d3ec 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ 使用的技术如下: ```java -spring-boot:2.2.4.RELEASE -spring-cloud:Hoxton.SR12 -spring-cloud-starter-gateway:2.2.9.RELEASE +spring-boot:2.1.4.RELEASE +spring-cloud:Greenwich.SR1 +spring-cloud-starter-gateway:2.1.1.RELEASE nacos:2.1.3.RELEASE mybatis-plus: 3.3.2 rabbitmq:3.7-management @@ -14,6 +14,9 @@ redis: 3.2.9 mysql:5.7 ``` + + + #### 更新日志: to look doc ---- diff --git a/micro-service-plus.iml b/micro-service-plus.iml index aad4444..7f10b3d 100644 --- a/micro-service-plus.iml +++ b/micro-service-plus.iml @@ -8,61 +8,50 @@ - - - - - - - - - + + + + + + + + + - - - - - - - + + + + + + + - - - - - - - - - - - - + - - - - - - + + + + + + - - - - + + + + - - - - - - + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 715f5ce..8872073 100644 --- a/pom.xml +++ b/pom.xml @@ -21,12 +21,12 @@ org.springframework.boot spring-boot-starter-parent - 2.2.4.RELEASE + 2.1.4.RELEASE - Hoxton.SR12 + Greenwich.SR1 @@ -88,9 +88,6 @@ dev - - true - dev 8.135.1.141 @@ -105,6 +102,7 @@ test + true @@ -120,23 +118,23 @@ 123456 - - - prod - - true - - - prod - 8.135.1.141 - ${baseLinuxIp}:8848 - 1000 - 127.0.0.1 - df87d91b-b1ab-4720-8e1c-5a147edc6ddc - nacos-group-${activatedProperties} - jzfai - 123456 - - + + + + + + + + + + + + + + + + + + diff --git a/ty-auth/src/main/resources/bootstrap.yml b/ty-auth/src/main/resources/bootstrap.yml index 40f8dfe..23a6628 100644 --- a/ty-auth/src/main/resources/bootstrap.yml +++ b/ty-auth/src/main/resources/bootstrap.yml @@ -16,20 +16,20 @@ spring: file-extension: yml # 用于共享的配置文件 shared-configs: - - data-id: application-@activatedProperties@.yml + - data-id: application-main.yml group: @nacosGroup@ refresh: true # 额外的配置文件 -# extension-configs: -# - data-id: application-db.yml -# group: @nacosGroup@ -# refresh: true -# - data-id: application-rabbit.yml -# group: @nacosGroup@ -# refresh: true -# - data-id: application-redis.yml -# group: @nacosGroup@ -# refresh: true + # extension-configs: + # - data-id: application-db.yml + # group: @nacosGroup@ + # refresh: true + # - data-id: application-rabbit.yml + # group: @nacosGroup@ + # refresh: true + # - data-id: application-redis.yml + # group: @nacosGroup@ + # refresh: true discovery: namespace: @nacosNamespace@ group: @nacosGroup@ diff --git a/ty-common/ty-common.iml b/ty-common/ty-common.iml index e823a48..3ffe7b5 100644 --- a/ty-common/ty-common.iml +++ b/ty-common/ty-common.iml @@ -20,49 +20,48 @@ - - - + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - + - + - - - + + + - + @@ -82,13 +81,15 @@ - - - - - - - + + + + + + + + + @@ -97,132 +98,123 @@ - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - + + + - - - - - - - - - + + + - - - + + + - + - + - + - + - - - - + + + + - - - - - - - - - - + + + + + + - - - - + + + + - - - - + + + + \ No newline at end of file diff --git a/ty-example/pom.xml b/ty-example/pom.xml index f809565..416031b 100644 --- a/ty-example/pom.xml +++ b/ty-example/pom.xml @@ -32,6 +32,13 @@ org.springframework.boot spring-boot-starter-mail + + + + com.github.tobato + fastdfs-client + 1.27.2 + diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/controller/HystrixRibbonController.java b/ty-example/src/main/java/top/kuanghua/tyexample/controller/HystrixRibbonController.java new file mode 100644 index 0000000..ced9bb3 --- /dev/null +++ b/ty-example/src/main/java/top/kuanghua/tyexample/controller/HystrixRibbonController.java @@ -0,0 +1,31 @@ +package top.kuanghua.tyexample.controller; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import top.kuanghua.khcomomon.entity.ResResult; + +/** + * @Title: HystrixRibbonController + * @Description: + * @Auther: kuanghua + * @create 2022-01-08 17:20 + */ +@Api(tags = "HystrixRibbon和限流测试") +@RestController +@RequestMapping("hystrixRibbon") +public class HystrixRibbonController { + @ApiOperation(value = "测试Hystrix熔断和Ribbon") + @GetMapping("timeoutTest") + public ResResult timeoutTest() { + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + return new ResResult<>().success(); + + } +} diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/controller/SmsController.java b/ty-example/src/main/java/top/kuanghua/tyexample/controller/SmsController.java deleted file mode 100644 index d986fc0..0000000 --- a/ty-example/src/main/java/top/kuanghua/tyexample/controller/SmsController.java +++ /dev/null @@ -1,32 +0,0 @@ -package top.kuanghua.tyexample.controller; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; -import top.kuanghua.khcomomon.entity.ResResult; -import top.kuanghua.tyexample.service.SendMsgService; - -/** - * @Title: SmsController @Description: @Auther: - * - * @create 2020/8/20 11:33 - */ -@Api(tags = "短信") -@RestController -@RequestMapping("sms") -public class SmsController { - - @Autowired - private SendMsgService sendMsgService; - @ApiOperation(value = "发送短信") - @PostMapping("sendSms") - public ResResult sendSms(@ApiParam("手机号") @RequestParam("phone") String phone) { - sendMsgService.sendMsg(phone); - return new ResResult().success("短信发送成功"); - } -} diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/controller/UploadController.java b/ty-example/src/main/java/top/kuanghua/tyexample/controller/UploadController.java new file mode 100644 index 0000000..cd46146 --- /dev/null +++ b/ty-example/src/main/java/top/kuanghua/tyexample/controller/UploadController.java @@ -0,0 +1,84 @@ +package top.kuanghua.tyexample.controller; + +import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; +import top.kuanghua.khcomomon.entity.ResResult; +import top.kuanghua.tyexample.service.UploadService; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; + +/** + * @Title: UploadController @Description: @Auther:jzfai @Version: 1.0 + * @create 2020/3/4 21:58 + */ +@RestController +@RequestMapping("upload") +@Api(tags = "图片上传") +@DefaultProperties(defaultFallback = "fallBackMethod") // 指定一个类的全局熔断方法 +@RefreshScope +public class UploadController { + + + @Autowired + private UploadService uploadService; + + @ApiOperation(value = "上传图片或文件", notes = "上传图片接口") + @PostMapping("image") + public ResResult uploadImage(@RequestParam("file") MultipartFile file) + throws IOException, InterruptedException { + String url = this.uploadService.upload(file); + Thread.sleep(20000); + HashMap map = new HashMap<>(); + map.put("shortPath", url); + return new ResResult().success(map); + } + + // +// @ApiOperation(value = "上传图片(多张)") +// @PostMapping("uploadGetMetaData") +// public ResResult uploadGetMetaData(@RequestParam("files") MultipartFile[] files) +// throws IOException, InterruptedException { +// ArrayList strings = new ArrayList<>(); +// for (MultipartFile file : files) { +// Map stringStringMap = this.uploadService.uploadGetMetaData(file); +// strings.add(stringStringMap); +// } +// //Thread.sleep(5000); +// return new ResResult().success(strings); +// } + @ApiOperation(value = "批量上传图片或文件") + @PostMapping("files") + public ResResult uploadFileList(@RequestParam("files") MultipartFile[] files) throws IOException { + ArrayList strings = new ArrayList<>(); + for (MultipartFile file : files) { + String url = this.uploadService.upload(file); + strings.add(url); + } + return new ResResult().success(strings); + } + + public String fallBackMethod() { + return "请求繁忙,请稍后再试!"; + } + +// @Value(value = "${demo.a}") +// private String data12; +// @Value(value = "${demo.b}") +// private String datas; +// @ApiOperation(value = "test") +// @GetMapping("test") +// public String test() { +// System.out.println("data :" + data12 + ",datas="+datas); +// return "data :" + data12 + ",datas="+datas; +// } +} diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/service/UploadService.java b/ty-example/src/main/java/top/kuanghua/tyexample/service/UploadService.java new file mode 100644 index 0000000..eb5317b --- /dev/null +++ b/ty-example/src/main/java/top/kuanghua/tyexample/service/UploadService.java @@ -0,0 +1,92 @@ +package top.kuanghua.tyexample.service; + + +import com.alibaba.fastjson.JSON; +import com.github.tobato.fastdfs.domain.fdfs.MetaData; +import com.github.tobato.fastdfs.domain.fdfs.StorePath; +import com.github.tobato.fastdfs.service.FastFileStorageClient; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.util.*; + +/** + * @Title: UploadService + * @Description: + * @Auther:jzfai + * @Version: 1.0 + * @create 2020/3/4 21:58 + */ +@Service +@Slf4j +public class UploadService { + + @Resource + private FastFileStorageClient storageClient; + + private static final List CONTENT_TYPES = Arrays.asList("image/jpeg", "image/gif"); + + public String upload(MultipartFile file) throws IOException { + String originalFilename = file.getOriginalFilename(); + //检验文件类型 + String contentType = file.getContentType(); + if (!CONTENT_TYPES.contains(contentType)) { + //文件类型不合法 + log.info("文件类型不合法:{}", originalFilename); + throw new RuntimeException("文件内容不合法"); + } + //检验文件内容 + BufferedImage bufferedImage = ImageIO.read(file.getInputStream()); + if (bufferedImage == null) { + log.info("文件内容不合法:{}", originalFilename); + throw new RuntimeException("文件内容不合法"); + } + //保存到服务器 + //file.transferTo(new File("D:\\java\\javaproject\\pinyou\\pinyou-upload\\src\\main\\resources\\static\\" + originalFilename)); + //上传到FastDfs + String ext = StringUtils.substringAfterLast(originalFilename, "."); + HashSet metaData = new HashSet<>(); + metaData.add(new MetaData("name", file.getOriginalFilename())); + metaData.add(new MetaData("createTime", JSON.toJSONString(new Date()))); + StorePath storePath = this.storageClient.uploadFile(file.getInputStream(), file.getSize(), ext, metaData); + return storePath.getFullPath(); + } + + public Map uploadGetMetaData(MultipartFile file) throws IOException { + String originalFilename = file.getOriginalFilename(); + //检验文件类型 + String contentType = file.getContentType(); + if (!CONTENT_TYPES.contains(contentType)) { + //文件类型不合法 + log.info("文件类型不合法:{}", originalFilename); + } + //检验文件内容 + BufferedImage bufferedImage = ImageIO.read(file.getInputStream()); + if (bufferedImage == null) { + log.info("文件内容不合法:{}", originalFilename); + } + //保存到服务器 + //file.transferTo(new File("D:\\java\\javaproject\\pinyou\\pinyou-upload\\src\\main\\resources\\static\\" + originalFilename)); + //上传到FastDfs + String ext = StringUtils.substringAfterLast(originalFilename, "."); + HashSet metaData = new HashSet<>(); + metaData.add(new MetaData("name", file.getOriginalFilename())); + StorePath storePath = this.storageClient.uploadFile(file.getInputStream(), file.getSize(), ext, metaData); + //获取数据源信息 + Set metadata = this.storageClient.getMetadata(storePath.getGroup(), storePath.getPath()); + ArrayList metaDataArrayList = new ArrayList<>(metadata); + String name = metaDataArrayList.get(0).getValue(); + //拼接name和url返回 + Map hashMap = new HashMap<>(); + hashMap.put("name", name); + hashMap.put("url", storePath.getFullPath()); + hashMap.put("group", storePath.getGroup()); + return hashMap; + } +} diff --git a/ty-example/src/main/resources/bootstrap.yml b/ty-example/src/main/resources/bootstrap.yml index c1b6427..76ddd5d 100644 --- a/ty-example/src/main/resources/bootstrap.yml +++ b/ty-example/src/main/resources/bootstrap.yml @@ -16,20 +16,26 @@ spring: file-extension: yml # 用于共享的配置文件 shared-configs: - - data-id: application-@activatedProperties@.yml + - data-id: application-main.yml group: @nacosGroup@ refresh: true # 额外的配置文件 extension-configs: + #get mysql config - data-id: application-db.yml group: @nacosGroup@ refresh: true - data-id: application-rabbit.yml group: @nacosGroup@ refresh: true + #get redis config - data-id: application-redis.yml group: @nacosGroup@ refresh: true + #get fdfs config + - data-id: application-upload.yml + group: @nacosGroup@ + refresh: true discovery: namespace: @nacosNamespace@ group: @nacosGroup@ diff --git a/ty-example/ty-auth.iml b/ty-example/ty-auth.iml deleted file mode 100644 index 9447a05..0000000 --- a/ty-example/ty-auth.iml +++ /dev/null @@ -1,222 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ty-example/ty-example.iml b/ty-example/ty-example.iml index 866c9e1..27a5064 100644 --- a/ty-example/ty-example.iml +++ b/ty-example/ty-example.iml @@ -21,37 +21,30 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + - - + - - - + + + - + @@ -60,7 +53,6 @@ - @@ -70,7 +62,16 @@ - + + + + + + + + + + @@ -79,165 +80,160 @@ - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - + + - - - - - - - - + + - - - + + + - + - + - - + - + - - + + - + - - - + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + - - - - + + - - - - - + + + + + \ No newline at end of file diff --git a/ty-excel/src/main/resources/bootstrap.yml b/ty-excel/src/main/resources/bootstrap.yml index 97d7d53..5336782 100644 --- a/ty-excel/src/main/resources/bootstrap.yml +++ b/ty-excel/src/main/resources/bootstrap.yml @@ -16,7 +16,7 @@ spring: file-extension: yml # 用于共享的配置文件 shared-configs: - - data-id: application-@activatedProperties@.yml + - data-id: application-main.yml group: @nacosGroup@ refresh: true extension-configs: diff --git a/ty-excel/ty-excel.iml b/ty-excel/ty-excel.iml index a9383d1..ac0db2e 100644 --- a/ty-excel/ty-excel.iml +++ b/ty-excel/ty-excel.iml @@ -27,7 +27,7 @@ - + @@ -39,47 +39,41 @@ - - - - - - - + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - + - - - + + + - + @@ -98,7 +92,16 @@ - + + + + + + + + + + @@ -107,145 +110,129 @@ - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - + + - - - - - - - - + + - - - + + + - + - + - + - + - - - - + + + + - - - - - - - + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + - - - - + + + + - - - - - + + + + + \ No newline at end of file diff --git a/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/GatewayOneApplication.java b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/GatewayOneApplication.java index d767278..4b46482 100644 --- a/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/GatewayOneApplication.java +++ b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/GatewayOneApplication.java @@ -18,11 +18,12 @@ @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) public class GatewayOneApplication { public static void main(String[] args) { - SpringApplication.run(GatewayOneApplication.class,args); + SpringApplication.run(GatewayOneApplication.class, args); } + //创建一个ipKeyResolver 指定用户的IP - @Bean(name="ipKeyResolver") - public KeyResolver keyResolver(){ + @Bean(name = "ipKeyResolver") + public KeyResolver keyResolver() { return new KeyResolver() { @Override public Mono resolve(ServerWebExchange exchange) { @@ -35,4 +36,5 @@ public Mono resolve(ServerWebExchange exchange) { } }; } + } diff --git a/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/config/BaseConfig.java b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/config/BaseConfig.java index 198fee6..6effeec 100644 --- a/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/config/BaseConfig.java +++ b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/config/BaseConfig.java @@ -18,4 +18,6 @@ //dao包扫描 @ComponentScan(basePackages = {"top.kuanghua.khcomomon"}) @EnableFeignClients(basePackages = {"top.kuanghua.feign"}) -public class BaseConfig {} +public class BaseConfig { + +} diff --git a/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/config/JwtProperties.java b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/config/JwtProperties.java index 15e5447..9bf7775 100644 --- a/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/config/JwtProperties.java +++ b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/config/JwtProperties.java @@ -34,7 +34,7 @@ public void init() throws Exception { File priKeyFile = new File(priKeyPath); if (!pubKeyFile.exists() || !priKeyFile.exists()) { File fileParent = pubKeyFile.getParentFile(); - if(!fileParent.exists()){ + if (!fileParent.exists()) { fileParent.mkdirs(); } throw new RuntimeException("秘钥文件不存在"); @@ -45,7 +45,7 @@ public void init() throws Exception { // } catch (Exception e) { // log.error("生成秘钥失败"); // //e.printStackTrace(); -// } +// }r } //读取公钥和私钥文件 this.publicKey = RsaUtils.getPublicKey(pubKeyPath); diff --git a/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/config/SpecialHystrixGatewayFilterFactory.java b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/config/SpecialHystrixGatewayFilterFactory.java new file mode 100644 index 0000000..a206eeb --- /dev/null +++ b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/config/SpecialHystrixGatewayFilterFactory.java @@ -0,0 +1,241 @@ +package top.kuanghua.gatewaytwo.config; + +import com.netflix.hystrix.HystrixCommandGroupKey; +import com.netflix.hystrix.HystrixCommandKey; +import com.netflix.hystrix.HystrixCommandProperties; +import com.netflix.hystrix.HystrixObservableCommand; +import com.netflix.hystrix.exception.HystrixRuntimeException; +import org.springframework.beans.factory.ObjectProvider; +import org.springframework.cloud.gateway.filter.GatewayFilter; +import org.springframework.cloud.gateway.filter.GatewayFilterChain; +import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; +import org.springframework.core.annotation.AnnotatedElementUtils; +import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.reactive.DispatcherHandler; +import org.springframework.web.server.ResponseStatusException; +import org.springframework.web.server.ServerWebExchange; +import org.springframework.web.util.UriComponentsBuilder; +import reactor.core.publisher.Mono; +import rx.Observable; +import rx.RxReactiveStreams; +import rx.Subscription; + +import java.math.BigDecimal; +import java.net.URI; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeoutException; +import java.util.function.Function; + +import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR; +import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.containsEncodedParts; + +@Component +public class SpecialHystrixGatewayFilterFactory extends AbstractGatewayFilterFactory { + + private static final String NAME = "SpecialHystrix"; + + private final ObjectProvider dispatcherHandler; + + public SpecialHystrixGatewayFilterFactory(ObjectProvider dispatcherHandler) { + super(Config.class); + this.dispatcherHandler = dispatcherHandler; + } + + @Override + public List shortcutFieldOrder() { + return Collections.singletonList(NAME_KEY); + } + + @Override + public GatewayFilter apply(Config config) { + return (exchange, chain) -> { + ServerHttpRequest request = exchange.getRequest(); + String path = request.getPath().pathWithinApplication().value(); + Map timeoutMap = config.getTimeout(); + Integer timeout = null; + if (timeoutMap != null) { + //对rest接口通配符url进行转换 暂只配置url 末尾为数字的的接口--- + path = config.wildCard(path); + timeout = timeoutMap.get(path); + } + + MyRouteHystrixCommand command; + if (timeout == null) { + //没有定义时间的接口将使用配置的default时间 + command = new MyRouteHystrixCommand(config.getFallbackUri(), exchange, chain, path); + } else { + //有配置时间的接口将使用配置的时间 + command = new MyRouteHystrixCommand(config.getFallbackUri(), exchange, chain, timeout, path); + } + + return Mono.create(s -> { + Subscription sub = command.toObservable().subscribe(s::success, s::error, s::success); + s.onCancel(sub::unsubscribe); + }).onErrorResume((Function>) throwable -> { + if (throwable instanceof HystrixRuntimeException) { + HystrixRuntimeException e = (HystrixRuntimeException) throwable; + HystrixRuntimeException.FailureType failureType = e.getFailureType(); + switch (failureType) { + case TIMEOUT: + return Mono.error(new TimeoutException()); + case COMMAND_EXCEPTION: { + Throwable cause = e.getCause(); + if (cause instanceof ResponseStatusException || AnnotatedElementUtils + .findMergedAnnotation(cause.getClass(), ResponseStatus.class) != null) { + return Mono.error(cause); + } + } + default: + break; + } + } + return Mono.error(throwable); + }).then(); + }; + } + + @Override + public String name() { + return NAME; + } + + private class MyRouteHystrixCommand extends HystrixObservableCommand { + + private final URI fallbackUri; + private final ServerWebExchange exchange; + private final GatewayFilterChain chain; + + public MyRouteHystrixCommand(URI fallbackUri, ServerWebExchange exchange, GatewayFilterChain chain, + String key) { + super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(key)) + .andCommandKey(HystrixCommandKey.Factory.asKey(key))); + this.fallbackUri = fallbackUri; + this.exchange = exchange; + this.chain = chain; + + } + + public MyRouteHystrixCommand(URI fallbackUri, ServerWebExchange exchange, GatewayFilterChain chain, + int timeout, + String key) { + //***出现通配符的情况**// + super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(key)) + .andCommandKey(HystrixCommandKey.Factory.asKey(key)) + .andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(timeout))); + this.fallbackUri = fallbackUri; + this.exchange = exchange; + this.chain = chain; + + } + + @Override + protected Observable construct() { + return RxReactiveStreams.toObservable(this.chain.filter(exchange)); + } + + @Override + protected Observable resumeWithFallback() { + if (null == fallbackUri) { + return super.resumeWithFallback(); + } + URI uri = exchange.getRequest().getURI(); + boolean encoded = containsEncodedParts(uri); + URI requestUrl = UriComponentsBuilder.fromUri(uri) + .host(null) + .port(null) + .uri(this.fallbackUri) + .build(encoded) + .toUri(); + exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, requestUrl); + + ServerHttpRequest request = this.exchange.getRequest().mutate().uri(requestUrl).build(); + ServerWebExchange mutated = exchange.mutate().request(request).build(); + DispatcherHandler dispatcherHandler = SpecialHystrixGatewayFilterFactory.this.dispatcherHandler.getIfAvailable(); + return RxReactiveStreams.toObservable(dispatcherHandler.handle(mutated)); + } + } + + public static class Config { + + private String id; + private URI fallbackUri; + /** + * url -> timeout ms + */ + private Map timeout; + + public String getId() { + return id; + } + + public Config setId(String id) { + this.id = id; + return this; + } + + public URI getFallbackUri() { + return fallbackUri; + } + + public Config setFallbackUri(URI fallbackUri) { + if (fallbackUri != null && !"forward".equals(fallbackUri.getScheme())) { + throw new IllegalArgumentException("Hystrix Filter currently only supports 'forward' URIs, found " + fallbackUri); + } + this.fallbackUri = fallbackUri; + return this; + } + + public Map getTimeout() { + return timeout; + } + + public Config setTimeout(Map timeout) { + //YAML解析的时候MAP的KEY不支持'/',这里只能用'-'替代 + Map tempTimeout = new HashMap<>(timeout.size()); + for (String key : timeout.keySet()) { + Integer value = timeout.get(key); + + key = key.replace("-", "/"); + if (!key.startsWith("/")) { + key = "/" + key; + } + /** 末尾有动态传参 **/ + if (key.endsWith("/")) { + key = key + "**"; + } + tempTimeout.put(key, value); + } + this.timeout = tempTimeout; + return this; + } + + + public String wildCard(String path) { + String replace = path; + String[] split = path.split("/"); + if (split.length > 0) { + String wildcard = split[split.length - 1]; + boolean numeric = isNumeric(wildcard); + if (numeric) { + replace = path.replace(wildcard, "**"); + } + } + return replace; + } + + private boolean isNumeric(String str) { + String bigStr; + try { + bigStr = new BigDecimal(str).toString(); + } catch (Exception e) { + return false;//异常 说明包含非数字。 + } + return true; + } + } +} \ No newline at end of file diff --git a/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/controller/HstrixController.java b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/controller/HstrixController.java new file mode 100644 index 0000000..9138091 --- /dev/null +++ b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/controller/HstrixController.java @@ -0,0 +1,26 @@ +package top.kuanghua.gatewaytwo.controller; + +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import top.kuanghua.khcomomon.entity.ResResult; + +/** + * @Title: hstrixController + * @Description: + * @Auther: kuanghua + * @create 2022-01-08 18:15 + */ +@RestController +public class HstrixController { + @ApiOperation(value = "") + @GetMapping("fallback") + public ResResult fallback() { + ResResult resResult = new ResResult(); + //设置20010为熔断状态吗 + resResult.setCode(20010); + resResult.setMsg("接口发生了熔断"); + resResult.setFlag(false); + return resResult; + } +} \ No newline at end of file diff --git a/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/filter/AuthorizeFilterBefore.java b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/filter/AuthorizeFilterBefore.java index d99b2f2..75eecf8 100644 --- a/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/filter/AuthorizeFilterBefore.java +++ b/ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo/filter/AuthorizeFilterBefore.java @@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.gateway.filter.GatewayFilterChain; import org.springframework.cloud.gateway.filter.GlobalFilter; @@ -17,11 +16,10 @@ import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Mono; import top.kuanghua.feign.tyauth.feign.TokenFeign; -import top.kuanghua.khcomomon.entity.ResResult; import top.kuanghua.khcomomon.utils.ObjectUtilsSelf; +import javax.annotation.Resource; import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.List; @@ -46,7 +44,7 @@ * */ public class AuthorizeFilterBefore implements GlobalFilter, Ordered { - private static final String AUTHORIZE_TOKEN="AUTHORIZE_TOKEN"; + private static final String AUTHORIZE_TOKEN = "AUTHORIZE_TOKEN"; @Value("#{'${filter.allowPaths:}'.empty ? null : '${filter.allowPaths:}'.split(',')}") private List allowPaths; // @Value("${filter.allowPaths}") @@ -56,7 +54,7 @@ public class AuthorizeFilterBefore implements GlobalFilter, Ordered { // @Value("${jwt-properties.priKeyPath}") // private String priKeyPath; - @Autowired + @Resource private TokenFeign tokenFeign; @Override @@ -68,18 +66,18 @@ public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { //List stringList = Arrays.asList("/api/user/login","/api/search/searchData"); //1.白名单放行 for (String allowPath : allowPaths) { - if(StringUtils.contains(path,allowPath)){ - return chain.filter(exchange); + if (StringUtils.contains(path, allowPath)) { + return chain.filter(exchange); } } //2.解析jwt token放行 String jwtToken = request.getHeaders().getFirst(AUTHORIZE_TOKEN); - if(ObjectUtils.isEmpty(jwtToken)){ + if (ObjectUtils.isEmpty(jwtToken)) { JSONObject message = new JSONObject(); - message.put("code",403); + message.put("code", 403); message.put("msg", "token为空"); - DataBuffer buffer = getDataBuffer(response,message); + DataBuffer buffer = getDataBuffer(response, message); return response.writeWith(Mono.just(buffer)); } //2.1 将解析到的jwt数据保存到线程中(转发过去的服务都能接收) @@ -88,13 +86,13 @@ public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { //Claims claims = JwtUtilsKh.parserTokenGetBody(jwtToken, RsaUtils.getPublicKey(pubKeyPath)); //System.out.println("解析出来的body"+claims); //调用feign服务进行解析 - Object resResult= tokenFeign.parseToken(jwtToken); + Object resResult = tokenFeign.parseToken(jwtToken); Map tokenInfo = ObjectUtilsSelf.parseResToData(resResult); - log.info("解析的token数据",tokenInfo.toString()); + log.info("解析的token数据", tokenInfo.toString()); //将信息设置到头部 ServerHttpRequest httpRequest = exchange.getRequest().mutate().headers(httpHeaders -> { - String decode=""; + String decode = ""; try { decode = URLEncoder.encode(JSON.toJSONString(tokenInfo), "utf-8"); } catch (UnsupportedEncodingException e) { @@ -107,14 +105,14 @@ public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { return chain.filter(build); } catch (Exception e) { JSONObject message = new JSONObject(); - message.put("code",403); - message.put("msg","token解析失败"+e.getMessage()); - log.error("token解析失败"+e); - return response.writeWith(Mono.just(getDataBuffer(response,message))); + message.put("code", 403); + message.put("msg", "token解析失败" + e.getMessage()); + log.error("token解析失败" + e); + return response.writeWith(Mono.just(getDataBuffer(response, message))); } } - private DataBuffer getDataBuffer(ServerHttpResponse response, JSONObject message) { + private DataBuffer getDataBuffer(ServerHttpResponse response, JSONObject message) { byte[] bits = message.toJSONString().getBytes(StandardCharsets.UTF_8); DataBuffer buffer = response.bufferFactory().wrap(bits); //response.setStatusCode(HttpStatus.UNAUTHORIZED); diff --git a/ty-gateway/ty-gateway-one/src/main/resources/application.yml b/ty-gateway/ty-gateway-one/src/main/resources/application.yml index bb642e0..b77388d 100644 --- a/ty-gateway/ty-gateway-one/src/main/resources/application.yml +++ b/ty-gateway/ty-gateway-one/src/main/resources/application.yml @@ -1,96 +1,109 @@ -#server: -# port: ${envpt.tomcatPortPre}0156 -# -#spring: -# cloud: -# gateway: -# globalcors: -# corsConfigurations: -# '[/**]': -# # 允许携带认证信息 -# # 允许跨域的源(网站域名/ip),设置*为全部 -# # 允许跨域请求里的head字段,设置*为全部 -# # 允许跨域的method, 默认为GET和OPTIONS,设置*为全部 -# # 跨域允许的有效期 -# allow-credentials: true -# allowed-origins: "*" -# allowed-headers: "*" -# allowed-methods: -# - OPTIONS -# - GET -# - POST -# - PUT -# - DELETE -# #max-age: 3600 -# routes: -# - id: ty-auth -# uri: lb://ty-auth -# predicates: -# - Path=/api/ty-auth/** -# filters: -# - StripPrefix=2 -# -# - id: ty-email -# uri: lb://ty-email -# predicates: -# - Path=/api/ty-email/** -# filters: -# - StripPrefix=2 -# -# - id: ty-excel -# uri: lb://ty-excel -# predicates: -# - Path=/api/ty-excel/** -# filters: -# - StripPrefix=2 -# -# - id: ty-user -# uri: lb://ty-user -# predicates: -# - Path=/api/ty-user/** -# filters: -# - StripPrefix=2 -# -# - id: ty-upload -# uri: lb://ty-upload -# predicates: -# - Path=/api/ty-upload/** -# filters: -# - StripPrefix=2 -# -## - id: fai_search_route -## uri: lb://search -## predicates: -## - Path=/api/search/** -## filters: -## - StripPrefix=2 -## - name: RequestRateLimiter #请求数限流 名字不能随便写 ,使用默认的facatory -## args: -## key-resolver: "#{@ipKeyResolver}" -## redis-rate-limiter.replenishRate: 2 -## redis-rate-limiter.burstCapacity: 2 -# -# -#management: -# endpoint: -# gateway: -# enabled: true -# web: -# exposure: -# include: true -# -# -##白名单过滤 -#filter: -# allowPaths: swagger,docs,userRegister,userLogin,sendEmailCode,registry,login,loginOut,insertUser -# -# -# -#token-properties: -# renewTokenMinute: 1440 #默认1天时间告知前端刷新token -# -#swagger-doc: -# serviceMap: { -# ty-user: "用户模块", -# ty-upload: "文件上传" -# } \ No newline at end of file +server: + port: ${envpt.tomcatPortPre}0156 + +spring: + cloud: + gateway: + globalcors: + corsConfigurations: + '[/**]': + # 允许携带认证信息 + # 允许跨域的源(网站域名/ip),设置*为全部 + # 允许跨域请求里的head字段,设置*为全部 + # 允许跨域的method, 默认为GET和OPTIONS,设置*为全部 + # 跨域允许的有效期 + allow-credentials: true + allowed-origins: "*" + allowed-headers: "*" + allowed-methods: + - OPTIONS + - GET + - POST + - PUT + - DELETE + #max-age: 3600 + routes: + - id: ty-auth + uri: lb://ty-auth + predicates: + - Path=/api/ty-auth/** + filters: + - StripPrefix=2 + + - id: ty-email + uri: lb://ty-email + predicates: + - Path=/api/ty-email/** + filters: + - StripPrefix=2 + + - id: ty-example + uri: lb://ty-example + predicates: + - Path=/api/ty-example/** + filters: + - StripPrefix=2 + + #请求数限流 名字不能随便写 ,使用默认的facatory + - name: RequestRateLimiter + args: + key-resolver: "#{@ipKeyResolver}" + redis-rate-limiter.replenishRate: 2 + redis-rate-limiter.burstCapacity: 2 + + # hystrix 熔断配置 + - RemoveRequestHeader=Origin # 去除请求头的origin字段,此字段导致post请求 无法进入网关post熔断 + - name: SpecialHystrix #自定义熔断 + args: + id: SpecialHystrix + fallbackUri: forward:/fallback + timeout: + #指定接口超时处理 hystrixRibbon -> @RequestMapping("hystrixRibbon") + #timeoutTest-> @GetMapping("timeoutTest") , - > / + hystrixRibbon-timeoutTest: 11000 + #file-upload-: 20000 + #file-download-: 20000 + #course-file-upload-local-: 20000 + + - id: ty-user + uri: lb://ty-user + predicates: + - Path=/api/ty-user/** + filters: + - StripPrefix=2 + + - id: ty-upload + uri: lb://ty-upload + predicates: + - Path=/api/ty-upload/** + filters: + - StripPrefix=2 + +management: + endpoint: + gateway: + enabled: true + web: + exposure: + include: true + + +#白名单过滤 +filter: + allowPaths: / + notValidExpList: export,excel + + + +token-properties: + renewTokenMinute: 1440 #默认1天时间告知前端刷新token + + + +#config the visit service of gateway swagger +swagger-doc: + serviceMap: { + ty-user: "用户模块", + ty-upload: "文件上传", + ty-example: "使用例子" + } \ No newline at end of file diff --git a/ty-gateway/ty-gateway-one/src/main/resources/bootstrap.yml b/ty-gateway/ty-gateway-one/src/main/resources/bootstrap.yml index c3c775c..e6c3e43 100644 --- a/ty-gateway/ty-gateway-one/src/main/resources/bootstrap.yml +++ b/ty-gateway/ty-gateway-one/src/main/resources/bootstrap.yml @@ -16,13 +16,10 @@ spring: file-extension: yml # 用于共享的配置文件 shared-configs: - - data-id: application-@activatedProperties@.yml + - data-id: application-main.yml group: @nacosGroup@ refresh: true extension-configs: - - data-id: ty-gateway-one.yml - group: @nacosGroup@ - refresh: true - data-id: application-rabbit.yml group: @nacosGroup@ refresh: true diff --git a/ty-gateway/ty-gateway-one/ty-gateway-one.iml b/ty-gateway/ty-gateway-one/ty-gateway-one.iml index a5b16e9..2e4a4dc 100644 --- a/ty-gateway/ty-gateway-one/ty-gateway-one.iml +++ b/ty-gateway/ty-gateway-one/ty-gateway-one.iml @@ -27,14 +27,14 @@ - + - - - + + + - + @@ -53,7 +53,16 @@ - + + + + + + + + + + @@ -62,183 +71,165 @@ - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - + + + - - - - - - - - - + + + - - - + + + - + - - + + - + - + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - + + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + - - - - + + + + - - - - - + + + + + \ No newline at end of file diff --git a/ty-gateway/ty-gateway.iml b/ty-gateway/ty-gateway.iml index b92bf04..e5e33c2 100644 --- a/ty-gateway/ty-gateway.iml +++ b/ty-gateway/ty-gateway.iml @@ -15,14 +15,14 @@ - + - - - + + + - + @@ -41,7 +41,16 @@ - + + + + + + + + + + @@ -50,183 +59,165 @@ - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - + + + - - - - - - - - - + + + - - - + + + - + - - + + - + - + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - + + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + - - - - + + + + - - - - - + + + + + \ No newline at end of file diff --git a/ty-upload/src/main/resources/bootstrap.yml b/ty-upload/src/main/resources/bootstrap.yml index 19f67dc..3609f31 100644 --- a/ty-upload/src/main/resources/bootstrap.yml +++ b/ty-upload/src/main/resources/bootstrap.yml @@ -16,7 +16,7 @@ spring: file-extension: yml # 用于共享的配置文件 shared-configs: - - data-id: application-@activatedProperties@.yml + - data-id: application-main.yml group: @nacosGroup@ refresh: true extension-configs: diff --git a/ty-upload/ty-upload.iml b/ty-upload/ty-upload.iml index fa94c36..39cc125 100644 --- a/ty-upload/ty-upload.iml +++ b/ty-upload/ty-upload.iml @@ -26,32 +26,30 @@ - - - - - - - - - - - - - + + + + + + + + + + + - + - - - + + + - + @@ -69,7 +67,16 @@ - + + + + + + + + + + @@ -78,162 +85,146 @@ - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - + + + - - - - - - - - + + - - - + + + - + - + - + - + - - + + - - - - + + + + - - - - - - + + + + + + - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + - - + + - - - - - + + + + + \ No newline at end of file diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/controller/BrandController.java b/ty-user/src/main/java/top/kuanghua/tyuser/controller/BrandController.java index ebddde9..c171fa4 100644 --- a/ty-user/src/main/java/top/kuanghua/tyuser/controller/BrandController.java +++ b/ty-user/src/main/java/top/kuanghua/tyuser/controller/BrandController.java @@ -3,21 +3,18 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; -import com.baomidou.mybatisplus.extension.api.ApiController; -import com.baomidou.mybatisplus.extension.api.R; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; +import org.springframework.web.bind.annotation.*; import top.kuanghua.khcomomon.entity.KHCommonParams; import top.kuanghua.khcomomon.entity.ResResult; import top.kuanghua.tyuser.entity.Brand; import top.kuanghua.tyuser.service.BrandService; -import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import java.io.Serializable; -import java.util.*; +import java.util.List; @Api(tags = "品牌表(Brand)") @RestController @@ -30,25 +27,32 @@ public class BrandController { /** * 分页查询所有数据 * - * @param brand 查询实体 + * @param brand 查询实体 * @return 所有数据 */ @GetMapping("selectPage") @ApiOperation(value = "分页查询所有数据") public ResResult selectPage(Brand brand, KHCommonParams commonParams) { QueryWrapper queryWrapper = new QueryWrapper<>(); + if (ObjectUtils.isNotEmpty(brand.getId())) { + queryWrapper.like("id", brand.getId()); + } if (ObjectUtils.isNotEmpty(brand.getName())) { queryWrapper.like("name", brand.getName()); } if (ObjectUtils.isNotEmpty(brand.getImage())) { queryWrapper.like("image", brand.getImage()); } + if (ObjectUtils.isNotEmpty(brand.getLetter())) { queryWrapper.like("letter", brand.getLetter()); } + if (ObjectUtils.isNotEmpty(brand.getSeq())) { + queryWrapper.like("seq", brand.getSeq()); + } queryWrapper.orderByDesc("create_time"); - if(StringUtils.isNotEmpty(commonParams.getStartTime())) { - queryWrapper.between("create_time",commonParams.getStartTime(),commonParams.getEndTime()); + if (StringUtils.isNotEmpty(commonParams.getStartTime())) { + queryWrapper.between("create_time", commonParams.getStartTime(), commonParams.getEndTime()); } queryWrapper.select("id,name,image,letter,seq,create_time,update_time"); Page brandPage = this.brandService.selectPage(commonParams.getPageNum(), commonParams.getPageSize(), queryWrapper); diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/controller/ErrorCollectionController.java b/ty-user/src/main/java/top/kuanghua/tyuser/controller/ErrorCollectionController.java index 04c8696..dcae33f 100644 --- a/ty-user/src/main/java/top/kuanghua/tyuser/controller/ErrorCollectionController.java +++ b/ty-user/src/main/java/top/kuanghua/tyuser/controller/ErrorCollectionController.java @@ -3,21 +3,18 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; -import com.baomidou.mybatisplus.extension.api.ApiController; -import com.baomidou.mybatisplus.extension.api.R; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; +import org.springframework.web.bind.annotation.*; import top.kuanghua.khcomomon.entity.KHCommonParams; import top.kuanghua.khcomomon.entity.ResResult; import top.kuanghua.tyuser.entity.ErrorCollection; import top.kuanghua.tyuser.service.ErrorCollectionService; -import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import java.io.Serializable; -import java.util.*; +import java.util.List; @Api(tags = "日志相关") @RestController @@ -50,8 +47,8 @@ public ResResult selectPage(ErrorCollection errorCollection, KHCommonParams khCo queryWrapper.like("create_time", errorCollection.getCreateTime()); } - if(StringUtils.isNotEmpty(khCommonParams.getStartTime())) { - queryWrapper.between("create_time",khCommonParams.getStartTime(),khCommonParams.getEndTime()); + if (StringUtils.isNotEmpty(khCommonParams.getStartTime())) { + queryWrapper.between("create_time", khCommonParams.getStartTime(), khCommonParams.getEndTime()); } queryWrapper.orderByDesc("create_time"); Page errorCollectionPage = this.errorCollectionService.selectPage(khCommonParams.getPageNum(), khCommonParams.getPageSize(), queryWrapper); diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/controller/VciController.java b/ty-user/src/main/java/top/kuanghua/tyuser/controller/VciController.java index c258672..93a0285 100644 --- a/ty-user/src/main/java/top/kuanghua/tyuser/controller/VciController.java +++ b/ty-user/src/main/java/top/kuanghua/tyuser/controller/VciController.java @@ -33,6 +33,7 @@ public class VciController { @Resource private VciService vciService; + /** * 分页查询所有数据 * @param vci 查询实体 diff --git a/ty-user/src/main/resources/bootstrap.yml b/ty-user/src/main/resources/bootstrap.yml index 1d93e57..3a75337 100644 --- a/ty-user/src/main/resources/bootstrap.yml +++ b/ty-user/src/main/resources/bootstrap.yml @@ -16,7 +16,7 @@ spring: file-extension: yml # 用于共享的配置文件 shared-configs: - - data-id: application-@activatedProperties@.yml + - data-id: application-main.yml group: @nacosGroup@ refresh: true extension-configs: From dc1c2cd185ee58dd805c70b57f6560d978574cfa Mon Sep 17 00:00:00 2001 From: jzfai <869653722@qq.com> Date: Sun, 9 Jan 2022 20:18:57 +0800 Subject: [PATCH 13/36] add redis lock demo --- README.md | 3 +- ty-auth/src/main/resources/bootstrap.yml | 11 - ty-auth/ty-auth.iml | 246 ++++++++--------- ...RedisClient.java => RedisClientUtils.java} | 2 +- .../kuanghua/tyexample/config/BaseConfig.java | 6 + .../controller/RedisTestController.java | 133 +++++++++ .../tyexample/entity/ErrorCollection.java | 36 +++ .../mapper/ErrorCollectionMapper.java | 8 + .../tyexample/service/SendEmailService.java | 9 +- .../service/CacheAvalancheServiceTest.java | 32 +++ ty-example/ty-example.iml | 6 + .../kuanghua/tyuser/service/UserService.java | 92 +++---- ty-user/ty-user.iml | 253 +++++++++--------- 13 files changed, 511 insertions(+), 326 deletions(-) rename ty-common/src/main/java/top/kuanghua/khcomomon/utils/{RedisClient.java => RedisClientUtils.java} (99%) create mode 100644 ty-example/src/main/java/top/kuanghua/tyexample/controller/RedisTestController.java create mode 100644 ty-example/src/main/java/top/kuanghua/tyexample/entity/ErrorCollection.java create mode 100644 ty-example/src/main/java/top/kuanghua/tyexample/mapper/ErrorCollectionMapper.java create mode 100644 ty-example/src/test/java/top/kuanghua/tyexample/service/CacheAvalancheServiceTest.java diff --git a/README.md b/README.md index 1a0d3ec..2c5c8cc 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,6 @@ mysql:5.7 ``` - - #### 更新日志: to look doc ---- @@ -70,6 +68,7 @@ git clone https://github.com/jzfai/micro-service-plus.git >注:在Maven Projects->Profies 选择环境时,请不要选择prod环境。目前线上是prod环境下构建的包 + #### 架构亮点 1.网关中将jwt token和解析后的token信息已经设置在请求头中,在后续转发的微服务可以在请求头中,轻松的拿到token和token解析后的数据。不用再通过feign去调用ty-auth,获取token信息。 diff --git a/ty-auth/src/main/resources/bootstrap.yml b/ty-auth/src/main/resources/bootstrap.yml index 23a6628..bc12133 100644 --- a/ty-auth/src/main/resources/bootstrap.yml +++ b/ty-auth/src/main/resources/bootstrap.yml @@ -19,17 +19,6 @@ spring: - data-id: application-main.yml group: @nacosGroup@ refresh: true - # 额外的配置文件 - # extension-configs: - # - data-id: application-db.yml - # group: @nacosGroup@ - # refresh: true - # - data-id: application-rabbit.yml - # group: @nacosGroup@ - # refresh: true - # - data-id: application-redis.yml - # group: @nacosGroup@ - # refresh: true discovery: namespace: @nacosNamespace@ group: @nacosGroup@ diff --git a/ty-auth/ty-auth.iml b/ty-auth/ty-auth.iml index 7d21540..9447a05 100644 --- a/ty-auth/ty-auth.iml +++ b/ty-auth/ty-auth.iml @@ -21,39 +21,38 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - + - - - + + + - + @@ -72,7 +71,16 @@ - + + + + + + + + + + @@ -81,150 +89,134 @@ - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - + + + - - - - - - - - - + + + - - - + + + - + - + - + - + - + - - - + + + - - - - - - - + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + - - - - + + + + - - - - - + + + + + \ No newline at end of file diff --git a/ty-common/src/main/java/top/kuanghua/khcomomon/utils/RedisClient.java b/ty-common/src/main/java/top/kuanghua/khcomomon/utils/RedisClientUtils.java similarity index 99% rename from ty-common/src/main/java/top/kuanghua/khcomomon/utils/RedisClient.java rename to ty-common/src/main/java/top/kuanghua/khcomomon/utils/RedisClientUtils.java index 19e3e86..841c22b 100644 --- a/ty-common/src/main/java/top/kuanghua/khcomomon/utils/RedisClient.java +++ b/ty-common/src/main/java/top/kuanghua/khcomomon/utils/RedisClientUtils.java @@ -14,7 +14,7 @@ * Redis工具类 */ @Component -public class RedisClient { +public class RedisClientUtils { @Autowired private RedisTemplate redisTemplate; diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/config/BaseConfig.java b/ty-example/src/main/java/top/kuanghua/tyexample/config/BaseConfig.java index 9c668a7..5994fd9 100644 --- a/ty-example/src/main/java/top/kuanghua/tyexample/config/BaseConfig.java +++ b/ty-example/src/main/java/top/kuanghua/tyexample/config/BaseConfig.java @@ -1,5 +1,7 @@ package top.kuanghua.tyexample.config; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -16,6 +18,10 @@ @Configuration //扫描公用包的配置和自身的配置类 @ComponentScan(basePackages = {"top.kuanghua.khcomomon"}) +//mapper包扫描 +@MapperScan(basePackages = {"top.kuanghua.tyexample.mapper"}) +//feign扫描 +@EnableFeignClients(basePackages = {"top.kuanghua.feign.tyauth"}) public class BaseConfig { } diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/controller/RedisTestController.java b/ty-example/src/main/java/top/kuanghua/tyexample/controller/RedisTestController.java new file mode 100644 index 0000000..62d21d9 --- /dev/null +++ b/ty-example/src/main/java/top/kuanghua/tyexample/controller/RedisTestController.java @@ -0,0 +1,133 @@ +package top.kuanghua.tyexample.controller; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.BoundHashOperations; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import top.kuanghua.khcomomon.entity.ResResult; +import top.kuanghua.khcomomon.utils.ObjectUtilsSelf; +import top.kuanghua.khcomomon.utils.RedisClientUtils; +import top.kuanghua.tyexample.entity.ErrorCollection; +import top.kuanghua.tyexample.mapper.ErrorCollectionMapper; + +import javax.annotation.PostConstruct; +import javax.annotation.Resource; +import java.text.MessageFormat; +import java.util.List; +import java.util.concurrent.TimeUnit; + +/** + * @Title: CacheAvalancheController + * @Description: + * @Auther: kuanghua + * @create 2022-01-09 16:48 + */ +@Api(tags = "缓存击穿和雪崩解决方案") +@RestController +@RequestMapping("redisCache") +public class RedisTestController { + + @Resource + private ErrorCollectionMapper errorCollectionMapper; + + @Autowired + private RedisTemplate redisTemplate; + + @Resource + private RedisClientUtils redisClient; + + + private Integer orderCount = 10; + private String redisCountKey = "orderCo"; + + + @PostConstruct + public void intParam() { + BoundHashOperations hashKey = redisTemplate.boundHashOps("hashKey"); + hashKey.increment(redisCountKey, orderCount); + } + + /* redis缓存击穿问题 + * 1. 当用户根据key 查询数据时,先查询缓存,如果缓存有命中,返回, + 2. 但是如果缓存没有命中直接穿过缓存层,访问数据层 如果有,则存储指缓存, + 3. 但是同样如果没有命中,(也就是数据库中也没有数据)直接返回用户,但是不缓存 + 这就是缓存的穿透。如果某一个key 请求量很大,但是存储层也没有数据,大量的请求都会达到存储层就会造成数据库压力巨大,有可能宕机的情况。 + + + 缓存雪崩 + 如果缓存集中在一段时间内失效,发生大量的缓存穿透,所有的查询都落在数据库上,造成了缓存雪崩。 + 这个没有完美解决办法,但可以分析用户行为,尽量让失效时间点均匀分布。 + + 限流 加锁排队 + + 在缓存失效后,通过对某一个key加锁或者是队列 来控制key的线程访问的数量。例如:某一个key 只允许一个线程进行 操作。 + + + 限流 + + 在缓存失效后,某一个key 做count统计限流,达到一定的阈值,直接丢弃,不再查询数据库。例如:令牌桶算法。等等。 + + + 数据预热 + + 在缓存失效应当尽量避免某一段时间,可以先进行数据预热,比如某些热门的商品。提前在上线之前,或者开放给用户使用之前,先进行loading 缓存中,这样用户使用的时候,直接从缓存中获取。要注意的是,要更加业务来进行过期时间的设置 ,尽量均匀。 + + + 做缓存降级(二级缓存策略) + + 当分布式缓存失效的时候,可以采用本地缓存,本地缓存没有再查询数据库。这种方式,可以避免很多数据分布式缓存没有,就直接打到数据库的情况。 + + * */ + + + @ApiOperation(value = "查询错误日志") + @GetMapping("queryErrorLogList") + public ResResult queryErrorLogList() { + + String key = "queryErrorLogList"; + /* + * 解决缓存穿透带来的问题 + * 1.查询值为空的时候也设置到redis的key上 + * 2.给空值的key设定过期时间(为了避免过多的KEY 存储在redis中) + * */ + if (redisTemplate.hasKey(key)) { + List redisList = redisTemplate.opsForList().range(key, 0, -1); + return new ResResult().success(redisList); + } else { + List ecList = errorCollectionMapper.selectList(null); + //无论ecList是否为空都设置到redis的key上,解决缓存穿透带来的雪崩问题 + //如果为空,一般情况下都需要设置一个过期时间,例如:5分钟失效。(为了避免过多的KEY 存储在redis中) + redisTemplate.opsForList().leftPushAll(key, ecList); + if (ObjectUtilsSelf.isEmpty(ecList)) { + //此处设置为20s,进行测试 + redisTemplate.expire(key, 20, TimeUnit.SECONDS); + } else { + //此处设置为20s,进行测试,不为空时可以不设置过期时间,根据业务需求进行设置 + redisTemplate.expire(key, 20, TimeUnit.SECONDS); + } + return new ResResult().success(ecList); + + } + } + + + @ApiOperation(value = "并发请求改接口测试redis锁") + @GetMapping("testRedisLock") + public void testRedisLock() throws InterruptedException { + //订单超卖问题 +// orderCount--; +// if (orderCount >= 0) { +// Thread.sleep(1000); +// System.out.println(MessageFormat.format("订单还剩{0}", orderCount)); +// } + + /*用redis锁*/ + BoundHashOperations hashKey = redisTemplate.boundHashOps("hashKey"); + Long decrement = hashKey.increment(redisCountKey, -1); + if (decrement >= 0) { + System.out.println(MessageFormat.format("redis订单还剩{0}", decrement)); + } + + } + +} diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/entity/ErrorCollection.java b/ty-example/src/main/java/top/kuanghua/tyexample/entity/ErrorCollection.java new file mode 100644 index 0000000..afe96e0 --- /dev/null +++ b/ty-example/src/main/java/top/kuanghua/tyexample/entity/ErrorCollection.java @@ -0,0 +1,36 @@ +package top.kuanghua.tyexample.entity; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.activerecord.Model; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; + +/** + * error_log_collection(ErrorCollection)表实体类 + * + * @author kuanghua + * @since 2021-10-08 11:37:25 + */ +@Data +@ApiModel("错误日志相关") +@TableName(value = "tb_error_collection") +public class ErrorCollection extends Model { + @ApiModelProperty(value = "id主键") + private Long id; + @ApiModelProperty(value = "错误日志") + private String errorLog; + @ApiModelProperty(value = "页面路径") + private String pageUrl; + @ApiModelProperty(value = "当前版本") + private String version; + @ApiModelProperty(value = "浏览器类型", hidden = true) + private String browserType; + @TableField(fill = FieldFill.INSERT) + @ApiModelProperty(value = "创建时间", hidden = true) + private Date createTime; +} diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/mapper/ErrorCollectionMapper.java b/ty-example/src/main/java/top/kuanghua/tyexample/mapper/ErrorCollectionMapper.java new file mode 100644 index 0000000..0e5413a --- /dev/null +++ b/ty-example/src/main/java/top/kuanghua/tyexample/mapper/ErrorCollectionMapper.java @@ -0,0 +1,8 @@ +package top.kuanghua.tyexample.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import top.kuanghua.tyexample.entity.ErrorCollection; + +public interface ErrorCollectionMapper extends BaseMapper { + +} diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/service/SendEmailService.java b/ty-example/src/main/java/top/kuanghua/tyexample/service/SendEmailService.java index afcfba6..2dc1f96 100644 --- a/ty-example/src/main/java/top/kuanghua/tyexample/service/SendEmailService.java +++ b/ty-example/src/main/java/top/kuanghua/tyexample/service/SendEmailService.java @@ -1,23 +1,20 @@ package top.kuanghua.tyexample.service; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSenderImpl; import org.springframework.mail.javamail.MimeMessageHelper; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; -import org.springframework.util.ResourceUtils; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.multipart.MultipartFile; import top.kuanghua.khcomomon.utils.ObjectUtilsSelf; +import javax.annotation.Resource; import javax.mail.MessagingException; import javax.mail.internet.MimeMessage; import java.io.File; import java.io.IOException; -import java.util.List; /** * @Title: SendEmailService @@ -28,7 +25,7 @@ @Service public class SendEmailService { - @Autowired + @Resource private JavaMailSenderImpl javaMailSender; @Value("${spring.mail.username}") @@ -66,7 +63,7 @@ public void sendEmailText(String subject, String text, String sendTo) { * @Date: 2020-08-20 */ @Async - public void sendMimeMail(String subject, String text, String sendTo,MultipartFile file) + public void sendMimeMail(String subject, String text, String sendTo, MultipartFile file) throws MessagingException, IOException { // String path = ResourceUtils.getURL("classpath:").getPath(); // System.out.println(path + file.getOriginalFilename()); diff --git a/ty-example/src/test/java/top/kuanghua/tyexample/service/CacheAvalancheServiceTest.java b/ty-example/src/test/java/top/kuanghua/tyexample/service/CacheAvalancheServiceTest.java new file mode 100644 index 0000000..4f3b9c6 --- /dev/null +++ b/ty-example/src/test/java/top/kuanghua/tyexample/service/CacheAvalancheServiceTest.java @@ -0,0 +1,32 @@ +package top.kuanghua.tyexample.service; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * @Title: CacheAvalancheServiceTest + * @Description: + * @Auther: kuanghua + * @create 2022-01-09 16:35 + */ +@SpringBootTest +@RunWith(SpringRunner.class) +public class CacheAvalancheServiceTest { + + @Autowired + private RedisTemplate redisTemplate; + + @Test + public void test() throws InterruptedException { + redisTemplate.opsForValue().set("fai", "1"); + String fai = (String) redisTemplate.opsForValue().get("fai"); + System.out.println(fai); + //Thread.sleep(10000); + } + + +} \ No newline at end of file diff --git a/ty-example/ty-example.iml b/ty-example/ty-example.iml index 27a5064..24c4b6e 100644 --- a/ty-example/ty-example.iml +++ b/ty-example/ty-example.iml @@ -7,6 +7,10 @@ + + + + @@ -16,6 +20,8 @@ + + diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/service/UserService.java b/ty-user/src/main/java/top/kuanghua/tyuser/service/UserService.java index 3169080..df5a045 100644 --- a/ty-user/src/main/java/top/kuanghua/tyuser/service/UserService.java +++ b/ty-user/src/main/java/top/kuanghua/tyuser/service/UserService.java @@ -2,18 +2,13 @@ import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import lombok.extern.java.Log; -import lombok.extern.log4j.Log4j; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.aspectj.weaver.ast.Var; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; -import org.springframework.web.bind.annotation.RequestHeader; -import springfox.documentation.annotations.ApiIgnore; import top.kuanghua.feign.tyauth.feign.TokenFeign; import top.kuanghua.feign.tyexecl.feign.ExcelFeign; import top.kuanghua.khcomomon.entity.ResResult; @@ -41,10 +36,10 @@ public class UserService { @Resource private UserMapper userMapper; - @Autowired + @Resource private ExcelFeign excelFeign; - @Autowired + @Resource private TokenFeign tokenFeign; @Autowired private StringRedisTemplate stringRedisTemplate; @@ -53,25 +48,25 @@ public void registry(User user, String code) throws Exception { QueryWrapper queryWrapper = new QueryWrapper() .select("phone") .eq("phone", user.getPhone()); - Boolean bl=this.userMapper.selectCount(queryWrapper)==1; - if(bl){ + Boolean bl = this.userMapper.selectCount(queryWrapper) == 1; + if (bl) { throw new Exception("手机号已存在"); } String codeStr = stringRedisTemplate.opsForValue().get("user:code:phone:" + user.getPhone()); - if(StringUtils.isEmpty(codeStr)){ + if (StringUtils.isEmpty(codeStr)) { throw new Exception("验证码失效,请重新获取"); } - if(!Objects.equals(codeStr,code)){ + if (!Objects.equals(codeStr, code)) { throw new Exception("验证码输入错误"); } String salt = CodecUtils.generateSalt(); user.setSalt(salt); - user.setPassword(CodecUtils.md5Hex(user.getPassword(),salt)); - boolean insertBl = this.userMapper.insert(user)==1; - if(insertBl){ + user.setPassword(CodecUtils.md5Hex(user.getPassword(), salt)); + boolean insertBl = this.userMapper.insert(user) == 1; + if (insertBl) { //删除redis中的code this.stringRedisTemplate.delete("user:code:phone:" + user.getPhone()); - }else{ + } else { throw new Exception("用户注册失败"); } } @@ -85,7 +80,7 @@ public Object insert(User user) { @Transactional(rollbackFor = Exception.class) public Object updateById(User user) { int updateById = this.userMapper.updateById(user); - int i=10/0; + int i = 10 / 0; return updateById; } @@ -98,34 +93,35 @@ public void loginOut() { /** * 用户注册 + * * @param code * @param username * @param password */ - public void userRegister(String email,String code,String username, String password){ + public void userRegister(String email, String code, String username, String password) { //user表中查询用户是否重复 QueryWrapper queryWrapper = new QueryWrapper() .eq("username", username); - if(this.userMapper.selectCount(queryWrapper)==1){ - throw new RuntimeException(MessageFormat.format("账号【{0}】已存在,请误重复注册", username)); + if (this.userMapper.selectCount(queryWrapper) == 1) { + throw new RuntimeException(MessageFormat.format("账号【{0}】已存在,请误重复注册", username)); } //去ty-execl中查询用户名是否存在 ResResult resResult = excelFeign.selectExcelByUser(username); List list = ObjectUtilsSelf.parseResToList(resResult); - if (list.size()==0) { - throw new RuntimeException(MessageFormat.format("考勤表中不存在用户名【{0}】", username)); + if (list.size() == 0) { + throw new RuntimeException(MessageFormat.format("考勤表中不存在用户名【{0}】", username)); } //校验验证码 String codeInfo = stringRedisTemplate.opsForValue().get("email.code.routing.name" + email); Map map = JSON.parseObject(codeInfo); - if(ObjectUtilsSelf.isEmpty(map)){ - throw new RuntimeException("验证码失效,请重新获取"); + if (ObjectUtilsSelf.isEmpty(map)) { + throw new RuntimeException("验证码失效,请重新获取"); } - if (!Objects.equals(map.get("code"),code)) { - throw new RuntimeException("验证码不正确"); + if (!Objects.equals(map.get("code"), code)) { + throw new RuntimeException("验证码不正确"); } //插入数据,用户添加成功 User userEt = new User(); @@ -135,58 +131,61 @@ public void userRegister(String email,String code,String username, String passwo //添加盐设置密码为md5 String salt = CodecUtils.generateSalt(); userEt.setSalt(salt); - userEt.setPassword(CodecUtils.md5Hex(userEt.getPassword(),salt)); + userEt.setPassword(CodecUtils.md5Hex(userEt.getPassword(), salt)); boolean inResult = userMapper.insert(userEt) == 1; - if(!inResult){ - throw new RuntimeException("插入失败"); + if (!inResult) { + throw new RuntimeException("插入失败"); } } + /** * 用户登录 + * * @param user * @return * @throws Exception */ public HashMap loginValid(User user) { QueryWrapper phoneQW = new QueryWrapper().like("email", user.getEmail()) - .or().eq("username",user.getUsername()); + .or().eq("username", user.getUsername()); User resUser = this.userMapper.selectOne(phoneQW); - if(ObjectUtils.isEmpty(resUser)){ + if (ObjectUtils.isEmpty(resUser)) { throw new RuntimeException("用户不存在"); } - if(!resUser.getPassword().equals(CodecUtils.md5Hex(user.getPassword(),resUser.getSalt()))){ + if (!resUser.getPassword().equals(CodecUtils.md5Hex(user.getPassword(), resUser.getSalt()))) { throw new RuntimeException("用户名或密码错误"); } //生成jwt token HashMap hm = new HashMap<>(); - hm.put("username",resUser.getUsername()); - hm.put("email",resUser.getEmail()); + hm.put("username", resUser.getUsername()); + hm.put("email", resUser.getEmail()); ResResult resResult = tokenFeign.generateToken(hm); - hm.put("jwtToken",resResult.getData()); - return hm; + hm.put("jwtToken", resResult.getData()); + return hm; } + /*修改用户密码*/ - public void changePassword(String username,String oldPassword,String newPassword) { + public void changePassword(String username, String oldPassword, String newPassword) { //校验oldPassword是否正确 QueryWrapper qw = new QueryWrapper() - .eq("username",username); + .eq("username", username); User resUser = this.userMapper.selectOne(qw); if (ObjectUtilsSelf.isEmpty(resUser)) { throw new RuntimeException("用户不存在"); } - if(!resUser.getPassword().equals(CodecUtils.md5Hex(oldPassword,resUser.getSalt()))){ + if (!resUser.getPassword().equals(CodecUtils.md5Hex(oldPassword, resUser.getSalt()))) { throw new RuntimeException("密码错误"); } //设置新的密码 String salt = CodecUtils.generateSalt(); resUser.setSalt(salt); - resUser.setPassword(CodecUtils.md5Hex(newPassword,salt)); - boolean insertBl = this.userMapper.updateById(resUser)==1; - if(!insertBl){ + resUser.setPassword(CodecUtils.md5Hex(newPassword, salt)); + boolean insertBl = this.userMapper.updateById(resUser) == 1; + if (!insertBl) { throw new RuntimeException("修改密码失败"); } } @@ -194,12 +193,13 @@ public void changePassword(String username,String oldPassword,String newPassword /** * 插入用户 + * * @param username 用户名 */ public void insertUser(String username) { //先查询当前用户是否存在不存在则导入 QueryWrapper qw = new QueryWrapper() - .eq("username",username); + .eq("username", username); User resUser = this.userMapper.selectOne(qw); if (ObjectUtilsSelf.isEmpty(resUser)) { @@ -209,7 +209,7 @@ public void insertUser(String username) { user.setUsername(username); String salt = CodecUtils.generateSalt(); user.setSalt(salt); - user.setPassword(CodecUtils.md5Hex(user.getPassword(),salt)); + user.setPassword(CodecUtils.md5Hex(user.getPassword(), salt)); userMapper.insert(user); } } @@ -218,13 +218,13 @@ public void insertUser(String username) { /** * 重置用用户名:如果用用户存在先删除原有用户在新增一个用户,没有则新建用户 */ - public void resetUser(String username){ + public void resetUser(String username) { QueryWrapper userWrap = new QueryWrapper().eq("username", username); List users = userMapper.selectList(userWrap); //用户存在,先删除用户 - if (users.size()==1) { + if (users.size() == 1) { userMapper.delete(userWrap); - }else{ + } else { //新增用户 this.insertUser(username); } diff --git a/ty-user/ty-user.iml b/ty-user/ty-user.iml index bb1bebe..0ccd583 100644 --- a/ty-user/ty-user.iml +++ b/ty-user/ty-user.iml @@ -22,7 +22,7 @@ - + @@ -34,47 +34,41 @@ - - - - - - - + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - + - - - + + + - + @@ -93,7 +87,16 @@ - + + + + + + + + + + @@ -102,145 +105,129 @@ - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - + + - - - - - - - - + + - - - + + + - + - + - + - + - - - - + + + + - - - - - - - + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + - - - - + + + + - - - - - + + + + + \ No newline at end of file From b968ddfa19a011e1ef56d06736afabfa8aa37b83 Mon Sep 17 00:00:00 2001 From: jzfai <869653722@qq.com> Date: Mon, 10 Jan 2022 18:36:32 +0800 Subject: [PATCH 14/36] fix some isuue --- ty-example/pom.xml | 6 ++ .../tyexample/ExampleApplication.java | 3 +- .../kuanghua/tyexample/config/BaseConfig.java | 2 +- .../controller/RedisTestController.java | 2 - .../controller/SeataTestController.java | 34 +++++++++++ .../listener/CanalDataEventListener.java | 53 +++++++++++++++++ .../mapper/ErrorCollectionMapper.java | 1 + .../tyexample/service/SeataTestService.java | 26 ++++++++ ty-example/src/main/resources/application.yml | 59 +++++++++++++++++++ ty-example/ty-example.iml | 8 +++ .../top/kuanghua/tyuser/UserApplication.java | 5 +- ty-user/src/main/resources/application.yml | 25 +++++++- ty-user/src/main/resources/bootstrap.yml | 6 +- 13 files changed, 221 insertions(+), 9 deletions(-) create mode 100644 ty-example/src/main/java/top/kuanghua/tyexample/controller/SeataTestController.java create mode 100644 ty-example/src/main/java/top/kuanghua/tyexample/listener/CanalDataEventListener.java create mode 100644 ty-example/src/main/java/top/kuanghua/tyexample/service/SeataTestService.java diff --git a/ty-example/pom.xml b/ty-example/pom.xml index 416031b..b040d7d 100644 --- a/ty-example/pom.xml +++ b/ty-example/pom.xml @@ -39,6 +39,12 @@ fastdfs-client 1.27.2 + + + com.xpand + starter-canal + 0.0.1-SNAPSHOT + diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/ExampleApplication.java b/ty-example/src/main/java/top/kuanghua/tyexample/ExampleApplication.java index 003fdb0..35ae229 100644 --- a/ty-example/src/main/java/top/kuanghua/tyexample/ExampleApplication.java +++ b/ty-example/src/main/java/top/kuanghua/tyexample/ExampleApplication.java @@ -8,8 +8,9 @@ @SpringBootApplication @EnableScheduling @EnableAsync +//@EnableAutoDataSourceProxy public class ExampleApplication { public static void main(String[] args) { - SpringApplication.run(ExampleApplication.class,args); + SpringApplication.run(ExampleApplication.class, args); } } diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/config/BaseConfig.java b/ty-example/src/main/java/top/kuanghua/tyexample/config/BaseConfig.java index 5994fd9..809d29d 100644 --- a/ty-example/src/main/java/top/kuanghua/tyexample/config/BaseConfig.java +++ b/ty-example/src/main/java/top/kuanghua/tyexample/config/BaseConfig.java @@ -21,7 +21,7 @@ //mapper包扫描 @MapperScan(basePackages = {"top.kuanghua.tyexample.mapper"}) //feign扫描 -@EnableFeignClients(basePackages = {"top.kuanghua.feign.tyauth"}) +@EnableFeignClients(basePackages = {"top.kuanghua.feign.tyuser"}) public class BaseConfig { } diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/controller/RedisTestController.java b/ty-example/src/main/java/top/kuanghua/tyexample/controller/RedisTestController.java index 62d21d9..69a2a70 100644 --- a/ty-example/src/main/java/top/kuanghua/tyexample/controller/RedisTestController.java +++ b/ty-example/src/main/java/top/kuanghua/tyexample/controller/RedisTestController.java @@ -79,11 +79,9 @@ public void intParam() { * */ - @ApiOperation(value = "查询错误日志") @GetMapping("queryErrorLogList") public ResResult queryErrorLogList() { - String key = "queryErrorLogList"; /* * 解决缓存穿透带来的问题 diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/controller/SeataTestController.java b/ty-example/src/main/java/top/kuanghua/tyexample/controller/SeataTestController.java new file mode 100644 index 0000000..f9444cd --- /dev/null +++ b/ty-example/src/main/java/top/kuanghua/tyexample/controller/SeataTestController.java @@ -0,0 +1,34 @@ +package top.kuanghua.tyexample.controller; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +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 top.kuanghua.tyexample.service.SeataTestService; + +/** + * @Title: SeataTestController + * @Description: + * @Auther: kuanghua + * @create 2022-01-10 15:05 + */ + +@Api(tags = "seata测试") +@RestController +@RequestMapping("seataTest") +public class SeataTestController { + @Autowired + private SeataTestService seataTestService; + + @ApiOperation(value = "测试seata回滚") + @GetMapping("test-seata-rollback") + public void testSeataRollback() { + try { + seataTestService.testSeataRollback(); + } catch (InterruptedException e) { + throw new RuntimeException("错误了"); + } + } +} diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/listener/CanalDataEventListener.java b/ty-example/src/main/java/top/kuanghua/tyexample/listener/CanalDataEventListener.java new file mode 100644 index 0000000..5e45cc6 --- /dev/null +++ b/ty-example/src/main/java/top/kuanghua/tyexample/listener/CanalDataEventListener.java @@ -0,0 +1,53 @@ +package top.kuanghua.tyexample.listener; + +import com.alibaba.otter.canal.protocol.CanalEntry; +import com.xpand.starter.canal.annotation.*; + +/** + * @Title: CanalDataEventListener + * @Description: + * @Auther: kuanghua + * @create 2020/9/1 22:43 + */ +@CanalEventListener +public class CanalDataEventListener { + @InsertListenPoint + public void onEventInsert(CanalEntry.EventType eventType, CanalEntry.RowData rowData) { + for (CanalEntry.Column column : rowData.getAfterColumnsList()) { + System.out.println("新增" + column.getName() + ":获取的数据" + column.getValue()); + } + } + + @UpdateListenPoint + public void onEventUpdate(CanalEntry.EventType eventType, CanalEntry.RowData rowData) { + for (CanalEntry.Column column : rowData.getBeforeColumnsList()) { + System.out.println("修改前" + column.getName() + ":获取的数据" + column.getValue()); + } + for (CanalEntry.Column column : rowData.getAfterColumnsList()) { + System.out.println("修改后" + column.getName() + ":获取的数据" + column.getValue()); + } + } + + @DeleteListenPoint + public void onEventDelete(CanalEntry.EventType eventType, CanalEntry.RowData rowData) { + for (CanalEntry.Column column : rowData.getBeforeColumnsList()) { + System.out.println("删除前" + column.getName() + ":获取的数据" + column.getValue()); + } + } + + //自定义监听 + @ListenPoint( + eventType = {CanalEntry.EventType.DELETE, CanalEntry.EventType.UPDATE}, //监听类型 + schema = {"changgou_content"}, + table = {"tb_content"}, //指定监控的表 + destination = "example" //指定实例的地址 + ) + public void onEventCustomUpdate(CanalEntry.EventType eventType, CanalEntry.RowData rowData) { + for (CanalEntry.Column column : rowData.getBeforeColumnsList()) { + System.out.println("自定义前" + column.getName() + ":获取的数据" + column.getValue()); + } + for (CanalEntry.Column column : rowData.getAfterColumnsList()) { + System.out.println("自定义后" + column.getName() + ":获取的数据" + column.getValue()); + } + } +} diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/mapper/ErrorCollectionMapper.java b/ty-example/src/main/java/top/kuanghua/tyexample/mapper/ErrorCollectionMapper.java index 0e5413a..49b5aba 100644 --- a/ty-example/src/main/java/top/kuanghua/tyexample/mapper/ErrorCollectionMapper.java +++ b/ty-example/src/main/java/top/kuanghua/tyexample/mapper/ErrorCollectionMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import top.kuanghua.tyexample.entity.ErrorCollection; + public interface ErrorCollectionMapper extends BaseMapper { } diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/service/SeataTestService.java b/ty-example/src/main/java/top/kuanghua/tyexample/service/SeataTestService.java new file mode 100644 index 0000000..192ff88 --- /dev/null +++ b/ty-example/src/main/java/top/kuanghua/tyexample/service/SeataTestService.java @@ -0,0 +1,26 @@ +package top.kuanghua.tyexample.service; + +import org.springframework.stereotype.Service; +import top.kuanghua.feign.tyuser.feign.UserFeign; + +import javax.annotation.Resource; + +/** + * @Title: SeataTestService + * @Description: + * @Auther: kuanghua + * @create 2022-01-10 15:09 + */ +@Service +public class SeataTestService { + + @Resource + private UserFeign userFeign; + + + public void testSeataRollback() throws InterruptedException { + userFeign.insertUser("jzfai"); + Thread.sleep(2000); + int fai = 1 / 0; + } +} diff --git a/ty-example/src/main/resources/application.yml b/ty-example/src/main/resources/application.yml index e69de29..bf57b5a 100644 --- a/ty-example/src/main/resources/application.yml +++ b/ty-example/src/main/resources/application.yml @@ -0,0 +1,59 @@ +#msg config, place change to you sms config +kuanghua: + sms: + accessKeyId: LTAI4FrD2voTK2wTgRCPwT6d + accessKeySecret: Zj07thnb2jiBkl4wtqgvPeuSzkJRJ3 + signName: 品优商城 # 签名名称 + verifyCodeTemplate: SMS_189216068 # 模板名称 + + + +#email config, place change to you email +spring: + mail: + username: 869653722@qq.com + password: xbthzedhnxatbcab + host: smtp.qq.com + properties: + mail.smtp.starttls.enable: true + + + +server: + port: ${envpt.tomcatPortPre}0121 + + +#seata +seata: + enabled: true + enable-auto-data-source-proxy: false + application-id: product-server + #需要和nacos中配置保持一致config.txt service.vgroupMapping.product-server-group=default + tx-service-group: product-server-group + config: + type: nacos + nacos: + #需要和server在同一个注册中心下 + serverAddr: 8.135.1.141:8848 + #需要server端(registry和config)、nacos配置client端(registry和config)保持一致 + group: SEATA_GROUP + userName: "jzfai" + password: "123456" + registry: + type: nacos + nacos: + #需要和server端保持一致,即server在nacos中的名称,默认为seata-server + application: seata-server + server-addr: 8.135.1.141:8848 + #需要server端(registry和config)、nacos配置client端(registry和config)保持一致 + group: SEATA_GROUP + userName: "jzfai" + + +#canal配置 +canal: + client: + instances: + example: + host: 8.135.1.141 + port: 11111 diff --git a/ty-example/ty-example.iml b/ty-example/ty-example.iml index 24c4b6e..aa31c78 100644 --- a/ty-example/ty-example.iml +++ b/ty-example/ty-example.iml @@ -216,6 +216,14 @@ + + + + + + + + diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/UserApplication.java b/ty-user/src/main/java/top/kuanghua/tyuser/UserApplication.java index afcf358..e61174e 100644 --- a/ty-user/src/main/java/top/kuanghua/tyuser/UserApplication.java +++ b/ty-user/src/main/java/top/kuanghua/tyuser/UserApplication.java @@ -11,8 +11,9 @@ * @create 2020/11/7 20:07 */ @SpringBootApplication +@EnableAutoDataSourceProxy //开启seata事务管理 public class UserApplication { public static void main(String[] args) { - SpringApplication.run(UserApplication.class,args); + SpringApplication.run(UserApplication.class, args); } -} \ No newline at end of file +} diff --git a/ty-user/src/main/resources/application.yml b/ty-user/src/main/resources/application.yml index 3744044..340c3c1 100644 --- a/ty-user/src/main/resources/application.yml +++ b/ty-user/src/main/resources/application.yml @@ -1,2 +1,23 @@ -server: - port: ${envpt.tomcatPortPre}0106 +seata: + enabled: true + enable-auto-data-source-proxy: true + application-id: product-server + #需要和nacos中配置保持一致config.txt service.vgroupMapping.product-server-group=default + tx-service-group: product-server-group + config: + type: nacos + nacos: + #需要和server在同一个注册中心下 + serverAddr: 8.135.1.141:8848 + #需要server端(registry和config)、nacos配置client端(registry和config)保持一致 + group: SEATA_GROUP + userName: "jzfai" + password: "123456" + registry: + type: nacos + nacos: + #需要和server端保持一致,即server在nacos中的名称,默认为seata-server + application: seata-server + server-addr: 8.135.1.141:8848 + #需要server端(registry和config)、nacos配置client端(registry和config)保持一致 + group: SEATA_GROUP \ No newline at end of file diff --git a/ty-user/src/main/resources/bootstrap.yml b/ty-user/src/main/resources/bootstrap.yml index 3a75337..5968baf 100644 --- a/ty-user/src/main/resources/bootstrap.yml +++ b/ty-user/src/main/resources/bootstrap.yml @@ -38,4 +38,8 @@ spring: username: @nacosUsername@ password: @nacosPassword@ server-addr: @nacosIpPort@ - weight: @nacosWeight@ \ No newline at end of file + weight: @nacosWeight@ + + +server: + port: ${envpt.tomcatPortPre}0106 \ No newline at end of file From 7b0e5d2c907b2c6fb52282da650a3c5e824994a2 Mon Sep 17 00:00:00 2001 From: kuanghua <869653722@qq.com> Date: Mon, 10 Jan 2022 21:00:35 +0800 Subject: [PATCH 15/36] add seata use demo --- micro-service-plus.iml | 57 ---- pom.xml | 2 +- ty-auth/pom.xml | 5 - ty-auth/ty-auth.iml | 222 --------------- ty-common/pom.xml | 1 - ty-common/src/main/main3.iml | 11 - ty-common/ty-common.iml | 220 --------------- ty-example/pom.xml | 5 - .../tyexample/ExampleApplication.java | 5 +- .../controller/SeataTestController.java | 6 +- .../tyexample/service/SeataTestService.java | 8 +- ty-example/src/main/main12.iml | 13 - ty-example/src/main/resources/application.yml | 26 -- ty-example/src/main/resources/bootstrap.yml | 4 + ty-example/ty-example.iml | 253 ------------------ ty-excel/ty-excel.iml | 238 ---------------- ty-gateway/ty-gateway-one/ty-gateway-one.iml | 235 ---------------- ty-gateway/ty-gateway.iml | 223 --------------- ty-upload/ty-upload.iml | 230 ---------------- .../top/kuanghua/tyuser/UserApplication.java | 2 +- ty-user/src/main/main4.iml | 13 - ty-user/src/main/resources/application.yml | 23 -- ty-user/src/main/resources/bootstrap.yml | 5 + ty-user/ty-user.iml | 233 ---------------- 24 files changed, 20 insertions(+), 2020 deletions(-) delete mode 100644 micro-service-plus.iml delete mode 100644 ty-auth/ty-auth.iml delete mode 100644 ty-common/src/main/main3.iml delete mode 100644 ty-common/ty-common.iml delete mode 100644 ty-example/src/main/main12.iml delete mode 100644 ty-example/ty-example.iml delete mode 100644 ty-excel/ty-excel.iml delete mode 100644 ty-gateway/ty-gateway-one/ty-gateway-one.iml delete mode 100644 ty-gateway/ty-gateway.iml delete mode 100644 ty-upload/ty-upload.iml delete mode 100644 ty-user/src/main/main4.iml delete mode 100644 ty-user/ty-user.iml diff --git a/micro-service-plus.iml b/micro-service-plus.iml deleted file mode 100644 index 7f10b3d..0000000 --- a/micro-service-plus.iml +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/pom.xml b/pom.xml index 8872073..5166516 100644 --- a/pom.xml +++ b/pom.xml @@ -60,7 +60,7 @@ com.alibaba fastjson - 1.2.51 + 1.2.79 diff --git a/ty-auth/pom.xml b/ty-auth/pom.xml index 21837ec..c04f8eb 100644 --- a/ty-auth/pom.xml +++ b/ty-auth/pom.xml @@ -17,11 +17,6 @@ ty-common 1.0-SNAPSHOT - - top.kuanghua - user-api - 1.0-SNAPSHOT - diff --git a/ty-auth/ty-auth.iml b/ty-auth/ty-auth.iml deleted file mode 100644 index 9447a05..0000000 --- a/ty-auth/ty-auth.iml +++ /dev/null @@ -1,222 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ty-common/pom.xml b/ty-common/pom.xml index 27b5bbe..1a35ee8 100644 --- a/ty-common/pom.xml +++ b/ty-common/pom.xml @@ -123,7 +123,6 @@ spring-boot-devtools - com.alibaba.cloud spring-cloud-starter-alibaba-seata diff --git a/ty-common/src/main/main3.iml b/ty-common/src/main/main3.iml deleted file mode 100644 index 908ad4f..0000000 --- a/ty-common/src/main/main3.iml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/ty-common/ty-common.iml b/ty-common/ty-common.iml deleted file mode 100644 index 3ffe7b5..0000000 --- a/ty-common/ty-common.iml +++ /dev/null @@ -1,220 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ty-example/pom.xml b/ty-example/pom.xml index b040d7d..bc88a27 100644 --- a/ty-example/pom.xml +++ b/ty-example/pom.xml @@ -16,11 +16,6 @@ ty-common 1.0-SNAPSHOT - - top.kuanghua - user-api - 1.0-SNAPSHOT - com.aliyun diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/ExampleApplication.java b/ty-example/src/main/java/top/kuanghua/tyexample/ExampleApplication.java index 35ae229..eb9767a 100644 --- a/ty-example/src/main/java/top/kuanghua/tyexample/ExampleApplication.java +++ b/ty-example/src/main/java/top/kuanghua/tyexample/ExampleApplication.java @@ -1,5 +1,7 @@ package top.kuanghua.tyexample; +import com.xpand.starter.canal.annotation.EnableCanalClient; +import io.seata.spring.annotation.datasource.EnableAutoDataSourceProxy; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableAsync; @@ -8,7 +10,8 @@ @SpringBootApplication @EnableScheduling @EnableAsync -//@EnableAutoDataSourceProxy +//@EnableCanalClient +@EnableAutoDataSourceProxy public class ExampleApplication { public static void main(String[] args) { SpringApplication.run(ExampleApplication.class, args); diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/controller/SeataTestController.java b/ty-example/src/main/java/top/kuanghua/tyexample/controller/SeataTestController.java index f9444cd..006e993 100644 --- a/ty-example/src/main/java/top/kuanghua/tyexample/controller/SeataTestController.java +++ b/ty-example/src/main/java/top/kuanghua/tyexample/controller/SeataTestController.java @@ -25,10 +25,6 @@ public class SeataTestController { @ApiOperation(value = "测试seata回滚") @GetMapping("test-seata-rollback") public void testSeataRollback() { - try { - seataTestService.testSeataRollback(); - } catch (InterruptedException e) { - throw new RuntimeException("错误了"); - } + seataTestService.testSeataRollback(); } } diff --git a/ty-example/src/main/java/top/kuanghua/tyexample/service/SeataTestService.java b/ty-example/src/main/java/top/kuanghua/tyexample/service/SeataTestService.java index 192ff88..3b733e7 100644 --- a/ty-example/src/main/java/top/kuanghua/tyexample/service/SeataTestService.java +++ b/ty-example/src/main/java/top/kuanghua/tyexample/service/SeataTestService.java @@ -1,6 +1,7 @@ package top.kuanghua.tyexample.service; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import top.kuanghua.feign.tyuser.feign.UserFeign; import javax.annotation.Resource; @@ -17,10 +18,9 @@ public class SeataTestService { @Resource private UserFeign userFeign; - - public void testSeataRollback() throws InterruptedException { + @Transactional(rollbackFor = Exception.class) + public void testSeataRollback(){ userFeign.insertUser("jzfai"); - Thread.sleep(2000); - int fai = 1 / 0; + int i=10/0; } } diff --git a/ty-example/src/main/main12.iml b/ty-example/src/main/main12.iml deleted file mode 100644 index f608aea..0000000 --- a/ty-example/src/main/main12.iml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/ty-example/src/main/resources/application.yml b/ty-example/src/main/resources/application.yml index bf57b5a..5d95712 100644 --- a/ty-example/src/main/resources/application.yml +++ b/ty-example/src/main/resources/application.yml @@ -23,32 +23,6 @@ server: port: ${envpt.tomcatPortPre}0121 -#seata -seata: - enabled: true - enable-auto-data-source-proxy: false - application-id: product-server - #需要和nacos中配置保持一致config.txt service.vgroupMapping.product-server-group=default - tx-service-group: product-server-group - config: - type: nacos - nacos: - #需要和server在同一个注册中心下 - serverAddr: 8.135.1.141:8848 - #需要server端(registry和config)、nacos配置client端(registry和config)保持一致 - group: SEATA_GROUP - userName: "jzfai" - password: "123456" - registry: - type: nacos - nacos: - #需要和server端保持一致,即server在nacos中的名称,默认为seata-server - application: seata-server - server-addr: 8.135.1.141:8848 - #需要server端(registry和config)、nacos配置client端(registry和config)保持一致 - group: SEATA_GROUP - userName: "jzfai" - #canal配置 canal: diff --git a/ty-example/src/main/resources/bootstrap.yml b/ty-example/src/main/resources/bootstrap.yml index 76ddd5d..883a2b2 100644 --- a/ty-example/src/main/resources/bootstrap.yml +++ b/ty-example/src/main/resources/bootstrap.yml @@ -36,6 +36,10 @@ spring: - data-id: application-upload.yml group: @nacosGroup@ refresh: true + #get seata config need after db config + - data-id: application-seata.yml + group: @nacosGroup@ + refresh: true discovery: namespace: @nacosNamespace@ group: @nacosGroup@ diff --git a/ty-example/ty-example.iml b/ty-example/ty-example.iml deleted file mode 100644 index aa31c78..0000000 --- a/ty-example/ty-example.iml +++ /dev/null @@ -1,253 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ty-excel/ty-excel.iml b/ty-excel/ty-excel.iml deleted file mode 100644 index ac0db2e..0000000 --- a/ty-excel/ty-excel.iml +++ /dev/null @@ -1,238 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ty-gateway/ty-gateway-one/ty-gateway-one.iml b/ty-gateway/ty-gateway-one/ty-gateway-one.iml deleted file mode 100644 index 2e4a4dc..0000000 --- a/ty-gateway/ty-gateway-one/ty-gateway-one.iml +++ /dev/null @@ -1,235 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ty-gateway/ty-gateway.iml b/ty-gateway/ty-gateway.iml deleted file mode 100644 index e5e33c2..0000000 --- a/ty-gateway/ty-gateway.iml +++ /dev/null @@ -1,223 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ty-upload/ty-upload.iml b/ty-upload/ty-upload.iml deleted file mode 100644 index 39cc125..0000000 --- a/ty-upload/ty-upload.iml +++ /dev/null @@ -1,230 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/UserApplication.java b/ty-user/src/main/java/top/kuanghua/tyuser/UserApplication.java index e61174e..836265c 100644 --- a/ty-user/src/main/java/top/kuanghua/tyuser/UserApplication.java +++ b/ty-user/src/main/java/top/kuanghua/tyuser/UserApplication.java @@ -11,7 +11,7 @@ * @create 2020/11/7 20:07 */ @SpringBootApplication -@EnableAutoDataSourceProxy //开启seata事务管理 +@EnableAutoDataSourceProxy public class UserApplication { public static void main(String[] args) { SpringApplication.run(UserApplication.class, args); diff --git a/ty-user/src/main/main4.iml b/ty-user/src/main/main4.iml deleted file mode 100644 index f608aea..0000000 --- a/ty-user/src/main/main4.iml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/ty-user/src/main/resources/application.yml b/ty-user/src/main/resources/application.yml index 340c3c1..e69de29 100644 --- a/ty-user/src/main/resources/application.yml +++ b/ty-user/src/main/resources/application.yml @@ -1,23 +0,0 @@ -seata: - enabled: true - enable-auto-data-source-proxy: true - application-id: product-server - #需要和nacos中配置保持一致config.txt service.vgroupMapping.product-server-group=default - tx-service-group: product-server-group - config: - type: nacos - nacos: - #需要和server在同一个注册中心下 - serverAddr: 8.135.1.141:8848 - #需要server端(registry和config)、nacos配置client端(registry和config)保持一致 - group: SEATA_GROUP - userName: "jzfai" - password: "123456" - registry: - type: nacos - nacos: - #需要和server端保持一致,即server在nacos中的名称,默认为seata-server - application: seata-server - server-addr: 8.135.1.141:8848 - #需要server端(registry和config)、nacos配置client端(registry和config)保持一致 - group: SEATA_GROUP \ No newline at end of file diff --git a/ty-user/src/main/resources/bootstrap.yml b/ty-user/src/main/resources/bootstrap.yml index 5968baf..98d883d 100644 --- a/ty-user/src/main/resources/bootstrap.yml +++ b/ty-user/src/main/resources/bootstrap.yml @@ -32,6 +32,10 @@ spring: - data-id: application-db.yml group: @nacosGroup@ refresh: true + #get seata config need after db config + - data-id: application-seata.yml + group: @nacosGroup@ + refresh: true discovery: namespace: @nacosNamespace@ group: @nacosGroup@ @@ -41,5 +45,6 @@ spring: weight: @nacosWeight@ + server: port: ${envpt.tomcatPortPre}0106 \ No newline at end of file diff --git a/ty-user/ty-user.iml b/ty-user/ty-user.iml deleted file mode 100644 index 0ccd583..0000000 --- a/ty-user/ty-user.iml +++ /dev/null @@ -1,233 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From ef05adc8399a61a50b57eaef79a282ee8082b2ea Mon Sep 17 00:00:00 2001 From: jzfai <869653722@qq.com> Date: Tue, 11 Jan 2022 16:10:31 +0800 Subject: [PATCH 16/36] add seata canal email send msg demo update fastJson version --- README-zh_CN.md | 2 +- README.md | 7 +- {ty-user => integration-front}/pom.xml | 2 +- .../IntegrationFrontApplication.java | 38 +- .../integrationfront}/config/BaseConfig.java | 54 +-- .../config/Swagger2Config.java | 112 ++--- .../controller/BrandController.java | 254 +++++----- .../controller/ErrorCollectionController.java | 246 +++++----- .../controller/UserController.java | 404 ++++++++------- .../controller/VciController.java | 341 +++++++------ .../integrationfront}/entity/Access.java | 90 ++-- .../integrationfront}/entity/Admin.java | 98 ++-- .../integrationfront}/entity/Brand.java | 100 ++-- .../entity/ErrorCollection.java | 72 ++- .../integrationfront}/entity/Role.java | 82 ++-- .../integrationfront}/entity/RoleAccess.java | 92 ++-- .../integrationfront}/entity/User.java | 130 ++--- .../integrationfront}/entity/UserRole.java | 90 ++-- .../integrationfront}/entity/Vci.java | 102 ++-- .../excel/cv/VciStatusImpCv.java | 68 +-- .../integrationfront}/excel/cv/VciTimeCv.java | 54 +-- .../excel/imp/VciExcelImp.java | 80 +-- .../mapper/AccessMapper.java | 26 +- .../integrationfront}/mapper/AdminMapper.java | 42 +- .../integrationfront}/mapper/BrandMapper.java | 16 +- .../mapper/ErrorCollectionMapper.java | 16 +- .../mapper/MultiPageMapper.java | 32 +- .../mapper/RoleAccessMapper.java | 26 +- .../integrationfront}/mapper/RoleMapper.java | 26 +- .../integrationfront}/mapper/UserMapper.java | 28 +- .../mapper/UserRoleMapper.java | 26 +- .../integrationfront}/mapper/VciMapper.java | 16 +- .../service/AccessService.java | 96 ++-- .../service/AdminService.java | 82 ++-- .../service/BrandService.java | 102 ++-- .../service/ErrorCollectionService.java | 102 ++-- .../service/RoleAccessService.java | 72 +-- .../service/RoleService.java | 72 +-- .../service/UserRoleService.java | 72 +-- .../service/UserService.java | 458 +++++++++--------- .../integrationfront}/service/VciService.java | 266 +++++----- .../vo/ExcelCheckResult.java | 58 +-- .../kuanghua/integrationfront}/vo/UserVo.java | 72 +-- .../src/main/resources/application.yml | 0 .../src/main/resources/bootstrap.yml | 0 .../src/main/resources/mapper/AdminMapper.xml | 220 ++++----- pom.xml | 31 +- .../tyauth/config/Swagger2Config.java | 2 +- ty-common/pom.xml | 2 +- .../controller/HstrixController.java | 5 +- .../feign/UserFeign.java | 32 +- .../feign/tyexecl/feign/ExcelFeign.java | 22 - .../tyexample/ExampleApplication.java | 2 +- .../kuanghua/tyexample/config/BaseConfig.java | 6 +- .../tyexample/config/Swagger2Config.java | 2 +- .../listener/CanalDataEventListener.java | 52 +- .../tyexample/service/SeataTestService.java | 6 +- .../tyexample/service/UploadService.java | 22 +- ty-example/src/main/resources/application.yml | 33 -- .../tyexcel/service/ExcelService.java | 2 - .../SpecialHystrixGatewayFilterFactory.java | 2 +- .../src/main/resources/application.yml | 55 ++- 62 files changed, 2325 insertions(+), 2395 deletions(-) rename {ty-user => integration-front}/pom.xml (97%) rename ty-user/src/main/java/top/kuanghua/tyuser/UserApplication.java => integration-front/src/main/java/top/kuanghua/integrationfront/IntegrationFrontApplication.java (72%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/config/BaseConfig.java (67%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/config/Swagger2Config.java (95%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/controller/BrandController.java (94%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/controller/ErrorCollectionController.java (94%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/controller/UserController.java (89%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/controller/VciController.java (93%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/entity/Access.java (93%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/entity/Admin.java (93%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/entity/Brand.java (94%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/entity/ErrorCollection.java (91%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/entity/Role.java (93%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/entity/RoleAccess.java (94%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/entity/User.java (95%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/entity/UserRole.java (93%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/entity/Vci.java (94%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/excel/cv/VciStatusImpCv.java (94%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/excel/cv/VciTimeCv.java (94%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/excel/imp/VciExcelImp.java (84%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/mapper/AccessMapper.java (69%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/mapper/AdminMapper.java (84%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/mapper/BrandMapper.java (54%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/mapper/ErrorCollectionMapper.java (56%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/mapper/MultiPageMapper.java (88%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/mapper/RoleAccessMapper.java (70%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/mapper/RoleMapper.java (69%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/mapper/UserMapper.java (72%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/mapper/UserRoleMapper.java (70%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/mapper/VciMapper.java (54%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/service/AccessService.java (90%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/service/AdminService.java (83%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/service/BrandService.java (87%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/service/ErrorCollectionService.java (88%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/service/RoleAccessService.java (84%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/service/RoleService.java (83%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/service/UserRoleService.java (84%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/service/UserService.java (70%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/service/VciService.java (91%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/vo/ExcelCheckResult.java (91%) rename {ty-user/src/main/java/top/kuanghua/tyuser => integration-front/src/main/java/top/kuanghua/integrationfront}/vo/UserVo.java (89%) rename {ty-user => integration-front}/src/main/resources/application.yml (100%) rename {ty-user => integration-front}/src/main/resources/bootstrap.yml (100%) rename {ty-user => integration-front}/src/main/resources/mapper/AdminMapper.xml (91%) rename {ty-gateway/ty-gateway-one/src/main/java/top/kuanghua/gatewaytwo => ty-common/src/main/java/top/kuanghua}/controller/HstrixController.java (83%) rename ty-common/src/main/java/top/kuanghua/feign/{tyuser => integrationfront}/feign/UserFeign.java (72%) delete mode 100644 ty-common/src/main/java/top/kuanghua/feign/tyexecl/feign/ExcelFeign.java diff --git a/README-zh_CN.md b/README-zh_CN.md index 19d331a..f198909 100644 --- a/README-zh_CN.md +++ b/README-zh_CN.md @@ -50,7 +50,7 @@ ty-common: 统一依赖,统一配置管理,feign接口整合等 本架构的微服务有: ty-gateway:网关微服务。使用的是spring-cloud-starter-gateway,先对于zull网关来说性能更好。主要实现了,权限控制和拦截,jwt token解析和校验,swagger文件整合,使用令牌技术请求限流等 ty-auth:权限服务。jwt token生成,解析,校验等,默认配置3天有效期,少于一天自动续约(此处感兴趣的可以查看下源码) -ty-user:用户服务。用户的登录,注册,查看用户信息等一系列功能 +integration-front:用户服务。用户的登录,注册,查看用户信息等一系列功能 ty-excel:excel文件的读取和导出 ty-upload:文件上传服务。使用的技术为fastDFS技术,此服务主要用于文件的上传和下载 ``` diff --git a/README.md b/README.md index 2c5c8cc..1eae783 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,8 @@ mybatis-plus: 3.3.2 rabbitmq:3.7-management redis: 3.2.9 mysql:5.7 +seata:1.4.2 +cancel ``` @@ -51,9 +53,8 @@ ty-common: 统一依赖,统一配置管理,feign接口整合等 本架构的微服务有: ty-gateway:网关微服务。使用的是spring-cloud-starter-gateway,先对于zull网关来说性能更好。主要实现了,权限控制和拦截,jwt token解析和校验,swagger文件整合,使用令牌技术请求限流等 ty-auth:权限服务。jwt token生成,解析,校验等,默认配置3天有效期,少于一天自动续约(此处感兴趣的可以查看下源码) -ty-user:用户服务。用户的登录,注册,查看用户信息等一系列功能 -ty-excel:excel文件的读取和导出 -ty-upload:文件上传服务。使用的技术为fastDFS技术,此服务主要用于文件的上传和下载 +integration-front:前端实例数据。用户的登录,注册,查看用户信息等一系列功能 +ty-example:全分布式事务seata,rabbitmq延时队列,短信发送,email发送,canal等功能实例 ``` diff --git a/ty-user/pom.xml b/integration-front/pom.xml similarity index 97% rename from ty-user/pom.xml rename to integration-front/pom.xml index cb45de4..8fea0ed 100644 --- a/ty-user/pom.xml +++ b/integration-front/pom.xml @@ -9,7 +9,7 @@ 4.0.0 - ty-user + integration-front diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/UserApplication.java b/integration-front/src/main/java/top/kuanghua/integrationfront/IntegrationFrontApplication.java similarity index 72% rename from ty-user/src/main/java/top/kuanghua/tyuser/UserApplication.java rename to integration-front/src/main/java/top/kuanghua/integrationfront/IntegrationFrontApplication.java index 836265c..ac8b53d 100644 --- a/ty-user/src/main/java/top/kuanghua/tyuser/UserApplication.java +++ b/integration-front/src/main/java/top/kuanghua/integrationfront/IntegrationFrontApplication.java @@ -1,19 +1,19 @@ -package top.kuanghua.tyuser; - -import io.seata.spring.annotation.datasource.EnableAutoDataSourceProxy; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -/** - * @Title: UserApplication - * @Description: - * @Auther: kuanghua - * @create 2020/11/7 20:07 - */ -@SpringBootApplication -@EnableAutoDataSourceProxy -public class UserApplication { - public static void main(String[] args) { - SpringApplication.run(UserApplication.class, args); - } -} +package top.kuanghua.integrationfront; + +import io.seata.spring.annotation.datasource.EnableAutoDataSourceProxy; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @Title: UserApplication + * @Description: + * @Auther: kuanghua + * @create 2020/11/7 20:07 + */ +@SpringBootApplication +@EnableAutoDataSourceProxy +public class IntegrationFrontApplication { + public static void main(String[] args) { + SpringApplication.run(IntegrationFrontApplication.class, args); + } +} diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/config/BaseConfig.java b/integration-front/src/main/java/top/kuanghua/integrationfront/config/BaseConfig.java similarity index 67% rename from ty-user/src/main/java/top/kuanghua/tyuser/config/BaseConfig.java rename to integration-front/src/main/java/top/kuanghua/integrationfront/config/BaseConfig.java index b9b4cf5..6d960e2 100644 --- a/ty-user/src/main/java/top/kuanghua/tyuser/config/BaseConfig.java +++ b/integration-front/src/main/java/top/kuanghua/integrationfront/config/BaseConfig.java @@ -1,27 +1,27 @@ -package top.kuanghua.tyuser.config; - -import org.mybatis.spring.annotation.MapperScan; -import org.springframework.cloud.openfeign.EnableFeignClients; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -/** - * @Title: BaseConfig - * @Description: - * @Auther: kuanghua - * @create 2020/8/23 21:52 - */ -/* - * 总结:1.@Configuration 下的@ComponentScan回将包下带有@Component扫描变成配置类, - * 而@SpringBootApplication扫描的只会变成普通类 - * */ -@Configuration -//扫描公用包的配置和自身的配置类 -@ComponentScan(basePackages = {"top.kuanghua.khcomomon","top.kuanghua.tyuser"}) -//feign扫描 -@EnableFeignClients(basePackages = {"top.kuanghua.feign.tyexecl","top.kuanghua.feign.tyauth"}) -//mapper包扫描 -@MapperScan(basePackages = {"top.kuanghua.tyuser.mapper"}) -public class BaseConfig { - -} +package top.kuanghua.integrationfront.config; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +/** + * @Title: BaseConfig + * @Description: + * @Auther: kuanghua + * @create 2020/8/23 21:52 + */ +/* + * 总结:1.@Configuration 下的@ComponentScan回将包下带有@Component扫描变成配置类, + * 而@SpringBootApplication扫描的只会变成普通类 + * */ +@Configuration +//扫描公用包的配置和自身的配置类 +@ComponentScan(basePackages = {"top.kuanghua.khcomomon", "top.kuanghua.integrationfront"}) +//feign扫描 +@EnableFeignClients(basePackages = {"top.kuanghua.feign.tyauth"}) +//mapper包扫描 +@MapperScan(basePackages = {"top.kuanghua.integrationfront.mapper"}) +public class BaseConfig { + +} diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/config/Swagger2Config.java b/integration-front/src/main/java/top/kuanghua/integrationfront/config/Swagger2Config.java similarity index 95% rename from ty-user/src/main/java/top/kuanghua/tyuser/config/Swagger2Config.java rename to integration-front/src/main/java/top/kuanghua/integrationfront/config/Swagger2Config.java index 934deb1..0f38531 100644 --- a/ty-user/src/main/java/top/kuanghua/tyuser/config/Swagger2Config.java +++ b/integration-front/src/main/java/top/kuanghua/integrationfront/config/Swagger2Config.java @@ -1,56 +1,56 @@ -package top.kuanghua.tyuser.config; - -import io.swagger.annotations.ApiOperation; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.stereotype.Component; -import springfox.documentation.builders.ApiInfoBuilder; -import springfox.documentation.builders.PathSelectors; -import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.service.ApiInfo; -import springfox.documentation.service.Contact; -import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spring.web.plugins.Docket; -import springfox.documentation.swagger2.annotations.EnableSwagger2; - -@Component -@EnableSwagger2 //开启在线接口文档 -//配置包扫描 -public class Swagger2Config { - private boolean swagger_is_enable = true; -// @Value("${.ipAddr}") -// private String ipAddr; - @Value("${server.port}") - private String port; - - @Bean - public Docket api() { - return new Docket(DocumentationType.SWAGGER_2) - .enable(swagger_is_enable) - //.host(this.ipAddr + ":" + this.port) - .apiInfo(apiInfo()) - .select() - .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) - //.apis(basePackage("top.kuanghua.swagger.controller")) - .paths(PathSelectors.any()) - .build(); - } - - /** - * 构建 api文档的详细信息函数 - * - * @return - */ - private ApiInfo apiInfo() { - return new ApiInfoBuilder() - .title("标题:swagger文档") - .description("描述:新一代的微服务架构") - .contact(new Contact("jzfai", null, "869653722@qq.com")) - .version("版本号:2.8") - .build(); - } - - /** - * http://localhost:8080/swagger-ui.html - */ -} +package top.kuanghua.integrationfront.config; + +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.stereotype.Component; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Component +@EnableSwagger2 //开启在线接口文档 +//配置包扫描 +public class Swagger2Config { + private boolean swagger_is_enable = true; +// @Value("${.ipAddr}") +// private String ipAddr; + @Value("${server.port}") + private String port; + + @Bean + public Docket api() { + return new Docket(DocumentationType.SWAGGER_2) + .enable(swagger_is_enable) + //.host(this.ipAddr + ":" + this.port) + .apiInfo(apiInfo()) + .select() + .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) + //.apis(basePackage("top.kuanghua.swagger.controller")) + .paths(PathSelectors.any()) + .build(); + } + + /** + * 构建 api文档的详细信息函数 + * + * @return + */ + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("标题:swagger文档") + .description("描述:新一代的微服务架构") + .contact(new Contact("jzfai", null, "869653722@qq.com")) + .version("版本号:2.8") + .build(); + } + + /** + * http://localhost:8080/swagger-ui.html + */ +} diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/controller/BrandController.java b/integration-front/src/main/java/top/kuanghua/integrationfront/controller/BrandController.java similarity index 94% rename from ty-user/src/main/java/top/kuanghua/tyuser/controller/BrandController.java rename to integration-front/src/main/java/top/kuanghua/integrationfront/controller/BrandController.java index c171fa4..1a43e45 100644 --- a/ty-user/src/main/java/top/kuanghua/tyuser/controller/BrandController.java +++ b/integration-front/src/main/java/top/kuanghua/integrationfront/controller/BrandController.java @@ -1,127 +1,127 @@ -package top.kuanghua.tyuser.controller; - - -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import org.apache.commons.lang3.StringUtils; -import org.springframework.web.bind.annotation.*; -import top.kuanghua.khcomomon.entity.KHCommonParams; -import top.kuanghua.khcomomon.entity.ResResult; -import top.kuanghua.tyuser.entity.Brand; -import top.kuanghua.tyuser.service.BrandService; - -import javax.annotation.Resource; -import java.util.List; - -@Api(tags = "品牌表(Brand)") -@RestController -@RequestMapping("brand") -public class BrandController { - - @Resource - private BrandService brandService; - - /** - * 分页查询所有数据 - * - * @param brand 查询实体 - * @return 所有数据 - */ - @GetMapping("selectPage") - @ApiOperation(value = "分页查询所有数据") - public ResResult selectPage(Brand brand, KHCommonParams commonParams) { - QueryWrapper queryWrapper = new QueryWrapper<>(); - if (ObjectUtils.isNotEmpty(brand.getId())) { - queryWrapper.like("id", brand.getId()); - } - if (ObjectUtils.isNotEmpty(brand.getName())) { - queryWrapper.like("name", brand.getName()); - } - if (ObjectUtils.isNotEmpty(brand.getImage())) { - queryWrapper.like("image", brand.getImage()); - } - - if (ObjectUtils.isNotEmpty(brand.getLetter())) { - queryWrapper.like("letter", brand.getLetter()); - } - if (ObjectUtils.isNotEmpty(brand.getSeq())) { - queryWrapper.like("seq", brand.getSeq()); - } - queryWrapper.orderByDesc("create_time"); - if (StringUtils.isNotEmpty(commonParams.getStartTime())) { - queryWrapper.between("create_time", commonParams.getStartTime(), commonParams.getEndTime()); - } - queryWrapper.select("id,name,image,letter,seq,create_time,update_time"); - Page brandPage = this.brandService.selectPage(commonParams.getPageNum(), commonParams.getPageSize(), queryWrapper); - return new ResResult().success(brandPage); - } - - /** - * 通过主键查询单条数据 - * - * @param id 主键 - * @return 单条数据 - */ - @GetMapping("selectById") - @ApiOperation(value = "通过id主键查询单条数据") - public ResResult selectById(@RequestParam("id") Integer id) { - return new ResResult().success(this.brandService.selectById(id)); - } - - /** - * @Description: 根据id数组查询品牌列表 - * @Param: idList id数组 - * @return: ids列表数据 - */ - @ApiOperation(value = "根据id数组查询品牌列表") - @PostMapping("selectBatchIds") - public ResResult selectBatchIds(@RequestParam("idList") List idList) { - return new ResResult().success(this.brandService.selectBatchIds(idList)); - } - - - /** - * 新增数据 - * - * @param brand 实体对象 - * @return 新增结果 - */ - @ApiOperation(value = "新增数据") - @PostMapping("insert") - public ResResult insert(@RequestBody Brand brand) { - return new ResResult().success(this.brandService.insert(brand)); - } - - /** - * 修改数据 - * - * @param brand 实体对象 - * @return 修改结果 - */ - @ApiOperation(value = "根据id修改数据") - @PutMapping("updateById") - public ResResult updateById(@RequestBody Brand brand) { - return new ResResult().success(this.brandService.updateById(brand)); - } - - /** - * 删除数据 - * - * @param idList 主键结合 - * @return 删除结果 - */ - @ApiOperation(value = "根据id数组删除数据") - @DeleteMapping("deleteBatchIds") - public ResResult deleteBatchIds(@RequestBody List idList) { - return new ResResult().success(this.brandService.deleteBatchIds(idList)); - } - - @DeleteMapping("deleteById") - @ApiOperation(value = "根据id数组删除数据") - public ResResult deleteById(@RequestParam("id") Integer id) { - return new ResResult().success(this.brandService.deleteById(id)); - } -} +package top.kuanghua.integrationfront.controller; + + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.springframework.web.bind.annotation.*; +import top.kuanghua.khcomomon.entity.KHCommonParams; +import top.kuanghua.khcomomon.entity.ResResult; +import top.kuanghua.integrationfront.entity.Brand; +import top.kuanghua.integrationfront.service.BrandService; + +import javax.annotation.Resource; +import java.util.List; + +@Api(tags = "品牌表(Brand)") +@RestController +@RequestMapping("brand") +public class BrandController { + + @Resource + private BrandService brandService; + + /** + * 分页查询所有数据 + * + * @param brand 查询实体 + * @return 所有数据 + */ + @GetMapping("selectPage") + @ApiOperation(value = "分页查询所有数据") + public ResResult selectPage(Brand brand, KHCommonParams commonParams) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (ObjectUtils.isNotEmpty(brand.getId())) { + queryWrapper.like("id", brand.getId()); + } + if (ObjectUtils.isNotEmpty(brand.getName())) { + queryWrapper.like("name", brand.getName()); + } + if (ObjectUtils.isNotEmpty(brand.getImage())) { + queryWrapper.like("image", brand.getImage()); + } + + if (ObjectUtils.isNotEmpty(brand.getLetter())) { + queryWrapper.like("letter", brand.getLetter()); + } + if (ObjectUtils.isNotEmpty(brand.getSeq())) { + queryWrapper.like("seq", brand.getSeq()); + } + queryWrapper.orderByDesc("create_time"); + if (StringUtils.isNotEmpty(commonParams.getStartTime())) { + queryWrapper.between("create_time", commonParams.getStartTime(), commonParams.getEndTime()); + } + queryWrapper.select("id,name,image,letter,seq,create_time,update_time"); + Page brandPage = this.brandService.selectPage(commonParams.getPageNum(), commonParams.getPageSize(), queryWrapper); + return new ResResult().success(brandPage); + } + + /** + * 通过主键查询单条数据 + * + * @param id 主键 + * @return 单条数据 + */ + @GetMapping("selectById") + @ApiOperation(value = "通过id主键查询单条数据") + public ResResult selectById(@RequestParam("id") Integer id) { + return new ResResult().success(this.brandService.selectById(id)); + } + + /** + * @Description: 根据id数组查询品牌列表 + * @Param: idList id数组 + * @return: ids列表数据 + */ + @ApiOperation(value = "根据id数组查询品牌列表") + @PostMapping("selectBatchIds") + public ResResult selectBatchIds(@RequestParam("idList") List idList) { + return new ResResult().success(this.brandService.selectBatchIds(idList)); + } + + + /** + * 新增数据 + * + * @param brand 实体对象 + * @return 新增结果 + */ + @ApiOperation(value = "新增数据") + @PostMapping("insert") + public ResResult insert(@RequestBody Brand brand) { + return new ResResult().success(this.brandService.insert(brand)); + } + + /** + * 修改数据 + * + * @param brand 实体对象 + * @return 修改结果 + */ + @ApiOperation(value = "根据id修改数据") + @PutMapping("updateById") + public ResResult updateById(@RequestBody Brand brand) { + return new ResResult().success(this.brandService.updateById(brand)); + } + + /** + * 删除数据 + * + * @param idList 主键结合 + * @return 删除结果 + */ + @ApiOperation(value = "根据id数组删除数据") + @DeleteMapping("deleteBatchIds") + public ResResult deleteBatchIds(@RequestBody List idList) { + return new ResResult().success(this.brandService.deleteBatchIds(idList)); + } + + @DeleteMapping("deleteById") + @ApiOperation(value = "根据id数组删除数据") + public ResResult deleteById(@RequestParam("id") Integer id) { + return new ResResult().success(this.brandService.deleteById(id)); + } +} diff --git a/ty-user/src/main/java/top/kuanghua/tyuser/controller/ErrorCollectionController.java b/integration-front/src/main/java/top/kuanghua/integrationfront/controller/ErrorCollectionController.java similarity index 94% rename from ty-user/src/main/java/top/kuanghua/tyuser/controller/ErrorCollectionController.java rename to integration-front/src/main/java/top/kuanghua/integrationfront/controller/ErrorCollectionController.java index dcae33f..e474129 100644 --- a/ty-user/src/main/java/top/kuanghua/tyuser/controller/ErrorCollectionController.java +++ b/integration-front/src/main/java/top/kuanghua/integrationfront/controller/ErrorCollectionController.java @@ -1,123 +1,123 @@ -package top.kuanghua.tyuser.controller; - - -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import org.apache.commons.lang3.StringUtils; -import org.springframework.web.bind.annotation.*; -import top.kuanghua.khcomomon.entity.KHCommonParams; -import top.kuanghua.khcomomon.entity.ResResult; -import top.kuanghua.tyuser.entity.ErrorCollection; -import top.kuanghua.tyuser.service.ErrorCollectionService; - -import javax.annotation.Resource; -import java.util.List; - -@Api(tags = "日志相关") -@RestController -@RequestMapping("errorCollection") -public class ErrorCollectionController { - - @Resource - private ErrorCollectionService errorCollectionService; - - /** - * 分页查询所有数据 - * - * @param errorCollection 查询实体 - * @return 所有数据 - */ - @GetMapping("selectPage") - @ApiOperation(value = "分页查询所有数据") - public ResResult selectPage(ErrorCollection errorCollection, KHCommonParams khCommonParams) { - QueryWrapper queryWrapper = new QueryWrapper<>(); - if (ObjectUtils.isNotEmpty(errorCollection.getErrorLog())) { - queryWrapper.like("error_log", errorCollection.getErrorLog()); - } - if (ObjectUtils.isNotEmpty(errorCollection.getPageUrl())) { - queryWrapper.like("page_url", errorCollection.getPageUrl()); - } - if (ObjectUtils.isNotEmpty(errorCollection.getVersion())) { - queryWrapper.like("version", errorCollection.getVersion()); - } - if (ObjectUtils.isNotEmpty(errorCollection.getCreateTime())) { - queryWrapper.like("create_time", errorCollection.getCreateTime()); - } - - if (StringUtils.isNotEmpty(khCommonParams.getStartTime())) { - queryWrapper.between("create_time", khCommonParams.getStartTime(), khCommonParams.getEndTime()); - } - queryWrapper.orderByDesc("create_time"); - Page errorCollectionPage = this.errorCollectionService.selectPage(khCommonParams.getPageNum(), khCommonParams.getPageSize(), queryWrapper); - return new ResResult().success(errorCollectionPage); - } - - /** - * 通过主键查询单条数据 - * - * @param id 主键 - * @return 单条数据 - */ - @GetMapping("selectById") - @ApiOperation(value = "通过id主键查询单条数据") - public ResResult selectById(@RequestParam("id") Integer id) { - return new ResResult().success(this.errorCollectionService.selectById(id)); - } - - /** - * @Description: 根据id数组查询品牌列表 - * @Param: idList id数组 - * @return: ids列表数据 - */ - @ApiOperation(value = "根据id数组查询品牌列表") - @PostMapping("selectBatchIds") - public ResResult selectBatchIds(@RequestParam("idList") List