package com.engine.kq.wfset.attendance.dao;

import com.engine.kq.cmd.hrmAttProcSet.KqTempletEnum;
import com.engine.kq.wfset.attendance.domain.HrmAttProcSet;
import com.engine.kq.wfset.attendance.framework.BaseConnection;
import com.engine.kq.wfset.attendance.framework.BaseDao;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import weaver.common.StringUtil;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.common.database.dialect.DbDialectFactory;
import weaver.hrm.common.database.dialect.DialectUtil;

/**
 * HrmAttProcSetDao
 * @author wcd
 * @version 1.0 2015-04-23
 */
public class HrmAttProcSetDao extends BaseConnection implements BaseDao<HrmAttProcSet> {

	public Comparable insert(HrmAttProcSet bean) {
    RecordSet rs = new RecordSet();
		String id = "-1";
		if(bean == null) return id;
		StringBuffer sql = new StringBuffer()
		.append(" insert into kq_ATT_PROC_SET (field001,field002,field003,field004,field005,field006,")
		.append(" field007,field008,field009,field010,field011,field012,")
		.append(" field013,field014,field015,mfid,ishalfday,usedetail,templetfile,templetmobilefile,templetroute,tablename,detailtablename,flow_deduct_card )")
		.append(" values("+bean.getField001()+","+bean.getField002()+","+bean.getField003()+","+bean.getField004()+",")
		.append(" "+bean.getField005()+","+bean.getField006()+","+bean.getField007()+",'"+bean.getField008()+"',")
		.append(" '"+bean.getField009()+"','"+bean.getField010()+"','"+bean.getField011()+"','"+bean.getField012()+"',")
		.append(" '"+bean.getField013()+"',"+bean.getField014()+","+bean.getField015()+","+bean.getMfid()+","+bean.getIsHalfDay()+","+bean.getUsedetail()+", ")
    .append(" '"+bean.getTempletfile()+"','"+bean.getTempletmobilefile()+"','"+bean.getTempletroute()+"','"+bean.getTablename()+"','"+bean.getDetailtablename()+"',"+bean.getFlow_deduct_card()+" )");
		rs.executeSql(sql.toString());
		rs.executeSql("select id from kq_ATT_PROC_SET where mfid = '"+bean.getMfid()+"'");
		return rs.next() ? rs.getString(1) : id;
	}

	public void update(HrmAttProcSet bean) {
    RecordSet rs = new RecordSet();
		if(bean == null) return;
		StringBuffer sql = new StringBuffer()
		.append(" update kq_ATT_PROC_SET set")
		.append(" field001 = "+bean.getField001()+",field002 = "+bean.getField002()+",field003 = "+bean.getField003()+",")
		.append(" field004 = "+bean.getField004()+",field005 = "+bean.getField005()+",field006 = "+bean.getField006()+",")
		.append(" field007 = "+bean.getField007()+",field008 = '"+bean.getField008()+"',field009 = '"+bean.getField009()+"',")
		.append(" field010 = '"+bean.getField010()+"',field011 = '"+bean.getField011()+"',field012 = '"+bean.getField012()+"',")
		.append(" field013 = '"+bean.getField013()+"',field014 = "+bean.getField014()+",field015 = "+bean.getField015()+",")
		.append(" mfid = "+bean.getMfid()+",ishalfday= "+bean.getIsHalfDay()+",usedetail="+bean.getUsedetail()+",")
		.append(" tablename = '"+bean.getTablename()+"',detailtablename= '"+bean.getDetailtablename()+"',")
    .append(" templetfile='"+bean.getTempletfile()+"',templetmobilefile='"+bean.getTempletmobilefile()+"',templetroute='"+bean.getTempletroute()+"'")
     .append(" ,flow_deduct_card="+bean.getFlow_deduct_card())
		.append(" where id = "+bean.getId()+"");
		rs.executeSql(sql.toString());
	}

