From 2687fed5daf0fb0494cdea1684996ad6259e1fb9 Mon Sep 17 00:00:00 2001 From: "DESKTOP-G8BCEP0\\HP" <2037158277@qq.com> Date: Tue, 10 Aug 2021 09:06:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=99=BB=E5=BD=95=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E7=9A=84=E4=BB=A3=E7=A0=81=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=AC=A1=E6=95=B0=E7=9A=84=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../account/CustomAuthenticationProvider.java | 2 +- src/main/java/com/xkrs/dao/SysUserDao.java | 14 +++++++++-- .../java/com/xkrs/model/vo/SysUserVo.java | 24 ++++++++++++++++++- .../java/com/xkrs/service/SysUserService.java | 7 ++++++ .../xkrs/service/impl/SysUserServiceImpl.java | 12 ++++++++++ 5 files changed, 55 insertions(+), 4 deletions(-) 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); + } + }