| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springblade.common.constant.CommonConstant; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.mp.base.BaseServiceImpl; |
| | |
| | | import org.springblade.system.user.service.IUserService; |
| | | import org.springblade.system.user.vo.UserVO; |
| | | import org.springblade.system.user.wrapper.UserWrapper; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.DigestUtils; |
| | |
| | | * @author Chill |
| | | */ |
| | | @Service |
| | | @AllArgsConstructor |
| | | @RequiredArgsConstructor |
| | | public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implements IUserService { |
| | | private static final String GUEST_NAME = "guest"; |
| | | |
| | |
| | | private final IUserOauthService userOauthService; |
| | | private final ISysClient sysClient; |
| | | private final BladeTenantProperties tenantProperties; |
| | | //拿到配置的超管id |
| | | @Value("${user-info.id}") |
| | | private String adminUserId; |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | if(!result){ |
| | | throw new ServiceException(resException); |
| | | } |
| | | //修改密码同时,改变用户信息中的密码修改状态字段 |
| | | //修改密码同时,改变用户信息中的密码修改状态字段,密码修改时间 |
| | | return this.update(Wrappers.<User>update().lambda() |
| | | .set(User::getPassword, DigestUtil.hex(DigestUtils.md5DigestAsHex((newPassword1).getBytes()))) |
| | | .set(User::getStrategyUpdateStatus,CommonConstant.TOP_PARENT_ID) |
| | | .set(User::getPwdUpdateTime,new Date()) |
| | | .eq(User::getId, userId)); |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | public Long checkRenAndExpr(Long userId) { |
| | | //超级管理员直接返回不需要提醒密码修改 |
| | | if(adminUserId.equals(userId)){ |
| | | return 0L; |
| | | } |
| | | //获取到密码修改时间 |
| | | Date pwdUpdateTime = this.getOne(Wrappers.<User>query().eq("ID", userId)).getPwdUpdateTime(); |
| | | Long pwdupdateday = 0L; |
| | |
| | | pwdupdateday = dateToDay(pwdUpdateTime); |
| | | } |
| | | Strategy strategy = sysClient.getByUserId(userId).getData(); |
| | | System.out.println("当前时间=================="+dateToDay(new Date())); |
| | | System.out.println("密码修改时间======================"+pwdupdateday); |
| | | System.out.println("提醒时间======================"+strategy.getReminderTime()); |
| | | System.out.println("过期时间======================="+strategy.getExpirationTime()); |
| | | //是否提醒通过最后一次修改密码的时间加上过期时间减去当前时间,如果小于过期提醒时间就进行提醒,如果<=0就提醒必须修改密码 |
| | | long reminder = pwdupdateday+strategy.getExpirationTime()-dateToDay(pwdUpdateTime); |
| | | //必须去修改密码 |
| | | //提醒用户必须修改密码 |
| | | if(reminder<=0){ |
| | | return -1L; |
| | | } |
| | |
| | | return 0L; |
| | | } |
| | | |
| | | /** |
| | | * 时间格式转天 |
| | | * @param date |
| | | * @return |
| | | */ |
| | | private Long dateToDay(Date date){ |
| | | long time = date.getTime(); |
| | | return time/(1000 * 60 * 60 * 24); |