	public List<HrmAttProcSet> find(Map<String, Comparable> map) {
    RecordSet rs = new RecordSet();
		List<HrmAttProcSet> list = new ArrayList<HrmAttProcSet>();
		StringBuffer sql = new StringBuffer()
		.append(" select t.id,t.field001,t.field002,t.field003,t.field004,t.field005,t.field006,")
		.append(" t.field007,t.field008,t.field009,t.field010,t.field011,t.field012,")
		.append(" t.field013,t.field014,t.field015,t.ishalfday,t.usedetail,t.flow_deduct_card,t.templetfile,t.templetmobilefile,t.templetroute,b.from_module_ as field016,t.mfid,w.formid,b.tablename,t.detailtablename ")
		.append(" from kq_ATT_PROC_SET t left join workflow_base w on t.field001 = w.id left join workflow_bill b on w.formid = b.id")
		.append(" where  1 = 1");
		if(map != null) {
			if(map.containsKey("id")){
				sql.append(" and t.id = ").append(StringUtil.vString(map.get("id")));
			}
			if(map.containsKey("begin_id")){
				sql.append(" and t.id >= ").append(StringUtil.vString(map.get("begin_id")));
			}
			if(map.containsKey("end_id")){
				sql.append(" and t.id < ").append(StringUtil.vString(map.get("end_id")));
			}
			if(map.containsKey("ishalfday")){
				sql.append(" and t.ishalfday = ").append(StringUtil.vString(map.get("ishalfday")));
			}
			if(map.containsKey("begin_ishalfday")){
				sql.append(" and t.ishalfday >= ").append(StringUtil.vString(map.get("begin_ishalfday")));
			}
			if(map.containsKey("end_ishalfday")){
				sql.append(" and t.ishalfday < ").append(StringUtil.vString(map.get("end_ishalfday")));
			}
			if(map.containsKey("sql_id")){
				sql.append(" " + StringUtil.vString(map.get("sql_id")));
			}
			if(map.containsKey("field001")){
				sql.append(" and t.field001 = ").append(StringUtil.vString(map.get("field001")));
			}
			if(map.containsKey("begin_field001")){
				sql.append(" and t.field001 >= ").append(StringUtil.vString(map.get("begin_field001")));
			}
			if(map.containsKey("end_field001")){
				sql.append(" and t.field001 < ").append(StringUtil.vString(map.get("end_field001")));
			}
			if(map.containsKey("sql_field001")){
				sql.append(" " + StringUtil.vString(map.get("sql_field001")));
			}
			if(map.containsKey("field002")){
				sql.append(" and t.field002 = ").append(StringUtil.vString(map.get("field002")));
			}
			if(map.containsKey("begin_field002")){
				sql.append(" and t.field002 >= ").append(StringUtil.vString(map.get("begin_field002")));
			}
			if(map.containsKey("end_field002")){
				sql.append(" and t.field002 < ").append(StringUtil.vString(map.get("end_field002")));
			}
			if(map.containsKey("sql_field002")){
				sql.append(" " + StringUtil.vString(map.get("sql_field002")));
			}
			if(map.containsKey("field003")){
				sql.append(" and t.field003 = ").append(StringUtil.vString(map.get("field003")));
			}
			if(map.containsKey("begin_field003")){
				sql.append(" and t.field003 >= ").append(StringUtil.vString(map.get("begin_field003")));
			}
			if(map.containsKey("end_field003")){
				sql.append(" and t.field003 < ").append(StringUtil.vString(map.get("end_field003")));
			}
			if(map.containsKey("sql_field003")){
				sql.append(" " + StringUtil.vString(map.get("sql_field003")));
			}
			if(map.containsKey("field004")){
				sql.append(" and t.field004 = ").append(StringUtil.vString(map.get("field004")));
			}
			if(map.containsKey("begin_field004")){
				sql.append(" and t.field004 >= ").append(StringUtil.vString(map.get("begin_field004")));
			}
			if(map.containsKey("end_field004")){
				sql.append(" and t.field004 < ").append(StringUtil.vString(map.get("end_field004")));
			}
			if(map.containsKey("sql_field004")){
				sql.append(" " + StringUtil.vString(map.get("sql_field004")));
			}
			if(map.containsKey("field005")){
				sql.append(" and t.field005 = ").append(StringUtil.vString(map.get("field005")));
			}
			if(map.containsKey("begin_field005")){
				sql.append(" and t.field005 >= ").append(StringUtil.vString(map.get("begin_field005")));
			}
			if(map.containsKey("end_field005")){
				sql.append(" and t.field005 < ").append(StringUtil.vString(map.get("end_field005")));
			}
			if(map.containsKey("sql_field005")){
				sql.append(" " + StringUtil.vString(map.get("sql_field005")));
			}
			if(map.containsKey("field006")){
				sql.append(" and t.field006 = ").append(StringUtil.vString(map.get("field006")));
			}
			if(map.containsKey("begin_field006")){
				sql.append(" and t.field006 >= ").append(StringUtil.vString(map.get("begin_field006")));
			}
			if(map.containsKey("end_field006")){
				sql.append(" and t.field006 < ").append(StringUtil.vString(map.get("end_field006")));
			}
			if(map.containsKey("sql_field006")){
				sql.append(" " + StringUtil.vString(map.get("sql_field006")));
			}
			if(map.containsKey("field007")){
				sql.append(" and t.field007 = ").append(StringUtil.vString(map.get("field007")));
			}
			if(map.containsKey("begin_field007")){
				sql.append(" and t.field007 >= ").append(StringUtil.vString(map.get("begin_field007")));
			}
			if(map.containsKey("end_field007")){
				sql.append(" and t.field007 < ").append(StringUtil.vString(map.get("end_field007")));
			}
			if(map.containsKey("sql_field007")){
				sql.append(" " + StringUtil.vString(map.get("sql_field007")));
			}
			if(map.containsKey("field014")){
				sql.append(" and t.field014 = ").append(StringUtil.vString(map.get("field014")));
			}
			if(map.containsKey("begin_field014")){
				sql.append(" and t.field014 >= ").append(StringUtil.vString(map.get("begin_field014")));
			}
			if(map.containsKey("end_field014")){
				sql.append(" and t.field014 < ").append(StringUtil.vString(map.get("end_field014")));
			}
			if(map.containsKey("sql_field014")){
				sql.append(" " + StringUtil.vString(map.get("sql_field014")));
			}
			if(map.containsKey("field015")){
				sql.append(" and t.field015 = ").append(StringUtil.vString(map.get("field015")));
			}
			if(map.containsKey("begin_field015")){
				sql.append(" and t.field015 >= ").append(StringUtil.vString(map.get("begin_field015")));
			}
			if(map.containsKey("end_field015")){
				sql.append(" and t.field015 < ").append(StringUtil.vString(map.get("end_field015")));
			}
			if(map.containsKey("sql_field015")){
				sql.append(" " + StringUtil.vString(map.get("sql_field015")));
			}
			if(map.containsKey("mfid")){
				sql.append(" and t.mfid = ").append(StringUtil.vString(map.get("mfid")));
			}
			if(map.containsKey("begin_mfid")){
				sql.append(" and t.mfid >= ").append(StringUtil.vString(map.get("begin_mfid")));
			}
			if(map.containsKey("end_mfid")){
				sql.append(" and t.mfid < ").append(StringUtil.vString(map.get("end_mfid")));
			}
			if(map.containsKey("sql_mfid")){
				sql.append(" " + StringUtil.vString(map.get("sql_mfid")));
			}
			if(map.containsKey("field008")){
				sql.append(" and t.field008 = '").append(StringUtil.vString(map.get("field008"))).append("'");
			}
			if(map.containsKey("like_field008")){
				sql.append(" and t.field008 like '%").append(StringUtil.vString(map.get("like_field008"))).append("%'");
			}
			if(map.containsKey("sql_field008")){
				sql.append(" " + StringUtil.vString(map.get("sql_field008")));
			}
			if(map.containsKey("field009")){
				sql.append(" and t.field009 = '").append(StringUtil.vString(map.get("field009"))).append("'");
			}
			if(map.containsKey("like_field009")){
				sql.append(" and t.field009 like '%").append(StringUtil.vString(map.get("like_field009"))).append("%'");
			}
			if(map.containsKey("sql_field009")){
				sql.append(" " + StringUtil.vString(map.get("sql_field009")));
			}
			if(map.containsKey("field010")){
				sql.append(" and t.field010 = '").append(StringUtil.vString(map.get("field010"))).append("'");
			}
			if(map.containsKey("like_field010")){
				sql.append(" and t.field010 like '%").append(StringUtil.vString(map.get("like_field010"))).append("%'");
			}
			if(map.containsKey("sql_field010")){
				sql.append(" " + StringUtil.vString(map.get("sql_field010")));
			}
			if(map.containsKey("field011")){
				sql.append(" and t.field011 = '").append(StringUtil.vString(map.get("field011"))).append("'");
			}
			if(map.containsKey("like_field011")){
				sql.append(" and t.field011 like '%").append(StringUtil.vString(map.get("like_field011"))).append("%'");
			}
			if(map.containsKey("sql_field011")){
				sql.append(" " + StringUtil.vString(map.get("sql_field011")));
			}
			if(map.containsKey("field012")){
				sql.append(" and t.field012 = '").append(StringUtil.vString(map.get("field012"))).append("'");
			}
			if(map.containsKey("like_field012")){
				sql.append(" and t.field012 like '%").append(StringUtil.vString(map.get("like_field012"))).append("%'");
			}
			if(map.containsKey("sql_field012")){
				sql.append(" " + StringUtil.vString(map.get("sql_field012")));
			}
			if(map.containsKey("field013")){
				sql.append(" and t.field013 = '").append(StringUtil.vString(map.get("field013"))).append("'");
			}
			if(map.containsKey("like_field013")){
				sql.append(" and t.field013 like '%").append(StringUtil.vString(map.get("like_field013"))).append("%'");
			}
			if(map.containsKey("sql_field013")){
				sql.append(" " + StringUtil.vString(map.get("sql_field013")));
			}

      if(map.containsKey("usedetail")){
        sql.append(" and t.usedetail = ").append(StringUtil.vString(map.get("usedetail")));
      }
      if(map.containsKey("begin_usedetail")){
        sql.append(" and t.usedetail >= ").append(StringUtil.vString(map.get("begin_usedetail")));
      }
      if(map.containsKey("end_usedetail")){
        sql.append(" and t.usedetail < ").append(StringUtil.vString(map.get("end_usedetail")));
      }
      if(map.containsKey("sql_usedetail")){
        sql.append(" " + StringUtil.vString(map.get("sql_usedetail")));
      }

      if(map.containsKey("flow_deduct_card")){
        sql.append(" and t.flow_deduct_card = ").append(StringUtil.vString(map.get("flow_deduct_card")));
      }
      if(map.containsKey("begin_flow_deduct_card")){
        sql.append(" and t.flow_deduct_card >= ").append(StringUtil.vString(map.get("begin_flow_deduct_card")));
      }
      if(map.containsKey("end_flow_deduct_card")){
        sql.append(" and t.flow_deduct_card < ").append(StringUtil.vString(map.get("end_flow_deduct_card")));
      }
      if(map.containsKey("sql_flow_deduct_card")){
        sql.append(" " + StringUtil.vString(map.get("sql_flow_deduct_card")));
      }

			if(map.containsKey("mfsql")){
				sql.append(" " + StringUtil.vString(map.get("mfsql")));
			}
			if(map.containsKey("sqlorderby")){
				sql.append(" order by " + StringUtil.vString(map.get("sqlorderby")));
			}else{
				sql.append(" order by t.id ").append(StringUtil.vString(map.get("sqlsortway")).length() > 0 ? StringUtil.vString(map.get("sqlsortway")) : "desc");
			}
		}
		rs.executeSql(sql.toString());
		HrmAttProcSet bean = null;
		while(rs.next()){
			bean = new HrmAttProcSet();
			bean.setId(StringUtil.parseToLong(rs.getString("id")));
			bean.setField001(StringUtil.parseToInt(rs.getString("field001")));
			bean.setField002(StringUtil.parseToInt(rs.getString("field002")));
			bean.setField003(StringUtil.parseToInt(rs.getString("field003")));
			bean.setField004(StringUtil.parseToInt(rs.getString("field004")));
			bean.setField005(StringUtil.parseToInt(rs.getString("field005")));
			bean.setField006(StringUtil.parseToInt(rs.getString("field006")));
			bean.setField007(StringUtil.parseToInt(rs.getString("field007")));
			bean.setField008(StringUtil.vString(rs.getString("field008")));
			bean.setField009(StringUtil.vString(rs.getString("field009")));
			bean.setField010(StringUtil.vString(rs.getString("field010")));
			bean.setField011(StringUtil.vString(rs.getString("field011")));
			bean.setField012(StringUtil.vString(rs.getString("field012")));
			bean.setField013(StringUtil.vString(rs.getString("field013")));
			bean.setField014(StringUtil.parseToInt(rs.getString("field014")));
			bean.setField015(StringUtil.parseToInt(rs.getString("field015")));
			bean.setHAF(bean.getField003() == 1 || StringUtil.vString(rs.getString("field016")).equalsIgnoreCase("hrm_mf"));
			bean.setMfid(StringUtil.parseToLong(rs.getString("mfid")));
			bean.setFormid(StringUtil.parseToInt(rs.getString("formid")));
			bean.setTablename(StringUtil.vString(rs.getString("tablename")));
			bean.setDetailtablename(StringUtil.vString(rs.getString("detailtablename")));
			bean.setIsHalfDay((StringUtil.parseToInt(rs.getString("ishalfday"))));
			bean.setUsedetail(StringUtil.parseToInt(rs.getString("usedetail")));
			bean.setFlow_deduct_card(StringUtil.parseToInt(rs.getString("flow_deduct_card")));
			bean.setTempletfile(StringUtil.vString(rs.getString("templetfile")));
      bean.setTempletmobilefile(StringUtil.vString(rs.getString("templetmobilefile")));
      bean.setTempletroute(StringUtil.vString(rs.getString("templetroute")));
			list.add(bean);
		}
		return list;
	}

