提交 28a32e48 编写于 作者: rushui.chen's avatar rushui.chen

20190903 日志模块代码优化

上级 2173c002
流水线 #13965 已失败 于阶段
in 0 second
......@@ -147,11 +147,8 @@ public class LoginController extends AccountBaseController {
if (StringUtils.isNotEmpty(token)) {
Integer id = accountUser.getAcctId();
//记录登录日志
LogLoginEntity entity = AccountLogEntityUtils.getLogLoginEntity(id, super.getProductType(), super.getSourceType());
entity.setLoginType(AccountEnumType.LOGIN_OUT.getCode());
entity.setLoginIp(super.getIpAddr());
entity.setLoginStatus(AccountEnumType.LOGIN_STATUS_SUCCESS.getCode());
entity.setLogType(AccountEnumType.LOG_TYPE_LOGIN.getCode());
LogLoginEntity entity = AccountLogEntityUtils.getLogLoginEntity(id, super.getProductType(), super.getSourceType(),
AccountEnumType.LOGIN_OUT.getCode(),super.getIpAddr(),AccountEnumType.LOGIN_STATUS_SUCCESS.getCode(),AccountEnumType.LOG_TYPE_LOGIN.getCode());
picaLogUtils.info(entity);
if (redisClient.deleteToken(token)) {
return PicaResponse.toResponse();
......
......@@ -2,6 +2,7 @@ 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.foundation.utils.utils.EncryptCreateUtil;
import java.util.Date;
......@@ -15,7 +16,8 @@ public class AccountLogEntityUtils {
* @param sourceType
* @return
*/
public static LogLoginEntity getLogLoginEntity(Integer acctId, Integer productType, Integer sourceType) {
public static LogLoginEntity getLogLoginEntity(Integer acctId, Integer productType, Integer sourceType,
int code, String ipAddr, int code1, int code2) {
LogLoginEntity entity = new LogLoginEntity();
Date currentTime = new Date();
entity.setAcctId(acctId);
......@@ -27,6 +29,10 @@ public class AccountLogEntityUtils {
entity.setLoginTime(currentTime);
entity.setProductType(productType);
entity.setSourceType(sourceType);
entity.setLoginType(code);
entity.setLoginIp(ipAddr);
entity.setLoginStatus(code1);
entity.setLogType(code2);
return entity;
}
......@@ -36,7 +42,7 @@ public class AccountLogEntityUtils {
* @param acctId
* @return
*/
public static LogPWDModifyEntity getLogPWDModifyEntity(Integer acctId) {
public static LogPWDModifyEntity getLogPWDModifyEntity(Integer acctId, String mobile, String oldpwd, String newPwd, Integer logType) {
LogPWDModifyEntity entity = new LogPWDModifyEntity();
Date currentTime = new Date();
entity.setCreatedId(acctId);
......@@ -44,8 +50,10 @@ public class AccountLogEntityUtils {
entity.setDeleteFlag(1);
entity.setModifiedId(acctId);
entity.setModifiedTime(currentTime);
entity.setMobilePhone(mobile);
entity.setOldPwd(oldpwd);
entity.setNewPwd(EncryptCreateUtil.encrypt(newPwd));
entity.setLogType(logType);
return entity;
}
}
......@@ -14,13 +14,22 @@ public interface AccountUserInfoMapper {
AccountUserInfoEntity selectByPrimaryKey(Integer id);
/**
* 通过户id查询居民信息
* 通过户id查询居民信息
*
* @param id 用户id
* @return
*/
AccountUserInfoEntity selectByUserId(Integer id);
/**
* 通过账户id查询账户信息
*
* @param acctId
* @return
*/
AccountUserInfoEntity selectByAcctId(Integer acctId);
/**
* 更新居民信息接口
*
......@@ -29,6 +38,7 @@ public interface AccountUserInfoMapper {
*/
int updateByPrimaryKeySelective(AccountUserInfoEntity record);
int insertSelective(AccountUserInfoEntity record);
int updateByPrimaryKey(AccountUserInfoEntity record);
......
......@@ -20,4 +20,12 @@ public interface UserInfoService {
* @return
*/
AccountUserInfoEntity getUserInfo(Integer userId);
/**
* 获取用户信息接口
*
* @param acctId 账户id
* @return
*/
AccountUserInfoEntity getUserInfoByAcctId(Integer acctId);
}
......@@ -98,11 +98,9 @@ public class LoginServiceImpl implements LoginService {
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(AccountEnumType.LOGIN_STATUS_SUCCESS.getCode());
entity.setLogType(AccountEnumType.LOG_TYPE_LOGIN.getCode());
LogLoginEntity entity = AccountLogEntityUtils.getLogLoginEntity(acctId, productType, request.getSourceType(),
AccountEnumType.LOGIN_PWD.getCode(), request.getLoginIp(), AccountEnumType.LOGIN_STATUS_SUCCESS.getCode(),
AccountEnumType.LOG_TYPE_LOGIN.getCode());
picaLogUtils.info(entity);
return jsonObject.toJSONString();
} else {
......@@ -133,7 +131,7 @@ public class LoginServiceImpl implements LoginService {
*/
private String processLogin(BaseRequest baseRequest, Integer acctId, Integer loginType) {
Date currentTime = new Date();
AccountUserInfoEntity accountUserInfoEntity = accountUserInfoMapper.selectByAcctId(acctId);
AccountUserInfoEntity accountUserInfoEntity = accountUserInfoMapper.selectByUserId(acctId);
//验证码登陆:只要相同即可成功
AccountReq accountReq = new AccountReq();
accountReq.setAuthCode(baseRequest.getSysCode());
......@@ -151,11 +149,9 @@ public class LoginServiceImpl implements LoginService {
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(AccountEnumType.LOGIN_STATUS_SUCCESS.getCode());
entity.setLogType(AccountEnumType.LOG_TYPE_LOGIN.getCode());
LogLoginEntity entity = AccountLogEntityUtils.getLogLoginEntity(acctId, baseRequest.getProductType(), baseRequest.getSourceType(),
loginType, baseRequest.getLoginIp(), AccountEnumType.LOGIN_STATUS_SUCCESS.getCode(), AccountEnumType.LOG_TYPE_LOGIN.getCode());
;
picaLogUtils.info(entity);
return jsonObject.toJSONString();
}
......
......@@ -36,11 +36,8 @@ public class PasswordServiceImpl implements PasswordService {
accountInfoEntity.setPassword(EncryptCreateUtil.encrypt(pwd));
accountInfoDetailMapper.updatePasswordByPrimaryKey(accountInfoEntity);
//密码修改日志
LogPWDModifyEntity logPWDModifyEntity = AccountLogEntityUtils.getLogPWDModifyEntity(acctId);
logPWDModifyEntity.setMobilePhone(entity.getMobilePhone());
logPWDModifyEntity.setOldPwd(EncryptCreateUtil.encrypt(oldPwd));
logPWDModifyEntity.setNewPwd(EncryptCreateUtil.encrypt(pwd));
logPWDModifyEntity.setLogType(AccountEnumType.LOG_TYPE_PASSWORD.getCode());
LogPWDModifyEntity logPWDModifyEntity = AccountLogEntityUtils.getLogPWDModifyEntity(acctId, entity.getMobilePhone(),
EncryptCreateUtil.encrypt(oldPwd), EncryptCreateUtil.encrypt(pwd), AccountEnumType.LOG_TYPE_PASSWORD.getCode());
picaLogUtils.info(logPWDModifyEntity);
} else {
throw new AccountException(AccountExceptionType.PICA_PASSWORD_ERROR);
......@@ -58,12 +55,10 @@ public class PasswordServiceImpl implements PasswordService {
accountInfoEntity.setModifiedTime(new Date());
accountInfoEntity.setPassword(EncryptCreateUtil.encrypt(request.getPassword()));
accountInfoDetailMapper.updatePasswordByPrimaryKey(accountInfoEntity);
//密码修改日志
LogPWDModifyEntity logPWDModifyEntity = AccountLogEntityUtils.getLogPWDModifyEntity(accId);
logPWDModifyEntity.setMobilePhone(entity.getMobilePhone());
logPWDModifyEntity.setOldPwd("");
logPWDModifyEntity.setNewPwd(EncryptCreateUtil.encrypt(request.getPassword()));
logPWDModifyEntity.setLogType(AccountEnumType.LOG_TYPE_PASSWORD.getCode());
LogPWDModifyEntity logPWDModifyEntity = AccountLogEntityUtils.getLogPWDModifyEntity(accId, entity.getMobilePhone(),
"", EncryptCreateUtil.encrypt(request.getPassword()), AccountEnumType.LOG_TYPE_PASSWORD.getCode());
picaLogUtils.info(logPWDModifyEntity);
} else {
//未注册,请先注册
......
......@@ -16,7 +16,6 @@ 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.redis.ICacheClient;
import com.pica.cloud.foundation.utils.utils.EncryptCreateUtil;
import org.apache.commons.lang3.StringUtils;
......@@ -95,11 +94,9 @@ public class RegisterServiceImpl implements RegisterService {
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(AccountEnumType.LOGIN_STATUS_SUCCESS.getCode());
entity.setLogType(AccountEnumType.LOG_TYPE_LOGIN.getCode());
LogLoginEntity entity = AccountLogEntityUtils.getLogLoginEntity(acctId, productType, baseRequest.getSourceType(),
AccountEnumType.LOGIN_REGISTER.getCode(), baseRequest.getLoginIp(), AccountEnumType.LOGIN_STATUS_SUCCESS.getCode(),
AccountEnumType.LOG_TYPE_LOGIN.getCode());
picaLogUtils.info(entity);
return jsonObject.toJSONString();
} else {
......
......@@ -47,4 +47,9 @@ public class UserInfoServerImpl implements UserInfoService {
public AccountUserInfoEntity getUserInfo(Integer userId) {
return accountUserInfoMapper.selectByUserId(userId);
}
@Override
public AccountUserInfoEntity getUserInfoByAcctId(Integer acctId) {
return accountUserInfoMapper.selectByAcctId(acctId);
}
}
......@@ -45,7 +45,7 @@
where id = #{id,jdbcType=INTEGER}
</select>
<!--通过户id查询信息-->
<!--通过户id查询信息-->
<select id="selectByUserId" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
<include refid="Base_Column_List"/>
......@@ -53,6 +53,13 @@
where id = #{id,jdbcType=INTEGER}
</select>
<!--通过账户id查询信息-->
<select id="selectByAcctId" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
<include refid="Base_Column_List"/>
from p_patient
where acct_id = #{AcctId,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from p_patient
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册