Commit 6ad6ff58 authored by suichenguang's avatar suichenguang

解析XML包

parent a91e411e
...@@ -60,7 +60,11 @@ ...@@ -60,7 +60,11 @@
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.3</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId> <artifactId>poi</artifactId>
......
package com.yxproject.start.api; package com.yxproject.start.api;
import com.yxproject.start.entity.FilesEntity;
import com.yxproject.start.entity.PreproPersonEntity; import com.yxproject.start.entity.PreproPersonEntity;
import com.yxproject.start.service.ImportXmlService; import com.yxproject.start.service.ImportXmlService;
import com.yxproject.start.utils.IDCardFactory; 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.catalina.Manager; import org.apache.catalina.Manager;
import org.apache.tomcat.util.http.fileupload.FileItem; import org.apache.commons.fileupload.FileItem;
import org.apache.tomcat.util.http.fileupload.FileUploadException; import org.apache.commons.fileupload.FileUploadException;
import org.apache.tomcat.util.http.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.dom4j.DocumentException; import org.dom4j.DocumentException;
import org.dom4j.Element;
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;
...@@ -61,7 +63,6 @@ public class ImportXmlApi { ...@@ -61,7 +63,6 @@ public class ImportXmlApi {
try { try {
list = upload.parseRequest(requ); list = upload.parseRequest(requ);
for (FileItem item : list) { for (FileItem item : list) {
try { try {
// 如果fileitem中封装的是普通输入项的数据 // 如果fileitem中封装的是普通输入项的数据
...@@ -81,11 +82,9 @@ public class ImportXmlApi { ...@@ -81,11 +82,9 @@ public class ImportXmlApi {
} }
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));
} }
...@@ -117,65 +116,11 @@ public class ImportXmlApi { ...@@ -117,65 +116,11 @@ public class ImportXmlApi {
} }
private void idcardsFactory(Map<String, Object> map1) { private Boolean idcardsFactory(Map<String, Object> map1) {
Map<String, Object> packageMap = (Map<String, Object>) map1.get("package"); importXmlService.importPersonXml ((List<PreproPersonEntity>) map1.get("preproPerson"), (FilesEntity) map1.get("file"));
PreproPersonEntity preproPersonEntity = new PreproPersonEntity(); return true;
preproPersonEntity.set
specialpackageEntity.setBbh((String) packageMap.get("BBH"));
specialpackageEntity.setChecknum((Integer) packageMap.get("checknum"));
specialpackageEntity.setCount((Integer) packageMap.get("COUNT"));
specialpackageEntity.setDwdm((String) packageMap.get("DWDM"));
specialpackageEntity.setDwmc((String) packageMap.get("DWMC"));
specialpackageEntity.setJls((String) packageMap.get("JLS"));
specialpackageEntity.setScsj((String) packageMap.get("SCSJ"));
specialpackageEntity.setSjbbh((String) packageMap.get("SJBBH"));
ArrayList<ProductionEntity> arrayList = new ArrayList<ProductionEntity>();
List<Map<String, Object>> personList = (List<Map<String, Object>>) map1.get("person");
for (Map<String, Object> person : personList) {
ProductionEntity productionEntity = new ProductionEntity();
productionEntity.setJmsfzslh((String) person.get("JMSFZSLH"));
productionEntity.setGmsfhm((String) person.get("GMSFHM"));
if (person.get("sid") != null) {
productionEntity.setSid((String) person.get("sid"));
}
productionEntity.setXm((String) person.get("XM"));
productionEntity.setXbdm((String) person.get("XBDM"));
productionEntity.setMzdm((String) person.get("MZDM"));
productionEntity.setCsrq((String) person.get("CSRQ"));
productionEntity.setSsxqdm((String) person.get("SSXQDM"));
productionEntity.setDzmc((String) person.get("DZMC"));
productionEntity.setSdxp((String) person.get("SDXP"));
productionEntity.setZwyZwtxsj((String) person.get("ZWY_ZWTXSJ"));
productionEntity.setZwyZwtzsj((String) person.get("ZWY_ZWTZSJ"));
productionEntity.setZweZwtxsj((String) person.get("ZWE_ZWTXSJ"));
productionEntity.setZweZwtzsj((String) person.get("ZWE_ZWTZSJ"));
productionEntity.setQfjgGajgmc((String) person.get("QFJG_GAJGMC"));
productionEntity.setYxqqsrq((String) person.get("YXQQSRQ"));
productionEntity.setYxqjzrq((String) person.get("YXQJZRQ"));
productionEntity.setJmsfzslyydm((String) person.get("JMSFZSLYYDM"));
productionEntity.setJmsfzzzlxdm((String) person.get("JMSFZZZLXDM"));
productionEntity.setYxLczt(0);
productionEntity.setJmsfzlzfsdm((String) person.get("JMSFZLZFSDM"));
productionEntity.setSjrXm((String) person.get("SJR_XM"));
productionEntity.setSjrLxdh((String) person.get("SJR_LXDH"));
productionEntity.setSjrYzbm((String) person.get("SJR_YZBM"));
productionEntity.setYxSjbh((String) packageMap.get("SJBBH"));
productionEntity.setSjrTxdz((String) person.get("SJR_TXDZ"));
productionEntity.setYxZpzlfk("0");
if (person.get("SJBLX") != null) {
productionEntity.setSjblx((String) person.get("SJBLX"));
}
arrayList.add(productionEntity);
} }
Manager manager = (Manager) SpringBeanUtil.getContext().getBean("manager");
try {
manager.saveProductionEntityByList(arrayList);
} catch (Exception e) {
e.printStackTrace();
}
manager.saveSpecialpackageBySpecialpackageEntity(specialpackageEntity);
}
......
package com.yxproject.start.mapper;
import com.yxproject.start.entity.FilesEntity;
import org.apache.ibatis.annotations.Insert;
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})")
public boolean insertFiles(FilesEntity filesEntity);
}
package com.yxproject.start.mapper; package com.yxproject.start.mapper;
import com.yxproject.start.entity.PreproPersonEntity; import com.yxproject.start.entity.PreproPersonEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update; import org.apache.ibatis.annotations.Update;
...@@ -10,7 +11,11 @@ import org.apache.ibatis.annotations.Update; ...@@ -10,7 +11,11 @@ import org.apache.ibatis.annotations.Update;
@Mapper @Mapper
public interface PreproPersonMapper { public interface PreproPersonMapper {
/*导入XMl*/ /*导入XMl*/
@Update("UPDATE PREPRO_PERSON SET JMSFZSLH=#{jmsfzslh},GMSFHM=#{gmsfhm},XM=#{xm},XBDM=#{xbdm},MZDM=#{mzdm},CSRQ=#{csrq},SSXQDM=#{ssxqdm},DZMC=#{dzmc},SDXP=#{sdxp},ZWY_ZWTXSJ=#{zwyZwtxsj},ZWY_ZWTZSJ=#{zwyZwtzsj},ZWE_ZWTXSJ=#{zweZwtxsj},ZWE_ZWTZSJ=#{zweZwtzsj},QFJG_GAJGMC=#{qfjgGajgmc},YXQQSRQ=#{yxqqsrq},YXQJZRQ=#{yxqjzrq},JMSFZSLYYDM=#{jmsfzslyydm},JMSFZZZLXDM=#{jmsfzzzlxdm},JMSFZLZFSDM=#{jmsfzlzfsdm},SJR_XM=#{sjrXm},SJR_LXDH=#{sjrLxdh},SJR_YZBM=#{sjrYzbm},SJR_TXDZ=#{sjrTxdz},SID=#{sid},FILE_NAME=#{fileName} where JMSFZSLH=#{jmsfzslh}") @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,)" +
"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}")
public boolean savePreproPersonEntity(PreproPersonEntity personEntity); public boolean savePreproPersonEntity(PreproPersonEntity personEntity);
/*更新制证数据是否邮寄*/ /*更新制证数据是否邮寄*/
......
package com.yxproject.start.service; package com.yxproject.start.service;
import com.yxproject.start.entity.FilesEntity;
import com.yxproject.start.entity.PreproPersonEntity; import com.yxproject.start.entity.PreproPersonEntity;
import java.util.List; import java.util.List;
...@@ -10,5 +11,5 @@ import java.util.List; ...@@ -10,5 +11,5 @@ import java.util.List;
*/ */
public interface ImportXmlService { public interface ImportXmlService {
public boolean importPersonXml(List<PreproPersonEntity> preproPersonEntities); public boolean importPersonXml(List<PreproPersonEntity> preproPersonEntities,FilesEntity filesEntity);
} }
package com.yxproject.start.service.impl; package com.yxproject.start.service.impl;
import com.yxproject.start.entity.FilesEntity;
import com.yxproject.start.entity.PreproPersonEntity; import com.yxproject.start.entity.PreproPersonEntity;
import com.yxproject.start.mapper.FilesMapper;
import com.yxproject.start.mapper.PreproPersonMapper; import com.yxproject.start.mapper.PreproPersonMapper;
import com.yxproject.start.service.ImportXmlService; import com.yxproject.start.service.ImportXmlService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
...@@ -15,14 +18,19 @@ import java.util.List; ...@@ -15,14 +18,19 @@ import java.util.List;
public class ImportXmlServiceImpl implements ImportXmlService { public class ImportXmlServiceImpl implements ImportXmlService {
@Autowired @Autowired
private PreproPersonMapper preproPersonMapper; private PreproPersonMapper preproPersonMapper;
@Autowired
private FilesMapper filesMapper;
@Override @Override
@Transactional(rollbackFor = Exception.class)
public boolean importPersonXml(List<PreproPersonEntity> preproPersonEntities,FilesEntity filesEntity) {
public boolean importPersonXml(List<PreproPersonEntity> preproPersonEntities) { filesMapper.insertFiles(filesEntity);
boolean b = true;
for (PreproPersonEntity preproPersonEntity:preproPersonEntities){ for (PreproPersonEntity preproPersonEntity:preproPersonEntities){
b = preproPersonMapper.savePreproPersonEntity(preproPersonEntity); preproPersonMapper.savePreproPersonEntity(preproPersonEntity);
} }
return b; return true;
} }
} }
package com.yxproject.start.utils; 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.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;
import org.dom4j.Element; import org.dom4j.Element;
import java.util.ArrayList; import java.text.SimpleDateFormat;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Map;
public class IDCardFactory { public class IDCardFactory {
...@@ -21,50 +21,66 @@ public class IDCardFactory { ...@@ -21,50 +21,66 @@ public class IDCardFactory {
* @return 返回xml包Map * @return 返回xml包Map
* @throws Exception * @throws Exception
*/ */
public List<PreproPersonEntity> extractIDCard(String file) throws Exception { public Map<String, Object> extractIDCard(String file) throws Exception {
List<Map<String, Object>> personMapList = new ArrayList<Map<String, Object>>(); Map<String,Object> resultMap = new HashMap<>();
List<PreproPersonEntity> preproPersonEntityList = new ArrayList<>();
FilesEntity filesEntity = new FilesEntity();
try { try {
Document document = DocumentHelper.parseText(file); Document document = DocumentHelper.parseText(file);
Element root = document.getRootElement(); Element root = document.getRootElement();
Element packagehead = root.element("PACKAGEHEAD"); Element packagehead = root.element("PACKAGEHEAD");
String SJBBH = packagehead.element("SJBBH").getTextTrim(); String SJBBH = packagehead.element("SJBBH").getTextTrim();
Element records = root.element("DATA"); Element records = root.element("DATA");
filesEntity.setSourceFileName(SJBBH);
String DWDM = packagehead.element("DWDM").getTextTrim();
filesEntity.setDwdm(DWDM);
String DWMC = packagehead.element("DWMC").getTextTrim();
filesEntity.setDwdm(DWMC);
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
filesEntity.setCreatTime(simpleDateFormat.format(date));
List<Element> recordlist = records.elements("RECORD"); List<Element> recordlist = records.elements("RECORD");
int checknum = 0;
for (Element e : recordlist) { for (Element e : recordlist) {
Map<String, Object> personMap = new HashMap<String, Object>(); PreproPersonEntity preproPersonEntity = new PreproPersonEntity();
Element chileEle = e; Element chileEle = e;
personMap.put("sid", e.attributeValue("sid")); preproPersonEntity.setJmsfzslh( e.attributeValue("JMSFZSLH"));
List<Element> personElement = chileEle.elements(); preproPersonEntity.setGmsfhm(e.attributeValue("JMSFZSLH"));
for (Element element : personElement) { preproPersonEntity.setSid(e.attributeValue("sid"));
personMap.put(element.getName(), element.getStringValue()); preproPersonEntity.setXm(e.attributeValue("XM"));
} preproPersonEntity.setXbdm(e.attributeValue("XBDM"));
preproPersonEntity.setMzdm(e.attributeValue("MZDM"));
personMapList.add(personMap); preproPersonEntity.setCsrq(e.attributeValue("CSRQ"));
checknum++; 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"));
preproPersonEntityList.add(preproPersonEntity);
} }
Map<String, Object> packageMap = new HashMap<String, Object>();
packageMap.put("BBH", packagehead.element("BBH").getTextTrim());
packageMap.put("DWDM", packagehead.element("DWDM").getTextTrim()); resultMap.put("preproPerson",preproPersonEntityList);
packageMap.put("DWMC", packagehead.element("DWMC").getTextTrim()); filesEntity.setRecordNumber((long)recordlist.size());
packageMap.put("JLS", packagehead.element("JLS").getTextTrim()); resultMap.put("file",filesEntity);
packageMap.put("COUNT", 0);
packageMap.put("SCSJ", packagehead.element("SCSJ").getTextTrim());
packageMap.put("SJBBH", SJBBH);
packageMap.put("checknum", checknum);
map.put("package", packageMap);
map.put("person", personMapList);
} catch (DocumentException e) { } catch (DocumentException e) {
throw e; throw e;
} }
return map; return resultMap;
}
public String removeStr(String string) {
String str = string.replace("&#xD; ", "");
return str;
} }
} }
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