	public HrmAttProcSet get(Comparable id) {
		HrmAttProcSet bean = null;
		Map<String, Comparable> map = new HashMap<String, Comparable>();
		map.put("id", id);
		List<HrmAttProcSet> list = find(map);
		if(list != null && list.size() > 0){
			bean = list.get(0);
		}
		return bean;
	}

	@Override
  public void delete(Comparable id) {
    RecordSet rs = new RecordSet();
		rs.executeSql(new StringBuffer("update workflow_base set custompage = '', custompage4Emoble = '' where id in (select field001 from kq_ATT_PROC_SET where id in (").append(id).append("))").toString());
		rs.executeSql("delete from kq_ATT_PROC_SET where id in ( "+id+" )");
	}
	
	public List<HrmAttProcSet> getByField006(int field006, boolean field005, String id,String usedetail) {
    RecordSet rs = new RecordSet();
		List<HrmAttProcSet> list = new ArrayList<HrmAttProcSet>();
		String pField = "";
		if(rs.getDBType().equalsIgnoreCase("oracle")) {
			pField = "(case when t.field004 is null then t.field002||'_temp' else t.field004 end) pField";
		}else if(DialectUtil.isMySql(rs.getDBType())){
			String concat = DbDialectFactory.get(rs.getDBType()).concatStr("t.field002", "'_temp'") ;
			pField = "(case when (t.field004 is null or t.field004 = '') then "+concat+" else t.field004 end) pField";
		}else if(rs.getDBType().equalsIgnoreCase("postgresql")){
			pField = "(case when (t.field004 is null or t.field004 = '') then t.field002||'_temp' else t.field004 end) pField";
		} else {
			pField = "(case when (t.field004 is null or t.field004 = '') then t.field002+'_temp' else t.field004 end) pField";
		}
		String sqlwhere = " where 1=1 ";
		if(!StringUtil.isNull(id)){
      sqlwhere += " and t.id in ("+id+")";
    }
		if(!StringUtil.isNull(usedetail)){
      sqlwhere += " and t.usedetail = '"+usedetail+"'";
    }

		StringBuffer sql = new StringBuffer("select * from (select t.id, t.tablename,").append(pField).append(",t.field002 as oField,wfid,usedetail,detailtablename")
		.append(" from (select ").append(StringUtil.isNull(id) ? "min(a.id) id" : "a.id").append(", a.tablename,min(c.field004) as field004,d.field002,a.field001 as wfid,a.usedetail,a.detailtablename from kq_ATT_PROC_SET a ")
		.append(" left join kq_ATT_PROC_RELATION c on a.id = c.field001")
		.append(" left join kq_ATT_PROC_FIELDS d on c.field002 = d.id where a.field006 = ").append(field006).append(field005 ? " and a.field005 = 1" : "")
		.append(" and c.field004 is not null and d.field002 is not null group by ").append(StringUtil.isNull(id) ? "" : "a.id,").append("a.tablename,d.field002,a.field001,a.usedetail,a.detailtablename) t ) t")
		.append(sqlwhere)
		.append(" order by t.tablename,t.oField");
		rs.executeSql(sql.toString());
    kqLog.info("getByField006:"+sql.toString());
		
		HrmAttProcSet bean = null;
		while (rs.next()) {
			bean = new HrmAttProcSet();
			bean.setField001(rs.getInt("wfid"));
			bean.setId(StringUtil.parseToLong(rs.getString("id")));
			bean.setTablename(StringUtil.vString(rs.getString("tablename")));
			bean.setField010(StringUtil.vString(rs.getString("pField")));
			bean.setField011(StringUtil.vString(rs.getString("oField")));
			bean.setUsedetail(Util.getIntValue(rs.getString("usedetail")));
      bean.setDetailtablename(Util.null2String(rs.getString("detailtablename")));
			list.add(bean);
		}
		return list;
	}
	
