1.下載文件,將文件保存到本地。(只試用excel);
2.對文件的標題進行檢驗;
3.獲取導入的批次(取一個表的一個值,加1);
4.循環獲取文件某一個行,某一列的值,set到對象中;
5.檢驗值的合法性;
6.循環保存到對象中。
7.用map將錯誤的信息和正確的信息,JSONObject.fromObject(map);
public String uploadFile() throws Exception {
logger.info("開始導入規則文件:" + fileInputFileName);
InputStream is = new FileInputStream(fileInput);
String uploadPath = ServletActionContext.getServletContext()
.getRealPath("/upload");
System.out.println(uploadPath);
File targetFile = new File(uploadPath, this.getFileInputFileName());
OutputStream os = new FileOutputStream(targetFile);
byte[] buffer = new byte[1024];
int length = 0;
while ((length = is.read(buffer)) > 0) {
os.write(buffer, 0, length);
}
is.close();
os.close();
Map<String, Object> map = personalKPIMonitorManualRuleService
.importRules(targetFile);
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
out.println(JSONObject.fromObject(map));
// if(flag==true){
// logger.info("規則文件導入成功:"+fileInputFileName);
// out.println("規則文件導入成功:"+fileInputFileName);
// }else{
// logger.info("規則文件導入失敗:"+fileInputFileName);
// out.println("規則文件導入失敗,詳見日誌:"+fileInputFileName);
// }
out.flush();
out.close();
return null;
}