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

import java.util.List;

public class SpecDevGlThread implements Runnable {

    private ITSpecdevGlService specdevGlService;
    protected final Logger logger = LoggerFactory.getLogger(BaseController.class);
    public SpecDevGlThread(ITSpecdevGlService specdevGlService) {
        this.specdevGlService = specdevGlService;
    }

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