package com.action;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.dao.ArticleDAO;
import com.dao.BbsDAO;
import com.dao.CateDAO;
import com.dao.CourseDAO;
import com.dao.FavDAO;
import com.dao.FilesDAO;
import com.dao.RebbsDAO;
import com.dao.TeacherDAO;
import com.dao.TopicDAO;
import com.dao.UsersDAO;
import com.dao.VedioDAO;
import com.dao.XuankeDAO;
import com.entity.Article;
import com.entity.Bbs;
import com.entity.Cate;
import com.entity.Course;
import com.entity.Fav;
import com.entity.Files;
import com.entity.Rebbs;
import com.entity.Teacher;
import com.entity.Topic;
import com.entity.Users;
import com.entity.Vedio;
import com.entity.Xuanke;
import java.util.HashMap;
import com.util.VeDate;
import sun.util.resources.cldr.shi.CalendarData_shi_Latn_MA;
//定义为控制器
@Controller
// 设置路径
@RequestMapping("/index")
public class IndexAction extends BaseAction {
private BbsDAO bbsDAO;
private UsersDAO usersDAO;
private CateDAO cateDAO;
private FavDAO favDAO;
private RebbsDAO rebbsDAO;
private ArticleDAO articleDAO;
private CourseDAO courseDAO;
private TeacherDAO teacherDAO;
private TopicDAO topicDAO;
private VedioDAO vedioDAO;
private FilesDAO filesDAO;
private XuankeDAO xuankeDAO;
// 公共方法 提供公共查询数据
private void front() {
getRequest().setAttribute("title", "研考教育管理信息系统");
List<Cate> cateList = this.cateDAO.getAllCate();
this.getRequest().setAttribute("cateList", cateList);
List<Course> hotList = this.courseDAO.getCourseByHot();
this.getRequest().setAttribute("hotList", hotList);
}
// 首页显示的控制器
@RequestMapping("index.action")
public String index() {
this.front();
List<Cate> cateList = this.cateDAO.getAllCate();
List<Cate> frontList = new ArrayList<Cate>();
for (Cate cate : cateList) {
List<Course> courseList = this.courseDAO.getCourseByCate(cate.getCateid());
cate.setCourseList(courseList);
frontList.add(cate);
}
this.getRequest().setAttribute("frontList", frontList);
List<Teacher> teacherList = this.teacherDAO.getFrontTeacher();
this.getRequest().setAttribute("newsList", teacherList);
List<Article> articleList = this.articleDAO.getFrontArticle();
this.getRequest().setAttribute("articleList", articleList);
return "users/index";
}
// 按分类查询
@RequestMapping("cate.action")
public String cate(String id) {
this.front();
Course course = new Course();
course.setCateid(id);
List<Course> courseList = this.courseDAO.getCourseByCond(course);
this.getRequest().setAttribute("courseList", courseList);
return "users/list";
}
//选课
@RequestMapping("xuanke.action")
public String xuanke() {
this.front();
// List<Course> courseList = this.courseDAO.getAllCourse();
List <Xuanke> xuankeList=this.xuankeDAO.getAllXuanke();
this.getRequest().setAttribute("xuankeList", xuankeList);
return "users/xuanke";
}
//测试页面0课程热度图
@RequestMapping("ceshi.action")
public String ceshi() {
this.front();
List<Course> courseList = this.courseDAO.getAllCourse();
// String[] strings = new String[courseList.size()];
// String[] strings2 = new String[courseList.size()];
// for(int i = 0; i < courseList.size(); i++) {
//// strings[i] =
//// strings2.add(dCourse.getHits());
// }
// Map<String, String[]> map = new HashMap<String, String[]>();
// map.put("names",strings );
//// map.put("hits", value)
this.getRequest().setAttribute("courseList", courseList);
return "users/ceshi";
}
//测试页面1学生男女图
@RequestMapping("ceshi1.action")
public String ceshi1() {
this.front();
List<Users> usersList = this.usersDAO.getAllUsers();
// String[] strings = new String[courseList.size()];
// String[] strings2 = new String[courseList.size()];
// for(int i = 0; i < courseList.size(); i++) {
//// strings[i] =
//// strings2.add(dCourse.getHits());
// }
// Map<String, String[]> map = new HashMap<String, String[]>();
// map.put("names",strings );
//// map.put("hits", value)
this.getRequest().setAttribute("usersList", usersList);
return "users/ceshi1";
}
//测试页面0课程热度图
@RequestMapping("ceshi2.action")
public String ceshi2() {
this.front();
List<Users> usersList = this.usersDAO.getAllUsers();
// String[] strings = new String[courseList.size()];
// String[] strings2 = new String[courseList.size()];
// for(int i = 0; i < courseList.size(); i++) {
//// strings[i] =
//// strings2.add(dCourse.getHits());
// }
// Map<String, String[]> map = new HashMap<String, String[]>();
// map.put("names",strings );
//// map.put("hits", value)
this.getRequest().setAttribute("usersList", usersList);
return "users/ceshi2";
}
// 全部商品
@RequestMapping("all.action")
public String all(String number) {
this.front();
List<Course> courseList = this.courseDAO.getAllCourse();
this.getRequest().setAttribute("courseList", courseList);
return "users/list";
}
// 新品上架
@RequestMapping("news.action")
public String news(String number) {
this.front();
List<Course> courseList = this.courseDAO.getCourseByNews();
this.getRequest().setAttribute("courseList", courseList);
return "users/list";
}
// 查询商品
@RequestMapping("query.action")
public String query(String name) {
this.front();
Course course = new Course();
course.setCoursename(name);
List<Course> courseList = this.courseDAO.getCourseByLike(course);
this.getRequest().setAttribute("courseList", courseList);
return "users/list";
}
// 商品详情
@RequestMapping("coursedetail.action")
public String coursedetail(String id) {
this.front();
Course course = this.courseDAO.getCourseById(id);
course.setHits("" + (Integer.parseInt(course.getHits()) + 1));
this.courseDAO.updateCourse(course);
this.getRequest().setAttribute("course", course);
Files f = new Files();
f.setCourseid(id);
List<Files> filesList = this.filesDAO.getFilesByCond(f);
this.getRequest().setAttribute("filesList", filesList);
Vedio v = new Vedio();
v.setCourseid(id);
List<Vedio> vedioList = this.vedioDAO.getVedioByCond(v);
this.getRequest().setAttribute("vedioList", vedioList);
Topic t = new Topic();
t.setCourseid(id);
List<Topic> topicList = this.topicDAO.getTopicByCond(t);
this.getRequest().setAttribute("topicList", topicList);
this.getRequest().setAttribute("tnum", topicList.size());
List <Xuanke> xuankeList=this.xuankeDAO.getAllXuanke();
this.getRequest().setAttribute("xuankeList", xuankeList);
return "users/detail2";
}
// 商品详情
@RequestMapping("coursedetail1.action")
public String coursedetail1(String id) {
this.front();
Course course = this.courseDAO.getCourseById(id);
course.setHits("" + (Integer.parseInt(course.getHits()) + 1));
this.courseDAO.updateCourse(course);
this.getRequest().setAttribute("course", course);
Files f = new Files();
f.setCourseid(id);
List<Files> filesList = this.filesDAO.getFilesByCond(f);
this.getRequest().setAttribute("filesList", filesList);
Vedio v = new Vedio();
v.setCourseid(id);
List<Vedio> vedioList = this.vedioDAO.getVedioByCond(v);
this.getRequest().setAttribute("vedioList", vedioList);
Topic t = new Topic();
t.setCourseid(id);
List<Topic> topicList = this.topicDAO.getTopicByCond(t);
this.getRequest().setAttribute("topicList", topicList);
this.getRequest().setAttribute("tnum", topicList.size());
return "users/detail";
}
@RequestMapping("addTopic.action")
public String addTopic() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
String userid = (String) this.getSession().getAttribute("userid");
Topic top