	public void setCustomPage(int field001) {
		setCustomPage(field001, 0);
	}
	
	public void setCustomPage(int field001, int field006) {
    setCustomPage(field001, field006,"","","");
  }

	public void setCustomPage(int field001, int field006,String templetfile,String templetmobilefile,String templetroute) {
	  String new_custompage = "";
	  String new_custompage4Emoble = "";
    String new_templetroute = "";
	  switch (field006){
      case 0 :
        new_custompage = KqTempletEnum.LEAVE.getTempletfile();
        new_custompage4Emoble = KqTempletEnum.LEAVE.getTempletmobilefile();
        new_templetroute = KqTempletEnum.LEAVE.getTempletroute();
        break;
      case 1 :
        new_custompage = KqTempletEnum.EVECTION.getTempletfile();
        new_custompage4Emoble = KqTempletEnum.EVECTION.getTempletmobilefile();
        new_templetroute = KqTempletEnum.EVECTION.getTempletroute();
        break;
      case 2 :
        new_custompage = KqTempletEnum.OUT.getTempletfile();
        new_custompage4Emoble = KqTempletEnum.OUT.getTempletmobilefile();
        new_templetroute = KqTempletEnum.OUT.getTempletroute();
        break;
      case 3 :
        new_custompage = KqTempletEnum.OVERTIME.getTempletfile();
        new_custompage4Emoble = KqTempletEnum.OVERTIME.getTempletmobilefile();
        new_templetroute = KqTempletEnum.OVERTIME.getTempletroute();
        break;
      case 4 :
        new_custompage = KqTempletEnum.OTHER.getTempletfile();
        new_custompage4Emoble = KqTempletEnum.OTHER.getTempletmobilefile();
        new_templetroute = KqTempletEnum.OTHER.getTempletroute();
        break;
      case 5 :
        new_custompage = KqTempletEnum.SHIFT.getTempletfile();
        new_custompage4Emoble = KqTempletEnum.SHIFT.getTempletmobilefile();
        new_templetroute = KqTempletEnum.SHIFT.getTempletroute();
        break;
      case 6 :
        new_custompage = KqTempletEnum.LEAVEBACK.getTempletfile();
        new_custompage4Emoble = KqTempletEnum.LEAVEBACK.getTempletmobilefile();
        new_templetroute = KqTempletEnum.LEAVEBACK.getTempletroute();
        break;
      case 7 :
        new_custompage = KqTempletEnum.Card.getTempletfile();
        new_custompage4Emoble = KqTempletEnum.Card.getTempletmobilefile();
        new_templetroute = KqTempletEnum.Card.getTempletroute();
        break;
      case 8 :
        new_custompage = KqTempletEnum.PROCESSCHANGE.getTempletfile();
        new_custompage4Emoble = KqTempletEnum.PROCESSCHANGE.getTempletmobilefile();
        new_templetroute = KqTempletEnum.PROCESSCHANGE.getTempletroute();
        break;
      default:
        break;
    }
    if(templetfile.length() > 0){
	    new_custompage = templetfile;
    }
    if(templetmobilefile.length() > 0){
      new_custompage4Emoble = templetmobilefile;
    }
    RecordSet rs = new RecordSet();
//    new_templetroute 这个还不让修改
		rs.executeSql(new StringBuffer("update workflow_base set custompage = '"+new_templetroute+new_custompage+"', custompage4Emoble = '"+new_templetroute+(new_custompage4Emoble)+"' where id = "+field001).toString());
	}
	
