diff --git a/src/main/java/com/dispose/manager/UserAccountCacheManager.java b/src/main/java/com/dispose/manager/UserAccountCacheManager.java index 4ba91967..4e15c084 100644 --- a/src/main/java/com/dispose/manager/UserAccountCacheManager.java +++ b/src/main/java/com/dispose/manager/UserAccountCacheManager.java @@ -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; } diff --git a/src/main/java/com/dispose/mapper/UserAccountMapper.java b/src/main/java/com/dispose/mapper/UserAccountMapper.java index a8413563..8818814e 100644 --- a/src/main/java/com/dispose/mapper/UserAccountMapper.java +++ b/src/main/java/com/dispose/mapper/UserAccountMapper.java @@ -36,9 +36,34 @@ public interface UserAccountMapper extends Mapper, 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); } diff --git a/src/main/java/com/dispose/pojo/entity/UserAccount.java b/src/main/java/com/dispose/pojo/entity/UserAccount.java index 33f78175..1275ee8e 100644 --- a/src/main/java/com/dispose/pojo/entity/UserAccount.java +++ b/src/main/java/com/dispose/pojo/entity/UserAccount.java @@ -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; } diff --git a/src/main/java/com/dispose/service/impl/UserAccountServiceImpl.java b/src/main/java/com/dispose/service/impl/UserAccountServiceImpl.java index 16918fb6..a2275dac 100644 --- a/src/main/java/com/dispose/service/impl/UserAccountServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/UserAccountServiceImpl.java @@ -58,7 +58,7 @@ public class UserAccountServiceImpl implements UserAccountService { */ @Override public MulReturnType loginService(String username, String password) throws NoSuchAlgorithmException { - userAccountMapper.refreshLoginTime(username); + userAccountMapper.upgradeLoginTime(username); UserAccount loginUser = userAccountMapper.getUserByName(username); // 该用户是否存在 diff --git a/src/main/resources/mappers/UserAccount.xml b/src/main/resources/mappers/UserAccount.xml index 71ad50b4..627c3558 100644 --- a/src/main/resources/mappers/UserAccount.xml +++ b/src/main/resources/mappers/UserAccount.xml @@ -7,6 +7,7 @@ FROM user_account WHERE username = #{username} + UPDATE user_account @@ -14,6 +15,7 @@ lockTime = CURRENT_TIMESTAMP WHERE username = #{username, jdbcType=VARCHAR} + UPDATE user_account @@ -21,10 +23,32 @@ lockTime = 0 WHERE username = #{username, jdbcType=VARCHAR} - + + UPDATE user_account SET lastLoginTime = CURRENT_TIMESTAMP WHERE username = #{username, jdbcType=VARCHAR} + + + UPDATE + user_account + SET lastAccess = CURRENT_TIMESTAMP + WHERE username = #{username, jdbcType=VARCHAR} + + + + UPDATE + user_account + SET token = #{token, jdbcType=VARCHAR} + WHERE username = #{username, jdbcType=VARCHAR} + + + + UPDATE + user_account + SET pwdErrTimes = #{pwdErrTimes, jdbcType=INTEGER} + WHERE username = #{username, jdbcType=VARCHAR} + \ No newline at end of file diff --git a/src/test/java/com/dispose/test/mapper/UserAccountMapperTest.java b/src/test/java/com/dispose/test/mapper/UserAccountMapperTest.java index 35f68fc8..3e4d7da5 100644 --- a/src/test/java/com/dispose/test/mapper/UserAccountMapperTest.java +++ b/src/test/java/com/dispose/test/mapper/UserAccountMapperTest.java @@ -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)); - } }