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.verify.VerifyWorkOrderState;
import com.sw.mes.yb.plan.entity.ProductionOrder;
import com.sw.mes.yb.plan.service.ProductionOrderService;

/**
 * 工单状态STATE == 关闭生产
 * 
 * @author liru
 * @date 2024-04-17
 */
@Component("sapOrderStatusVerify")
public class SapOrderStatusVerify 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 (null != productionOrder.getStatus() && !productionOrder.getStatus().equals("REL")) {
			result.setStatus(false);
			result.setMsg("工单SAP状态非REL,不允许关单");
			return;
		}
	}

}
