package com.ruoyi.common.thread.sems;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.sems.domain.TSpecdevYlrq;
import com.ruoyi.project.sems.service.ITSpecdevYlrqService;

import java.util.List;

public class SpecDevYlrqThread implements Runnable {
    private ITSpecdevYlrqService specdevYlrqService;

    public SpecDevYlrqThread(ITSpecdevYlrqService specdevYlrqService) {
        this.specdevYlrqService = specdevYlrqService;
    }

    @Override
    public void run() {
        List<TSpecdevYlrq> list = this.specdevYlrqService.list(new QueryWrapper<TSpecdevYlrq>()
                .eq("del_flag", 0));
        /*boolean flag = false;
        List<String> collect = list.stream().map(e -> {
            return flag ? e.getPlantCode() : e.getDevno();
        }).collect(Collectors.toMap(e -> e, e -> 1, (a, b) -> a + b)).entrySet().stream() // 所有 entry 对应的 Stream
                .filter(entry -> entry.getValue() > 1) // 过滤出元素出现次数大于 1 的 entry
                .map(entry -> entry.getKey()) // 获得 entry 的键（重复元素）对应的 Stream
                .collect(Collectors.toList());// 转化为 List
        for (String s : collect) {
            TSpecdevYlrq tSpecdevYlrq = new TSpecdevYlrq();
            tSpecdevYlrq.setDevno(s);
            tSpecdevYlrq.setIsRepeat(1L);
            this.specdevYlrqService.updateTSpecdevYlrq(tSpecdevYlrq);
        }*/
        for (TSpecdevYlrq t : list) {
            System.out.println("=======压力管道更新=====================================");
            t.setIsRepeat(0L);
            this.specdevYlrqService.updateTSpecdevYlrq(t);
        }
        for (TSpecdevYlrq tSpecdevYlrq : list) {
            for (TSpecdevYlrq specdevYlrq : list) {
                if (tSpecdevYlrq.getId() == specdevYlrq.getId() || StringUtils.isEmpty(tSpecdevYlrq.getDevno())
                        || StringUtils.isEmpty(specdevYlrq.getDevno())) {
                    continue;
                }
                if (tSpecdevYlrq.getDevno().equals(specdevYlrq.getDevno()) && tSpecdevYlrq.getPlantCode().equals(specdevYlrq.getPlantCode())) {
                    specdevYlrq.setIsRepeat(1L);
                    tSpecdevYlrq.setIsRepeat(1L);
                    this.specdevYlrqService.updateTSpecdevYlrq(specdevYlrq);
                    this.specdevYlrqService.updateTSpecdevYlrq(tSpecdevYlrq);
                }
            }
        }
    }
}
