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

import java.util.List;

public class SpecDevCcThread implements Runnable {

    private ITSpecdevCcService specdevCcService;
    protected final Logger logger = LoggerFactory.getLogger(BaseController.class);
    public SpecDevCcThread(ITSpecdevCcService specdevCcService) {
        this.specdevCcService = specdevCcService;
    }

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