jiangping
2025-01-06 7c5484cc1169aa6ef55c77c70f136a781469a7c3
server/system_gateway/src/main/java/com/doumee/api/gateway/JwtAuthController.java
@@ -6,15 +6,16 @@
import com.doumee.core.annotation.pr.PreventRepeat;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.ApiResponse;
import com.doumee.core.model.LoginUserInfo;
import com.doumee.dao.system.dto.LoginH5DTO;
import com.doumee.service.business.third.model.ApiResponse;
import com.doumee.service.business.third.model.LoginUserInfo;
import com.doumee.core.utils.Constants;
import com.doumee.dao.system.dto.LoginDTO;
import com.doumee.dao.system.dto.LoginPhoneDTO;
import com.doumee.service.common.CaptchaService;
import com.doumee.service.system.SystemLoginService;
import com.doumee.service.system.SystemUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.server.reactive.ServerHttpRequest;
@@ -60,6 +61,7 @@
    public ApiResponse<String> login (@Validated @RequestBody LoginDTO dto, ServerWebExchange serverWebExchange) {
        try {
            ServerHttpRequest request = serverWebExchange.getRequest();
            dto.setCheckCode(true);
            LoginUserInfo user = systemLoginService.loginByPasswordNew(dto,request);
            String token = jwtTokenUtil.generateToken(user);
            return ApiResponse.success(token);
@@ -71,6 +73,150 @@
        }
    }
    @PreventRepeat(limit = 10, lockTime = 10000)
    @ApiOperation("短信验证码登录")
    @PostMapping("/loginByPhone")
    @LoginNoRequired
    public ApiResponse<String> loginByPhone (@Validated @RequestBody LoginPhoneDTO dto, ServerWebExchange serverWebExchange) {
        try {
            ServerHttpRequest request = serverWebExchange.getRequest();
            LoginUserInfo user = systemLoginService.loginByPhone(dto,request);
            String token = jwtTokenUtil.generateToken(user);
            return ApiResponse.success(token);
        }catch (BusinessException e){
            return ApiResponse.failed(e.getCode(),e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return ApiResponse.failed(ResponseStatus.SERVER_ERROR);
        }
    }
    @PreventRepeat(limit = 10, lockTime = 10000)
    @ApiOperation("H5业务登录")
    @PostMapping("/loginH5")
    @LoginNoRequired
    public ApiResponse<String> loginH5 (@Validated @RequestBody LoginH5DTO dto, ServerWebExchange serverWebExchange) {
        try {
            ServerHttpRequest request = serverWebExchange.getRequest();
            dto.setCheckCode(false);
            LoginUserInfo user =  systemLoginService.loginH5(dto,request);
            String token = jwtTokenUtil.generateToken(user);
            return ApiResponse.success(token);
        }catch (BusinessException e){
            return ApiResponse.failed(e.getCode(),e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return ApiResponse.failed(ResponseStatus.SERVER_ERROR);
        }
    }
    @PreventRepeat(limit = 10, lockTime = 10000)
    @ApiOperation("H5业务登录(手机号验证码登录)")
    @PostMapping("/loginH5ByPhone")
    @LoginNoRequired
    public ApiResponse<String> loginH5ByPhone (@Validated @RequestBody LoginPhoneDTO dto, ServerWebExchange serverWebExchange) {
        try {
            ServerHttpRequest request = serverWebExchange.getRequest();
            LoginUserInfo user =  systemLoginService.loginH5ByPhone(dto,request);
            String token = jwtTokenUtil.generateToken(user);
            return ApiResponse.success(token);
        }catch (BusinessException e){
            return ApiResponse.failed(e.getCode(),e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return ApiResponse.failed(ResponseStatus.SERVER_ERROR);
        }
    }
    @PreventRepeat(limit = 10, lockTime = 10000)
    @ApiOperation("PDA业务登录")
    @PostMapping("/loginPDA")
    @LoginNoRequired
    public ApiResponse<String> loginPDA (@Validated @RequestBody LoginDTO dto, ServerWebExchange serverWebExchange) {
        try {
            ServerHttpRequest request = serverWebExchange.getRequest();
            dto.setCheckCode(false);
            LoginUserInfo user = systemLoginService.loginByPasswordForPda(dto,request);
            String token = jwtTokenUtil.generateToken(user);
            return ApiResponse.success(token);
        }catch (BusinessException e){
            return ApiResponse.failed(e.getCode(),e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return ApiResponse.failed(ResponseStatus.SERVER_ERROR);
        }
    }
    @PreventRepeat(limit = 10, lockTime = 10000)
    @ApiOperation("司机登录(手机号验证码登录)")
    @PostMapping("/loginDriverByPhone")
    @LoginNoRequired
    public ApiResponse<String> loginDriverByPhone (@Validated @RequestBody LoginPhoneDTO dto, ServerWebExchange serverWebExchange) {
        try {
            ServerHttpRequest request = serverWebExchange.getRequest();
            LoginUserInfo user = systemLoginService.loginDriverByPhone(dto,request);
            String token = jwtTokenUtil.generateToken(user);
            return ApiResponse.success(token);
        }catch (BusinessException e){
            return ApiResponse.failed(e.getCode(),e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return ApiResponse.failed(ResponseStatus.SERVER_ERROR);
        }
    }
    @PreventRepeat(limit = 10, lockTime = 10000)
    @ApiOperation("司机登录")
    @PostMapping("/loginDriver")
    @LoginNoRequired
    public ApiResponse<String> loginDriver (@Validated @RequestBody LoginH5DTO dto, ServerWebExchange serverWebExchange) {
        try {
            ServerHttpRequest request = serverWebExchange.getRequest();
            dto.setCheckCode(false);
            LoginUserInfo user = systemLoginService.driverLogin(dto,request);
            String token = jwtTokenUtil.generateToken(user);
            return ApiResponse.success(token);
        }catch (BusinessException e){
            return ApiResponse.failed(e.getCode(),e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return ApiResponse.failed(ResponseStatus.SERVER_ERROR);
        }
    }
    @ApiOperation("司机验证码登录")
    @PostMapping("/loginDriverWithCode")
    @LoginNoRequired
    public ApiResponse<String> loginDriverWithCode (@Validated @RequestBody LoginPhoneDTO dto, ServerWebExchange serverWebExchange) {
        try {
            ServerHttpRequest request = serverWebExchange.getRequest();
            LoginUserInfo user = systemLoginService.loginDriverWithCode(dto,request);
            String token = jwtTokenUtil.generateToken(user);
            return ApiResponse.success(token);
        }catch (BusinessException e){
            return ApiResponse.failed(e.getCode(),e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return ApiResponse.failed(ResponseStatus.SERVER_ERROR);
        }
    }
    @ApiOperation("管控人员验证码登录")
    @PostMapping("/loginGkUserWithCode")
    @LoginNoRequired
    public ApiResponse<String> loginGkUserWithCode (@Validated @RequestBody LoginPhoneDTO dto, ServerWebExchange serverWebExchange) {
        try {
            ServerHttpRequest request = serverWebExchange.getRequest();
            LoginUserInfo user = systemLoginService.loginGkUserWithCode(dto,request);
            String token = jwtTokenUtil.generateToken(user);
            return ApiResponse.success(token);
        }catch (BusinessException e){
            return ApiResponse.failed(e.getCode(),e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return ApiResponse.failed(ResponseStatus.SERVER_ERROR);
        }
    }
    /**
     * 刷新JWT令牌,用旧的令牌换新的令牌
@@ -88,7 +234,6 @@
        }catch (Exception e){
            return ApiResponse.failed(ResponseStatus.SERVER_ERROR);
        }
    }
    /**
     * 刷新JWT令牌,用旧的令牌换新的令牌
@@ -97,7 +242,8 @@
    @ApiOperation("退出登陆")
    public ApiResponse<String> logout(@RequestHeader(Constants.HEADER_USER_TOKEN) String oldToken){
        try {
             jwtTokenUtil.logout(oldToken);
                jwtTokenUtil.logout(oldToken);
        }catch (BusinessException e){
            return ApiResponse.failed(e.getCode(),e.getMessage());
        }catch (Exception e){
@@ -107,6 +253,22 @@
    }
    @PostMapping("/logoutForH5")
    @ApiOperation("退出登陆")
    public ApiResponse<String> logoutForH5(@RequestHeader(Constants.HEADER_USER_TOKEN) String oldToken){
        try {
            jwtTokenUtil.logoutForH5(oldToken);
        }catch (BusinessException e){
            return ApiResponse.failed(e.getCode(),e.getMessage());
        }catch (Exception e){
            return ApiResponse.failed(ResponseStatus.SERVER_ERROR);
        }
        return ApiResponse.success(null);
    }
    /**
     * 刷新JWT令牌,用旧的令牌换新的令牌
     */