自己的一些TeacherService

来源:互联网 发布:js分割字符串包含转义 编辑:程序博客网 时间:2024/06/08 08:07

TeacherService


package com.neustu.service.teacher;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;

import com.neustu.bean.Answer;
import com.neustu.bean.Class_tab;
import com.neustu.bean.Course;
import com.neustu.bean.Problem;
import com.neustu.bean.Teacher;
import com.neustu.bean.Testpaper;
import com.neustu.dao.teacher.TeacherAnswerDao;
import com.neustu.dao.teacher.TeacherCourseDao;
import com.neustu.dao.teacher.TeacherClassDao;
import com.neustu.dao.teacher.TeacherDao;
import com.neustu.dao.teacher.TeacherProblemDao;
import com.neustu.dao.teacher.TeacherScDao;
import com.neustu.dao.teacher.TeacherTcDao;
import com.neustu.dao.teacher.TeacherTestPaperDao;
import com.neustu.dao.teacher.TeacherTpDao;
import com.neustu.utils.JDBCUtil;

public class TeacherService {

    public Teacher teacherLogin(String name, String pass) throws SQLException {
        Connection con = JDBCUtil.getCon();
        Teacher teacher = null;
        TeacherDao teadao = new TeacherDao();
        teacher = teadao.checkTeacherByNaPa(con,name,pass);
        JDBCUtil.closeCon(con);
        return teacher;
    }

    

