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.mes.model.StationRequestBean;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 发送物料号
 */
@Service
public class PartWriteVariableService 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 = productionPartContextList.stream().filter(pductionPartContext -> Objects.equals(pductionPartContext.getForeignKey(), foreignKey)).findFirst().orElse(null);

        if (mesProductionPartContext != null) {
            return mesProductionPartContext.getPartNo();
        }
     /*
        for (MesProductionPartContext mesProductionPartContext : productionPartContextList) {

           if (orderNoList.contains(mesProductionPartContext.getWorkOrderNo())) {
               continue;
           }
            orderNo = mesProductionPartContext.getWorkOrderNo();
            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;
    }*/
}
