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

20190903 日志模块代码优化

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