⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 courseserviceimpl.java

📁 本程序所写的排课
💻 JAVA
字号:
package com.briup.service.impl;import static com.briup.common.HibernateSessionFactory.getSession;import java.util.ArrayList;import java.util.List;import java.util.Set;import org.hibernate.Session;import org.hibernate.Transaction;import com.briup.bean.Classroom;import com.briup.bean.Course;import com.briup.bean.Deploy;import com.briup.bean.SC;import com.briup.common.BeanFactory;import com.briup.common.exception.CourseServiceException;import com.briup.dao.impl.CourseDaoImpl;import com.briup.service.ICourseService;public class CourseServiceImpl implements ICourseService{	public List<Deploy> lookupCourse() throws CourseServiceException{				CourseDaoImpl courseDao = (CourseDaoImpl)BeanFactory.getBean(BeanFactory.COURSEDAOIMPL);		List<Deploy> list = null;		try {			list = courseDao.findAllDeploy();		} catch (Exception e) {			// TODO Auto-generated catch block			e.printStackTrace();		}		return list;	}	public Deploy searchCourse(Long id) throws CourseServiceException{		// TODO Auto-generated method stub		return null;	}	public Deploy searchCourse(String name) throws CourseServiceException{		// TODO Auto-generated method stub		return null;	}	public void selectCourse() throws CourseServiceException{		// TODO Auto-generated method stub			}	public List<Course> lookupMyCourse(Long id) throws CourseServiceException {		//		Session session = getSession();		CourseDaoImpl courseDao = (CourseDaoImpl)BeanFactory.getBean(BeanFactory.COURSEDAOIMPL);		List<Course> list = new ArrayList<Course>();		try {			list = courseDao.lookupMyCourse(id);		} catch (Exception e) {						e.printStackTrace();		}		return list;	}	public List<Deploy> planOfCourse(List<Course> courselist, List<Classroom> roomlist) throws CourseServiceException {				List<Deploy> deployList = new ArrayList<Deploy>();		Long roomid;		int timeid;		for(Course course : courselist)		{						boolean flag = false;			String[] roomTime = new String[15];	//			Deploy deploy = new Deploy();//			deploy.setCourse(course);			if(course.getPoint() == 6)			{				int count = 3;				while(count != 0)				{					Deploy deploy = new Deploy();					deploy.setCourse(course);					Classroom room = new Classroom();					roomid = Long.valueOf((long)(Math.random()*18));					room.setId(roomid);//					System.out.println(roomid);					for(Deploy d : deployList)					{						if(d.getRoom().getId() == roomid)						{//							room = d.getRoom();							roomTime[Integer.valueOf(d.getTime())] = d.getTime();							flag = true;//							for(int i = 0; i < roomTime.length; i++)//							{//								if(roomTime == null)//								{//									flag = true;//									roomTime[i]=d.getTime();//									break;//								}//							} 						}					}					if(!flag)					{						timeid = (int)(Math.random()*15);						deploy.setTime(""+timeid);						deploy.setRoom(room);//						System.out.println(""+room.getId());						deployList.add(deploy);						for(int i = 0; i < roomTime.length; i++)						{							roomTime[i] = null;						}						flag = false;					}					else					{						timeid = (int)(Math.random()*15);						while(roomTime[timeid]!=null)						{							timeid=(int)(Math.random()*15);						}						deploy.setTime(""+timeid);						deploy.setRoom(room);//						System.out.println(""+room.getId());						deployList.add(deploy);						flag = false;					}					count--;				}			}			else if(course.getPoint() ==4 || course.getPoint() == 3)			{				int count = 2;				while(count != 0)				{					Deploy deploy = new Deploy();					deploy.setCourse(course);					Classroom room = new Classroom();					roomid = Long.valueOf((long)(Math.random()*18));					room.setId(roomid);//					System.out.println(roomid);					for(Deploy d : deployList)					{						if(d.getRoom().getId() == roomid)						{//							room = d.getRoom();							roomTime[Integer.valueOf(d.getTime())] = d.getTime();							flag = true;//							for(int i = 0; i < roomTime.length; i++)//							{//								if(roomTime == null)//								{//									flag = true;//									roomTime[i]=d.getTime();//									break;//								}//							} 						}					}					if(!flag)					{						timeid = (int)(Math.random()*15);						deploy.setTime(""+timeid);						deploy.setRoom(room);//						System.out.println(""+room.getId());						deployList.add(deploy);						for(int i = 0; i < roomTime.length; i++)						{							roomTime[i] = null;						}						flag = false;					}					else					{						timeid = (int)(Math.random()*15);						while(roomTime[timeid]!=null)						{							timeid=(int)(Math.random()*15);						}						deploy.setTime(""+timeid);						deploy.setRoom(room);//						System.out.println(""+room.getId());						deployList.add(deploy);						flag = false;					}					count--;				}			}			else			{				Deploy deploy = new Deploy();				deploy.setCourse(course);				Classroom room = new Classroom();				roomid = Long.valueOf((long)(Math.random()*18));				room.setId(roomid);//				System.out.println(roomid);				for(Deploy d : deployList)				{					if(d.getRoom().getId() == roomid)					{//						room = d.getRoom();						for(int i = 0; i < roomTime.length; i++)						{							roomTime[Integer.valueOf(d.getTime())] = d.getTime();							flag = true;//							if(roomTime == null)//							{//								flag = true;//								roomTime[i]=d.getTime();//								break;//							}						} 					}				}				if(!flag)				{					timeid = (int)(Math.random()*15);					deploy.setTime(""+timeid);					deploy.setRoom(room);//					System.out.println(""+room.getId());					deployList.add(deploy);					for(int i = 0; i < roomTime.length; i++)					{						roomTime[i] = null;					}					flag = false;				}				else				{					timeid = (int)(Math.random()*15);					while(roomTime[timeid]!=null)					{						timeid=(int)(Math.random()*15);					}					deploy.setTime(""+timeid);					deploy.setRoom(room);//					System.out.println(""+room.getId());					deployList.add(deploy);					flag = false;				}			}		}		return deployList;	}	public List<Classroom> listAllClassroom() throws CourseServiceException {				Session session = getSession();		CourseDaoImpl courseDao = (CourseDaoImpl)BeanFactory.getBean(BeanFactory.COURSEDAOIMPL);		List<Classroom> list = new ArrayList<Classroom>();		try {			list = courseDao.findAllClassroom();			for(Classroom room : list)			{				System.out.println("room:\t"+room);			}		} catch (Exception e) {			// TODO Auto-generated catch block			e.printStackTrace();		}		session.close();		return list;	}	public List<Course> listAllCourse() throws CourseServiceException {				Session session = getSession();		CourseDaoImpl courseDao = (CourseDaoImpl)BeanFactory.getBean(BeanFactory.COURSEDAOIMPL);		List<Course> list = new ArrayList<Course>();		try {			list = courseDao.findAllCourse();		} catch (Exception e) {			// TODO Auto-generated catch block			e.printStackTrace();		}		session.close();		return list;	}		public List<Deploy> transDeploy(List<Deploy> deployList, List<Classroom> roomList)	{		Long i = new Long(1);		List<Deploy> list = new ArrayList<Deploy>();		for(Deploy deploy : deployList)		{			deploy.setId(i++);			Long roomid = deploy.getRoom().getId()+1;			for(Classroom room : roomList)			{				if(room.getId().equals(roomid))				{					deploy.setRoom(room);					break;				}			}			String time = deploy.getTime();			int timeint = Integer.parseInt(time)/3;			switch(timeint)			{			case 0:				deploy.setTime("星期一");				break;			case 1:				deploy.setTime("星期二");				break;			case 2:				deploy.setTime("星期三");				break;			case 3:				deploy.setTime("星期四");				break;			case 4:				deploy.setTime("星期五");				break;			case 5:				deploy.setTime("");				break;			default:				deploy.setTime("");				break;			}			int timedec = Integer.parseInt(time)%3;			switch(timedec)			{			case 0:				deploy.setTime(deploy.getTime()+"第一节");				break;			case 1:				deploy.setTime(deploy.getTime()+"第二节");				break;			case 2:				deploy.setTime(deploy.getTime()+"第三节");				break;			default:				break;			}			list.add(deploy);		}		return list;	}	public void saveSC(Set<SC> scSet) throws CourseServiceException {				Session session = getSession();		Transaction trans = session.beginTransaction();		CourseDaoImpl courseDao = (CourseDaoImpl)BeanFactory.getBean(BeanFactory.COURSEDAOIMPL);		try {			courseDao.saveSC(scSet);			trans.commit();		} catch (Exception e) {			// TODO Auto-generated catch block			e.printStackTrace();			trans.rollback();			throw new CourseServiceException("提交失败!请稍后再选!");		}		session.close();	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -