package com.panzhihua.grid_app.api;
|
|
import com.panzhihua.common.controller.BaseController;
|
import com.panzhihua.common.model.vos.LoginReturnVO;
|
import com.panzhihua.common.model.vos.R;
|
import com.panzhihua.common.service.auth.TokenService;
|
import com.panzhihua.grid_app.model.vos.LoginBody;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.util.ObjectUtils;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.annotation.Resource;
|
|
/**
|
* @author cedoo
|
*/
|
@RestController
|
@RequestMapping("/")
|
@Api(tags = {"网格综治APP登录模块"})
|
public class LoginApi extends BaseController {
|
@Resource
|
private TokenService tokenService;
|
|
@ApiOperation(value = "网格综治APP登录",response = LoginReturnVO.class)
|
@PostMapping("login")
|
public R login(@RequestBody LoginBody loginBody){
|
String account = loginBody.getAccount();
|
String password = loginBody.getPassword();
|
boolean empty = ObjectUtils.isEmpty(account);
|
boolean empty1 = ObjectUtils.isEmpty(password);
|
if (empty||empty1) {
|
return R.fail("账户密码不能为空");
|
}
|
R r = tokenService.loginGridApp(account, password);
|
return r;
|
}
|
|
@ApiOperation(value = "刷新token",response =LoginReturnVO.class)
|
@GetMapping("refreshToken")
|
@ApiImplicitParam(name ="refreshToken",value = "登录返回的刷新token")
|
public R refreshToken(@RequestParam("refreshToken")String refreshToken){
|
return tokenService.refreshToken(refreshToken);
|
}
|
|
@ApiOperation(value = "用户登出")
|
@PostMapping("logout")
|
public R logout(){
|
String token = this.getToken();
|
boolean empty2 = ObjectUtils.isEmpty(token);
|
if (empty2) {
|
return R.ok();
|
}
|
return tokenService.logout(token);
|
}
|
|
|
}
|