package com.sw.mes.yb.pc.service.impl;


import com.sw.mes.base.factory.inspect.entity.ProductAssemblyRule;
import com.sw.mes.core.base.BaseServiceImpl;
import com.sw.mes.core.enums.SectionIndexRangeEnum;
import com.sw.mes.core.exception.BusinessException;
import com.sw.mes.core.response.ResultGenerator;
import com.sw.mes.core.utils.BeanUtil;
import com.sw.mes.core.utils.StringUtils;
import com.sw.mes.inspect.entity.YbInspectData;
import com.sw.mes.inspect.service.YbInspectDataService;
import com.sw.mes.production.service.TruncationReccutDetailsService;
import com.sw.mes.yb.fls.dto.SectionRecycledResultDto;
import com.sw.mes.yb.fls.dto.SectionRequestDto;
import com.sw.mes.yb.mcs.dto.HeadTailMaterialTypeDto;
import com.sw.mes.yb.pad.entity.ProductionBackCuttingRecord;
import com.sw.mes.yb.pad.entity.ProductionPaintingLine;
import com.sw.mes.yb.pad.entity.ProductionPaintingLineDetail;
import com.sw.mes.yb.pad.service.ProductionPaintingLineDetailService;
import com.sw.mes.yb.pad.service.ProductionPaintingLineService;
import com.sw.mes.yb.pad.service.ProductionRecutService;
import com.sw.mes.yb.pc.dao.HeadTailMaterialRuleDao;
import com.sw.mes.yb.pc.entity.HeadTailMaterialRule;
import com.sw.mes.yb.pc.service.HeadTailMaterialRuleService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;


/**
 * @Author
 * @Description：
 * @Date: Create in
 * @Modified By:
 */
@Service
@Transactional
public class HeadTailMaterialRuleServiceImpl extends BaseServiceImpl<HeadTailMaterialRule> implements HeadTailMaterialRuleService {
    HeadTailMaterialRuleDao dao;

    @Autowired
    public void setDao(HeadTailMaterialRuleDao dao) {
        super.setBaseDao(dao);
        this.dao = dao;
    }

    /**
     * 画线信息service
     */
    @Autowired
    ProductionPaintingLineService productionPaintingLineService;

    /**
     * 画线信息详情
     */
    @Autowired
    ProductionPaintingLineDetailService productionPaintingLineDetailService;

    /**
     * 返切画线信息
     */
    @Autowired
    private ProductionRecutService productionRecutService;

    /**
     * 圆棒检验数据库service
     */
    @Autowired
    private YbInspectDataService inspectDataBaseService;

    /**
     * 截断返切记录service
     */
    @Autowired
    private TruncationReccutDetailsService truncationReccutDetailsService;

    @Override
    public Integer findCountByBracketNo(Integer bracketNo) {

        return dao.findCountByBracketNo(bracketNo);
    }

