package com.yhcj.Dao.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.yhcj.Dao.Project;
import com.yhcj.Dao.ProjectInfo;
import com.yhcj.enity.ProAndReviewObject;
import com.yhcj.enity.ProRevObject;
import com.yhcj.enity.ProStuTeaAndRev;
import com.yhcj.enity.ProjectInfoObject;
import com.yhcj.enity.ProjectObject;
import com.yhcj.enity.UserObject;
import com.yhcj.utils.DBUtil;
public class ProjectInfoImpl extends DBUtil implements ProjectInfo {
@Override
public int getCount() {
Connection conn=null;
Statement statement = null;
ResultSet resultSet = null;
try {
conn=getConn();
statement = conn.createStatement();
//查询学生信息
String sqlForAllProInfo = "select count(*) from project";
System.out.println(sqlForAllProInfo);
resultSet = statement.executeQuery(sqlForAllProInfo);
if(resultSet.next()) {
System.out.println(resultSet.getInt(1)+"");
return resultSet.getInt(1);
}else {
return 0;
}
}catch(Exception e) {
e.printStackTrace();
return 0;
}
finally{
closeConn(resultSet,statement, conn);
}
}
@Override
public List<ProjectInfoObject> findAllProInfo(String pageNum, String pageSize) {
// TODO Auto-generated method stub
Connection conn=null;
Statement statement = null;
Statement statementLeader = null;
Statement statementTea = null;
ResultSet resultSet = null;
ResultSet resultSetLeader = null;
ResultSet resultSetTea = null;
// System.out.println(proId);
int numer = Integer.parseInt(pageNum);
int size = Integer.parseInt(pageSize);
try {
conn=getConn();
statement = conn.createStatement();
String sqlForAllPro = "select * from project limit "+(numer-1)*size+","+size+";";
// System.out.println(sqlForAllPro);
resultSet = statement.executeQuery(sqlForAllPro);
if(resultSet != null) {
// System.out.println(sqlForAllPro);
List<ProjectInfoObject> proInfoList = new ArrayList<ProjectInfoObject>();
while(resultSet.next()) {
System.out.println(sqlForAllPro);
ProjectObject proObj = new ProjectObject();
UserObject teaObj = new UserObject();
UserObject leaderObj = new UserObject();
// 项目信息
proObj.setPro_id(resultSet.getString("project_id"));
proObj.setPro_name(resultSet.getString("project_name"));
proObj.setPro_status(resultSet.getString("project_status"));
Project findActNum = new ProjectImpl();
int num = findActNum.projectActNumber(proObj.getPro_id());
proObj.setAct_num(num+"");
System.out.println("实际人数"+ proObj.getAct_num());
proObj.setStart_year(resultSet.getString("start_year"));
proObj.setPlan_num(resultSet.getString("plan_number"));
proObj.setPro_principal_id(resultSet.getString("project_principal_id"));
proObj.setPro_teacher_id(resultSet.getString("project_teacher_id"));
proObj.setPro_state(resultSet.getString("project_state"));
// 负责人信息
statementLeader = conn.createStatement();
String leaderId = proObj.getPro_principal_id();
String sqlLeader = "select user_id,user_name,user_mail,user_phone from user where user_id = '" + leaderId + "';";
resultSetLeader = statementLeader.executeQuery(sqlLeader);
if(resultSetLeader.next()) {
// 负责人信息
leaderObj.setUser_id(resultSetLeader.getString("user_id"));
leaderObj.setUser_name(resultSetLeader.getString("user_name"));
leaderObj.setUser_mail(resultSetLeader.getString("user_mail"));
leaderObj.setUser_phone(resultSetLeader.getString("user_phone"));
}
statementTea = conn.createStatement();
// 教师信息
String teaId = proObj.getPro_teacher_id();
String sqlTea = "select user_id,user_name,user_mail,user_phone from user where user_id = '" + teaId + "';";
resultSetTea = statementTea.executeQuery(sqlTea);
if(resultSetTea.next()) {
// 负责人信息
teaObj.setUser_id(resultSetTea.getString("user_id"));
teaObj.setUser_name(resultSetTea.getString("user_name"));
teaObj.setUser_mail(resultSetTea.getString("user_mail"));
teaObj.setUser_phone(resultSetTea.getString("user_phone"));
}
//项目学生老师对象
ProjectInfoObject proInfo = new ProjectInfoObject();
proInfo.setProObj(proObj);
proInfo.setLeaderObj(leaderObj);
proInfo.setTeaObj(teaObj);
proInfoList.add(proInfo);
}
return proInfoList;
}else {
//用户不存在
return null;
}
}catch(Exception e) {
e.printStackTrace();
return null;
}
finally{
closeConn(resultSet,statement, conn);
closeConn(resultSetLeader,statementLeader, conn);
closeConn(resultSetTea,statementTea, conn);
}
}
@Override
public ProjectInfoObject findProInfoById(String proId) {
// TODO Auto-generated method stub
Connection conn=null;
Statement statement = null;
Statement statementLeader = null;
Statement statementTea = null;
Statement statementProAndRev = null;
Statement statementRev = null;
ResultSet resultSet = null;
ResultSet resultSetLeader = null;
ResultSet resultSetTea = null;
ResultSet resultSetProAndRev = null;
ResultSet resultSetRev = null;
System.out.println(proId);
try {
conn=getConn();
statement = conn.createStatement();
ProjectObject proObj = new ProjectObject();
UserObject leaderObj = new UserObject();
UserObject teaObj = new UserObject();
ProAndReviewObject reviewObj = new ProAndReviewObject();
// 项目
String sqlPro = "select * from project where project_id = '" + proId + "';";
System.out.println(sqlPro);
resultSet = statement.executeQuery(sqlPro);
if(resultSet.next()) {
proObj.setPro_name(resultSet.getString("project_name"));
proObj.setPro_status(resultSet.getString("project_status"));
Project findActNum = new ProjectImpl();
int num = findActNum.projectActNumber(proObj.getPro_id());
proObj.setAct_num(num+"");
System.out.println("实际人数"+ proObj.getAct_num());
proObj.setPlan_num(resultSet.getString("plan_number"));
proObj.setStart_year(resultSet.getString("start_year"));
proObj.setFinish_year(resultSet.getString("finish_year"));
proObj.setPro_principal_id(resultSet.getString("project_principal_id"));
proObj.setPro_teacher_id(resultSet.getString("project_teacher_id"));
proObj.setPro_state(resultSet.getString("project_state"));
// 负责人
statementLeader = conn.createStatement();
String leaderId = proObj.getPro_principal_id();
String sqlStu = "select user_id,user_name,user_mail,user_phone from user where user_id = '" + leaderId + "';";
resultSetLeader = statementLeader.executeQuery(sqlStu);
if(resultSetLeader.next()) {
leaderObj.setUser_id(resultSetLeader.getString("user_id"));
leaderObj.setUser_name(resultSetLeader.getString("user_name"));
leaderObj.setUser_mail(resultSetLeader.getString("user_mail"));
leaderObj.setUser_phone(resultSetLeader.getString("user_phone"));
}
// 教师
statementTea = conn.createStatement();
String teaId = proObj.getPro_teacher_id();
String sqlTea = "select user_id,user_name,user_mail,user_phone from user where user_id = '" + teaId + "';";
resultSetTea = statementTea.executeQuery(sqlTea);
if(resultSetTea.next()) {
teaObj.setUser_id(resultSetTea.getString("user_id"));
teaObj.setUser_name(resultSetTea.getString("user_name"));
teaObj.setUser_mai