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.HeatTreatmentResult;

/**
 * 热处理实绩服务类
 * @author lzh 2015-7-27
 *
 */
public class HeatTreatmentService extends DBCommon{

	/**
	 * 根据计划号查询热处理实绩
	 * @param planNo
	 * @return
	 */
	public CoreReturnObject getHeatTreatmentResult(String planNo){
		Object[] params = new Object[]{planNo};
		return this.getDataBySqlID("HeatTreatmentService.GetHeatTreatmentResultByID", params);
	}
	
	/**
	 * 保存热处理实绩
	 * @param result
	 * @return
	 */
	public CoreReturnObject saveHeatTreatmentResult(HeatTreatmentResult result){
		Object[] hHeat = new Object[]{result.getPlineCode(),result.getColShft(),
				result.getColGroup(),result.getColUser(),
				result.getProducer(),result.getProducerTime(),result.gethHeatEnterTime(),
				result.gethHeatOutTime(),result.gethHeatExitTemp(),result.gethHeatTaktTime(),
				result.gethHeatAvgTemp1(),result.gethHeatAvgTemp2(),result.gethHeatAvgTemp3(),
				result.gethHeatAvgTemp4(),result.gethHeatAvgTemp5(),result.gethHeatAvgTemp6(),
				result.gethHeatQuenchMode(),result.gethHeatQuenchFlow(),
				result.gethHeatQuenchSecs(),result.getPlanNo()};
		
		Object[] lHeat = new Object[]{result.getPlineCode(),result.getColShft(),
				result.getColGroup(),result.getColUser(),
				result.getProducer(),result.getProducerTime(),result.getlHeatEnterTime(),
				result.getlHeatOutTime(),result.getlHeatExitTemp(),result.getlHeatTaktTime(),
				result.getlHeatAvgTemp1(),result.getlHeatAvgTemp2(),result.getlHeatAvgTemp3(),
				result.getlHeatAvgTemp4(),result.getlHeatAvgTemp5(),result.getlHeatAvgTemp6(),
				result.getlHeatAvgTemp7(),result.getlHeatAvgTemp8(),result.getlHeatAvgTemp9(),
				result.getPlanNo()};
		
		CoreReturnObject core = this.getHeatTreatmentResult(result.getPlanNo());
		CoreReturnSortObject ct = (CoreReturnSortObject) core.getResult();
		CoreReturnObject core2 = new CoreReturnObject();
		ArrayList<Object[]> params = new ArrayList<Object[]>();
		params.add(hHeat);
		params.add(lHeat);
		if(ct.getResult().size()>0){
			try {
				ArrayList<String> sqlId = new ArrayList<String>();
				sqlId.add("HeatTreatmentService.UpdateHHeatResult");
				sqlId.add("HeatTreatmentService.UpdateLHeatResult");
				core2 = this.setDataById(sqlId, params);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}else{
			try {
				ArrayList<String> sqlId = new ArrayList<String>();
				sqlId.add("HeatTreatmentService.AddHHeatResult");
				sqlId.add("HeatTreatmentService.AddLHeatResult");
				core2 = this.setDataById(sqlId, params);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return core2;
	}
}