    @Override
    public String findBracketNoByRecoveryNo(String recoveryNo) {
        //根据sn查询画线规则，获取参杂剂信息，电阻率、少子寿命、碳含量等信息待相关功能开发完成获取，
        ProductionPaintingLineDetail productionPaintingLineDetail = productionPaintingLineDetailService.findBySegmentNo(recoveryNo);
        if (productionPaintingLineDetail == null) {
            throw new RuntimeException("画线详情不存在");
        }
        ProductionPaintingLine productionPaintingLine = productionPaintingLineService.get(productionPaintingLineDetail.getOperateDrawId());
        if (productionPaintingLine == null) {
            throw new RuntimeException("画线信息不存在");
        }

        //参杂剂
        String dopant = productionPaintingLine.getDopant();
        //电阻率
        BigDecimal resistivity = null;
        //碳含量
        BigDecimal carbon = null;
        //少子寿命
        BigDecimal sinton = null;
        //电阻率，头回收料电阻率为第一根晶段电阻率，尾回收料为最后一根晶段电阻率
        List<ProductionPaintingLineDetail> productionPaintingLineDetailList = productionPaintingLineDetailService.findByOperateDrawId(productionPaintingLineDetail.getOperateDrawId());
        //单晶头编号
        String headNo = null;
        //单晶尾编号
        String tailNo = null;
        //第一段单晶编号
        String firstSectionNo = null;
        //最后一段单晶编号
        String lastSectionNo = null;
        Integer maxSequence = 0;
        Integer minSequence = 0;
        Integer maxSegmentNum = 0;
        Integer minSegmentNum = 0;
        //找出单晶头、单晶尾、第一根晶段、最后一根晶段
        for (ProductionPaintingLineDetail paintingLineDetail : productionPaintingLineDetailList) {
            if (paintingLineDetail.getSequence() <= minSequence) {
                minSequence = paintingLineDetail.getSequence();
                headNo = paintingLineDetail.getNo();
            }
            if (paintingLineDetail.getSequence() >= maxSequence) {
                maxSequence = paintingLineDetail.getSequence();
                tailNo = paintingLineDetail.getNo();
            }
            if (paintingLineDetail.getSegmentNum() <= minSegmentNum) {
                minSegmentNum = paintingLineDetail.getSegmentNum();
                firstSectionNo = paintingLineDetail.getNo();
            }
            if (paintingLineDetail.getSegmentNum() >= maxSegmentNum) {
                maxSegmentNum = paintingLineDetail.getSegmentNum();
                lastSectionNo = paintingLineDetail.getNo();
            }
        }
        //头回收料
        if (headNo != null && headNo.equals(recoveryNo)) {
            if (firstSectionNo == null) {
                return null;
            } else {
                YbInspectData inspectDataBase = inspectDataBaseService.findBySectionNo(firstSectionNo);
                // TODO: 2022/2/7 赋值  //电阻率
                //        BigDecimal resistivity = null;
                //        //碳含量
                //        BigDecimal carbon = null;
                //        //少子寿命
                //        BigDecimal sinton = null;
            }


            //尾回收料
        } else if (tailNo != null && tailNo.equals(recoveryNo)) {
            if (lastSectionNo == null) {
                return null;
            } else {
                YbInspectData inspectDataBase = inspectDataBaseService.findBySectionNo(firstSectionNo);
                // TODO: 2022/2/7 赋值  //电阻率
                //        BigDecimal resistivity = null;
                //        //碳含量
                //        BigDecimal carbon = null;
                //        //少子寿命
                //        BigDecimal sinton = null;
            }
        } else {
            return null;
        }
        String bracketNo = null;
        List<HeadTailMaterialRule> headTailMaterialRuleList = dao.findByDopant(dopant);
        for (HeadTailMaterialRule headTailMaterialRule : headTailMaterialRuleList) {
            if (resistivity == null || carbon == null || sinton == null) {
                continue;
            }
            Boolean b1 = isMatch(resistivity, headTailMaterialRule.getBorder());
            Boolean b2 = isMatch(carbon, headTailMaterialRule.getCarbon());
            Boolean b3 = isMatch(sinton, headTailMaterialRule.getSinton());
            if (b1 && b2 && b3) {
                bracketNo = String.valueOf(headTailMaterialRule.getBracketNo());
            }
        }

        return bracketNo;
    }


    private Boolean isMatch(BigDecimal value, String rule) {
        if (rule == null) {
            return true;
        }
        if (rule.contains("不配置")) {
            return true;
        }
        rule = rule.trim();
        if (rule.equals("")) {
            return true;
        }
        String[] split = rule.split(",");
        for (String s : split) {
            //">=100,<56,>66,"
            if (s.contains(">=")) {
                String s1 = s.replaceAll(">=", "");
                BigDecimal ruleValue = new BigDecimal(s1);
                if (value.compareTo(ruleValue) < 0) {
                    return false;
                }

            } else if (s.contains("<=")) {
                String s1 = s.replaceAll("<=", "");
                BigDecimal ruleValue = new BigDecimal(s1);
                if (value.compareTo(ruleValue) > 0) {
                    return false;
                }
            } else if (s.contains("!=")) {
                String s1 = s.replaceAll("!=", "");
                BigDecimal ruleValue = new BigDecimal(s1);
                if (value.compareTo(ruleValue) == 0) {
                    return false;
                }
            } else if (s.contains(">")) {
                String s1 = s.replaceAll(">", "");
                BigDecimal ruleValue = new BigDecimal(s1);
                if (value.compareTo(ruleValue) <= 0) {
                    return false;
                }
            } else if (s.contains("<")) {
                String s1 = s.replaceAll("<", "");
                BigDecimal ruleValue = new BigDecimal(s1);
                if (value.compareTo(ruleValue) >= 0) {
                    return false;
                }
            } else if (s.contains("=")) {
                String s1 = s.replaceAll("=", "");
                BigDecimal ruleValue = new BigDecimal(s1);
                if (value.compareTo(ruleValue) != 0) {
                    return false;
                }
            } else {
                return false;
            }
        }
        return true;
    }


