فهرست منبع

根据场景码,获取用户token

lyhzzz 2 سال پیش
والد
کامیت
3a817f50c8

+ 39 - 4
src/main/java/com/fdkankan/ucenter/controller/fire/FdUserSceneController.java

@@ -4,18 +4,22 @@ import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.common.util.JwtUtil;
 import com.fdkankan.ucenter.common.BaseController;
 import com.fdkankan.ucenter.common.Result;
+import com.fdkankan.ucenter.common.ResultData;
+import com.fdkankan.ucenter.constant.LoginConstant;
+import com.fdkankan.ucenter.entity.ScenePlus;
+import com.fdkankan.ucenter.entity.ScenePro;
+import com.fdkankan.ucenter.entity.User;
+import com.fdkankan.ucenter.service.IScenePlusService;
 import com.fdkankan.ucenter.service.ISceneProService;
 import com.fdkankan.ucenter.service.ISceneService;
 import com.fdkankan.ucenter.service.IUserService;
+import com.fdkankan.ucenter.service.impl.LoginService;
 import com.fdkankan.ucenter.vo.ResponseScene;
 import lombok.extern.log4j.Log4j2;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.StringUtils;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -28,6 +32,12 @@ public class FdUserSceneController extends BaseController {
 
     @Autowired
     private ISceneProService sceneProService;
+    @Autowired
+    private IScenePlusService scenePlusService;
+    @Autowired
+    private LoginService loginService;
+    @Autowired
+    private IUserService userService;
 
     /**
      * 获取场景详情
@@ -48,4 +58,29 @@ public class FdUserSceneController extends BaseController {
         log.info("火调返回数据:{}",sceneDetailList);
         return Result.success(sceneDetailList);
     }
+
+    @GetMapping("/getTokenByNum")
+    public ResultData getTokenByNum(@RequestParam(required = false) String num ){
+        if(StringUtils.isEmpty(num)){
+            throw new BusinessException(-1,"参数为空");
+        }
+        Long userId = null;
+        ScenePlus scenePlus = scenePlusService.getByNum(num);
+        if(scenePlus != null){
+            userId = scenePlus.getUserId();
+        }else {
+            ScenePro scenePro = sceneProService.getByNum(num);
+            if(scenePro != null){
+                userId = scenePro.getUserId();
+            }
+        }
+        if(userId == null){
+            throw new BusinessException(-1,"场景为空");
+        }
+        User user = userService.getById(userId);
+        if(user == null){
+            throw new BusinessException(LoginConstant.FAILURE_CODE_3015, LoginConstant.FAILURE_MSG_3015);
+        }
+        return ResultData.ok(loginService.login(user));
+    }
 }

+ 12 - 8
src/main/java/com/fdkankan/ucenter/service/impl/LoginService.java

@@ -65,6 +65,17 @@ public class LoginService {
     private IMailTemplateService mailTemplateService;
 
 
+    public LoginVo login(User user){
+        String token = this.redisLogin(user.getUserName(),JSONObject.toJSONString(user),"user");
+        loginLogService.addLog("",token);
+        UserVo userVo = new UserVo();
+        BeanUtils.copyProperties(user,userVo);
+        LoginVo vo = new LoginVo();
+        vo.setToken(token);
+        vo.setUser(userVo);
+        return vo;
+    }
+
     public LoginVo login(LoginParam param) {
         if (StringUtils.isEmpty(param.getPassword()) || StringUtils.isEmpty(param.getPhoneNum())){
             throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
@@ -83,14 +94,7 @@ public class LoginService {
         if(!user.getPassword().equals(passwordCode)){
             throw new BusinessException(LoginConstant.FAILURE_CODE_3014, LoginConstant.FAILURE_MSG_3014);
         }
-        String token = this.redisLogin(user.getUserName(),JSONObject.toJSONString(user),"user");
-        loginLogService.addLog("",token);
-        UserVo userVo = new UserVo();
-        BeanUtils.copyProperties(user,userVo);
-        LoginVo vo = new LoginVo();
-        vo.setToken(token);
-        vo.setUser(userVo);
-        return vo;
+        return login(user);
     }
 
     public void logout(String token) {