public String execute() throws Exception { String userId = (String) ActionContext.getContext().getSession().get("userId"); String targetDirectory = servletContext.getRealPath("Excel"); // 获得路径 if (upload != null) { try { String targetFileName = GenerateUtils.generateFileName(uploadFileName); File target = new File(targetDirectory, targetFileName); FileUtils.copyFile(upload, target); String userInfoExcelPath = targetDirectory + "\\" + targetFileName; File excelfile = new File(userInfoExcelPath); String info = excelToDBService.readInfoExceltoDB(excelfile, userId, targetDirectory); if ("ALLSUC".equals(info)) { warning = "数据全部导入成功!"; } else if ("ERR".equals(info)) { warning = "数据导入中出现问题,请看是否上传的是正确的excel,否则请联系管理员!"; } else { warning = "部分未导入的数据生成的excel,请及时下载!"; url = info; } if (target.exists()) { target.delete(); } return SUCCESS; } catch (Exception e) { e.printStackTrace(); return ERROR; } } warning = "请上传材料"; return ERROR; }
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; } }