    @Override
    public HeadTailMaterialTypeDto findHeadTailMaterialRuleByRecoveryNo(String recoveryNo) {
        HeadTailMaterialTypeDto headTailMaterialTypeDto = new HeadTailMaterialTypeDto();
        int type = 1;//1头料2尾料3中间段回收料4截断反切记录编号
        //晶段编号
        String no = "";
        //晶棒编号
        String crystalNoBySectionNo = "";
        //掺杂剂
        String dopant = null;
        //电阻率
        BigDecimal resistivity = null;
        //碳含量
        BigDecimal carbon = null;
        //少子寿命
        BigDecimal sinton = null;

        //回收料对应的晶段编号
        YbInspectData inspectDataBase = null;

        for (int i = 0; i < 2; i++) {
            //查询画线明细数据
            ProductionPaintingLineDetail bySegmentNo = productionPaintingLineDetailService.findBySegmentNo(recoveryNo);
            if (bySegmentNo != null) {
//                if (bySegmentNo.getType() == 0) {
//                    throw new RuntimeException("编号【" + recoveryNo + "】非回收料！");
//                }

//                T2BP0011R51WP
                String fromMark = bySegmentNo.getNo().substring(SectionIndexRangeEnum.基地追溯产品类型.getBeginIndex(), SectionIndexRangeEnum.基地追溯产品类型.getEndIndex());
                if (fromMark.matches("[A-Z]+")) {
                    if (bySegmentNo.getNo().substring(SectionIndexRangeEnum.断次.getBeginIndex()).toUpperCase().contains("T") || bySegmentNo.getNo().toUpperCase().contains("01Y")
                            || ("1".equals(bySegmentNo.getNo().toUpperCase().substring(SectionIndexRangeEnum.断次.getBeginIndex(), SectionIndexRangeEnum.断次.getEndIndex()))
                            && (bySegmentNo.getNo().toUpperCase().substring(SectionIndexRangeEnum.断次.getBeginIndex()).contains("1P") || bySegmentNo.getNo().toUpperCase().substring(SectionIndexRangeEnum.断次.getBeginIndex()).contains("TP") || bySegmentNo.getNo().toUpperCase().contains("X")))) {
                        type = 1;
                    } else if (bySegmentNo.getNo().toUpperCase().substring(SectionIndexRangeEnum.截断数.getBeginIndex()).contains("W")) {
                        type = 2;
                    } else {
                        type = 3;
                    }
                } else {
                    if (bySegmentNo.getNo().substring(11).toUpperCase().contains("T") || bySegmentNo.getNo().toUpperCase().contains("01Y") || (bySegmentNo.getNo().toUpperCase().substring(11, 12).equals("1")
                            && (bySegmentNo.getNo().toUpperCase().substring(11).contains("1P") || bySegmentNo.getNo().toUpperCase().substring(11).contains("TP") || bySegmentNo.getNo().toUpperCase().contains("X")))) {
                        type = 1;
                    } else if (bySegmentNo.getNo().toUpperCase().substring(12).contains("W")) {
                        type = 2;
                    } else {
                        type = 3;
                    }
                }
//                //正常长晶棒画线
//                if (recoveryNo.charAt(recoveryNo.length() - 3) == 'W') {
//                    type = 2;
//                } else if (recoveryNo.charAt(recoveryNo.length() - 3) == '1') {
//                    type = 1;
//                }
            } else {
                crystalNoBySectionNo = truncationReccutDetailsService.findCrystalNoBySectionNo(recoveryNo);
                if (StringUtils.isBlank(crystalNoBySectionNo)) {
                    throw new RuntimeException("编号【" + recoveryNo + "】不存在数据！");
                }
                type = 4;
            }

            //查询查询画线详情
            List<ProductionPaintingLineDetail> productionPaintingLineDetailList = productionPaintingLineDetailService.findByRecycledSectionNo(recoveryNo);
            if (type == 1) {
                if (productionPaintingLineDetailList == null || productionPaintingLineDetailList.size() < 1) {
                    throw new RuntimeException("头料编号【" + recoveryNo + "】对应的长晶棒画线信息不存在！");
                }
                for (ProductionPaintingLineDetail productionPaintingLineDetail : productionPaintingLineDetailList) {
                    String fromMark = bySegmentNo.getNo().substring(SectionIndexRangeEnum.基地追溯产品类型.getBeginIndex(), SectionIndexRangeEnum.基地追溯产品类型.getEndIndex());
                    if (fromMark.matches("[A-Z]+")) {
                        if (bySegmentNo.getNo().contains("TP")) {
                            no = productionPaintingLineDetail.getNo();
                        } else if (bySegmentNo.getNo().substring(SectionIndexRangeEnum.毛棒到截断位数.getBeginIndex(), SectionIndexRangeEnum.毛棒到截断位数.getEndIndex()).equals(productionPaintingLineDetail.getNo().substring(SectionIndexRangeEnum.毛棒到截断位数.getBeginIndex(), SectionIndexRangeEnum.毛棒到截断位数.getEndIndex()))) {
                            no = productionPaintingLineDetail.getNo();
                        }
                    } else {
                        if(bySegmentNo.getNo().contains("TP")){
                            no = productionPaintingLineDetail.getNo();
                        } else if (bySegmentNo.getNo().substring(0,13).equals(productionPaintingLineDetail.getNo().substring(0, 13))){
                            no = productionPaintingLineDetail.getNo();
                        }
                    }
                    if(!StringUtils.isBlank(no)){
                        break;
                    }
                }
            } else if (type == 2) {
                if (productionPaintingLineDetailList == null || productionPaintingLineDetailList.size() < 1) {
                    throw new RuntimeException("尾料编号【" + recoveryNo + "】对应的长晶棒画线信息不存在！");
                }
//                no = productionPaintingLineDetailList.get(productionPaintingLineDetailList.size()-1).getNo();
                List<ProductionPaintingLineDetail> detailList = productionPaintingLineDetailList.stream().filter(productionPaintingLineDetail -> productionPaintingLineDetail.getNo().substring(productionPaintingLineDetail.getNo().length()-2,productionPaintingLineDetail.getNo().length()-1).toUpperCase().contains("W")).collect(Collectors.toList());
                if(CollectionUtils.isNotEmpty(detailList)) {
                    no = detailList.get(0).getNo();
                }
            } else if (type == 3) {
//                productionPaintingLineDetailList = productionPaintingLineDetailService.findByRecycledSectionNoFQ(recoveryNo);
                if (productionPaintingLineDetailList != null && productionPaintingLineDetailList.size() > 0) {
                    for (ProductionPaintingLineDetail productionPaintingLineDetail : productionPaintingLineDetailList) {

                        String fromMark = bySegmentNo.getNo().substring(SectionIndexRangeEnum.基地追溯产品类型.getBeginIndex(), SectionIndexRangeEnum.基地追溯产品类型.getEndIndex());
                        if (fromMark.matches("[A-Z]+")) {
                            if (productionPaintingLineDetail.getNo().toUpperCase().substring(SectionIndexRangeEnum.毛棒到截断位数.getBeginIndex(), SectionIndexRangeEnum.毛棒到截断位数.getEndIndex()).equals(bySegmentNo.getNo().toUpperCase().substring(SectionIndexRangeEnum.毛棒到截断位数.getBeginIndex(), SectionIndexRangeEnum.毛棒到截断位数.getEndIndex()))) {
                                no = productionPaintingLineDetail.getNo();
                            }
                        } else {
                            if (productionPaintingLineDetail.getNo().toUpperCase().substring(0, 13).equals(bySegmentNo.getNo().toUpperCase().substring(0, 13))) {
                                no = productionPaintingLineDetail.getNo();
                            }
                        }
                        if(!StringUtils.isBlank(no)){
                            break;
                        }
                    }
                }
//                else {
//                    //圆棒返切记录
//                    ProductionBackCuttingRecord productionBackCuttingRecord = productionRecutService.get(bySegmentNo.getOperateReversecutDrawId());
//                    if (productionBackCuttingRecord == null) {
//                        throw new RuntimeException("回收料编号【" + recoveryNo + "】返切记录不存在！");
//                    }
//                    recoveryNo = productionBackCuttingRecord.getSegmentNo();
//                }
            } else if (type == 4) {
                productionPaintingLineDetailList = productionPaintingLineDetailService.findByRecycledCrystalNo(crystalNoBySectionNo);
                if (productionPaintingLineDetailList == null || productionPaintingLineDetailList.size() < 1) {
                    throw new RuntimeException("编号【" + crystalNoBySectionNo + "】对应的长晶棒画线信息不存在！");
                }
                no = productionPaintingLineDetailList.get(0).getNo();
            }
            //如果已匹配到单晶编号则退出循环
            if (StringUtils.isNoneBlank(no)) {
                break;
            }
        }

        inspectDataBase = inspectDataBaseService.findBySectionNo(no);
        if (inspectDataBase == null) {
            throw new RuntimeException("晶段编号【" + no + "】对应的圆棒检验数据库信息不存在！");
        }

        //todo 头段取头，尾段取尾，中间段取头
        if (type == 1 || type == 3) {
            dopant = inspectDataBase.getDopant();
            resistivity = inspectDataBase.getTRadialCentre();
            carbon = inspectDataBase.getCarbonContentHead();
            sinton = inspectDataBase.getTCentreLife();
            //赋值返回
            headTailMaterialTypeDto.setSectionNo(inspectDataBase.getSectionNo());
            headTailMaterialTypeDto.setTempRadialCentre(inspectDataBase.getTRadialCentre());
            headTailMaterialTypeDto.setTempRadialEdge1(inspectDataBase.getTRadialEdge1());
            headTailMaterialTypeDto.setCentreLife(inspectDataBase.getTCentreLife());
            headTailMaterialTypeDto.setLifeEdge1(inspectDataBase.getTLifeEdge1());              //没问题
            headTailMaterialTypeDto.setCarbonContent(inspectDataBase.getCarbonContentHead());
//            headTailMaterialTypeDto.setCarbonContentBorder(inspectDataBase.getCarbonContentBorder());
        } else if (type == 2 || type == 4) {
            dopant = inspectDataBase.getDopant();
            resistivity = inspectDataBase.getWRadialCentre();
            carbon = inspectDataBase.getCarbonContentTail();
            sinton = inspectDataBase.getWCentreLife();
            //赋值返回
            headTailMaterialTypeDto.setSectionNo(inspectDataBase.getSectionNo());
            headTailMaterialTypeDto.setTempRadialCentre(inspectDataBase.getWRadialCentre());
            headTailMaterialTypeDto.setTempRadialEdge1(inspectDataBase.getWRadialEdge1());
            headTailMaterialTypeDto.setCentreLife(inspectDataBase.getWCentreLife());
            headTailMaterialTypeDto.setLifeEdge1(inspectDataBase.getWLifeEdge1());
            headTailMaterialTypeDto.setCarbonContent(inspectDataBase.getCarbonContentTail());
//            headTailMaterialTypeDto.setCarbonContentBorder(inspectDataBase.getCarbonContentBorderTail());
        }
        //返回值增加头氧数值
        headTailMaterialTypeDto.setOxygenContentHead(inspectDataBase.getOxygenContentHead());
        List<HeadTailMaterialRule> headTailMaterialRuleList = dao.findByDopant(dopant);
        if (headTailMaterialRuleList == null || headTailMaterialRuleList.size() <= 0) {
            throw new RuntimeException("掺杂剂【" + dopant + "】对应的头尾料分类规则不存在！");
        }

        if (resistivity == null || carbon == null || sinton == null) {
            throw new RuntimeException("单晶【" + inspectDataBase.getSectionNo() + "】：电阻率【" + resistivity + "】,碳含量【" + carbon + "】,少子寿命【" + sinton + "】参数异常，无法匹配规则！");
        }

        for (HeadTailMaterialRule headTailMaterialRule : headTailMaterialRuleList) {
            Boolean b1 = isMatch(resistivity, headTailMaterialRule.getBorder());
            Boolean b2 = isMatch(carbon, headTailMaterialRule.getCarbon());
            Boolean b3 = isMatch(sinton, headTailMaterialRule.getSinton());
            headTailMaterialTypeDto.setBracketNo(headTailMaterialRule.getBracketNo());
            if (b1 && b2 && b3) {
                BeanUtil.copyBeanPropWithNullValue(headTailMaterialTypeDto, headTailMaterialRule, null);
                //产品等级字段赋值
                if (null != inspectDataBase && !inspectDataBase.getProductLevel().isEmpty()){
                    headTailMaterialTypeDto.setProductLevel(inspectDataBase.getProductLevel());
                }
                return headTailMaterialTypeDto;
            }
        }
        return null;
    }

