package com.yfd.platform.task;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yfd.platform.system.domain.Message;
import com.yfd.platform.system.service.IMessageService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.List;

/**
 *
 * @Date: 2023/3/22 15:39
 * @Description:
 */
@Component
public class TaskMessage {

    @Resource
    private IMessageService messageService;


    /**********************************
     * 用途说明: 定时监控消息是否过期
     * 参数说明 iis_examine_plan,iis_task,iis_task_result,iis_task_todo
     * 返回值说明: void
     ***********************************/
    public void examineMessage() {
        List<Message> list =
                messageService.list(new LambdaQueryWrapper<Message>().eq(Message::getStatus, "1"));
        for (Message message : list) {
            Timestamp createtime = message.getCreatetime();
            Timestamp timestamp = new Timestamp(System.currentTimeMillis());
            long create = createtime.getTime();
            long now = timestamp.getTime();
            Integer validperiod = message.getValidperiod();
            long v = validperiod * 60 * 60 * 1000;
            if ((now - create) > v) {
                message.setStatus("9");
                message.setReadtime(new Timestamp(System.currentTimeMillis()));
                messageService.updateById(message);
            }
        }
    }

}
