| | |
| | | package com.panzhihua.grid_app.api; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.panzhihua.common.controller.BaseController; |
| | | import com.panzhihua.common.model.vos.LoginReturnVO; |
| | | import com.panzhihua.common.model.vos.LoginReturnsVO; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.model.vos.community.ComMngStructAreaVO; |
| | | import com.panzhihua.common.service.auth.TokenService; |
| | | import com.panzhihua.common.service.user.UserService; |
| | | 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.beans.BeanUtils; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | | * @author cedoo |
| | |
| | | @Resource |
| | | private UserService userService; |
| | | |
| | | @ApiOperation(value = "网格综治APP登录",response = LoginReturnVO.class) |
| | | @ApiOperation(value = "网格综治APP登录", response = LoginReturnVO.class) |
| | | @PostMapping("login") |
| | | public R login(@RequestBody LoginBody loginBody){ |
| | | 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) { |
| | | if (empty || empty1) { |
| | | return R.fail("账户密码不能为空"); |
| | | } |
| | | R r = tokenService.loginGridApp(account, password); |
| | | if(R.isOk(r)){ |
| | | LoginReturnsVO returnsVO = JSONObject.parseObject(JSONObject.toJSONString(r.getData()), LoginReturnsVO.class); |
| | | //查询用户是否绑定网格,如果未绑定则提示用户 |
| | | if (R.isOk(r)) { |
| | | LoginReturnsVO returnsVO = |
| | | JSONObject.parseObject(JSONObject.toJSONString(r.getData()), LoginReturnsVO.class); |
| | | // 查询用户是否绑定网格,如果未绑定则提示用户 |
| | | R r1 = userService.getGridIsOk(returnsVO.getUserId()); |
| | | if(R.isOk(r1)){ |
| | | if (R.isOk(r1)) { |
| | | LoginReturnVO returnVO = new LoginReturnVO(); |
| | | BeanUtils.copyProperties(returnsVO,returnVO); |
| | | BeanUtils.copyProperties(returnsVO, returnVO); |
| | | r.setData(returnVO); |
| | | return r; |
| | | }else { |
| | | } else { |
| | | return R.fail("请联系管理员创建网格管理权限"); |
| | | } |
| | | } |
| | | return r; |
| | | } |
| | | |
| | | @ApiOperation(value = "刷新token",response =LoginReturnVO.class) |
| | | @ApiOperation(value = "刷新token", response = LoginReturnVO.class) |
| | | @GetMapping("refreshToken") |
| | | @ApiImplicitParam(name ="refreshToken",value = "登录返回的刷新token") |
| | | public R refreshToken(@RequestParam("refreshToken")String refreshToken){ |
| | | @ApiImplicitParam(name = "refreshToken", value = "登录返回的刷新token") |
| | | public R refreshToken(@RequestParam("refreshToken") String refreshToken) { |
| | | return tokenService.refreshToken(refreshToken); |
| | | } |
| | | |
| | | @ApiOperation(value = "用户登出") |
| | | @PostMapping("logout") |
| | | public R logout(){ |
| | | public R logout() { |
| | | String token = this.getToken(); |
| | | boolean empty2 = ObjectUtils.isEmpty(token); |
| | | if (empty2) { |
| | |
| | | } |
| | | return tokenService.logout(token); |
| | | } |
| | | |
| | | |
| | | } |