添加了修改用户账号过期时间的接口

This commit is contained in:
DESKTOP-G8BCEP0\HP 2021-08-04 16:17:58 +08:00
parent 46d43660d1
commit 5c172ae90b
5 changed files with 161 additions and 0 deletions

View File

@ -54,6 +54,7 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers(HttpMethod.GET,"/selectFirePoint").permitAll()
.antMatchers(HttpMethod.POST,"/updateTypeByFireCode").permitAll()
.antMatchers(HttpMethod.GET,"/api/user/verificationCode").permitAll()
.antMatchers(HttpMethod.POST,"/api/user/updateExpireDate").permitAll()
// 所有其它请求需要身份认证
.anyRequest().authenticated()
.and()

View File

@ -264,4 +264,24 @@ public class SysUserController {
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"",locale);
}
/**
* 更改账号过期时间
* @return
*/
@PostMapping("/updateExpireDate")
public String updateExpireDate(@RequestBody Map map){
Integer userId = (Integer) map.get("userId");
Integer timeNum = (Integer) map.get("timeNum");
String keepType = (String) map.get("keepType");
if("1".equals(keepType)){
return sysUserService.updateExpireDateDay(userId, timeNum);
}else if("2".equals(keepType)){
return sysUserService.updateExpireDateMonth(userId,timeNum);
}else if("3".equals(keepType)){
return sysUserService.updateExpireDateYear(userId,timeNum);
}else {
return sysUserService.updatePermanent(userId);
}
}
}

View File

@ -127,4 +127,20 @@ public interface SysUserDao extends JpaRepository<SysUserEntity,Integer> {
*/
@Query(value = "select * from sys_user where id = ?",nativeQuery = true)
SysUserEntity selectByUserId(Integer userId);
/**
* 根据id修改账户的到期时间
* @param userId
* @param overTime
*/
@Query(value = "update sys_user set over_time = ?2 where id = ?1",nativeQuery = true)
@Modifying(clearAutomatically=true)
void updateOverTime(Integer userId,String overTime);
/**
* 将账户的期限修改为永久有效
* @param userId
*/
@Query(value = "update sys_user set over_time = '永久' and day_num = 1 where id = ?",nativeQuery = true)
void updateDayNum(Integer userId);
}

View File

@ -103,4 +103,35 @@ public interface SysUserService {
* @return
*/
SysUserVo getUserByUserName(String userName);
/**
* 按天数修改账号到期时间
* @param userId
* @param dayNum
* @return
*/
String updateExpireDateDay(Integer userId, Integer dayNum);
/**
* 按月份修改账号到期时间
* @param userId
* @param dayNum
* @return
*/
String updateExpireDateMonth(Integer userId, Integer dayNum);
/**
* 按年份修改账号到期时间
* @param userId
* @param dayNum
* @return
*/
String updateExpireDateYear(Integer userId, Integer dayNum);
/**
* 设置账号时间永久有效
* @param userId
* @return
*/
String updatePermanent(Integer userId);
}

View File

@ -247,4 +247,97 @@ public class SysUserServiceImpl implements SysUserService {
return sysUserDao.selectUserByUserName(userName);
}
/**
* 按天数修改账号到期时间
* @param userId
* @param dayNum
* @return
*/
@Transactional(rollbackFor=Exception.class)
@Override
public String updateExpireDateDay(Integer userId, Integer dayNum) {
Locale locale = LocaleContextHolder.getLocale();
long l = dayNum.longValue();
LocalDateTime now = LocalDateTime.now();
SysUserEntity sysUserEntity = sysUserDao.selectByUserId(userId);
if(DateTimeUtil.dateTimeToString(now).compareTo(sysUserEntity.getOverTime()) > 0){
LocalDateTime localDateTime = now.plusDays(l);
String time = dateTimeToString(localDateTime);
sysUserDao.updateOverTime(userId,time);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"修改成功",locale);
}else {
LocalDateTime localDateTime = DateTimeUtil.stringToDateTime(sysUserEntity.getOverTime());
LocalDateTime localDateTime1 = localDateTime.plusDays(l);
String time = dateTimeToString(localDateTime1);
sysUserDao.updateOverTime(userId,time);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"修改成功",locale);
}
}
/**
* 按月份修改账号过期时间
* @param userId
* @param dayNum
* @return
*/
@Transactional(rollbackFor=Exception.class)
@Override
public String updateExpireDateMonth(Integer userId, Integer dayNum) {
Locale locale = LocaleContextHolder.getLocale();
long l = dayNum.longValue();
LocalDateTime now = LocalDateTime.now();
SysUserEntity sysUserEntity = sysUserDao.selectByUserId(userId);
if(DateTimeUtil.dateTimeToString(now).compareTo(sysUserEntity.getOverTime()) > 0){
LocalDateTime localDateTime = now.plusMonths(l);
String time = dateTimeToString(localDateTime);
sysUserDao.updateOverTime(userId,time);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"修改成功",locale);
}else {
LocalDateTime localDateTime = DateTimeUtil.stringToDateTime(sysUserEntity.getOverTime());
LocalDateTime localDateTime1 = localDateTime.plusMonths(l);
String time = dateTimeToString(localDateTime1);
sysUserDao.updateOverTime(userId,time);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"修改成功",locale);
}
}
/**
* 按年份修改账号到期时间
* @param userId
* @param dayNum
* @return
*/
@Transactional(rollbackFor=Exception.class)
@Override
public String updateExpireDateYear(Integer userId, Integer dayNum) {
Locale locale = LocaleContextHolder.getLocale();
long l = dayNum.longValue();
LocalDateTime now = LocalDateTime.now();
SysUserEntity sysUserEntity = sysUserDao.selectByUserId(userId);
if(DateTimeUtil.dateTimeToString(now).compareTo(sysUserEntity.getOverTime()) > 0){
LocalDateTime localDateTime = now.plusYears(l);
String time = dateTimeToString(localDateTime);
sysUserDao.updateOverTime(userId,time);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"修改成功",locale);
}else {
LocalDateTime localDateTime = DateTimeUtil.stringToDateTime(sysUserEntity.getOverTime());
LocalDateTime localDateTime1 = localDateTime.plusYears(l);
String time = dateTimeToString(localDateTime1);
sysUserDao.updateOverTime(userId,time);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"修改成功",locale);
}
}
/**
* 设置账号永久有效
* @param userId
* @return
*/
@Override
public String updatePermanent(Integer userId) {
Locale locale = LocaleContextHolder.getLocale();
sysUserDao.updateDayNum(userId);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"修改成功",locale);
}
}