int beginTime = Integer.parseInt(strbeginTimes[0])*60 + Integer.parseInt(strbeginTimes[1]);
int continueTime = Integer.parseInt(strcontinueTime);
//存放冲突的Book对象
List<Book> books = new ArrayList<Book>();
Date date = DateUtil.strFormatDate(stringDate);
Book oldBook = bookService.cancleBook(id);
oldBook.flush();//刷新对象
books = bookService.getExistBook(date, beginTime, continueTime);
//如果books存在元素,那么说明存在冲突的预定信息
if(0 != books.size()){
oldBook = bookService.activateBook(id);
oldBook.flush();//刷新对象
Iterator<Book> iter = books.iterator();
StringBuilder msg = new StringBuilder();
msg.append("更改失败 !<br />");
Book book = null;
while (iter.hasNext()){
book = iter.next();
msg.append(stringDate + " ");
msg.append(book.getStrBeginTime()+ " 至 ");
msg.append(book.getStrEndTime()+ " 都已被");
msg.append(" " + book.getDepartment() + " ");
msg.append("占用 !<br />如有必要,请找预订人 "+book.getLinkman()+" 协商 !<br />");
}
//如果预定已经存在,那么就提示这个时间段已被某部门预定
request.setAttribute("msg", msg);
request.setAttribute("book",oldBook);
return "book/update";
}else {
//如果如果不存在冲突预定,那么就提示预定成功,并告知开会时间
Book book = bookService.addBook(date, beginTime, continueTime, department,linkman);
if ("".equals(title) || null == title){
title = book.getDepartment() + "的会议" ;
}
if ("".equals(content) || null == content){
content = book.getDepartment() + "的会议" ;
}
book.init(title, content);
book.flush();//刷新对象
request.setAttribute("msg", "更改成功,开会时间更改为 "+stringDate
+ " " + book.getStrBeginTime() + " 至 " + book.getStrEndTime()+ " !");
//如果来自index.jspx,那么操作后,跳转到原页面
if ("index".equals(from)){
List<Book> todaybooks = bookService.searchBook(DateUtil.formatDate(new Date()));
request.setAttribute("todaybooks", todaybooks);
return "book/"+from;