Commit f4f328c6 authored by suichenguang's avatar suichenguang

添加数据返回boolean

parent d8ca0dbf
......@@ -37,7 +37,6 @@ public class ReadExcelApi {
PersonPostService personPostService;
@Autowired
FileNameDicService fileNameDicService;
Boolean result = null;
/**
* 导入个人邮寄信息表
......@@ -46,7 +45,7 @@ public class ReadExcelApi {
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@Transactional(rollbackFor = Exception.class)
public String ReadPersonPost(HttpServletResponse resp, HttpServletRequest requ) {
public boolean ReadPersonPost(HttpServletResponse resp, HttpServletRequest requ) {
YXJSONResponse yxresp = new YXJSONResponse();
resp.setCharacterEncoding("UTF-8");
String filename = "";
......@@ -68,7 +67,7 @@ public class ReadExcelApi {
//将当前上下文初始化给 CommonsMutipartResolver (多部分解析器)
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(
requ.getSession().getServletContext());
// 判断是否是多数据段提交格式
// 判断是否是多数据段提交格式
if (multipartResolver.isMultipart(requ)) {
MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) requ;
Iterator<String> iter = multiRequest.getFileNames();
......@@ -159,97 +158,11 @@ public class ReadExcelApi {
}
// list = upload.parseRequest(requ);
//
// for (FileItem item : list) {
// File file =null;
// try {
// // 如果fileitem中封装的是普通输入项的数据
// if (item.isFormField()) {
// String name = item.getFieldName();
// // 解决普通输入项的数据的中文乱码问题
// String value = item.getString("UTF-8");
// map.put(name, value);
// } else {
// // 如果fileitem中封装的是上传文件
// // 得到上传的文件名称,
// filename = item.getName();
//
// if (filename == null || filename.trim().equals("")) {
// continue;
// }
// InputStream in = item.getInputStream();
// OutputStream os = new FileOutputStream(file);
// int bytesRead = 0;
// byte[] buffer = new byte[8192];
// while ((bytesRead = in.read(buffer, 0, 8192)) != -1) {
// os.write(buffer, 0, bytesRead);
// }
// os.close();
// in.close();
// }
// ReadExcel readExcel = new ReadExcel();
// List list1 = readExcel.readExcel(file);
// //保存EXCEL文件信息
// FileNameDicEntity fileNameDicEntity = new FileNameDicEntity();
// fileNameDicEntity.setFileName(filename);
// fileNameDicEntity.setUploadDate(new Date());
// //保存个人邮寄信息
// long fileID = fileNameDicService.saveFileNameDic(fileNameDicEntity);
// List<PersonPostEntity> entityList= new ArrayList<PersonPostEntity>();
// for (int i = 0; i < list1.size(); i++){
// PersonPostEntity personPostEntity = new PersonPostEntity();
// List list2 = (List) list1.get(i);
// //跳过空行和第一行
// if (list2 == null||i==0){
// continue;
// }
// personPostEntity.setBackWaybillNumber((String) list2.get(0));
// personPostEntity.setOrderNumber((String) list2.get(1));
// personPostEntity.setCreateDate((Time) list2.get(2));
// personPostEntity.setOpenid((String) list2.get(3));
// personPostEntity.setWcPlayOrderNumber((String) list2.get(4));
// personPostEntity.setPlayState((String) list2.get(5));
// personPostEntity.setOrderState((String) list2.get(6));
// personPostEntity.setApplicantName((String) list2.get(7));
// personPostEntity.setSenderName((String) list2.get(8));
// personPostEntity.setSenderPhone((String) list2.get(9));
// personPostEntity.setSenderAddress((String) list2.get(10));
// personPostEntity.setRecipientName((String) list2.get(11));
// personPostEntity.setRecipientPhone((String) list2.get(12));
// personPostEntity.setRecipientAddress((String) list2.get(13));
// personPostEntity.setOrderBlankNumber((String) list2.get(14));
// personPostEntity.setGetToProvince((String) list2.get(15));
// personPostEntity.setGetToCity((String) list2.get(16));
// personPostEntity.setGetToCounty((String) list2.get(17));
// personPostEntity.setBusinessType((String) list2.get(18));
// personPostEntity.setLatticeMouthInformation((String) list2.get(19));
// personPostEntity.setNatureOfTheInternal((String) list2.get(20));
// personPostEntity.setNatureOfTheInformation((String) list2.get(21));
// personPostEntity.setFirstWhite((String) list2.get(22));
// personPostEntity.setFileId(fileID);
// entityList.add(personPostEntity);
// }
// boolean b = personPostService.savePersonPost(entityList);
// } catch (UnsupportedEncodingException e) {
// e.printStackTrace();
// yxresp.outPutError("UnsupportedEncodingException", "上传文件时发现文件编码错误:" + e.getMessage());
// continue;
// } catch (IOException e) {
// e.printStackTrace();
// yxresp.outPutError("IOException", "上传文件时发生IO错误:" + e.getMessage());
// continue;
// } catch (Exception e) {
// e.printStackTrace();
// yxresp.outPutError("Exception", "上传文件时发生错误,非法XML文件:" + filename);
// continue;
// }
// }
} catch (Exception e) {
e.printStackTrace();
yxresp.outPutError("FileUploadException", "文件上载发生异常:" + e.getMessage());
} finally {
return yxresp.toJSONString();
return true;
}
}
}
......@@ -258,6 +171,6 @@ public class ReadExcelApi {
}finally {
}
return null;
return true;
}
}
\ No newline at end of file
......@@ -11,6 +11,7 @@ import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.dom4j.DocumentException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
......@@ -33,7 +34,7 @@ import java.util.Map;
@RestController
@RequestMapping("importXML")
public class ImportXmlApi {
public class ReadXmlApi {
@Autowired
private ImportXmlService importXmlService;
......@@ -45,10 +46,11 @@ public class ImportXmlApi {
* @return 成功返回 上传完成 失败返回 异常信息
*/
@RequestMapping("getXMLToCheck")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@RequestMapping("getXMLToCheck")
public String getXMLToCheck(@Context HttpServletResponse resp, @Context HttpServletRequest requ) {
@Transactional(rollbackFor = Exception.class)
public boolean getXMLToCheck(@Context HttpServletResponse resp, @Context HttpServletRequest requ) {
YXJSONResponse yxresp = new YXJSONResponse();
resp.setCharacterEncoding("UTF-8");
String filename = "";
......@@ -110,7 +112,7 @@ public class ImportXmlApi {
e.printStackTrace();
yxresp.outPutError("FileUploadException", "文件上传发生异常:" + e.getMessage());
} finally {
return yxresp.toJSONString();
return true;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment