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

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import weaver.common.StringUtil;
import weaver.conn.RecordSet;
import com.engine.kq.wfset.attendance.framework.BaseDao;
import com.engine.kq.wfset.attendance.domain.HrmAttProcFields;

/**
 * HrmAttProcFieldsDao
 * @author wcd
 * @version 1.0 2015-04-24
 */
public class HrmAttProcFieldsDao implements BaseDao<HrmAttProcFields> {

	//private RecordSet rs;

	public HrmAttProcFieldsDao() {
		//this.rs = new RecordSet();
	}

	public Comparable insert(HrmAttProcFields bean) {
		return -1;
	}

	public void update(HrmAttProcFields bean) {}

	public List<HrmAttProcFields> find(Map<String, Comparable> map) {
		RecordSet rs = new RecordSet();
		List<HrmAttProcFields> list = new ArrayList<HrmAttProcFields>();
		StringBuffer sql = new StringBuffer()
		.append(" select distinct t.id,t.mfid,t.field001,t.field002,t.field003,t.field004,t.field005,")
		.append(" t.field006,t.field007,t.field008,t.field009,t.field010,'' indexid,'' labelname,7 languageid")
		.append(" from kq_ATT_PROC_FIELDS t")
		.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("sql_id")){
				sql.append(" " + StringUtil.vString(map.get("sql_id")));
			}
			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("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("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("field009")){
				sql.append(" and t.field009 = ").append(StringUtil.vString(map.get("field009")));
			}
			if(map.containsKey("begin_field009")){
				sql.append(" and t.field009 >= ").append(StringUtil.vString(map.get("begin_field009")));
			}
			if(map.containsKey("end_field009")){
				sql.append(" and t.field009 < ").append(StringUtil.vString(map.get("end_field009")));
			}
			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")));
			}
			if(map.containsKey("begin_field010")){
				sql.append(" and t.field010 >= ").append(StringUtil.vString(map.get("begin_field010")));
			}
			if(map.containsKey("end_field010")){
				sql.append(" and t.field010 < ").append(StringUtil.vString(map.get("end_field010")));
			}
			if(map.containsKey("sql_field010")){
				sql.append(" " + StringUtil.vString(map.get("sql_field010")));
			}
			if(map.containsKey("field002")){
				sql.append(" and t.field002 = '").append(StringUtil.vString(map.get("field002"))).append("'");
			}
			if(map.containsKey("like_field002")){
				sql.append(" and t.field002 like '%").append(StringUtil.vString(map.get("like_field002"))).append("%'");
			}
			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"))).append("'");
			}
			if(map.containsKey("like_field003")){
				sql.append(" and t.field003 like '%").append(StringUtil.vString(map.get("like_field003"))).append("%'");
			}
			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"))).append("'");
			}
			if(map.containsKey("like_field004")){
				sql.append(" and t.field004 like '%").append(StringUtil.vString(map.get("like_field004"))).append("%'");
			}
			if(map.containsKey("sql_field004")){
				sql.append(" " + StringUtil.vString(map.get("sql_field004")));
			}
			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("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.field009, t.id ").append(StringUtil.vString(map.get("sqlsortway")).length() > 0 ? StringUtil.vString(map.get("sqlsortway")) : "desc");
			}
		}
		rs.executeSql(sql.toString());
		HrmAttProcFields bean = null;
		while(rs.next()){
			bean = new HrmAttProcFields();
			bean.setId(StringUtil.parseToLong(rs.getString("id")));
			bean.setMfid(StringUtil.parseToLong(rs.getString("mfid")));
			bean.setLabelName(StringUtil.vString(rs.getString("labelname")));
			bean.setLanguageid(StringUtil.parseToInt(rs.getString("languageid")));
			bean.setField001(StringUtil.parseToInt(rs.getString("field001")));
			bean.setField002(StringUtil.vString(rs.getString("field002")));
			bean.setField003(StringUtil.vString(rs.getString("field003")));
			bean.setField004(StringUtil.vString(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.parseToDouble(rs.getString("field009")));
			bean.setField010(StringUtil.parseToInt(rs.getString("field010")));
			list.add(bean);
		}
		return list;
	}

	public HrmAttProcFields get(Comparable id) {
		return null;
	}

	public void delete(Comparable id) {}

}
