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

import java.math.BigDecimal;

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.service.ReportSapGoodsmvtService;
import com.sw.mes.sap.service.ReportSapWorkinghoursService;
import com.sw.mes.sap.verify.VerifyWorkOrderState;

/**
 * 未报工记录
 * 
 * @author liru
 * @date 2024-04-17
 */
@Component("noSendSapLogNumVerify")
public class NoSendSapLogNumVerify implements VerifyWorkOrderState {

	@Autowired
	private ReportSapGoodsmvtService reportSapGoodsmvtService;
	@Autowired
	private ReportSapWorkinghoursService reportSapWorkinghoursService;

	@Override
	public void executeVerify(JipCloseOrderVerifyResult result, String AUFNR, String WERKS) {
		Double noSendSum = reportSapGoodsmvtService.getSumNoSendSapLog(AUFNR);
		if(noSendSum!=null && noSendSum!=0) {
			BigDecimal bd = new BigDecimal(noSendSum);
	        bd = bd.setScale(3, BigDecimal.ROUND_HALF_UP);
	        noSendSum = bd.doubleValue();
			
			result.setStatus(false);
            result.setMsg("工单["+AUFNR+"]未上报数量:"+noSendSum+",不允许关单");
		}
		
		result.setNorepnum(noSendSum);
		
		
		Long noSendSapTime = reportSapWorkinghoursService.getSendSapLog(AUFNR);
		if(noSendSapTime!=null && noSendSapTime>0) {
			result.setStatus(false);
            result.setMsg("工单["+AUFNR+"]未上报工时记录数:"+noSendSapTime+",不允许关单");
		}
	}

}
