@Secured({"ROLE_TESTER"}) @RequestMapping("addBugFromUC.htm") public ModelAndView addBugFromUC(HttpServletRequest request) throws Exception { User user = (User) request.getSession().getAttribute("user"); String destinationDir = "E:\\workplace\\bugmanagement\\src\\main\\webapp\\source\\bug\\"; MultipartHttpServletRequest multipartReq = (MultipartHttpServletRequest) request; String usercaseId = multipartReq.getParameter("usercaseId"); String module1 = multipartReq.getParameter("module"); String assignedTo = multipartReq.getParameter("assignedTo"); String title = multipartReq.getParameter("title"); String chongxian = multipartReq.getParameter("chongxian"); String os = multipartReq.getParameter("os"); String browser = multipartReq.getParameter("browser"); String type = multipartReq.getParameter("type"); String severity = multipartReq.getParameter("severity"); String keywords = multipartReq.getParameter("keywords"); String[] version = multipartReq.getParameterValues("version"); String[] mailto = (String[]) multipartReq.getParameterValues("mailto"); int size = mailto.length; String mail = ""; String mail1 = ""; String email = ""; String email1 = ""; System.out.println(keywords); System.out.println(size); for (int j = 0; j < size; j++) { System.out.println(" mail to " + mailto[j]); User user1 = aService.findById(User.class, Integer.parseInt(mailto[j])); if (j == (mailto.length - 1)) { email = user1.getEmail(); } else { email = user1.getEmail() + ";"; } email1 = email1 + email; if (j == (mailto.length - 1)) { mail = user1.getRealName(); } else { mail = user1.getRealName() + ";"; } mail1 = mail1 + mail; } Module module = aService.findById(Module.class, Integer.parseInt(module1)); Developer develop = aService.findById(Developer.class, Integer.parseInt(assignedTo)); UserCase userCase = aService.findById(UserCase.class, Integer.parseInt(usercaseId)); Bug bug = new Bug(); bug.setAssignedTo(develop); bug.setBrowser(browser); bug.setConfirm(false); bug.setKeyword(keywords); bug.setModule(module); bug.setCreatedAt(new Date()); bug.setCreator(user); bug.setMailto(mail1); bug.setOs(os); bug.setSeverity(Integer.parseInt(severity)); bug.setTitle(title); bug.setType(type); bug.setSteps(chongxian); bug.setStatus("激活"); bug.setFromCase(userCase); aService.save(bug); userCase.setToBug(bug); aService.update(userCase); History hs = new History(); hs.setUser(user); hs.setObjectId(bug.getBugId()); hs.setObjectType("bug"); hs.setOperateTime(new Date()); hs.setOperation("创建"); aService.save(hs); History hs1 = new History(); hs1.setUser(user); hs1.setObjectId(userCase.getCaseId()); hs1.setObjectType("usercase"); hs1.setOperateTime(new Date()); hs1.setOperation("编辑"); hs1.setComment("生成BUG"); aService.save(hs1); for (int x = 0; x < version.length; x++) { Version ver = aService.findById(Version.class, Integer.parseInt(version[x])); AffectedVersion av = new AffectedVersion(); av.setBug(bug); av.setVersion(ver); aService.save(av); } List<MultipartFile> files = multipartReq.getFiles("files"); System.out.println("files size =====" + files.size()); for (int i = 0; i < files.size(); i++) { String[] labels = multipartReq.getParameterValues("labels"); MultipartFile file = files.get(i); String fileName = file.getOriginalFilename(); if (!fileName.isEmpty()) { String filetype = fileName.substring(fileName.lastIndexOf(".") + 1); Resource re = new Resource(); re.setObjectId(bug.getBugId()); re.setObjectType("bug"); re.setResourceName(labels[i]); re.setResourceUrl("/source/bug/" + UUID.randomUUID() + "." + filetype); aService.save(re); File destination = new File(destinationDir + UUID.randomUUID() + "." + filetype); file.transferTo(destination); } } SendMailService email2 = new SendMailService("smtp.qq.com", 25, 0, true, "2424208347", "1136822939", true); String url = "尊敬的用户您好," + user.getName() + "创建了新BUG,并抄送给了你请注意查收,点击<a href='http://*****:*****@qq.com", "BUG管理系统", email1, "通知", url); request.setAttribute("note", "尊敬的用户您好," + user.getName() + "创建了新BUG,并抄送给了你请注意查收"); } catch (Exception e) { e.printStackTrace(); System.out.println("send fail"); request.setAttribute("note", "尊敬的用户,很不幸的消息,由于网络故障,邮件发送失败。"); } return new ModelAndView("redirect:bug.htm"); }
@Secured({"ROLE_DEVELOPER", "ROLE_TESTER"}) @RequestMapping("goeditBug.htm") public ModelAndView goeditBug(HttpServletRequest request) { String bugId = request.getParameter("bugId"); Bug bug = aService.findById(Bug.class, Integer.parseInt(bugId)); Project project = bug.getModule().getProject(); List<ModuleBean> modulebean = ModuleUtil.getModuleNameList(aService, project); Company company = (Company) request.getSession().getAttribute("company"); DetachedCriteria dCriteria1 = DetachedCriteria.forClass(Project.class); dCriteria1 .add(Restrictions.eq("company", company)) .add(Restrictions.ne("projectId", project.getProjectId())); List<Project> projectList = aService.queryAllOfCondition(Project.class, dCriteria1); DetachedCriteria dCriteria2 = DetachedCriteria.forClass(Version.class); dCriteria2.add(Restrictions.eq("project", project)); List<Version> versionList = aService.queryAllOfCondition(Version.class, dCriteria2); DetachedCriteria dCriteria3 = DetachedCriteria.forClass(AffectedVersion.class); dCriteria3.add(Restrictions.eq("bug", bug)); List<AffectedVersion> avList = aService.queryAllOfCondition(AffectedVersion.class, dCriteria3); List<Version> aList = new ArrayList<Version>(); for (AffectedVersion aversion : avList) { aList.add(aversion.getVersion()); } DetachedCriteria dCriteria5 = DetachedCriteria.forClass(Department.class); dCriteria5.add(Restrictions.eq("company", company)); List<Department> deptList = aService.queryAllOfCondition(Department.class, dCriteria5); DetachedCriteria dCriteria4 = DetachedCriteria.forClass(Developer.class) .add(Restrictions.ne("developerId", bug.getAssignedTo().getDeveloperId())); dCriteria4.createCriteria("user").add(Restrictions.in("department", deptList)); List<Developer> userList = aService.queryAllOfCondition(Developer.class, dCriteria4); DetachedCriteria dCriteria7 = DetachedCriteria.forClass(History.class); dCriteria7 .add(Restrictions.eq("objectId", bug.getBugId())) .add(Restrictions.eq("objectType", "bug")) .addOrder(Order.asc("operateTime")); List<History> hisList = aService.queryAllOfCondition(History.class, dCriteria7); DetachedCriteria dCriteria6 = DetachedCriteria.forClass(User.class); dCriteria6.add(Restrictions.in("department", deptList)); List<User> userList1 = aService.queryAllOfCondition(User.class, dCriteria6); String mailto = bug.getMailto(); String[] name = mailto.split(";"); List<User> userlist = new ArrayList<User>(); for (int i = 0; i < name.length; i++) { User user1 = new User(); user1.setRealName(name[i]); userlist.add(user1); } ModelMap map = new ModelMap(); map.put("bug", bug); map.put("modulebean", modulebean); map.put("projectList", projectList); map.put("versionList", versionList); map.put("userlist", userlist); map.put("userList", userList); map.put("userList1", userList1); map.put("aList", aList); map.put("hisList", hisList); return new ModelAndView("/bug/editBug", map); }