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

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) {
permissions.add(new GrantedAuthorityImpl(sysAuthorityEntity.getAuthorityName()));
}
customAuthenticationProvider.sysUserService.updateLoginNum(userEntity.getId(),userEntity.getLoginNum() + 1);
// 生成令牌
Authentication authToken = new UsernamePasswordAuthenticationToken(userName, encryptPassword, permissions);
return authToken;

View File

@ -82,7 +82,7 @@ public interface SysUserDao extends JpaRepository<SysUserEntity,Integer> {
* 查询用户信息
* @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<SysUserVo> selectAll();
@ -91,7 +91,7 @@ public interface SysUserDao extends JpaRepository<SysUserEntity,Integer> {
* @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<SysUserEntity,Integer> {
* @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);
}

View File

@ -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;
}
}

View File

@ -143,4 +143,11 @@ public interface SysUserService {
* @return
*/
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);
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);
}
}