@RequestMapping(params = "doAdd")
public ModelAndView doAdd(ProjectMainAttEntity projectMainAtt, HttpServletRequest request, @RequestParam("file") MultipartFile[] file) {
String message = null;
message = "待审核经费添加成功";
String yyyyMM = DateUtils.date2Str(DateUtils.date_yyyy_mm);
String path = request.getSession().getServletContext().getRealPath("upload/") + "/" +"moneyfile"+"/" + yyyyMM + "/";
String[] detailNames = request.getParameterValues("detailName");
String[] detailMoneys = request.getParameterValues("detailMoney");
String[] realDateArray = request.getParameterValues("realDate");
int i = 0;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try{
projectMainAtt.setCheckedStatus("0");
projectMainAttService.save(projectMainAtt);
systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
}catch(Exception e){
e.printStackTrace();
message = "待审核经费添加失败";
throw new BusinessException(e.getMessage());
}
for(MultipartFile f:file){
String fileName = f.getOriginalFilename().substring(0,f.getOriginalFilename().lastIndexOf("."));
String fileType = f.getOriginalFilename().substring(f.getOriginalFilename().lastIndexOf(".")+1);
String targetFileName = this.pmMoneyFileService.targetFileName(fileType);
PmMoneyFileEntity moneyFileEntity = new PmMoneyFileEntity();
moneyFileEntity.setDetailName(detailNames[i]);
moneyFileEntity.setDetailMoney(detailMoneys[i]);
Date realDate = null;
try {
realDate = sdf.parse(realDateArray[i]);
} catch (ParseException e1) {
e1.printStackTrace();
}
moneyFileEntity.setRealDate(realDate);
String filePath="upload" + "/" + "moneyfile"+ "/" + yyyyMM + "/";
filePath = filePath + targetFileName;
moneyFileEntity.setFilePath(filePath);
moneyFileEntity.setFileName(fileName);
moneyFileEntity.setDocumentId(projectMainAtt.getId());
try {
pmMoneyFileService.save(moneyFileEntity);
} catch (Exception e1) {
e1.printStackTrace();
}
File targetFile = new File(path,targetFileName);
if(!targetFile.exists()){
targetFile.mkdirs();
}
try {
f.transferTo(targetFile);
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
i++;
}
request.setAttribute("message", message);
request.setAttribute("returnURL", "projectMainAttController.do?list");
return new ModelAndView("success");
}