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

import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesCellEquipContext;
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProdRuleContext;
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionProcessContext;
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionPsInContext;
import cn.estsh.i3plus.pojo.mes.bean.MesProdRuleIgnoreCfg;
import cn.estsh.i3plus.pojo.mes.bean.MesWorkCell;
import cn.estsh.i3plus.pojo.mes.bean.MesWorkCenter;
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 lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Description : 显示前道所有工序装配件工步【排序】
 * @Author : wangjie
 **/
@Slf4j
@Service("mesAssemblyShowSortPreCraftStepService")
public class MesAssemblyShowSortPreCraftStepService extends MesAssemblyShowSortStepService {

    @Override
    public StepResult execute(StationRequestBean reqBean) {
        return super.execute(reqBean);
    }

    public MesProdRuleContext getProdRuleSortContext(StationRequestBean reqBean, MesProductionProcessContext productionProcessContext, MesCellEquipContext cellEquipContext, MesProductionPsInContext productionPsInContext,
                                                     Map<String, List<MesProdRuleIgnoreCfg>> prodRuleIgnoreCfgMap) {
        Map<String, MesWorkCell> workCellMap = productionProcessContextStepService.dispatchWorkCellMap(reqBean);
        MesProdRuleContext prodRuleContext = new MesProdRuleContext(reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode(), reqBean.getProcessCode(), productionProcessContext.getCraftCode())
                .equipmentCode(cellEquipContext.getEquipmentCode()).workOrderNo(productionPsInContext.getWorkOrderNo()).productSn(productionPsInContext.getProductSn()).foreignKey(productionPsInContext.getForeignKey());
        return prodRuleCfgExtService.getProdRuleSortPreCraftContext(prodRuleContext, workCellMap, prodRuleIgnoreCfgMap);
    }

    public Boolean showProductionAssembly(StationRequestBean reqBean, StationResultBean resultBean, MesWorkCenter workCenter, List<MesProdRuleContext> prodRuleContextList) {
        return showProductionAssembly(reqBean, resultBean, workCenter, prodRuleContextList, true, false);
    }

}
