package com.ekexiu.portal.dao;

import java.sql.Connection;
import java.sql.SQLException;

import org.jfw.apt.orm.annotation.dao.DAO;
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;

import com.ekexiu.portal.po.Professor;
import com.ekexiu.portal.po.Tidings;

@DAO
public abstract class TidingsDao {
	@Insert
	public abstract int insert(Connection con, Tidings tidings) throws SQLException;
	
	public com.ekexiu.portal.po.Tidings query(java.sql.Connection con,java.lang.String tidingsId) throws java.sql.SQLException{
        int _m_1 = 1;
        String sql = "SELECT TIDINGS_ID,TIDINGS_CONTANT,SENDER_ID,CONSULT_ID,TIDINGS.CREATE_TIME,PROFESSOR.NAME FROM TIDINGS LEFT JOIN PROFESSOR ON SENDER_ID = PROFESSOR.ID WHERE TIDINGS_ID = ?";
        java.sql.PreparedStatement ps = con.prepareStatement(sql);
        try{
            ps.setString(_m_1++,tidingsId);
            java.sql.ResultSet rs = ps.executeQuery();
            try{
                if(rs.next()){
                    com.ekexiu.portal.po.Tidings _result = new com.ekexiu.portal.po.Tidings();
                    _result.setTidingsId(rs.getString(1));
                    _result.setTidingsContant(rs.getString(2));
                    Professor professor = new Professor();
                    professor.setId(rs.getString(3));
                    _result.setConsultId(rs.getString(4));
                    _result.setCreateTime(rs.getString(5));
                    professor.setName(rs.getString(6));
                    _result.setProfessor(professor);
                    return _result;
                }else{
                    return null;
                }
            }finally{
                try{rs.close();}catch(Exception _m_2){}
            }
        }finally{
            try{ps.close();}catch(Exception _m_3){}
        }
    }
	
	public java.util.List<com.ekexiu.portal.po.Tidings> queryCon(java.sql.Connection con,java.lang.String consultId) throws java.sql.SQLException{
        int _m_1 = 1;
        String sql = "SELECT TIDINGS_ID,TIDINGS_CONTANT,SENDER_ID,TIDINGS.CONSULT_ID,TIDINGS.CREATE_TIME,PROFESSOR.NAME FROM TIDINGS LEFT JOIN PROFESSOR ON SENDER_ID = PROFESSOR.ID WHERE TIDINGS.CONSULT_ID = ? ORDER BY TIDINGS.CREATE_TIME";
        java.sql.PreparedStatement ps = con.prepareStatement(sql);
        try{
            ps.setString(_m_1++,consultId);
            java.sql.ResultSet rs = ps.executeQuery();
            try{
                java.util.List<com.ekexiu.portal.po.Tidings> _result = new java.util.ArrayList<com.ekexiu.portal.po.Tidings>();
                while(rs.next()){
                    com.ekexiu.portal.po.Tidings _obj =  new com.ekexiu.portal.po.Tidings();
                    _obj.setTidingsId(rs.getString(1));
                    _obj.setTidingsContant(rs.getString(2));
                    Professor professor = new Professor();
                    professor.setId(rs.getString(3));
                    _obj.setConsultId(rs.getString(4));
                    _obj.setCreateTime(rs.getString(5));
                    professor.setName(rs.getString(6));
                    _obj.setProfessor(professor);
                    _result.add(_obj);
                }
                return _result;
            }finally{
                try{rs.close();}catch(Exception _m_2){}
            }
        }finally{
            try{ps.close();}catch(Exception _m_3){}
        }
    }
	
}
