package com.steering.mes.mcp.heatTreatment;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;

import com.steering.comm.converter.CoreConverter;
import com.steering.comm.converter.EntityTool;
import com.steering.comm.db.DBCommon;
import com.steering.mes.mcp.entity.HttControlShiftEntity;
import com.steering.mes.mcp.entity.HttSignatureEntity;

public class HttControlShift extends DBCommon {

	/**
	 * 查询
	 * 
	 * @param plineCode
	 * @return
	 */
	public CoreReturnObject doQuery(String[] plineCode) {
		String sql = "";
		sql = CoreXmlSqlParsersFactory.getSql("HttControlShift.doQuery");
		sql += CoreConverter.toSqlConditionString("PLINE_CODE", plineCode);
		return this.getData(sql);
	}

	/**
	 * 查询
	 * 
	 * @param plineCode
	 * @param proBc
	 * @return
	 */
	public CoreReturnObject getSameData(String plineCode, String proBc) {
		String sql = "";
		sql = CoreXmlSqlParsersFactory.getSql("HttControlShift.doQuery");
		if (!plineCode.equals("")) {
			sql += " AND T.PLINE_CODE = '" + plineCode + "'";
		}
		if (!proBc.equals("")) {
			sql += " AND T.PRO_BC = '" + proBc + "'";
		}
		return this.getData(sql);
	}

	/**
	 * 新增
	 * 
	 * @param list
	 * @return
	 */
	public CoreReturnObject doSave(ArrayList<String> list) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			ArrayList<String> sqllist = new ArrayList<String>();
			for (String str : list) {
				HttControlShiftEntity httEntity = EntityTool
						.getEntityByJSONStr(str, HttControlShiftEntity.class);
				HttControlShiftEntity httReport = new HttControlShiftEntity();
				// 新增信息
				httReport.setPlineCode(httEntity.getPlineCode());
				httReport.setPlineName(httEntity.getPlineName());
				httReport.setProBc(httEntity.getProBc());
				httReport.setLastBc(httEntity.getLastBc());
				httReport.setShiftBeg(httEntity.getShiftBeg());
				httReport.setShiftEnd(httEntity.getShiftEnd());
				httReport.setShiftTime(httEntity.getShiftTime());

				String insertBcSql = CoreXmlSqlParsersFactory
						.getSql("HttControlShift.add");
				insertBcSql = EntityTool
						.fillSqlByEntity(insertBcSql, httReport);
				sqllist.add(insertBcSql);
			}

			core = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
					sqllist);

			if (core.getV_errMsg().equals("")) {
				core.setV_errMsg("新增成功！");
			}
		} catch (Exception e) {
			core.setV_errMsg(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return core;
	}

	/**
	 * 修改
	 * 
	 * @param list
	 * @return
	 */
	public CoreReturnObject doUpdate(ArrayList<String> list) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();

		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			ArrayList<String> sqllist = new ArrayList<String>();
			for (String str : list) {
				HttControlShiftEntity httEntity = EntityTool
						.getEntityByJSONStr(str, HttControlShiftEntity.class);
				HttControlShiftEntity httReport = new HttControlShiftEntity();
				// 修改
				httReport.setPlineCode(httEntity.getPlineCode());
				httReport.setPlineName(httEntity.getPlineName());
				httReport.setProBc(httEntity.getProBc());
				httReport.setLastBc(httEntity.getLastBc());
				httReport.setShiftBeg(httEntity.getShiftBeg());
				httReport.setShiftEnd(httEntity.getShiftEnd());
				httReport.setShiftTime(httEntity.getShiftTime());

				String insertBcSql = CoreXmlSqlParsersFactory
						.getSql("HttControlShift.update");
				insertBcSql = EntityTool
						.fillSqlByEntity(insertBcSql, httReport);
				sqllist.add(insertBcSql);
			}
			core = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
					sqllist);
			if (core.getV_errMsg().equals("")) {
				core.setV_errMsg("修改成功！");
			}
		} catch (Exception e) {
			core.setV_errMsg(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return core;
	}

	/**
	 * 删除
	 * 
	 * @param list
	 * @return
	 */
	public CoreReturnObject doDelete(ArrayList<String> list) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();

		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			ArrayList<String> sqllist = new ArrayList<String>();
			for (String str : list) {
				HttControlShiftEntity httEntity = EntityTool
						.getEntityByJSONStr(str, HttControlShiftEntity.class);
				HttControlShiftEntity httReport = new HttControlShiftEntity();
				// 删除
				httReport.setPlineCode(httEntity.getPlineCode());
				httReport.setPlineName(httEntity.getPlineName());
				httReport.setProBc(httEntity.getProBc());

				String insertBcSql = CoreXmlSqlParsersFactory
						.getSql("HttControlShift.delete");
				insertBcSql = EntityTool
						.fillSqlByEntity(insertBcSql, httReport);
				sqllist.add(insertBcSql);
			}
			core = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
					sqllist);
			if (core.getV_errMsg().equals("")) {
				core.setV_errMsg("删除成功！");
			}
		} catch (Exception e) {
			core.setV_errMsg(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return core;
	}
}
