Commit c2d36cdb authored by dahai's avatar dahai

调试上传文件

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