REM:
1. 增加用户管理数据库相关代码
This commit is contained in:
HuangXin 2020-07-17 17:47:24 +08:00
parent cdc880b575
commit 86456fef59
6 changed files with 100 additions and 32 deletions

View File

@ -1,7 +1,6 @@
package com.dispose.manager;
import com.dispose.common.ErrorCode;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.security.NoSuchAlgorithmException;
@ -75,12 +74,4 @@ public interface UserAccountCacheManager {
* @return the error code
*/
ErrorCode verifyPermission(String token);
/**
* Gets cache user.
*
* @return the cache user
* @throws JsonProcessingException the json processing exception
*/
String getCacheUser() throws JsonProcessingException;
}

View File

@ -36,9 +36,34 @@ public interface UserAccountMapper extends Mapper<UserAccount>,
void unlockUserAccount(@Param("username") String username);
/**
* Refresh login time.
* Upgrade login time.
*
* @param username the username
*/
void refreshLoginTime(@Param("username") String username);
void upgradeLoginTime(@Param("username") String username);
/**
* Upgrade last access time.
*
* @param username the username
*/
void upgradeLastAccessTime(@Param("username") String username);
/**
* Upgrade token.
*
* @param username the username
* @param token the token
*/
void upgradeToken(@Param("username") String username,
@Param("token") String token);
/**
* Sets pwd err times.
*
* @param username the username
* @param pwdErrTimes the pwd err times
*/
void setPwdErrTimes(@Param("username") String username,
@Param("pwdErrTimes") Integer pwdErrTimes);
}

View File

@ -29,20 +29,59 @@ import java.io.Serializable;
@NameStyle(Style.normal)
public class UserAccount implements Serializable {
/**
* The constant serialVersionUID.
*/
private static final long serialVersionUID = -1L;
/**
* The Id.
*/
@Id
@KeySql(useGeneratedKeys = true)
private Long id;
/**
* The Username.
*/
private String username;
/**
* The Password.
*/
private String password;
/**
* The Last login time.
*/
private String lastLoginTime;
/**
* The Token.
*/
private String token;
/**
* The Last access.
*/
private String lastAccess;
/**
* The Pwd err times.
*/
private Integer pwdErrTimes;
/**
* The Lock time.
*/
private String lockTime;
/**
* The Status.
* 0: 正常
* 1: 锁定
* 2: 禁用
* 3: 删除
*/
private Integer status;
}

View File

@ -58,7 +58,7 @@ public class UserAccountServiceImpl implements UserAccountService {
*/
@Override
public MulReturnType<ErrorCode, String> loginService(String username, String password) throws NoSuchAlgorithmException {
userAccountMapper.refreshLoginTime(username);
userAccountMapper.upgradeLoginTime(username);
UserAccount loginUser = userAccountMapper.getUserByName(username);
// 该用户是否存在

View File

@ -7,6 +7,7 @@
FROM user_account
WHERE username = #{username}
</select>
<update id="lockUserAccount">
UPDATE
user_account
@ -14,6 +15,7 @@
lockTime = CURRENT_TIMESTAMP
WHERE username = #{username, jdbcType=VARCHAR}
</update>
<update id="unlockUserAccount">
UPDATE
user_account
@ -21,10 +23,32 @@
lockTime = 0
WHERE username = #{username, jdbcType=VARCHAR}
</update>
<update id="refreshLoginTime">
<update id="upgradeLoginTime">
UPDATE
user_account
SET lastLoginTime = CURRENT_TIMESTAMP
WHERE username = #{username, jdbcType=VARCHAR}
</update>
<update id="upgradeLastAccessTime">
UPDATE
user_account
SET lastAccess = CURRENT_TIMESTAMP
WHERE username = #{username, jdbcType=VARCHAR}
</update>
<update id="upgradeToken">
UPDATE
user_account
SET token = #{token, jdbcType=VARCHAR}
WHERE username = #{username, jdbcType=VARCHAR}
</update>
<update id="setPwdErrTimes">
UPDATE
user_account
SET pwdErrTimes = #{pwdErrTimes, jdbcType=INTEGER}
WHERE username = #{username, jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -3,7 +3,6 @@ package com.dispose.test.mapper;
import com.dispose.common.ConstValue;
import com.dispose.mapper.UserAccountMapper;
import com.dispose.pojo.entity.UserAccount;
import com.dispose.test.Global.InitTestEnvironment;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
@ -29,7 +28,7 @@ import javax.annotation.Resource;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Transactional
@Rollback
public class UserAccountMapperTest extends InitTestEnvironment {
public class UserAccountMapperTest {
/**
* The Obj mapper.
*/
@ -54,6 +53,7 @@ public class UserAccountMapperTest extends InitTestEnvironment {
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
Assert.assertNotNull(user);
Assert.assertEquals(user.getUsername(), "admin");
}
/**
@ -70,34 +70,23 @@ public class UserAccountMapperTest extends InitTestEnvironment {
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
userAccountMapper.unlockUserAccount("admin");
user = userAccountMapper.getUserByName("admin");
Assert.assertEquals(new Long(user.getStatus()), new Long(ConstValue.UserAccountStatus.NORMAL));
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
}
/**
* T 3 refresh login time.
* T 3 upgrade login time.
*
* @throws JsonProcessingException the json processing exception
*/
@Test
public void t3_refreshLoginTime() throws JsonProcessingException {
userAccountMapper.refreshLoginTime("admin");
public void t3_upgradeLoginTime() throws JsonProcessingException {
userAccountMapper.upgradeLoginTime("admin");
UserAccount user = userAccountMapper.getUserByName("admin");
Assert.assertNotNull(user);
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
}
/**
* T 4 unlock user.
*
* @throws JsonProcessingException the json processing exception
*/
@Test
public void t4_unlockUser() throws JsonProcessingException {
userAccountMapper.unlockUserAccount("admin");
UserAccount user = userAccountMapper.getUserByName("admin");
Assert.assertEquals(new Long(user.getStatus()), new Long(ConstValue.UserAccountStatus.NORMAL));
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
}
}