提交 15965222 编写于 作者:  Peijun.zhao's avatar Peijun.zhao

Merge branch 'dev-circle-20200630' into 'release'

Dev circle 20200630

reviewcode赵培军

See merge request !35
流水线 #27255 已失败 于阶段
in 0 second
......@@ -11,7 +11,7 @@
<groupId>com.pica.cloud.account</groupId>
<artifactId>pica-cloud-account-client</artifactId>
<version>1.0.3.5</version>
<version>1.0.3.6</version>
<name>pica-cloud-account-client</name>
<packaging>jar</packaging>
......@@ -28,7 +28,7 @@
<dependency>
<groupId>com.pica.cloud.account</groupId>
<artifactId>pica-cloud-account-common</artifactId>
<version>1.0.1.4</version>
<version>1.0.1.6</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
......
......@@ -3,10 +3,14 @@ package com.pica.cloud.account.account.client;
import com.pica.cloud.account.account.common.req.EncryptEntity;
import com.pica.cloud.account.account.common.req.LoginResult;
import com.pica.cloud.account.account.common.req.OCINRequest;
import com.pica.cloud.account.account.common.req.circle.CircleAcctInitReq;
import com.pica.cloud.foundation.entity.PicaResponse;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import java.util.List;
/**
* Created on 2019/10/16 17:28
......@@ -22,4 +26,8 @@ public interface RegisterClient {
@PostMapping(value = "/account/register/ocin")
PicaResponse register(@RequestBody OCINRequest ocinRequest);
}
@PostMapping(value = "/account/circle/acct")
PicaResponse<List<Integer>> register(@RequestBody CircleAcctInitReq circleAcctInitReq, @RequestHeader(value = "token") String token);
}
\ No newline at end of file
......@@ -11,7 +11,7 @@
<groupId>com.pica.cloud.account</groupId>
<artifactId>pica-cloud-account-common</artifactId>
<version>1.0.1.4</version>
<version>1.0.1.6</version>
<name>pica-cloud-account-common</name>
<packaging>jar</packaging>
......
package com.pica.cloud.account.account.common.req.circle;
/**
* @DESCRIPTOIN:
* @AUTHOR: joy
* @DATE:2020/6/21 11:01 上午
*/
public class CircleAcctInit {
private String userName;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getEncryMobile() {
return encryMobile;
}
public void setEncryMobile(String encryMobile) {
this.encryMobile = encryMobile;
}
private String encryMobile;
}
package com.pica.cloud.account.account.common.req.circle;
import java.util.List;
/**
* @DESCRIPTOIN:
* @AUTHOR: joy
* @DATE:2020/6/21 11:02 上午
*/
public class CircleAcctInitReq {
private List<CircleAcctInit> circleAcctInitList;
private Integer registerSource; // 1 安卓 2 ios 3 web 4 h5 5 admin
private Integer circleId;
public List<CircleAcctInit> getCircleAcctInitList() {
return circleAcctInitList;
}
public void setCircleAcctInitList(List<CircleAcctInit> circleAcctInitList) {
this.circleAcctInitList = circleAcctInitList;
}
public Integer getRegisterSource() {
return registerSource;
}
public void setRegisterSource(Integer registerSource) {
this.registerSource = registerSource;
}
public Integer getCircleId() {
return circleId;
}
public void setCircleId(Integer circleId) {
this.circleId = circleId;
}
}
......@@ -138,7 +138,7 @@
<dependency>
<groupId>com.pica.cloud.account</groupId>
<artifactId>pica-cloud-account-common</artifactId>
<version>1.0.1.4</version>
<version>1.0.1.6</version>
</dependency>
<dependency>
......
......@@ -270,6 +270,139 @@ public class AccountController extends AccountBaseController {
}
}
@ApiOperation("webLive端验证码登录-沿用 /login-register/v1")
@PostMapping("/login-register/v2")
// @RepeatForbidden(uniqueKey = "content")
//当前版本存在性能问题 luo优化后上
public PicaResponse loginRegisterV2(@RequestBody EncryptEntity entity) throws Exception {
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
this.checkMobilePhone(request.getMobile());
//接入新旭事务一致性
String batchNo = IntactUtils.getUUID();
intactUtil.sendIntact(batchNo,"webLive-loginRegister",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_1,"entity:"+ JSON.toJSONString(entity));
AccountReq req = new AccountReq();
req.setMobilePhone(request.getMobile());
// 登录或注册,只能使用验证码
req.setPassword(null);
req.setAuthCode(request.getAuthCode());
req.setFlag("0");
req.setUnionid(request.getUnionId());
// 判断账号是否已经存在
Account account = accountService.getByMobilePhone(req.getMobilePhone());
if (account != null) {
// 登录
PicaResponse response = null;
try {
// response = this.login(req);
this.checkMobilePhone(req.getMobilePhone());
logger.info("login:{}", JSONObject.toJSONString(req));
//接入新旭事务一致性
String batchNo1 = IntactUtils.getUUID();
intactUtil.sendIntact(batchNo1,"login",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_1,"req:"+ JSON.toJSONString(req));
Account account1 = accountService.getByMobilePhone(req.getMobilePhone()); //获取账号信息
if (account1 == null) {
intactUtil.sendIntact(batchNo1,"login",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3,"未注册,请验证码登录");
return PicaResponse.toResponse(null, PicaResultCode.RESULE_DATA_NONE.code(), "未注册,请验证码登录");
}
if (StringUtils.isBlank(req.getPassword())) {
//验证码登录
req.setFlag("0");
intactUtil.sendIntact(batchNo1,"login",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3,"校验验证码前的返回,因为验证码可能校验不通过,就直接返回了");
//校验验证码
this.checkAuthCode(req);
} else { //密码登录
if (!StringUtils.equals(req.getPassword(), account1.getPassword())) {
intactUtil.sendIntact(batchNo1,"login",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3,"请输入正确的密码");
return PicaResponse.toResponse(null, PicaResultCode.PARAM_IS_INVALID.code(), "请输入正确的密码");
}
}
//更新最后登录时间
Account update = new Account();
update.setId(account1.getId());
update.setLastLoginTime(new Date());
if (StringUtils.isBlank(account1.getUnionid()) && StringUtils.isNotBlank(req.getUnionid())) {
update.setUnionid(req.getUnionid()); //绑定微信unionid
update.setModifyId(account1.getId());
update.setModifyTime(new Date());
}
accountService.updateAccountById(update);
//登录成功,清除旧token,生成新token
String deviceType = super.getDeviceInfo("device_type"); //1:pc 2:android 3:ios
String newToken = this.generateTokenWebLive(account1, deviceType);
intactUtil.sendIntact(batchNo1,"login",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3,"req:"+ JSON.toJSONString(req));
response = PicaResponse.toResponse(newToken);
} catch (PicaException e) {
if(e.getCode().equals(PicaResultCode.PARAM_IS_INVALID.code()) || e.getCode().equals(PicaResultCode.RESULE_DATA_NONE.code())){
intactUtil.sendIntact(batchNo,"webLive-loginRegister",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3,"验证码错误或过期-不加入提醒,返回值:"+ JSON.toJSONString(response));
}
throw e;
}
if (response.getData() != null) {
LoginResult result = new LoginResult();
result.setToken(response.getData().toString());
intactUtil.sendIntact(batchNo,"webLive-loginRegister",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3,"登录成功,返回值:"+ JSON.toJSONString(response.getData()));
return PicaResponse.toResponse(result);
}
return response;
} else {
// 注册
PicaResponse<LoginResult> result = null;
try {
// result = this.register(req);
this.checkMobilePhone(req.getMobilePhone());
accountUtils.checkRegisterMobilePhoneAndAuthCode(req.getMobilePhone(),req.getFlag(),req.getAuthCode());
//接入新旭事务一致性
String batchNo2 = IntactUtils.getUUID();
intactUtil.sendIntact(batchNo2,"register",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_1,"req:"+ JSON.toJSONString(req));
String deviceType = super.getDeviceInfo("device_type"); //1:pc 2:android 3:ios
Account account2 = new Account();
account2.setMobilePhone(EncryptUtils.encryptContent(req.getMobilePhone(), EncryptConstants.ENCRYPT_TYPE_MOBILE));
switch (deviceType) { //注册来源
case "1":
account2.setRegisterSource(CommonConstants.SYSTEM_TYPE_P024_NO_3); //pc
break;
case "2":
account2.setRegisterSource(CommonConstants.SYSTEM_TYPE_P024_NO_1); //android
break;
case "3":
account2.setRegisterSource(CommonConstants.SYSTEM_TYPE_P024_NO_2); //ios
break;
default:
account2.setRegisterSource(AccountTypeEnum.DEVICE_TYPE_H5.getCode()); //H5注册
}
//创建账号
accountService.createAccount(account2);
//生成token并返回
String newToken = this.generateTokenWebLive(account2, deviceType);
LoginResult result1 = new LoginResult();
result1.setToken(newToken);
intactUtil.sendIntact(batchNo2,"register",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3,"req:"+ JSON.toJSONString(req));
// return PicaResponse.toResponse(result);
result = PicaResponse.toResponse(result1);
} catch (PicaException e) {
if(e.getCode().equals(PicaResultCode.PARAM_IS_INVALID.code()) || e.getCode().equals(PicaResultCode.RESULE_DATA_NONE.code())){
intactUtil.sendIntact(batchNo,"webLive--loginRegister",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3,"验证码错误或过期-不加入提醒,返回值:"+ JSON.toJSONString(result));
}
throw e;
}
intactUtil.sendIntact(batchNo,"webLive--loginRegister",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3,"注册成功,返回值:"+ JSON.toJSONString(result));
return result;
}
}
//手机格式校验
private void checkMobilePhone(String mobilePhone) {
if (StringUtils.isBlank(mobilePhone) || !ValidateUtils.isMobile(mobilePhone)) {
......@@ -339,6 +472,40 @@ public class AccountController extends AccountBaseController {
return newToken;
}
private String generateH5TokenWebLive(Account account) {
String newToken = StringUtils.EMPTY;
try {
//先清除旧token
String tokenValue = "token-doctor-" + account.getId().toString();
String oldToken = redisClient.get(tokenValue + "-h5");
if (StringUtils.isNotBlank(oldToken)) {
redisClient.del(oldToken);
}
//生成新token
int expiredSeconds = 30 * 24 * 60 * 60; //H5 token有效期30天
newToken = UUID.randomUUID().toString().replace("-", "").toUpperCase();
String tokenKey = "token-" + newToken;
redisClient.set(tokenKey, tokenValue, expiredSeconds);
redisClient.set(tokenValue + "-h5", tokenKey, expiredSeconds);
//用户数据放入缓存
PicaUser picaUser = new PicaUser();
picaUser.setToken(newToken);
picaUser.setId(account.getId().intValue());
picaUser.setMobile(account.getMobilePhone());
picaUser.setName(account.getName()); //保留原name
picaUser.setCreated_time(account.getCreatTime());
Map<String, String> data = Object2Map.objectToMapString("yyyy-MM-dd HH:mm:ss", picaUser, new String[0]);
data.put("sysCode", "h5");
data.forEach((key, value) -> {
value = value == null ? "" : value;
redisClient.hset(tokenValue, key, value);
});
} catch (Exception ex) {
logger.error("生成H5 token异常:{}" + ex.getMessage(), ex);
}
return newToken;
}
//清除旧token,生成新token
private String generateToken(Account account, String deviceType) {
//接入新旭事务一致性
......@@ -362,6 +529,28 @@ public class AccountController extends AccountBaseController {
return newToken;
}
private String generateTokenWebLive(Account account, String deviceType) {
//接入新旭事务一致性
String batchNo = IntactUtils.getUUID();
intactUtil.sendIntact(batchNo,"generateToken",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_1,"account:"+ JSON.toJSONString(account)+",deviceType:"+deviceType);
String newToken;
switch (deviceType) { //设备信息
case "1": //pc
//TODO
newToken = StringUtils.EMPTY;
break;
case "2": //android
case "3": //ios
//TODO 更新设备信息
newToken = StringUtils.EMPTY;
break;
default: //H5
newToken = this.generateH5TokenWebLive(account);
}
intactUtil.sendIntact(batchNo,"generateToken",com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3,"newToken:"+newToken);
return newToken;
}
public static void main(String[] args) {
JSON.toJSONString(null);
System.out.println("成功");
......
package com.pica.cloud.account.account.server.controller;
import com.pica.cloud.account.account.common.req.circle.CircleAcctInitReq;
import com.pica.cloud.account.account.server.service.CircleAccountService;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.service.starter.interceptor.EnabledLoginValidate;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @DESCRIPTOIN:
* @AUTHOR: joy
* @DATE:2020/6/21 10:22 上午
*/
@Api(description = "")
@RestController
@RequestMapping("/circle")
public class CircleUserController {
private Logger logger = LoggerFactory.getLogger(CircleUserController.class);
@Autowired
private CircleAccountService circleAccountService;
@PostMapping("/acct")
@EnabledLoginValidate
public PicaResponse<List<Integer>> circleUserInit(@RequestBody CircleAcctInitReq circleAcctInitReq) {
return PicaResponse.toResponse(circleAccountService.createCircleAccount(circleAcctInitReq));
}
}
package com.pica.cloud.account.account.server.service;
import com.pica.cloud.account.account.common.req.circle.CircleAcctInitReq;
import com.pica.cloud.account.account.server.entity.Account;
import com.pica.cloud.account.account.server.entity.AccountInfoEntity;
import java.util.List;
import java.util.Map;
/**
*
*/
public interface CircleAccountService {
//创建圈子入口-用户账号
List<Integer> createCircleAccount(CircleAcctInitReq circleAcctInitReq);
}
......@@ -91,7 +91,11 @@ public class AccountServiceImpl implements AccountService {
accountInfo.setDeleteFlag(1);
accountInfo.setSex(0);
accountInfo.setRegisterProduct(AccountTypeEnum.PRODUCT_TYPE_DOCTOR.getCode());
accountInfo.setRegisterSource(AccountTypeEnum.DEVICE_TYPE_H5.getCode());
if(null != account.getRegisterSource() && 0 != account.getRegisterSource()){
accountInfo.setRegisterSource(account.getRegisterSource());
}else {
accountInfo.setRegisterSource(AccountTypeEnum.DEVICE_TYPE_H5.getCode());
}
accountInfoDetailMapper.insertSelective(accountInfo);
Integer acctId = accountInfo.getId();
//doctor表,存入用户id
......
package com.pica.cloud.account.account.server.service.impl;
import com.pica.cloud.account.account.common.req.circle.CircleAcctInit;
import com.pica.cloud.account.account.common.req.circle.CircleAcctInitReq;
import com.pica.cloud.account.account.server.entity.Account;
import com.pica.cloud.account.account.server.mapper.AccountMapper;
import com.pica.cloud.account.account.server.service.CircleAccountService;
import com.pica.cloud.account.account.server.service.AccountService;
import groovy.util.logging.Log;
import groovy.util.logging.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
/**
* @DESCRIPTOIN:
* @AUTHOR: joy
* @DATE:2020/6/21 10:25 上午
*/
@Service
public class CircleAccountServiceImpl implements CircleAccountService {
private static Logger logger = LoggerFactory.getLogger(CircleAccountServiceImpl.class);
@Autowired
private AccountService accountService;
@Autowired
private AccountMapper accountMapper;
@Override
@Transactional
public List<Integer> createCircleAccount(CircleAcctInitReq circleAcctInitReq) {
List<CircleAcctInit> circleAcctInits = circleAcctInitReq.getCircleAcctInitList();
List<Integer> savedIds = new ArrayList<>();
try {
for(CircleAcctInit acct : circleAcctInits){
Account dbAcct = accountMapper.getByMobilePhone(acct.getEncryMobile()); //获取医生表账号信息
if(null == dbAcct){
Account account = new Account();
account.setNickname(acct.getUserName());
account.setMobilePhone(acct.getEncryMobile());
account.setRegisterSource(circleAcctInitReq.getRegisterSource());
accountService.createAccount(account);
savedIds.add(account.getId().intValue());
}else {
savedIds.add(dbAcct.getId().intValue());
}
}
}catch (Exception e){
logger.error("createCircleAccount error:{}",e.getMessage());
throw e;
}
return savedIds;
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册