package com.steering.pss.judge.DAL;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

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

import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.comm.tools.SqlBuilder;
import com.steering.pss.judge.Bll.BllAuditMeltingData;
import com.steering.pss.judge.comm.ChemJudgeHelper;
import com.steering.pss.judge.model.CraftOrdDesignStdCicEntity;
import com.steering.pss.judge.model.QcmJhyElementsEntity;
import com.steering.pss.judge.model.QcmLgChemjudgeEntity;
import com.steering.pss.qcm.model.GenericEntity;

public class SteelMakingAdvanceJudgeDAL extends DBCommon {
	
//	public static void main(String[] args){
//		try {
//	      Class.forName("oracle.jdbc.driver.OracleDriver");// 加载Oracle驱动程序
//	      System.out.println("开始尝试连接数据库！");
//	      String url = "jdbc:oracle:" + "thin:@172.16.2.128:1521/tgcxtest";// 127.0.0.1是本机地址，XE是精简版Oracle的默认数据库名
//	      String user = "cxuser";// 用户名,系统默认的账户名
//	      String password = "cxuser";// 你安装时选设置的密码
//	      Connection con = DriverManager.getConnection(url, user, password);// 获取连接
//			
//	      //judge("20180001", "070001", "CICN000100", "ZZ_20170700003", "01", con);
//			
//	      con.close();
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//	}
//	
//	public CoreReturnObject Test(){
//		Connection con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
//		//judge("20180001", "070001", "CICN000100", "ZZ_20170700003", "01", con);
//		try {
//			con.close();
//		} catch (SQLException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		return new CoreReturnObject();
//	}
//	
//	/**
//	 * 炼钢预判
//	 * @param stoveNo
//	 * @param judgeStoveNo
//	 * @param cic
//	 * @param proPlanId
//	 * @param gxPlanNo
//	 */
//	public CoreReturnObject judge(String stoveNo, String judgeStoveNo, String cic,
//			String proPlanId, String gxPlanNo){
//		CoreReturnObject cro = new CoreReturnObject();
//		Connection con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
//		try{
//			Statement st = con.createStatement();
//			QcmJhyElementsEntity jhyElements = BllAuditMeltingData.getElements(stoveNo, con);
//			SqlBuilder b = new SqlBuilder("SteelMakingAdvanceJudgeDAL.queryCraftDesignKey");
//			b.Fill(new String[]{ proPlanId });
//			ResultSet craftRs = st.executeQuery(b.toString());
//			b = new SqlBuilder("SteelMakingAdvanceJudgeDAL.queryStlInCision");
//			b.Fill(new String[]{ proPlanId, gxPlanNo, stoveNo, judgeStoveNo });
//			Statement st2 = con.createStatement();
//			ResultSet stlInCisionRs = st2.executeQuery(b.toString());
//			stlInCisionRs.next();
//			if(craftRs.next()){
//				b = new SqlBuilder("SteelMakingAdvanceJudgeDAL.queryCraftChem");
//				b.Fill(new String[]{ craftRs.getString("DESGIN_KEY"), craftRs.getString("MSC_PLINE"),
//						cic });
//				ArrayList<CraftOrdDesignStdCicEntity> craftCics = EntityTool.getEntitysBySqlNoClsCon(
//						b.toString(), con, CraftOrdDesignStdCicEntity.class);
//				
//				Object[] results = ChemJudgeHelper.Judge(jhyElements, craftCics, null);
//				QcmLgChemjudgeEntity lgChemJudge = new QcmLgChemjudgeEntity();
//				if(Boolean.parseBoolean(results[0].toString())){
//					lgChemJudge.setJudgeresultChem("40740101");
//				}else{
//					lgChemJudge.setJudgeresultChem("40740102");
//				}
//				
//				GenericEntity maxChemJudgeId = EntityTool.getEntityBySqlNoClsCon(CoreXmlSqlParsersFactory.getSql(
//						"QcmLgChemJudgeDAL.getMaxChemJudgeId"), con, GenericEntity.class);
//				lgChemJudge.setChemJudgeId(maxChemJudgeId.getMaxValue());
//				lgChemJudge.setStoveNo(stoveNo);
//				lgChemJudge.setJudgeStoveNo(judgeStoveNo);
//				lgChemJudge.setPlineCode(stlInCisionRs.getString("PLINE_CODE"));
//				lgChemJudge.setProcessCdoe("B");
//				lgChemJudge.setProcessDesc("铸造");
//				lgChemJudge.setOrderisunchain("0");
//				lgChemJudge.setAssayno(jhyElements.getAssayno());
//				lgChemJudge.setCreateName("SYSTEM");
//				String sql = CoreXmlSqlParsersFactory.getSql("QcmLgChemjudgeDAL.Insert");
//				sql = EntityTool.fillSqlByEntity(sql, lgChemJudge);
//				st.executeUpdate(sql);
//				
//				//更新切割实绩表
//				b = new SqlBuilder("SteelMakingAdvanceJudgeDAL.updateStlInCision");
//				b.Fill(new String[]{ maxChemJudgeId.getMaxValue(), "20", lgChemJudge.getJudgeresultChem(),
//						proPlanId, gxPlanNo, stoveNo, judgeStoveNo });
//				st.executeUpdate(b.toString());
//				
//			}
//			
//			craftRs.close();
//			stlInCisionRs.close();
//			st.close();
//			st2.close();
//			con.commit();
//			
//			return cro;
//		}catch(Exception ex){
//			try {
//				con.rollback();
//			} catch (SQLException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//			cro.setV_errCode(-1);
//			cro.setV_errMsg(ex.getMessage());
//			return cro;
//		}finally{
//			try {
//				con.close();
//			} catch (SQLException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//		}
//	}
//	
//	/**
//	 * 查询工艺评审DESIGNKEY
//	 * @param stoveNo
//	 * @return
//	 */
//	public CoreReturnObject queryCraftDesignKey(String proPlanId){
//		SqlBuilder b = new SqlBuilder("SteelMakingAdvanceJudgeDAL.queryCraftDesignKey");
//		b.Fill(new String[]{proPlanId});
//		
//		return this.getData(b.toString());
//	}
}
