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

import java.util.List;

public class SpecDevDtThread implements Runnable {

    private ITSpecdevDtService specdevDtService;
    protected final Logger logger = LoggerFactory.getLogger(BaseController.class);
    public SpecDevDtThread(ITSpecdevDtService specdevDtService) {
        this.specdevDtService = specdevDtService;
    }

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