From 2acc40db4dd14c3d27ea1645f2b5833969e5c1cb Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期一, 20 四月 2026 19:56:33 +0800
Subject: [PATCH] 代码生成

---
 server/services/src/main/java/com/doumee/config/jwt/WebMvcConfig.java |  143 ++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 134 insertions(+), 9 deletions(-)

diff --git a/server/services/src/main/java/com/doumee/config/jwt/WebMvcConfig.java b/server/services/src/main/java/com/doumee/config/jwt/WebMvcConfig.java
index a52062a..3c85107 100644
--- a/server/services/src/main/java/com/doumee/config/jwt/WebMvcConfig.java
+++ b/server/services/src/main/java/com/doumee/config/jwt/WebMvcConfig.java
@@ -1,16 +1,20 @@
 package com.doumee.config.jwt;
 
 import com.alibaba.fastjson.JSONObject;
+import com.doumee.core.annotation.LoginDriverRequired;
 import com.doumee.core.annotation.LoginRequired;
+import com.doumee.core.annotation.LoginShopRequired;
 import com.doumee.core.constants.Constants;
 import com.doumee.core.constants.ResponseStatus;
 import com.doumee.core.exception.BusinessException;
 import com.doumee.dao.business.model.Member;
+import com.doumee.dao.business.model.ShopInfo;
 import io.jsonwebtoken.JwtException;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.web.client.RestTemplate;
 import org.springframework.web.method.HandlerMethod;
@@ -30,8 +34,9 @@
     @Autowired
     private JdbcTemplate dao;
 
