package com.njcn.system.timer.tasks;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.njcn.dataProcess.api.DataRecallFeignClient;
import com.njcn.message.message.RecallMessage;
import com.njcn.system.pojo.po.PqFrontLogs;
import com.njcn.system.pojo.po.PqFrontLogsChild;
import com.njcn.system.service.PqFrontLogsChildService;
import com.njcn.system.service.PqFrontLogsService;
import com.njcn.system.timer.TimerTaskRunner;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.time.LocalDate;

/**
 * 类的介绍：装置算法执行链定时任务
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2023/12/6 9:35
 */
@Component
@RequiredArgsConstructor
public class FrontLogsCleanTaskRunner implements TimerTaskRunner {

    private final PqFrontLogsChildService pqFrontLogsChildService;
    private final PqFrontLogsService pqFrontLogsService;


    @Override
    public void action(String date) {
        //主表清60d的之前的数据，子表清7天之前的数据
        QueryWrapper<PqFrontLogsChild> queryWrapper = new QueryWrapper<>();
        QueryWrapper<PqFrontLogs> pqFrontLogsQueryWrapper = new QueryWrapper<>();
        LocalDate calDate;
        if(!StrUtil.isBlank(date)){
            calDate = LocalDate.parse(date, DatePattern.NORM_DATE_FORMATTER);

        }else {
            calDate =LocalDate.now();
        }

        queryWrapper.lambda().lt(PqFrontLogsChild::getCreateTime,calDate.minusDays(7).atTime(0,0,0));
        pqFrontLogsChildService.getBaseMapper().delete(queryWrapper);
        pqFrontLogsQueryWrapper.lambda().lt(PqFrontLogs::getUpdateTime,calDate.minusDays(60).atTime(0,0,0));
        pqFrontLogsService.getBaseMapper().delete(pqFrontLogsQueryWrapper);
    }


}
