From 70f46d241b24cb26ebde9bcd8706646b45249648 Mon Sep 17 00:00:00 2001 From: "jiakun.lin" Date: Mon, 17 May 2021 17:58:34 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E8=BF=94=E5=9B=9EdataTime=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/yipin/liuwanr/service/UserInfoService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/yipin/liuwanr/service/UserInfoService.java b/src/main/java/com/yipin/liuwanr/service/UserInfoService.java index 0df73e2..fa1c87f 100644 --- a/src/main/java/com/yipin/liuwanr/service/UserInfoService.java +++ b/src/main/java/com/yipin/liuwanr/service/UserInfoService.java @@ -541,8 +541,8 @@ public class UserInfoService { userInfoMapper.updateLogInNumber(user); String token = user.getToken(); ValueOperations redis = stringRedisTemplate.opsForValue(); - //redis.set(token,lastLoginTime, 24, TimeUnit.HOURS); - //user.setDataTime(lastLoginTime); + redis.set(token,lastLoginTime, 24, TimeUnit.HOURS); + user.setDataTime(lastLoginTime); resp.put("retvalue",user); resp.put("retcode", 200); } From 50d0a855c9ae999d0e9ec11cb03373adc3094c7a Mon Sep 17 00:00:00 2001 From: "jiakun.lin" Date: Thu, 20 May 2021 17:36:31 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=A7=91=E5=A4=A7?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=8E=AF=E5=A2=83=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application-test_keda.properties | 49 +++++++++++++++++++ src/main/resources/application.properties | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/application-test_keda.properties diff --git a/src/main/resources/application-test_keda.properties b/src/main/resources/application-test_keda.properties new file mode 100644 index 0000000..a156057 --- /dev/null +++ b/src/main/resources/application-test_keda.properties @@ -0,0 +1,49 @@ +server.port=8090 +server.servlet.context-path=/liuwanr + +#\u6D4B\u8BD5\u6570\u636E\u5E93\u8FDE\u63A5 +spring.datasource.url=jdbc:mysql://rm-wz9y13wf7u8q8610fwo.mysql.rds.aliyuncs.com:3306/keda?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai +spring.datasource.username=super +spring.datasource.password=huoran888 +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver + +#redis\u914D\u7F6E +spring.redis.database=0 +spring.redis.host=127.0.0.1 +spring.redis.password=msdw@2021 +spring.redis.port=6379 +spring.redis.timeout=3000 +spring.redis.jedis.pool.max-idle=500 +spring.redis.jedis.pool.min-idle=50 +spring.redis.jedis.pool.max-active=2000 +spring.redis.jedis.pool.max-wait=1000 + +#redis-cluster +redis.cluster.maxTotal=200 +redis.cluster.maxIdle=8 +redis.cluster.minIdle=3 +redis.cluster.nodes=192.168.136.191:8000,192.168.136.191:8001,192.168.136.191:8002 + +spring.mina.port=9123 +spring.mina.buffersize=2048 +spring.mina.idletime=15 +spring.main.show-banner=false + +#\u65E5\u5FD7\u7EA7\u522B +logging.level.jdbc=OFF +logging.level.jdbc.sqltiming=DEBUG +logging.level.jdbc.resultsettable=DEBUG +logging.level.com.yipin.liuwar.mapper=DEBUG +logging.level.com.yipin.liuwanr.mapper=DEBUG + +spring.elasticsearch.rest.uris=http://es-cn-v641e944a0006xtwy.elasticsearch.aliyuncs.com:9200 +spring.elasticsearch.rest.username=elastic +spring.elasticsearch.rest.password=1qaz@WSX + +# maxFileSize \u5355\u4E2A\u6570\u636E\u5927\u5C0F +spring.servlet.multipart.maxFileSize = 1024MB +# maxRequestSize \u662F\u603B\u6570\u636E\u5927\u5C0F +spring.servlet.multipart.maxRequestSize=10240MB + +pagehelper.reasonable=false + diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index bab924b..69bb6a9 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,2 +1,2 @@ #\u9009\u62E9\u6307\u5B9A\u73AF\u5883,\u76EE\u524D\u53EA\u6709\u6D4B\u8BD5\u548C\u6B63\u5F0F\u73AF\u5883 -spring.profiles.active=prod \ No newline at end of file +spring.profiles.active=test_keda \ No newline at end of file From 96712cfb23b9daf7bc71d9752d49c197dce86b1f Mon Sep 17 00:00:00 2001 From: shijie <648688341@qq.com> Date: Thu, 20 May 2021 17:52:59 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E7=BB=84=E7=BB=87=E6=9E=B6=E6=9E=84?= =?UTF-8?q?=E9=83=A8=E5=88=86=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/StaffGradeController.java | 11 ++++++++- .../liuwanr/mapper/StaffGradeMapper.java | 12 +++++++++- .../liuwanr/service/StaffGradeService.java | 24 ++++++++++++++++--- .../liuwanr/service/StaffGradServiceTest.java | 18 +++++++------- 4 files changed, 51 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/yipin/liuwanr/controller/StaffGradeController.java b/src/main/java/com/yipin/liuwanr/controller/StaffGradeController.java index 0e170fd..744ac20 100644 --- a/src/main/java/com/yipin/liuwanr/controller/StaffGradeController.java +++ b/src/main/java/com/yipin/liuwanr/controller/StaffGradeController.java @@ -1,6 +1,7 @@ package com.yipin.liuwanr.controller; import java.util.HashMap; +import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.CrossOrigin; @@ -103,11 +104,19 @@ public class StaffGradeController { Response deleteStaffGrade(@RequestBody StaffGrade staffGrade) { Response resp = new Response(); Integer staffGradeId = staffGrade.getStaffGradeId(); + HashMap ret = new HashMap<>(); if (staffGradeId==null) { resp.setStatus(300); resp.setErrmessage("Parameter Invalid"); } else { - HashMap ret = staffGradeService.deleteStaffGrade(staffGradeId); + List userIds = staffGradeService.queryUserIdsByGradeId(staffGradeId); + if(userIds.size()>0){ + ret = staffGradeService.deleteStaffGrade(userIds); + ret = staffGradeService.deleteStaffGradePs(staffGradeId); + }else{//如果组织架构下面没有员工,则只删除组织架构 + ret = staffGradeService.deleteStaffGradePs(staffGradeId); + } + int status = (int) ret.get("retcode"); if (200 == status) { resp.setStatus(status); diff --git a/src/main/java/com/yipin/liuwanr/mapper/StaffGradeMapper.java b/src/main/java/com/yipin/liuwanr/mapper/StaffGradeMapper.java index aaeef71..df85618 100644 --- a/src/main/java/com/yipin/liuwanr/mapper/StaffGradeMapper.java +++ b/src/main/java/com/yipin/liuwanr/mapper/StaffGradeMapper.java @@ -21,8 +21,15 @@ public interface StaffGradeMapper { " "}) List queryStaffGrade(Integer staffProfessionalArchitectureId); +// @Update("UPDATE staff_grade SET isdel = 1 where staffGradeId = #{staffGradeId}") + @Update("UPDATE staff s,hr_user_info u SET s.isdel = 1,u.isdel = 1 WHERE s.userId = u.userId AND s.userId IN" + + "(" + + "#{userId}" + + ")") + void deleteStaffGrade(List userIds); + @Update("UPDATE staff_grade SET isdel = 1 where staffGradeId = #{staffGradeId}") - void deleteStaffGrade(Integer staffGradeId); + void deleteStaffGradePs(Integer staffGradeId); @Select({" "}) List queryStaffGrade(Integer staffProfessionalArchitectureId); - -// @Update("UPDATE staff_grade SET isdel = 1 where staffGradeId = #{staffGradeId}") - @Update("UPDATE staff s,hr_user_info u SET s.isdel = 1,u.isdel = 1 WHERE s.userId = u.userId AND s.userId IN" + - "(" + - "#{userId}" + - ")") - void deleteStaffGrade(List userIds); + + @Update({""}) + void deleteStaffGrade(@Param("userIds") List userIds); + @Update("UPDATE staff_grade SET isdel = 1 where staffGradeId = #{staffGradeId}") void deleteStaffGradePs(Integer staffGradeId); @@ -41,4 +41,10 @@ public interface StaffGradeMapper { @Select("select userId from staff where staffGradeId =#{staffGradeId} and isdel = 0") List queryUserIdsByGradeId(Integer staffGradeId); + + @Update("UPDATE staff_grade SET isdel = 1 where staffProfessionalArchitectureId = #{staffProfessionalArchitectureId}") + void delStaffGradeByArchId(Integer staffProfessionalArchitectureId); + + @Update("UPDATE staff_grade SET isdel = 1 where staffProfessionalArchitectureId = #{staffProfessionalArchitectureId}") + void deleteStaffArch(Integer staffProfessionalArchitectureId); } \ No newline at end of file diff --git a/src/main/java/com/yipin/liuwanr/mapper/StaffMapper.java b/src/main/java/com/yipin/liuwanr/mapper/StaffMapper.java index c282345..dc58cb2 100644 --- a/src/main/java/com/yipin/liuwanr/mapper/StaffMapper.java +++ b/src/main/java/com/yipin/liuwanr/mapper/StaffMapper.java @@ -123,4 +123,7 @@ public interface StaffMapper { @Select("select schoolId,staffId FROM staff WHERE userId = #{userId} AND isdel = 0 GROUP BY schoolId ORDER BY staffId limit 1") Integer querySchoolId(Integer userId); + @Select("select userId from staff where staffProfessionalArchitectureId =#{staffProfessionalArchitectureId} and isdel = 0") + List queryUserIdsByArchId(Integer staffProfessionalArchitectureId); + } \ No newline at end of file diff --git a/src/main/java/com/yipin/liuwanr/service/StaffProfessionalArchitectureService.java b/src/main/java/com/yipin/liuwanr/service/StaffProfessionalArchitectureService.java index 03a3914..893954a 100644 --- a/src/main/java/com/yipin/liuwanr/service/StaffProfessionalArchitectureService.java +++ b/src/main/java/com/yipin/liuwanr/service/StaffProfessionalArchitectureService.java @@ -1,7 +1,10 @@ package com.yipin.liuwanr.service; import java.util.HashMap; +import java.util.List; +import com.yipin.liuwanr.mapper.StaffGradeMapper; +import com.yipin.liuwanr.mapper.StaffMapper; import org.jboss.logging.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -17,6 +20,11 @@ public class StaffProfessionalArchitectureService { @Autowired private StaffProfessionalArchitectureMapper staffProfessionalArchitectureMapper; + @Autowired + private StaffGradeMapper staffGradeMapper; + @Autowired + private StaffMapper staffMapper; + public HashMap addStaffProfessionalArchitecture(StaffProfessionalArchitecture staffProfessionalArchitecture){ HashMap resp = new HashMap(); try { @@ -78,7 +86,19 @@ public class StaffProfessionalArchitectureService { public HashMap deleteStaffProfessionalArchitecture(Integer staffProfessionalArchitectureId){ HashMap resp = new HashMap(); try { + //删除员工专业一级组织架构 staffProfessionalArchitectureMapper.deleteStaffProfessionalArchitecture(staffProfessionalArchitectureId); + //根据一级架构id删除staff_grade表中二级组织架构(假删) + staffGradeMapper.delStaffGradeByArchId(staffProfessionalArchitectureId); + //根据staffProfessionalArchitectureId查询staff表中的userId,然后调用批量删除员工信息接口 + List userIds =staffMapper.queryUserIdsByArchId(staffProfessionalArchitectureId); + if(userIds.size()>0){//说明年级架构下面存在用户 + staffGradeMapper.deleteStaffGrade(userIds); + staffGradeMapper.deleteStaffArch(staffProfessionalArchitectureId); + }else{//如果组织架构下面没有员工,则只删除组织架构 + staffGradeMapper.deleteStaffArch(staffProfessionalArchitectureId); + } + resp.put("retcode", 200); } catch (RuntimeException e) { logger.error(e.getMessage()); From 6f5a7d21059486adac8ccde67ff181754f81e907 Mon Sep 17 00:00:00 2001 From: shijie <648688341@qq.com> Date: Wed, 26 May 2021 14:32:13 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E5=A4=84=E7=90=86=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=BB=A5=E5=8F=8A=E8=AE=A2=E5=8D=95=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/yipin/liuwanr/mapper/CourseMapper.java | 2 +- src/main/java/com/yipin/liuwanr/mapper/OrderMapper.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/yipin/liuwanr/mapper/CourseMapper.java b/src/main/java/com/yipin/liuwanr/mapper/CourseMapper.java index 994d92c..cac1643 100644 --- a/src/main/java/com/yipin/liuwanr/mapper/CourseMapper.java +++ b/src/main/java/com/yipin/liuwanr/mapper/CourseMapper.java @@ -94,7 +94,7 @@ public interface CourseMapper { //删除课程 @Update({" "}) diff --git a/src/main/java/com/yipin/liuwanr/mapper/OrderMapper.java b/src/main/java/com/yipin/liuwanr/mapper/OrderMapper.java index 6df3a52..b71ef3a 100644 --- a/src/main/java/com/yipin/liuwanr/mapper/OrderMapper.java +++ b/src/main/java/com/yipin/liuwanr/mapper/OrderMapper.java @@ -54,7 +54,7 @@ public interface OrderMapper { " and o.cityId = #{cityId} ", " and o.orderType = #{orderType} ", " and o.orderStatus = #{orderStatus} ", - " and o.orderNumber like CONCAT('%',#{searchContent},'%') or c.customerName like CONCAT('%',#{searchContent},'%')", + " and (o.orderNumber like CONCAT('%',#{searchContent},'%') or c.customerName like CONCAT('%',#{searchContent},'%'))", "order by o.orderDate desc", " "}) List queryOrder(Order order); From bf7ce4dd0b0bf6643db8c4e5b45a116dd9dbd389 Mon Sep 17 00:00:00 2001 From: chen <1251790704@qq.com> Date: Fri, 28 May 2021 15:10:39 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E7=A7=91=E5=A4=A7=E6=AD=A3=E5=BC=8F?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/application-keda.properties | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/main/resources/application-keda.properties diff --git a/src/main/resources/application-keda.properties b/src/main/resources/application-keda.properties new file mode 100644 index 0000000..441c064 --- /dev/null +++ b/src/main/resources/application-keda.properties @@ -0,0 +1,49 @@ +server.port=8090 +server.servlet.context-path=/liuwanr + +#\u79D1\u5927\u6B63\u5F0F\u6570\u636E\u5E93\u8FDE\u63A5 +spring.datasource.url=jdbc:mysql://192.168.0.99:3306/keda?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai +spring.datasource.username=root +spring.datasource.password=mssdk@028 +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver + +#redis\u914D\u7F6E +spring.redis.database=0 +spring.redis.host=127.0.0.1 +spring.redis.password= +spring.redis.port=6379 +spring.redis.timeout=3000 +spring.redis.jedis.pool.max-idle=500 +spring.redis.jedis.pool.min-idle=50 +spring.redis.jedis.pool.max-active=2000 +spring.redis.jedis.pool.max-wait=1000 + +#redis-cluster +redis.cluster.maxTotal=200 +redis.cluster.maxIdle=8 +redis.cluster.minIdle=3 +redis.cluster.nodes=192.168.136.191:8000,192.168.136.191:8001,192.168.136.191:8002 + +spring.mina.port=9123 +spring.mina.buffersize=2048 +spring.mina.idletime=15 +spring.main.show-banner=false + +#\u65E5\u5FD7\u7EA7\u522B +logging.level.jdbc=OFF +logging.level.jdbc.sqltiming=DEBUG +logging.level.jdbc.resultsettable=DEBUG +logging.level.com.yipin.liuwar.mapper=DEBUG +logging.level.com.yipin.liuwanr.mapper=DEBUG + +spring.elasticsearch.rest.uris=http://es-cn-v641e944a0006xtwy.elasticsearch.aliyuncs.com:9200 +spring.elasticsearch.rest.username=elastic +spring.elasticsearch.rest.password=1qaz@WSX + +# maxFileSize \u5355\u4E2A\u6570\u636E\u5927\u5C0F +spring.servlet.multipart.maxFileSize = 1024MB +# maxRequestSize \u662F\u603B\u6570\u636E\u5927\u5C0F +spring.servlet.multipart.maxRequestSize=10240MB + +pagehelper.reasonable=false + From b3cba9f9c7d5b141c0b96f2f988e38934de00f59 Mon Sep 17 00:00:00 2001 From: chen <1251790704@qq.com> Date: Fri, 28 May 2021 15:35:26 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E7=A7=91=E5=A4=A7redis=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-keda.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application-keda.properties b/src/main/resources/application-keda.properties index 441c064..fa02aba 100644 --- a/src/main/resources/application-keda.properties +++ b/src/main/resources/application-keda.properties @@ -10,7 +10,7 @@ spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver #redis\u914D\u7F6E spring.redis.database=0 spring.redis.host=127.0.0.1 -spring.redis.password= +spring.redis.password=msdw@2021 spring.redis.port=6379 spring.redis.timeout=3000 spring.redis.jedis.pool.max-idle=500 From a86beca6e2cb8179feffab8e9669c6fbd6890294 Mon Sep 17 00:00:00 2001 From: shijie <648688341@qq.com> Date: Fri, 28 May 2021 17:14:23 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E4=B8=AD=E5=8F=B0=E4=B8=AA=E4=BA=BA?= =?UTF-8?q?=E6=A1=A3=E6=A1=88=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/yipin/liuwanr/service/UserInfoService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/yipin/liuwanr/service/UserInfoService.java b/src/main/java/com/yipin/liuwanr/service/UserInfoService.java index fa1c87f..3a6c9c9 100644 --- a/src/main/java/com/yipin/liuwanr/service/UserInfoService.java +++ b/src/main/java/com/yipin/liuwanr/service/UserInfoService.java @@ -127,13 +127,13 @@ public class UserInfoService { userInfoMapper.userAddStudent(student); } int size = userProfilesList.size(); - if (size<=0){ +// if (size<=0){ for (int i = 0;i Date: Thu, 3 Jun 2021 17:24:55 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E4=B8=AD=E5=8F=B0=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8B=A6=E6=88=AA=E5=99=A8=EF=BC=8Ctoken?= =?UTF-8?q?=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 ++ .../com/yipin/liuwanr/config/AuthConfig.java | 29 ++++++++++ .../com/yipin/liuwanr/entity/UserInfo.java | 3 + .../yipin/liuwanr/filter/AuthInterceptor.java | 58 +++++++++++++++++++ .../liuwanr/service/UserInfoService.java | 13 +++++ 5 files changed, 109 insertions(+) create mode 100644 src/main/java/com/yipin/liuwanr/config/AuthConfig.java create mode 100644 src/main/java/com/yipin/liuwanr/filter/AuthInterceptor.java diff --git a/pom.xml b/pom.xml index 1b0714e..e5da5f8 100644 --- a/pom.xml +++ b/pom.xml @@ -271,6 +271,12 @@ 2.3.28 compile + + org.springframework.boot + spring-boot-devtools + runtime + true + root diff --git a/src/main/java/com/yipin/liuwanr/config/AuthConfig.java b/src/main/java/com/yipin/liuwanr/config/AuthConfig.java new file mode 100644 index 0000000..376825b --- /dev/null +++ b/src/main/java/com/yipin/liuwanr/config/AuthConfig.java @@ -0,0 +1,29 @@ +package com.yipin.liuwanr.config; + +/** + * @description + * @author: Mr.JK + * @create: 2021-06-03 16:24 + **/ + +import com.yipin.liuwanr.filter.AuthInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class AuthConfig implements WebMvcConfigurer { + + @Bean + public AuthInterceptor initAuthInterceptor(){ + return new AuthInterceptor(); + } + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(initAuthInterceptor()).addPathPatterns("/**") + .excludePathPatterns("/userInfo/adminLogins/**","/userInfo/loginSchoolClient/**","/userInfo/logins/**","/userInfo/updateLogInNumber/**"); + } + +} \ No newline at end of file diff --git a/src/main/java/com/yipin/liuwanr/entity/UserInfo.java b/src/main/java/com/yipin/liuwanr/entity/UserInfo.java index 6949a8c..b1c0922 100644 --- a/src/main/java/com/yipin/liuwanr/entity/UserInfo.java +++ b/src/main/java/com/yipin/liuwanr/entity/UserInfo.java @@ -101,4 +101,7 @@ public class UserInfo { private Integer organizationRelationshipId; //登陆时间 private String dataTime; + + //鉴权token + private String loginToken; } diff --git a/src/main/java/com/yipin/liuwanr/filter/AuthInterceptor.java b/src/main/java/com/yipin/liuwanr/filter/AuthInterceptor.java new file mode 100644 index 0000000..414a255 --- /dev/null +++ b/src/main/java/com/yipin/liuwanr/filter/AuthInterceptor.java @@ -0,0 +1,58 @@ +package com.yipin.liuwanr.filter; + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.data.redis.core.ValueOperations; +import org.springframework.util.StringUtils; +import org.springframework.web.servlet.HandlerInterceptor; +import org.springframework.web.servlet.ModelAndView; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.Objects; +import java.util.concurrent.TimeUnit; + +/** + * @description + * @author: Mr.JK + * @create: 2021-06-03 16:19 + **/ +public class AuthInterceptor implements HandlerInterceptor { + + @Resource + StringRedisTemplate stringRedisTemplate; + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + response.setCharacterEncoding("UTF-8"); + response.setContentType("text/html;charset=utf-8"); + String token = request.getHeader("token"); + if (StringUtils.isEmpty(token)) { + response.getWriter().print("0");//用户未登录,请登录后操作! + return false; + } + + ValueOperations ops = stringRedisTemplate.opsForValue(); + Object loginStatus = ops.get(token); + + + if( Objects.isNull(loginStatus)){ + response.getWriter().print("1");//token错误 + return false; + } + return true; + } + + @Override + public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { + + } + + @Override + public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { + + } + +} diff --git a/src/main/java/com/yipin/liuwanr/service/UserInfoService.java b/src/main/java/com/yipin/liuwanr/service/UserInfoService.java index fa1c87f..b8409b6 100644 --- a/src/main/java/com/yipin/liuwanr/service/UserInfoService.java +++ b/src/main/java/com/yipin/liuwanr/service/UserInfoService.java @@ -437,6 +437,13 @@ public class UserInfoService { // List studentList = userInfoMapper.loginsGetStudentSchoolInfo(userId,schoolId); List studentList = userInfoMapper.loginsGetStudentSchoolInfo(userId,schoolId); obj.put("studentList",studentList); + + //鉴权,登录后将信息存入redis + ValueOperations redis = stringRedisTemplate.opsForValue(); + String loginToken = UUID.randomUUID().toString(); + redis.set(loginToken,user.getUserName(),2, TimeUnit.HOURS); + obj.put("loginToken",loginToken); + resp.put("retcode", 200); resp.put("retvalue", obj); }else { @@ -543,6 +550,12 @@ public class UserInfoService { ValueOperations redis = stringRedisTemplate.opsForValue(); redis.set(token,lastLoginTime, 24, TimeUnit.HOURS); user.setDataTime(lastLoginTime); + + //鉴权,登录后将信息存入redis + String loginToken = UUID.randomUUID().toString(); + redis.set(loginToken,user.getUserName(),2, TimeUnit.HOURS); + user.setLoginToken(loginToken); + resp.put("retvalue",user); resp.put("retcode", 200); }