package com.steering.mes.signature;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Date;

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

import com.steering.comm.converter.CoreConverter;
import com.steering.comm.db.DBCommon;
import com.steering.common.EntityTool;
import com.steering.mes.zgmil.entity.YdmZcOutlistEntity;

public class FrmCancelAll extends DBCommon{

	/***
	 * 查询出库记录
	 * @param jugeNo
	 * @return
	 */
	public CoreReturnObject doQueryOutList(String jugeNo)
	{
		return this.getDataBySqlID("FrmCancelAll.doQueryOutList",new Object[]{jugeNo});
	}
	/***
	 * 查询该炉是否申请判定
	 * @param jugeNo
	 * @return
	 */
	public CoreReturnObject doQueryJugde(String jugeNo)
	{
		return this.getDataBySqlID("FrmCancelAll.doQueryJugde", new Object[]{jugeNo});
	}
	/***
	 * 查询该炉是否在交库点结炉
	 * @param jugeNo
	 * @return
	 */
	public CoreReturnObject doQueryInstoreRs(String jugeNo)
	{
		return this.getDataBySqlID("FrmCancelAll.doQueryInstoreRs", new Object[]{jugeNo});
	}
	/***
	 * 一键撤销
	 * @param ydmTity
	 * @return
	 */
	public CoreReturnObject cancelAll(String ydmTity,String userName)
	{
		CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        PreparedStatement psta = null;
        String sql = "";
        ResultSet rs = null;
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat(
        "yyyy-MM-dd HH:mm:ss");
        String systime = dateFormat.format(now);
        try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String updateSql = CoreXmlSqlParsersFactory.getSql("FrmCancelAll.cancelAll");
			
			YdmZcOutlistEntity ydmEntity = EntityTool.getEntityByJSONStr(ydmTity, YdmZcOutlistEntity.class);
			ydmEntity.setDeleteName(userName);
			updateSql = EntityTool.fillSqlByEntity(updateSql, ydmEntity);
			PreparedStatement updatePsta = connection.prepareStatement(updateSql);
			updatePsta.executeUpdate();
			updatePsta.close();
			
			cro.setV_errMsg("撤销成功!");
			connection.commit();
        }
	   	catch (Exception e) {
            System.out.println(e.getMessage());
            if (connection != null) {
                try {
                	cro.setV_errMsg(e.getMessage());
                    connection.rollback(); // 回滚事务
                }
                catch (Exception e2) {
                }
            }
        }
        finally {
            try {
                if (connection != null && !connection.isClosed()) {
                    connection.close();
                }
            }
            catch (Exception e2) {
            }
        }
        return cro;
	}
}
