From d19e01c1b3db5cc4918cdb1b4cc9bad225fbb3c9 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] 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") + + + + + 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") + + + + + 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>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J 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 @@ + + + + + + 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 @@ - - - - - - - - \ 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 @@ - - - - - - - - \ 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 @@ + + + + + + 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 @@ + + + + + + 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 @@ + + + + + +