Commit b4fbca5b authored by dahai's avatar dahai

Merge remote-tracking branch 'origin/dev' into dev

parents f0a6d7aa 9651b5f6
......@@ -60,7 +60,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.3</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
......
package com.yxproject.start.api;
import com.yxproject.start.entity.FilesEntity;
import com.yxproject.start.entity.PreproPersonEntity;
import com.yxproject.start.service.ImportXmlService;
import com.yxproject.start.utils.IDCardFactory;
import com.yxproject.start.utils.YXJSONResponse;
import com.yxproject.start.utils.YXStringUtils;
import org.apache.catalina.Manager;
import org.apache.tomcat.util.http.fileupload.FileItem;
import org.apache.tomcat.util.http.fileupload.FileUploadException;
import org.apache.tomcat.util.http.fileupload.disk.DiskFileItemFactory;
import org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload;
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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.Context;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -61,7 +59,6 @@ public class ImportXmlApi {
try {
list = upload.parseRequest(requ);
for (FileItem item : list) {
try {
// 如果fileitem中封装的是普通输入项的数据
......@@ -81,11 +78,9 @@ public class ImportXmlApi {
}
InputStream in = item.getInputStream();
String str = YXStringUtils.inputStream2String(in, "utf-8");
in.close();
IDCardFactory idCardFactory = new IDCardFactory();
idcardsFactory(idCardFactory.extractIDCard(str));
}
......@@ -117,65 +112,11 @@ public class ImportXmlApi {
}
private void idcardsFactory(Map<String, Object> map1) {
Map<String, Object> packageMap = (Map<String, Object>) map1.get("package");
PreproPersonEntity preproPersonEntity = new PreproPersonEntity();
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();
private Boolean idcardsFactory(Map<String, Object> map1) {
importXmlService.importPersonXml ((List<PreproPersonEntity>) map1.get("preproPerson"), (FilesEntity) map1.get("file"));
return true;
}
manager.saveSpecialpackageBySpecialpackageEntity(specialpackageEntity);
}
......
package com.yxproject.start.api;
import com.yxproject.start.entity.PreproPersonEntity;
import com.yxproject.start.service.ImportXmlService;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Created by Administrator on 2019/2/15.
*/
@RestController
@RequestMapping("yingxin")
public class YingxinApi {
@Autowired
private ImportXmlService importXmlService;
/*导入XML文件*/
@RequestMapping("importXmlData")
public List<PreproPersonEntity> importXmlData(){
List<PreproPersonEntity> list=new ArrayList<>();
try{
File file = new File("D:\\dengzhou.xml");
// 该文件目录下文件全部放入数组
File[] files = file.listFiles();
if(files!=null){
for(int i=0;i<files.length;i++){
String fileName=files[i].getName();
if(fileName.endsWith("xml")){
SAXReader reader = new SAXReader();
//读取文件到document中
Document doc=reader.read(file);
//获取xml文件的根节点
Element rootElement=doc.getRootElement();
Element data = rootElement.element("DATA");
//定义一个Element用于遍历
Element fooElement;
//遍历所有名叫“RECORD”的节点
for (Iterator j = data.elementIterator("RECORD"); j.hasNext();) {
fooElement = (Element) j.next();
PreproPersonEntity preproPersonEntity = new PreproPersonEntity();
preproPersonEntity.setJmsfzslh(fooElement.elementText("jmsfzslh"));
preproPersonEntity.setGmsfhm(fooElement.elementText("gmsfhm"));
preproPersonEntity.setXm(fooElement.elementText("xm"));
preproPersonEntity.setXbdm(fooElement.elementText("xbdm"));
preproPersonEntity.setMzdm(fooElement.elementText("mzdm"));
preproPersonEntity.setCsrq(fooElement.elementText("csrq"));
preproPersonEntity.setSsxqdm(fooElement.elementText("ssxqdm"));
preproPersonEntity.setDzmc(fooElement.elementText("dzmc"));
preproPersonEntity.setSdxp(fooElement.elementText("sdxp"));
preproPersonEntity.setZwyZwtxsj(fooElement.elementText("zwyZwtxsj"));
preproPersonEntity.setZwyZwtzsj(fooElement.elementText("zwyZwtzsj"));
preproPersonEntity.setZweZwtxsj(fooElement.elementText("zweZwtxsj"));
preproPersonEntity.setZweZwtzsj(fooElement.elementText("zweZwtzsj"));
preproPersonEntity.setQfjgGajgmc(fooElement.elementText("qfjgGajgmc"));
preproPersonEntity.setYxqqsrq(fooElement.elementText("yxqqsrq"));
preproPersonEntity.setYxqjzrq(fooElement.elementText("yxqjzrq"));
preproPersonEntity.setJmsfzslyydm(fooElement.elementText("jmsfzslyydm"));
preproPersonEntity.setJmsfzzzlxdm(fooElement.elementText("jmsfzzzlxdm"));
preproPersonEntity.setJmsfzlzfsdm(fooElement.elementText("jmsfzlzfsdm"));
preproPersonEntity.setSjrXm(fooElement.elementText("sjrXm"));
preproPersonEntity.setSjrLxdh(fooElement.elementText("sjrLxdh"));
preproPersonEntity.setSjrYzbm(fooElement.elementText("sjrYzbm"));
preproPersonEntity.setSjrTxdz(fooElement.elementText("sjrTxdz"));
preproPersonEntity.setSid(fooElement.elementText("sid"));
list.add(preproPersonEntity);
}
ImportXmlService.importPersonXml(list);
}else {
continue;
}
}
}
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return list;
}
}
package com.yxproject.start.mapper;
public interface Analysis {
}
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;
import com.yxproject.start.entity.PreproPersonEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;
......@@ -10,7 +11,11 @@ import org.apache.ibatis.annotations.Update;
@Mapper
public interface PreproPersonMapper {
/*导入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);
/*更新制证数据是否邮寄*/
......
package com.yxproject.start.service;
import com.yxproject.start.entity.FilesEntity;
import com.yxproject.start.entity.PreproPersonEntity;
import java.util.List;
......@@ -10,5 +11,5 @@ import java.util.List;
*/
public interface ImportXmlService {
public boolean importPersonXml(List<PreproPersonEntity> preproPersonEntities);
public boolean importPersonXml(List<PreproPersonEntity> preproPersonEntities,FilesEntity filesEntity);
}
package com.yxproject.start.service.impl;
import com.yxproject.start.entity.FilesEntity;
import com.yxproject.start.entity.PreproPersonEntity;
import com.yxproject.start.mapper.FilesMapper;
import com.yxproject.start.mapper.PreproPersonMapper;
import com.yxproject.start.service.ImportXmlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
......@@ -15,14 +18,19 @@ import java.util.List;
public class ImportXmlServiceImpl implements ImportXmlService {
@Autowired
private PreproPersonMapper preproPersonMapper;
@Autowired
private FilesMapper filesMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public boolean importPersonXml(List<PreproPersonEntity> preproPersonEntities,FilesEntity filesEntity) {
public boolean importPersonXml(List<PreproPersonEntity> preproPersonEntities) {
boolean b = true;
filesMapper.insertFiles(filesEntity);
for (PreproPersonEntity preproPersonEntity:preproPersonEntities){
b = preproPersonMapper.savePreproPersonEntity(preproPersonEntity);
preproPersonMapper.savePreproPersonEntity(preproPersonEntity);
}
return b;
return true;
}
}
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;
import org.dom4j.Element;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.text.SimpleDateFormat;
import java.util.*;
public class IDCardFactory {
......@@ -21,50 +21,66 @@ public class IDCardFactory {
* @return 返回xml包Map
* @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 {
Document document = DocumentHelper.parseText(file);
Element root = document.getRootElement();
Element packagehead = root.element("PACKAGEHEAD");
String SJBBH = packagehead.element("SJBBH").getTextTrim();
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");
int checknum = 0;
for (Element e : recordlist) {
Map<String, Object> personMap = new HashMap<String, Object>();
PreproPersonEntity preproPersonEntity = new PreproPersonEntity();
Element chileEle = e;
personMap.put("sid", e.attributeValue("sid"));
List<Element> personElement = chileEle.elements();
for (Element element : personElement) {
personMap.put(element.getName(), element.getStringValue());
}
personMapList.add(personMap);
checknum++;
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"));
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());
packageMap.put("DWMC", packagehead.element("DWMC").getTextTrim());
packageMap.put("JLS", packagehead.element("JLS").getTextTrim());
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);
resultMap.put("preproPerson",preproPersonEntityList);
filesEntity.setRecordNumber((long)recordlist.size());
resultMap.put("file",filesEntity);
} catch (DocumentException e) {
throw e;
}
return map;
}
public String removeStr(String string) {
String str = string.replace("&#xD; ", "");
return str;
return resultMap;
}
}
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