package com.steering.pss.ydm.pipemanage;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.Util.StringUtils;

import com.steering.comm.data.ComBaseInfo;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.pss.plnsaleord.stove.PlanFurnProduction;
import com.steering.pss.sale.order.qualityDesign.QualityDesignTool;
import com.steering.pss.ydm.base.MeanValueCalculation;
import com.steering.pss.ydm.entity.MatBcMEntity;
import com.steering.pss.ydm.entity.PlnOrderZgSEntity;
import com.steering.pss.ydm.entity.YdmBsStorageEntity;
import com.steering.pss.ydm.entity.YdmZcInlistEntity;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class FrmSemiFinish extends DBCommon{
	/***
	 * 查询轧管订单信息
	 * @return
	 */
	public CoreReturnObject doQueryPlnOrderZg()
	{
		return this.getDataBySqlID("FrmSemiFinish.doQueryPlnOrderZg");
	}

	/***
	 * 查询手工入库记录
	 * @param regStartTim
	 * @param regEndTim
	 * @param jugeNo
	 * @return
	 */
	public CoreReturnObject doQueryInListWg(String regStartTim,String regEndTim,String jugeNo)
	{
		String sql = CoreXmlSqlParsersFactory.getSql("FrmSemiFinish.doQueryInListWg");
		if(!regStartTim.equals(""))
		{
			sql += " AND TRUNC(INSTOCK_TIME) >= TO_DATE('"+regStartTim+"','YYYY-MM-DD HH24:MI:SS') AND TRUNC(INSTOCK_TIME) <= TO_DATE('"+regEndTim+"','YYYY-MM-DD HH24:MI:SS')";
		}
		if(!jugeNo.equals(""))
		{
			sql += " AND T.JUDGE_STOVE_NO = '"+jugeNo+"'";
		}
		sql += " group by t.JUDGE_STOVE_NO,t.BATCH_NO,t.INSTOCK_DOC,t.PRODUCCODE,t.PRODUCNAME,t.STD_CODE,t.STD_NAME,t.STEELCODE,t.STEELNAME,t.STD_STYLE,t.STD_STYLE_DESC,t.SPEC_CODE,t.SPEC_NAME,t.JUDGE_STD_CODE,t.JUDGE_STD_NAME,t.GRADECODE,t.GRADENAME,t.BAL_YEAR_MONTH,t.PIPMEMO,t.BATCH_GROUD_NO,T.FLAG_STOVE_NO_ZG,";
		sql += " t.MODEL_DESC,t.ACT_DIMATER,t.ACT_HEIGHT,t.ACT_LEN_MIN,t.ACT_LEN_MAX,t.BELONG_CODE,t.BELONG_NAME,s.STORAGE_NAME,t.MEMO,t.CREATE_NAME,t.ORDER_NO,t.ORDER_SEQ,t.DELIVERY_NO,t.MODEL_CODE,t.PRODUCT_FLAG,t.PLINE_CODE,t.PLINE_NAME,T.MATERIAL_NAME,T.LOT_NO,T.PRO_ORDER_NO,T.MAT_STATUS,T.PRO_PLAN_ID,T.GX_PLAN_NO";
		sql += " order by t.instock_doc desc";
		
		return this.getData(sql);
	}
	
	/***
	 * 外购管手工入库
	 * @param ydmInList
	 * @param plnOrdZgS
	 * @return
	 */
	public CoreReturnObject doAddInListData(String ydmInListTity,String plnOrdZgSTity)
	{
		    YdmZcInlistEntity ydmInList = EntityTool.getEntityByJSONStr(ydmInListTity, YdmZcInlistEntity.class);
		    PlnOrderZgSEntity plnOrdZgS = EntityTool.getEntityByJSONStr(plnOrdZgSTity, PlnOrderZgSEntity.class);
		    QualityDesignTool.nullConverNullString(ydmInList);
		    QualityDesignTool.nullConverNullString(plnOrdZgS);
	        CoreReturnObject core = new CoreReturnObject();
	        Connection con = null;
	        PreparedStatement ps = null;
	        ResultSet rs = null;
	        String sql = "";
	        String nextProcessCode = "";
	        String nextProcessName = "";
	        Date now = new Date();
			SimpleDateFormat dateFormat = new SimpleDateFormat(
					"yyyy-MM-dd HH:mm:ss");
			SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
			String systime = dateFormat.format(now);
			//String yearMoth = df.format(now);
		    String yearMoth = "120504".equals(ydmInList.getSupplyUnitCode())? ComBaseInfo.GetBalYear_2416(new Date()): ComBaseInfo.GetBalYear(new Date());
	        try {
	            con = this.getDao("TgDao").getConnection();
	            con.setAutoCommit(false);
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmPipeInventoryIn.getStorgeInfo");
			ps = con.prepareStatement(sql);
			ps.setObject(1, ydmInList.getStorageNo());
			rs = ps.executeQuery();
			List<YdmBsStorageEntity> storageEntitys = EntityTool
					.getEntitysByRs(rs, YdmBsStorageEntity.class);
			ps.close();
			rs.close();
			
			if (plnOrdZgS.getWholeBacklogDesc().contains("镦拔扩")) {
				nextProcessCode = "E";
				nextProcessName = "镦拔扩";
			} else if (plnOrdZgS.getWholeBacklogDesc().contains("热处理")) {
				nextProcessCode = "F";
				nextProcessName = "热处理";
			} else if (plnOrdZgS.getWholeBacklogDesc().contains("加工")) {
				nextProcessCode = "G";
				nextProcessName = "管加工";
			}else
			{
				core.setV_errMsg("工艺制程有问题，请核实!");
				return  core;
			}
			
			
			if(nextProcessCode.equals("E"))
			{
				sql = CoreXmlSqlParsersFactory.getSql("FrmSemiFinish.SelectDbkS");//查询镦拔扩订单
			}else if(nextProcessCode.equals("F"))
			{
				sql = CoreXmlSqlParsersFactory.getSql("FrmSemiFinish.SelectRclS");//查询热处理订单
			}else if(nextProcessCode.equals("G"))
			{
				sql = CoreXmlSqlParsersFactory.getSql("FrmSemiFinish.SelectGxS");//查询管加工订单
			}
			sql = EntityTool.fillSqlByEntity(sql, plnOrdZgS);
			ps = con.prepareStatement(sql);
			rs = ps.executeQuery();
			List<PlnOrderZgSEntity> allOrderS = EntityTool.getEntitysByRs(rs, PlnOrderZgSEntity.class);
			rs.close();
			ps.close();
			// 查询仓库信息
			YdmBsStorageEntity storageEntity = null;
			if (storageEntitys != null && storageEntitys.size() > 0) {
				for (YdmBsStorageEntity ydmBsStorageEntity : storageEntitys) {
					QualityDesignTool.nullConverNullString(ydmBsStorageEntity);
				}
				storageEntity = storageEntitys.get(0);
			}

			if (storageEntity == null) {
				core.setV_errMsg("仓库信息不存在");
				return core;
			}
			ydmInList.setStorageAttr(storageEntity.getStorageAttr());
			ydmInList.setStorageAttrName(storageEntity.getStorageAttrName());
			ydmInList.setStorageTypeNo(storageEntity.getStorageTypeNo());
			ydmInList.setStorageTypeName(storageEntity.getStorageTypeName());
			// 计算支数与重量
            int actNum = Integer.parseInt(ydmInList.getActCount());
            double actWgt = Double.parseDouble(ydmInList.getActWeight());
            List<double[]> list = MeanValueCalculation.MeanCalculation(actWgt,
                    actNum);
            int index = -1;
            DecimalFormat strDf = new DecimalFormat("0000");
            // 查询最大物料编号
             sql = CoreXmlSqlParsersFactory.getSql("FrmPipeInventoryIn.getMaxMatNo");
             ps = con.prepareStatement(sql);
             ps.setObject(1, ydmInList.getJudgeStoveNo());
             ps.setObject(2, ydmInList.getBatchNo());
             ps.setObject(3, ydmInList.getJudgeStoveNo());
             ps.setObject(4, ydmInList.getBatchNo());
             rs = ps.executeQuery();
             if (rs.next()) {
                 index = rs.getInt("MAX_SEQ");
             }
             rs.close();
             ps.close();
             //生成入库单号
             String inListDoc = "";
             sql = CoreXmlSqlParsersFactory.getSql("FrmSemiFinish.SelectMaxInDoc");
             ps = con.prepareStatement(sql);
             rs = ps.executeQuery();
             if (rs.next()) {
            	 inListDoc = rs.getString("INSTOCK_DOC");
             }
             rs.close();
             ps.close();
             //组号
             String groupNo = queryGroupNo(con, ydmInList.getJudgeStoveNo(), ydmInList.getBatchNo());
             
             // 新增物料SQL
             String sqlMatNo = CoreXmlSqlParsersFactory
                     .getSql("FrmSemiFinish.addMatZcM");
             // 新增位置SQL
             String sqlButtress = CoreXmlSqlParsersFactory
                     .getSql("FrmSemiFinish.addYdmZcButtress");
             // 新增入库SQL
             String sqlInlist = CoreXmlSqlParsersFactory
                     .getSql("FrmSemiFinish.addYdmZcInlist");
             //新增下线点实绩
             String sqlInMil = CoreXmlSqlParsersFactory.getSql("FrmSemiFinish.addMilInStore");
             
             //回写排产支数、重量
             String updatePlnOrderZgS = CoreXmlSqlParsersFactory.getSql("FrmSemiFinish.updatePlanOrderZgS");
             ArrayList<String> lengthList = null;
             if(Double.parseDouble(ydmInList.getActLen())>0)
             {
             	lengthList = new ArrayList<String>();
                 List<double[]> lenList = MeanValueCalculation.MeanCalculation(Double.parseDouble(ydmInList.getActLen()), Integer.parseInt(ydmInList.getActCount()));
                 for(int k = 0;k<lenList.size();k++)
                 {
                 	double[] conLen = lenList.get(k);
                 	if((int)conLen[0]>0)
                 	{
                 		for(int x = 0;x<(int)conLen[0];x++)
                 		{
                 			DecimalFormat dt = new DecimalFormat("0.000");
                 			lengthList.add(dt.format(conLen[1]));
                 		}
                 	}
                 }
             }
             
             
             int k = 0 ;
          // 循环支数
             for (int i = 0; i < list.size(); i++) {
                 double[] dataArr = list.get(i);
                 int dataArr1 = (int) dataArr[0];
                 if (dataArr1 > 0) {
                     for (int j = 0; j < dataArr1; j++) {
                    	 ydmInList.setActCount("1");
                    	 ydmInList.setActWeight(String.valueOf(dataArr[1]));
                    	 ydmInList.setActTheoryWeight(String.valueOf(dataArr[1]));
                    	 ydmInList.setBatchGroudNo(groupNo);
                    	 //ydmInList.setActLen(lengthList.get(k));
                    	 ydmInList.setProOrderNo(plnOrdZgS.getOrderNo()+ '/'+ plnOrdZgS.getOrderSeq());//+'/'+ plnOrdZgS.getDeliveryNo()
                    	 ydmInList.setProOrderId(plnOrdZgS.getProPlanId());
                    	 ydmInList.setOrderNo(plnOrdZgS.getOrderNo());
                    	 ydmInList.setOrderSeq(plnOrdZgS.getOrderSeq());
                    	 ydmInList.setDeliveryNo(plnOrdZgS.getDeliveryNo());
                    	 ydmInList.setOrdPk(plnOrdZgS.getOrdPk());
                    	 ydmInList.setOrdLnPk(plnOrdZgS.getOrdLnPk());
                    	 ydmInList.setOrdLnDlyPk(plnOrdZgS.getOrdLnDlyPk());
                    	 ydmInList.setCraftFileNo(plnOrdZgS.getCraftFileNo());
                    	 ydmInList.setCraftSeq(plnOrdZgS.getCraftSeq());
                    	 ydmInList.setCreateTime(systime);
                    	 ydmInList.setBalYearMonth(yearMoth);
                    	 ydmInList.setGxPlanNo(plnOrdZgS.getGxPlanNo());
                    	 ydmInList.setNextProcessCdoe(nextProcessCode);
                    	 ydmInList.setNextProcessName(nextProcessName);
                    	 
                    	 ydmInList.setFlagStoveNoZg(StringUtils.isEmpty(ydmInList.getFlagStoveNoZg())?ydmInList.getJudgeStoveNo():ydmInList.getFlagStoveNoZg());
                    	 ydmInList.setCic(plnOrdZgS.getCicGp());
                    	 if ((plnOrdZgS.getCicGp() + "+" + plnOrdZgS.getPic()
 								+ "+" + plnOrdZgS.getSic() + "+" + plnOrdZgS
 								.getDic()).equals("++++")) {
                    		 ydmInList.setJudgeStdName("");
                    		 ydmInList.setJudgeStdDes("");
 						} else {
 							ydmInList.setJudgeStdName(plnOrdZgS.getCicGp()
 									+ "+" + plnOrdZgS.getPic() + "+"
 									+ plnOrdZgS.getSic() + "+"
 									+ plnOrdZgS.getDic());
 							ydmInList.setJudgeStdDes(plnOrdZgS.getCicGp()
 									+ "+" + plnOrdZgS.getPic() + "+"
 									+ plnOrdZgS.getSic() + "+"
 									+ plnOrdZgS.getDic());
 						}
                         index++;
                         
                         String matNo = ydmInList.getJudgeStoveNo() 
                         + ydmInList.getBatchNo();
                         int maxSeq = doQueryMaxMatNo(ydmInList.getJudgeStoveNo(), ydmInList.getBatchNo());
                         matNo = (maxSeq > 0) ? matNo+strDf.format(maxSeq+index) : matNo+strDf.format(index);
                         //+ strDf.format(index);
                         
                         ydmInList.setMatNo(matNo);
                         //插入材料表
                         String sqlMatNostr = EntityTool.fillSqlByEntity(
                                 sqlMatNo, ydmInList);
                         ps = con.prepareStatement(sqlMatNostr);
                         ps.executeUpdate();
                         ps.close();
                         //插入位置表
                         ps = con.prepareStatement(sqlButtress);
                         ps.setObject(1, matNo);
                         ps.setObject(2, ydmInList.getJudgeStoveNo());
                         ps.setObject(3, ydmInList.getBatchNo());
                         ps.setObject(4, groupNo);
                         ps.setObject(5, ydmInList.getStorageNo());
                         ps.setObject(6, ydmInList.getLocationNo());
                         ps.setObject(7, ydmInList.getStorageAttr());
                         ps.setObject(8, ydmInList.getStorageAttrName());
                         ps.setObject(9, ydmInList.getStorageTypeNo());
                         ps.setObject(10, ydmInList.getStorageTypeName());
                         ps.setObject(11, ydmInList.getMemo());
                         ps.setObject(12, ydmInList.getCreateName());
                         ps.executeUpdate();
                         ps.close();
                         
                         String inListDocSeq = inListDoc + strDf.format(index);
                         //入库信息
                         ydmInList.setInstockSqe(inListDocSeq);
                         ydmInList.setInstockDoc(inListDoc);
                         ydmInList.setInstockTypeCode("800701");
                         ydmInList.setInstockTypeName("产出入库");
                         ydmInList.setProPlanId(plnOrdZgS.getProPlanId());
                    	 ydmInList.setGxPlanNo(plnOrdZgS.getGxPlanNo());
                         String sqlInlistStr = EntityTool.fillSqlByEntity(
                                 sqlInlist, ydmInList);
                         ps = con.prepareStatement(sqlInlistStr);
                         ps.executeUpdate();
                         ps.close();
                         k++;
                     }
                 }
              }
             
             sql = CoreXmlSqlParsersFactory.getSql("FrmSemiFinish.SelectMatBc");//查询半成品表
             sql = EntityTool.fillSqlByEntity(sql, ydmInList);
             ps = con.prepareStatement(sql);
             rs = ps.executeQuery();
             List<MatBcMEntity> matBcEntity = EntityTool.getEntitysByRs(rs, MatBcMEntity.class);
             rs.close();
             ps.close();
             
             for(int m = 0;m<allOrderS.size();m++)
        	 {
            	 double allOrderSWgt = Double.parseDouble(allOrderS.get(m).getWeigthS());//订单量
            	 double zyMWgt = Double.parseDouble(allOrderS.get(m)
							.getPlnInsingleWt().equals("") ? "0":allOrderS.get(m)
									.getPlnInsingleWt());//炉计划已挂订单量
            	 
				for (int n = 0; n < matBcEntity.size(); n++) {
					MatBcMEntity matBcTity = new MatBcMEntity();
					if(m + 1 == allOrderS.size())
					{
						matBcTity.setJudgeStoveNo(matBcEntity.get(n)
								.getJudgeStoveNo());
						matBcTity.setBatchNo(matBcEntity.get(n).getBatchNo());
						matBcTity.setMatNo(matBcEntity.get(n).getMatNo());
						matBcTity.setProPlanIdNext(allOrderS.get(m)
								.getProPlanId());
						matBcTity.setGxPlanNoNext(allOrderS.get(m)
 								.getGxPlanNo());
						String updateMatBcSql = CoreXmlSqlParsersFactory
								.getSql("FrmSemiFinish.UpdateMatBcPro");
						updateMatBcSql = EntityTool.fillSqlByEntity(
								updateMatBcSql, matBcTity);
						ps = con.prepareStatement(updateMatBcSql);
						ps.executeUpdate();
						ps.close();
					}else
					{
						if (allOrderSWgt > Double.parseDouble(matBcEntity.get(n).getActWeight())+ zyMWgt) {
							matBcTity.setJudgeStoveNo(matBcEntity.get(n)
									.getJudgeStoveNo());
							matBcTity.setBatchNo(matBcEntity.get(n).getBatchNo());
							matBcTity.setMatNo(matBcEntity.get(n).getMatNo());
							matBcTity.setProPlanIdNext(allOrderS.get(m)
									.getProPlanId());
							matBcTity.setGxPlanNoNext(allOrderS.get(m)
	 								.getGxPlanNo());
							String updateMatBcSql = CoreXmlSqlParsersFactory
									.getSql("FrmSemiFinish.UpdateMatBcPro");
							updateMatBcSql = EntityTool.fillSqlByEntity(
									updateMatBcSql, matBcTity);
							ps = con.prepareStatement(updateMatBcSql);
							ps.executeUpdate();
							ps.close();
							zyMWgt = zyMWgt + Double
							.parseDouble(matBcEntity.get(n).getActWeight());
						}
					}
				}
				PlanFurnProduction.addPlnFurnWg(allOrderS.get(m)
							.getProPlanId(), allOrderS.get(m)
							.getGxPlanNo(),
		         			ydmInList.getCreateName(), ydmInList.getJudgeStoveNo(), nextProcessCode,
		         			con);
             }
             
             
           //生成下线点实绩编号
             String resultNo = "";
             sql = CoreXmlSqlParsersFactory.getSql("FrmSemiFinish.SelectMaxresultNo");
             ps = con.prepareStatement(sql);
             rs = ps.executeQuery();
             if (rs.next()) {
            	 resultNo = rs.getString("RESULT_NO");
             }
             rs.close();
             ps.close();
             
             ydmInList.setResultNo(resultNo);
             ydmInList.setActCount(String.valueOf(actNum));
             ydmInList.setActWeight(String.valueOf(actWgt));
             ydmInList.setJudgeStoveNo(ydmInList.getJudgeStoveNo()+"-01");
             ydmInList.setProPlanId(plnOrdZgS.getProPlanId());
             ydmInList.setGxPlanNo(plnOrdZgS.getGxPlanNo());
             String insertInStoreSql = EntityTool.fillSqlByEntity(sqlInMil, ydmInList);
             ps = con.prepareStatement(insertInStoreSql);
             ps.executeUpdate();
             ps.close();
             
             plnOrdZgS.setFinishnum(String.valueOf(actNum));
             plnOrdZgS.setFinishweight(String.valueOf(actWgt));
             String updatePlnSql = EntityTool.fillSqlByEntity(updatePlnOrderZgS, plnOrdZgS);
             ps = con.prepareStatement(updatePlnSql);
             ps.executeUpdate();
             ps.close();
             
           

             
             
             
             core.setV_errMsg("入库成功!");
             con.commit();
	        }
	        catch (Exception e) {
	        	  core.setV_errMsg(e.getMessage());
	            e.printStackTrace();
	        }
	        finally {
	            if (con != null) {
	                try {
	                    con.close();
	                }
	                catch (SQLException e) {
	                    e.printStackTrace();
	                }
	            }
	        }
	        return core;
	}
	

	
	 /**
     * 根据炉号、批号自动组号
     * @param conn c
     * @param strLcode 传递参数
     * @return obj
     * @throws Exception 异常处理
     */
    public String queryGroupNo(Connection conn, String strLcode, String strBatch)
            throws Exception {
        int count = 0;
        String groupNo = "";
        PreparedStatement psta = null;
        String sqlLovsqe = CoreXmlSqlParsersFactory
                .getSql("FrmSemiFinish.queryGroupNo");
        psta = conn.prepareStatement(sqlLovsqe);
        psta.setString(1, strLcode);
        psta.setString(2, strBatch);
        psta.setString(3, strLcode);
        psta.setString(4, strBatch);
        ResultSet rs = psta.executeQuery();
        if (rs.next()) {

        	groupNo = rs.getString("BATCH_GROUD_NO");
        }
        rs.close();
        psta.close();
        return groupNo;
    }
    
    /***
     * 撤销手工入库
     * @param ydmZcInListTity
     * @return
     */
    public CoreReturnObject doCancelInList(String ydmZcInListTity)
    {
    	CoreReturnObject core = new CoreReturnObject();
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        String sql = "";
        int actCount = 0;
        try {
            con = this.getDao("TgDao").getConnection();
            con.setAutoCommit(false);
            YdmZcInlistEntity ydmInList = EntityTool.getEntityByJSONStr(ydmZcInListTity, YdmZcInlistEntity.class);
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmSemiFinish.SelectMatZcCount");
			ps = con.prepareStatement(sql);
			ps.setObject(1, ydmInList.getJudgeStoveNo());
			ps.setObject(2, ydmInList.getBatchNo());
			ps.setObject(3, ydmInList.getBatchGroudNo());
			rs = ps.executeQuery();
			if(rs.next())
			{
				actCount = Integer.parseInt(rs.getString("ACT_COUNT"));
			}
			ps.close();
			rs.close();
			if(actCount != Integer.parseInt(ydmInList.getActCount()))
			{
				core.setV_errMsg("库存支数已变化,不允许进行撤销!");
				return core;
			}
			
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmSemiFinish.SelectApplyMatZcCount");
			ps = con.prepareStatement(sql);
			ps.setObject(1, ydmInList.getJudgeStoveNo());
			ps.setObject(2, ydmInList.getBatchNo());
			ps.setObject(3, ydmInList.getBatchGroudNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				actCount = Integer.parseInt(rs.getString("APPLY_ACT_COUNT"));
			}
			ps.close();
			rs.close();
			if (actCount >0) {
				core.setV_errMsg("已有申请判定支数,不允许进行撤销!");
				return core;
			}


				PlanFurnProduction.deletePlnFurnWg(ydmInList.getProPlanId(),
						ydmInList.getJudgeStoveNo(),
						con);


            String cancelInListSql = CoreXmlSqlParsersFactory.getSql("FrmSemiFinish.doCancelInList");
            cancelInListSql = EntityTool.fillSqlByEntity(cancelInListSql, ydmInList);
            ps = con.prepareStatement(cancelInListSql);
            ps.executeUpdate();
            ps.close();
        	
            
            
            core.setV_errMsg("撤销成功!");
            con.commit();
        }
        catch (Exception e) {
			core.setV_errMsg(e.getMessage());
            e.printStackTrace();
        }
        finally {
            if (con != null) {
                try {
                    con.close();
                }
                catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
        return core;
    }
    /**
     * 查询是否存在同炉
     * @param jugeNo
     * @return
     */
    public CoreReturnObject doQueryJugdeCount(String jugeNo) {
		return this.getDataBySqlID("FrmSemiFinish.doQueryJugdeCount",
				new Object[] { jugeNo,jugeNo,jugeNo,jugeNo,jugeNo });
	}
    
    
    public int doQueryMaxMatNo(String stove_no,String batch_no){
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        String sql = "";
        int actCount = 0;
        try {
        	sql = CoreXmlSqlParsersFactory
					.getSql("FrmSemiFinish.getMaxMatNo");
        	con = this.getDao("TgDao").getConnection();
        	ps = con.prepareStatement(sql);
			ps.setObject(1, stove_no);
			ps.setObject(2, batch_no);
			ps.setObject(3, stove_no);
			ps.setObject(4, batch_no);
			rs = ps.executeQuery();
			if(rs.next())
			{
				actCount = Integer.parseInt(rs.getString("MAX_SEQ"));
			}
			ps.close();
			rs.close();
        }
        catch (Exception e) {
			return 0 ;
        }
        return  actCount;
        
    }
}
