package com.steering.mes.zgmil.report;

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 java.sql.Connection;
import java.sql.PreparedStatement;

public class FrmProcessFlowCard extends DBCommon {

    /**
     *查询工艺流动卡
     */
    public CoreReturnObject queryMinResult(String lotNo, String juNo,
            String[] pline) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmProcessFlowCard.queryMinResult");
        sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", pline);
        sql += " GROUP BY  REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') ,T.LOT_NO,T.CONTRACT_NO," +
        		"T.PLINE_CODE,T.VARIETIES,T.PIPE_SIZE,T.GRADENAME,T.STEELNAME,T.ROLL_STANDRAD,T.LOT_SEQ_PATH";
        return this.getData(sql, new Object[] { lotNo, juNo });
    }

    public CoreReturnObject DoUpdateFilePath(String judgeStoveNo,String FilePath) throws Exception {


        CoreReturnObject core = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();

        try {
            connection.setAutoCommit(false); //


            String sql = CoreXmlSqlParsersFactory
                    .getSql("FrmProcessFlowCard.DoUpdateFilePath");
            PreparedStatement pst = connection.prepareStatement(sql);
            pst.setObject(1, FilePath);
            pst.setObject(2, judgeStoveNo);
            pst.executeUpdate();
            pst.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;

    }
}
