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.From;
import org.jfw.apt.orm.annotation.dao.method.operator.DeleteWith;
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
import org.jfw.apt.orm.annotation.dao.method.operator.Update;

import com.ekexiu.portal.po.Assess;
import com.ekexiu.portal.po.Professor;
import com.ekexiu.portal.po.Resource;

@DAO
public abstract class AssessDao {
	@Insert
	public abstract int insert(Connection con, Assess assess) throws SQLException;
	
	@Update
	public abstract int update(Connection con, Assess assess) throws SQLException;
	
	public com.ekexiu.portal.po.Assess query(java.sql.Connection con,java.lang.String assessId) throws java.sql.SQLException{
        int _m_1 = 1;
        String sql = "SELECT ASSESS_ID,STAR_LEVEL,ASSESS.DESCP,ASSESS.OPERATION_ID,ASSESS.RESOURCE_ID,"
        		+ " ASSESS.PROFESSOR_ID,RESOURCE_NAME,PROFESSOR.NAME,ASSESS.CREATE_TIME "
        		+ " FROM ASSESS INNER JOIN RESOURCE ON ASSESS.RESOURCE_ID = RESOURCE.RESOURCE_ID "
        		+ " INNER JOIN PROFESSOR ON ASSESS.PROFESSOR_ID = PROFESSOR.ID "
        		+ " WHERE ASSESS_ID = ?";
        java.sql.PreparedStatement ps = con.prepareStatement(sql);
        try{
            ps.setString(_m_1++,assessId);
            java.sql.ResultSet rs = ps.executeQuery();
            try{
                if(rs.next()){
                    com.ekexiu.portal.po.Assess _result = new com.ekexiu.portal.po.Assess();
                    _result.setAssessId(rs.getString(1));
                    _result.setStarLevel(rs.getInt(2));
                    java.lang.String _m_2 = rs.getString(3);
                    if(rs.wasNull()){
                        _m_2 = null;
                    }
                    _result.setDescp(_m_2);
                    _result.setOperationId(rs.getString(4));
                    Resource resource = new Resource();
                    resource.setResourceId(rs.getString(5));
                    Professor professor = new Professor();
                    professor.setId(rs.getString(6));
                    resource.setResourceName(rs.getString(7));
                    _result.setResource(resource);
                    professor.setName(rs.getString(8));
                    _result.setProfessor(professor);
                    _result.setCreateTime(rs.getString(9));
                    return _result;
                }else{
                    return null;
                }
            }finally{
                try{rs.close();}catch(Exception _m_3){}
            }
        }finally{
            try{ps.close();}catch(Exception _m_4){}
        }
    }
	
	public java.util.List<com.ekexiu.portal.po.Assess> queryOper(java.sql.Connection con,java.lang.String operationId) throws java.sql.SQLException{
        int _m_1 = 1;
        String sql = "SELECT ASSESS_ID,STAR_LEVEL,ASSESS.DESCP,ASSESS.OPERATION_ID,ASSESS.RESOURCE_ID,"
        		+ " ASSESS.PROFESSOR_ID,RESOURCE_NAME,PROFESSOR.NAME,ASSESS.CREATE_TIME "
        		+ " FROM ASSESS INNER JOIN RESOURCE ON ASSESS.RESOURCE_ID = RESOURCE.RESOURCE_ID "
        		+ " INNER JOIN PROFESSOR ON ASSESS.PROFESSOR_ID = PROFESSOR.ID "
        		+ " WHERE ASSESS.OPERATION_ID = ?";
        java.sql.PreparedStatement ps = con.prepareStatement(sql);
        try{
            ps.setString(_m_1++,operationId);
            java.sql.ResultSet rs = ps.executeQuery();
            try{
                java.util.List<com.ekexiu.portal.po.Assess> _result = new java.util.ArrayList<com.ekexiu.portal.po.Assess>();
                while(rs.next()){
                    com.ekexiu.portal.po.Assess _obj =  new com.ekexiu.portal.po.Assess();
                    _obj.setAssessId(rs.getString(1));
                    _obj.setStarLevel(rs.getInt(2));
                    java.lang.String _m_2 = rs.getString(3);
                    if(rs.wasNull()){
                        _m_2 = null;
                    }
                    _obj.setDescp(_m_2);
                    _obj.setOperationId(rs.getString(4));
                    Resource resource = new Resource();
                    resource.setResourceId(rs.getString(5));
                    Professor professor = new Professor();
                    professor.setId(rs.getString(6));
                    resource.setResourceName(rs.getString(7));
                    _obj.setResource(resource);
                    professor.setName(rs.getString(8));
                    _obj.setProfessor(professor);
                    _obj.setCreateTime(rs.getString(9));
                    _result.add(_obj);
                }
                return _result;
            }finally{
                try{rs.close();}catch(Exception _m_3){}
            }
        }finally{
            try{ps.close();}catch(Exception _m_4){}
        }
    }
	
