diff --git a/src/main/java/com/xkrs/common/account/CustomAuthenticationProvider.java b/src/main/java/com/xkrs/common/account/CustomAuthenticationProvider.java index a5486c3..02885a0 100644 --- a/src/main/java/com/xkrs/common/account/CustomAuthenticationProvider.java +++ b/src/main/java/com/xkrs/common/account/CustomAuthenticationProvider.java @@ -100,7 +100,7 @@ public class CustomAuthenticationProvider implements AuthenticationProvider { for(SysAuthorityEntity sysAuthorityEntity : permissionList) { permissions.add(new GrantedAuthorityImpl(sysAuthorityEntity.getAuthorityName())); } - + customAuthenticationProvider.sysUserService.updateLoginNum(userEntity.getId(),userEntity.getLoginNum() + 1); // 生成令牌 Authentication authToken = new UsernamePasswordAuthenticationToken(userName, encryptPassword, permissions); return authToken; diff --git a/src/main/java/com/xkrs/dao/SysUserDao.java b/src/main/java/com/xkrs/dao/SysUserDao.java index 4c1a77a..39bce2d 100644 --- a/src/main/java/com/xkrs/dao/SysUserDao.java +++ b/src/main/java/com/xkrs/dao/SysUserDao.java @@ -82,7 +82,7 @@ public interface SysUserDao extends JpaRepository { * 查询用户信息 * @return */ - @Query(value = "select new com.xkrs.model.vo.SysUserVo (id,reallyName,telephone,countyCode,activeFlag,addTime,overTime,dayNum,accountType,countyName) " + + @Query(value = "select new com.xkrs.model.vo.SysUserVo (id,reallyName,telephone,countyCode,activeFlag,addTime,overTime,dayNum,accountType,countyName,lastEntryIp,loginNum) " + "from SysUserEntity") List selectAll(); @@ -91,7 +91,7 @@ public interface SysUserDao extends JpaRepository { * @param userName * @return */ - @Query(value = "select new com.xkrs.model.vo.SysUserVo (id,reallyName,telephone,countyCode,activeFlag,addTime,overTime,dayNum,accountType,countyName) " + + @Query(value = "select new com.xkrs.model.vo.SysUserVo (id,reallyName,telephone,countyCode,activeFlag,addTime,overTime,dayNum,accountType,countyName,lastEntryIp,loginNum) " + "from SysUserEntity where userName = :userName") SysUserVo selectUserByUserName(String userName); @@ -142,5 +142,15 @@ public interface SysUserDao extends JpaRepository { * @param userId */ @Query(value = "update sys_user set over_time = '永久' and day_num = 1 where id = ?",nativeQuery = true) + @Modifying(clearAutomatically=true) void updateDayNum(Integer userId); + + /** + * 记录用户登录次数 + * @param userId + * @param loginNum + */ + @Query(value = "update sys_user set login_num = ?2 where id = ?1",nativeQuery = true) + @Modifying(clearAutomatically=true) + void updateLoginNum(Integer userId,Integer loginNum); } diff --git a/src/main/java/com/xkrs/model/vo/SysUserVo.java b/src/main/java/com/xkrs/model/vo/SysUserVo.java index 76eecc2..6cb8295 100644 --- a/src/main/java/com/xkrs/model/vo/SysUserVo.java +++ b/src/main/java/com/xkrs/model/vo/SysUserVo.java @@ -28,7 +28,11 @@ public class SysUserVo implements Serializable { private String countyName; - public SysUserVo(Integer id, String reallyName, String telephone, String countyCode, Integer activeFlag, String addTime, String overTime, Integer dayNum, String accountType, String countyName) { + private String lastEntryIp; + + private Integer loginNum; + + public SysUserVo(Integer id, String reallyName, String telephone, String countyCode, Integer activeFlag, String addTime, String overTime, Integer dayNum, String accountType, String countyName, String lastEntryIp, Integer loginNum) { this.id = id; this.reallyName = reallyName; this.telephone = telephone; @@ -39,6 +43,8 @@ public class SysUserVo implements Serializable { this.dayNum = dayNum; this.accountType = accountType; this.countyName = countyName; + this.lastEntryIp = lastEntryIp; + this.loginNum = loginNum; } public Integer getId() { @@ -120,5 +126,21 @@ public class SysUserVo implements Serializable { public void setCountyName(String countyName) { this.countyName = countyName; } + + public String getLastEntryIp() { + return lastEntryIp; + } + + public void setLastEntryIp(String lastEntryIp) { + this.lastEntryIp = lastEntryIp; + } + + public Integer getLoginNum() { + return loginNum; + } + + public void setLoginNum(Integer loginNum) { + this.loginNum = loginNum; + } } diff --git a/src/main/java/com/xkrs/service/SysUserService.java b/src/main/java/com/xkrs/service/SysUserService.java index d8d0886..ef23fc0 100644 --- a/src/main/java/com/xkrs/service/SysUserService.java +++ b/src/main/java/com/xkrs/service/SysUserService.java @@ -143,4 +143,11 @@ public interface SysUserService { * @return */ String updateOverTime(Integer userId,String overTime); + + /** + * 记录用户登录次数 + * @param userId + * @param loginNum + */ + void updateLoginNum(Integer userId,Integer loginNum); } diff --git a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java index b32d4dd..4c9922f 100644 --- a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java @@ -100,6 +100,7 @@ public class SysUserServiceImpl implements SysUserService { sysUserEntity.setDayNum(7); String string = dateTimeToString(LocalDateTime.now().plusDays(7L)); sysUserEntity.setOverTime(string); + sysUserEntity.setLoginNum(0); sysUserEntity.setCountyName(sysUserQo.getCountyName()); sysUserDao.save(sysUserEntity); @@ -365,4 +366,15 @@ public class SysUserServiceImpl implements SysUserService { return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"修改成功",locale); } + /** + * 记录用户登录次数 + * @param userId + * @param loginNum + */ + @Transactional(rollbackFor=Exception.class) + @Override + public void updateLoginNum(Integer userId, Integer loginNum) { + sysUserDao.updateLoginNum(userId,loginNum); + } + }