package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.step;

import cn.estsh.i3plus.ext.mes.pcn.api.base.IMesCustomerPartService;
import cn.estsh.i3plus.ext.mes.pcn.api.base.IMesPackingDefineService;
import cn.estsh.i3plus.ext.mes.pcn.api.base.IMesTemplateService;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.*;
import cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.step.method.MesPartDataMapSaveStepService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.*;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesWorkOrderCutDetailModel;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.BaseStepService;
import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.IStepService;
import cn.estsh.i3plus.mes.pcn.util.StationKvBeanUtil;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.mes.bean.*;
import cn.estsh.i3plus.pojo.mes.model.StationKvBean;
import cn.estsh.i3plus.pojo.mes.model.StationRequestBean;
import cn.estsh.i3plus.pojo.mes.model.StationResultBean;
import cn.estsh.i3plus.pojo.mes.model.StepResult;
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
import com.google.common.base.Objects;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Description : 裁片工单验证工步
 * @Author : wangjie
 **/
@Slf4j
@Service("mesWorkOrderCutCheckStepService")
public class MesWorkOrderCutCheckStepService extends BaseStepService {

    @Autowired
    private IMesProductionProcessContextStepService productionProcessContextStepService;

    @Autowired
    private IMesProductionDispatchContextStepService productionDispatchContextStepService;

    @Autowired
    private MesPartDataMapSaveStepService partDataMapSaveStepService;

    @Autowired
    private IMesWorkOrderExtService workOrderExtService;

    @Autowired
    private IMesWorkOrderCutService workOrderCutService;

    @Autowired
    private IMesProduceSnExtService produceSnExtService;

    @Autowired
    private IMesPackingDefineService packingDefineService;

    @Autowired
    private IMesCustomerPartService customerPartService;

    @Autowired
    private IMesTemplateService mesTemplateService;

