package com.ruoyi; import com.ruoyi.common.core.domain.entity.SysRole; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.system.mapper.SysRoleMapper; import com.ruoyi.system.service.ISysRoleService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; @Component public class RoleTask { @Autowired private SysRoleMapper sysRoleMapper; @Scheduled(cron="0 0 0 * * ?") //每日00:00执行数据 // @Scheduled(cron="0/10 * * * * ?") //每日00:00执行数据 public void execute() throws ParseException { List list =sysRoleMapper.selectRoleAllList(); Date date = new Date(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //设置日期格式 for(SysRole sysRole:list){ if(sysRole.getRemark() != null && StringUtils.isNotBlank(sysRole.getRemark()) && sysRole.getRoleId() != 1){ Date youxiaoqi = df.parse(sysRole.getRemark()); if(youxiaoqi.getTime() < date.getTime()){ sysRole.setStatus("1"); sysRoleMapper.updateById(sysRole); } } } } }