package com.steering.mes.mcp.coup;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA06.CoreReturnSortObject;

import com.steering.comm.db.DBCommon;
import com.steering.mes.mcp.entity.CoupLoading;

/**
 * 接箍上料实绩业务类
 * @author lzh 2015-7-16
 *
 */
public class CoupLoadingService extends DBCommon{

	/**
	 * 查询详细计划和实绩
	 * @param planNo 计划号
	 * @return
	 */
	public CoreReturnObject getCoupPlan(String planNo){
		Object[] params = new Object[] {planNo};
		CoreReturnObject core = new CoreReturnObject();
		core = this.getLoadResultById(planNo);
		CoreReturnSortObject ct = (CoreReturnSortObject) core.getResult();
		if(ct.getResult().size()>0){
			return this.getDataBySqlID("CoupLoadingService.GetCoupPlanAndLoadResultByID", params);
		}else{
			return this.getDataBySqlID("CoupLoadingService.GetCoupPlanByID", params);
		}
	}
	/**
	 * 上料实绩保存
	 * @param load 上料实绩实体类
	 * @return
	 */
	public CoreReturnObject saveLoadResult(CoupLoading load){
		CoreReturnObject core = new CoreReturnObject();
		core = this.getLoadResultById(load.getCoupcutBatchId());
		CoreReturnSortObject ct = (CoreReturnSortObject) core.getResult();
		Object[] params = new Object[] {load.getLoadPieces(),load.getLoadShift(),
				load.getLoadGroup(),load.getLoadUser(),load.getLoadTime(),load.getCoupcutBatchId()};
		if(ct.getResult().size()>0){
			//修改
			return this.setDataBySqlID("CoupLoadingService.UpdateLoadResult", params);
		}else{
			//新增
			return this.setDataBySqlID("CoupLoadingService.AddLoadResult", params);
		}
	}
	
	/**
	 * 查询上料实绩
	 * @param planNo
	 * @return
	 */
	public CoreReturnObject getLoadResultById(String planNo){
		return this.getDataBySqlID("CoupLoadingService.GetLoadResultByID", new Object[] {planNo});
	}
	 
}
