Sfoglia il codice sorgente

Merge branch 'dev' of http://www.lockingos.org:3000/yeqd/user-parent into dev

# Conflicts:
#	user-service/src/main/java/com/hp/user/service/entity/Account.java
dev
1517874642 4 anni fa
parent
commit
c475265d47
5 ha cambiato i file con 99 aggiunte e 53 eliminazioni
  1. +0
    -47
      user-service/src/main/java/com/hp/user/service/config/SwaggerConfig1.java
  2. +23
    -2
      user-service/src/main/java/com/hp/user/service/controller/AuthenticationController.java
  3. +70
    -1
      user-service/src/main/java/com/hp/user/service/impl/AccountServiceImpl.java
  4. +5
    -2
      user-service/src/main/java/com/hp/user/service/impl/MessageServiceImpl.java
  5. +1
    -1
      user-service/src/main/java/com/hp/user/service/redis/RedisOperation.java

+ 0
- 47
user-service/src/main/java/com/hp/user/service/config/SwaggerConfig1.java Vedi File

@@ -1,47 +0,0 @@
package com.hp.user.service.config;

import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@Configuration
@EnableSwagger2
public class SwaggerConfig1{
/**
* 创建API应用
* apiInfo() 增加API相关信息
* 通过select()函数返回一个ApiSelectorBuilder实例,用来控制哪些接口暴露给Swagger来展现,
* 本例采用指定扫描的包路径来定义指定要建立API的目录。
*
* @return
*/
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.hp.user.service.controller"))
.paths(PathSelectors.any())
.build();
}

/**
* 创建该API的基本信息(这些基本信息会展现在文档页面中)
* 访问地址:http://项目实际地址/swagger-ui.html
* @return
*/
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Spring Boot中使用Swagger2构建RESTful APIs")
.version("1.0")
.build();
}
}

+ 23
- 2
user-service/src/main/java/com/hp/user/service/controller/AuthenticationController.java Vedi File

@@ -5,7 +5,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hp.user.client.entity.AccountVO;
import com.hp.user.client.service.AccountService;
import com.hp.user.service.entity.Account;

import io.swagger.annotations.Api;

@@ -41,8 +43,27 @@ public class AuthenticationController {
* 需要用户信息
*/
@RequestMapping("/register")
public void register() {

public void register(AccountVO account) {
accountService.register(account);
}
/**
* 微信注册
* 需要用户信息
*/
@RequestMapping("/wxRegister")
public void wxRegister() {
}
/**
* 绑定微信号
* @param userId
* @param wxNumber
*/
@RequestMapping("/bingWx")
public void bindWx(String userId,String wxNumber) {
accountService.bindWx(userId, wxNumber);
}


+ 70
- 1
user-service/src/main/java/com/hp/user/service/impl/AccountServiceImpl.java Vedi File

@@ -1,9 +1,20 @@
package com.hp.user.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.hp.user.client.entity.AccountVO;
import com.hp.user.client.service.AccountService;
import com.hp.user.client.service.MessageService;
import com.hp.user.service.constants.UserConstants;
import com.hp.user.service.dao.AccountMapper;
import com.hp.user.service.entity.Account;
import com.hp.user.service.redis.RedisOperation;
import redis.clients.jedis.Jedis;
import org.apache.commons.codec.binary.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -20,19 +31,77 @@ public class AccountServiceImpl implements AccountService {
@Autowired
private MessageService messageService;
@Autowired
private AccountMapper accountMapper;
@Override
public void login(String phone, String verificationCode) {
try {
//需要判断phone是否存在
checkPhone(phone);
String code = messageService.getVerificationCode(phone);
if(StringUtils.equals(verificationCode, code)) {
//登陆成功
}else {
//登陆失败,返回验证码
//登陆失败
//返回错误信息
}
}catch(Exception e) {
}
}
@Override
public Boolean checkPhone(String phone) {
//不存在为true
Boolean flage = true;
try {
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("phone", phone);
queryWrapper.eq("sys_deleted", 0);
Integer count = accountMapper.selectCount(queryWrapper);
if(count>0) {
//表示手机以及存在,需要返回错误
System.out.println("手机号已经存在");
flage = false;
}
}catch(Exception e) {
}
return flage;
}
@Override
public void register(AccountVO accountVo) {
try {
if(checkPhone(accountVo.getPhone())) {
Account account = new Account();
BeanUtils.copyProperties(accountVo, account);
account.setUserId(IdWorker.getId());
accountMapper.insert(account);
}
}catch(Exception e) {
}
}
@Override
public void bindWx(String userIdStr, String wxNumber) {
try {
Long userId = Long.parseLong(userIdStr);
Account account = new Account();
account.setUserId(userId);
account.setWxNumber(wxNumber);
accountMapper.updateById(account);
}catch(Exception e) {
}
}
}

+ 5
- 2
user-service/src/main/java/com/hp/user/service/impl/MessageServiceImpl.java Vedi File

@@ -56,8 +56,11 @@ public class MessageServiceImpl implements MessageService {

@Override
public String getVerificationCode(String phone) {
// TODO Auto-generated method stub
return null;
Jedis jedis = redisOperation.getRedis();
String key = UserConstants.VERIFICATION_CODE+phone;
String code = jedis.get(key);
jedis.del(key);
return code;
}

}

+ 1
- 1
user-service/src/main/java/com/hp/user/service/redis/RedisOperation.java Vedi File

@@ -139,7 +139,7 @@ public class RedisOperation implements ApplicationRunner{

@Override
public void run(ApplicationArguments args) throws Exception {
System.out.print("redis");
// System.out.print("redis");
// JedisPool pool = null;
// common-pool配置
if (pool == null) {


Caricamento…
Annulla
Salva