package com.steering.mes.zgmil.coup;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import com.steering.comm.db.DBCommon;
import com.steering.common.EntityTool;
import com.steering.mes.mcp.common.PlanService;
import com.steering.mes.signature.MeanValueCalculation;
import com.steering.mes.zgmil.entity.MatZcMEntity;
import com.steering.mes.zgmil.entity.MilMeasureResultEntity;
import com.steering.mes.zgmil.entity.RtdMeasurePosdataEntity;
import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;

public class FrmMeasureResultZG extends DBCommon {

	/**
	 * 查询
	 * 
	 * @param date
	 * @param endDate
	 * @param judgeStoveNo
	 * @return
	 */
	public CoreReturnObject doQuery(String date, String endDate,
			String judgeStoveNo, String[] arr) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMeasureResultZG.doQuery");
		String sql1 = "";
		if (!date.equals("")) {
			sql1 += " AND T.COL_TIME BETWEEN TO_DATE('" + date
					+ "' ,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE('" + endDate
					+ "' ,'YYYY-MM-DD HH24:MI:SS') ";
		}
		if (!judgeStoveNo.equals("")) {
			sql1 += " AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = '"
					+ judgeStoveNo + "' ";
		}
		for (int i = 0; i < arr.length; i++) {
			if (arr.length > 1) {
				if (i == 0) {
					sql1 += " AND (DEPARTMENT_CODE LIKE '%" + arr[i] + "%'";
				} else if (i == arr.length - 1) {
					sql1 += " OR DEPARTMENT_CODE LIKE '%" + arr[i] + "%')";
				} else {
					sql1 += " OR DEPARTMENT_CODE LIKE '%" + arr[i] + "%'";
				}
			} else {
				sql1 += " AND DEPARTMENT_CODE LIKE '%" + arr[i] + "%'";
			}
		}
		sql = sql.replace("#someThing#", sql1);
		return this.getData(sql);
	}

	/**
	 * 查询量测点实绩
	 * 
	 * @param HeatPlanNo
	 * @param JudgeStoveNo
	 * @param PlineCode
	 * @return
	 */
	public CoreReturnObject doQueryMilMeasureResult(String HeatPlanNo,
			String JudgeStoveNo, String PlineCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMeasureResultZG.doQueryMilMeasureResult");
		return this.getData(sql, new Object[] { HeatPlanNo, JudgeStoveNo,
				PlineCode });
	}

	/**
	 * 查询进程表数据
	 * 
	 * @param HeatPlanNo
	 * @param JudgeStoveNo
	 * @param PlineCode
	 * @return
	 */
	public CoreReturnObject doQueryPortMilBatchSampleResult(String HeatPlanNo,
			String JudgeStoveNo, String PlineCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMeasureResultZG.doQueryPortMilBatchSampleResult");
		return this.getData(sql, new Object[] { HeatPlanNo, JudgeStoveNo,
				PlineCode });
	}

	/**
	 * 保存喷印管号
	 * 
	 * @param parm
	 * @return
	 */
	public CoreReturnObject doSaveMeasuringSeq(ArrayList<String> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();

		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String SaveSql = CoreXmlSqlParsersFactory
					.getSql("FrmMeasureResultZG.doSaveMeasuringSeq");
			PreparedStatement SaveSqlPsta = connection
					.prepareStatement(SaveSql);
			SaveSqlPsta.setString(1, parm.get(0));
			SaveSqlPsta.setString(2, parm.get(1));
			SaveSqlPsta.setString(3, parm.get(2));
			SaveSqlPsta.setString(4, parm.get(3));
			SaveSqlPsta.setString(5, parm.get(4));
			SaveSqlPsta.addBatch();
			SaveSqlPsta.executeBatch();

			if (cro.getV_errMsg().equals("")) {
				cro.setV_errMsg("保存喷印管号成功!");
			}
			connection.commit();

		} catch (SQLException e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}

	/**
	 * 发送喷印信息
	 * 
	 * @param parm
	 * @return
	 */
	public CoreReturnObject doSaveMatInfo(ArrayList<String> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String SaveSql = CoreXmlSqlParsersFactory
					.getSql("FrmMeasureResultZG.doSaveMatInfo");
			PreparedStatement SaveSqlPsta = connection
					.prepareStatement(SaveSql);
			SaveSqlPsta.setString(1, parm.get(0));
			SaveSqlPsta.setString(2, parm.get(1));
			SaveSqlPsta.setString(3, parm.get(2));
			SaveSqlPsta.setString(4, parm.get(3));
			SaveSqlPsta.setString(5, parm.get(4));
			SaveSqlPsta.addBatch();
			SaveSqlPsta.executeBatch();

			if (cro.getV_errMsg().equals("")) {
				cro.setV_errMsg("发送喷印信息成功!");
			}
			connection.commit();

		} catch (SQLException e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}

	/**
	 * 新增
	 * 
	 * @param milMeasureResult
	 * @param HeatPlanNo
	 * @param JudgeStoveNo
	 * @param PlineCode
	 * @return
	 */
	public CoreReturnObject DoAdd(String milMeasureResultStr,
			String HeatPlanNo, String JudgeStoveNo, String PlineCode) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		String resultNo = "";
		String proWt = "";
		ResultSet rs = null;
		int matCount = 0;
		int processCount = 0;
		try {
			connection.setAutoCommit(false); //
			String updatePort = CoreXmlSqlParsersFactory
					.getSql("FrmMeasureResultZG.updatePort");// 更新管号队列
			PreparedStatement patsupdatePort = connection
					.prepareStatement(updatePort);

			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("FrmMeasureResultZG.AddResult");// 新增上料实绩

			// 获取最大实绩编号
			String sql = CoreXmlSqlParsersFactory
					.getSql("FrmMeasureResultZG.queryResultNo");
			psta = connection.prepareStatement(sql);
			psta.setObject(1, PlineCode);
			psta.setObject(2, PlineCode);
			rs = psta.executeQuery();
			if (rs.next()) {
				resultNo = rs.getString("RESULT_NO");
			}
			rs.close();
			psta.close();

			// 查询未匹配的支数
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmMeasureResultZG.queryMatCount");
			psta = connection.prepareStatement(sql);
			psta.setObject(1, JudgeStoveNo);
			psta.setObject(2, PlineCode);
			rs = psta.executeQuery();
			if (rs.next()) {
				matCount = Integer.parseInt(rs.getString("MatCount"));
			}
			rs.close();
			psta.close();
			
			// 查询进程表未匹配的支数
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmMeasureResultZG.queryProcessCount");
			psta = connection.prepareStatement(sql);
			psta.setObject(1, JudgeStoveNo);
			psta.setObject(2, PlineCode);
			rs = psta.executeQuery();
			if (rs.next()) {
				processCount = Integer.parseInt(rs.getString("MatCount"));
			}
			rs.close();
			psta.close();

			MilMeasureResultEntity milMeasureResult = EntityTool
					.getEntityByJSONStr(milMeasureResultStr,
							MilMeasureResultEntity.class);
			if (Integer.parseInt(milMeasureResult.getProNum()) > matCount) {
				core.setV_errMsg("没有足够的管,无法新增实绩！");
				return core;
			}
			if (Integer.parseInt(milMeasureResult.getProNum()) > processCount) {
				core.setV_errMsg("没有足够的好管,无法新增实绩！");
				return core;
			}
			patsupdatePort.setString(1, HeatPlanNo);
			patsupdatePort.setString(2, JudgeStoveNo);
			patsupdatePort.setString(3, milMeasureResult.getBatchNo());
			patsupdatePort.setString(4, PlineCode);
			patsupdatePort.setString(5, milMeasureResult.getProNum());
			patsupdatePort.setString(6, resultNo);
			patsupdatePort.addBatch();
			patsupdatePort.executeBatch();

			// 获取重量
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmMeasureResultZG.queryProWt");
			psta = connection.prepareStatement(sql);
			psta.setObject(1, resultNo);
			rs = psta.executeQuery();
			if (rs.next()) {
				proWt = rs.getString("MEASURE_WEIGHT");
			}
			rs.close();
			psta.close();
			milMeasureResult.setResultNo(resultNo);
			milMeasureResult.setProWt(proWt);

			sqlAdd = com.steering.common.EntityTool.fillSqlByEntity(sqlAdd,
					milMeasureResult);
			PreparedStatement patAdd = connection.prepareStatement(sqlAdd);
			patAdd.addBatch();
			patAdd.executeBatch();
			core.setV_errMsg("新增成功!");
			core.setResult(1);
			connection.commit();
		} 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 resultNo
	 * @param HeatPlanNo
	 * @param JudgeStoveNo
	 * @param PlineCode
	 * @return
	 */
	public CoreReturnObject DoDelete(String resultNo, String HeatPlanNo,
			String JudgeStoveNo, String PlineCode) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String DeleteResultSql = CoreXmlSqlParsersFactory
					.getSql("FrmMeasureResultZG.DeleteResult");// 删除实绩
			PreparedStatement patsDeleteResult = connection
					.prepareStatement(DeleteResultSql);
			patsDeleteResult.setString(1, resultNo);
			patsDeleteResult.setString(2, HeatPlanNo);
			patsDeleteResult.setString(3, JudgeStoveNo);
			patsDeleteResult.setString(4, PlineCode);
			patsDeleteResult.addBatch();
			patsDeleteResult.executeBatch();

			core.setV_errMsg("删除成功!");
			core.setResult(1);
			connection.commit();
		} 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;
	}

	/**
	 * 查询成品测量点数据
	 */
	public CoreReturnObject geRtdMeasurePosdataAll(String judgeStoveNo,
			String BatchNo, String PlineCode, String Flag) {

		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMeasureResultZG.geRtdMeasurePosdata2");

		if (!judgeStoveNo.equals("")) {
			sql += " AND T.JUDGE_STOVE_NO='" + judgeStoveNo + "'";
		}
		if (!BatchNo.equals("")) {
			sql += " AND T.BATCH_NO ='" + BatchNo + "'";
		}
		if (!judgeStoveNo.equals("")) {
			sql += " AND T.PLINE_CODE='" + PlineCode + "'";
		}

		if (Flag.equals("1")) {
			sql += " AND T.FLAG = '00'";
		}

		sql += "ORDER BY TO_NUMBER (MAT_NO)";

		return this.getData(sql);
	}

	/**
	 * 手动新增
	 * 
	 * @param EntityStr
	 * @param HeatPlanID
	 * @return
	 */
	public CoreReturnObject DoAddMeasureData(String EntityStr, String HeatPlanID) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		String sql = "";
		ResultSet rs = null;
		String contractNo = "";
		String plineCode = "";
		String plineName = "";

		try {
			connection.setAutoCommit(false);
			RtdMeasurePosdataEntity entity = EntityTool.getEntityByJSONStr(
					EntityStr, RtdMeasurePosdataEntity.class);

			sql = CoreXmlSqlParsersFactory
					.getSql("FrmMeasureResultZG.queryMilplan");// 查询计划信息
			psta = connection.prepareStatement(sql);
			psta.setObject(1, HeatPlanID);
			psta.setObject(2, entity.getJudgeStoveNo());
			rs = psta.executeQuery();
			if (rs.next()) {
				contractNo = rs.getString("CONTRACT_NO");
				plineCode = rs.getString("PLINE_CODE");
				plineName = rs.getString("PLINE_NAME");
			}
			rs.close();
			psta.close();

			entity.setProOrderNo(contractNo);
			entity.setPlineCode(plineCode);
			entity.setPlineName(plineName);

			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("FrmMeasureResultZG.DoAddMeasureData");

			sqlAdd = com.steering.common.EntityTool.fillSqlByEntity(sqlAdd,
					entity);
			PreparedStatement patAdd = connection.prepareStatement(sqlAdd);
			patAdd.addBatch();
			patAdd.executeBatch();

			core.setV_errMsg("新增成功");
			core.setResult(1);
			connection.commit();
		} 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 EntityStr
	 * @param HeatPlanID
	 * @return
	 */
	public CoreReturnObject Doupdate(String EntityStr, String HeatPlanID) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		String sql = "";
		ResultSet rs = null;
		try {
			connection.setAutoCommit(false);
			RtdMeasurePosdataEntity entity = EntityTool.getEntityByJSONStr(
					EntityStr, RtdMeasurePosdataEntity.class);
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("FrmMeasureResultZG.Doupdate");

			sqlAdd = com.steering.common.EntityTool.fillSqlByEntity(sqlAdd,
					entity);
			PreparedStatement patAdd = connection.prepareStatement(sqlAdd);
			patAdd.setString(1, HeatPlanID);
			patAdd.addBatch();
			patAdd.executeBatch();

			core.setV_errMsg("成功");
			core.setResult(1);
			connection.commit();
		} 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;
	}

	/**
	 * Excel导入
	 * 
	 * @param EntityStrs
	 * @param HeatPlanID
	 * @return
	 */
	public CoreReturnObject DoAddMeasureData(ArrayList<String> EntityStrs,
			String HeatPlanID) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		String sql = "";
		ResultSet rs = null;
		String contractNo = "";
		String plineCode = "";
		String plineName = "";

		try {
			connection.setAutoCommit(false);
			RtdMeasurePosdataEntity entityFirst = EntityTool
					.getEntityByJSONStr(EntityStrs.get(0),
							RtdMeasurePosdataEntity.class);
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmMeasureResultZG.queryMilplan");// 查询计划信息
			psta = connection.prepareStatement(sql);
			psta.setObject(1, HeatPlanID);
			psta.setObject(2, entityFirst.getJudgeStoveNo());
			rs = psta.executeQuery();
			if (rs.next()) {
				contractNo = rs.getString("CONTRACT_NO");
				plineCode = rs.getString("PLINE_CODE");
				plineName = rs.getString("PLINE_NAME");
			}
			rs.close();
			psta.close();

			for (String EntityStr : EntityStrs) {
				RtdMeasurePosdataEntity entity = EntityTool.getEntityByJSONStr(
						EntityStr, RtdMeasurePosdataEntity.class);
				entity.setProOrderNo(contractNo);
				entity.setPlineCode(plineCode);
				entity.setPlineName(plineName);
				String sqlAdd = CoreXmlSqlParsersFactory
						.getSql("FrmMeasureResultZG.DoAddMeasureData");
				sqlAdd = com.steering.common.EntityTool.fillSqlByEntity(sqlAdd,
						entity);
				PreparedStatement patAdd = connection.prepareStatement(sqlAdd);
				patAdd.addBatch();
				patAdd.executeBatch();
				patAdd.close();
			}

			core.setV_errMsg("新增成功");
			core.setResult(1);
			connection.commit();
		} 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 HeatPlanID
	 * @param ID
	 * @return
	 */
	public CoreReturnObject DoRecover(String HeatPlanID, String ID) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss", Locale.CHINA);
		String systime = dateFormat.format(now);

		try {
			connection.setAutoCommit(false);
			RtdMeasurePosdataEntity entity = getRtdMeasurePosdataEntityByID(
					connection, ID);
			if (entity == null) {
				core.setV_errMsg("找不到测量点数据,请刷新数据！");
				return core;
			}

			if (!entity.getFlag().equals("10")) {
				core.setV_errMsg("该数据未剔除,请刷新数据！");
				return core;
			}

			if (!entity.getMatNoCx().equals("")) {
				String NewMatNo = "";
				String sql = CoreXmlSqlParsersFactory
						.getSql("FrmMeasureResultZG.GetExitsRtdData");
				psta = connection.prepareStatement(sql);
				psta.setString(1, entity.getMatNoCx());
				ResultSet rs = psta.executeQuery();
				if (rs.next()) {
					NewMatNo = rs.getString("MAT_NO");
				}
				if (!NewMatNo.equals("")) {
					core.setV_errMsg("改管号已经重新匹配新的喷印管号,不允许恢复剔除！");
					return core;
				}

			}

			String UpdateFlagSql = CoreXmlSqlParsersFactory
					.getSql("FrmMeasureResultZG.UpdateFlag");
			PreparedStatement patUpdateFlagSql = connection
					.prepareStatement(UpdateFlagSql);
			patUpdateFlagSql.setObject(1, "00");
			patUpdateFlagSql.setObject(2, entity.getMatNoCx());
			patUpdateFlagSql.setObject(3, ID);
			patUpdateFlagSql.addBatch();
			patUpdateFlagSql.executeBatch();

			core.setV_errMsg("成功");
			core.setResult(1);
			connection.commit();
		} 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 HeatPlanID
	 * @param ID
	 * @return
	 */
	public CoreReturnObject DoRemove(String HeatPlanID, String ID) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			connection.setAutoCommit(false);
			RtdMeasurePosdataEntity entity = getRtdMeasurePosdataEntityByID(
					connection, ID);
			if (entity == null) {
				core.setV_errMsg("找不到测量点数据,请刷新数据！");
				return core;
			}

			if (!entity.getFlag().equals("00")) {
				core.setV_errMsg("该数据已经被剔除,请刷新数据！");
				return core;
			}

			String UpdateFlagSql = CoreXmlSqlParsersFactory
					.getSql("FrmMeasureResultZG.UpdateFlag");
			PreparedStatement patUpdateFlagSql = connection
					.prepareStatement(UpdateFlagSql);
			patUpdateFlagSql.setObject(1, "10");
			patUpdateFlagSql.setObject(2, entity.getMatNoCx());
			patUpdateFlagSql.setObject(3, ID);
			patUpdateFlagSql.addBatch();
			patUpdateFlagSql.executeBatch();
			core.setV_errMsg("成功");
			core.setResult(1);
			connection.commit();
		} 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;
	}

	public static RtdMeasurePosdataEntity getRtdMeasurePosdataEntityByID(
			Connection con, String ID) throws SQLException {

		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMeasureResultZG.getRtdMeasurePosdataEntityByID");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, ID);
		ResultSet rs = ps.executeQuery();
		List<RtdMeasurePosdataEntity> data = EntityTool.getEntitysByRs(rs,
				RtdMeasurePosdataEntity.class);
		rs.close();
		ps.close();
		if (data == null || data.size() == 0) {
			return null;
		} else {
			for (RtdMeasurePosdataEntity sendPlanCEntity : data) {
				EntityTool.nullConverNullString(sendPlanCEntity);
			}
			return data.get(0);
		}

	}

	/***
	 * 回报重量
	 * 
	 * @return
	 */
	public CoreReturnObject insertProssWt(String milMeasureStr) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		int acount = 0;
		int k = 0;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String updateProssWtSql = CoreXmlSqlParsersFactory
					.getSql("FrmMeasureResultZG.updateProWt");
			PreparedStatement updateProssPsta = connection
					.prepareStatement(updateProssWtSql);
			String updateProssWtSql2 = CoreXmlSqlParsersFactory
					.getSql("FrmMeasureResultZG.updateMeasureResult");
			PreparedStatement updateProssPsta2 = connection
					.prepareStatement(updateProssWtSql2);
			MilMeasureResultEntity milMeasureTity = EntityTool
					.getEntityByJSONStr(milMeasureStr,
							MilMeasureResultEntity.class);

			sql = CoreXmlSqlParsersFactory
					.getSql("FrmMeasureResultZG.selectCount");// 查询送判支数
			psta = connection.prepareStatement(sql);
			psta.setString(1, milMeasureTity.getResultNo());
			psta.setString(2, milMeasureTity.getHeatPlanNo());
			rs = psta.executeQuery();
			if (rs.next()) {
				acount = Integer.parseInt(rs.getString("ACOUNT"));
			}
			rs.close();
			psta.close();
			if (acount > 0) {
				cro.setV_errMsg("此数据已送判，不能回报重量！");
				return cro;
			}

			
			updateProssPsta.setString(1, milMeasureTity.getProWt());
			updateProssPsta.setString(2, milMeasureTity.getProNum());
			updateProssPsta.setString(3, milMeasureTity
					.getResultNo());
			updateProssPsta.setString(4, milMeasureTity
					.getPlineCode());
			updateProssPsta.setString(5, milMeasureTity
					.getHeatPlanNo());
			updateProssPsta.addBatch();
			
			updateProssPsta2.setString(1, milMeasureTity.getProWt());
			updateProssPsta2.setString(2, milMeasureTity.getResultNo());
			updateProssPsta2.addBatch();

			updateProssPsta.executeBatch();
			updateProssPsta2.executeBatch();
			cro.setV_errMsg("回报成功!");
			connection.commit();
		} catch (SQLException e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}

}
