package com.market.controller;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.market.pojo.Bug;
import com.market.pojo.Bugfile;
import com.market.pojo.Ponderance;
import com.market.pojo.Project;
import com.market.pojo.User;
import com.market.pojo.result;
import com.market.service.BugService;
import com.market.service.BugfileService;
import com.market.service.PonderanceService;
import com.market.service.ProjectService;
import com.market.service.UserService;
import com.market.service.resultService;
import com.market.util.common.ViewExcel;
import com.market.util.tag.PageModel;
/**
* @Description:
* @author 敖海洋
* @version 创建时间:2017-07-14 11:30:57
*/
@Controller
public class bugController {
@Autowired
@Qualifier("bugService")
private BugService bugService;
@Autowired
@Qualifier("userService")
private UserService userService;
@Autowired
@Qualifier("projectService")
ProjectService projectService;
@Autowired
@Qualifier("ponderanceService")
private PonderanceService ponderanceService;
@Autowired
@Qualifier("resultService")
private resultService resultService;
@Autowired
@Qualifier("bugfileService")
private BugfileService bugfileService;
/***********************************
* admin bug
**********************************/
// 管理员后台显示所有bug
@RequestMapping(value = "/bug/selectBug")
public String AdminselectBug(Model model, Integer pageIndex, Integer pro_id,Integer pon_id, Integer result_id,
Integer reporter_id, Integer handler_id, @ModelAttribute Bug bug, HttpSession session) {
// 模糊查询时判断是否有关联对象传递,如果有,创建并封装关联对象
this.genericAssociation(pro_id, pon_id,result_id, reporter_id, handler_id, bug);
PageModel pageModel = new PageModel();
if (pageIndex != null) {
pageModel.setPageIndex(pageIndex);
}
/** 查询信息 */
List<User> users = userService.findAllUser();
List<Project> projects = projectService.selectAllProjects();
List<Ponderance> ponderances = ponderanceService.selectAllponderances();
List<Bug> bugs = bugService.findBug(bug, pageModel);
List<result> results = resultService.selectAllresults();
model.addAttribute("results", results);
model.addAttribute("bugs", bugs);
model.addAttribute("users", users);
model.addAttribute("projects", projects);
model.addAttribute("ponderances", ponderances);
model.addAttribute("pageModel", pageModel);
return "bug/Abug";
}
// 根据项目id:pro_id导出Excel
@RequestMapping(value = "/project/exportExcel")
public ModelAndView exportExcel(ModelMap model, Integer pro_id, HttpServletRequest request,
HttpServletResponse response, @ModelAttribute Bug bug) throws Exception {
if (pro_id != null) {
Project project = new Project();
project.setPro_id(pro_id);
bug.setProject(project);
}
ViewExcel viewExcel = new ViewExcel();
Map obj = null;
HSSFWorkbook workbook = bugService.SetToExcel(bug);
viewExcel.buildExcelDocument(obj, workbook, request, response);
return new ModelAndView(viewExcel, model);
}
// 模糊查询导出Excel
@RequestMapping(value = "/bug/exportExcel")
public ModelAndView mohuexportExcel(ModelMap model, HttpServletRequest request, HttpSession session,
HttpServletResponse response, @ModelAttribute Bug bug) throws Exception {
bug = (Bug) session.getAttribute("bug");
ViewExcel viewExcel = new ViewExcel();
Map obj = null;
HSSFWorkbook workbook = bugService.SetToExcel(bug);
viewExcel.buildExcelDocument(obj, workbook, request, response);
return new ModelAndView(viewExcel, model);
}
// 管理员修改bug(分配bug)
@RequestMapping(value = "/bug/updateBug")
public ModelAndView AdminupdateBug(String flag, Integer pro_id, Integer pon_id,Integer result_id, Integer handler_id,
HttpSession session, @ModelAttribute Bug bug, ModelAndView mv) {
// 当flag==1, 跳转页面
if (flag.equals("1")) {
// 根据id查询部门
Bug target = bugService.selectBugById(bug.getBug_id());
List<User> users = userService.findAllUser();
List<Project> projects = projectService.selectAllProjects();
List<Ponderance> Ponderances = ponderanceService.selectAllponderances();
List<result> results = resultService.selectAllresults();
mv.addObject("results", results);
mv.addObject("projects", projects);
mv.addObject("ponderances", Ponderances);
mv.addObject("users", users);
// 设置Model数据
mv.addObject("bug", target);
// 设置跳转到修改页面
mv.setViewName("bug/Aupdatebug");
} else {
// 管理员修改bug
// 设置bug处理人
if (handler_id != null) {
User handler = new User();
handler.setUser_id(handler_id);
bug.setHandler(handler);
}
if (pon_id != null) {
Ponderance Ponderance = new Ponderance();
Ponderance.setPon_id(pon_id);
bug.setPonderance(Ponderance);
}
if (result_id != null) {
result result = new result();
result.setResult_id(result_id);
bug.setResult(result);
}
bugService.modifyBug(bug);
/* if (session.getAttribute("user_id") != null) {
Bug target = new Bug();
Project project = new Project();
project.setPro_id(pro_id);
target.setProject(project);
PageModel pageModel = new PageModel();
*//** 查询信息 *//*
List<User> users = userService.findAllUser();
List<Ponderance> Ponderances = ponderanceService.selectAllponderances();
List<Bug> bugs = bugService.findBug(target, pageModel);
mv.addObject("pro_id", pro_id);// 继续在此项目内进行查询
mv.addObject("bugs", bugs);
mv.addObject("users", users);
mv.addObject("pageModel", pageModel);
mv.addObject("ponderances", Ponderances);
//mv.setViewName("bug/selectBug");
}
else {*/
mv.setViewName("redirect:/bug/selectBug");
}
return mv;
}
// 返回
//`}
// 删除bug
@RequestMapping(value = "/bug/removeBug")
public ModelAndView removeBug(@RequestParam("bug_id") String bug_id, ModelAndView mv) {
// 根据id删除
bugService.deleteBug(Integer.parseInt(bug_id));
// 设置客户端跳转到查询请求
mv.setViewName("redirect:/bug/selectBug");
// 返回ModelAndView
return mv;
}
/********************************** 公共部分 *****************************************/
// bug详情
@RequestMapping(value = "/bug/detailBug")
public ModelAndView detailProject(@ModelAttribute Bug bug, ModelAndView mv) {
// 根据bug_id查询附件
Bug target = bugService.selectBugById(bug.getBug_id());
List<Bugfile> bugfiles = bugfileService.selectBugfileByBugId(bug.getBug_id());
// 设置Model数据
mv.addObject("bugfiles", bugfiles);
mv.addObject("bug", target);
// 设置跳转到修改页面
mv.setViewName("bug/bugdetail");
return mv;
}
/**
* 由于对象关联映射, 所以不能直