package com.sw.mes.sap.verify.closeOrderState;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.sw.mes.sap.dto.jip.JipCloseOrderVerifyResult;
import com.sw.mes.sap.dto.jip.JipOrderStateResult;
import com.sw.mes.sap.task.MblnrQueryHandler;
import com.sw.mes.sap.verify.VerifyWorkOrderState;
import com.sw.mes.yb.plan.entity.ProductionOrder;
import com.sw.mes.yb.plan.service.ProductionOrderService;

import lombok.extern.slf4j.Slf4j;

/**
 * 工单状态STATE == 关闭生产
 * @author liru
 * @date 2024-04-17
 */
@Component("orderStatusVerify")
public class OrderStatusVerify implements VerifyWorkOrderState {
	
	@Autowired
    private ProductionOrderService productionOrderService;

	@Override
	public void executeVerify(JipCloseOrderVerifyResult result, String AUFNR, String WERKS) {
		ProductionOrder productionOrder = productionOrderService.findByAufnr(AUFNR.toString());
		
		if(productionOrder==null) {
			result.setStatus(false);
            result.setMsg("工单不存在,不允许关单");
            return;
		}
		
		if(productionOrder.getProductionStatus()) {
        	result.setStatus(false);
            result.setMsg("工单处于生产状态,不允许关单");
            return;
        }
	}

}