    public ArrayList<Course> TeacherGetAllCourse(int i) throws SQLException {
        Connection con = JDBCUtil.getCon();
        ArrayList<Integer> courseid = new ArrayList<Integer>();
        TeacherTcDao teadao = new TeacherTcDao();
        try {
            courseid = teadao.teacherGetAllCourse(con,i);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        ArrayList<Course> courseList = new ArrayList<Course>();
        TeacherCourseDao coudao = new TeacherCourseDao();
        courseList = coudao.getAllCourse(con,courseid);
        JDBCUtil.closeCon(con);
        return courseList;
    }

    
    public ArrayList<Class_tab> teacherGetAllClass(int couid, int id) throws SQLException {
        Connection con = JDBCUtil.getCon();
        ArrayList<Integer> classid = new ArrayList<Integer>();
        ArrayList<Class_tab> classList = new ArrayList<Class_tab>();
        TeacherScDao teadao = new TeacherScDao();
        classid = teadao.teacherGetAllClass(con,couid,id);
        TeacherClassDao cladao = new TeacherClassDao();
        classList = cladao.teacherGetAllClass(con,classid);
        JDBCUtil.closeCon(con);
        return classList;
    }



    public Course teacherQueryCourse(int couid) throws SQLException {
        Connection con = JDBCUtil.getCon();
        TeacherCourseDao teadao = new TeacherCourseDao();
        Course course = teadao.getCourse(con, couid);
        JDBCUtil.closeCon(con);
        return course;
    }



    public String teacherDelClass(Integer classid,
            Integer courseid, Integer teacherid) throws SQLException {
        String flag = "";
        Connection con = JDBCUtil.getCon();
        TeacherScDao scdao = new TeacherScDao();
        flag = scdao.teacherDelClass(con,classid,courseid,teacherid);
        if("删除成功".equals(flag)){
            return flag;
        }else {
            return "删除失败";
        }
        
    }



    public ArrayList<Class_tab> teacherGetLeftClass(int couid, int id) throws SQLException {
        Connection con = JDBCUtil.getCon();
        ArrayList<Integer> allclassid = new ArrayList<Integer>();
        ArrayList<Integer> classid = new ArrayList<Integer>();
        ArrayList<Class_tab> classLeftList = new ArrayList<Class_tab>();
        TeacherScDao teadao = new TeacherScDao();
        TeacherClassDao classdao = new TeacherClassDao();
        classid = teadao.teacherGetAllClass(con,couid,id);
        allclassid = classdao.teacherGetAllClassId(con);
        for(int i=0;i<classid.size();i++){
            for(int j=0;j<allclassid.size();j++){
                if(allclassid.get(j)==classid.get(i)){
                    allclassid.remove(j);
                }
            }
        }
        TeacherClassDao cladao = new TeacherClassDao();
        classLeftList = cladao.teacherGetAllClass(con,allclassid);
        JDBCUtil.closeCon(con);
        return classLeftList;
    }



    public String teacherAddClass(int classid, int courseid, int teacherid) {
        Connection con = JDBCUtil.getCon();
        String flag = "";
        TeacherScDao teadao = new TeacherScDao();
        flag = teadao.teacherAddClass(con,classid,courseid,teacherid);
        JDBCUtil.closeCon(con);
        return flag;
    }



    public ArrayList<Problem> teacherGetAllPro(int couid) throws SQLException {
        Connection con = JDBCUtil.getCon();
        ArrayList<Problem> problems = new ArrayList<Problem>();
        TeacherProblemDao prodao = new TeacherProblemDao();
        problems = prodao.teacherGetAllPro(con,couid);
        JDBCUtil.closeCon(con);
        return problems;
    }



    


    public Problem teacherQueryPro(int problemid) throws SQLException {
        Connection con = JDBCUtil.getCon();
        Problem problem = new Problem();
        TeacherProblemDao prodao = new TeacherProblemDao();
        problem = prodao.teacherQueryPro(con,problemid);
        JDBCUtil.closeCon(con);
        return problem;
    }



    public Answer teacherQueryAnswer(int problemid) throws SQLException {
        Connection con = JDBCUtil.getCon();
        Answer answer = new Answer();
        TeacherProblemDao prodao = new TeacherProblemDao();
        int ansid = prodao.getAnswerId(con,problemid);
        TeacherAnswerDao ansdao = new TeacherAnswerDao();
        answer = ansdao.teacherQueryAnswer(con,ansid);
        JDBCUtil.closeCon(con);
        return answer;
    }



    public String teacherEditPro(Problem problem, int courseId) throws SQLException {
        Connection con = JDBCUtil.getCon();
        String flag = "";
        TeacherProblemDao teadao = new TeacherProblemDao();
        flag = teadao.checkProblemByNo(con,problem,courseId);
        if("无重复习题no".equals(flag)){
            flag = teadao.teacherEditProblem(con,problem);
        }
        JDBCUtil.closeCon(con);
        return flag;
    }



    public String teacherEditAns(Answer answer) throws SQLException {
        Connection con = JDBCUtil.getCon();
        String flag = "";
        TeacherAnswerDao teadao = new TeacherAnswerDao();
            flag = teadao.teacherEditProblem(con,answer);
        JDBCUtil.closeCon(con);
        return flag;
    }



    public String teacherDelPro(int problemid) throws SQLException {
        Connection con = JDBCUtil.getCon();
        String flag = "";
        TeacherAnswerDao ansdao = new TeacherAnswerDao();
        TeacherTpDao tpdao = new TeacherTpDao();
        TeacherProblemDao prodao = new TeacherProblemDao();
        int ansid = prodao.getAnswerId(con, problemid);
        flag = ansdao.teacherDelProblem(con,ansid);
        if("答案删除成功".equals(flag)){
            flag = tpdao.teacherDelProblem(con,problemid);
            if("试题中的习题删除成功".equals(flag)){
                flag = prodao.teacherDelProblem(con,problemid);
                if("习题库中习题删除成功".equals(flag)){
                    return flag;
                }else {
                    return flag;
                }
            }else{
                return flag;
            }
        }else {
            return flag;
        }
        
    }



    public String teacherAddAnswer(Answer answer, int courseId) throws SQLException {
        Connection con = JDBCUtil.getCon();
        String flag = "";
        TeacherAnswerDao teadao = new TeacherAnswerDao();
        flag = teadao.addAnsCheckByNo(con,answer,courseId);
        if("无重复答案no".equals(flag)){
            flag = teadao.teacherAddProblem(con,answer);
        }
        JDBCUtil.closeCon(con);
        return flag;
    }



    public int teacherQueryAnswerByNo(String ansNo) throws SQLException {
        Connection con = JDBCUtil.getCon();
        int num = 0;
        TeacherAnswerDao teadao = new TeacherAnswerDao();
        num = teadao.teacherQueryAnswerByNo(con,ansNo);
        JDBCUtil.closeCon(con);
        return num;
    }



    public String teacherAddPro(Problem problem,int course_id) throws SQLException {
        Connection con = JDBCUtil.getCon();
        String flag = "";
        TeacherProblemDao teadao = new TeacherProblemDao();
        flag = teadao.addProCheckByNo(con,problem,course_id);
        if("无重复习题no".equals(flag)){
            flag = teadao.teacherAddProblem(con,problem);
        }
        JDBCUtil.closeCon(con);
        return flag;
    }



    public ArrayList<Testpaper> teacherGetAllPaper(int couid) throws SQLException {
        Connection con = JDBCUtil.getCon();
        ArrayList<Testpaper> testpaperList = new ArrayList<Testpaper>();
        TeacherTestPaperDao paperdao = new TeacherTestPaperDao();
        testpaperList = paperdao.teacherGetAllPaper(con,couid);
        JDBCUtil.closeCon(con);
        return testpaperList;
    }



    public ArrayList<Problem> teacherQueryTestPaperPro(int testpaperid) throws SQLException {
        Connection con = JDBCUtil.getCon();
        ArrayList<Problem> problemList = new ArrayList<Problem>();
        ArrayList<Integer> problemIdList = new ArrayList<Integer>();
        TeacherTpDao tpdao = new TeacherTpDao();
        TeacherProblemDao prodao = new TeacherProblemDao();
        problemIdList = tpdao.teacherGetAllProblem(con, testpaperid);
        problemList = prodao.getAllProInPaper(con,problemIdList);
        JDBCUtil.closeCon(con);
        return problemList;
    }



    public ArrayList<Answer> teacherQueryTestPaperAns(int testpaperid) throws SQLException {
        Connection con = JDBCUtil.getCon();
        ArrayList<Answer> answerList = new ArrayList<Answer>();
        ArrayList<Integer> problemIdList = new ArrayList<Integer>();
        ArrayList<Integer> answerIdList = new ArrayList<Integer>();
        TeacherTpDao tpdao = new TeacherTpDao();
        TeacherAnswerDao ansdao = new TeacherAnswerDao();
        TeacherProblemDao prodao = new TeacherProblemDao();
        problemIdList = tpdao.teacherGetAllProblem(con, testpaperid);
        answerIdList = prodao.teacherGetAllAnswer(con,problemIdList);
        answerList = ansdao.getAllProInPaper(con,answerIdList);
        JDBCUtil.closeCon(con);
        return answerList;
    }



    public Testpaper teacherQueryTestPaper(int testpaperid) throws SQLException {
        Connection con = JDBCUtil.getCon();
        TeacherTestPaperDao paperdao = new TeacherTestPaperDao();
        Testpaper testpaper = new Testpaper();
        testpaper = paperdao.queryTestPaper(con,testpaperid);
        JDBCUtil.closeCon(con);
        return testpaper;
        
    }



    public String teacherDelPaper(Integer testpaperid) throws SQLException {
        String flag = "";
        Connection con = JDBCUtil.getCon();
        TeacherTpDao tpdao = new TeacherTpDao();
        TeacherTestPaperDao paperdao = new TeacherTestPaperDao();
        flag = tpdao.teacherDelPaper(con,testpaperid);
        if("删除成功".equals(flag)){
            flag = paperdao.teacherDelPaper(con,testpaperid);
        }
        return flag;
    }



    public String teacherAddPaper(Testpaper testpaper) throws SQLException {
        Connection con = JDBCUtil.getCon();
        String flag = "";
        TeacherTestPaperDao paperdao = new TeacherTestPaperDao();
        flag = paperdao.teacherAddPaper(con,testpaper);
        JDBCUtil.closeCon(con);
        return flag;
    }



    public String teacherAddProToPaper(int testpaperid, ArrayList<Integer> problemIdList) throws SQLException {
        Connection con = JDBCUtil.getCon();
        String flag = "";
        TeacherTpDao tpdao = new TeacherTpDao();
        flag = tpdao.teacherAddProToPaper(con,testpaperid,problemIdList);
        JDBCUtil.closeCon(con);
        return flag;
    }



    public int queryTestPaperIdByCourseNo(String tstNo, String tstName,
            int courseId) throws SQLException {
        Connection con = JDBCUtil.getCon();
        int testpaperid = 0;
        TeacherTestPaperDao paperdao = new TeacherTestPaperDao();
        testpaperid = paperdao.queryTestPaperIdByCourseNo(con,tstNo,tstName,courseId);
        JDBCUtil.closeCon(con);
        return testpaperid;
    }



    public ArrayList<Problem> teacherGetAllProByKeyw(int couid, String querypro, String queryproby) throws SQLException {
        Connection con = JDBCUtil.getCon();
        ArrayList<Problem> problems = new ArrayList<Problem>();
        TeacherProblemDao prodao = new TeacherProblemDao();
        problems = prodao.teacherGetAllPro(con,couid,querypro,queryproby);
        JDBCUtil.closeCon(con);
        return problems;
    }



    public ArrayList<Problem> teacherGetAllProOutPaper(int testpaperid, int courseid) throws SQLException {
        Connection con = JDBCUtil.getCon();
        ArrayList<Problem> problemList = new ArrayList<Problem>();
        ArrayList<Integer> problemIdListIn = new ArrayList<Integer>();
        ArrayList<Integer> problemIdListOut = new ArrayList<Integer>();
        ArrayList<Integer> problemIdListAll = new ArrayList<Integer>();
        TeacherTpDao tpdao = new TeacherTpDao();
        TeacherProblemDao prodao = new TeacherProblemDao();
        problemIdListAll = prodao.teacherGetAllProId(con,courseid);
        problemIdListIn = tpdao.teacherGetAllProblem(con, testpaperid);
        for(int i=0;i<problemIdListIn.size();i++){
            for(int j=0;j<problemIdListAll.size();j++){
                problemIdListAll.remove(j);
            }
        }
        problemIdListOut = problemIdListAll;
        problemList = prodao.getAllProInPaper(con, problemIdListOut);
        return problemList;
    }



    public ArrayList<Answer> teacherGetAllAnsOutPaper(int testpaperid, int courseid) throws SQLException {
        Connection con = JDBCUtil.getCon();
        ArrayList<Problem> problemList = new ArrayList<Problem>();
        ArrayList<Integer> problemIdListIn = new ArrayList<Integer>();
        ArrayList<Integer> problemIdListOut = new ArrayList<Integer>();
        ArrayList<Integer> problemIdListAll = new ArrayList<Integer>();
        TeacherTpDao tpdao = new TeacherTpDao();
        TeacherProblemDao prodao = new TeacherProblemDao();
        problemIdListAll = prodao.teacherGetAllProId(con,courseid);
        problemIdListIn = tpdao.teacherGetAllProblem(con, testpaperid);
        for(int i=0;i<problemIdListIn.size();i++){
            for(int j=0;j<problemIdListAll.size();j++){
                problemIdListAll.remove(j);
            }
        }
        problemIdListOut = problemIdListAll;
        ArrayList<Answer> answerList = new ArrayList<Answer>();
        ArrayList<Integer> answerIdList = new ArrayList<Integer>();
        TeacherAnswerDao ansdao = new TeacherAnswerDao();
        answerIdList = prodao.teacherGetAllAnswer(con,problemIdListOut);
        answerList = ansdao.getAllProInPaper(con,answerIdList);
        JDBCUtil.closeCon(con);
        return answerList;
    }



    public String teacherDelProInPaper(Integer testpaperid,
            ArrayList<Integer> problemIdList) throws SQLException {
        Connection con = JDBCUtil.getCon();
        String flag = "";
        TeacherTpDao tpdao = new TeacherTpDao();
        flag = tpdao.teacherDelProInPaper(con,testpaperid,problemIdList);
        JDBCUtil.closeCon(con);
        return flag;
        
    }



    public String teacherUpdateNumInPaper(Testpaper testpaper) throws SQLException {
        Connection con = JDBCUtil.getCon();
        String flag = "";
        TeacherTestPaperDao tpdao = new TeacherTestPaperDao();
        flag = tpdao.teacherUpdateNumInPaper(con,testpaper);
        JDBCUtil.closeCon(con);
        return flag;
    }

    

}


0 0