-    @Resource
-    private JwtTokenUtil jwtTokenUtil;
+    @Autowired
+    private RedisTemplate<String,Object> redisTemplate;
+
 
     /**
      * 娣诲姞鎷︽埅鍣�
@@ -55,7 +60,7 @@
                     //鑾峰彇token
                     String token = request.getHeader(JwtTokenUtil.HEADER_KEY);  // 浠� http 璇锋眰澶翠腑鍙栧嚭 token
                     if (StringUtils.isNotBlank(token)) {
-                        checkLogin(request,response);
+                        checkMemberLogin(request,response);
                     } else {
                         throw new BusinessException(ResponseStatus.BE_OVERDUE.getCode(),"鏈櫥褰�");
                     }
@@ -63,7 +68,39 @@
                     //鑾峰彇token
                     String token = request.getHeader(JwtTokenUtil.HEADER_KEY);  // 浠� http 璇锋眰澶翠腑鍙栧嚭 token
                     if (StringUtils.isNotBlank(token)) {
-                        checkLogin(request,response);
+                        checkMemberLogin(request,response);
+                    } else {
+                        throw new BusinessException(ResponseStatus.BE_OVERDUE.getCode(),"鏈櫥褰�");
+                    }
+                }else if (beanType.isAnnotationPresent(LoginShopRequired.class)) {
+                    //鑾峰彇token
+                    String token = request.getHeader(JwtTokenUtil.HEADER_KEY);  // 浠� http 璇锋眰澶翠腑鍙栧嚭 token
+                    if (StringUtils.isNotBlank(token)) {
+                        checkShopLogin(request,response);
+                    } else {
+                        throw new BusinessException(ResponseStatus.BE_OVERDUE.getCode(),"鏈櫥褰�");
+                    }
+                }else if (handlerMethod.hasMethodAnnotation(LoginShopRequired.class)){
+                    //鑾峰彇token
+                    String token = request.getHeader(JwtTokenUtil.HEADER_KEY);  // 浠� http 璇锋眰澶翠腑鍙栧嚭 token
+                    if (StringUtils.isNotBlank(token)) {
+                        checkShopLogin(request,response);
+                    } else {
+                        throw new BusinessException(ResponseStatus.BE_OVERDUE.getCode(),"鏈櫥褰�");
+                    }
+                }else if (beanType.isAnnotationPresent(LoginDriverRequired.class)) {
+                    //鑾峰彇token
+                    String token = request.getHeader(JwtTokenUtil.HEADER_KEY);  // 浠� http 璇锋眰澶翠腑鍙栧嚭 token
+                    if (StringUtils.isNotBlank(token)) {
+                        checkDriverLogin(request,response);
+                    } else {
+                        throw new BusinessException(ResponseStatus.BE_OVERDUE.getCode(),"鏈櫥褰�");
+                    }
+                }else if (handlerMethod.hasMethodAnnotation(LoginDriverRequired.class)){
+                    //鑾峰彇token
+                    String token = request.getHeader(JwtTokenUtil.HEADER_KEY);  // 浠� http 璇锋眰澶翠腑鍙栧嚭 token
+                    if (StringUtils.isNotBlank(token)) {
+                        checkDriverLogin(request,response);
                     } else {
                         throw new BusinessException(ResponseStatus.BE_OVERDUE.getCode(),"鏈櫥褰�");
                     }
@@ -76,12 +113,19 @@
 
 
 
-    public Boolean checkLogin(HttpServletRequest request, HttpServletResponse response){
+    public Boolean checkMemberLogin(HttpServletRequest request, HttpServletResponse response){
         String token = request.getHeader(JwtTokenUtil.HEADER_KEY);
         try {
-            Member member  = jwtTokenUtil.getUserInfoByToken(token);
+            if(!token.startsWith(Constants.ZERO+"")){
+                throw new BusinessException(ResponseStatus.TOKEN_EXCEED_TIME);
+            }
+            String tokenRedis = (String) redisTemplate.opsForValue().get(Constants.REDIS_TOKEN_KEY+token);
+            if(StringUtils.isBlank(tokenRedis)){
+                throw new BusinessException(ResponseStatus.BE_OVERDUE);
+            }
+            Member member = JSONObject.parseObject(tokenRedis, Member.class);
             if(Objects.isNull(member)){
-                throw new BusinessException(ResponseStatus.TOKEN_EXCEED_TIME.getCode(),"闀挎椂闂存湭鎿嶄綔,璇烽噸鏂扮櫥褰�");
+                throw new BusinessException(ResponseStatus.TOKEN_EXCEED_TIME);
             }
             Integer isDeleted = dao.queryForObject(" select COALESCE(DELETED,1)  from member where id  = ?", Integer.class, member.getId());
             if(isDeleted.equals(Constants.ONE)){
@@ -89,8 +133,6 @@
             }
             Integer count = dao.queryForObject("select count(1) from member where id  = ?", Integer.class, member.getId());
             if (count != null && count > 0) {
-//                jwtTokenUtil.refreshToken(token,member);
-                request.setAttribute(JwtTokenUtil.MEMBER_INFO, JSONObject.toJSONString(member));
                 request.setAttribute(JwtTokenUtil.MEMBER_ID, member.getId());
                 return true;
             }else{
@@ -101,6 +143,89 @@
         }
     }
 
+
+    public Boolean checkShopLogin(HttpServletRequest request, HttpServletResponse response){
+        String token = request.getHeader(JwtTokenUtil.HEADER_KEY);
+        try {
+            if(!token.startsWith(Constants.TWO+"")){
+                throw new BusinessException(ResponseStatus.TOKEN_EXCEED_TIME);
+            }
+            String tokenRedis = (String) redisTemplate.opsForValue().get(Constants.REDIS_TOKEN_KEY+token);
+            if(StringUtils.isBlank(tokenRedis)){
+                throw new BusinessException(ResponseStatus.BE_OVERDUE);
+            }
+            ShopInfo shop = JSONObject.parseObject(tokenRedis, ShopInfo.class);
+            if(Objects.isNull(shop)){
+                throw new BusinessException(ResponseStatus.BE_OVERDUE);
+            }
+            String openid = shop.getOpenid();
+            Integer shopId = getTokenId(token);
+            Integer isDeleted = dao.queryForObject(" select COALESCE(ISDELETED,0)  from shop_info where id  = ?", Integer.class, shopId);
+            if(isDeleted== Constants.ONE){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鍟嗘埛宸插垹闄�,璇疯仈绯荤鐞嗗憳");
+            }
+            Integer isForbidden = dao.queryForObject(" select COALESCE(STATUS,0)  from shop_info where id  = ?", Integer.class, shopId);
+            if(isForbidden == Constants.ONE){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鍟嗘埛宸茬鐢�,璇疯仈绯荤鐞嗗憳");
+            }
+            String dbOpenid = dao.queryForObject(" select ifnull(openid,'')  from shop where id  = ?", String.class, shopId);
+            if(StringUtils.isBlank(dbOpenid)||!openid.equals(dbOpenid)){
+                throw new BusinessException(ResponseStatus.TOKEN_EXCEED_TIME);
+            }
+            Integer count = dao.queryForObject("select count(1) from shop where id  = ?", Integer.class, shopId);
+            if (count != null && count > 0) {
+                request.setAttribute(JwtTokenUtil.SHOP_ID, shop.getId());
+                return true;
+            }else{
+                throw new BusinessException(ResponseStatus.BE_OVERDUE.getCode(),"鐢ㄦ埛淇℃伅鍑洪敊");
+            }
+        } catch (IllegalArgumentException | JwtException e) {
+            throw new BusinessException(ResponseStatus.BE_OVERDUE);
+        }
+    }
+
+    public Boolean checkDriverLogin(HttpServletRequest request, HttpServletResponse response){
+        String token = request.getHeader(JwtTokenUtil.HEADER_KEY);
+        try {
+            if(!token.startsWith(Constants.ONE+"")){
+                throw new BusinessException(ResponseStatus.TOKEN_EXCEED_TIME);
+            }
+            String tokenRedis = (String) redisTemplate.opsForValue().get(Constants.REDIS_TOKEN_KEY+token);
+            if(StringUtils.isBlank(tokenRedis)){
+                throw new BusinessException(ResponseStatus.BE_OVERDUE);
+            }
+            Integer memberId = getTokenId(token);
+            Integer isDeleted = dao.queryForObject(" select COALESCE(DELETED,1)  from member where user_type = 1 and   id  = ?", Integer.class, memberId);
+            if(isDeleted== Constants.ONE){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鍙告満淇℃伅宸插垹闄�,璇疯仈绯荤鐞嗗憳");
+            }
+            Integer isForbidden = dao.queryForObject(" select COALESCE(STATUS,0)  from member where user_type = 1 and  id  = ?", Integer.class, memberId);
+            if(isForbidden == Constants.ONE){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鍙告満淇℃伅宸茬鐢�,璇疯仈绯荤鐞嗗憳");
+            }
+            Integer count = dao.queryForObject("select count(1) from member where  user_type = 1  and id  = ?", Integer.class, memberId);
+            if (count != null && count > 0) {
+                request.setAttribute(JwtTokenUtil.DRIVER_ID, memberId);
+                return true;
+            }else{
+                throw new BusinessException(ResponseStatus.BE_OVERDUE.getCode(),"鍙告満淇℃伅鍑洪敊");
+            }
+        } catch (IllegalArgumentException | JwtException e) {
+            throw new BusinessException(ResponseStatus.BE_OVERDUE);
+        }
+    }
+
+
+    public Integer getTokenId(String token){
+        try {
+            Integer lastIndex = token.lastIndexOf("_")+1;
+            Integer tokenId = Integer.valueOf(token.substring(lastIndex));
+            return tokenId;
+        }catch (Exception e){
+            throw new BusinessException(ResponseStatus.BE_OVERDUE);
+        }
+    }
+
     @Bean
     public RestTemplate getRestTemplate(){
         return new RestTemplate();

--
Gitblit v1.9.3