package com.steering.mes.mcp.heatTreatment;

import java.util.ArrayList;

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

import com.steering.comm.db.DBCommon;
import com.steering.mes.mcp.entity.FinishingResult;
/**
 * 精整作业实绩服务类
 * @author lzh 2015-7-23
 *
 */
public class FinishingService extends DBCommon {

	/**
	 * 查询精整作业实绩
	 * @param planNo
	 * @return
	 */
	public CoreReturnObject getFinishingResult(String planNo){
		return this.getDataBySqlID("FinishingService.GetFinishingResultByID", 
				new Object[]{ planNo});
	}
	/**
	 * 保存精整作业实绩
	 * @param result 精整作业实绩
	 * @return
	 */
	public CoreReturnObject saveFinishingResult(FinishingResult result){
		Object[]  hLstraighten = new Object[]{result.gethRollNum1(),result.gethRollNum2(),
				result.gethRollNum3(),result.gethBendRate(),result.gethLstraightenTemp(),
				result.gethRollPieces(),result.gethRollShift(),result.gethRollGroup(),
				result.gethRollOperator(),result.gethRollTime(),result.getPlineCode(),
				result.getPlanNo(),0};
		Object[] lLstraighten = new Object[]{result.getlRollNum1(),result.getlRollNum2(),
				result.getlRollNum3(),result.getlBendRate(),result.getlLstraightenTemp(),
				result.getlRollPieces(),result.getlRollShift(),result.getlRollGroup(),
				result.getlRollOperator(),result.getlRollTime(),result.getPlineCode(),
				result.getPlanNo(),1};
		Object[] sizing = new Object[]{result.getSizingPieces(),result.getSizingShift(),
				result.getSizingGroup(),result.getSizingOperator(),result.getSizingTime(),
				result.getPlineCode(),result.getPlanNo()};
		CoreReturnObject core = new CoreReturnObject();
		core = this.getSizingResultByID(result.getPlanNo()); 
		CoreReturnSortObject ct = (CoreReturnSortObject) core.getResult();
		CoreReturnObject core2 = new CoreReturnObject();
		ArrayList<Object[]> params = new ArrayList<Object[]>();
		params.add(hLstraighten);
		params.add(lLstraighten);
		params.add(sizing);
		if(ct.getResult().size()>0)
		{
			try {
				ArrayList<String> sqlIDlist = new ArrayList<String>();
				sqlIDlist.add("FinishingService.UpdateLstraightenResult");
				sqlIDlist.add("FinishingService.UpdateLstraightenResult");
				sqlIDlist.add("FinishingService.UpdateSizingResult");
				core2 = this.setDataById(sqlIDlist, params);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}else{
			try {
				ArrayList<String> sqlIDlist = new ArrayList<String>();
				sqlIDlist.add("FinishingService.AddLstraightenResult");
				sqlIDlist.add("FinishingService.AddLstraightenResult");
				sqlIDlist.add("FinishingService.AddSizingResult");
				core2 = this.setDataById(sqlIDlist, params);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return core2;
	}
	
	/**
	 * 定径实绩查询
	 * @param planNo
	 * @return
	 */
	public CoreReturnObject getSizingResultByID(String planNo){
		return this.getDataBySqlID("FinishingService.GetSizingResultByID", new Object[]{planNo});
	}
}
