package com.yem.wm.im.giftrule.validator;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.validate.AbstractValidator;

/**
 * @author power
 * @ClassName
 * @description: 提交检验
 * @date 2023/10/9
 */
public class SubmitOpValidator  extends AbstractValidator {

    @Override
    public void validate() {
        ExtendedDataEntity[]  datas = this.getDataEntities();
        for(ExtendedDataEntity temp:datas) {
            DynamicObject bill = temp.getDataEntity();
            DynamicObjectCollection giftrules = bill.getDynamicObjectCollection("yem_bd_giftrules_a");
            for (int i = 0; i < giftrules.size(); i++) {
                for (int j = i+1; j < giftrules.size(); j++) {
                    String variatea = giftrules.get(i).getString("yem_producttype.number");
                    String variateb = giftrules.get(j).getString("yem_producttype.number");
                    if (variatea.equals(variateb)){
                        this.addErrorMessage(temp,"基本规则明细"+variatea+"产品机型重复");
                        return;
                    }
                }
            }



            DynamicObjectCollection yem_bd_giftrules_bs = bill.getDynamicObjectCollection("yem_bd_giftrules_b");




            if (yem_bd_giftrules_bs.size()>0){
                for (int i = 0; i < yem_bd_giftrules_bs.size(); i++) {

                    if (yem_bd_giftrules_bs.size()==1){

                        if (yem_bd_giftrules_bs.get(i).getDynamicObjectCollection("yem_bd_giftrules_c").size()>0){
                            for (int k = 0; k < yem_bd_giftrules_bs.get(i).getDynamicObjectCollection("yem_bd_giftrules_c").size(); k++) {

                                if (yem_bd_giftrules_bs.get(i).getDynamicObjectCollection("yem_bd_giftrules_c").size()==1){

                                }
                                if (yem_bd_giftrules_bs.get(i).getDynamicObjectCollection("yem_bd_giftrules_c").size()>1){
                                    for (int l = k+1; l < yem_bd_giftrules_bs.get(i).getDynamicObjectCollection("yem_bd_giftrules_c").size(); l++) {

                                        String variatea = yem_bd_giftrules_bs.get(i).getDynamicObjectCollection("yem_bd_giftrules_c")
                                                .get(k).getString("yem_producttypea.number");

                                        String variateb = yem_bd_giftrules_bs.get(i).getDynamicObjectCollection("yem_bd_giftrules_c")
                                                .get(l).getString("yem_producttypea.number");

                                        if (variatea.equals(variateb)){
                                            this.addErrorMessage(temp,"特殊规则型号"+variatea+"产品机型重复");
                                            return;
                                        }
                                    }
                                }
                            }
                        }

                    }




                    if (yem_bd_giftrules_bs.size()>1){
                        for (int j = i+1; j < yem_bd_giftrules_bs.size(); j++) {

                            if (yem_bd_giftrules_bs.get(i).getDynamicObjectCollection("yem_bd_giftrules_c").size()==0){

                                if (yem_bd_giftrules_bs.get(j).getDynamicObjectCollection("yem_bd_giftrules_c").size()>0){

                                    for (int m = 0; m < yem_bd_giftrules_bs.get(j).getDynamicObjectCollection("yem_bd_giftrules_c").size(); m++) {
                                        if (yem_bd_giftrules_bs.get(j).getDynamicObjectCollection("yem_bd_giftrules_c").size()==1){

                                        }

                                        if (yem_bd_giftrules_bs.get(j).getDynamicObjectCollection("yem_bd_giftrules_c").size()>1){
                                            for (int n = m+1; n < yem_bd_giftrules_bs.get(j).getDynamicObjectCollection("yem_bd_giftrules_c").size(); n++) {
                                                String variatec = yem_bd_giftrules_bs.get(j).getDynamicObjectCollection("yem_bd_giftrules_c")
                                                        .get(m).getString("yem_producttypea.number");

                                                String variated = yem_bd_giftrules_bs.get(j).getDynamicObjectCollection("yem_bd_giftrules_c")
                                                        .get(n).getString("yem_producttypea.number");
                                                if (variatec.equals(variated)){
                                                    this.addErrorMessage(temp,"特殊规则型号"+variatec+"产品机型重复");
                                                    return;
                                                }
                                            }
                                        }
                                    }
                                }
                            }




                            if (yem_bd_giftrules_bs.get(i).getDynamicObjectCollection("yem_bd_giftrules_c").size()>0){
                                for (int k = 0; k < yem_bd_giftrules_bs.get(i).getDynamicObjectCollection("yem_bd_giftrules_c").size(); k++) {

                                    if (yem_bd_giftrules_bs.get(i).getDynamicObjectCollection("yem_bd_giftrules_c").size()==1){



                                        if (yem_bd_giftrules_bs.get(j).getDynamicObjectCollection("yem_bd_giftrules_c").size()>0){
                                            for (int m = 0; m < yem_bd_giftrules_bs.get(j).getDynamicObjectCollection("yem_bd_giftrules_c").size(); m++) {

                                                if (yem_bd_giftrules_bs.get(j).getDynamicObjectCollection("yem_bd_giftrules_c").size()==1){
                                                    String variatea = yem_bd_giftrules_bs.get(i).getDynamicObjectCollection("yem_bd_giftrules_c")
                                                            .get(k).getString("yem_producttypea.number");

                                                    String variatec = yem_bd_giftrules_bs.get(j).getDynamicObjectCollection("yem_bd_giftrules_c")
                                                            .get(m).getString("yem_producttypea.number");

                                                    if (variatea.equals(variatec)){
                                                        this.addErrorMessage(temp,"特殊规则型号"+variatea+"产品机型重复");
                                                        return;
                                                    }

                                                }
                                                if (yem_bd_giftrules_bs.get(j).getDynamicObjectCollection("yem_bd_giftrules_c").size()>1){

                                                    for (int n = m+1; n < yem_bd_giftrules_bs.get(j).getDynamicObjectCollection("yem_bd_giftrules_c").size(); n++) {
                                                        String variatea = yem_bd_giftrules_bs.get(i).getDynamicObjectCollection("yem_bd_giftrules_c")
                                                                .get(k).getString("yem_producttypea.number");


                                                        String variatec = yem_bd_giftrules_bs.get(j).getDynamicObjectCollection("yem_bd_giftrules_c")
                                                                .get(m).getString("yem_producttypea.number");

                                                        String variated = yem_bd_giftrules_bs.get(j).getDynamicObjectCollection("yem_bd_giftrules_c")
                                                                .get(n).getString("yem_producttypea.number");

                                                        if (variatea.equals(variatec)){
                                                            this.addErrorMessage(temp,"特殊规则型号"+variatea+"产品机型重复");
                                                            return;
                                                        }
                                                        if (variatea.equals(variated)){
                                                            this.addErrorMessage(temp,"特殊规则型号"+variatea+"产品机型重复");
                                                            return;
                                                        }

                                                        if (variatec.equals(variated)){
                                                            this.addErrorMessage(temp,"特殊规则型号"+variatec+"产品机型重复");
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    if (yem_bd_giftrules_bs.get(i).getDynamicObjectCollection("yem_bd_giftrules_c").size()>1){
                                        for (int l = k+1; l < yem_bd_giftrules_bs.get(i).getDynamicObjectCollection("yem_bd_giftrules_c").size(); l++) {

                                            if (yem_bd_giftrules_bs.get(j).getDynamicObjectCollection("yem_bd_giftrules_c").size()==0){
                                                String variatea = yem_bd_giftrules_bs.get(i).getDynamicObjectCollection("yem_bd_giftrules_c")
                                                        .get(k).getString("yem_producttypea.number");

                                                String variateb = yem_bd_giftrules_bs.get(i).getDynamicObjectCollection("yem_bd_giftrules_c")
                                                        .get(l).getString("yem_producttypea.number");


                                                if (variatea.equals(variateb)){
                                                    this.addErrorMessage(temp,"特殊规则型号"+variatea+"产品机型重复");
                                                    return;
                                                }
                                            }

                                            if (yem_bd_giftrules_bs.get(j).getDynamicObjectCollection("yem_bd_giftrules_c").size()>0){
                                                for (int m = 0; m < yem_bd_giftrules_bs.get(j).getDynamicObjectCollection("yem_bd_giftrules_c").size(); m++) {

                                                    if (yem_bd_giftrules_bs.get(j).getDynamicObjectCollection("yem_bd_giftrules_c").size()==1){
                                                        String variatea = yem_bd_giftrules_bs.get(i).getDynamicObjectCollection("yem_bd_giftrules_c")
                                                                .get(k).getString("yem_producttypea.number");

                                                        String variateb = yem_bd_giftrules_bs.get(i).getDynamicObjectCollection("yem_bd_giftrules_c")
                                                                .get(l).getString("yem_producttypea.number");

                                                        String variatec = yem_bd_giftrules_bs.get(j).getDynamicObjectCollection("yem_bd_giftrules_c")
                                                                .get(m).getString("yem_producttypea.number");

                                                        if (variatea.equals(variateb)){
                                                            this.addErrorMessage(temp,"特殊规则型号"+variatea+"产品机型重复");
                                                            return;
                                                        }
                                                        if (variatea.equals(variatec)){
                                                            this.addErrorMessage(temp,"特殊规则型号"+variatea+"产品机型重复");
                                                            return;
                                                        }
                                                        if (variateb.equals(variatec)){
                                                            this.addErrorMessage(temp,"特殊规则型号"+variateb+"产品机型重复");
                                                            return;
                                                        }
                                                    }
                                                    if (yem_bd_giftrules_bs.get(j).getDynamicObjectCollection("yem_bd_giftrules_c").size()>1){

                                                        for (int n = m+1; n < yem_bd_giftrules_bs.get(j).getDynamicObjectCollection("yem_bd_giftrules_c").size(); n++) {
                                                            String variatea = yem_bd_giftrules_bs.get(i).getDynamicObjectCollection("yem_bd_giftrules_c")
                                                                    .get(k).getString("yem_producttypea.number");

                                                            String variateb = yem_bd_giftrules_bs.get(i).getDynamicObjectCollection("yem_bd_giftrules_c")
                                                                    .get(l).getString("yem_producttypea.number");

                                                            String variatec = yem_bd_giftrules_bs.get(j).getDynamicObjectCollection("yem_bd_giftrules_c")
                                                                    .get(m).getString("yem_producttypea.number");

                                                            String variated = yem_bd_giftrules_bs.get(j).getDynamicObjectCollection("yem_bd_giftrules_c")
                                                                    .get(n).getString("yem_producttypea.number");
                                                            if (variatea.equals(variateb)){
                                                                this.addErrorMessage(temp,"特殊规则型号"+variatea+"产品机型重复");
                                                                return;
                                                            }
                                                            if (variatea.equals(variatec)){
                                                                this.addErrorMessage(temp,"特殊规则型号"+variatea+"产品机型重复");
                                                                return;
                                                            }
                                                            if (variatea.equals(variated)){
                                                                this.addErrorMessage(temp,"特殊规则型号"+variatea+"产品机型重复");
                                                                return;
                                                            }
                                                            if (variateb.equals(variatec)){
                                                                this.addErrorMessage(temp,"特殊规则型号"+variateb+"产品机型重复");
                                                                return;
                                                            }
                                                            if (variateb.equals(variated)){
                                                                this.addErrorMessage(temp,"特殊规则型号"+variateb+"产品机型重复");
                                                                return;
                                                            }
                                                            if (variatec.equals(variated)){
                                                                this.addErrorMessage(temp,"特殊规则型号"+variatec+"产品机型重复");
                                                                return;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