    @Override
    public List<SectionRecycledResultDto> findHeadTailMaterialRuleBySection(SectionRequestDto sectionRequestDto) {
        List<SectionRecycledResultDto> list = new ArrayList<>();
        String section = sectionRequestDto.getSectionNo();
        String line = sectionRequestDto.getLine();
        String regionCode = sectionRequestDto.getRegionCode();
        if (StringUtils.isBlank(section) || StringUtils.isBlank(line) || StringUtils.isBlank(regionCode)) {
            throw new BusinessException("参数异常,请校验!");
        }
        //掺杂剂
        String dopant = null;
        //电阻率T中心点
        BigDecimal tRadialCentre = null;
        //中心寿命
        BigDecimal tCentreLife = null;
        //碳含量中心
        BigDecimal carbonContentHead = null;
        //产品类别
        String productType = null;
        //产品等级
        String productGrade =null;

        YbInspectData inspectDataBase = inspectDataBaseService.findBySectionNo(section);
        if (inspectDataBase == null) {
            throw new RuntimeException("晶段编号【" + section + "】对应的圆棒检验数据库信息不存在！");
        }
        dopant = inspectDataBase.getDopant();

        tRadialCentre = inspectDataBase.getWRadialCentre();

        tCentreLife = inspectDataBase.getWCentreLife();

        carbonContentHead = inspectDataBase.getCarbonContentTail();

        productType = inspectDataBase.getProductType();

        productGrade = inspectDataBase.getProductLevel();
        //产品等级productLevel加入头尾料规则筛选条件中
        List<HeadTailMaterialRule> headTailMaterialRuleList = dao.findByDopantAndLineAndRegionCodeAndProductType(dopant, line, regionCode, productType);
        if (headTailMaterialRuleList == null || headTailMaterialRuleList.size() <= 0) {
            throw new RuntimeException("掺杂剂【" + dopant + "】对应的头尾料分类规则不存在！");
        }

        if (tRadialCentre == null || tCentreLife == null || carbonContentHead == null) {
            throw new RuntimeException("单晶【" + inspectDataBase.getSectionNo() + "】：" +
                    "电阻率【" + tRadialCentre + "】,中心寿命【" + tCentreLife + "】,碳含量中心【" + carbonContentHead + "】参数异常，无法匹配规则！");
        }
        for (HeadTailMaterialRule headTailMaterialRule : headTailMaterialRuleList) {
            //产品类别productType加入头尾料规则筛选条件中
            Boolean b1 = isMatch(tRadialCentre, headTailMaterialRule.getBorder());
            Boolean b2 = isMatch(tCentreLife, headTailMaterialRule.getSinton());
            Boolean b3 = isMatch(carbonContentHead, headTailMaterialRule.getCarbon());
            Boolean productTypeFlag = matchProductType(productType, headTailMaterialRule.getProductType());
            SectionRecycledResultDto sectionRecycledResultDto = new SectionRecycledResultDto();
            sectionRecycledResultDto.setSectionNo(section);
            if (b1 && b2 && b3 && productTypeFlag) {
                //等待fls确定最新方案,满足的点位是否全部返回
                sectionRecycledResultDto.setBracketNo(String.valueOf(headTailMaterialRule.getBracketNo()));
                sectionRecycledResultDto.setRecoveryName(headTailMaterialRule.getRecoveryName());
                list.add(sectionRecycledResultDto);
                // return sectionRecycledResultDto;
            }
        }
        if (list.size() == 0) {
            throw new RuntimeException("掺杂剂【" + dopant + ",产品类型" + productType + "】对应的头尾料分类规则都不存在!!！");
        }
        return list;
    }

    /**
     * 匹配圆棒产品类别和头尾料规则产品类别是否匹配
     * 产品类别必须存在筛选规则
     * @param productType
     * @param headTailProductType
     * @return
     */
    private boolean matchProductType(String productType, String headTailProductType) {
        boolean flag = false;
        if (StringUtils.isNotBlank(headTailProductType)) {
            String[] headTailProductTypes = headTailProductType.split(",");
            long count = Arrays.stream(headTailProductTypes).filter(str -> str.equals(String.valueOf(productType))).count();
            if (count > 0) {
                flag = true;
            }
        }
        return flag;
    }



}
