Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
sunweiguo committed Jan 8, 2019
1 parent a80359d commit 0062667
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ spring cloud并不是像spring是一个框架,他是解决微服务的一种
和扣减放在lua脚本中原子执行,然后MQ异步出去生成订单(生成订单主表和订单详情表放在一个本地事务中),这两步操作成功之后,再用MQ去异步删除购物车。MQ消费不成功则重试。
对于扣减库存这一步,想法是用定时任务,定时与redis中进行同步。这里是模拟了秒杀场景,预减库存+MQ异步,提交订单-->redis判断并且减库存-->调用cart-service获取购物车-->MQ异步(userId,shippingId)生成订单主表和详情表-->上面都成功,则MQ异步(userId)
去清除购物车,库存用定时任务去同步(未做),理想的做法是:MQ异步扣减库存,订单服务订阅扣减库存消息,一旦库存扣减成功,则进行订单生成。
- [ ] 2019/1/8 继续完善订单接口,完成支付服务,就直接放在订单服务里面了,因为与订单逻辑紧密,就放在一起了。
- [ ] 2019/1/9 swagger
- [x] 2019/1/8 继续完善订单接口,完成支付服务,就直接放在订单服务里面了,因为与订单逻辑紧密,就放在一起了。
- [x] 2019/1/8 使用了一下swagger,发现代码侵入比较强,每一个接口上面都要手动打上响应的注解
- [ ] 2019/1/10 服务跟踪、自动化部署
- [ ] 2019/1/11 整合前端
- [ ] 2019/1/12 docker部署
Expand Down
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,18 @@
<version>20161215</version>
</dependency>

<!-- 自动生成API文档 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.5.0</version>
</dependency>


