提交 2173c002 编写于 作者: rushui.chen's avatar rushui.chen

20190903 用户日志更新记录

上级 f26e5057
流水线 #13963 已失败 于阶段
in 2 second
......@@ -6,11 +6,22 @@ package com.pica.cloud.account.account.server.constants;
*/
public class Constants {
private Constants() {}
private Constants() {
}
public static final String SEND_MESSAGE = "/sms/send";
/** 批量短信url */
/**
* 批量短信url
*/
public static final String BATCH_SEND_MESSAGE = "/sms/send_batch_dif";
//token
public static final String TOKEN = "token";
//用户id
public static final String USER_ID = "userId";
//是否绑定
public static final String BIND_FLAG = "bindFlag";
//联合登录id
public static final String UNION_ID = "unionId";
}
......@@ -5,7 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.pica.cloud.account.account.server.configuration.PropertiesConfiguration;
import com.pica.cloud.account.account.server.constants.Constants;
import com.pica.cloud.account.account.server.entity.AccountUser;
import com.pica.cloud.account.account.server.enums.ExceptionType;
import com.pica.cloud.account.account.server.enums.AccountExceptionType;
import com.pica.cloud.account.account.server.exception.AccountException;
import com.pica.cloud.account.account.server.util.PICAPSendMsgModel;
import com.pica.cloud.foundation.entity.PicaException;
......@@ -159,7 +159,7 @@ public abstract class AccountBaseController extends BaseController {
return accountUser.getAcctId();
} catch (Exception e) {
e.printStackTrace();
throw new AccountException(ExceptionType.PICA_LOGIN_AGAIN);
throw new AccountException(AccountExceptionType.PICA_LOGIN_AGAIN);
}
}
......
......@@ -4,16 +4,15 @@ package com.pica.cloud.account.account.server.controller;
import com.pica.cloud.account.account.server.entity.AccountUser;
import com.pica.cloud.account.account.server.entity.EncryptEntity;
import com.pica.cloud.account.account.server.entity.LogLoginEntity;
import com.pica.cloud.account.account.server.enums.EnumsType;
import com.pica.cloud.account.account.server.log.PicaLogUtils;
import com.pica.cloud.account.account.server.enums.AccountEnumType;
import com.pica.cloud.account.account.server.log.AccountLogEntityUtils;
import com.pica.cloud.account.account.server.log.AccountLogUtils;
import com.pica.cloud.account.account.server.req.BaseRequest;
import com.pica.cloud.account.account.server.service.LoginService;
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.CryptoUtil;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.redis.ICacheClient;
import com.pica.cloud.foundation.utils.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
......@@ -38,7 +37,7 @@ public class LoginController extends AccountBaseController {
private ICacheClient redisClient;
@Autowired
private PicaLogUtils picaLogUtils;
private AccountLogUtils picaLogUtils;
@Autowired
private AccountUtils accountUtils;
......@@ -77,7 +76,7 @@ public class LoginController extends AccountBaseController {
public PicaResponse loginAndRegister(@RequestBody EncryptEntity entity) throws Exception {
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
accountUtils.checkMobilePhone(request.getMobile());
accountUtils.getAuthCodeKey(request.getMobile(), EnumsType.SYSCODE_TYPE_LOGIN.getCode() + "");
accountUtils.getAuthCodeKey(request.getMobile(), AccountEnumType.SYSCODE_TYPE_LOGIN.getCode() + "");
request.setProductType(super.getProductType());
request.setSourceType(super.getSourceType());
request.setLoginIp(super.getIpAddr());
......@@ -101,7 +100,7 @@ public class LoginController extends AccountBaseController {
public PicaResponse loginByWeChatStep(@RequestBody EncryptEntity entity) throws Exception {
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
accountUtils.checkMobilePhone(request.getMobile());
accountUtils.checkAuthCode(request.getMobile(), EnumsType.SYSCODE_TYPE_WE_CHAT.getCode() + "", request.getSysCode());
accountUtils.checkAuthCode(request.getMobile(), AccountEnumType.SYSCODE_TYPE_WE_CHAT.getCode() + "", request.getSysCode());
request.setProductType(super.getProductType());
request.setSourceType(super.getSourceType());
request.setLoginIp(super.getIpAddr());
......@@ -120,12 +119,20 @@ public class LoginController extends AccountBaseController {
@PostMapping("/login/wechat/bind")
public PicaResponse<String> bindWeChat(@RequestBody EncryptEntity entity) throws Exception {
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
String weChatCode = request.getWeChatCode();
request.setProductType(super.getProductType());
// TODO: 2019/8/29 绑定微信接口
return null;
loginService.bindWeChat(request);
request.setAccId(super.getAcctId());
return PicaResponse.toResponse();
}
@ApiOperation("微信解除绑定接口")
@GetMapping("/login/wechat/unbind")
public PicaResponse unbindWeChat() {
Integer acctId = super.getAcctId();
loginService.unbindWeChat(acctId);
return PicaResponse.toResponse();
}
/**
* 退出登录接口
*
......@@ -139,20 +146,12 @@ public class LoginController extends AccountBaseController {
String token = accountUser.getToken();
if (StringUtils.isNotEmpty(token)) {
Integer id = accountUser.getAcctId();
LogLoginEntity entity = new LogLoginEntity();
entity.setAcctId(id);
entity.setCreateId(id);
entity.setCreateTime(new Date());
entity.setModifyId(id);
entity.setModifyTime(new Date());
entity.setDeleteFlag(1);
entity.setLoginTime(new Date());
entity.setProductType(super.getProductType());
entity.setSourceType(super.getSourceType());
entity.setLoginType(EnumsType.LOGIN_OUT.getCode());
//记录登录日志
LogLoginEntity entity = AccountLogEntityUtils.getLogLoginEntity(id, super.getProductType(), super.getSourceType());
entity.setLoginType(AccountEnumType.LOGIN_OUT.getCode());
entity.setLoginIp(super.getIpAddr());
entity.setLoginStatus(EnumsType.LOGIN_STATUS_SUCCESS.getCode());
entity.setLogType(EnumsType.LOG_TYPE_LOGIN.getCode());
entity.setLoginStatus(AccountEnumType.LOGIN_STATUS_SUCCESS.getCode());
entity.setLogType(AccountEnumType.LOG_TYPE_LOGIN.getCode());
picaLogUtils.info(entity);
if (redisClient.deleteToken(token)) {
return PicaResponse.toResponse();
......@@ -160,18 +159,4 @@ public class LoginController extends AccountBaseController {
}
return null;
}
@ApiOperation("微信解除绑定接口")
@PostMapping("/login/wechat/unbind")
public PicaResponse unbindWeChat(@RequestBody EncryptEntity entity) throws Exception {
String token = super.getToken();
if (!StringUtil.isEmpty(redisClient.get(token))) {
//说明用户登录状态,//联合登录表中
loginService.unbindWeChat(super.getAcctId());
}
return PicaResponse.toResponse();
}
}
package com.pica.cloud.account.account.server.controller;
import com.pica.cloud.account.account.server.entity.EncryptEntity;
import com.pica.cloud.account.account.server.enums.EnumsType;
import com.pica.cloud.account.account.server.enums.AccountEnumType;
import com.pica.cloud.account.account.server.req.BaseRequest;
import com.pica.cloud.account.account.server.service.ModifyMobileService;
import com.pica.cloud.account.account.server.util.AccountUtils;
......@@ -31,7 +31,7 @@ public class ModifyMobileController extends AccountBaseController {
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
String mobile = request.getMobile();
accountUtils.checkMobilePhone(mobile);
accountUtils.checkAuthCode(mobile, EnumsType.SYSCODE_TYPE_MODIFY_MOBILE.getCode() + "", request.getSysCode());
accountUtils.checkAuthCode(mobile, AccountEnumType.SYSCODE_TYPE_MODIFY_MOBILE.getCode() + "", request.getSysCode());
modifyMobileService.modify(acctId, mobile);
return PicaResponse.toResponse();
}
......
package com.pica.cloud.account.account.server.controller;
import com.pica.cloud.account.account.server.entity.EncryptEntity;
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.enums.AccountEnumType;
import com.pica.cloud.account.account.server.enums.AccountExceptionType;
import com.pica.cloud.account.account.server.exception.AccountException;
import com.pica.cloud.account.account.server.req.BaseRequest;
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.CryptoUtil;
import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -46,10 +46,10 @@ public class PasswordController extends AccountBaseController {
passwordService.modifyPassword(acctId, oldPwd, password);
return PicaResponse.toResponse();
} else {
throw new PicaException(ExceptionType.PICA_PASSWORD_EQUAL.getCode(), ExceptionType.PICA_PASSWORD_EQUAL.getMessage());
throw new AccountException(AccountExceptionType.PICA_PASSWORD_EQUAL);
}
} else {
throw new PicaException(ExceptionType.PICA_PASSWORD_NULL.getCode(), ExceptionType.PICA_PASSWORD_NULL.getMessage());
throw new AccountException(AccountExceptionType.PICA_PASSWORD_NULL);
}
}
......@@ -63,9 +63,9 @@ public class PasswordController extends AccountBaseController {
public PicaResponse forgetPassword(@RequestBody EncryptEntity entity) throws Exception {
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
accountUtils.checkMobilePhone(request.getMobile());
accountUtils.checkAuthCode(request.getMobile(), EnumsType.SYSCODE_TYPE_RESET_PASSWORD.getCode() + "", request.getSysCode());
accountUtils.checkAuthCode(request.getMobile(), AccountEnumType.SYSCODE_TYPE_RESET_PASSWORD.getCode() + "", request.getSysCode());
if (StringUtils.isEmpty(request.getPassword())) {
throw new PicaException(ExceptionType.PICA_PASSWORD_ERROR.getCode(), ExceptionType.PICA_PASSWORD_ERROR.getMessage());
throw new AccountException(AccountExceptionType.PICA_PASSWORD_ERROR);
}
passwordService.forgetPassword(request);
return PicaResponse.toResponse();
......
package com.pica.cloud.account.account.server.controller;
import com.pica.cloud.account.account.server.entity.EncryptEntity;
import com.pica.cloud.account.account.server.enums.EnumsType;
import com.pica.cloud.account.account.server.enums.AccountEnumType;
import com.pica.cloud.account.account.server.req.BaseRequest;
import com.pica.cloud.account.account.server.service.RegisterService;
import com.pica.cloud.account.account.server.util.AccountUtils;
......@@ -28,9 +28,9 @@ public class RegisterController extends AccountBaseController {
public PicaResponse<String> register(@RequestBody EncryptEntity entity) throws Exception {
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
AccountUtils.checkMobilePhone(request.getMobile());
AccountUtils.getAuthCodeKey(request.getSysCode(), EnumsType.SYSCODE_TYPE_REGISTER.getCode() + "");
AccountUtils.getAuthCodeKey(request.getSysCode(), AccountEnumType.SYSCODE_TYPE_REGISTER.getCode() + "");
AccountUtils.checkPassword(request.getPassword());
request.setFlag(EnumsType.SYSCODE_TYPE_REGISTER.getCode());
request.setFlag(AccountEnumType.SYSCODE_TYPE_REGISTER.getCode());
request.setProductType(super.getProductType());
request.setSourceType(super.getSourceType());
request.setLoginIp(super.getIpAddr());
......
......@@ -3,8 +3,9 @@ package com.pica.cloud.account.account.server.controller;
import com.pica.cloud.account.account.server.entity.AccountInfoEntity;
import com.pica.cloud.account.account.server.entity.AccountUnionEntity;
import com.pica.cloud.account.account.server.entity.EncryptEntity;
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.enums.AccountEnumType;
import com.pica.cloud.account.account.server.enums.AccountExceptionType;
import com.pica.cloud.account.account.server.exception.AccountException;
import com.pica.cloud.account.account.server.mapper.AccountInfoDetailMapper;
import com.pica.cloud.account.account.server.req.BaseRequest;
import com.pica.cloud.account.account.server.service.AccountUnionService;
......@@ -62,14 +63,14 @@ public class SysCodeController extends AccountBaseController {
@PostMapping(value = "/authCode/wechat")
public PicaResponse getWChatSysCode(@RequestBody EncryptEntity entity) throws Exception {
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
request.setFlag(EnumsType.SYSCODE_TYPE_WE_CHAT.getCode());
request.setFlag(AccountEnumType.SYSCODE_TYPE_WE_CHAT.getCode());
AccountUtils.checkMobilePhone(request.getMobile());
AccountUnionEntity accountUnionEntity = accountUnionService.selectInfoByUnionId(request.getUnionId());
if (accountUnionEntity != null) {
processSysCode(request.getMobile(), request.getFlag());
return PicaResponse.toResponse();
}
throw new PicaException(ExceptionType.PICA_UNBIND_MOBILE.getCode(), ExceptionType.PICA_UNBIND_MOBILE.getMessage());
throw new AccountException(AccountExceptionType.PICA_UNBIND_MOBILE);
}
......
......@@ -4,7 +4,6 @@ import com.pica.cloud.account.account.server.entity.AccountUserInfoEntity;
import com.pica.cloud.account.account.server.entity.EncryptEntity;
import com.pica.cloud.account.account.server.req.PatientReq;
import com.pica.cloud.account.account.server.service.UserInfoService;
import com.pica.cloud.account.account.server.util.BeanUtil;
import com.pica.cloud.account.account.server.util.CryptoUtil;
import com.pica.cloud.foundation.entity.PicaResponse;
import io.swagger.annotations.Api;
......@@ -31,8 +30,8 @@ public class UserInfoController extends AccountBaseController {
@ApiOperation("获取用户信息接口")
@GetMapping(value = "/user/info")
public PicaResponse getUserInfo() {
Integer acctId = super.getAcctId();
AccountUserInfoEntity userInfo = userInfoService.getUserInfo(acctId);
Integer userId = super.getPicaUser().getId();
AccountUserInfoEntity userInfo = userInfoService.getUserInfo(userId);
return PicaResponse.toResponse(userInfo);
}
......@@ -47,8 +46,9 @@ public class UserInfoController extends AccountBaseController {
Integer id = super.getAccountUser().getId();
PatientReq request = CryptoUtil.decrypt(entity, PatientReq.class);
request.setId(id);
request.setAcctId(super.getAcctId());
AccountUserInfoEntity accountUserInfoEntity = new AccountUserInfoEntity();
BeanUtils.copyProperties(accountUserInfoEntity,request);
BeanUtils.copyProperties(accountUserInfoEntity, request);
userInfoService.updateUserInfo(accountUserInfoEntity);
return PicaResponse.toResponse();
}
......
package com.pica.cloud.account.account.server.entity;
import com.pica.cloud.account.account.server.log.PicaLogEntity;
import com.pica.cloud.account.account.server.log.AccountLogEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Date;
@ApiModel
public class LogLoginEntity extends PicaLogEntity {
public class LogLoginEntity extends AccountLogEntity {
private Integer id;
private Integer acctId;
......
package com.pica.cloud.account.account.server.entity;
import com.pica.cloud.account.account.server.log.PicaLogEntity;
import com.pica.cloud.account.account.server.log.AccountLogEntity;
import java.util.Date;
public class LogPWDModifyEntity extends PicaLogEntity {
public class LogPWDModifyEntity extends AccountLogEntity {
private Integer id;
private String mobilePhone;
......
package com.pica.cloud.account.account.server.entity;
import com.pica.cloud.account.account.server.log.PicaLogEntity;
import com.pica.cloud.account.account.server.log.AccountLogEntity;
import java.util.Date;
public class LogUserInfoEntity extends PicaLogEntity {
public class LogUserInfoEntity extends AccountLogEntity {
private Integer id;
private Integer acctId;
......
package com.pica.cloud.account.account.server.enums;
public enum EnumsType {
public enum AccountEnumType {
//登录类型枚举
//登录类型枚举(记录登录日志时使用)
LOGIN_CODE(1, "验证码登录"),
LOGIN_PWD(2, "密码登录"),
LOGIN_WE_CHAT(3, "微信登录"),
......@@ -48,7 +48,7 @@ public enum EnumsType {
private int code;
private String type;
EnumsType(int code, String type) {
AccountEnumType(int code, String type) {
this.code = code;
this.type = type;
}
......
package com.pica.cloud.account.account.server.enums;
public enum ExceptionType {
public enum AccountExceptionType {
PICA_NOT_EMPTY("216501", "字段非空提示信息"),
PICA_MOBILE_ERROR("216502", "请输入正确的手机号"),
......@@ -20,7 +20,7 @@ public enum ExceptionType {
private String code;
private String message;
ExceptionType(String code, String message) {
AccountExceptionType(String code, String message) {
this.code = code;
this.message = message;
}
......
package com.pica.cloud.account.account.server.exception;
import com.pica.cloud.account.account.server.enums.ExceptionType;
import com.pica.cloud.account.account.server.enums.AccountExceptionType;
import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResultCode;
......@@ -17,7 +17,7 @@ public class AccountException extends PicaException {
super(picaResultCode);
}
public AccountException(ExceptionType exceptionType) {
public AccountException(AccountExceptionType exceptionType) {
super(exceptionType.getCode(), exceptionType.getMessage());
}
}
......@@ -3,7 +3,7 @@ package com.pica.cloud.account.account.server.log;
/**
* 日志记录
*/
public class PicaLogEntity {
public class AccountLogEntity {
//标记当前记录的是哪种日志
private int logType;
......
package com.pica.cloud.account.account.server.log;
import com.pica.cloud.account.account.server.entity.LogLoginEntity;
import com.pica.cloud.account.account.server.entity.LogPWDModifyEntity;
import java.util.Date;
public class AccountLogEntityUtils {
/**
* 获取登录日志实例
*
* @param acctId
* @param productType
* @param sourceType
* @return
*/
public static LogLoginEntity getLogLoginEntity(Integer acctId, Integer productType, Integer sourceType) {
LogLoginEntity entity = new LogLoginEntity();
Date currentTime = new Date();
entity.setAcctId(acctId);
entity.setCreateId(acctId);
entity.setCreateTime(currentTime);
entity.setModifyId(acctId);
entity.setModifyTime(currentTime);
entity.setDeleteFlag(1);
entity.setLoginTime(currentTime);
entity.setProductType(productType);
entity.setSourceType(sourceType);
return entity;
}
/**
* 获取密码修改实例
*
* @param acctId
* @return
*/
public static LogPWDModifyEntity getLogPWDModifyEntity(Integer acctId) {
LogPWDModifyEntity entity = new LogPWDModifyEntity();
Date currentTime = new Date();
entity.setCreatedId(acctId);
entity.setCreatedTime(currentTime);
entity.setDeleteFlag(1);
entity.setModifiedId(acctId);
entity.setModifiedTime(currentTime);
return entity;
}
}
......@@ -4,16 +4,14 @@ package com.pica.cloud.account.account.server.log;
import com.pica.cloud.account.account.server.entity.LogLoginEntity;
import com.pica.cloud.account.account.server.entity.LogPWDModifyEntity;
import com.pica.cloud.account.account.server.entity.LogUserInfoEntity;
import com.pica.cloud.account.account.server.enums.EnumsType;
import com.pica.cloud.account.account.server.enums.AccountEnumType;
import com.pica.cloud.account.account.server.mapper.LogLoginMapper;
import com.pica.cloud.account.account.server.mapper.LogPWDModifyMapper;
import com.pica.cloud.account.account.server.mapper.LogUserInfoMapper;
import com.pica.cloud.account.account.server.util.BeanUtil;
import com.pica.cloud.foundation.utils.utils.SpringContextUtil;
import org.springframework.beans.factory.annotation.Autowired;
public class PicaLogTask implements Runnable {
public class AccountLogTask implements Runnable {
private LogLoginMapper loginLogMapper;
......@@ -29,9 +27,9 @@ public class PicaLogTask implements Runnable {
/**
* 日志内容
*/
private PicaLogEntity picaLogEntity;
private AccountLogEntity picaLogEntity;
PicaLogTask(PicaLogEntity picaLogEntity) {
AccountLogTask(AccountLogEntity picaLogEntity) {
this.picaLogEntity = picaLogEntity;
type = picaLogEntity.getLogType();
loginLogMapper = BeanUtil.getBean(LogLoginMapper.class);
......@@ -41,11 +39,11 @@ public class PicaLogTask implements Runnable {
@Override
public void run() {
if (type == EnumsType.LOG_TYPE_LOGIN.getCode()) {
if (type == AccountEnumType.LOG_TYPE_LOGIN.getCode()) {
loginLogMapper.insertSelective((LogLoginEntity) picaLogEntity);
} else if (type == EnumsType.LOG_TYPE_PASSWORD.getCode()) {
} else if (type == AccountEnumType.LOG_TYPE_PASSWORD.getCode()) {
logPWDModifyMapper.insert((LogPWDModifyEntity) picaLogEntity);
} else if (type == EnumsType.LOG_TYPE_USER_INFO.getCode()) {
} else if (type == AccountEnumType.LOG_TYPE_USER_INFO.getCode()) {
logUserInfoMapper.insertSelective((LogUserInfoEntity) picaLogEntity);
}
}
......
......@@ -6,7 +6,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@Component
public class PicaLogUtils {
public class AccountLogUtils {
/**
* 线程池
......@@ -16,9 +16,9 @@ public class PicaLogUtils {
/**
* 日志记录方法
*
* @param picaLogEntity
* @param accountLogEntity
*/
public void info(PicaLogEntity picaLogEntity) {
executor.submit(new PicaLogTask(picaLogEntity));
public void info(AccountLogEntity accountLogEntity) {
executor.submit(new AccountLogTask(accountLogEntity));
}
}
......@@ -4,22 +4,11 @@ package com.pica.cloud.account.account.server.mapper;
import com.pica.cloud.account.account.server.entity.AccountUnionEntity;
public interface AccountUnionMapper {
int deleteByPrimaryKey(Integer id);
int insert(AccountUnionEntity record);
int insertSelective(AccountUnionEntity record);
AccountUnionEntity selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(AccountUnionEntity record);
int updateByPrimaryKey(AccountUnionEntity record);
/**
* 解除绑定关系
*
* @param acctId
* @param acctId 账户id
* @return
*/
int updateUnbindByAcctId(Integer acctId);
......@@ -27,8 +16,23 @@ public interface AccountUnionMapper {
/**
* 是否绑定过手机号
*
* @param unionId
* @param unionId 联合id
* @return
*/
AccountUnionEntity selectByUnionId(String unionId);
int deleteByPrimaryKey(Integer id);
int insert(AccountUnionEntity record);
int insertSelective(AccountUnionEntity record);
AccountUnionEntity selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(AccountUnionEntity record);
int updateByPrimaryKey(AccountUnionEntity record);
}
\ No newline at end of file
......@@ -5,12 +5,10 @@ import com.pica.cloud.account.account.server.entity.AccountUserInfoEntity;
public interface AccountUserInfoMapper {
int insertSelective(AccountUserInfoEntity record);
/**
* 通过userId查询居民信息
*
* @param id
* @param id userId
* @return
*/
AccountUserInfoEntity selectByPrimaryKey(Integer id);
......@@ -18,19 +16,21 @@ public interface AccountUserInfoMapper {
/**
* 通过账户id查询居民信息
*
* @param acctId
* @param id 用户id
* @return
*/
AccountUserInfoEntity selectByAcctId(Integer acctId);
AccountUserInfoEntity selectByUserId(Integer id);
/**
* 更新居民信息接口
*
* @param record
* @param record 居民信息模型
* @return
*/
int updateByPrimaryKeySelective(AccountUserInfoEntity record);
int insertSelective(AccountUserInfoEntity record);
int updateByPrimaryKey(AccountUserInfoEntity record);
int deleteByPrimaryKey(Integer id);
......
......@@ -3,6 +3,14 @@ package com.pica.cloud.account.account.server.mapper;
import com.pica.cloud.account.account.server.entity.AccountWeChatInfoEntity;
public interface AccountWeChatInfoMapper {
/**
* UnionId 是否存在
* @param id 联合id
* @return
*/
AccountWeChatInfoEntity selectByUnionId(String id);
int deleteByPrimaryKey(Integer id);
int insert(AccountWeChatInfoEntity record);
......@@ -15,10 +23,5 @@ public interface AccountWeChatInfoMapper {
int updateByPrimaryKey(AccountWeChatInfoEntity record);
/**
* UnionId 是否存在
* @param id
* @return
*/
AccountWeChatInfoEntity selectByUnionId(String id);
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ package com.pica.cloud.account.account.server.mapper;
import com.pica.cloud.account.account.server.entity.LogLoginEntity;
public interface LogLoginMapper {
int deleteByPrimaryKey(Integer id);
......
......@@ -7,7 +7,7 @@ public interface AccountUnionService {
/**
* 通过unionId查询绑定信息
*
* @param unionId
* @param unionId 联合id
* @return
*/
AccountUnionEntity selectInfoByUnionId(String unionId);
......
......@@ -6,7 +6,7 @@ public interface LoginService {
/**
* 密码登录功能
*
* @param request
* @param request 参数模型
* @return
*/
String login(BaseRequest request);
......@@ -14,7 +14,7 @@ public interface LoginService {
/**
* 一键登录功能
*
* @param request
* @param request 参数模型
* @return
*/
String loginAndRegister(BaseRequest request);
......@@ -22,14 +22,14 @@ public interface LoginService {
/**
* 微信登录
*
* @param baseRequest
* @param baseRequest 参数模型
*/
String loginByWeChat(BaseRequest baseRequest);
/**
* 微信登陆第二步
*
* @param request
* @param request 参数模型
* @return
*/
String loginByWeChatStep(BaseRequest request);
......@@ -37,9 +37,15 @@ public interface LoginService {
/**
* 解除绑定
*
* @param acctId
* @param acctId 账户id
*/
void unbindWeChat(Integer acctId);
/**
* 绑定微信接口
*
* @param request 参数模型
*/
void bindWeChat(BaseRequest request);
}
......@@ -3,5 +3,11 @@ package com.pica.cloud.account.account.server.service;
public interface ModifyMobileService {
void modify(Integer acctId,String mobile);
/**
* 修改手机号
*
* @param acctId 账户id
* @param mobile 手机号
*/
void modify(Integer acctId, String mobile);
}
......@@ -4,7 +4,19 @@ import com.pica.cloud.account.account.server.req.BaseRequest;
public interface PasswordService {
/**
* 修改密码
*
* @param acctId 账户id
* @param oldPwd 旧密码
* @param pwd 新密码
*/
void modifyPassword(Integer acctId, String oldPwd, String pwd);
/**
* 忘记密码
*
* @param request 参数模型
*/
void forgetPassword(BaseRequest request);
}
......@@ -5,7 +5,13 @@ import com.pica.cloud.account.account.server.req.BaseRequest;
public interface RegisterService {
String register(BaseRequest baseRequest);
/**
* 注册
*
* @param baseRequest 参数模型
* @return token和userId
*/
String register(BaseRequest baseRequest);
}
......@@ -8,7 +8,7 @@ public interface UserInfoService {
/**
* 更新用户信息接口
*
* @param accountUserInfoEntity
* @param accountUserInfoEntity 更新信息
*/
void updateUserInfo(AccountUserInfoEntity accountUserInfoEntity);
......@@ -16,8 +16,8 @@ public interface UserInfoService {
/**
* 获取用户信息接口
*
* @param acctId
* @param userId 用户id
* @return
*/
AccountUserInfoEntity getUserInfo(Integer acctId);
AccountUserInfoEntity getUserInfo(Integer userId);
}
package com.pica.cloud.account.account.server.service.impl;
import com.pica.cloud.account.account.server.entity.AccountUnionEntity;
import com.pica.cloud.account.account.server.mapper.AccountUnionMapper;
import com.pica.cloud.account.account.server.service.AccountUnionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
@Service("")
public class AccountUnionServiceImpl implements AccountUnionService {
@Autowired
......
......@@ -2,12 +2,16 @@ package com.pica.cloud.account.account.server.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.pica.cloud.account.account.server.constants.Constants;
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.log.PicaLogUtils;
import com.pica.cloud.account.account.server.enums.AccountEnumType;
import com.pica.cloud.account.account.server.enums.AccountExceptionType;
import com.pica.cloud.account.account.server.log.AccountLogEntityUtils;
import com.pica.cloud.account.account.server.log.AccountLogUtils;
import com.pica.cloud.account.account.server.mapper.AccountInfoDetailMapper;
import com.pica.cloud.account.account.server.mapper.AccountUnionMapper;
import com.pica.cloud.account.account.server.mapper.AccountUserInfoMapper;
import com.pica.cloud.account.account.server.mapper.AccountWeChatInfoMapper;
import com.pica.cloud.account.account.server.req.AccountReq;
import com.pica.cloud.account.account.server.req.BaseRequest;
import com.pica.cloud.account.account.server.service.LoginService;
......@@ -49,7 +53,7 @@ public class LoginServiceImpl implements LoginService {
private AccountWeChatInfoMapper accountWeChatInfoMapper;
@Autowired
private PicaLogUtils picaLogUtils;
private AccountLogUtils picaLogUtils;
@Autowired
private TokenUtils tokenUtils;
......@@ -91,30 +95,22 @@ public class LoginServiceImpl implements LoginService {
account.setRegisterSource(sourceType);
String newToken = tokenUtils.generateToken(account);
JSONObject jsonObject = new JSONObject();
jsonObject.put("token", newToken);
jsonObject.put("userId", accountUserInfoEntity.getId().longValue());
LogLoginEntity entity = new LogLoginEntity();
entity.setAcctId(acctId);
entity.setCreateId(acctId);
entity.setCreateTime(currentTime);
entity.setModifyId(acctId);
entity.setModifyTime(currentTime);
entity.setDeleteFlag(1);
entity.setLoginTime(currentTime);
entity.setProductType(productType);
entity.setSourceType(request.getSourceType());
entity.setLoginType(EnumsType.LOGIN_REGISTER.getCode());
jsonObject.put(Constants.TOKEN, newToken);
jsonObject.put(Constants.USER_ID, accountUserInfoEntity.getId().longValue());
//记录登录日志
LogLoginEntity entity = AccountLogEntityUtils.getLogLoginEntity(acctId, productType, request.getSourceType());
entity.setLoginType(AccountEnumType.LOGIN_PWD.getCode());
entity.setLoginIp(request.getLoginIp());
entity.setLoginStatus(EnumsType.LOGIN_STATUS_SUCCESS.getCode());
entity.setLogType(EnumsType.LOG_TYPE_LOGIN.getCode());
entity.setLoginStatus(AccountEnumType.LOGIN_STATUS_SUCCESS.getCode());
entity.setLogType(AccountEnumType.LOG_TYPE_LOGIN.getCode());
picaLogUtils.info(entity);
return jsonObject.toJSONString();
} else {
logger.info("login failure:" + mobile);
throw new PicaException(ExceptionType.PICA_PASSWORD_ERROR.getCode(), ExceptionType.PICA_PASSWORD_ERROR.getMessage());
throw new PicaException(AccountExceptionType.PICA_PASSWORD_ERROR.getCode(), AccountExceptionType.PICA_PASSWORD_ERROR.getMessage());
}
} else {
throw new PicaException(ExceptionType.PICA_NOT_REGISTER.getCode(), ExceptionType.PICA_NOT_REGISTER.getMessage());
throw new PicaException(AccountExceptionType.PICA_NOT_REGISTER.getCode(), AccountExceptionType.PICA_NOT_REGISTER.getMessage());
}
}
......@@ -126,7 +122,7 @@ public class LoginServiceImpl implements LoginService {
if (accountInfoEntity == null) {
return registerService.register(baseRequest);
} else {
return processLogin(baseRequest, accountInfoEntity.getId());
return processLogin(baseRequest, accountInfoEntity.getId(), AccountEnumType.LOGIN_CODE.getCode());
}
}
......@@ -135,7 +131,7 @@ public class LoginServiceImpl implements LoginService {
*
* @param baseRequest
*/
private String processLogin(BaseRequest baseRequest, Integer acctId) {
private String processLogin(BaseRequest baseRequest, Integer acctId, Integer loginType) {
Date currentTime = new Date();
AccountUserInfoEntity accountUserInfoEntity = accountUserInfoMapper.selectByAcctId(acctId);
//验证码登陆:只要相同即可成功
......@@ -152,22 +148,14 @@ public class LoginServiceImpl implements LoginService {
account.setRegisterSource(baseRequest.getSourceType());
String newToken = tokenUtils.generateToken(account);
JSONObject jsonObject = new JSONObject();
jsonObject.put("token", newToken);
jsonObject.put("userId", accountUserInfoEntity.getId().longValue());
LogLoginEntity entity = new LogLoginEntity();
entity.setAcctId(acctId);
entity.setCreateId(acctId);
entity.setCreateTime(currentTime);
entity.setModifyId(acctId);
entity.setModifyTime(currentTime);
entity.setDeleteFlag(1);
entity.setLoginTime(currentTime);
entity.setProductType(baseRequest.getProductType());
entity.setSourceType(baseRequest.getSourceType());
entity.setLoginType(EnumsType.LOGIN_REGISTER.getCode());
jsonObject.put(Constants.TOKEN, newToken);
jsonObject.put(Constants.USER_ID, accountUserInfoEntity.getId().longValue());
//记录登录日志
LogLoginEntity entity = AccountLogEntityUtils.getLogLoginEntity(acctId, baseRequest.getProductType(), baseRequest.getSourceType());
entity.setLoginType(loginType);
entity.setLoginIp(baseRequest.getLoginIp());
entity.setLoginStatus(EnumsType.LOGIN_STATUS_SUCCESS.getCode());
entity.setLogType(EnumsType.LOG_TYPE_LOGIN.getCode());
entity.setLoginStatus(AccountEnumType.LOGIN_STATUS_SUCCESS.getCode());
entity.setLogType(AccountEnumType.LOG_TYPE_LOGIN.getCode());
picaLogUtils.info(entity);
return jsonObject.toJSONString();
}
......@@ -176,11 +164,9 @@ public class LoginServiceImpl implements LoginService {
public String loginByWeChat(BaseRequest request) {
WeChatEntity weChatEntity = WeChatUtils.getAuthorizationInfo(appId, appSecret, request.getWeChatCode());
//todo:微信登录获取个人信息
Map map = new HashMap();
map.put("access_token", weChatEntity.getAccess_token());
map.put("openid", weChatEntity.getOpenid());
Map weChatUserInfo = WeChatUtils.getWeChatUserInfo(map, weChatURL);
WeChatUserInfoEntity weChatUserInfoEntity = WeChatUtils.mergeWechatUserInfo(weChatUserInfo, weChatEntity.getOpenid());
String unionId = weChatUserInfoEntity.getUnionid();
......@@ -197,34 +183,18 @@ public class LoginServiceImpl implements LoginService {
account.setRegisterSource(request.getSourceType());
String newToken = tokenUtils.generateToken(account);
JSONObject jsonObject = new JSONObject();
jsonObject.put("token", newToken);
jsonObject.put("userId", accountUserInfoEntity.getId().longValue());
jsonObject.put("bindFlag", EnumsType.BIND_STATUS_SUCCESS.getCode());
jsonObject.put(Constants.TOKEN, newToken);
jsonObject.put(Constants.USER_ID, accountUserInfoEntity.getId().longValue());
jsonObject.put(Constants.BIND_FLAG, AccountEnumType.BIND_STATUS_SUCCESS.getCode());
return jsonObject.toJSONString();
} else {
AccountWeChatInfoEntity entity = accountWeChatInfoMapper.selectByUnionId(unionId);
if (entity == null) {
Date currentTime = new Date();
AccountWeChatInfoEntity accountWeChatInfoEntity = new AccountWeChatInfoEntity();
accountWeChatInfoEntity.setCreatedId(0);
accountWeChatInfoEntity.setCreatedTime(currentTime);
accountWeChatInfoEntity.setDeleteFlag(1);
accountWeChatInfoEntity.setGroupid(weChatUserInfoEntity.getGroupid() + "");
accountWeChatInfoEntity.setType(request.getWeChatLoginType());
accountWeChatInfoEntity.setModifiedId(0);
accountWeChatInfoEntity.setModifiedTime(currentTime);
accountWeChatInfoEntity.setOpenid(weChatUserInfoEntity.getOpenid());
accountWeChatInfoEntity.setUnionid(weChatUserInfoEntity.getUnionid());
accountWeChatInfoEntity.setPrivilege(weChatUserInfoEntity.getPrivilege());
accountWeChatInfoEntity.setRemark(weChatUserInfoEntity.getRemark());
accountWeChatInfoEntity.setSubscribe(weChatUserInfoEntity.getSubscribe());
accountWeChatInfoEntity.setSubscribeTime(weChatUserInfoEntity.getSubscribe_time());
accountWeChatInfoEntity.setTagidList(weChatUserInfoEntity.getTagid_list());
accountWeChatInfoMapper.insertSelective(accountWeChatInfoEntity);
processWeChatInfoUser(weChatUserInfoEntity, request.getWeChatLoginType());
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("bindFlag", EnumsType.BIND_STATUS_FAILURE.getCode());
jsonObject.put("unionId", unionId);
jsonObject.put(Constants.BIND_FLAG, AccountEnumType.BIND_STATUS_FAILURE.getCode());
jsonObject.put(Constants.UNION_ID, unionId);
return jsonObject.toJSONString();
}
}
......@@ -237,14 +207,11 @@ public class LoginServiceImpl implements LoginService {
if (accountInfoEntity == null) {
json = registerService.register(request);
} else {
json = processLogin(request, accountInfoEntity.getId());
json = processLogin(request, accountInfoEntity.getId(), AccountEnumType.LOGIN_WE_CHAT.getCode());
}
//向表中插入数据
//todo:向联合登录表插入信息,信息哪里来?
AccountInfoEntity accountInfo = accountInfoDetailMapper.selectByMobile(EncryptCreateUtil.encrypt(request.getMobile()));
Integer acctId = accountInfo.getId();
processAccountUnion(acctId, request.getUnionId());
return json;
}
......@@ -253,6 +220,64 @@ public class LoginServiceImpl implements LoginService {
accountUnionMapper.updateUnbindByAcctId(acctId);
}
@Override
public void bindWeChat(BaseRequest request) {
WeChatEntity weChatEntity = WeChatUtils.getAuthorizationInfo(appId, appSecret, request.getWeChatCode());
Map map = new HashMap();
map.put("access_token", weChatEntity.getAccess_token());
map.put("openid", weChatEntity.getOpenid());
Map weChatUserInfo = WeChatUtils.getWeChatUserInfo(map, weChatURL);
WeChatUserInfoEntity weChatUserInfoEntity = WeChatUtils.mergeWechatUserInfo(weChatUserInfo, weChatEntity.getOpenid());
String unionId = weChatUserInfoEntity.getUnionid();
AccountWeChatInfoEntity entity = accountWeChatInfoMapper.selectByUnionId(unionId);
if (entity == null) {
processWeChatInfoUser(weChatUserInfoEntity, request.getWeChatLoginType());
}
processAccountUnion(request.getAccId(), unionId);
}
private void processAccountUnion(Integer acctId, String unionId) {
AccountUnionEntity accountUnionEntity = new AccountUnionEntity();
accountUnionEntity.setAcctId(acctId.longValue());
accountUnionEntity.setDeleteFlag(1);
accountUnionEntity.setUnionId(unionId);
accountUnionEntity.setCreatedTime(new Date());
accountUnionEntity.setModifiedTime(new Date());
accountUnionEntity.setCreatedId(acctId);
accountUnionEntity.setModifiedId(acctId);
accountUnionEntity.setUnionType(AccountEnumType.UNION_LOGIN_WE_CHAT.getCode());
accountUnionMapper.insertSelective(accountUnionEntity);
}
private void processWeChatInfoUser(WeChatUserInfoEntity weChatUserInfoEntity, int type) {
AccountWeChatInfoEntity accountWeChatInfoEntity = new AccountWeChatInfoEntity();
Date currentTime = new Date();
accountWeChatInfoEntity.setCreatedId(0);
accountWeChatInfoEntity.setCreatedTime(currentTime);
accountWeChatInfoEntity.setDeleteFlag(1);
accountWeChatInfoEntity.setGroupid(weChatUserInfoEntity.getGroupid() + "");
accountWeChatInfoEntity.setType(type);
accountWeChatInfoEntity.setModifiedId(0);
accountWeChatInfoEntity.setModifiedTime(currentTime);
accountWeChatInfoEntity.setOpenid(weChatUserInfoEntity.getOpenid());
accountWeChatInfoEntity.setUnionid(weChatUserInfoEntity.getUnionid());
accountWeChatInfoEntity.setPrivilege(weChatUserInfoEntity.getPrivilege());
accountWeChatInfoEntity.setRemark(weChatUserInfoEntity.getRemark());
accountWeChatInfoEntity.setSubscribe(weChatUserInfoEntity.getSubscribe());
accountWeChatInfoEntity.setSubscribeTime(weChatUserInfoEntity.getSubscribe_time());
accountWeChatInfoEntity.setTagidList(weChatUserInfoEntity.getTagid_list());
accountWeChatInfoEntity.setCity(weChatUserInfoEntity.getCity());
accountWeChatInfoEntity.setNickname(weChatUserInfoEntity.getNickname());
accountWeChatInfoEntity.setHeadImgUrl(weChatUserInfoEntity.getHeadimgurl());
accountWeChatInfoEntity.setCountry(weChatUserInfoEntity.getCountry());
accountWeChatInfoEntity.setSex(weChatUserInfoEntity.getSex());
accountWeChatInfoEntity.setProvince(weChatUserInfoEntity.getProvince());
accountWeChatInfoEntity.setLanguage(weChatUserInfoEntity.getLanguage());
accountWeChatInfoMapper.insertSelective(accountWeChatInfoEntity);
}
//校验验证码
private void checkAuthCode(AccountReq req) {
String flag = StringUtils.isBlank(req.getFlag()) ? "0" : req.getFlag();
......@@ -269,7 +294,7 @@ public class LoginServiceImpl implements LoginService {
if (!StringUtils.equals(req.getAuthCode(), cacheCode)) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "短信验证码错误");
}
redisClient.del(authCodeKey); //清除验证码
//清除验证码
redisClient.del(authCodeKey);
}
}
......@@ -2,14 +2,14 @@ package com.pica.cloud.account.account.server.service.impl;
import com.pica.cloud.account.account.server.entity.AccountInfoEntity;
import com.pica.cloud.account.account.server.entity.LogPWDModifyEntity;
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.enums.AccountEnumType;
import com.pica.cloud.account.account.server.enums.AccountExceptionType;
import com.pica.cloud.account.account.server.exception.AccountException;
import com.pica.cloud.account.account.server.log.PicaLogUtils;
import com.pica.cloud.account.account.server.log.AccountLogEntityUtils;
import com.pica.cloud.account.account.server.log.AccountLogUtils;
import com.pica.cloud.account.account.server.mapper.AccountInfoDetailMapper;
import com.pica.cloud.account.account.server.req.BaseRequest;
import com.pica.cloud.account.account.server.service.PasswordService;
import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.utils.utils.EncryptCreateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -23,7 +23,7 @@ public class PasswordServiceImpl implements PasswordService {
private AccountInfoDetailMapper accountInfoDetailMapper;
@Autowired
private PicaLogUtils picaLogUtils;
private AccountLogUtils picaLogUtils;
@Override
public void modifyPassword(Integer acctId, String oldPwd, String pwd) {
......@@ -36,20 +36,14 @@ public class PasswordServiceImpl implements PasswordService {
accountInfoEntity.setPassword(EncryptCreateUtil.encrypt(pwd));
accountInfoDetailMapper.updatePasswordByPrimaryKey(accountInfoEntity);
//密码修改日志
Date currentTime = new Date();
LogPWDModifyEntity logPWDModifyEntity = new LogPWDModifyEntity();
logPWDModifyEntity.setCreatedId(acctId);
logPWDModifyEntity.setCreatedTime(currentTime);
logPWDModifyEntity.setDeleteFlag(1);
LogPWDModifyEntity logPWDModifyEntity = AccountLogEntityUtils.getLogPWDModifyEntity(acctId);
logPWDModifyEntity.setMobilePhone(entity.getMobilePhone());
logPWDModifyEntity.setModifiedId(acctId);
logPWDModifyEntity.setModifiedTime(currentTime);
logPWDModifyEntity.setOldPwd(EncryptCreateUtil.encrypt(oldPwd));
logPWDModifyEntity.setNewPwd(EncryptCreateUtil.encrypt(pwd));
logPWDModifyEntity.setLogType(EnumsType.LOG_TYPE_PASSWORD.getCode());
logPWDModifyEntity.setLogType(AccountEnumType.LOG_TYPE_PASSWORD.getCode());
picaLogUtils.info(logPWDModifyEntity);
} else {
throw new AccountException(ExceptionType.PICA_PASSWORD_ERROR);
throw new AccountException(AccountExceptionType.PICA_PASSWORD_ERROR);
}
}
......@@ -65,21 +59,15 @@ public class PasswordServiceImpl implements PasswordService {
accountInfoEntity.setPassword(EncryptCreateUtil.encrypt(request.getPassword()));
accountInfoDetailMapper.updatePasswordByPrimaryKey(accountInfoEntity);
//密码修改日志
Date currentTime = new Date();
LogPWDModifyEntity logPWDModifyEntity = new LogPWDModifyEntity();
logPWDModifyEntity.setCreatedId(accId);
logPWDModifyEntity.setCreatedTime(currentTime);
logPWDModifyEntity.setDeleteFlag(1);
LogPWDModifyEntity logPWDModifyEntity = AccountLogEntityUtils.getLogPWDModifyEntity(accId);
logPWDModifyEntity.setMobilePhone(entity.getMobilePhone());
logPWDModifyEntity.setModifiedId(accId);
logPWDModifyEntity.setModifiedTime(currentTime);
logPWDModifyEntity.setOldPwd("");
logPWDModifyEntity.setNewPwd(EncryptCreateUtil.encrypt(request.getPassword()));
logPWDModifyEntity.setLogType(EnumsType.LOG_TYPE_PASSWORD.getCode());
logPWDModifyEntity.setLogType(AccountEnumType.LOG_TYPE_PASSWORD.getCode());
picaLogUtils.info(logPWDModifyEntity);
} else {
//未注册,请先注册
throw new AccountException(ExceptionType.PICA_NOT_REGISTER);
throw new AccountException(AccountExceptionType.PICA_NOT_REGISTER);
}
}
}
package com.pica.cloud.account.account.server.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.pica.cloud.account.account.server.constants.Constants;
import com.pica.cloud.account.account.server.entity.Account;
import com.pica.cloud.account.account.server.entity.AccountInfoEntity;
import com.pica.cloud.account.account.server.entity.AccountUserInfoEntity;
import com.pica.cloud.account.account.server.entity.LogLoginEntity;
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.log.PicaLogUtils;
import com.pica.cloud.account.account.server.enums.AccountEnumType;
import com.pica.cloud.account.account.server.enums.AccountExceptionType;
import com.pica.cloud.account.account.server.exception.AccountException;
import com.pica.cloud.account.account.server.log.AccountLogEntityUtils;
import com.pica.cloud.account.account.server.log.AccountLogUtils;
import com.pica.cloud.account.account.server.mapper.AccountInfoDetailMapper;
import com.pica.cloud.account.account.server.mapper.AccountUserInfoMapper;
import com.pica.cloud.account.account.server.req.BaseRequest;
import com.pica.cloud.account.account.server.service.RegisterService;
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.apache.commons.lang3.StringUtils;
......@@ -43,7 +45,7 @@ public class RegisterServiceImpl implements RegisterService {
private ICacheClient cacheClient;
@Autowired
private PicaLogUtils picaLogUtils;
private AccountLogUtils picaLogUtils;
@Override
public String register(BaseRequest baseRequest) {
......@@ -90,26 +92,18 @@ public class RegisterServiceImpl implements RegisterService {
account.setRegisterSource(sourceType);
String newToken = this.generateToken(account);
JSONObject jsonObject = new JSONObject();
jsonObject.put("token", newToken);
jsonObject.put("userId", userId);
LogLoginEntity entity = new LogLoginEntity();
entity.setAcctId(acctId);
entity.setCreateId(acctId);
entity.setCreateTime(currentTime);
entity.setModifyId(acctId);
entity.setModifyTime(currentTime);
entity.setDeleteFlag(1);
entity.setLoginTime(currentTime);
entity.setProductType(productType);
entity.setSourceType(baseRequest.getSourceType());
entity.setLoginType(EnumsType.LOGIN_REGISTER.getCode());
jsonObject.put(Constants.TOKEN, newToken);
jsonObject.put(Constants.USER_ID, userId);
//记录登录日志
LogLoginEntity entity = AccountLogEntityUtils.getLogLoginEntity(acctId, productType, baseRequest.getSourceType());
entity.setLoginType(AccountEnumType.LOGIN_REGISTER.getCode());
entity.setLoginIp(baseRequest.getLoginIp());
entity.setLoginStatus(EnumsType.LOGIN_STATUS_SUCCESS.getCode());
entity.setLogType(EnumsType.LOG_TYPE_LOGIN.getCode());
entity.setLoginStatus(AccountEnumType.LOGIN_STATUS_SUCCESS.getCode());
entity.setLogType(AccountEnumType.LOG_TYPE_LOGIN.getCode());
picaLogUtils.info(entity);
return jsonObject.toJSONString();
} else {
throw new PicaException(ExceptionType.PICA_ALREADY_REGISTER.getCode(), ExceptionType.PICA_ALREADY_REGISTER.getMessage());
throw new AccountException(AccountExceptionType.PICA_ALREADY_REGISTER);
}
}
......
package com.pica.cloud.account.account.server.service.impl;
import com.pica.cloud.account.account.server.entity.AccountUserInfoEntity;
import com.pica.cloud.account.account.server.entity.LogUserInfoEntity;
import com.pica.cloud.account.account.server.log.AccountLogUtils;
import com.pica.cloud.account.account.server.mapper.AccountUserInfoMapper;
import com.pica.cloud.account.account.server.service.UserInfoService;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.lang.reflect.InvocationTargetException;
import java.util.Date;
@Service
......@@ -14,15 +18,33 @@ public class UserInfoServerImpl implements UserInfoService {
@Autowired
private AccountUserInfoMapper accountUserInfoMapper;
@Autowired
private AccountLogUtils accountLogUtils;
@Override
public void updateUserInfo(AccountUserInfoEntity accountUserInfoEntity) {
accountUserInfoEntity.setModifyTime(new Date());
accountUserInfoEntity.setModifyId(accountUserInfoEntity.getAcctId());
accountUserInfoMapper.updateByPrimaryKeySelective(accountUserInfoEntity);
//用户信息更新日志
Integer userId = accountUserInfoEntity.getId();
AccountUserInfoEntity userInfo = getUserInfo(userId);
LogUserInfoEntity logUserInfoEntity = new LogUserInfoEntity();
try {
BeanUtils.copyProperties(logUserInfoEntity, userInfo);
Date currentTime = new Date();
logUserInfoEntity.setCreateTime(currentTime);
logUserInfoEntity.setModifyTime(currentTime);
accountLogUtils.info(logUserInfoEntity);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
@Override
public AccountUserInfoEntity getUserInfo(Integer acctId) {
return accountUserInfoMapper.selectByAcctId(acctId);
public AccountUserInfoEntity getUserInfo(Integer userId) {
return accountUserInfoMapper.selectByUserId(userId);
}
}
package com.pica.cloud.account.account.server.util;
import com.alibaba.fastjson.JSONObject;
import com.pica.cloud.account.account.server.enums.ExceptionType;
import com.pica.cloud.account.account.server.enums.AccountExceptionType;
import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.foundation.redis.ICacheClient;
......@@ -34,7 +34,7 @@ public class AccountUtils {
//手机格式校验
public static void checkPassword(String password) {
if (StringUtils.isBlank(password)) {
throw new PicaException(ExceptionType.PICA_NOT_EMPTY.getCode(), ExceptionType.PICA_NOT_EMPTY.getMessage());
throw new PicaException(AccountExceptionType.PICA_NOT_EMPTY.getCode(), AccountExceptionType.PICA_NOT_EMPTY.getMessage());
}
}
......
package com.pica.cloud.account.account.server.util;
public class PicaAccountException extends RuntimeException {
}
......@@ -46,11 +46,11 @@
</select>
<!--通过账户id查询信息-->
<select id="selectByAcctId" resultMap="BaseResultMap" parameterType="java.lang.Integer">
<select id="selectByUserId" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
<include refid="Base_Column_List"/>
from p_patient
where acct_id = #{acctId,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</select>
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册