	public int getWFStartNodeId(int wfId) {
    RecordSet rs = new RecordSet();
		StringBuffer sql = new StringBuffer("select a.nodeid from  workflow_flownode a left join workflow_nodebase b on a.nodeid = b.id")
		.append(" where a.workflowId = ").append(wfId).append(" and (b.isFreeNode != '1' OR b.isFreeNode IS null) and b.isstart =1 ");
		rs.executeSql(sql.toString());
		return rs.next() ? rs.getInt("nodeid") : -1;
	
	}
	public boolean hasFreezeNodeId(int wfId) {
    RecordSet rs = new RecordSet();
		StringBuffer sql = new StringBuffer(" select field006 from kq_ATT_PROC_ACTION where field001 in (select id from kq_ATT_PROC_SET where field001 = ").append(wfId).append(") and field002 = 'freeze' ");
		rs.executeSql(sql.toString());
		return rs.next() ? true : false;
	}
	public int getFreezeNodeType(int wfId) {
    RecordSet rs = new RecordSet();
		StringBuffer sql = new StringBuffer("select a.nodeType from  workflow_flownode a left join workflow_nodebase b on a.nodeid = b.id")
		.append(" where a.workflowId = ").append(wfId).append(" and (b.isFreeNode != '1' OR b.isFreeNode IS null) and a.nodeid in (")
		.append(" select field006 from kq_ATT_PROC_ACTION where field001 in (select id from kq_ATT_PROC_SET where field001 = ").append(wfId).append(") and field002 = 'freeze' ) order by b.nodeName asc");
		rs.executeSql(sql.toString());
    kqLog.info("getFreezeNodeType:"+sql.toString());
		return rs.next() ? rs.getInt("nodeType") : -1;
	}

}
