package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.rulematch.strategy;

import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionDispatchContextStepService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionPartContext;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.mes.model.StationRequestBean;
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collector;
import java.util.stream.Collectors;

/**
 * 发送工单号
 */
@Service
public class OrderWriteVariableService extends AbstractWriteVariableService{

    @Autowired
    private IMesProductionDispatchContextStepService mesProductionDispatchContextStepService;

    private  Map<String, String> map = new HashMap<>();

    private String orderNo;

    @Override
    public String transferValue(StationRequestBean reqBean, String value, Integer foreignKey, Integer index) {

        List<MesProductionPartContext> productionPartContextList = mesProductionDispatchContextStepService.getProductionPartContext(reqBean);
        MesProductionPartContext mesProductionPartContext = null;
        if (index != null && foreignKey == null) {
            mesProductionPartContext = productionPartContextList.get(index);
            if (mesProductionPartContext == null || Objects.equals(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue(), mesProductionPartContext.getIsFinishCode())) {
                return  null;
            }
        }
         mesProductionPartContext = productionPartContextList.stream().filter(pductionPartContext -> Objects.equals(pductionPartContext.getForeignKey(), foreignKey)).findFirst().orElse(null);

        if (mesProductionPartContext != null) {
            return mesProductionPartContext.getWorkOrderNo();
        }
       return  null;
    }

   /* public void addList(String orderNo){
        orderNoList.add(orderNo);
    }

    @Override
    public void handlerValue() {
         orderNoList.add(this.orderNo);
    }

    @Override
    public void removeValue() {
        orderNoList.clear();
        orderNo = null;
    }*/
}