	public java.util.List<com.ekexiu.portal.po.Assess> queryRes(java.sql.Connection con,java.lang.String resourceId) throws java.sql.SQLException{
        int _m_1 = 1;
        String sql = "SELECT ASSESS_ID,STAR_LEVEL,ASSESS.DESCP,ASSESS.OPERATION_ID,ASSESS.RESOURCE_ID,"
        		+ " ASSESS.PROFESSOR_ID,RESOURCE_NAME,PROFESSOR.NAME,ASSESS.CREATE_TIME "
        		+ " FROM ASSESS INNER JOIN RESOURCE ON ASSESS.RESOURCE_ID = RESOURCE.RESOURCE_ID "
        		+ " INNER JOIN PROFESSOR ON ASSESS.PROFESSOR_ID = PROFESSOR.ID "
        		+ " WHERE ASSESS.RESOURCE_ID = ?";
        java.sql.PreparedStatement ps = con.prepareStatement(sql);
        try{
            ps.setString(_m_1++,resourceId);
            java.sql.ResultSet rs = ps.executeQuery();
            try{
                java.util.List<com.ekexiu.portal.po.Assess> _result = new java.util.ArrayList<com.ekexiu.portal.po.Assess>();
                while(rs.next()){
                    com.ekexiu.portal.po.Assess _obj =  new com.ekexiu.portal.po.Assess();
                    _obj.setAssessId(rs.getString(1));
                    _obj.setStarLevel(rs.getInt(2));
                    java.lang.String _m_2 = rs.getString(3);
                    if(rs.wasNull()){
                        _m_2 = null;
                    }
                    _obj.setDescp(_m_2);
                    _obj.setOperationId(rs.getString(4));
                    Resource resource = new Resource();
                    resource.setResourceId(rs.getString(5));
                    Professor professor = new Professor();
                    professor.setId(rs.getString(6));
                    resource.setResourceName(rs.getString(7));
                    _obj.setResource(resource);
                    professor.setName(rs.getString(8));
                    _obj.setProfessor(professor);
                    _obj.setCreateTime(rs.getString(9));
                    _result.add(_obj);
                }
                return _result;
            }finally{
                try{rs.close();}catch(Exception _m_3){}
            }
        }finally{
            try{ps.close();}catch(Exception _m_4){}
        }
    }
	
	public java.util.List<com.ekexiu.portal.po.Assess> queryPro(java.sql.Connection con,java.lang.String professorId) throws java.sql.SQLException{
        int _m_1 = 1;
        String sql = "SELECT ASSESS_ID,STAR_LEVEL,ASSESS.DESCP,ASSESS.OPERATION_ID,ASSESS.RESOURCE_ID,"
        		+ " ASSESS.PROFESSOR_ID,RESOURCE_NAME,PROFESSOR.NAME,ASSESS.CREATE_TIME "
        		+ " FROM ASSESS INNER JOIN RESOURCE ON ASSESS.RESOURCE_ID = RESOURCE.RESOURCE_ID "
        		+ " INNER JOIN PROFESSOR ON ASSESS.PROFESSOR_ID = PROFESSOR.ID "
        		+ " WHERE ASSESS.PROFESSOR_ID = ?";
        java.sql.PreparedStatement ps = con.prepareStatement(sql);
        try{
            ps.setString(_m_1++,professorId);
            java.sql.ResultSet rs = ps.executeQuery();
            try{
                java.util.List<com.ekexiu.portal.po.Assess> _result = new java.util.ArrayList<com.ekexiu.portal.po.Assess>();
                while(rs.next()){
                    com.ekexiu.portal.po.Assess _obj =  new com.ekexiu.portal.po.Assess();
                    _obj.setAssessId(rs.getString(1));
                    _obj.setStarLevel(rs.getInt(2));
                    java.lang.String _m_2 = rs.getString(3);
                    if(rs.wasNull()){
                        _m_2 = null;
                    }
                    _obj.setDescp(_m_2);
                    _obj.setOperationId(rs.getString(4));
                    Resource resource = new Resource();
                    resource.setResourceId(rs.getString(5));
                    Professor professor = new Professor();
                    professor.setId(rs.getString(6));
                    resource.setResourceName(rs.getString(7));
                    _obj.setResource(resource);
                    professor.setName(rs.getString(8));
                    _obj.setProfessor(professor);
                    _obj.setCreateTime(rs.getString(9));
                    _result.add(_obj);
                }
                return _result;
            }finally{
                try{rs.close();}catch(Exception _m_3){}
            }
        }finally{
            try{ps.close();}catch(Exception _m_4){}
        }
    }
	
	@DeleteWith
	@From(Assess.class)
	public abstract int delete(Connection con, String assessId) throws SQLException;
	
	@DeleteWith
	@From(Assess.class)
	public abstract int deleteRes(Connection con, String resourceId) throws SQLException;
	
	@DeleteWith
	@From(Assess.class)
	public abstract int deletePro(Connection con, String professorId) throws SQLException;
	
}
