package com.steering.mes.zgmil.coup;

import java.util.ArrayList;

import com.steering.comm.db.DBCommon;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import com.steering.common.EntityTool;
import com.steering.mes.zgmil.entity.MilSlabScrapSeqEntity;

/**
 * 穿孔实绩业务类
 * 
 * @author lr 2015/05/28
 * @version v1.0
 */
public class PerforationResult extends DBCommon {
	/**
	 * 查询简单作业计划
	 * 
	 * @param MilPlan
	 *            作业计划实体类
	 * @return CoreReturnObject
	 */

	public CoreReturnObject getSingleMainPlanTC(
			com.steering.mes.zgmil.entity.MilPlan MilPlan) {
		return this.getDataBySqlID("PerforationResult.PlanQueryCKTC",
				new Object[] { MilPlan.getJudgeStoveNo(),
						MilPlan.getProPlanId(), MilPlan.getGxPlanNo() });
	}

	public CoreReturnObject getPerResult(String JudgeStoveNo, String proPlanId,
			String gxPlanNo) {
		return this.getDataBySqlID("PerforationResult.SingleFurResultQuery",
				new Object[] { JudgeStoveNo, proPlanId, gxPlanNo });
	}

	public CoreReturnObject UpdatePerforationStatue(
			com.steering.mes.zgmil.entity.MilPerforationResultEntity FeedRowPlan) {
		ArrayList<String> sqllist = new ArrayList<String>();
		// ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
		String sql = CoreXmlSqlParsersFactory
				.getSql("PerforationResult.UpdatePerforationStatue");
		String sql1 = CoreXmlSqlParsersFactory
				.getSql("PerforationResult.Addperforation_result");
		sql1 = EntityTool.fillSqlByEntity(sql1, FeedRowPlan);
		sql = EntityTool.fillSqlByEntity(sql, FeedRowPlan);
		sqllist.add(sql);
		sqllist.add(sql1);
		// sqllist.add("FeedResult.UpdateFeedRowStatue");
		// sqllist.add("FeedResult.AddFeedSawResult");
		// parmlist.add(new
		// Object[]{"1",FeedRowPlan.getJudgeStoveNo(),FeedRowPlan.getFeedRowNo()});
		// parmlist.add(new
		// Object[]{FeedRowPlan.getLotNo(),FeedRowPlan.getStoveNo(),FeedRowPlan.getJudgeStoveNo(),FeedRowPlan.getPlineCode()
		// ,FeedRowPlan.getColMode(),FeedRowPlan.getColUser(),FeedRowPlan.getColShift(),FeedRowPlan.getColGroup()});
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);
	}

	public CoreReturnObject scrapFurMat(MilSlabScrapSeqEntity MilScrapSlab) {
		ArrayList<String> sqllist = new ArrayList<String>();
		// 新增剔除管号序列
		String sql = CoreXmlSqlParsersFactory
				.getSql("PerforationResult.AddScrapSlabSeq");
		// 修改穿孔表物料状态
		String sql1 = CoreXmlSqlParsersFactory
				.getSql("PerforationResult.UpdateFurStatue");
		// 修改穿孔实绩表剔除支数
		String sql2 = CoreXmlSqlParsersFactory
				.getSql("PerforationResult.UpdateFurScrapNum");

		sql = EntityTool.fillSqlByEntity(sql, MilScrapSlab);
		sql1 = EntityTool.fillSqlByEntity(sql1, MilScrapSlab);
		sql2 = EntityTool.fillSqlByEntity(sql2, MilScrapSlab);
		sqllist.add(sql);
		sqllist.add(sql1);
		sqllist.add(sql2);
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);
	}

	/**
	 * 保存
	 * 
	 * @param MilPerforationResultEntity
	 * @return
	 */
	public CoreReturnObject savePerResult(
			com.steering.mes.zgmil.entity.MilPerforationResultEntity MilPerforationResultEntity) {
		ArrayList<String> sqllist = new ArrayList<String>();
		String sql = CoreXmlSqlParsersFactory
				.getSql("PerforationResult.UpdatePerResult");
		sql = EntityTool.fillSqlByEntity(sql, MilPerforationResultEntity);
		String sql1 = CoreXmlSqlParsersFactory
				.getSql("PerforationResult.UpdatePerRackEndTime");
		sql1 = EntityTool.fillSqlByEntity(sql1, MilPerforationResultEntity);
		sqllist.add(sql);
		sqllist.add(sql1);
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);

	}

	/**
	 * 结炉
	 * 
	 * @param MilPerforationResultEntity
	 * @return
	 */
	public CoreReturnObject nodePerResult(
			com.steering.mes.zgmil.entity.MilPerforationResultEntity MilPerforationResultEntity) {

		ArrayList<String> sqllist = new ArrayList<String>();
		String sql = CoreXmlSqlParsersFactory
				.getSql("PerforationResult.UpdatePerResultNode");
		String sql1 = CoreXmlSqlParsersFactory
				.getSql("PerforationResult.UpdateMainPlanStatue");
		String sql2 = CoreXmlSqlParsersFactory
				.getSql("PerforationResult.UpdateNodeRack");
		// 交接班时上个班的结束时间为空时，补齐时间
		String sql3 = CoreXmlSqlParsersFactory
				.getSql("PerforationResult.UpdateNodeRackEndTime");
		String updateProcess = CoreXmlSqlParsersFactory
				.getSql("FrmInOnlineStore.insertMilProcess2");// 更新进程表mil_processes数据
		
		sql = EntityTool.fillSqlByEntity(sql, MilPerforationResultEntity);
		sql1 = EntityTool.fillSqlByEntity(sql1, MilPerforationResultEntity);
		sql2 = EntityTool.fillSqlByEntity(sql2, MilPerforationResultEntity);
		sql3 = EntityTool.fillSqlByEntity(sql3, MilPerforationResultEntity);
		updateProcess = EntityTool.fillSqlByEntity(updateProcess, MilPerforationResultEntity);
		sqllist.add(sql);
		sqllist.add(sql1);
		sqllist.add(sql2);
		sqllist.add(sql3);
		sqllist.add(updateProcess);
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);

	}

	public CoreReturnObject GetSingleJRLResult(String JudgeStoveNo,
			String proPlanId, String gxPlanNo) {
		return this.getDataBySqlID("PerforationResult.SingleFeedSawResult",
				new Object[] { JudgeStoveNo, proPlanId, gxPlanNo });
	}

	public CoreReturnObject GetResult(String JudgeStoveNo, String proPlanId,
			String gxPlanNo) {
		return this.getDataBySqlID("PerforationResult.GetResult", new Object[] {
				JudgeStoveNo, proPlanId, gxPlanNo });
	}

	public CoreReturnObject GetSingleFurNodeResult(String PliceCode,
			String Shift, String Group, String StartTime, String EndTime) {
		return this.getDataBySqlID("PerforationResult.GetETResultNodeQuery",
				new Object[] { PliceCode, Shift, Group, StartTime, EndTime });
	}

	/**
	 * 查询工器具更换实绩
	 * 
	 * @param
	 * @return
	 */
	public CoreReturnObject toolChangeQuery(String PliceCode, String Shift,
			String Group, String StartTime, String EndTime) {

		return this.getDataBySqlID("FeedResult.PerToolQuery", new Object[] {
				PliceCode, Shift, Group, StartTime, EndTime });
	}

}
