提交 7cb7027e 编写于 作者: rushui.chen's avatar rushui.chen

“20190823 微信登陆

上级 1a89708f
流水线 #13639 已失败 于阶段
in 1 second
...@@ -13,4 +13,11 @@ public class Constants { ...@@ -13,4 +13,11 @@ public class Constants {
/** 批量短信url */ /** 批量短信url */
public static final String BATCH_SEND_MESSAGE = "/sms/send_batch_dif"; public static final String BATCH_SEND_MESSAGE = "/sms/send_batch_dif";
} }
...@@ -68,7 +68,7 @@ public abstract class AccountBaseController extends BaseController { ...@@ -68,7 +68,7 @@ public abstract class AccountBaseController extends BaseController {
*/ */
public Integer getProductType() { public Integer getProductType() {
HttpServletRequest request = super.getRequest(); HttpServletRequest request = super.getRequest();
String str = request.getHeader("productType"); String str = request.getHeader("producttype");
if (StringUtils.isNotEmpty(str)) { if (StringUtils.isNotEmpty(str)) {
return Integer.parseInt(str); return Integer.parseInt(str);
} }
...@@ -82,7 +82,7 @@ public abstract class AccountBaseController extends BaseController { ...@@ -82,7 +82,7 @@ public abstract class AccountBaseController extends BaseController {
*/ */
public Integer getSourceType() { public Integer getSourceType() {
HttpServletRequest request = super.getRequest(); HttpServletRequest request = super.getRequest();
String str = request.getHeader("sourceType"); String str = request.getHeader("sourcetype");
if (StringUtils.isNotEmpty(str)) { if (StringUtils.isNotEmpty(str)) {
return Integer.parseInt(str); return Integer.parseInt(str);
} }
......
package com.pica.cloud.account.account.server.controller;
import com.pica.cloud.account.account.server.entity.AccountUser;
import com.pica.cloud.account.account.server.service.AccountLoginOutService;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.redis.CacheClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@Api(value = "登录接口")
@RestController
public class AccountLoginController extends AccountBaseController {
@Autowired
private AccountLoginOutService accountLoginOutService;
@Autowired
private CacheClient cacheClient;
/**
* 退出登录接口
*
* @param sourceType
* @return
*/
@ApiOperation(value = "退出登录操作")
@PostMapping("/logout")
public PicaResponse loginOut(@RequestParam("sourceType") Integer sourceType) {
//只有在登录状态下才能调用此接口;
AccountUser accountUser = super.getAccountUser();
String token = accountUser.getToken();
if (StringUtils.isNotEmpty(token)) {
//记录日志
accountLoginOutService.insertLoginLog(accountUser);
//清除token信息
if (cacheClient.deleteToken(token)) {
return PicaResponse.toResponse();
}
}
return null;
}
}
...@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; ...@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.pica.cloud.account.account.server.entity.AccountUser; import com.pica.cloud.account.account.server.entity.AccountUser;
import com.pica.cloud.account.account.server.entity.AcctUserInfo; import com.pica.cloud.account.account.server.entity.AcctUserInfo;
import com.pica.cloud.account.account.server.service.AccountUserInfoService; import com.pica.cloud.account.account.server.service.AccountUserInfoService;
import com.pica.cloud.account.account.server.util.AccountUtils;
import com.pica.cloud.account.account.server.util.RSAUtils; import com.pica.cloud.account.account.server.util.RSAUtils;
import com.pica.cloud.foundation.entity.PicaResponse; import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.utils.entity.PicaUser; import com.pica.cloud.foundation.utils.entity.PicaUser;
...@@ -29,17 +30,16 @@ public class AccountUserInfoController extends AccountBaseController { ...@@ -29,17 +30,16 @@ public class AccountUserInfoController extends AccountBaseController {
/** /**
* 修改用户信息接口 * 修改用户信息接口
* *
* @param info * @param params
* @return * @return
*/ */
@ApiOperation(value = "修改用户信息接口") @ApiOperation(value = "修改用户信息接口")
@PutMapping(value = "") @PutMapping(value = "")
public PicaResponse updateUserInfo(String info) { public PicaResponse updateUserInfo(String params) {
AccountUser accountUser = super.getAccountUser(); AccountUser accountUser = super.getAccountUser();
//如何获取acct_id 只有注册成功才有 //如何获取acct_id 只有注册成功才有
try { try {
String str = RSAUtils.decrypt(info, RSAUtils.getPrivateKey()); AcctUserInfo acctUserInfo = AccountUtils.getRequestEntity(params,AcctUserInfo.class);
AcctUserInfo acctUserInfo = JSONObject.parseObject(str, AcctUserInfo.class);
accountUserInfoService.updateUserInfo(acctUserInfo); accountUserInfoService.updateUserInfo(acctUserInfo);
return PicaResponse.toResponse(); return PicaResponse.toResponse();
} catch (Exception e) { } catch (Exception e) {
......
package com.pica.cloud.account.account.server.controller;
import com.alibaba.fastjson.JSONObject;
import com.pica.cloud.account.account.server.entity.*;
import com.pica.cloud.account.account.server.enums.EnumsType;
import com.pica.cloud.account.account.server.enums.ExceptionType;
import com.pica.cloud.account.account.server.req.RegisterReq;
import com.pica.cloud.account.account.server.service.*;
import com.pica.cloud.account.account.server.util.AccountUtils;
import com.pica.cloud.account.account.server.util.TokenUtils;
import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.redis.ICacheClient;
import com.pica.cloud.foundation.utils.utils.EncryptCreateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import java.util.*;
@Api(value = "登录类资源")
@RestController
public class LoginController extends AccountBaseController {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private AccountLoginService accountLoginService;
@Autowired
private AccountContactService accountContactServer;
@Autowired
private AccountUserInfoService accountUserInfoService;
@Autowired
private RegisterService registerService;
@Autowired
private AccountWeChatService accountWeChatService;
@Autowired
@Qualifier("cacheMigrateClient")
private ICacheClient cacheClient;
@Autowired
private TokenUtils tokenUtils;
@Autowired
private AccountUtils accountUtils;
@ApiOperation("登录接口")
@PostMapping("/login")
public PicaResponse<String> loginByPassword(@RequestBody String params) throws Exception {
RegisterReq registerReq = AccountUtils.getRequestEntity(params, RegisterReq.class);
String mobile = registerReq.getMobile();
//手机号校验
AccountUtils.checkMobilePhone(mobile);
//是否注册校验
if (accountUtils.checkRegisterMobile(mobile)) {
throw new PicaException(ExceptionType.PICA_NOT_REGISTER.getCode(), ExceptionType.PICA_NOT_REGISTER.getMessage());
}
//手机号获取账户id,账户id再获取密码
boolean loginStatus = accountLoginService.checkLogin(mobile, registerReq.getPassword());
if (loginStatus) {
String result = processLogin(registerReq);
// TODO: 2019/8/23 :是否完善过信息
return PicaResponse.toResponse(result);
} else {
logger.info("login failure:" + mobile);
//accountUser = cacheClient.getToken(newToken, AccountUser.class);
//accountLoginService.insertLoginLog(accountUser, EnumsType.LOGIN_PWD.getCode(), EnumsType.LOGIN_STATUS_FAILURE.getCode());
throw new PicaException(ExceptionType.PICA_PASSWORD_ERROR.getCode(), ExceptionType.PICA_PASSWORD_ERROR.getMessage());
}
}
/**
* 一键登录
*
* @param params params
* @return
* @throws Exception
*/
@ApiOperation("一键登录接口")
@PostMapping(value = "/login-register")
public PicaResponse loginAndRegister(@RequestBody String params) throws Exception {
RegisterReq registerReq = AccountUtils.getRequestEntity(params, RegisterReq.class);
String mobile = registerReq.getMobile();
String authCode = registerReq.getAuthCode();
accountUtils.checkMobilePhoneAndAuthCode(mobile, "0", authCode);
//用于是否注册 todo:判断是否注册过 需要添加一个条件。
if (accountUtils.checkRegisterMobile(mobile)) {
//如果已经注册过:
String result = processLogin(registerReq);
return PicaResponse.toResponse(result);
} else {
registerReq.setProductType(super.getProductType());
registerReq.setSourceType(super.getSourceType());
registerReq.setIpAddress(super.getIpAddr());
registerReq.setPassword("");
return registerService.register(registerReq);
}
}
/**
* 退出登录接口
*
* @return
*/
@ApiOperation(value = "退出登录接口")
@GetMapping("/logout")
public PicaResponse loginOut() {
//只有在登录状态下才能调用此接口;
AccountUser accountUser = super.getAccountUser();
String token = accountUser.getToken();
if (StringUtils.isNotEmpty(token)) {
//记录日志
accountLoginService.insertLoginLog(super.getAccountUser(), EnumsType.LOGIN_OUT.getCode(), EnumsType.LOGIN_STATUS_SUCCESS.getCode());
//清除token信息
if (cacheClient.deleteToken(token)) {
return PicaResponse.toResponse();
}
}
return null;
}
/**
* 微信登录
*
* @param params
* @return
*/
@ApiOperation("微信登录")
@PostMapping("/login/wechat")
public PicaResponse loginByWeChat(@RequestBody String params) throws Exception {
RegisterReq registerReq = AccountUtils.getRequestEntity(params, RegisterReq.class);
String code = registerReq.getCode();
WeChatEntity weChatEntity = new WeChatEntity();
Map<String, Object> resultMap = new HashMap<String, Object>();
if (weChatEntity != null && StringUtils.isNotEmpty(weChatEntity.getOpenId())) {
//获取用户信息
// resultMap = getUserInfo(weChatEntity);
}
// getOpenIdAccessToken
// bindingMobile
// binding
// unbinding
return null;
}
// private Map<String, Object> getUserInfo(WeChatEntity weChatEntity) {
//
//
// }
/**
* 微信登录第二步
*
* @param params
* @return
*/
// @ApiOperation("微信登录第二步")
// @PostMapping("/login/wechat/step2")
// public PicaResponse loginByWeChat(@RequestBody String params) {
//
//
// }
/**
* 绑定微信
*
* @param params
* @return
*/
// @ApiOperation("绑定微信")
// @PostMapping("/login/wechat/bind")
// public PicaResponse bindWeChat(@RequestBody String params) {
//
//
//
// }
/**
* 解绑微信:必须在登录状态才能解绑微信
*
* @return
*/
@ApiOperation("解绑微信")
@PostMapping("/login/wechat/unbind")
public PicaResponse unbindWeChat() {
String token = super.getToken();
if (!tokenUtils.checkTokenStatus(token)) {
AccountUser accountUser = super.getAccountUser();
Integer acctId = accountUser.getAcctId();
accountWeChatService.updateUnBindInfo(acctId, EnumsType.UNION_LOGIN_WE_CHAT.getCode());
return PicaResponse.toResponse();
} else {
throw new PicaException(ExceptionType.PICA_LOGIN_AGAIN.getCode(), ExceptionType.PICA_LOGIN_AGAIN.getMessage());
}
}
/**
* 处理登录逻辑
*
* @param registerReq
* @return
*/
private String processLogin(RegisterReq registerReq) {
String mobile = registerReq.getMobile();
AccountContact accountContact = accountContactServer.selectByMobile(EncryptCreateUtil.encrypt(mobile));
Integer userId = accountUserInfoService.insertUserInfo(accountContact.getAcctId());
//登录成功,清除旧token,生成新token
Account account = new Account();
account.setMobilePhone(mobile);
account.setAcctId(accountContact.getAcctId());
account.setId(userId.longValue());
account.setCreatTime(new Date());
account.setRegisterSource(super.getSourceType());
String newToken = tokenUtils.generateToken(account);
AccountUser accountUser = cacheClient.getToken(newToken, AccountUser.class);
accountUser.setLoginFrom(super.getSourceType());
accountUser.setLoginPlatform(super.getProductType());
accountUser.setLoginIp(super.getIpAddr());
//把用户信息存到表里面
accountLoginService.insertLoginLog(accountUser, EnumsType.LOGIN_PWD.getCode(), EnumsType.LOGIN_STATUS_SUCCESS.getCode());
JSONObject map = new JSONObject();
map.put("token", newToken);
map.put("userId", userId);
return map.toJSONString();
}
}
...@@ -4,16 +4,19 @@ import com.alibaba.fastjson.JSONObject; ...@@ -4,16 +4,19 @@ import com.alibaba.fastjson.JSONObject;
import com.pica.cloud.account.account.server.entity.AccountUser; import com.pica.cloud.account.account.server.entity.AccountUser;
import com.pica.cloud.account.account.server.req.ModifyMobileReq; import com.pica.cloud.account.account.server.req.ModifyMobileReq;
import com.pica.cloud.account.account.server.service.ModifyMobileService; import com.pica.cloud.account.account.server.service.ModifyMobileService;
import com.pica.cloud.account.account.server.util.AccountUtils;
import com.pica.cloud.account.account.server.util.RSAUtils; import com.pica.cloud.account.account.server.util.RSAUtils;
import com.pica.cloud.foundation.entity.PicaException; import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResponse; import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.entity.PicaResultCode; import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.foundation.redis.CacheClient; import com.pica.cloud.foundation.redis.CacheClient;
import com.pica.cloud.foundation.redis.ICacheClient;
import com.pica.cloud.foundation.utils.utils.EncryptCreateUtil; import com.pica.cloud.foundation.utils.utils.EncryptCreateUtil;
import com.pica.cloud.foundation.utils.utils.ValidateUtils; import com.pica.cloud.foundation.utils.utils.ValidateUtils;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -30,7 +33,8 @@ public class ModifyMobileController extends AccountBaseController { ...@@ -30,7 +33,8 @@ public class ModifyMobileController extends AccountBaseController {
private final String AUTH_CODE_PREFIX = "authCode-"; private final String AUTH_CODE_PREFIX = "authCode-";
@Autowired @Autowired
private CacheClient cacheClient; @Qualifier("cacheMigrateClient")
private ICacheClient cacheClient;
@Autowired @Autowired
private ModifyMobileService modifyMobileService; private ModifyMobileService modifyMobileService;
...@@ -47,8 +51,8 @@ public class ModifyMobileController extends AccountBaseController { ...@@ -47,8 +51,8 @@ public class ModifyMobileController extends AccountBaseController {
accountUser = super.getAccountUser(); accountUser = super.getAccountUser();
String token = accountUser.getToken(); String token = accountUser.getToken();
if (StringUtils.isNotEmpty(token)) { if (StringUtils.isNotEmpty(token)) {
String json = RSAUtils.decrypt(params, RSAUtils.getPrivateKey()); ModifyMobileReq modifyMobileReq = AccountUtils.getRequestEntity(params, ModifyMobileReq.class);
ModifyMobileReq modifyMobileReq = JSONObject.parseObject(json, ModifyMobileReq.class);
String mobile = modifyMobileReq.getMobile(); String mobile = modifyMobileReq.getMobile();
this.checkMobilePhone(mobile); this.checkMobilePhone(mobile);
//flag表示验证码类型,3表示修改手机号 //flag表示验证码类型,3表示修改手机号
......
package com.pica.cloud.account.account.server.controller; package com.pica.cloud.account.account.server.controller;
import com.alibaba.fastjson.JSONObject;
import com.pica.cloud.account.account.server.entity.AccountContact; import com.pica.cloud.account.account.server.entity.AccountContact;
import com.pica.cloud.account.account.server.entity.AccountUser; import com.pica.cloud.account.account.server.entity.AccountUser;
import com.pica.cloud.account.account.server.mapper.AccountContactMapper;
import com.pica.cloud.account.account.server.req.ForgetPasswordReq; import com.pica.cloud.account.account.server.req.ForgetPasswordReq;
import com.pica.cloud.account.account.server.req.PasswordReq; import com.pica.cloud.account.account.server.req.PasswordReq;
import com.pica.cloud.account.account.server.service.AccountContactServer; import com.pica.cloud.account.account.server.service.AccountContactService;
import com.pica.cloud.account.account.server.service.PasswordService; import com.pica.cloud.account.account.server.service.PasswordService;
import com.pica.cloud.account.account.server.util.AccountUtils; import com.pica.cloud.account.account.server.util.AccountUtils;
import com.pica.cloud.account.account.server.util.RSAUtils;
import com.pica.cloud.foundation.entity.PicaException; import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResponse; import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.entity.PicaResultCode; import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.foundation.redis.CacheClient; import com.pica.cloud.foundation.redis.ICacheClient;
import com.pica.cloud.foundation.utils.utils.EncryptCreateUtil; import com.pica.cloud.foundation.utils.utils.EncryptCreateUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -34,10 +32,11 @@ public class PasswordController extends AccountBaseController { ...@@ -34,10 +32,11 @@ public class PasswordController extends AccountBaseController {
private PasswordService passwordService; private PasswordService passwordService;
@Autowired @Autowired
private AccountContactServer accountContactServer; private AccountContactService accountContactServer;
@Autowired @Autowired
private CacheClient cacheClient; @Qualifier("cacheMigrateClient")
private ICacheClient cacheClient;
/** /**
* 修改密码 * 修改密码
...@@ -52,8 +51,7 @@ public class PasswordController extends AccountBaseController { ...@@ -52,8 +51,7 @@ public class PasswordController extends AccountBaseController {
AccountUser accountUser = super.getAccountUser(); AccountUser accountUser = super.getAccountUser();
String token = accountUser.getToken(); String token = accountUser.getToken();
if (StringUtils.isNotEmpty(token)) { if (StringUtils.isNotEmpty(token)) {
String json = RSAUtils.decrypt(params, RSAUtils.getPrivateKey()); PasswordReq modifyPasswordReq = AccountUtils.getRequestEntity(params, PasswordReq.class);
PasswordReq modifyPasswordReq = JSONObject.parseObject(json, PasswordReq.class);
modifyPasswordReq.setId(accountUser.getAcctId()); modifyPasswordReq.setId(accountUser.getAcctId());
passwordService.modifyPassword(modifyPasswordReq); passwordService.modifyPassword(modifyPasswordReq);
return PicaResponse.toResponse("密码修改成功"); return PicaResponse.toResponse("密码修改成功");
...@@ -72,8 +70,7 @@ public class PasswordController extends AccountBaseController { ...@@ -72,8 +70,7 @@ public class PasswordController extends AccountBaseController {
@ApiOperation(value = "忘记密码操作") @ApiOperation(value = "忘记密码操作")
@PostMapping(value = "/reset") @PostMapping(value = "/reset")
public PicaResponse forwardPassword(@RequestBody String params) throws Exception { public PicaResponse forwardPassword(@RequestBody String params) throws Exception {
String json = RSAUtils.decrypt(params, RSAUtils.getPrivateKey()); ForgetPasswordReq forwardPasswordReq = AccountUtils.getRequestEntity(params, ForgetPasswordReq.class);
ForgetPasswordReq forwardPasswordReq = JSONObject.parseObject(json, ForgetPasswordReq.class);
forwardPasswordReq.setFlag("4"); forwardPasswordReq.setFlag("4");
//是否注册校验 //是否注册校验
checkRegisterMobile(forwardPasswordReq.getMobile()); checkRegisterMobile(forwardPasswordReq.getMobile());
......
package com.pica.cloud.account.account.server.controller; package com.pica.cloud.account.account.server.controller;
import com.alibaba.fastjson.JSONObject; import com.pica.cloud.account.account.server.enums.EnumsType;
import com.pica.cloud.account.account.server.entity.Account;
import com.pica.cloud.account.account.server.entity.AccountContact;
import com.pica.cloud.account.account.server.entity.AccountInfo;
import com.pica.cloud.account.account.server.entity.AccountUser;
import com.pica.cloud.account.account.server.req.RegisterReq; import com.pica.cloud.account.account.server.req.RegisterReq;
import com.pica.cloud.account.account.server.service.*; import com.pica.cloud.account.account.server.service.RegisterService;
import com.pica.cloud.account.account.server.util.AccountUtils; import com.pica.cloud.account.account.server.util.AccountUtils;
import com.pica.cloud.account.account.server.util.RSAUtils;
import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResponse; import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.redis.CacheClient;
import com.pica.cloud.foundation.utils.utils.EncryptCreateUtil;
import com.pica.cloud.foundation.utils.utils.json.Object2Map;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.Map;
import java.util.UUID;
@Api("注册资源") @Api("注册资源")
@RestController @RestController
@RequestMapping("/register") @RequestMapping("/register")
public class RegisterController extends AccountBaseController { public class RegisterController extends AccountBaseController {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private AccountUtils accountUtils;
@Autowired @Autowired
private AccountContactServer accountContactServer; private RegisterService registerService;
@Autowired @Autowired
private AccountDetailsService accountDetailsService; private AccountUtils accountUtils;
@Autowired
private AccountProductService accountProductService;
@Autowired
private AccountUserInfoService accountUserInfoService;
@Autowired
private AccountLoginOutService accountLoginOutService;
@Autowired
private CacheClient cacheClient;
@ApiOperation("注册接口") @ApiOperation("注册接口")
@PostMapping(value = "") @PostMapping(value = "")
public PicaResponse<String> register(@RequestBody String params) throws Exception { public PicaResponse<String> register(@RequestBody String params) throws Exception {
String json = RSAUtils.decrypt(params, RSAUtils.getPrivateKey()); RegisterReq registerReq = AccountUtils.getRequestEntity(params, RegisterReq.class);
RegisterReq registerReq = JSONObject.parseObject(json, RegisterReq.class);
String mobile = registerReq.getMobile(); String mobile = registerReq.getMobile();
String authCode = registerReq.getAuthCode(); String authCode = registerReq.getAuthCode();
AccountUtils.checkMobilePhone(mobile); accountUtils.checkMobilePhoneAndAuthCode(mobile, EnumsType.SYSCODE_TYPE_REGISTER.getCode() + "", authCode);
accountUtils.checkAuthCode(mobile, "1", authCode); registerReq.setProductType(super.getProductType());
//校验用户用户是否已经存在 registerReq.setSourceType(super.getSourceType());
AccountContact accountContact = accountContactServer.selectByMobile(mobile); registerReq.setIpAddress(super.getIpAddr());
if (accountContact == null) { return registerService.register(registerReq);
//账号信息表
AccountInfo accountInfo = new AccountInfo();
accountInfo.setPassword(EncryptCreateUtil.encrypt(registerReq.getPassword()));
Integer acctId = accountDetailsService.insertAccountInfo(accountInfo);
accountDetailsService.updateAccountInfo(acctId);
//账号产品线表
accountProductService.insertSelective(acctId, super.getProductType());
//账号联系人表
accountContactServer.insertSelective(mobile, acctId);
//用户信息表
Integer userId = accountUserInfoService.insertUserInfo(acctId);
//保存用户登陆成功状态
AccountUser accountUser = super.getAccountUser();
accountLoginOutService.insertLoginLog(accountUser);
Account account = new Account();
account.setId(userId.longValue());
account.setAcctId(acctId);
account.setCreatTime(new Date());
account.setMobilePhone(mobile);
account.setRegisterSource(super.getSourceType());
String newToken = this.generateToken(account);
JSONObject jsonObject = new JSONObject();
jsonObject.put("token", newToken);
jsonObject.put("userId", userId);
return PicaResponse.toResponse(jsonObject.toJSONString());
} else {
throw new PicaException("您已注册,请直接登录");
}
} }
//生成token
private String generateToken(Account account) {
String sourceType = null;
Integer registerSource = account.getRegisterSource();
if (registerSource.intValue() == 5) {
sourceType = "h5";
} else if (registerSource.intValue() == 3) {
sourceType = "saas";
} else {
sourceType = "app";
}
String newToken = org.apache.commons.lang3.StringUtils.EMPTY;
try {
//先清除旧token
String tokenValue = "token-doctor-" + account.getId().toString();
//String oldToken = cacheClient.get(tokenValue + "-h5");
//if (org.apache.commons.lang3.StringUtils.isNotBlank(oldToken)) {
// cacheClient.del(oldToken);
//}
//生成新token
int expiredSeconds = 30 * 24 * 60 * 60;//token有效期30天
newToken = UUID.randomUUID().toString().replace("-", "").toUpperCase();
String tokenKey = "token-" + newToken;
cacheClient.set(tokenKey, tokenValue, expiredSeconds);
cacheClient.set(tokenValue + sourceType, tokenKey, expiredSeconds);
//用户数据放入缓存
String userData = cacheClient.hget(tokenValue, "id");
if (org.apache.commons.lang3.StringUtils.isEmpty(userData)) {
AccountUser picaUser = new AccountUser();
picaUser.setToken(newToken);
//用户id
picaUser.setId(account.getId().intValue());
//
picaUser.setAcctId(account.getAcctId());
picaUser.setMobile(account.getMobilePhone());
picaUser.setName(EncryptCreateUtil.dencrypt(account.getMobilePhone()).replaceAll("(\\d{3})\\d{4}(\\w{4})", "$1****$2"));
picaUser.setCreated_time(account.getCreatTime());
Map<String, String> data = Object2Map.objectToMapString("yyyy-MM-dd HH:mm:ss", picaUser, new String[0]);
data.put("sysCode", sourceType);
data.forEach((key, value) -> {
value = value == null ? "" : value;
cacheClient.hset(tokenValue, key, value);
});
}
} catch (Exception ex) {
logger.error("生成H5 token异常:{}" + ex.getMessage(), ex);
}
return newToken;
}
} }
package com.pica.cloud.account.account.server.controller; package com.pica.cloud.account.account.server.controller;
import com.alibaba.fastjson.JSONObject;
import com.pica.cloud.account.account.server.entity.Account; import com.pica.cloud.account.account.server.entity.Account;
import com.pica.cloud.account.account.server.entity.AccountUnion; import com.pica.cloud.account.account.server.entity.AccountUnion;
import com.pica.cloud.account.account.server.entity.AccountUser; import com.pica.cloud.account.account.server.entity.AccountUser;
import com.pica.cloud.account.account.server.req.SysCodeReq; import com.pica.cloud.account.account.server.req.SysCodeReq;
import com.pica.cloud.account.account.server.service.AccountService; import com.pica.cloud.account.account.server.service.AccountService;
import com.pica.cloud.account.account.server.service.AccountUnionServer; import com.pica.cloud.account.account.server.service.AccountUnionService;
import com.pica.cloud.account.account.server.util.AccountUtils; import com.pica.cloud.account.account.server.util.AccountUtils;
import com.pica.cloud.account.account.server.util.RSAUtils;
import com.pica.cloud.foundation.entity.PicaException; import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResponse; import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.redis.CacheClient; import com.pica.cloud.foundation.redis.ICacheClient;
import com.pica.cloud.foundation.utils.utils.CommonUtil; import com.pica.cloud.foundation.utils.utils.CommonUtil;
import com.pica.cloud.foundation.utils.utils.EncryptCreateUtil; import com.pica.cloud.foundation.utils.utils.EncryptCreateUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Api("短信验证码") @Api("短信验证码")
@RestController @RestController
...@@ -34,34 +30,35 @@ public class SysCodeController extends AccountBaseController { ...@@ -34,34 +30,35 @@ public class SysCodeController extends AccountBaseController {
private AccountService accountService; private AccountService accountService;
@Autowired @Autowired
private AccountUnionServer accountUnionServer; private AccountUnionService accountUnionServer;
@Autowired @Autowired
private CacheClient cacheClient; @Qualifier("cacheMigrateClient")
private ICacheClient cacheClient;
// TODO: 2019/8/22 获取次数有限制 还没有处理
@ApiOperation("获取短信验证码") @ApiOperation("获取短信验证码")
@GetMapping(value = "") @PostMapping(value = "")
public PicaResponse getSysCode(@RequestBody String params) throws Exception { public PicaResponse getSysCode(@RequestBody String params) throws Exception {
String json = RSAUtils.decrypt(params, RSAUtils.getPrivateKey()); SysCodeReq sysCodeReq = AccountUtils.getRequestEntity(params, SysCodeReq.class);
SysCodeReq sysCodeReq = JSONObject.parseObject(json, SysCodeReq.class);
AccountUtils.checkMobilePhone(sysCodeReq.getMobilePhone()); AccountUtils.checkMobilePhone(sysCodeReq.getMobilePhone());
processSysCode(sysCodeReq.getMobilePhone(), sysCodeReq.getFlag()); processSysCode(sysCodeReq.getMobilePhone(), sysCodeReq.getFlag());
return PicaResponse.toResponse(StringUtils.EMPTY); return PicaResponse.toResponse();
} }
@ApiOperation("微信获取短信验证码") @ApiOperation("微信获取短信验证码")
@GetMapping(value = "/wechat") @GetMapping(value = "/wechat")
public PicaResponse getWeChatSysCode(String params) throws Exception { public PicaResponse getWeChatSysCode(String params) throws Exception {
AccountUser accountUser = super.getAccountUser(); AccountUser accountUser = super.getAccountUser();
String token = accountUser.getToken(); String token = accountUser.getToken();
if (StringUtils.isNotEmpty(token)) { if (StringUtils.isNotEmpty(token)) {
String json = RSAUtils.decrypt(params, RSAUtils.getPrivateKey()); SysCodeReq sysCodeReq = AccountUtils.getRequestEntity(params, SysCodeReq.class);
SysCodeReq sysCodeReq = JSONObject.parseObject(json, SysCodeReq.class);
AccountUtils.checkMobilePhone(sysCodeReq.getMobilePhone()); AccountUtils.checkMobilePhone(sysCodeReq.getMobilePhone());
//联合登录表查询是否存在记录 //联合登录表查询是否存在记录
sysCodeReq.setAcctId(accountUser.getAcctId()); sysCodeReq.setAcctId(accountUser.getAcctId());
sysCodeReq.setUnionId(sysCodeReq.getUnionId()); sysCodeReq.setUnionId(sysCodeReq.getUnionId());
//todo:是否绑定过微信
AccountUnion accountUnion = accountUnionServer.selectByUnionIdAndAcctId(sysCodeReq); AccountUnion accountUnion = accountUnionServer.selectByUnionIdAndAcctId(sysCodeReq);
if (accountUnion == null) { if (accountUnion == null) {
processSysCode(sysCodeReq.getMobilePhone(), sysCodeReq.getFlag()); processSysCode(sysCodeReq.getMobilePhone(), sysCodeReq.getFlag());
...@@ -93,11 +90,8 @@ public class SysCodeController extends AccountBaseController { ...@@ -93,11 +90,8 @@ public class SysCodeController extends AccountBaseController {
super.sendMobileMessage(mobilePhone, message, senderId); super.sendMobileMessage(mobilePhone, message, senderId);
} }
//获取验证码redis key //获取验证码redis key
private String getAuthCodeKey(String mobilePhone, String flag) { private String getAuthCodeKey(String mobilePhone, String flag) {
return AUTH_CODE_PREFIX + flag + "-" + EncryptCreateUtil.encrypt(mobilePhone); return AUTH_CODE_PREFIX + flag + "-" + EncryptCreateUtil.encrypt(mobilePhone);
} }
} }
...@@ -15,6 +15,16 @@ public class AccountUnion { ...@@ -15,6 +15,16 @@ public class AccountUnion {
private String headImgUrl; private String headImgUrl;
private int sex;
private String country;
private String province;
private String city;
private String language;
private Integer deleteFlag; private Integer deleteFlag;
private Long createdId; private Long createdId;
...@@ -54,7 +64,7 @@ public class AccountUnion { ...@@ -54,7 +64,7 @@ public class AccountUnion {
} }
public void setUnionId(String unionId) { public void setUnionId(String unionId) {
this.unionId = unionId == null ? null : unionId.trim(); this.unionId = unionId;
} }
public String getNickname() { public String getNickname() {
...@@ -62,7 +72,7 @@ public class AccountUnion { ...@@ -62,7 +72,7 @@ public class AccountUnion {
} }
public void setNickname(String nickname) { public void setNickname(String nickname) {
this.nickname = nickname == null ? null : nickname.trim(); this.nickname = nickname;
} }
public String getHeadImgUrl() { public String getHeadImgUrl() {
...@@ -70,7 +80,47 @@ public class AccountUnion { ...@@ -70,7 +80,47 @@ public class AccountUnion {
} }
public void setHeadImgUrl(String headImgUrl) { public void setHeadImgUrl(String headImgUrl) {
this.headImgUrl = headImgUrl == null ? null : headImgUrl.trim(); this.headImgUrl = headImgUrl;
}
public int getSex() {
return sex;
}
public void setSex(int sex) {
this.sex = sex;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
} }
public Integer getDeleteFlag() { public Integer getDeleteFlag() {
......
...@@ -14,6 +14,8 @@ public class AccountUser extends PicaUser { ...@@ -14,6 +14,8 @@ public class AccountUser extends PicaUser {
//登录ip //登录ip
private String loginIp; private String loginIp;
public Integer getAcctId() { public Integer getAcctId() {
return acctId; return acctId;
} }
......
package com.pica.cloud.account.account.server.entity;
import java.util.Date;
public class AccountWeChatInfo {
private Long id;
private String unionid;
private String openid;
private Integer type;
private String privilege;
private Integer subscribe;
private Date subscribeTime;
private String remark;
private String groupid;
private String tagidList;
private Integer deleteFlag;
private Long createdId;
private Date createdTime;
private Long modifiedId;
private Date modifiedTime;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUnionid() {
return unionid;
}
public void setUnionid(String unionid) {
this.unionid = unionid == null ? null : unionid.trim();
}
public String getOpenid() {
return openid;
}
public void setOpenid(String openid) {
this.openid = openid == null ? null : openid.trim();
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public String getPrivilege() {
return privilege;
}
public void setPrivilege(String privilege) {
this.privilege = privilege == null ? null : privilege.trim();
}
public Integer getSubscribe() {
return subscribe;
}
public void setSubscribe(Integer subscribe) {
this.subscribe = subscribe;
}
public Date getSubscribeTime() {
return subscribeTime;
}
public void setSubscribeTime(Date subscribeTime) {
this.subscribeTime = subscribeTime;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark == null ? null : remark.trim();
}
public String getGroupid() {
return groupid;
}
public void setGroupid(String groupid) {
this.groupid = groupid == null ? null : groupid.trim();
}
public String getTagidList() {
return tagidList;
}
public void setTagidList(String tagidList) {
this.tagidList = tagidList == null ? null : tagidList.trim();
}
public Integer getDeleteFlag() {
return deleteFlag;
}
public void setDeleteFlag(Integer deleteFlag) {
this.deleteFlag = deleteFlag;
}
public Long getCreatedId() {
return createdId;
}
public void setCreatedId(Long createdId) {
this.createdId = createdId;
}
public Date getCreatedTime() {
return createdTime;
}
public void setCreatedTime(Date createdTime) {
this.createdTime = createdTime;
}
public Long getModifiedId() {
return modifiedId;
}
public void setModifiedId(Long modifiedId) {
this.modifiedId = modifiedId;
}
public Date getModifiedTime() {
return modifiedTime;
}
public void setModifiedTime(Date modifiedTime) {
this.modifiedTime = modifiedTime;
}
}
\ No newline at end of file
package com.pica.cloud.account.account.server.entity;
import java.util.Date;
public class WeChatEntity {
/** 获取到的凭证 */
private String accessToken;
/** 凭证有效时间,单位:秒 */
private int expiresIn;
/** 用户刷新access_token */
private String refreshToken;
/** 用户唯一标识,请注意,在未关注公众号时,用户访问公众号的网页,也会产生一个用户和公众号唯一的OpenID */
private String openId;
/** 用户授权的作用域,使用逗号(,)分隔 */
private String scope;
private Date createdAt;
public String getAccessToken() {
return accessToken;
}
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
public int getExpiresIn() {
return expiresIn;
}
public void setExpiresIn(int expiresIn) {
this.expiresIn = expiresIn;
}
public String getRefreshToken() {
return refreshToken;
}
public void setRefreshToken(String refreshToken) {
this.refreshToken = refreshToken;
}
public String getOpenId() {
return openId;
}
public void setOpenId(String openId) {
this.openId = openId;
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
}
package com.pica.cloud.account.account.server.enums;
public enum EnumsType {
//登录类型枚举
LOGIN_CODE(1, "验证码登录"),
LOGIN_PWD(2, "密码登录"),
LOGIN_WE_CHAT(3, "微信登录"),
LOGIN_OUT(4, "退出登录"),
LOGIN_REGISTER(5, "注册登录"),
//登录态相关枚举
LOGIN_STATUS_SUCCESS(1, "登录成功"),
LOGIN_STATUS_FAILURE(2, "登录失败"),
//产品来源相关枚举
PRODUCT_TYPE_DOCTOR(1, "云鹊医产品系"),
PRODUCT_TYPE_HEALTH(2, "云鹊健康产品系"),
//终端类型
DEVICE_TYPE_ANDROID(1, "安卓"),
DEVICE_TYPE_IOS(2, "ios"),
DEVICE_TYPE_WEB(3, "web"),
DEVICE_TYPE_H5(4, "H5"),
DEVICE_TYPE_ADMIN(5, "admin"),
//验证码获取类型: flag:0登录(默认)1注册 2微信登录绑定手机 3修改手机 4重置密码
SYSCODE_TYPE_LOGIN(0, "登录"),
SYSCODE_TYPE_REGISTER(1, "注册"),
SYSCODE_TYPE_WE_CHAT(2, "微信登录绑定手机"),
SYSCODE_TYPE_MODIFY_MOBILE(3, "修改手机号"),
SYSCODE_TYPE_RESET_PASSWORD(4, "重置密码"),
//联合登录类型
UNION_LOGIN_WE_CHAT(1,"微信"),
UNION_LOGIN_QQ(2,"QQ"),
union_login_blog(3,"微博");
private int code;
private String type;
EnumsType(int code, String type) {
this.code = code;
this.type = type;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
package com.pica.cloud.account.account.server.enums;
public enum ExceptionType {
PICA_NOT_EMPTY("216501", "字段非空提示信息"),
PICA_MOBILE_ERROR("216502", "请输入正确的手机号"),
PICA_SYSCODE_ERROR("216503", "短信验证码错误"),
PICA_SYSCODE_EXPIRE("216504", "短信验证码已过期,请重新获取"),
PICA_SYSCODE_RESET("216505", "请X秒后重试(获取验证码),请重新获取"),
PICA_SYSCODE_LATER("216506", "验证码获取过于频繁,请隔天后重试"),
PICA_ALREADY_REGISTER("216507", "该手机号已注册,请直接登录"),
PICA_NOT_REGISTER("216508", "未注册,请先注册"),
PICA_PASSWORD_ERROR("216509", "请输入正确的密码"),
PICA_IMAGE_PASSWORD_ERROR("216511", "图形验证码错误"),
PICA_LOGIN_AGAIN("216512", "请重新登录");
private String code;
private String message;
ExceptionType(String code, String message) {
this.code = code;
this.message = message;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
...@@ -4,12 +4,9 @@ package com.pica.cloud.account.account.server.mapper; ...@@ -4,12 +4,9 @@ package com.pica.cloud.account.account.server.mapper;
import com.pica.cloud.account.account.server.entity.AccountInfo; import com.pica.cloud.account.account.server.entity.AccountInfo;
public interface AccountDetailsMapper { public interface AccountDetailsMapper {
int deleteByPrimaryKey(Long id);
int insert(AccountInfo record);
AccountInfo selectByPrimaryKey(Long id); int insert(AccountInfo record);
int updateByPrimaryKey(AccountInfo record); int updateByPrimaryKey(AccountInfo record);
...@@ -33,9 +30,18 @@ public interface AccountDetailsMapper { ...@@ -33,9 +30,18 @@ public interface AccountDetailsMapper {
/** /**
* 更新用户信息 * 更新用户信息
*
* @param record * @param record
* @return * @return
*/ */
int updateByPrimaryKeySelective(AccountInfo record); int updateByPrimaryKeySelective(AccountInfo record);
/**
* 获取账号详情
*
* @param id
* @return
*/
AccountInfo selectByPrimaryKey(Long id);
} }
\ No newline at end of file
...@@ -12,6 +12,14 @@ public interface AccountProductMapper { ...@@ -12,6 +12,14 @@ public interface AccountProductMapper {
AccountProduct selectByPrimaryKey(Long id); AccountProduct selectByPrimaryKey(Long id);
/**
* 通过acct_id获取产品线类型
*
* @param id
* @return
*/
AccountProduct selectByAccountId(Long id);
int updateByPrimaryKeySelective(AccountProduct record); int updateByPrimaryKeySelective(AccountProduct record);
int updateByPrimaryKey(AccountProduct record); int updateByPrimaryKey(AccountProduct record);
......
...@@ -15,6 +15,13 @@ public interface AccountUnionMapper { ...@@ -15,6 +15,13 @@ public interface AccountUnionMapper {
AccountUnion selectByUnionIdAndAcctId(SysCodeReq sysCodeReq); AccountUnion selectByUnionIdAndAcctId(SysCodeReq sysCodeReq);
/**
* 绑定关系
* @param acctId
* @param productType
*/
void updateUnBindInfo(Long acctId,Integer productType);
int insert(AccountUnion record); int insert(AccountUnion record);
...@@ -22,9 +29,10 @@ public interface AccountUnionMapper { ...@@ -22,9 +29,10 @@ public interface AccountUnionMapper {
AccountUnion selectByPrimaryKey(Long id); AccountUnion selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(AccountUnion record); int updateByPrimaryKeySelective(AccountUnion record);
int updateByPrimaryKey(AccountUnion record); int updateByPrimaryKey(AccountUnion record);
} }
\ No newline at end of file
package com.pica.cloud.account.account.server.mapper;
import com.pica.cloud.account.account.server.entity.AccountWeChatInfo;
public interface AccountWeChatInfoMapper {
int deleteByPrimaryKey(Long id);
int insert(AccountWeChatInfo record);
int insertSelective(AccountWeChatInfo record);
AccountWeChatInfo selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(AccountWeChatInfo record);
int updateByPrimaryKey(AccountWeChatInfo record);
}
\ No newline at end of file
...@@ -16,14 +16,14 @@ public class RegisterReq { ...@@ -16,14 +16,14 @@ public class RegisterReq {
private String inviteCode; private String inviteCode;
@ApiModelProperty("验证码标记") @ApiModelProperty("验证码标记")
private String flag; private String flag;
@ApiModelProperty("注册终端")
public String getFlag() { private int sourceType;
return flag; @ApiModelProperty("产品线类型")
} private int productType;
@ApiModelProperty("注册ip")
public void setFlag(String flag) { private String ipAddress;
this.flag = flag; @ApiModelProperty("微信授权码")
} private String code;
public String getMobile() { public String getMobile() {
return mobile; return mobile;
...@@ -56,6 +56,46 @@ public class RegisterReq { ...@@ -56,6 +56,46 @@ public class RegisterReq {
public void setInviteCode(String inviteCode) { public void setInviteCode(String inviteCode) {
this.inviteCode = inviteCode; this.inviteCode = inviteCode;
} }
public String getFlag() {
return flag;
}
public void setFlag(String flag) {
this.flag = flag;
}
public int getSourceType() {
return sourceType;
}
public void setSourceType(int sourceType) {
this.sourceType = sourceType;
}
public int getProductType() {
return productType;
}
public void setProductType(int productType) {
this.productType = productType;
}
public String getIpAddress() {
return ipAddress;
}
public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
} }
......
...@@ -2,7 +2,7 @@ package com.pica.cloud.account.account.server.service; ...@@ -2,7 +2,7 @@ package com.pica.cloud.account.account.server.service;
import com.pica.cloud.account.account.server.entity.AccountContact; import com.pica.cloud.account.account.server.entity.AccountContact;
public interface AccountContactServer { public interface AccountContactService {
AccountContact selectByMobile(String mobile); AccountContact selectByMobile(String mobile);
......
...@@ -4,9 +4,11 @@ import com.pica.cloud.account.account.server.entity.AccountUser; ...@@ -4,9 +4,11 @@ import com.pica.cloud.account.account.server.entity.AccountUser;
import com.pica.cloud.account.account.server.entity.LoginLog; import com.pica.cloud.account.account.server.entity.LoginLog;
/** /**
* 退出登录 * 登录相关操作
*/ */
public interface AccountLoginOutService { public interface AccountLoginService {
void insertLoginLog(AccountUser accountUser); void insertLoginLog(AccountUser accountUser,Integer loginType,Integer loginStatus);
boolean checkLogin(String mobile,String password);
} }
...@@ -4,5 +4,5 @@ package com.pica.cloud.account.account.server.service; ...@@ -4,5 +4,5 @@ package com.pica.cloud.account.account.server.service;
public interface AccountProductService { public interface AccountProductService {
int insertSelective(Integer acctId,Integer productType); void insertSelective(Integer acctId,Integer productType);
} }
...@@ -3,7 +3,7 @@ package com.pica.cloud.account.account.server.service; ...@@ -3,7 +3,7 @@ package com.pica.cloud.account.account.server.service;
import com.pica.cloud.account.account.server.entity.AccountUnion; import com.pica.cloud.account.account.server.entity.AccountUnion;
import com.pica.cloud.account.account.server.req.SysCodeReq; import com.pica.cloud.account.account.server.req.SysCodeReq;
public interface AccountUnionServer { public interface AccountUnionService {
AccountUnion selectByUnionIdAndAcctId(SysCodeReq sysCodeReq); AccountUnion selectByUnionIdAndAcctId(SysCodeReq sysCodeReq);
......
package com.pica.cloud.account.account.server.service;
import com.pica.cloud.account.account.server.entity.AccountProduct;
public interface AccountWeChatService {
AccountProduct selectByAccountId(Integer acctId);
void updateUnBindInfo(Integer acctId,Integer productType);
}
package com.pica.cloud.account.account.server.service;
import com.pica.cloud.account.account.server.req.RegisterReq;
import com.pica.cloud.foundation.entity.PicaResponse;
public interface RegisterService {
PicaResponse register(RegisterReq registerReq);
}
...@@ -2,7 +2,7 @@ package com.pica.cloud.account.account.server.service.impl; ...@@ -2,7 +2,7 @@ package com.pica.cloud.account.account.server.service.impl;
import com.pica.cloud.account.account.server.entity.AccountContact; import com.pica.cloud.account.account.server.entity.AccountContact;
import com.pica.cloud.account.account.server.mapper.AccountContactMapper; import com.pica.cloud.account.account.server.mapper.AccountContactMapper;
import com.pica.cloud.account.account.server.service.AccountContactServer; import com.pica.cloud.account.account.server.service.AccountContactService;
import com.pica.cloud.foundation.utils.utils.EncryptCreateUtil; import com.pica.cloud.foundation.utils.utils.EncryptCreateUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -10,7 +10,7 @@ import org.springframework.stereotype.Service; ...@@ -10,7 +10,7 @@ import org.springframework.stereotype.Service;
import java.util.Date; import java.util.Date;
@Service @Service
public class AccountContactServerImpl implements AccountContactServer { public class AccountContactServiceImpl implements AccountContactService {
@Autowired @Autowired
private AccountContactMapper accountContactMapper; private AccountContactMapper accountContactMapper;
...@@ -30,6 +30,7 @@ public class AccountContactServerImpl implements AccountContactServer { ...@@ -30,6 +30,7 @@ public class AccountContactServerImpl implements AccountContactServer {
accountContact.setCreatedTime(new Date()); accountContact.setCreatedTime(new Date());
accountContact.setModifiedTime(new Date()); accountContact.setModifiedTime(new Date());
accountContact.setDeleteFlag(1); accountContact.setDeleteFlag(1);
accountContactMapper.insertSelective(accountContact);
} }
} }
...@@ -23,7 +23,8 @@ public class AccountDetailsServiceImpl implements AccountDetailsService { ...@@ -23,7 +23,8 @@ public class AccountDetailsServiceImpl implements AccountDetailsService {
accountInfo.setRegTime(new Date()); accountInfo.setRegTime(new Date());
accountInfo.setModifiedTime(new Date()); accountInfo.setModifiedTime(new Date());
accountInfo.setDeleteFlag(1); accountInfo.setDeleteFlag(1);
return accountDetailsMapper.insertSelective(accountInfo); accountDetailsMapper.insertSelective(accountInfo);
return accountInfo.getId().intValue();
} }
@Override @Override
......
package com.pica.cloud.account.account.server.service.impl;
import com.pica.cloud.account.account.server.entity.AccountUser;
import com.pica.cloud.account.account.server.entity.LoginLog;
import com.pica.cloud.account.account.server.mapper.LoginLogMapper;
import com.pica.cloud.account.account.server.service.AccountLoginOutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class AccountLoginOutServiceImpl implements AccountLoginOutService {
@Autowired
private LoginLogMapper loginLogMapper;
@Override
public void insertLoginLog(AccountUser accountUser) {
LoginLog loginLog = new LoginLog();
loginLog.setAcctId(accountUser.getAcctId());
loginLog.setAcctName(accountUser.getName());
loginLog.setCreateId(accountUser.getId());
loginLog.setModifyId(accountUser.getId());
loginLog.setLoginFrom(accountUser.getLoginFrom());
loginLog.setLoginIp(accountUser.getLoginIp());
loginLog.setLoginPlatform(accountUser.getLoginPlatform());
loginLog.setLoginStatus(3);
loginLog.setLoginType(4);
loginLogMapper.insertSelective(loginLog);
}
}
package com.pica.cloud.account.account.server.service.impl;
import com.pica.cloud.account.account.server.entity.AccountContact;
import com.pica.cloud.account.account.server.entity.AccountInfo;
import com.pica.cloud.account.account.server.entity.AccountUser;
import com.pica.cloud.account.account.server.entity.LoginLog;
import com.pica.cloud.account.account.server.mapper.AccountDetailsMapper;
import com.pica.cloud.account.account.server.mapper.LoginLogMapper;
import com.pica.cloud.account.account.server.service.AccountContactService;
import com.pica.cloud.account.account.server.service.AccountLoginService;
import com.pica.cloud.account.account.server.util.AccountUtils;
import com.pica.cloud.foundation.utils.utils.EncryptCreateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class AccountLoginServiceImpl implements AccountLoginService {
@Autowired
private LoginLogMapper loginLogMapper;
@Autowired
private AccountContactService accountContactServer;
@Autowired
private AccountDetailsMapper accountDetailsMapper;
@Override
public void insertLoginLog(AccountUser accountUser, Integer loginType, Integer status) {
LoginLog loginLog = AccountUtils.getLoginLog(accountUser);
loginLog.setLoginStatus(status);
loginLog.setLoginType(loginType);
loginLogMapper.insertSelective(loginLog);
}
@Override
public boolean checkLogin(String mobile, String password) {
AccountContact accountContact = accountContactServer.selectByMobile(EncryptCreateUtil.encrypt(mobile));
if (accountContact != null) {
Integer acctId = accountContact.getAcctId();
AccountInfo accountInfo = accountDetailsMapper.selectByPrimaryKey(acctId.longValue());
String pwd = accountInfo.getPassword();
return password.equals(EncryptCreateUtil.dencrypt(pwd));
}
return false;
}
}
...@@ -16,7 +16,7 @@ public class AccountProductServiceImpl implements AccountProductService { ...@@ -16,7 +16,7 @@ public class AccountProductServiceImpl implements AccountProductService {
@Override @Override
public int insertSelective(Integer acctId, Integer productType) { public void insertSelective(Integer acctId, Integer productType) {
AccountProduct accountProduct = new AccountProduct(); AccountProduct accountProduct = new AccountProduct();
accountProduct.setAcctId(acctId.longValue()); accountProduct.setAcctId(acctId.longValue());
accountProduct.setCreatedId(acctId.longValue()); accountProduct.setCreatedId(acctId.longValue());
...@@ -25,6 +25,6 @@ public class AccountProductServiceImpl implements AccountProductService { ...@@ -25,6 +25,6 @@ public class AccountProductServiceImpl implements AccountProductService {
accountProduct.setModifiedTime(new Date()); accountProduct.setModifiedTime(new Date());
accountProduct.setDeleteFlag(1); accountProduct.setDeleteFlag(1);
accountProduct.setProductType(productType); accountProduct.setProductType(productType);
return accountProductMapper.insertSelective(accountProduct); accountProductMapper.insertSelective(accountProduct);
} }
} }
...@@ -3,12 +3,12 @@ package com.pica.cloud.account.account.server.service.impl; ...@@ -3,12 +3,12 @@ package com.pica.cloud.account.account.server.service.impl;
import com.pica.cloud.account.account.server.entity.AccountUnion; import com.pica.cloud.account.account.server.entity.AccountUnion;
import com.pica.cloud.account.account.server.mapper.AccountUnionMapper; import com.pica.cloud.account.account.server.mapper.AccountUnionMapper;
import com.pica.cloud.account.account.server.req.SysCodeReq; import com.pica.cloud.account.account.server.req.SysCodeReq;
import com.pica.cloud.account.account.server.service.AccountUnionServer; import com.pica.cloud.account.account.server.service.AccountUnionService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
public class AccountUnionServerImpl implements AccountUnionServer { public class AccountUnionServiceImpl implements AccountUnionService {
@Autowired @Autowired
private AccountUnionMapper accountUnionMapper; private AccountUnionMapper accountUnionMapper;
......
...@@ -43,7 +43,7 @@ public class AccountUserInfoServiceImpl implements AccountUserInfoService { ...@@ -43,7 +43,7 @@ public class AccountUserInfoServiceImpl implements AccountUserInfoService {
acctUserInfo.setModifyId(acctId); acctUserInfo.setModifyId(acctId);
acctUserInfo.setModifyTime(new Date()); acctUserInfo.setModifyTime(new Date());
acctUserInfo.setDeleteFlag(1); acctUserInfo.setDeleteFlag(1);
int userId = acctUserInfoMapper.insertSelective(acctUserInfo); acctUserInfoMapper.insertSelective(acctUserInfo);
return userId; return acctUserInfo.getId();
} }
} }
package com.pica.cloud.account.account.server.service.impl;
import com.pica.cloud.account.account.server.entity.AccountProduct;
import com.pica.cloud.account.account.server.mapper.AccountProductMapper;
import com.pica.cloud.account.account.server.mapper.AccountUnionMapper;
import com.pica.cloud.account.account.server.service.AccountWeChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class AccountWeChatServiceImpl implements AccountWeChatService {
@Autowired
private AccountProductMapper accountProductMapper;
@Autowired
private AccountUnionMapper accountUnionMapper;
@Override
public AccountProduct selectByAccountId(Integer acctId) {
return accountProductMapper.selectByAccountId(acctId.longValue());
}
@Override
public void updateUnBindInfo(Integer acctId, Integer productType) {
accountUnionMapper.updateUnBindInfo(acctId.longValue(),productType);
}
}
package com.pica.cloud.account.account.server.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.pica.cloud.account.account.server.enums.EnumsType;
import com.pica.cloud.account.account.server.enums.ExceptionType;
import com.pica.cloud.account.account.server.entity.Account;
import com.pica.cloud.account.account.server.entity.AccountContact;
import com.pica.cloud.account.account.server.entity.AccountInfo;
import com.pica.cloud.account.account.server.entity.AccountUser;
import com.pica.cloud.account.account.server.req.RegisterReq;
import com.pica.cloud.account.account.server.service.*;
import com.pica.cloud.account.account.server.util.AccountUtils;
import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.redis.ICacheClient;
import com.pica.cloud.foundation.utils.utils.EncryptCreateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.*;
@Service
public class RegisterServiceImpl implements RegisterService {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private AccountContactService accountContactServer;
@Autowired
private AccountDetailsService accountDetailsService;
@Autowired
private AccountProductService accountProductService;
@Autowired
private AccountUserInfoService accountUserInfoService;
@Autowired
private AccountLoginService accountLoginOutService;
@Autowired
@Qualifier("cacheMigrateClient")
private ICacheClient cacheClient;
@Override
public PicaResponse register(RegisterReq registerReq) {
String mobile = registerReq.getMobile();
String password = registerReq.getPassword();
//校验用户用户是否已经存在
AccountContact accountContact = accountContactServer.selectByMobile(EncryptCreateUtil.encrypt(mobile));
if (accountContact == null) {
//账号信息表
AccountInfo accountInfo = new AccountInfo();
accountInfo.setPassword(EncryptCreateUtil.encrypt(password));
accountInfo.setRegisterSource(registerReq.getSourceType());
accountDetailsService.insertAccountInfo(accountInfo);
Integer acctId = accountInfo.getId().intValue();
accountDetailsService.updateAccountInfo(acctId);
//账号产品线表
accountProductService.insertSelective(acctId, registerReq.getProductType());
//账号联系人表
accountContactServer.insertSelective(mobile, acctId);
//用户信息表
Integer userId = accountUserInfoService.insertUserInfo(acctId);
Account account = new Account();
account.setId(userId.longValue());
account.setAcctId(acctId);
account.setCreatTime(new Date());
account.setMobilePhone(mobile);
account.setRegisterSource(registerReq.getSourceType());
String newToken = this.generateToken(account);
JSONObject jsonObject = new JSONObject();
jsonObject.put("token", newToken);
jsonObject.put("userId", userId);
//保存用户登陆成功状态
AccountUser accountUser = cacheClient.getToken(newToken, AccountUser.class);
accountUser.setLoginFrom(registerReq.getSourceType());
accountUser.setLoginPlatform(registerReq.getProductType());
accountUser.setLoginIp(registerReq.getIpAddress());
accountUser.setId(userId);
accountLoginOutService.insertLoginLog(accountUser, EnumsType.LOGIN_REGISTER.getCode(), EnumsType.LOGIN_STATUS_SUCCESS.getCode());
return PicaResponse.toResponse(jsonObject.toJSONString());
} else {
throw new PicaException(ExceptionType.PICA_ALREADY_REGISTER.getCode(), ExceptionType.PICA_ALREADY_REGISTER.getMessage());
}
}
/**
* 生成新的token
*
* @param account
* @return
*/
private String generateToken(Account account) {
String sourceType = AccountUtils.getSourceType(account.getRegisterSource());
String newToken = org.apache.commons.lang3.StringUtils.EMPTY;
try {
String value = "token-doctor-" + account.getId().toString();
//生成新token
int expiredSeconds = 30 * 24 * 60 * 60;//token有效期30天
newToken = UUID.randomUUID().toString().replace("-", "").toUpperCase();
String Key = "token-" + newToken;
//存储token:(token-FF9FCB0D93A642328A01C279701B7607:token-doctor-1)
cacheClient.set(Key, value, expiredSeconds);
//存储token:(token-doctor-12345678-app:token-FF9FCB0D93A642328A01C279701B7607)
cacheClient.set(value + sourceType, Key, expiredSeconds);
//用户数据放入缓存
String userData = cacheClient.hget(value, "id");
if (org.apache.commons.lang3.StringUtils.isEmpty(userData)) {
Map<String, String> data = new HashMap<>();
data.put("token", newToken);
data.put("id", account.getId() + "");
data.put("acctId", account.getAcctId() + "");
data.put("mobile", account.getMobilePhone());
data.put("name", account.getMobilePhone().replaceAll("(\\d{3})\\d{4}(\\w{4})", "$1****$2"));
data.put("created_time", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(account.getCreatTime()));
data.put("sysCode", sourceType);
Iterator<Map.Entry<String, String>> iterator = data.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, String> map = iterator.next();
String key = map.getKey();
String valueInfo = map.getValue();
//存储token:(token-doctor-1:用户数据)
cacheClient.hset(value, key, valueInfo);
}
}
} catch (Exception ex) {
logger.error("生成token异常:{}" + ex.getMessage(), ex);
}
return newToken;
}
}
package com.pica.cloud.account.account.server.util; package com.pica.cloud.account.account.server.util;
import com.alibaba.fastjson.JSONObject;
import com.pica.cloud.account.account.server.entity.AccountContact;
import com.pica.cloud.account.account.server.entity.AccountUser;
import com.pica.cloud.account.account.server.entity.LoginLog;
import com.pica.cloud.account.account.server.service.AccountContactService;
import com.pica.cloud.foundation.entity.PicaException; import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResultCode; import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.foundation.redis.CacheClient; import com.pica.cloud.foundation.redis.ICacheClient;
import com.pica.cloud.foundation.utils.utils.EncryptCreateUtil; import com.pica.cloud.foundation.utils.utils.EncryptCreateUtil;
import com.pica.cloud.foundation.utils.utils.ValidateUtils; import com.pica.cloud.foundation.utils.utils.ValidateUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
...@@ -16,7 +22,11 @@ import org.springframework.stereotype.Component; ...@@ -16,7 +22,11 @@ import org.springframework.stereotype.Component;
public class AccountUtils { public class AccountUtils {
@Autowired @Autowired
private CacheClient cacheClient; private AccountContactService accountContactServer;
@Autowired
@Qualifier("cacheMigrateClient")
private ICacheClient cacheClient;
private static final String AUTH_CODE_PREFIX = "authCode-"; private static final String AUTH_CODE_PREFIX = "authCode-";
...@@ -50,5 +60,85 @@ public class AccountUtils { ...@@ -50,5 +60,85 @@ public class AccountUtils {
cacheClient.del(authCodeKey); cacheClient.del(authCodeKey);
} }
//手机号和验证码校验
public void checkMobilePhoneAndAuthCode(String mobile, String type, String sysCode) {
if (StringUtils.isBlank(mobile) || !ValidateUtils.isMobile(mobile)) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "请输入正确的手机号");
}
String flag = org.apache.commons.lang.StringUtils.isBlank(type) ? "0" : type;
if (org.apache.commons.lang.StringUtils.isBlank(sysCode)) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "短信验证码错误");
}
String authCodeKey = AccountUtils.getAuthCodeKey(mobile, flag);
String cacheCode = cacheClient.get(authCodeKey); //从redis获取验证码
if (org.apache.commons.lang.StringUtils.isBlank(cacheCode)) {
throw new PicaException(PicaResultCode.RESULE_DATA_NONE.code(), "短信验证码已过期,请重新获取");
}
if (!org.apache.commons.lang.StringUtils.equals(sysCode, cacheCode)) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "短信验证码错误");
}
cacheClient.del(authCodeKey);
}
/**
* 登陆日志工具类
*
* @return
*/
public static LoginLog getLoginLog(AccountUser accountUser) {
LoginLog loginLog = new LoginLog();
loginLog.setAcctId(accountUser.getAcctId());
loginLog.setAcctName(accountUser.getName());
loginLog.setCreateId(accountUser.getId());
loginLog.setModifyId(accountUser.getId());
loginLog.setLoginFrom(accountUser.getLoginFrom());
loginLog.setLoginIp(accountUser.getLoginIp());
loginLog.setLoginPlatform(accountUser.getLoginPlatform());
return loginLog;
}
/**
* 请求参数解密、反序列化
*
* @param params
* @param zClass
* @param <T>
* @return
*/
public static <T> T getRequestEntity(String params, Class<T> zClass) throws Exception {
// String json = RSAUtils.decryptByPrivateKey(params,RSAUtils.PRIVATE_KEY);
return JSONObject.parseObject(params, zClass);
}
/**
* 获取终端来源
*
* @param registerSource
* @return
*/
public static String getSourceType(Integer registerSource) {
String sourceType = null;
if (registerSource == 4) {
sourceType = "h5";
} else if (registerSource == 3) {
sourceType = "web";
} else if (registerSource == 5) {
sourceType = "admin";
} else {
sourceType = "app";
}
return sourceType;
}
/**
* 校验手机号是否注册过
*
* @param mobile
*/
public boolean checkRegisterMobile(String mobile) {
String encrypt = EncryptCreateUtil.encrypt(mobile);
AccountContact accountContact = accountContactServer.selectByMobile(encrypt);
return (accountContact != null && accountContact.getAcctId() != null);
}
} }
package com.pica.cloud.account.account.server.util;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import java.security.MessageDigest;
public class BASE64Utils {
public static final String KEY_SHA = "SHA";
public static final String KEY_MD5 = "MD5";
/**
* BASE64解密
*
* @param key
* @return
* @throws Exception
*/
public static byte[] decryptBASE64(String key) throws Exception {
return (new BASE64Decoder()).decodeBuffer(key);
}
/**
* BASE64加密
*
* @param key
* @return
* @throws Exception
*/
public static String encryptBASE64(byte[] key) throws Exception {
return (new BASE64Encoder()).encodeBuffer(key);
}
/**
* MD5加密
*
* @param data
* @return
* @throws Exception
*/
public static byte[] encryptMD5(byte[] data) throws Exception {
MessageDigest md5 = MessageDigest.getInstance(KEY_MD5);
md5.update(data);
return md5.digest();
}
/**
* SHA加密
*
* @param data
* @return
* @throws Exception
*/
public static byte[] encryptSHA(byte[] data) throws Exception {
MessageDigest sha = MessageDigest.getInstance(KEY_SHA);
sha.update(data);
return sha.digest();
}
}
package com.pica.cloud.account.account.server.util;
import com.pica.cloud.account.account.server.entity.Account;
import com.pica.cloud.foundation.redis.ICacheClient;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
/**
* Token工具类
*/
@Component
public class TokenUtils {
@Autowired
@Qualifier("cacheMigrateClient")
private ICacheClient cacheClient;
/**
* 校验token的状态
*
* @param token
* @return
*/
public boolean checkTokenStatus(String token) {
String str = cacheClient.get("token-" + token);
return StringUtils.isBlank(str);
}
/**
* 生成随机token
*
* @param account
* @return
*/
public String generateToken(Account account) {
//判断用户终端类型
String sourceType = AccountUtils.getSourceType(account.getRegisterSource());
String newToken = StringUtils.EMPTY;
//用户唯一key
String tokenDoctorId = "token-doctor-" + account.getId().toString();
//清除旧token对应的用户id
String oldToken = cacheClient.get(tokenDoctorId + "-" + sourceType);
if (StringUtils.isNoneBlank(oldToken)) {
cacheClient.del(oldToken);
}
//生成新的token,并和用户唯一key绑定
newToken = UUID.randomUUID().toString().replace("-", "").toUpperCase();
int expiredSeconds = 30 * 24 * 60 * 60;
cacheClient.set("token-" + newToken, tokenDoctorId, expiredSeconds);
//存储当前登录终端对应的token
cacheClient.set(tokenDoctorId + "-" + sourceType, "token-" + newToken, expiredSeconds);
String userData = cacheClient.hget(tokenDoctorId, "id");
if (StringUtils.isEmpty(userData)) {
Map<String, String> map = new HashMap<>();
map.put("token", newToken);
map.put("id", account.getId() + "");
map.put("acctId", account.getAcctId() + "");
map.put("mobile", account.getMobilePhone());
map.put("name", account.getMobilePhone().replaceAll("(\\d{3})\\d{4}(\\w{4})", "$1****$2"));
map.put("created_time", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(account.getCreatTime()));
map.put("sysCode", sourceType);
Iterator<Map.Entry<String, String>> iterator = map.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, String> mapData = iterator.next();
String key = mapData.getKey();
String valueInfo = mapData.getValue();
//存储token:(token-doctor-1:用户数据)
cacheClient.hset(tokenDoctorId, key, valueInfo);
}
}
return newToken;
}
}
...@@ -24,18 +24,18 @@ ...@@ -24,18 +24,18 @@
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long"> <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">
select select
<include refid="Base_Column_List"/> <include refid="Base_Column_List"/>
from accout_info from account_info
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</select> </select>
<!--通过id更新密码--> <!--通过id更新密码-->
<update id="updatePasswordById" parameterType="com.pica.cloud.account.account.server.entity.AccountInfo"> <update id="updatePasswordById" parameterType="com.pica.cloud.account.account.server.entity.AccountInfo">
update accout_info set password=#{password,jdbcType=VARCHAR} where id=#{id} update account_info set password=#{password,jdbcType=VARCHAR} where id=#{id}
</update> </update>
<!--插入用户信息--> <!--插入用户信息,返回新的账户主键-->
<insert id="insertSelective" parameterType="com.pica.cloud.account.account.server.entity.AccountInfo"> <insert id="insertSelective" parameterType="com.pica.cloud.account.account.server.entity.AccountInfo" useGeneratedKeys="true" keyProperty="id" >
insert into accout_info insert into account_info
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null"> <if test="id != null">
id, id,
...@@ -128,7 +128,7 @@ ...@@ -128,7 +128,7 @@
<!--更新用户信息--> <!--更新用户信息-->
<update id="updateByPrimaryKeySelective" parameterType="com.pica.cloud.account.account.server.entity.AccountInfo"> <update id="updateByPrimaryKeySelective" parameterType="com.pica.cloud.account.account.server.entity.AccountInfo">
update accout_info update account_info
<set> <set>
<if test="password != null"> <if test="password != null">
password = #{password,jdbcType=VARCHAR}, password = #{password,jdbcType=VARCHAR},
...@@ -179,7 +179,7 @@ ...@@ -179,7 +179,7 @@
<insert id="insert" parameterType="com.pica.cloud.account.account.server.entity.AccountInfo"> <insert id="insert" parameterType="com.pica.cloud.account.account.server.entity.AccountInfo">
insert into accout_info (id, password, name, insert into account_info (id, password, name,
age, birthday, sex, id_card, age, birthday, sex, id_card,
reg_time, register_source, delete_flag, reg_time, register_source, delete_flag,
created_id, created_time, modified_id, created_id, created_time, modified_id,
...@@ -196,7 +196,7 @@ ...@@ -196,7 +196,7 @@
<update id="updateByPrimaryKey" parameterType="com.pica.cloud.account.account.server.entity.AccountInfo"> <update id="updateByPrimaryKey" parameterType="com.pica.cloud.account.account.server.entity.AccountInfo">
update accout_info update account_info
set password = #{password,jdbcType=VARCHAR}, set password = #{password,jdbcType=VARCHAR},
name = #{name,jdbcType=VARCHAR}, name = #{name,jdbcType=VARCHAR},
age = #{age,jdbcType=TINYINT}, age = #{age,jdbcType=TINYINT},
......
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.pica.cloud.account.account.server.mapper.AccountProductMapper" > <mapper namespace="com.pica.cloud.account.account.server.mapper.AccountProductMapper">
<resultMap id="BaseResultMap" type="com.pica.cloud.account.account.server.entity.AccountProduct" > <resultMap id="BaseResultMap" type="com.pica.cloud.account.account.server.entity.AccountProduct">
<id column="id" property="id" jdbcType="BIGINT" /> <id column="id" property="id" jdbcType="BIGINT"/>
<result column="acct_id" property="acctId" jdbcType="BIGINT" /> <result column="acct_id" property="acctId" jdbcType="BIGINT"/>
<result column="product_type" property="productType" jdbcType="INTEGER" /> <result column="product_type" property="productType" jdbcType="INTEGER"/>
<result column="delete_flag" property="deleteFlag" jdbcType="INTEGER" /> <result column="delete_flag" property="deleteFlag" jdbcType="INTEGER"/>
<result column="created_id" property="createdId" jdbcType="BIGINT" /> <result column="created_id" property="createdId" jdbcType="BIGINT"/>
<result column="created_time" property="createdTime" jdbcType="TIMESTAMP" /> <result column="created_time" property="createdTime" jdbcType="TIMESTAMP"/>
<result column="modified_id" property="modifiedId" jdbcType="BIGINT" /> <result column="modified_id" property="modifiedId" jdbcType="BIGINT"/>
<result column="modified_time" property="modifiedTime" jdbcType="TIMESTAMP" /> <result column="modified_time" property="modifiedTime" jdbcType="TIMESTAMP"/>
</resultMap> </resultMap>
<sql id="Base_Column_List" > <sql id="Base_Column_List">
id, acct_id, product_type, delete_flag, created_id, created_time, modified_id, modified_time id, acct_id, product_type, delete_flag, created_id, created_time, modified_id, modified_time
</sql> </sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" > <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List"/>
from account_product from account_product
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</select> </select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
<!--通过账户id查询产品线类型-->
<select id="selectByAccountId" resultMap="BaseResultMap" parameterType="java.lang.Long">
select
<include refid="Base_Column_List"/>
from account_product
where acct_id= #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from account_product delete from account_product
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</delete> </delete>
<insert id="insert" parameterType="com.pica.cloud.account.account.server.entity.AccountProduct" > <insert id="insert" parameterType="com.pica.cloud.account.account.server.entity.AccountProduct">
insert into account_product (id, acct_id, product_type, insert into account_product (id, acct_id, product_type,
delete_flag, created_id, created_time, delete_flag, created_id, created_time,
modified_id, modified_time) modified_id, modified_time)
...@@ -32,89 +43,90 @@ ...@@ -32,89 +43,90 @@
#{deleteFlag,jdbcType=INTEGER}, #{createdId,jdbcType=BIGINT}, #{createdTime,jdbcType=TIMESTAMP}, #{deleteFlag,jdbcType=INTEGER}, #{createdId,jdbcType=BIGINT}, #{createdTime,jdbcType=TIMESTAMP},
#{modifiedId,jdbcType=BIGINT}, #{modifiedTime,jdbcType=TIMESTAMP}) #{modifiedId,jdbcType=BIGINT}, #{modifiedTime,jdbcType=TIMESTAMP})
</insert> </insert>
<insert id="insertSelective" parameterType="com.pica.cloud.account.account.server.entity.AccountProduct" > <insert id="insertSelective" parameterType="com.pica.cloud.account.account.server.entity.AccountProduct">
insert into account_product insert into account_product
<trim prefix="(" suffix=")" suffixOverrides="," > <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null" > <if test="id != null">
id, id,
</if> </if>
<if test="acctId != null" > <if test="acctId != null">
acct_id, acct_id,
</if> </if>
<if test="productType != null" > <if test="productType != null">
product_type, product_type,
</if> </if>
<if test="deleteFlag != null" > <if test="deleteFlag != null">
delete_flag, delete_flag,
</if> </if>
<if test="createdId != null" > <if test="createdId != null">
created_id, created_id,
</if> </if>
<if test="createdTime != null" > <if test="createdTime != null">
created_time, created_time,
</if> </if>
<if test="modifiedId != null" > <if test="modifiedId != null">
modified_id, modified_id,
</if> </if>
<if test="modifiedTime != null" > <if test="modifiedTime != null">
modified_time, modified_time,
</if> </if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides="," > <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null" > <if test="id != null">
#{id,jdbcType=BIGINT}, #{id,jdbcType=BIGINT},
</if> </if>
<if test="acctId != null" > <if test="acctId != null">
#{acctId,jdbcType=BIGINT}, #{acctId,jdbcType=BIGINT},
</if> </if>
<if test="productType != null" > <if test="productType != null">
#{productType,jdbcType=INTEGER}, #{productType,jdbcType=INTEGER},
</if> </if>
<if test="deleteFlag != null" > <if test="deleteFlag != null">
#{deleteFlag,jdbcType=INTEGER}, #{deleteFlag,jdbcType=INTEGER},
</if> </if>
<if test="createdId != null" > <if test="createdId != null">
#{createdId,jdbcType=BIGINT}, #{createdId,jdbcType=BIGINT},
</if> </if>
<if test="createdTime != null" > <if test="createdTime != null">
#{createdTime,jdbcType=TIMESTAMP}, #{createdTime,jdbcType=TIMESTAMP},
</if> </if>
<if test="modifiedId != null" > <if test="modifiedId != null">
#{modifiedId,jdbcType=BIGINT}, #{modifiedId,jdbcType=BIGINT},
</if> </if>
<if test="modifiedTime != null" > <if test="modifiedTime != null">
#{modifiedTime,jdbcType=TIMESTAMP}, #{modifiedTime,jdbcType=TIMESTAMP},
</if> </if>
</trim> </trim>
</insert> </insert>
<update id="updateByPrimaryKeySelective" parameterType="com.pica.cloud.account.account.server.entity.AccountProduct" > <update id="updateByPrimaryKeySelective"
update account_product parameterType="com.pica.cloud.account.account.server.entity.AccountProduct">
<set > update account_product
<if test="acctId != null" > <set>
acct_id = #{acctId,jdbcType=BIGINT}, <if test="acctId != null">
</if> acct_id = #{acctId,jdbcType=BIGINT},
<if test="productType != null" > </if>
product_type = #{productType,jdbcType=INTEGER}, <if test="productType != null">
</if> product_type = #{productType,jdbcType=INTEGER},
<if test="deleteFlag != null" > </if>
delete_flag = #{deleteFlag,jdbcType=INTEGER}, <if test="deleteFlag != null">
</if> delete_flag = #{deleteFlag,jdbcType=INTEGER},
<if test="createdId != null" > </if>
created_id = #{createdId,jdbcType=BIGINT}, <if test="createdId != null">
</if> created_id = #{createdId,jdbcType=BIGINT},
<if test="createdTime != null" > </if>
created_time = #{createdTime,jdbcType=TIMESTAMP}, <if test="createdTime != null">
</if> created_time = #{createdTime,jdbcType=TIMESTAMP},
<if test="modifiedId != null" > </if>
modified_id = #{modifiedId,jdbcType=BIGINT}, <if test="modifiedId != null">
</if> modified_id = #{modifiedId,jdbcType=BIGINT},
<if test="modifiedTime != null" > </if>
modified_time = #{modifiedTime,jdbcType=TIMESTAMP}, <if test="modifiedTime != null">
</if> modified_time = #{modifiedTime,jdbcType=TIMESTAMP},
</set> </if>
where id = #{id,jdbcType=BIGINT} </set>
</update> where id = #{id,jdbcType=BIGINT}
<update id="updateByPrimaryKey" parameterType="com.pica.cloud.account.account.server.entity.AccountProduct" > </update>
<update id="updateByPrimaryKey" parameterType="com.pica.cloud.account.account.server.entity.AccountProduct">
update account_product update account_product
set acct_id = #{acctId,jdbcType=BIGINT}, set acct_id = #{acctId,jdbcType=BIGINT},
product_type = #{productType,jdbcType=INTEGER}, product_type = #{productType,jdbcType=INTEGER},
......
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.pica.cloud.account.account.server.mapper.AccountUnionMapper"> <mapper namespace="com.pica.cloud.account.account.server.mapper.AccountUnionMapper">
<resultMap id="BaseResultMap" type="com.pica.cloud.account.account.server.entity.AccountUnion"> <resultMap id="BaseResultMap" type="com.pica.cloud.account.account.server.entity.AccountUnion">
<id column="id" property="id" jdbcType="BIGINT"/> <id column="id" jdbcType="BIGINT" property="id" />
<result column="acct_id" property="acctId" jdbcType="BIGINT"/> <result column="acct_id" jdbcType="BIGINT" property="acctId" />
<result column="union_type" property="unionType" jdbcType="INTEGER"/> <result column="union_type" jdbcType="INTEGER" property="unionType" />
<result column="union_id" property="unionId" jdbcType="VARCHAR"/> <result column="union_id" jdbcType="VARCHAR" property="unionId" />
<result column="nickname" property="nickname" jdbcType="VARCHAR"/> <result column="nickname" jdbcType="VARCHAR" property="nickname" />
<result column="head_img_url" property="headImgUrl" jdbcType="VARCHAR"/> <result column="head_img_url" jdbcType="VARCHAR" property="headImgUrl" />
<result column="delete_flag" property="deleteFlag" jdbcType="INTEGER"/> <result column="sex" jdbcType="TINYINT" property="sex" />
<result column="created_id" property="createdId" jdbcType="BIGINT"/> <result column="country" jdbcType="VARCHAR" property="country" />
<result column="created_time" property="createdTime" jdbcType="TIMESTAMP"/> <result column="province" jdbcType="VARCHAR" property="province" />
<result column="modified_id" property="modifiedId" jdbcType="BIGINT"/> <result column="city" jdbcType="VARCHAR" property="city" />
<result column="modified_time" property="modifiedTime" jdbcType="TIMESTAMP"/> <result column="language" jdbcType="VARCHAR" property="language" />
<result column="delete_flag" jdbcType="INTEGER" property="deleteFlag" />
<result column="created_id" jdbcType="BIGINT" property="createdId" />
<result column="created_time" jdbcType="TIMESTAMP" property="createdTime" />
<result column="modified_id" jdbcType="BIGINT" property="modifiedId" />
<result column="modified_time" jdbcType="TIMESTAMP" property="modifiedTime" />
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, acct_id, union_type, union_id, nickname, head_img_url, delete_flag, created_id, id, acct_id, union_type, union_id, nickname, head_img_url, sex, country, province,
created_time, modified_id, modified_time city, language, delete_flag, created_id, created_time, modified_id, modified_time
</sql> </sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from account_union
where id = #{id,jdbcType=BIGINT}
</select>
<!--查询是否绑定过微信--> <!--查询是否绑定过微信-->
<select id="selectByUnionIdAndAcctId" parameterType="com.pica.cloud.account.account.server.req.SysCodeReq" resultMap="BaseResultMap"> <select id="selectByUnionIdAndAcctId" parameterType="com.pica.cloud.account.account.server.req.SysCodeReq" resultMap="BaseResultMap">
select select
...@@ -27,26 +40,26 @@ ...@@ -27,26 +40,26 @@
where acct_id=#{acctId} and union_id =#{unionId} where acct_id=#{acctId} and union_id =#{unionId}
</select> </select>
<!--解除绑定-->
<update id="updateUnBindInfo" parameterType="com.pica.cloud.account.account.server.entity.AccountUnion">
update account_union
set delete_flag=2
where acct_id = #{acctId,jdbcType=BIGINT} and union_type=#{productType}
</update>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">
select
<include refid="Base_Column_List"/>
from account_union
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from account_union
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="com.pica.cloud.account.account.server.entity.AccountUnion"> <insert id="insert" parameterType="com.pica.cloud.account.account.server.entity.AccountUnion">
insert into account_union (id, acct_id, union_type, insert into account_union (id, acct_id, union_type,
union_id, nickname, head_img_url, union_id, nickname, head_img_url,
delete_flag, created_id, created_time, sex, country, province,
modified_id, modified_time) city, language, delete_flag,
values (#{id,jdbcType=BIGINT}, #{acctId,jdbcType=BIGINT}, #{unionType,jdbcType=INTEGER}, created_id, created_time, modified_id,
#{unionId,jdbcType=VARCHAR}, #{nickname,jdbcType=VARCHAR}, #{headImgUrl,jdbcType=VARCHAR}, modified_time)
#{deleteFlag,jdbcType=INTEGER}, #{createdId,jdbcType=BIGINT}, #{createdTime,jdbcType=TIMESTAMP}, values (#{id,jdbcType=BIGINT}, #{acctId,jdbcType=BIGINT}, #{unionType,jdbcType=INTEGER},
#{modifiedId,jdbcType=BIGINT}, #{modifiedTime,jdbcType=TIMESTAMP}) #{unionId,jdbcType=VARCHAR}, #{nickname,jdbcType=VARCHAR}, #{headImgUrl,jdbcType=VARCHAR},
#{sex,jdbcType=TINYINT}, #{country,jdbcType=VARCHAR}, #{province,jdbcType=VARCHAR},
#{city,jdbcType=VARCHAR}, #{language,jdbcType=VARCHAR}, #{deleteFlag,jdbcType=INTEGER},
#{createdId,jdbcType=BIGINT}, #{createdTime,jdbcType=TIMESTAMP}, #{modifiedId,jdbcType=BIGINT},
#{modifiedTime,jdbcType=TIMESTAMP})
</insert> </insert>
<insert id="insertSelective" parameterType="com.pica.cloud.account.account.server.entity.AccountUnion"> <insert id="insertSelective" parameterType="com.pica.cloud.account.account.server.entity.AccountUnion">
insert into account_union insert into account_union
...@@ -69,6 +82,21 @@ ...@@ -69,6 +82,21 @@
<if test="headImgUrl != null"> <if test="headImgUrl != null">
head_img_url, head_img_url,
</if> </if>
<if test="sex != null">
sex,
</if>
<if test="country != null">
country,
</if>
<if test="province != null">
province,
</if>
<if test="city != null">
city,
</if>
<if test="language != null">
language,
</if>
<if test="deleteFlag != null"> <if test="deleteFlag != null">
delete_flag, delete_flag,
</if> </if>
...@@ -104,6 +132,21 @@ ...@@ -104,6 +132,21 @@
<if test="headImgUrl != null"> <if test="headImgUrl != null">
#{headImgUrl,jdbcType=VARCHAR}, #{headImgUrl,jdbcType=VARCHAR},
</if> </if>
<if test="sex != null">
#{sex,jdbcType=TINYINT},
</if>
<if test="country != null">
#{country,jdbcType=VARCHAR},
</if>
<if test="province != null">
#{province,jdbcType=VARCHAR},
</if>
<if test="city != null">
#{city,jdbcType=VARCHAR},
</if>
<if test="language != null">
#{language,jdbcType=VARCHAR},
</if>
<if test="deleteFlag != null"> <if test="deleteFlag != null">
#{deleteFlag,jdbcType=INTEGER}, #{deleteFlag,jdbcType=INTEGER},
</if> </if>
...@@ -139,6 +182,21 @@ ...@@ -139,6 +182,21 @@
<if test="headImgUrl != null"> <if test="headImgUrl != null">
head_img_url = #{headImgUrl,jdbcType=VARCHAR}, head_img_url = #{headImgUrl,jdbcType=VARCHAR},
</if> </if>
<if test="sex != null">
sex = #{sex,jdbcType=TINYINT},
</if>
<if test="country != null">
country = #{country,jdbcType=VARCHAR},
</if>
<if test="province != null">
province = #{province,jdbcType=VARCHAR},
</if>
<if test="city != null">
city = #{city,jdbcType=VARCHAR},
</if>
<if test="language != null">
language = #{language,jdbcType=VARCHAR},
</if>
<if test="deleteFlag != null"> <if test="deleteFlag != null">
delete_flag = #{deleteFlag,jdbcType=INTEGER}, delete_flag = #{deleteFlag,jdbcType=INTEGER},
</if> </if>
...@@ -164,6 +222,11 @@ ...@@ -164,6 +222,11 @@
union_id = #{unionId,jdbcType=VARCHAR}, union_id = #{unionId,jdbcType=VARCHAR},
nickname = #{nickname,jdbcType=VARCHAR}, nickname = #{nickname,jdbcType=VARCHAR},
head_img_url = #{headImgUrl,jdbcType=VARCHAR}, head_img_url = #{headImgUrl,jdbcType=VARCHAR},
sex = #{sex,jdbcType=TINYINT},
country = #{country,jdbcType=VARCHAR},
province = #{province,jdbcType=VARCHAR},
city = #{city,jdbcType=VARCHAR},
language = #{language,jdbcType=VARCHAR},
delete_flag = #{deleteFlag,jdbcType=INTEGER}, delete_flag = #{deleteFlag,jdbcType=INTEGER},
created_id = #{createdId,jdbcType=BIGINT}, created_id = #{createdId,jdbcType=BIGINT},
created_time = #{createdTime,jdbcType=TIMESTAMP}, created_time = #{createdTime,jdbcType=TIMESTAMP},
...@@ -171,4 +234,6 @@ ...@@ -171,4 +234,6 @@
modified_time = #{modifiedTime,jdbcType=TIMESTAMP} modified_time = #{modifiedTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</update> </update>
</mapper>
\ No newline at end of file </mapper>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.pica.cloud.account.account.server.mapper.AccountWeChatInfoMapper" >
<resultMap id="BaseResultMap" type="com.pica.cloud.account.account.server.entity.AccountWeChatInfo" >
<id column="id" property="id" jdbcType="BIGINT" />
<result column="unionid" property="unionid" jdbcType="VARCHAR" />
<result column="openid" property="openid" jdbcType="VARCHAR" />
<result column="type" property="type" jdbcType="INTEGER" />
<result column="privilege" property="privilege" jdbcType="VARCHAR" />
<result column="subscribe" property="subscribe" jdbcType="INTEGER" />
<result column="subscribe_time" property="subscribeTime" jdbcType="TIMESTAMP" />
<result column="remark" property="remark" jdbcType="VARCHAR" />
<result column="groupid" property="groupid" jdbcType="VARCHAR" />
<result column="tagid_list" property="tagidList" jdbcType="VARCHAR" />
<result column="delete_flag" property="deleteFlag" jdbcType="INTEGER" />
<result column="created_id" property="createdId" jdbcType="BIGINT" />
<result column="created_time" property="createdTime" jdbcType="TIMESTAMP" />
<result column="modified_id" property="modifiedId" jdbcType="BIGINT" />
<result column="modified_time" property="modifiedTime" jdbcType="TIMESTAMP" />
</resultMap>
<sql id="Base_Column_List" >
id, unionid, openid, type, privilege, subscribe, subscribe_time, remark, groupid,
tagid_list, delete_flag, created_id, created_time, modified_id, modified_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
select
<include refid="Base_Column_List" />
from account_wechat_info
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
delete from account_wechat_info
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="com.pica.cloud.account.account.server.entity.AccountWeChatInfo" >
insert into account_wechat_info (id, unionid, openid,
type, privilege, subscribe,
subscribe_time, remark, groupid,
tagid_list, delete_flag, created_id,
created_time, modified_id, modified_time
)
values (#{id,jdbcType=BIGINT}, #{unionid,jdbcType=VARCHAR}, #{openid,jdbcType=VARCHAR},
#{type,jdbcType=INTEGER}, #{privilege,jdbcType=VARCHAR}, #{subscribe,jdbcType=INTEGER},
#{subscribeTime,jdbcType=TIMESTAMP}, #{remark,jdbcType=VARCHAR}, #{groupid,jdbcType=VARCHAR},
#{tagidList,jdbcType=VARCHAR}, #{deleteFlag,jdbcType=INTEGER}, #{createdId,jdbcType=BIGINT},
#{createdTime,jdbcType=TIMESTAMP}, #{modifiedId,jdbcType=BIGINT}, #{modifiedTime,jdbcType=TIMESTAMP}
)
</insert>
<insert id="insertSelective" parameterType="com.pica.cloud.account.account.server.entity.AccountWeChatInfo" >
insert into account_wechat_info
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="unionid != null" >
unionid,
</if>
<if test="openid != null" >
openid,
</if>
<if test="type != null" >
type,
</if>
<if test="privilege != null" >
privilege,
</if>
<if test="subscribe != null" >
subscribe,
</if>
<if test="subscribeTime != null" >
subscribe_time,
</if>
<if test="remark != null" >
remark,
</if>
<if test="groupid != null" >
groupid,
</if>
<if test="tagidList != null" >
tagid_list,
</if>
<if test="deleteFlag != null" >
delete_flag,
</if>
<if test="createdId != null" >
created_id,
</if>
<if test="createdTime != null" >
created_time,
</if>
<if test="modifiedId != null" >
modified_id,
</if>
<if test="modifiedTime != null" >
modified_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=BIGINT},
</if>
<if test="unionid != null" >
#{unionid,jdbcType=VARCHAR},
</if>
<if test="openid != null" >
#{openid,jdbcType=VARCHAR},
</if>
<if test="type != null" >
#{type,jdbcType=INTEGER},
</if>
<if test="privilege != null" >
#{privilege,jdbcType=VARCHAR},
</if>
<if test="subscribe != null" >
#{subscribe,jdbcType=INTEGER},
</if>
<if test="subscribeTime != null" >
#{subscribeTime,jdbcType=TIMESTAMP},
</if>
<if test="remark != null" >
#{remark,jdbcType=VARCHAR},
</if>
<if test="groupid != null" >
#{groupid,jdbcType=VARCHAR},
</if>
<if test="tagidList != null" >
#{tagidList,jdbcType=VARCHAR},
</if>
<if test="deleteFlag != null" >
#{deleteFlag,jdbcType=INTEGER},
</if>
<if test="createdId != null" >
#{createdId,jdbcType=BIGINT},
</if>
<if test="createdTime != null" >
#{createdTime,jdbcType=TIMESTAMP},
</if>
<if test="modifiedId != null" >
#{modifiedId,jdbcType=BIGINT},
</if>
<if test="modifiedTime != null" >
#{modifiedTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.pica.cloud.account.account.server.entity.AccountWeChatInfo" >
update account_wechat_info
<set >
<if test="unionid != null" >
unionid = #{unionid,jdbcType=VARCHAR},
</if>
<if test="openid != null" >
openid = #{openid,jdbcType=VARCHAR},
</if>
<if test="type != null" >
type = #{type,jdbcType=INTEGER},
</if>
<if test="privilege != null" >
privilege = #{privilege,jdbcType=VARCHAR},
</if>
<if test="subscribe != null" >
subscribe = #{subscribe,jdbcType=INTEGER},
</if>
<if test="subscribeTime != null" >
subscribe_time = #{subscribeTime,jdbcType=TIMESTAMP},
</if>
<if test="remark != null" >
remark = #{remark,jdbcType=VARCHAR},
</if>
<if test="groupid != null" >
groupid = #{groupid,jdbcType=VARCHAR},
</if>
<if test="tagidList != null" >
tagid_list = #{tagidList,jdbcType=VARCHAR},
</if>
<if test="deleteFlag != null" >
delete_flag = #{deleteFlag,jdbcType=INTEGER},
</if>
<if test="createdId != null" >
created_id = #{createdId,jdbcType=BIGINT},
</if>
<if test="createdTime != null" >
created_time = #{createdTime,jdbcType=TIMESTAMP},
</if>
<if test="modifiedId != null" >
modified_id = #{modifiedId,jdbcType=BIGINT},
</if>
<if test="modifiedTime != null" >
modified_time = #{modifiedTime,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.pica.cloud.account.account.server.entity.AccountWeChatInfo" >
update account_wechat_info
set unionid = #{unionid,jdbcType=VARCHAR},
openid = #{openid,jdbcType=VARCHAR},
type = #{type,jdbcType=INTEGER},
privilege = #{privilege,jdbcType=VARCHAR},
subscribe = #{subscribe,jdbcType=INTEGER},
subscribe_time = #{subscribeTime,jdbcType=TIMESTAMP},
remark = #{remark,jdbcType=VARCHAR},
groupid = #{groupid,jdbcType=VARCHAR},
tagid_list = #{tagidList,jdbcType=VARCHAR},
delete_flag = #{deleteFlag,jdbcType=INTEGER},
created_id = #{createdId,jdbcType=BIGINT},
created_time = #{createdTime,jdbcType=TIMESTAMP},
modified_id = #{modifiedId,jdbcType=BIGINT},
modified_time = #{modifiedTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>
\ No newline at end of file
...@@ -43,13 +43,13 @@ ...@@ -43,13 +43,13 @@
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer"> <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select select
<include refid="Base_Column_List"/> <include refid="Base_Column_List"/>
from p_user_info from account_user_info
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</select> </select>
<insert id="insert" parameterType="com.pica.cloud.account.account.server.entity.AcctUserInfo"> <insert id="insert" parameterType="com.pica.cloud.account.account.server.entity.AcctUserInfo">
insert into log_user_info_change (id, acct_id, village_name, insert into account_log_user_info_modify (id, acct_id, village_name,
village_id, town_name, town_id, village_id, town_name, town_id,
county_name, county_id, city_name, county_name, county_id, city_name,
city_id, province_name, province_id, city_id, province_name, province_id,
...@@ -71,8 +71,8 @@ ...@@ -71,8 +71,8 @@
#{modifyTime,jdbcType=TIMESTAMP}, #{deleteFlag,jdbcType=TINYINT}) #{modifyTime,jdbcType=TIMESTAMP}, #{deleteFlag,jdbcType=TINYINT})
</insert> </insert>
<insert id="insertSelective" parameterType="com.pica.cloud.account.account.server.entity.AcctUserInfo"> <insert id="insertSelective" parameterType="com.pica.cloud.account.account.server.entity.AcctUserInfo" useGeneratedKeys="true" keyProperty="id" >
insert into p_user_info insert into account_user_info
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null"> <if test="id != null">
id, id,
...@@ -255,7 +255,7 @@ ...@@ -255,7 +255,7 @@
<!--更新用户信息--> <!--更新用户信息-->
<update id="updateByPrimaryKeySelective" parameterType="com.pica.cloud.account.account.server.entity.AcctUserInfo"> <update id="updateByPrimaryKeySelective" parameterType="com.pica.cloud.account.account.server.entity.AcctUserInfo">
update p_user_info update account_user_info
<set> <set>
<if test="acctId != null"> <if test="acctId != null">
acct_id = #{acctId,jdbcType=INTEGER}, acct_id = #{acctId,jdbcType=INTEGER},
...@@ -346,7 +346,7 @@ ...@@ -346,7 +346,7 @@
</update> </update>
<update id="updateByPrimaryKey" parameterType="com.pica.cloud.account.account.server.entity.AcctUserInfo"> <update id="updateByPrimaryKey" parameterType="com.pica.cloud.account.account.server.entity.AcctUserInfo">
update p_user_info update account_user_info
set acct_id = #{acctId,jdbcType=INTEGER}, set acct_id = #{acctId,jdbcType=INTEGER},
village_name = #{villageName,jdbcType=VARCHAR}, village_name = #{villageName,jdbcType=VARCHAR},
village_id = #{villageId,jdbcType=BIGINT}, village_id = #{villageId,jdbcType=BIGINT},
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long"> <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">
select select
<include refid="Base_Column_List"/> <include refid="Base_Column_List"/>
from acct_contact from account_contact
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</select> </select>
...@@ -27,14 +27,14 @@ ...@@ -27,14 +27,14 @@
<select id="selectByMobile" resultMap="BaseResultMap" parameterType="java.lang.String"> <select id="selectByMobile" resultMap="BaseResultMap" parameterType="java.lang.String">
select select
<include refid="Base_Column_List"/> <include refid="Base_Column_List"/>
from acct_contact from account_contact
where mobile = #{mobile_phone} where mobile_phone = #{mobile_phone}
</select> </select>
<!--修改手机号--> <!--修改手机号-->
<update id="updateByPrimaryKeySelective" <update id="updateByPrimaryKeySelective"
parameterType="com.pica.cloud.account.account.server.entity.AccountContact"> parameterType="com.pica.cloud.account.account.server.entity.AccountContact">
update acct_contact update account_contact
<set> <set>
<if test="mobilePhone != null"> <if test="mobilePhone != null">
mobile_phone = #{mobilePhone,jdbcType=VARCHAR}, mobile_phone = #{mobilePhone,jdbcType=VARCHAR},
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
<insert id="insert" parameterType="com.pica.cloud.account.account.server.entity.AccountContact"> <insert id="insert" parameterType="com.pica.cloud.account.account.server.entity.AccountContact">
insert into acct_contact (id, acct_id, mobile_phone, insert into account_contact (id, acct_id, mobile_phone,
delete_flag, created_id, created_time, delete_flag, created_id, created_time,
modified_id, modified_time) modified_id, modified_time)
values (#{id,jdbcType=BIGINT}, #{acctId,jdbcType=INTEGER}, #{mobilePhone,jdbcType=VARCHAR}, values (#{id,jdbcType=BIGINT}, #{acctId,jdbcType=INTEGER}, #{mobilePhone,jdbcType=VARCHAR},
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
</insert> </insert>
<insert id="insertSelective" parameterType="com.pica.cloud.account.account.server.entity.AccountContact"> <insert id="insertSelective" parameterType="com.pica.cloud.account.account.server.entity.AccountContact">
insert into acct_contact insert into account_contact
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null"> <if test="id != null">
id, id,
......
...@@ -19,15 +19,15 @@ ...@@ -19,15 +19,15 @@
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" > <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
from log_password_modify from account_log_password_modify
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</select> </select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long" > <delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
delete from log_password_modify delete from account_log_password_modify
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</delete> </delete>
<insert id="insert" parameterType="com.pica.cloud.account.account.server.entity.LogPasswordModify" > <insert id="insert" parameterType="com.pica.cloud.account.account.server.entity.LogPasswordModify" >
insert into log_password_modify (id, mobile_phone, modified_time, insert into account_log_password_modify (id, mobile_phone, modified_time,
modified_id, old_pwd, new_pwd, modified_id, old_pwd, new_pwd,
delete_flag, created_id, created_time delete_flag, created_id, created_time
) )
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
) )
</insert> </insert>
<insert id="insertSelective" parameterType="com.pica.cloud.account.account.server.entity.LogPasswordModify" > <insert id="insertSelective" parameterType="com.pica.cloud.account.account.server.entity.LogPasswordModify" >
insert into log_password_modify insert into account_log_password_modify
<trim prefix="(" suffix=")" suffixOverrides="," > <trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" > <if test="id != null" >
id, id,
...@@ -98,7 +98,7 @@ ...@@ -98,7 +98,7 @@
</trim> </trim>
</insert> </insert>
<update id="updateByPrimaryKeySelective" parameterType="com.pica.cloud.account.account.server.entity.LogPasswordModify" > <update id="updateByPrimaryKeySelective" parameterType="com.pica.cloud.account.account.server.entity.LogPasswordModify" >
update log_password_modify update account_log_password_modify
<set > <set >
<if test="mobilePhone != null" > <if test="mobilePhone != null" >
mobile_phone = #{mobilePhone,jdbcType=VARCHAR}, mobile_phone = #{mobilePhone,jdbcType=VARCHAR},
...@@ -128,7 +128,7 @@ ...@@ -128,7 +128,7 @@
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</update> </update>
<update id="updateByPrimaryKey" parameterType="com.pica.cloud.account.account.server.entity.LogPasswordModify" > <update id="updateByPrimaryKey" parameterType="com.pica.cloud.account.account.server.entity.LogPasswordModify" >
update log_password_modify update account_log_password_modify
set mobile_phone = #{mobilePhone,jdbcType=VARCHAR}, set mobile_phone = #{mobilePhone,jdbcType=VARCHAR},
modified_time = #{modifiedTime,jdbcType=TIMESTAMP}, modified_time = #{modifiedTime,jdbcType=TIMESTAMP},
modified_id = #{modifiedId,jdbcType=INTEGER}, modified_id = #{modifiedId,jdbcType=INTEGER},
......
...@@ -24,15 +24,15 @@ ...@@ -24,15 +24,15 @@
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
from log_login from account_log_login
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</select> </select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" > <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from log_login delete from account_log_login
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</delete> </delete>
<insert id="insert" parameterType="com.pica.cloud.account.account.server.entity.LoginLog" > <insert id="insert" parameterType="com.pica.cloud.account.account.server.entity.LoginLog" >
insert into log_login (id, acct_id, acct_name, insert into account_log_login (id, acct_id, acct_name,
login_time, login_from, login_type, login_time, login_from, login_type,
login_ip, login_platform, login_status, login_ip, login_platform, login_status,
create_id, create_time, modify_id, create_id, create_time, modify_id,
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
#{modifyTime,jdbcType=TIMESTAMP}, #{deleteFlag,jdbcType=TINYINT}) #{modifyTime,jdbcType=TIMESTAMP}, #{deleteFlag,jdbcType=TINYINT})
</insert> </insert>
<insert id="insertSelective" parameterType="com.pica.cloud.account.account.server.entity.LoginLog" > <insert id="insertSelective" parameterType="com.pica.cloud.account.account.server.entity.LoginLog" >
insert into log_login insert into account_log_login
<trim prefix="(" suffix=")" suffixOverrides="," > <trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" > <if test="id != null" >
id, id,
...@@ -135,7 +135,7 @@ ...@@ -135,7 +135,7 @@
</trim> </trim>
</insert> </insert>
<update id="updateByPrimaryKeySelective" parameterType="com.pica.cloud.account.account.server.entity.LoginLog" > <update id="updateByPrimaryKeySelective" parameterType="com.pica.cloud.account.account.server.entity.LoginLog" >
update log_login update account_log_login
<set > <set >
<if test="acctId != null" > <if test="acctId != null" >
acct_id = #{acctId,jdbcType=INTEGER}, acct_id = #{acctId,jdbcType=INTEGER},
...@@ -180,7 +180,7 @@ ...@@ -180,7 +180,7 @@
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</update> </update>
<update id="updateByPrimaryKey" parameterType="com.pica.cloud.account.account.server.entity.LoginLog" > <update id="updateByPrimaryKey" parameterType="com.pica.cloud.account.account.server.entity.LoginLog" >
update log_login update account_log_login
set acct_id = #{acctId,jdbcType=INTEGER}, set acct_id = #{acctId,jdbcType=INTEGER},
acct_name = #{acctName,jdbcType=VARCHAR}, acct_name = #{acctName,jdbcType=VARCHAR},
login_time = #{loginTime,jdbcType=TIMESTAMP}, login_time = #{loginTime,jdbcType=TIMESTAMP},
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册