he2802 2 years ago
parent
commit
29c4e64373

+ 16 - 4
zhongzheng-api/src/main/java/com/zhongzheng/controller/distribution/SellerLoginController.java

@@ -1,7 +1,9 @@
 package com.zhongzheng.controller.distribution;
 
+import com.zhongzheng.common.constant.Constants;
 import com.zhongzheng.common.core.controller.BaseController;
 import com.zhongzheng.common.core.domain.AjaxResult;
+import com.zhongzheng.framework.web.service.SellerTokenService;
 import com.zhongzheng.modules.distribution.bo.SellerAppAccountLoginBo;
 import com.zhongzheng.modules.distribution.bo.SellerAppRegisterBo;
 import com.zhongzheng.modules.distribution.service.IDistributionSellerService;
@@ -11,11 +13,9 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
+import java.util.HashMap;
 import java.util.Map;
 
 /**
@@ -32,6 +32,8 @@ public class SellerLoginController extends BaseController {
 
     private final IDistributionSellerService iDistributionSellerService;
 
+    private final SellerTokenService sellerTokenService;
+
     /**
      * 用户注册
      */
@@ -60,4 +62,14 @@ public class SellerLoginController extends BaseController {
         Map<String,Object> map = iDistributionSellerService.accountLogin(bo);
         return AjaxResult.success(map);
     }
+
+    @ApiOperation("刷新业务员登录令牌")
+    @GetMapping("/refreshToken/{userAccount}")
+    public AjaxResult refreshToken(@PathVariable("userAccount") String userAccount)
+    {
+        String token = sellerTokenService.refreshSellerToken(userAccount);
+        Map<String,Object> map = new HashMap<>();
+        map.put(Constants.TOKEN, token);
+        return AjaxResult.success(map);
+    }
 }

+ 26 - 9
zhongzheng-framework/src/main/java/com/zhongzheng/framework/security/filter/JwtAuthenticationTokenFilter.java

@@ -7,7 +7,9 @@ import com.zhongzheng.common.core.domain.model.TopLoginUser;
 import com.zhongzheng.common.exception.CustomException;
 import com.zhongzheng.common.utils.ServletUtils;
 import com.zhongzheng.common.utils.ip.IpUtils;
+import com.zhongzheng.framework.web.service.SellerTokenService;
 import com.zhongzheng.framework.web.service.TopTokenService;
+import com.zhongzheng.modules.user.entity.ClientLoginSeller;
 import com.zhongzheng.modules.user.entity.ClientLoginUser;
 import com.zhongzheng.common.core.domain.model.LoginUser;
 import com.zhongzheng.common.utils.SecurityUtils;
@@ -45,6 +47,9 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter
     @Autowired
     private TopTokenService topTokenService;
 
+    @Autowired
+    private SellerTokenService sellerTokenService;
+
     @Value("${mybatis-plus.tenant.enabled-tenant:true}")
     private boolean enabledTenant;
 
@@ -54,7 +59,6 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter
     {
         try{
             String wxToken = wxTokenService.getToken(request);
-
             if(StringUtils.isNoneEmpty(wxToken)){
                 ClientLoginUser clientLoginUser = wxTokenService.getLoginUser(request);
                 if(clientLoginUser!=null){
@@ -75,18 +79,31 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter
                         SecurityContextHolder.getContext().setAuthentication(authenticationToken);
                     }
                 }else{
+                    String sellerToken = sellerTokenService.getToken(request);
+                    if(StringUtils.isNoneEmpty(sellerToken)){
+                        //业务员系统
+                        ClientLoginSeller clientLoginSeller = sellerTokenService.getLoginUser(request);
+                        if(clientLoginSeller!=null){
+                            sellerTokenService.verifyToken(clientLoginSeller);
+                            UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(clientLoginSeller, null,null);
+                            authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
+                            SecurityContextHolder.getContext().setAuthentication(authenticationToken);
+                        }
+                    }else{
                         //子系统
-                    LoginUser loginUser = null;
+                        LoginUser loginUser = null;
 
-                       loginUser = tokenService.getLoginUser(request);
+                        loginUser = tokenService.getLoginUser(request);
 
-                    if (Validator.isNotNull(loginUser) && Validator.isNull(SecurityUtils.getAuthentication()))
-                    {
-                        tokenService.verifyToken(loginUser);
-                        UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities());
-                        authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
-                        SecurityContextHolder.getContext().setAuthentication(authenticationToken);
+                        if (Validator.isNotNull(loginUser) && Validator.isNull(SecurityUtils.getAuthentication()))
+                        {
+                            tokenService.verifyToken(loginUser);
+                            UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities());
+                            authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
+                            SecurityContextHolder.getContext().setAuthentication(authenticationToken);
+                        }
                     }
+
                 }
 
             }

+ 14 - 0
zhongzheng-framework/src/main/java/com/zhongzheng/framework/web/service/SellerTokenService.java

@@ -7,6 +7,8 @@ import cn.hutool.http.useragent.UserAgentUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.zhongzheng.common.constant.Constants;
 import com.zhongzheng.common.core.redis.RedisCache;
+import com.zhongzheng.common.exception.CustomException;
+import com.zhongzheng.common.utils.DateUtils;
 import com.zhongzheng.common.utils.ServletUtils;
 import com.zhongzheng.common.utils.ip.AddressUtils;
 import com.zhongzheng.common.utils.ip.IpUtils;
@@ -250,4 +252,16 @@ public class SellerTokenService
     {
         return Constants.SELLER_LOGIN_TOKEN_KEY + uuid;
     }
+
+
+    public String refreshSellerToken(String userAccount) {
+        DistributionSeller seller = iDistributionSellerService.getOne(new LambdaQueryWrapper<DistributionSeller>().eq(DistributionSeller::getUserAccount, userAccount));
+        if (seller == null) {
+            throw new CustomException("userAccount不存在");
+        }
+
+        ClientLoginSeller loginUser = new ClientLoginSeller();
+        loginUser.setSeller(seller);
+        return createToken(loginUser);
+    }
 }

+ 6 - 6
zhongzheng-system/src/main/java/com/zhongzheng/modules/distribution/bo/DistributionSellerEditBo.java

@@ -47,12 +47,12 @@ public class DistributionSellerEditBo {
     private String avatar;
 
     /** 关联用户ID */
-    @ApiModelProperty("关联用户ID")
+   /* @ApiModelProperty("关联用户ID")
     private Long userId;
 
-    /** 业务员编号 */
+    *//** 业务员编号 *//*
     @ApiModelProperty("业务员编号")
-    private String userAccount;
+    private String userAccount;*/
 
     /** 公众号openid */
     @ApiModelProperty("公众号openid")
@@ -66,9 +66,9 @@ public class DistributionSellerEditBo {
     @ApiModelProperty("密码")
     private String password;
     /** 父ID */
-    @ApiModelProperty("父ID")
+   /* @ApiModelProperty("父ID")
     private Long parentId;
-    /** 分享码 */
+    *//** 分享码 *//*
     @ApiModelProperty("分享码")
-    private String shareCode;
+    private String shareCode;*/
 }

+ 1 - 1
zhongzheng-system/src/main/java/com/zhongzheng/modules/distribution/domain/DistributionSeller.java

@@ -19,7 +19,7 @@ import com.zhongzheng.common.annotation.Excel;
 @Data
 @NoArgsConstructor
 @Accessors(chain = true)
-@TableName("distribution_seller")
+@TableName(value ="distribution_seller",autoResultMap = true)
 public class DistributionSeller implements Serializable {
 
 private static final long serialVersionUID=1L;