public void testFindCQUPTUserByUserName() { this.init(); try { CQUPTUser u = submitInfoMemberDao.findCQUPTUserByUserName("爱测试"); System.out.println(u.getUserId()); System.out.println("测试成功!"); } catch (Exception e) { e.printStackTrace(); } }
public String execute() throws Exception { HttpServletRequest request = ServletActionContext.getRequest(); // 如果submit==保存,status=0,如果submit==提交,status=1 int status; if ("保存".equals(submit)) { status = 0; } else if ("提交".equals(submit)) { status = 1; } else { status = -1; } String id = GenerateUtils.getID(); // 生成ID // 取得存放在session中的userId String userId = (String) ActionContext.getContext().getSession().get("userId"); CQUPTUser user = new CQUPTUser(); user.setUserId(userId); /* * 构建一条记录对象 */ QualityProjectRecord qualityProjectRecord = new QualityProjectRecord(); qualityProjectRecord.setId(id); qualityProjectRecord.setName(projectName); qualityProjectRecord.setSubmitUser(user); qualityProjectRecord.setStatus(status); List<QualityProjectField> fieldsFromDataBase = searchDao.SearchObjectsByFactor( "com.cqupt.mis.rms.model.QualityProjectField", "isDelete", 0); Set<QualityProjectData> fields = new HashSet<QualityProjectData>(); // 将前台已填写的字段封装成qualityProjectData对象 for (QualityProjectField f : fieldsFromDataBase) { String value = (String) request.getParameter(f.getName()); if (value == null || "".equals(value)) { continue; } else { QualityProjectData tempData = new QualityProjectData(); tempData.setRecord(qualityProjectRecord); tempData.setField(f); tempData.setValue(value); fields.add(tempData); } } qualityProjectRecord.setFields(fields); /* * 构建上传材料,获奖教师的对象 */ String targetDirectory = context.getRealPath(GenerateUtils.generateSavePath()); // 获得路径 List<Proofs> proofs = new ArrayList<Proofs>(); List<QualityRecordAward> qualityRecordAwardList = new ArrayList<QualityRecordAward>(); try { // 上传旁证材料 if (upload != null) { for (int i = 0; i < upload.length; i++) { String fileName = uploadFileName[i]; // 上传的文件名 String fileType = uploadContentType[i]; // 文件类型 String targetFileName = GenerateUtils.generateFileName(fileName); File target = new File(targetDirectory, targetFileName); FileUtils.copyFile(upload[i], target); Proofs proof = new Proofs(); proof.setInfoApprovedId(id); proof.setTimeProofUpload(new Date()); proof.setUploadProofName(fileName); proof.setUploadContentType(fileType); proof.setUploadRealName(targetFileName); proof.setProofPath(GenerateUtils.generateSavePath()); if (!"".equals(descProof[i]) && descProof[i] != null) { proof.setDescProof(descProof[i]); } proofs.add(proof); } } // 保存成员信息 if (memberName != null) { for (int j = 0; j < memberName.length; j++) { if (!"".equals(memberName[j]) && memberName[j] != null) { QualityRecordAward qualityRecordAward = new QualityRecordAward(); qualityRecordAward.setQualityProjectRecord(qualityProjectRecord); qualityRecordAward.setMemberName(memberName[j]); if (!"".equals(remarksMem[j]) && remarksMem[j] != null) { qualityRecordAward.setRemarks(remarksMem[j]); } qualityRecordAwardList.add(qualityRecordAward); } } } boolean result1 = dynamicDataRecordDao.addRecord(qualityProjectRecord); boolean result2 = submitInfoAndProofsService.submitResearchMemberInfo(31, qualityRecordAwardList); boolean result3 = submitInfoAndProofsService.submitProofs(proofs); Confirm confirm = new Confirm(); if (result1 && result2 && result3) { confirm.setIsSuccess("right"); confirm.setMessage(DynamicDataFieldUtils.getInfoNameByClassNum(6) + "添加成功"); confirm.setUrl("viewQualityProjectRecords.action"); confirm.setRetName("管理个人" + DynamicDataFieldUtils.getInfoNameByClassNum(6) + "页面"); } else { confirm.setIsSuccess("error"); confirm.setMessage(DynamicDataFieldUtils.getInfoNameByClassNum(6) + "添加失败"); confirm.setUrl("viewQualityProjectRecords.action"); confirm.setRetName("管理个人" + DynamicDataFieldUtils.getInfoNameByClassNum(6) + "页面"); } ActionContext.getContext().put("confirm", confirm); return SUCCESS; } catch (Exception e) { e.printStackTrace(); return ERROR; } }