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

import java.util.Arrays;

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

import com.sw.mes.sap.dao.ReportSapGoodsmvtDao;
import com.sw.mes.sap.dto.jip.JipCloseOrderVerifyResult;
import com.sw.mes.sap.verify.VerifyWorkOrderState;

/**
 * 投入产出比(%)
 * 
 * @author liru
 * @date 2024-04-17
 */
@Component("tcratioVerify")
public class TcratioVerify implements VerifyWorkOrderState {

	@Autowired
	private ReportSapGoodsmvtDao reportSapGoodsmvtDao;

	@Override
	public void executeVerify(JipCloseOrderVerifyResult result, String AUFNR, String WERKS) {
		Double _sum101102531532 = reportSapGoodsmvtDao.getSumAufnrAndInBwart(AUFNR,Arrays.asList(new String[] { "101", "102", "531", "532" }));
		Double _sum261262 = reportSapGoodsmvtDao.getSumAufnrAndInBwart(AUFNR,Arrays.asList(new String[] { "261", "262" }));

		_sum101102531532 = _sum101102531532 == null ? 0 : _sum101102531532;
		_sum261262 = _sum261262 == null ? 0 : _sum261262;

		double value = 0;

		if (_sum261262 > 0) {
			value = _sum101102531532 / _sum261262;
		}

		value = (double) Math.round(value * 100 * 100) / 100;

		if (value > 100) {
			result.setStatus(false);
			result.setMsg("工单[" + AUFNR + "]投入产出比(%):" + value + ",不允许关单");
		}

		result.setTcratio(value);
	}

}
