diff --git a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java index 9f3cf4f..4f42c9e 100644 --- a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java +++ b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java @@ -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() diff --git a/src/main/java/com/xkrs/controller/SysUserController.java b/src/main/java/com/xkrs/controller/SysUserController.java index 0c02acc..d662b62 100644 --- a/src/main/java/com/xkrs/controller/SysUserController.java +++ b/src/main/java/com/xkrs/controller/SysUserController.java @@ -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); + } + } + } diff --git a/src/main/java/com/xkrs/dao/SysUserDao.java b/src/main/java/com/xkrs/dao/SysUserDao.java index 7615138..57b6069 100644 --- a/src/main/java/com/xkrs/dao/SysUserDao.java +++ b/src/main/java/com/xkrs/dao/SysUserDao.java @@ -127,4 +127,20 @@ public interface SysUserDao extends JpaRepository { */ @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); } diff --git a/src/main/java/com/xkrs/service/SysUserService.java b/src/main/java/com/xkrs/service/SysUserService.java index 2dd5787..f8edcad 100644 --- a/src/main/java/com/xkrs/service/SysUserService.java +++ b/src/main/java/com/xkrs/service/SysUserService.java @@ -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); } diff --git a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java index ba5af82..98bf756 100644 --- a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java @@ -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); + } + }