1.fix swagger version issue

main
hechanggeng 1 year ago
parent 10c196326d
commit 878b6f1dc5

@ -65,7 +65,7 @@
<dependency> <dependency>
<groupId>io.springfox</groupId> <groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId> <artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version> <version>2.8.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.xiaoymin</groupId> <groupId>com.github.xiaoymin</groupId>

@ -16,10 +16,14 @@ import org.springframework.web.bind.annotation.RestController;
import com.luoo.user.pojo.User; import com.luoo.user.pojo.User;
import com.luoo.user.service.UserService; import com.luoo.user.service.UserService;
import com.luoo.user.vo.UserVO;
import entity.PageResult; import entity.PageResult;
import entity.Result; import entity.Result;
import entity.ResultVO;
import entity.StatusCode; import entity.StatusCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import util.IdWorker; import util.IdWorker;
import util.JwtUtil; import util.JwtUtil;
@ -31,6 +35,7 @@ import util.JwtUtil;
@RestController @RestController
@CrossOrigin @CrossOrigin
@RequestMapping("/user") @RequestMapping("/user")
@Api(tags="UserController")
public class UserController { public class UserController {
@Autowired @Autowired
@ -73,37 +78,30 @@ public class UserController {
return new Result(true,StatusCode.OK,"登录成功",map); return new Result(true,StatusCode.OK,"登录成功",map);
} }
@ApiOperation(value="2.登录/注册后返回token")
@RequestMapping(value = "/appLogin/{mobile}/{checkcode}",method = RequestMethod.POST) @RequestMapping(value = "/appLogin/{mobile}/{checkcode}",method = RequestMethod.POST)
public Result appLogin(@PathVariable String mobile,@PathVariable String checkcode){ public ResultVO appLogin(@PathVariable String mobile,@PathVariable String checkcode){
// 得到缓存中的验证码 // 得到缓存中的验证码
String checkcodeRedis = (String)redisTemplate.opsForValue().get("checkcode_"+mobile); String checkcodeRedis = (String)redisTemplate.opsForValue().get("checkcode_"+mobile);
if (checkcodeRedis.isEmpty()){ if (checkcodeRedis.isEmpty()){
return new Result(false,StatusCode.ERROR,"请先获取手机验证码"); return new ResultVO(false,StatusCode.ERROR,"请先获取手机验证码");
} }
if (!checkcodeRedis.equals(checkcode)) { if (!checkcodeRedis.equals(checkcode)) {
return new Result(false,StatusCode.ERROR,"请输入正确的验证码"); return new ResultVO(false,StatusCode.ERROR,"请输入正确的验证码");
} }
UserVO userVO=userService.loginOrRegister(mobile);
User user = userService.findByMobile(mobile); return ResultVO.success(userVO);
// 如果数据库中有这个手机号,登录通道,
if (user != null){
String token = jwtUtil.createJWT(user.getId(),user.getMobile(),"user");
} }
// 如果数据库中没有这个手机号,为新用户,注册添加用户
return new Result(true,StatusCode.OK,"登录成功");}
/** /**
* *
*/ */
@ApiOperation(value="1.发送短信验证码")
@RequestMapping(value = "/sendsms/{mobile}",method = RequestMethod.POST) @RequestMapping(value = "/sendsms/{mobile}",method = RequestMethod.POST)
public Result sendSms(@PathVariable String mobile) { public ResultVO<Void> sendSms(@PathVariable String mobile) {
userService.sendSms(mobile); userService.sendSms(mobile);
return new Result(true,StatusCode.OK,"发送成功"); return ResultVO.success("发送成功");
} }
@RequestMapping(value = "/register/{code}",method = RequestMethod.POST) @RequestMapping(value = "/register/{code}",method = RequestMethod.POST)

@ -17,6 +17,7 @@ import io.jsonwebtoken.Claims;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate; import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
@ -29,8 +30,11 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import util.IdWorker; import util.IdWorker;
import com.apifan.common.random.RandomSource;
import com.luoo.user.dao.UserDao; import com.luoo.user.dao.UserDao;
import com.luoo.user.pojo.User; import com.luoo.user.pojo.User;
import com.luoo.user.vo.UserVO;
import util.JwtUtil; import util.JwtUtil;
/** /**
@ -249,7 +253,23 @@ public class UserService {
userDao.updatefanscount(x,friendid); userDao.updatefanscount(x,friendid);
userDao.updatefollowcount(x,userid); userDao.updatefollowcount(x,userid);
} }
public UserVO loginOrRegister(String mobile) {
User user = userDao.findByMobile(mobile);
if(null==user) {
user=new User();
user.setId(String.valueOf(idWorker.nextId()));
user.setMobile(mobile);
user.setNickname(RandomSource.personInfoSource().randomChineseNickName(8));
user.setAvatar("default");
userDao.save(user);
}
UserVO userVO=new UserVO();
BeanUtils.copyProperties(user, userVO);
String token = jwtUtil.createJWT(user.getId(),user.getMobile(),"user");
userVO.setToken(token);
return userVO;
}
public User findByMobile(String mobile) { public User findByMobile(String mobile) {
User user = userDao.findByMobile(mobile); User user = userDao.findByMobile(mobile);
return user; return user;

@ -3,6 +3,8 @@ package com.luoo.user.swagger;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.builders.RequestHandlerSelectors;
@ -34,6 +36,7 @@ public abstract class BaseSwaggerConfig {
.apiInfo(apiInfo(swaggerProperties)) .apiInfo(apiInfo(swaggerProperties))
.select() .select()
.apis(RequestHandlerSelectors.basePackage(swaggerProperties.getApiBasePackage())) .apis(RequestHandlerSelectors.basePackage(swaggerProperties.getApiBasePackage()))
//.apis(RequestHandlerSelectors.withClassAnnotation(ApiOperation.class))
.paths(PathSelectors.any()) .paths(PathSelectors.any())
.build(); .build();
} }

Loading…
Cancel
Save