修改登录模块的代码,添加登录次数的代码模块

This commit is contained in:
DESKTOP-G8BCEP0\HP 2021-08-10 09:06:16 +08:00
parent 85ffb7d594
commit 2687fed5da
5 changed files with 55 additions and 4 deletions

View File

@ -100,7 +100,7 @@ public class CustomAuthenticationProvider implements AuthenticationProvider {
for(SysAuthorityEntity sysAuthorityEntity : permissionList) { for(SysAuthorityEntity sysAuthorityEntity : permissionList) {
permissions.add(new GrantedAuthorityImpl(sysAuthorityEntity.getAuthorityName())); permissions.add(new GrantedAuthorityImpl(sysAuthorityEntity.getAuthorityName()));
} }
customAuthenticationProvider.sysUserService.updateLoginNum(userEntity.getId(),userEntity.getLoginNum() + 1);
// 生成令牌 // 生成令牌
Authentication authToken = new UsernamePasswordAuthenticationToken(userName, encryptPassword, permissions); Authentication authToken = new UsernamePasswordAuthenticationToken(userName, encryptPassword, permissions);
return authToken; return authToken;

View File

@ -82,7 +82,7 @@ public interface SysUserDao extends JpaRepository<SysUserEntity,Integer> {
* 查询用户信息 * 查询用户信息
* @return * @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") "from SysUserEntity")
List<SysUserVo> selectAll(); List<SysUserVo> selectAll();
@ -91,7 +91,7 @@ public interface SysUserDao extends JpaRepository<SysUserEntity,Integer> {
* @param userName * @param userName
* @return * @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") "from SysUserEntity where userName = :userName")
SysUserVo selectUserByUserName(String userName); SysUserVo selectUserByUserName(String userName);
@ -142,5 +142,15 @@ public interface SysUserDao extends JpaRepository<SysUserEntity,Integer> {
* @param userId * @param userId
*/ */
@Query(value = "update sys_user set over_time = '永久' and day_num = 1 where id = ?",nativeQuery = true) @Query(value = "update sys_user set over_time = '永久' and day_num = 1 where id = ?",nativeQuery = true)
@Modifying(clearAutomatically=true)
void updateDayNum(Integer userId); 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);
} }

View File

@ -28,7 +28,11 @@ public class SysUserVo implements Serializable {
private String countyName; 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.id = id;
this.reallyName = reallyName; this.reallyName = reallyName;
this.telephone = telephone; this.telephone = telephone;
@ -39,6 +43,8 @@ public class SysUserVo implements Serializable {
this.dayNum = dayNum; this.dayNum = dayNum;
this.accountType = accountType; this.accountType = accountType;
this.countyName = countyName; this.countyName = countyName;
this.lastEntryIp = lastEntryIp;
this.loginNum = loginNum;
} }
public Integer getId() { public Integer getId() {
@ -120,5 +126,21 @@ public class SysUserVo implements Serializable {
public void setCountyName(String countyName) { public void setCountyName(String countyName) {
this.countyName = 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;
}
} }

View File

@ -143,4 +143,11 @@ public interface SysUserService {
* @return * @return
*/ */
String updateOverTime(Integer userId,String overTime); String updateOverTime(Integer userId,String overTime);
/**
* 记录用户登录次数
* @param userId
* @param loginNum
*/
void updateLoginNum(Integer userId,Integer loginNum);
} }

View File

@ -100,6 +100,7 @@ public class SysUserServiceImpl implements SysUserService {
sysUserEntity.setDayNum(7); sysUserEntity.setDayNum(7);
String string = dateTimeToString(LocalDateTime.now().plusDays(7L)); String string = dateTimeToString(LocalDateTime.now().plusDays(7L));
sysUserEntity.setOverTime(string); sysUserEntity.setOverTime(string);
sysUserEntity.setLoginNum(0);
sysUserEntity.setCountyName(sysUserQo.getCountyName()); sysUserEntity.setCountyName(sysUserQo.getCountyName());
sysUserDao.save(sysUserEntity); sysUserDao.save(sysUserEntity);
@ -365,4 +366,15 @@ public class SysUserServiceImpl implements SysUserService {
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"修改成功",locale); 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);
}
} }