package com.ruoyi.common.thread.sems;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.project.sems.domain.TSpecdevYlgd;
import com.ruoyi.project.sems.domain.TSpecdevYlrq;
import com.ruoyi.project.sems.service.ITSpecdevYlgdService;
import com.ruoyi.project.sems.service.ITSpecdevYlrqService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class SpecDevYlgdThread implements Runnable {

    private ITSpecdevYlgdService specdevYlgdService;
    protected final Logger logger = LoggerFactory.getLogger(BaseController.class);
    public SpecDevYlgdThread(ITSpecdevYlgdService specdevYlgdService) {
        this.specdevYlgdService = specdevYlgdService;
    }

    @Override
    public void run() {
        List<TSpecdevYlgd> list = this.specdevYlgdService.list(new QueryWrapper<TSpecdevYlgd>()
                .eq("del_flag", 0).eq("status", "1"));
        logger.info("开始循环");
        //重置Repeat
        for (TSpecdevYlgd t : list
             ) {
            t.setIsRepeat(0L);
            this.specdevYlgdService.updateTSpecdevYlgd(t);
        }
        for (TSpecdevYlgd tSpecdevYlgd : list) {
            for (TSpecdevYlgd specdevYlgd : list) {
                if (tSpecdevYlgd.getId() == specdevYlgd.getId() || StringUtils.isEmpty(tSpecdevYlgd.getDevno())
                        || StringUtils.isEmpty(specdevYlgd.getDevno())) {
                    continue;
                }
                if (tSpecdevYlgd.getDevno().equals(specdevYlgd.getDevno()) && tSpecdevYlgd.getPlantCode().equals(specdevYlgd.getPlantCode())) {
                    specdevYlgd.setIsRepeat(1L);
                    this.specdevYlgdService.updateTSpecdevYlgd(specdevYlgd);
                }
            }
        }
    }
}
