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.TSpecdevDzsb;
import com.ruoyi.project.sems.service.ITSpecdevDzsbService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class SpecDevDzsbThread implements Runnable {

    private ITSpecdevDzsbService specdevDzsbService;
    protected final Logger logger = LoggerFactory.getLogger(BaseController.class);
    public SpecDevDzsbThread(ITSpecdevDzsbService specdevDzsbService) {
        this.specdevDzsbService = specdevDzsbService;
    }

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