</dependencies>
</dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ private ServerResponse getCartOrderItem(Integer userId, List<CartProductVo> cart




/**********************以下是关于支付的逻辑处理*****************************/



Expand Down
9 changes: 9 additions & 0 deletions snailmall-user-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@
<artifactId>curator-recipes</artifactId>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@SpringBootApplication
@EnableDiscoveryClient
@EnableSwagger2
public class SnailmallUserServiceApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import com.njupt.swg.entity.User;
import com.njupt.swg.service.IUserService;
import com.njupt.swg.vo.UserResVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -28,6 +32,8 @@
@RequestMapping("user")
@RestController
@Slf4j
// 表示标识这个类是swagger的资源
@Api(value = "UserController", tags = {"用户服务接口"})
public class UserController {

@Autowired
Expand All @@ -39,6 +45,11 @@ public class UserController {
* 用户登陆:验证参数、登陆、写到cookie中并且写到redis中
* 用户登陆以后,点击其他需要登陆才能看的页面时,先判断是否前端是否有这个key,没有则提示需要登陆
*/
@ApiOperation(value="用户登陆", notes="输入用户名,密码,不能为空")
@ApiImplicitParams({
@ApiImplicitParam(name = "username", value = "用户名", required = true, dataType = "String"),
@ApiImplicitParam(name = "password", value = "用户密码", required = true, dataType = "String")
})
@RequestMapping("/login.do")
public ServerResponse<UserResVO> login(HttpSession session, HttpServletResponse response, String username, String password){
log.info("【用户{}开始登陆】",username);
Expand All @@ -59,6 +70,8 @@ public ServerResponse<UserResVO> login(HttpSession session, HttpServletResponse
/**
* 用户注册,要判断用户名和邮箱是否重复,这里用了分布式锁来防止用户名和邮箱可能出现重复
*/
@ApiOperation(value="创建用户", notes="根据User对象创建用户")
@ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
@RequestMapping("/register.do")
public ServerResponse register(User user){
log.info("【开始注册】");
Expand All @@ -71,6 +84,11 @@ public ServerResponse register(User user){
/**
* 判断用户名和邮箱是否重复
*/
@ApiOperation(value="验证用户名和邮箱是否重复", notes="用户名和邮箱都不能用已经存在的")
@ApiImplicitParams({
@ApiImplicitParam(name = "str", value = "输入参数", required = true, dataType = "String"),
@ApiImplicitParam(name = "type", value = "参数类型", required = true, dataType = "String")
})
@RequestMapping("/check_valid.do")
public ServerResponse checkValid(@RequestParam("str") String str,
@RequestParam("type") String type){
Expand All @@ -85,6 +103,7 @@ public ServerResponse checkValid(@RequestParam("str") String str,
* 在浏览器中测试的时候,将login方法暂时开放为GET请求,然后请求路径为:http://oursnail.cn:8081/user/login.do?username=admin&password=123456
* 同样地,在测试获取登陆用户信息接口,也要按照域名来请求,否则拿不到token:http://oursnail.cn:8081/user/get_user_info.do
*/
@ApiOperation(value="获取用户个人信息", notes="登陆状态下获取")
@RequestMapping("/get_user_info.do")
public ServerResponse getUserInfo(HttpServletRequest request){
String loginToken = CookieUtil.readLoginToken(request);
Expand Down Expand Up @@ -113,6 +132,8 @@ public ServerResponse getUserInfo(HttpServletRequest request){
/**
* 根据用户名去拿到对应的问题
*/
@ApiOperation(value="根据用户名去拿到对应的问题", notes="忘记密码时首先根据用户名去获取设置的问题")
@ApiImplicitParam(name = "username", value = "用户名", required = true, dataType = "String")
@RequestMapping("/forget_get_question.do")
public ServerResponse forgetGetQuestion(String username){
log.info("【用户{}忘记密码,点击忘记密码输入用户名】",username);
Expand All @@ -123,6 +144,12 @@ public ServerResponse forgetGetQuestion(String username){
/**
* 校验答案是否正确
*/
@ApiOperation(value="校验答案是否正确", notes="忘记密码时输入正确的用户名之后就可以获取到问题,此时就可以输入答案")
@ApiImplicitParams({
@ApiImplicitParam(name = "username", value = "用户名", required = true, dataType = "String"),
@ApiImplicitParam(name = "question", value = "设置的问题", required = true, dataType = "String"),
@ApiImplicitParam(name = "answer", value = "提交的答案", required = true, dataType = "String")
})
@RequestMapping("/forget_check_answer.do")
public ServerResponse forgetCheckAnswer(String username,String question,String answer){
log.info("【用户{}忘记密码,提交问题答案】",username);
Expand All @@ -134,6 +161,12 @@ public ServerResponse forgetCheckAnswer(String username,String question,String a
/**
* 忘记密码的重置密码
*/
@ApiOperation(value="忘记密码的重置密码", notes="输入新的密码,要进行token的校验")
@ApiImplicitParams({
@ApiImplicitParam(name = "username", value = "用户名", required = true, dataType = "String"),
@ApiImplicitParam(name = "passwordNew", value = "新密码", required = true, dataType = "String"),
@ApiImplicitParam(name = "forgetToken", value = "前端保存的token", required = true, dataType = "String")
})
@RequestMapping("/forget_reset_password.do")
public ServerResponse forgetResetPasswd(String username,String passwordNew,String forgetToken){
log.info("【用户{}忘记密码,输入新密码】",username);
Expand All @@ -144,6 +177,11 @@ public ServerResponse forgetResetPasswd(String username,String passwordNew,Strin
/**
* 登陆状态的重置密码
*/
@ApiOperation(value="登陆状态的重置密码", notes="登陆的时候只需要输入老的密码和新密码即可")
@ApiImplicitParams({
@ApiImplicitParam(name = "passwordOld", value = "老密码", required = true, dataType = "String"),
@ApiImplicitParam(name = "passwordNew", value = "新密码", required = true, dataType = "String")
})
@RequestMapping("/reset_password.do")
public ServerResponse resetPasswd(String passwordOld,String passwordNew,HttpServletRequest request){
//1.读取cookie
Expand All @@ -166,6 +204,13 @@ public ServerResponse resetPasswd(String passwordOld,String passwordNew,HttpServ
/**
* 更新当前登陆用户信息
*/
@ApiOperation(value="更新当前登陆用户信息", notes="更新用户信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "email", value = "邮箱", required = true, dataType = "String"),
@ApiImplicitParam(name = "phone", value = "电话", required = true, dataType = "String"),
@ApiImplicitParam(name = "question", value = "问题", required = true, dataType = "String"),
@ApiImplicitParam(name = "answer", value = "答案", required = true, dataType = "String")
})
@RequestMapping("/update_information.do")
public ServerResponse updateInformation(String email,String phone,String question,String answer,HttpServletRequest request){
//1.读取cookie
Expand All @@ -187,6 +232,7 @@ public ServerResponse updateInformation(String email,String phone,String questio
/**
* 登出,删除cookie和redis即可
*/
@ApiOperation(value="登出", notes="退出登陆,删除cookie和redis缓存")
@RequestMapping("/logout.do")
public ServerResponse logout(HttpServletRequest request,HttpServletResponse response){
log.info("【用户删除cookie】");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.njupt.swg.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
* @Author swg.
* @Date 2019/1/8 11:39
* @CONTACT 317758022@qq.com
* @DESC
*/
@Configuration
public class SwaggerConfig {
// 接口版本号
private final String version = "3.0";
// 接口大标题
private final String title = "快乐蜗牛商城V3.0文档";
// 具体的描述
private final String description = "用户服务";
// 服务说明url
private final String termsOfServiceUrl = "http://www.kingeid.com";
// 接口作者联系方式
private final Contact contact = new Contact("fourColor", "https://github.com/sunweiguo", "sunweiguode@gmail.com");

@Bean
public Docket buildDocket() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(buildApiInf())
.select().build();
}

private ApiInfo buildApiInf() {
return new ApiInfoBuilder().title(title).termsOfServiceUrl(termsOfServiceUrl).description(description)
.version(version).contact(contact).build();

}

}

0 comments on commit 0062667

Please sign in to comment.