    @Override
    public StepResult execute(StationRequestBean reqBean) {

        StationResultBean resultBean = new StationResultBean();

        StepResult stepResult = StepResult.getSuccessComplete();

        //获取上下文信息
        MesProductionProcessContext productionProcessContext = productionProcessContextStepService.dispatchCurCellEquipment(reqBean);

        //配置错误 抛出异常
        if (!productionProcessContext.getSuccess()) stepExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), productionProcessContext.getMessage());

        //存储生产过程上下文对象
        productionProcessContextStepService.dispatchProductionProcessContext(reqBean, productionProcessContext);

        //获取上下文生产扫/读信息:加工单
        List<MesEquipVariableCollectContext> equipVariableCollectContextList = productionDispatchContextStepService.getScanWorkOrderNoContext(reqBean);
        if (CollectionUtils.isEmpty(equipVariableCollectContextList)) return stepNonCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, "当前缺失待验证的裁片工单信息!");

        //清除本次已获取得到的裁片工单信息
        productionDispatchContextStepService.removeScanWorkOrderNoContext(reqBean);

        //从上下文中取出生产线对象
        MesWorkCenter workCenter = productionProcessContext.getWorkCenter();

        MesWorkCell workCell = productionProcessContext.getWorkCell();

        //验证工单的有效性
        List<MesProductionPartContext> productionPartContextList = new ArrayList<>();
        List<MesProductionPsInContext> productionPsInContextList = new ArrayList<>();
        List<MesProductionPsOutContext> productionPsOutContextList = new ArrayList<>();

        if (!checkWorkOrderValid(reqBean, resultBean, stepResult, productionProcessContext, workCenter,
                equipVariableCollectContextList, productionPartContextList, productionPsInContextList,
                productionPsOutContextList, workCell).isCompleted()) return stepNonCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, stepResult.getMsg());

        //保存上下文零件信息
        productionDispatchContextStepService.dispatchProductionPartContext(reqBean, productionPartContextList);
        //保存上下文产出零件信息
        productionDispatchContextStepService.dispatchProductionPsInContext(reqBean, productionPsInContextList);
        //保存上下文产出零件信息
        productionDispatchContextStepService.dispatchProductionPsOutContext(reqBean, productionPsOutContextList);

        //存储展示组件MODULE_CONTENT内容
        productionDispatchContextStepService.dispatchModuleContentContext(reqBean, getModuleContextData(reqBean, productionPartContextList));

        //保存扫描的工单信息上下文
        if (MesExtEnumUtil.CELL_MESSAGE_SOURCE.SCAN.getValue() == equipVariableCollectContextList.get(0).getMessageSource()) {
            productionProcessContextStepService.dispatchFunctionChooseCavityOrderContext(reqBean, StationKvBeanUtil.addStationKvBeanList(new ArrayList<>(),
                    new StationKvBean(MesPcnExtConstWords.CAVITY, "腔数", String.valueOf(productionPartContextList.stream().collect(Collectors.groupingBy(MesProductionPartContext::getPartNo)).size())),
                    new StationKvBean(MesPcnExtConstWords.CELL_MESSAGE_SOURCE, "工位信息来源", MesExtEnumUtil.CELL_MESSAGE_SOURCE.READ.getValueStr()),
                    new StationKvBean(MesPcnExtConstWords.WORK_ORDER_NO, "裁片工单", productionPartContextList.stream().filter(o -> null != o).map(MesProductionPartContext::getWorkOrderNo).collect(Collectors.joining(MesPcnExtConstWords.SEMICOLON)))));
        }

        String workOrderStr = equipVariableCollectContextList.stream().filter(o -> null != o).map(MesEquipVariableCollectContext::getEquipVariableValue).collect(Collectors.toList()).toString();

        //执行匹配加工规则工步
        ((IStepService) SpringContextsUtil.getBean("mesWorkOrderCutMatchingProdRuleStepService")).executeInState(reqBean);

        return stepSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog().scanInfo(workOrderStr), stepResult, String.format("当前%s裁片工单%s验证工单状态成功%s!",
                MesExtEnumUtil.CELL_MESSAGE_SOURCE.valueOfDescription(equipVariableCollectContextList.get(0).getMessageSource()), workOrderStr, MesPcnExtConstWords.EMPTY));

    }

    //封装展示组件MODULE_CONTENT内容
    private List<List<StationKvBean>> getModuleContextData(StationRequestBean reqBean, List<MesProductionPartContext> productionPartContextList) {

        List<List<StationKvBean>> dataList = new ArrayList<>();

        List<MesProductionPartContext> orderList = filterProductionPartContext(productionPartContextList, true);

        AtomicReference<Integer> index = new AtomicReference<>(0);

        if (!CollectionUtils.isEmpty(orderList)) {

            // 腔数
            int cavityQty = productionPartContextList.stream().collect(Collectors.groupingBy(MesProductionPartContext::getPartNo)).size();

            orderList.forEach(o -> StationKvBeanUtil.addStationKvBeanList(dataList, new ArrayList<>(),
                    new StationKvBean(MesPcnExtConstWords.CUT_WORK_ORDER_NO, "裁片工单号", o.getCutWorkOrderNo()),
                    new StationKvBean(MesPcnExtConstWords.WORK_ORDER_NO, "工单号", o.getWorkOrderNo()),
                    new StationKvBean(MesPcnExtConstWords.PART_NO, "零件编码", new StringJoiner(MesPcnExtConstWords.SLANT_R).add(o.getPartNo()).toString()),
                    new StationKvBean(MesPcnExtConstWords.QTY, "裁片工单数/完成数/工单数", new StringJoiner(MesPcnExtConstWords.SLANT_R).add(String.valueOf(o.getCutQty().intValue())).add(String.valueOf(o.getCompleteQty().intValue())).add(String.valueOf(o.getQty().intValue())).toString()),
                    new StationKvBean(MesPcnExtConstWords.CAVITY, "腔数", new StringJoiner(MesPcnExtConstWords.SLANT_R).add(String.valueOf(index.updateAndGet(v -> v + 1))).add(String.valueOf(cavityQty)).toString())));
        }

        return dataList;
    }

    //验证工单的有效性
    private StepResult checkWorkOrderValid(StationRequestBean reqBean, StationResultBean resultBean, StepResult stepResult,
                                           MesProductionProcessContext productionProcessContext, MesWorkCenter workCenter,
                                           List<MesEquipVariableCollectContext> equipVariableCollectContextList,
                                           List<MesProductionPartContext> productionPartContextList,
                                           List<MesProductionPsInContext> productionPsInContextList,
                                           List<MesProductionPsOutContext> productionPsOutContextList,
                                           MesWorkCell workCell) {

        //搜集裁片工单号
        List<String> filterList = equipVariableCollectContextList.stream().filter(o -> (null != o)).map(MesEquipVariableCollectContext::getEquipVariableValue).collect(Collectors.toList());
        List<String> workOrderCutNoList = filterList.stream().filter(o -> (!StringUtils.isEmpty(o) && !o.equals(productionProcessContext.getFinishCode()))).distinct().collect(Collectors.toList());

        String cutWorkOrderNo = workOrderCutNoList.stream().findFirst().get();

        MesWorkOrderCut workOrderCut = workOrderCutService.getMesWorkOrderCut(cutWorkOrderNo, reqBean.getOrganizeCode());

        if (workOrderCut == null)
            return stepResult.isCompleted(false).msg(String.format("请检查裁片工单信息,裁片工单[%s]无效!", cutWorkOrderNo));

        MesCutScheme cutScheme = workOrderCutService.getCutScheme(workOrderCut.getCutCode(), reqBean.getOrganizeCode());

        if (cutScheme == null)
            return stepResult.isCompleted(false).msg(String.format("请检查裁片工单信息,裁片工单[%s]所属裁片配置无效!", cutWorkOrderNo));

        if (!cutScheme.getWorkCenterCode().equals(workCenter.getWorkCenterCode()))
            return stepResult.isCompleted(false).msg(String.format("裁片工单[%s]所属裁片方案[%s]产线[%s]与当前产线[%s]不一致!", cutWorkOrderNo, cutScheme.getCutCode(), cutScheme.getWorkCenterCode(), workCenter.getWorkCenterCode()));

        if (workOrderCut.getWorkOrderStatus() == MesExtEnumUtil.CUT_ORDER_STATUS.COMPLETE.getValue())
            return stepResult.isCompleted(false).msg(String.format("裁片工单[%s]当前状态[%s],无需加工!", cutWorkOrderNo, MesExtEnumUtil.CUT_ORDER_STATUS.valueOfDescription(workOrderCut.getWorkOrderStatus())));
        else if (CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue() == cutScheme.getIsCheckMaterial() && workOrderCut.getWorkOrderStatus() != MesExtEnumUtil.CUT_ORDER_STATUS.CHECKED_RAW.getValue() && workOrderCut.getWorkOrderStatus() != MesExtEnumUtil.CUT_ORDER_STATUS.PROCESS.getValue())
            return stepResult.isCompleted(false).msg(String.format("裁片工单[%s]未进行裁片原材料防错!", cutWorkOrderNo));
        else if (workOrderCut.getWorkOrderStatus() != MesExtEnumUtil.CUT_ORDER_STATUS.CHECKED_RAW.getValue() && workOrderCut.getWorkOrderStatus() != MesExtEnumUtil.CUT_ORDER_STATUS.RELEASED.getValue() && workOrderCut.getWorkOrderStatus() != MesExtEnumUtil.CUT_ORDER_STATUS.PROCESS.getValue())
            return stepResult.isCompleted(false).msg(String.format("裁片工单[%s]当前状态[%s]无需加工或无法加工!", cutWorkOrderNo, MesExtEnumUtil.CUT_ORDER_STATUS.valueOfDescription(workOrderCut.getWorkOrderStatus())));

        List<MesWorkOrderCutDetail> mesWorkOrderCutDetailList = workOrderCutService.queryMesWorkOrderCutDetailList(cutWorkOrderNo, reqBean.getOrganizeCode());

        if (CollectionUtils.isEmpty(mesWorkOrderCutDetailList))
            return stepResult.isCompleted(false).msg(String.format("请检查裁片工单信息,裁片工单[%s]明细不存在!", cutWorkOrderNo));

        List<String> workOrderNoList = mesWorkOrderCutDetailList.stream().map(MesWorkOrderCutDetail::getWorkOrderNo).distinct().collect(Collectors.toList());

        List<MesWorkOrder> workOrderList = workOrderExtService.getWorkOrderList(reqBean.getOrganizeCode(), workOrderNoList);

        if (CollectionUtils.isEmpty(workOrderList))
            return stepResult.isCompleted(false).msg(String.format("请检查工单信息,裁片工单[%s]绑定工单信息无效!", cutWorkOrderNo));

        for (MesWorkOrder workOrder : workOrderList) {
            if (!MesExtEnumUtil.ORDER_STATUS.checkAllowStatus(workCenter.getCenterType(), workOrder.getWorkOrderStatus()))
                return stepResult.isCompleted(false).msg(String.format("请检查工单信息,裁片工单[%s]绑定工单信息工单状态[%s]!", cutWorkOrderNo, MesExtEnumUtil.ORDER_STATUS.valueOfDescription(workOrder.getWorkOrderStatus())));

            if (!workOrder.getWorkCenterCode().equals(reqBean.getWorkCenterCode()))
                return stepResult.isCompleted(false).msg(String.format("请检查工单信息,裁片工单[%s]绑定工单[%s]信息所属生产线[%s]与当前生产线[%s]不一致!", cutWorkOrderNo, workOrder.getWorkOrderNo(), workOrder.getWorkCenterCode(), reqBean.getWorkCenterCode()));
        }

        //封装 上下文 产出零件信息
        packProductionPartContextList(productionProcessContext, equipVariableCollectContextList, productionPartContextList, cutScheme, mesWorkOrderCutDetailList, workOrderList);

        //保存 上下文 零件数据信息
        if (!partDataMapSaveStepService.savePartDataMap2PPC(reqBean, resultBean, stepResult, productionPartContextList, true, false, true).isCompleted()) return stepNonCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, stepResult.getMsg());

        // 裁片方案成品配置
        List<MesCutSchemeFg> mesCutSchemeFgList = workOrderCutService.queryCutSchemeFgList(cutScheme.getCutCode(), reqBean.getOrganizeCode());

        // 校验裁片方案成品配置
        if(!checkMesCutSchemeFgListValid(mesCutSchemeFgList, workOrderList, stepResult, cutWorkOrderNo, cutScheme.getCutCode()).isCompleted()) return stepResult;

        // 最后一个工位 封装 包装条码打印所需参数
        if (workCell.getIsEndWorkCell() != null && workCell.getIsEndWorkCell() == CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) {

            List<MesWorkOrderCutDetailModel> workOrderCutDetailModelList = new ArrayList<>();

            Map<String, MesPartContext> partDataExtContext = (Map<String, MesPartContext>) stepResult.getObj();

            for (MesCutSchemeFg mesCutSchemeFg : mesCutSchemeFgList) {
                if (StringUtils.isEmpty(mesCutSchemeFg.getPackageSnRuleCode()))
                    return stepResult.isCompleted(false).msg(String.format("请检查裁片方案成品信息,零件号[%s]未在裁片方案[%s]成品配置信息中维护包装编码规则!", mesCutSchemeFg.getPartNo(), cutScheme.getCutCode()));

                MesPackingDefine mesPackingDefine = packingDefineService.getMesPackingDefine(mesCutSchemeFg.getPackageSnRuleCode(), reqBean.getOrganizeCode());

                if (mesPackingDefine == null)
                    return stepResult.isCompleted(false).msg(String.format("裁片方案代码[%s]关联产成零件[%s]箱类别代号[%s]无效!", mesCutSchemeFg.getCutCode(), mesCutSchemeFg.getPartNo(), mesCutSchemeFg.getPackageSnRuleCode()));

                if (StringUtils.isEmpty(cutScheme.getPackageSnPrinter()) && StringUtils.isEmpty(mesPackingDefine.getPrinter()))
                    return stepResult.isCompleted(false).msg(String.format("请检查包装定义信息,包装定义代码[%s]未维护打印机!", mesPackingDefine.getPackCode()));

                if (StringUtils.isEmpty(cutScheme.getPackageLabelTemplateCode()) && StringUtils.isEmpty(mesPackingDefine.getPrintTemplate()))
                    return stepResult.isCompleted(false).msg(String.format("请检查包装定义信息,包装定义代码[%s]未维护打印模板!", mesPackingDefine.getPackCode()));

                if (StringUtils.isEmpty(mesPackingDefine.getPackageBarcodeRule()))
                    return stepResult.isCompleted(false).msg(String.format("请检查包装定义信息,包装定义代码[%s]未维护条码规则!", mesPackingDefine.getPackCode()));

                MesWorkOrderCutDetailModel workOrderCutDetailModel = new MesWorkOrderCutDetailModel();
                BeanUtils.copyProperties(mesCutSchemeFg, workOrderCutDetailModel);
                if (Objects.equal(cutScheme.getIsFree(), CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue())) {
                    Map<String, List<MesWorkOrderCutDetail>> map = mesWorkOrderCutDetailList.stream().collect(Collectors.groupingBy(MesWorkOrderCutDetail::getPartNo));
                    workOrderCutDetailModel.setQty(map.get(mesCutSchemeFg.getPartNo()).get(0).getQty());
                    workOrderCutDetailModel.setPackageQty(map.get(mesCutSchemeFg.getPartNo()).get(0).getPackageQty());
                }

                workOrderCutDetailModel.setCutWorkOrderNo(cutWorkOrderNo);

                MesCustomerPart customerPart = customerPartService.getMesCustomerPartByPartNo(mesCutSchemeFg.getPartNo(), mesPackingDefine.getCustCode(), reqBean.getOrganizeCode());

                MesLabelTemplate labelTemplate = mesTemplateService.getLabelTemplate(mesPackingDefine.getPackageTemplate(), reqBean.getOrganizeCode());

                if (labelTemplate == null)
                    return stepResult.isCompleted(false).msg(String.format("请检查包装定义信息,零件号[%s]对应模板代码[%s]无效!", mesCutSchemeFg.getPartNo(), mesPackingDefine.getPackageTemplate()));

                MesPartContext mesPartContext = partDataExtContext.get(mesCutSchemeFg.getPartNo().toUpperCase());
                mesPartContext.setCopies(mesPackingDefine.getPrintCopies() == null ? 1 : mesPackingDefine.getPrintCopies());
                mesPartContext.setPackageSnRule(mesPackingDefine.getPackageBarcodeRule());
                mesPartContext.setPrinter(StringUtils.isEmpty(cutScheme.getPackageSnPrinter()) ? mesPackingDefine.getPrinter() : cutScheme.getPackageSnPrinter());
                mesPartContext.setLabelTemplate(StringUtils.isEmpty(cutScheme.getPackageLabelTemplateCode()) ? mesPackingDefine.getPackageTemplate() : cutScheme.getPackageLabelTemplateCode());
                mesPartContext.setCustPartNo(customerPart == null ? "" : customerPart.getCustPartNo());

                partDataExtContext.put(mesCutSchemeFg.getPartNo().toUpperCase(), mesPartContext);
                workOrderCutDetailModelList.add(workOrderCutDetailModel);

            }

            productionDispatchContextStepService.dispatchPartDataContext(reqBean, partDataExtContext);

            productionDispatchContextStepService.dispatchMesWorkOrderCutFgDataContext(reqBean, workOrderCutDetailModelList);

        }

        // 如果裁片工单明细 productSn存在值则表名已 经过上道工位
        if (!StringUtils.isEmpty(mesWorkOrderCutDetailList.stream().findFirst().get().getProductSn())) {
            List<MesProduceSn> produceSnList = produceSnExtService.getProduceSnList(reqBean.getOrganizeCode(), cutWorkOrderNo);

            // 获取上道工艺生产的条码并封装到进料上下文中
            if (!CollectionUtils.isEmpty(produceSnList))
                produceSnList.stream().filter(o -> null != o).forEach(o -> {
                    productionPsInContextList.add(new MesProductionPsInContext(o).isCheck(workCell).cutCode(cutScheme.getCutCode()));
                    productionPsOutContextList.add(new MesProductionPsOutContext().copy(o));
                });
        }

        return stepResult;

    }

    private StepResult checkMesCutSchemeFgListValid(List<MesCutSchemeFg> mesCutSchemeFgList, List<MesWorkOrder> workOrderList, StepResult stepResult, String cutWorkOrderNo, String cutCode) {
        if (CollectionUtils.isEmpty(mesCutSchemeFgList))
            return stepResult.isCompleted(false).msg(String.format("请检查裁片方案成品信息,裁片工单[%s]关联裁片方案[%s]无成品配置!", cutWorkOrderNo, cutCode));

        List<String> fgPartNoList = mesCutSchemeFgList.stream().map(MesCutSchemeFg::getPartNo).distinct().collect(Collectors.toList());

        List<String> worKOrderPartNoList = workOrderList.stream().map(MesWorkOrder::getPartNo).distinct().collect(Collectors.toList());

        worKOrderPartNoList.removeAll(fgPartNoList);

        if (!CollectionUtils.isEmpty(worKOrderPartNoList))
            return stepResult.isCompleted(false).msg(String.format("请检查裁片方案成品信息,零件号[%s]未在裁片方案[%s]成品配置信息中维护!", worKOrderPartNoList, cutCode));

        stepResult.setCompleted(true);
        return stepResult;

    }

    private static void packProductionPartContextList(MesProductionProcessContext productionProcessContext, List<MesEquipVariableCollectContext> equipVariableCollectContextList, List<MesProductionPartContext> productionPartContextList, MesCutScheme cutScheme, List<MesWorkOrderCutDetail> mesWorkOrderCutDetailList, List<MesWorkOrder> workOrderList) {
        Map<String, MesWorkOrderCutDetail> workOrderCutDetailMap = mesWorkOrderCutDetailList.stream().collect(Collectors.toMap(o -> o.getWorkOrderNo().toUpperCase(), Function.identity(), (x, y) -> y));

        workOrderList.stream().filter(o -> null != o).forEach(o -> {
            MesProductionPartContext productionPartContext = new MesProductionPartContext()
                    .copyPartNo(o, workOrderCutDetailMap.get(o.getWorkOrderNo().toUpperCase()).getQty(), workOrderCutDetailMap.get(o.getWorkOrderNo().toUpperCase()).getCutWorkOrderNo(), equipVariableCollectContextList.get(0).getMessageSource())
                    .isCheck(productionProcessContext.getWorkCell());
            productionPartContext.setCutCode(cutScheme.getCutCode());
            productionPartContextList.add(productionPartContext);
        });
    }

    public List<MesProductionPartContext> removeBusiData(StationRequestBean reqBean) {
        productionDispatchContextStepService.removeProductionPartContext(reqBean);
        productionDispatchContextStepService.removeProductionPsInContext(reqBean);
        productionDispatchContextStepService.removeProductionPsOutContext(reqBean);
        productionDispatchContextStepService.removeProdRuleDataContext(reqBean);
        return null;
    }

    //根据是否空腔搜集数据
    public List<MesProductionPartContext> filterProductionPartContext(List<MesProductionPartContext> productionPartContextList, Boolean flag) {
        return flag ? productionPartContextList.stream().filter(o -> (null != o && o.getIsFinishCode().compareTo(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()) == 0)).collect(Collectors.toList()) :
                productionPartContextList.stream().filter(o -> (null != o && o.getIsFinishCode().compareTo(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) == 0)).collect(Collectors.toList());
    }

}
