Commit c2d36cdb authored by dahai's avatar dahai

调试上传文件

parent 5c67c788
...@@ -7,13 +7,16 @@ import com.yxproject.start.utils.IDCardFactory; ...@@ -7,13 +7,16 @@ import com.yxproject.start.utils.IDCardFactory;
import com.yxproject.start.utils.YXJSONResponse; import com.yxproject.start.utils.YXJSONResponse;
import com.yxproject.start.utils.YXStringUtils; import com.yxproject.start.utils.YXStringUtils;
import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.dom4j.DocumentException; import org.dom4j.DocumentException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
...@@ -24,6 +27,7 @@ import java.io.IOException; ...@@ -24,6 +27,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -35,6 +39,7 @@ public class ImportXmlApi { ...@@ -35,6 +39,7 @@ public class ImportXmlApi {
/** /**
* 导入检测XML * 导入检测XML
*
* @param resp 响应请求 * @param resp 响应请求
* @param requ 获得请求 * @param requ 获得请求
* @return 成功返回 上传完成 失败返回 异常信息 * @return 成功返回 上传完成 失败返回 异常信息
...@@ -44,8 +49,6 @@ public class ImportXmlApi { ...@@ -44,8 +49,6 @@ public class ImportXmlApi {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@RequestMapping("getXMLToCheck") @RequestMapping("getXMLToCheck")
public String getXMLToCheck(@Context HttpServletResponse resp, @Context HttpServletRequest requ) { public String getXMLToCheck(@Context HttpServletResponse resp, @Context HttpServletRequest requ) {
System.out.println("输入:"+requ);
System.out.println("输入2:"+resp);
YXJSONResponse yxresp = new YXJSONResponse(); YXJSONResponse yxresp = new YXJSONResponse();
resp.setCharacterEncoding("UTF-8"); resp.setCharacterEncoding("UTF-8");
String filename = ""; String filename = "";
...@@ -62,36 +65,31 @@ public class ImportXmlApi { ...@@ -62,36 +65,31 @@ public class ImportXmlApi {
Map<String, String> map = new HashMap<String, String>(); Map<String, String> map = new HashMap<String, String>();
List<FileItem> list = null; List<FileItem> list = null;
try { try {
list = upload.parseRequest(requ); //将当前上下文初始化给 CommonsMutipartResolver (多部分解析器)
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(
for (FileItem item : list) { requ.getSession().getServletContext());
// 判断是否是多数据段提交格式
if (multipartResolver.isMultipart(requ)) {
MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) requ;
Iterator<String> iter = multiRequest.getFileNames();
Integer fileCount = 0;
while (iter.hasNext()) {
MultipartFile item = multiRequest.getFile(iter.next());
try { try {
// 如果fileitem中封装的是普通输入项的数据 // 如果fileitem中封装的是普通输入项的数据
if (item.isFormField()) {
String name = item.getFieldName();
// 解决普通输入项的数据的中文乱码问题
String value = item.getString("UTF-8");
// value = new String(value.getBytes("iso8859-1"),"UTF-8");
map.put(name, value);
} else {
// 如果fileitem中封装的是上传文件 // 如果fileitem中封装的是上传文件
// 得到上传的文件名称, // 得到上传的文件名称,
filename = item.getName(); filename = item.getName();
if (filename == null || filename.trim().equals("")) { if (filename == null || filename.trim().equals("")) {
continue; continue;
} }
InputStream in = item.getInputStream(); InputStream in = item.getInputStream();
String str = YXStringUtils.inputStream2String(in, "utf-8"); String str = YXStringUtils.inputStream2String(in, "utf-8");
in.close(); in.close();
IDCardFactory idCardFactory = new IDCardFactory(); IDCardFactory idCardFactory = new IDCardFactory();
idcardsFactory(idCardFactory.extractIDCard(str)); idcardsFactory(idCardFactory.extractIDCard(str));
}
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
e.printStackTrace(); e.printStackTrace();
yxresp.outPutError("UnsupportedEncodingException", "上传文件时发现文件编码错误:" + e.getMessage()); yxresp.outPutError("UnsupportedEncodingException", "上传文件时发现文件编码错误:" + e.getMessage());
continue; continue;
} catch (IOException e) { } catch (IOException e) {
...@@ -108,7 +106,8 @@ public class ImportXmlApi { ...@@ -108,7 +106,8 @@ public class ImportXmlApi {
continue; continue;
} }
} }
} catch (FileUploadException e) { }
} catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
yxresp.outPutError("FileUploadException", "文件上传发生异常:" + e.getMessage()); yxresp.outPutError("FileUploadException", "文件上传发生异常:" + e.getMessage());
} finally { } finally {
...@@ -118,11 +117,9 @@ public class ImportXmlApi { ...@@ -118,11 +117,9 @@ public class ImportXmlApi {
} }
private Boolean idcardsFactory(Map<String, Object> map1) { private Boolean idcardsFactory(Map<String, Object> map1) {
importXmlService.importPersonXml ((List<PreproPersonEntity>) map1.get("preproPerson"), (FilesEntity) map1.get("file")); importXmlService.importPersonXml((List<PreproPersonEntity>) map1.get("preproPerson"), (FilesEntity) map1.get("file"));
return true; return true;
} }
} }
...@@ -2,6 +2,7 @@ package com.yxproject.start.entity; ...@@ -2,6 +2,7 @@ package com.yxproject.start.entity;
import javax.persistence.*; import javax.persistence.*;
import java.sql.Time; import java.sql.Time;
import java.util.Date;
import java.util.Objects; import java.util.Objects;
@Entity @Entity
...@@ -13,7 +14,7 @@ public class FilesEntity { ...@@ -13,7 +14,7 @@ public class FilesEntity {
private Long recordNumber; private Long recordNumber;
private String creatTime; private String creatTime;
private String sourceFileName; private String sourceFileName;
private Time newTime; private Date newTime;
@Basic @Basic
@Column(name = "VERSION_CODE") @Column(name = "VERSION_CODE")
...@@ -77,11 +78,11 @@ public class FilesEntity { ...@@ -77,11 +78,11 @@ public class FilesEntity {
@Basic @Basic
@Column(name = "NEW_TIME") @Column(name = "NEW_TIME")
public Time getNewTime() { public Date getNewTime() {
return newTime; return newTime;
} }
public void setNewTime(Time newTime) { public void setNewTime(Date newTime) {
this.newTime = newTime; this.newTime = newTime;
} }
......
...@@ -7,7 +7,7 @@ import org.apache.ibatis.annotations.Mapper; ...@@ -7,7 +7,7 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface FilesMapper { public interface FilesMapper {
@Insert("INSERT INTO FILES (VERSION_CODE,DWDM,DWMC,RECORD_NUMBER,CREAT_TIME,SOURCE_FILE_NAME,NEW_TIME)" + @Insert("INSERT INTO FILES (VERSION_CODE,DWDM,DWMC,RECORD_NUMBER,CREAT_TIME,SOURCE_FILE_NAME)" +
"VALUES(#{versionCode},#{dwdm},#{dwmc},#{recordNumber},#{creatTime},#{sourceFileName},#{newTime})") "VALUES(#{versionCode},#{dwdm},#{dwmc},#{recordNumber},#{creatTime},#{sourceFileName})")
public boolean insertFiles(FilesEntity filesEntity); public boolean insertFiles(FilesEntity filesEntity);
} }
...@@ -11,11 +11,11 @@ import java.util.List; ...@@ -11,11 +11,11 @@ import java.util.List;
@Mapper @Mapper
public interface PreproPersonMapper { public interface PreproPersonMapper {
/*导入XMl*/ /*导入XMl*/
@Insert("INSERT INTO PREPRO_PERSON (JMSFZSLH,GMSFHM,XM,XBDM,MZDM,CSRQ,SSXQDM,DZMC,SDXP,ZWY_ZWTXSJ,ZWY_ZWTZSJ,ZWE_ZWTXSJ,ZWE_ZWTZSJ" + @Insert("INSERT INTO PREPRO_PERSON (JMSFZSLH,GMSFHM,XM,XBDM,MZDM,CSRQ,SSXQDM,DZMC,SDXP,ZWY_ZWTXSJ,ZWY_ZWTZSJ,ZWE_ZWTXSJ,ZWE_ZWTZSJ," +
"QFJG_GAJGMC,YXQQSRQ,YXQJZRQ,JMSFZSLYYDM,JMSFZZZLXDM,JMSFZLZFSDM,SJR_XM,SJR_LXDH,SJR_YZBM,SJR_TXDZ,SID,FILE_NAME,)" + "QFJG_GAJGMC,YXQQSRQ,YXQJZRQ,JMSFZSLYYDM,JMSFZZZLXDM,JMSFZLZFSDM,SJR_XM,SJR_LXDH,SJR_YZBM,SJR_TXDZ,SID)" +
"VALUES(#{jmsfzslh},#{gmsfhm},#{xm},#{xbdm},#{mzdm},#{csrq},#{ssxqdm},#{dzmc},#{sdxp},#{zwyZwtxsj},#{zwyZwtzsj},#{zweZwtxsj}," + "VALUES(#{jmsfzslh},#{gmsfhm},#{xm},#{xbdm},#{mzdm},#{csrq},#{ssxqdm},#{dzmc},#{sdxp},#{zwyZwtxsj},#{zwyZwtzsj},#{zweZwtxsj}," +
"#{zweZwtzsj},#{qfjgGajgmc},#{yxqqsrq},#{yxqjzrq},#{jmsfzslyydm},#{jmsfzzzlxdm},#{jmsfzlzfsdm},#{sjrXm},#{sjrLxdh},#{sjrYzbm}," + "#{zweZwtzsj},#{qfjgGajgmc},#{yxqqsrq},#{yxqjzrq},#{jmsfzslyydm},#{jmsfzzzlxdm},#{jmsfzlzfsdm},#{sjrXm},#{sjrLxdh},#{sjrYzbm}," +
"#{sjrTxdz},#{sid},#{fileName}") "#{sjrTxdz},#{sid})")
public boolean savePreproPersonEntity(PreproPersonEntity personEntity); public boolean savePreproPersonEntity(PreproPersonEntity personEntity);
/*更新制证数据是否邮寄*/ /*更新制证数据是否邮寄*/
......
...@@ -27,6 +27,7 @@ public class ImportXmlServiceImpl implements ImportXmlService { ...@@ -27,6 +27,7 @@ public class ImportXmlServiceImpl implements ImportXmlService {
filesMapper.insertFiles(filesEntity); filesMapper.insertFiles(filesEntity);
for (PreproPersonEntity preproPersonEntity:preproPersonEntities){ for (PreproPersonEntity preproPersonEntity:preproPersonEntities){
System.out.println(preproPersonEntity.getJmsfzslh()+"___________");
preproPersonMapper.savePreproPersonEntity(preproPersonEntity); preproPersonMapper.savePreproPersonEntity(preproPersonEntity);
} }
return true; return true;
......
...@@ -3,7 +3,6 @@ package com.yxproject.start.utils; ...@@ -3,7 +3,6 @@ package com.yxproject.start.utils;
//import com.yingxin.hibernate.domain.ProductionEntity; //import com.yingxin.hibernate.domain.ProductionEntity;
import com.yxproject.start.entity.FilesEntity; import com.yxproject.start.entity.FilesEntity;
import com.yxproject.start.entity.PreproPersonEntity; import com.yxproject.start.entity.PreproPersonEntity;
import jxl.format.Format;
import org.dom4j.Document; import org.dom4j.Document;
import org.dom4j.DocumentException; import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper; import org.dom4j.DocumentHelper;
...@@ -35,9 +34,11 @@ public class IDCardFactory { ...@@ -35,9 +34,11 @@ public class IDCardFactory {
filesEntity.setSourceFileName(SJBBH); filesEntity.setSourceFileName(SJBBH);
String DWDM = packagehead.element("DWDM").getTextTrim(); String DWDM = packagehead.element("DWDM").getTextTrim();
filesEntity.setDwdm(DWDM); filesEntity.setDwdm(DWDM);
String BBH = packagehead.element("BBH").getTextTrim();
filesEntity.setVersionCode(BBH);
String DWMC = packagehead.element("DWMC").getTextTrim(); String DWMC = packagehead.element("DWMC").getTextTrim();
filesEntity.setDwdm(DWMC); filesEntity.setDwmc(DWMC);
Date date = new Date(); Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
filesEntity.setCreatTime(simpleDateFormat.format(date)); filesEntity.setCreatTime(simpleDateFormat.format(date));
...@@ -45,35 +46,33 @@ public class IDCardFactory { ...@@ -45,35 +46,33 @@ public class IDCardFactory {
List<Element> recordlist = records.elements("RECORD"); List<Element> recordlist = records.elements("RECORD");
for (Element e : recordlist) { for (Element e : recordlist) {
PreproPersonEntity preproPersonEntity = new PreproPersonEntity(); PreproPersonEntity preproPersonEntity = new PreproPersonEntity();
Element chileEle = e;
preproPersonEntity.setJmsfzslh( e.attributeValue("JMSFZSLH"));
preproPersonEntity.setGmsfhm(e.attributeValue("JMSFZSLH"));
preproPersonEntity.setSid(e.attributeValue("sid")); preproPersonEntity.setSid(e.attributeValue("sid"));
preproPersonEntity.setXm(e.attributeValue("XM")); preproPersonEntity.setJmsfzslh( e.element("JMSFZSLH").getStringValue());
preproPersonEntity.setXbdm(e.attributeValue("XBDM")); preproPersonEntity.setGmsfhm(e.element("GMSFHM").getStringValue());
preproPersonEntity.setMzdm(e.attributeValue("MZDM")); preproPersonEntity.setXm(e.element("XM").getStringValue());
preproPersonEntity.setCsrq(e.attributeValue("CSRQ")); preproPersonEntity.setXbdm(e.element("XBDM").getStringValue());
preproPersonEntity.setSsxqdm(e.attributeValue("SSXQDM")); preproPersonEntity.setMzdm(e.element("MZDM").getStringValue());
preproPersonEntity.setDzmc(e.attributeValue("DZMC")); preproPersonEntity.setCsrq(e.element("CSRQ").getStringValue());
preproPersonEntity.setSdxp(e.attributeValue("SDXP")); preproPersonEntity.setSsxqdm(e.element("SSXQDM").getStringValue());
preproPersonEntity.setZwyZwtxsj(e.attributeValue("ZWY_ZWTXSJ")); preproPersonEntity.setDzmc(e.element("DZMC").getStringValue());
preproPersonEntity.setZwyZwtzsj(e.attributeValue("ZWY_ZWTZSJ")); preproPersonEntity.setSdxp(e.element("SDXP").getStringValue());
preproPersonEntity.setZweZwtxsj(e.attributeValue("ZWE_ZWTXSJ")); preproPersonEntity.setZwyZwtxsj(e.element("ZWY_ZWTXSJ").getStringValue());
preproPersonEntity.setZweZwtzsj(e.attributeValue("ZWE_ZWTZSJ")); preproPersonEntity.setZwyZwtzsj(e.element("ZWY_ZWTZSJ").getStringValue());
preproPersonEntity.setQfjgGajgmc(e.attributeValue("QFJG_GAJGMC")); preproPersonEntity.setZweZwtxsj(e.element("ZWE_ZWTXSJ").getStringValue());
preproPersonEntity.setYxqqsrq(e.attributeValue("YXQQSRQ")); preproPersonEntity.setZweZwtzsj(e.element("ZWE_ZWTZSJ").getStringValue());
preproPersonEntity.setYxqjzrq(e.attributeValue("YXQJZRQ")); preproPersonEntity.setQfjgGajgmc(e.element("QFJG_GAJGMC").getStringValue());
preproPersonEntity.setJmsfzslyydm(e.attributeValue("JMSFZSLYYDM")); preproPersonEntity.setYxqqsrq(e.element("YXQQSRQ").getStringValue());
preproPersonEntity.setJmsfzzzlxdm(e.attributeValue("JMSFZZZLXDM")); preproPersonEntity.setYxqjzrq(e.element("YXQJZRQ").getStringValue());
preproPersonEntity.setJmsfzlzfsdm(e.attributeValue("JMSFZLZFSDM")); preproPersonEntity.setJmsfzslyydm(e.element("JMSFZSLYYDM").getStringValue());
preproPersonEntity.setSjrXm(e.attributeValue("SJR_XM")); preproPersonEntity.setJmsfzzzlxdm(e.element("JMSFZZZLXDM").getStringValue());
preproPersonEntity.setSjrLxdh(e.attributeValue("SJR_LXDH")); preproPersonEntity.setJmsfzlzfsdm(e.element("JMSFZLZFSDM").getStringValue());
preproPersonEntity.setSjrYzbm(e.attributeValue("SJR_YZBM")); preproPersonEntity.setSjrXm(e.element("SJR_XM").getStringValue());
preproPersonEntity.setSjrTxdz(e.attributeValue("SJR_TXDZ")); preproPersonEntity.setSjrLxdh(e.element("SJR_LXDH").getStringValue());
preproPersonEntity.setSjrYzbm(e.element("SJR_YZBM").getStringValue());
preproPersonEntity.setSjrTxdz(e.element("SJR_TXDZ").getStringValue());
preproPersonEntityList.add(preproPersonEntity); preproPersonEntityList.add(preproPersonEntity);
System.out.println(preproPersonEntity.getJmsfzslh()+"--------------");
} }
resultMap.put("preproPerson",preproPersonEntityList); resultMap.put("preproPerson",preproPersonEntityList);
filesEntity.setRecordNumber((long)recordlist.size()); filesEntity.setRecordNumber((long)recordlist.size());
resultMap.put("file",filesEntity); resultMap.put("file",filesEntity);
......
...@@ -7,6 +7,13 @@ spring: ...@@ -7,6 +7,13 @@ spring:
url: jdbc:oracle:thin:@192.168.1.197:1521:orcl url: jdbc:oracle:thin:@192.168.1.197:1521:orcl
username: yx username: yx
password: yx password: yx
servlet:
multipart:
enabled: true
max-file-size: 20MB
max-request-size: 200MB
mybatis: mybatis:
type-aliases-package: com.yxproject.start.entity type-aliases-package: com.yxproject.start.entity
......
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