Commit 7efbdb4f authored by dahai's avatar dahai

添加 并修改生成xml数据包

parent 3b14f791
package com.yxproject.start.api;
import com.yxproject.start.service.DetailReceiptListService;
import com.yxproject.start.service.ReceiptService;
import com.yxproject.start.utils.ExportExcel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -9,6 +12,13 @@ import java.util.List;
@RestController
@RequestMapping("exportExcel")
public class ExportExcelApi {
@Autowired
private ReceiptService receiptService;
@Autowired
private DetailReceiptListService detailReceiptListService;
public Byte[] exportExcel(){
return null;
}
......
......@@ -7,6 +7,7 @@ import com.yxproject.start.service.FilesService;
import com.yxproject.start.service.NewFilesService;
import com.yxproject.start.service.PreproPersonService;
import com.yxproject.start.utils.QuerySequenceSercive;
import com.yxproject.start.utils.ZipUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
......@@ -22,6 +23,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.zip.ZipOutputStream;
/**
* @auther zhangyusheng
......@@ -46,16 +48,9 @@ public class ExportXMLApi {
@RequestMapping("printXmlData")
// @RequiresPermissions("userInfo.add")//权限管理;
public byte[] printXmlData(@RequestParam("uploadNo") String uploadNo, @RequestParam("IDCard")String IDCard,@RequestParam("oldFile") String oldFile, @RequestParam("newFile")String newFile, @RequestParam("SSXQDM")String SSXQDM, @RequestParam("cardType")String cardType, @RequestParam("state")String state, @RequestParam("uploadDate")String uploadDate, HttpServletResponse response) {
response.setContentType("application/x-download");
response.setCharacterEncoding("UTF-8");
String dateTime = DateFormatUtils.format(new Date(), "yyyyMMddHH");
//使用Servlet实现文件下载的时候,避免浏览器自动打开文件
String fout = null;
List<PreproPersonEntity> preproPersonEntities = preproPersonService.selectAllPreproPerson(uploadNo, IDCard, oldFile, newFile, SSXQDM, cardType, state, replaceDate(uploadDate));
if (preproPersonEntities.size()>0){
//todo 查询制证数据包信息
//将制证详情详细划分
Map<Long,Object> map = new LinkedHashMap<>();
for (PreproPersonEntity preproPersonEntity:preproPersonEntities){
......@@ -76,9 +71,8 @@ public class ExportXMLApi {
List<PreproPersonEntity> preproPersonEntityList =(List<PreproPersonEntity>)map.get(cardTypeId);
Map<Long,Object> mapFileId = new LinkedHashMap<>();
for (PreproPersonEntity preproPersonEntity:preproPersonEntityList){
if (mapFileId!=null&&mapFileId.containsKey(preproPersonEntity.getFileId())){
List<PreproPersonEntity> preproPersonEntityListFileId = (List<PreproPersonEntity>)map.get(preproPersonEntity.getFileId());
List<PreproPersonEntity> preproPersonEntityListFileId = (List<PreproPersonEntity>)mapFileId.get(preproPersonEntity.getFileId());
preproPersonEntityListFileId.add(preproPersonEntity);
mapFileId.put(preproPersonEntity.getFileId(),preproPersonEntityListFileId);
}else {
......@@ -90,16 +84,17 @@ public class ExportXMLApi {
list.add(mapFileId);
lists.add(list);
}
//TODO
List<String> documentList = new ArrayList<>();
//执行生成XML文件方法
for(List<Map<Long,Object>> mapList :lists){
for (Map<Long,Object> objectMap :mapList){
for (Long fileId :objectMap.keySet()){
List<PreproPersonEntity> preproPersonEntityList =(List<PreproPersonEntity>)map.get(fileId);
List<PreproPersonEntity> preproPersonEntityList =(List<PreproPersonEntity>)objectMap.get(fileId);
int i =0;
List<List> listList = new ArrayList<>();
List list = new ArrayList();
for (PreproPersonEntity preproPersonEntity : preproPersonEntityList){
for (int a= 0;a<preproPersonEntityList.size();a++){
PreproPersonEntity preproPersonEntity = preproPersonEntityList.get(a);
list.add(preproPersonEntity);
i++;
if (i<80){
......@@ -109,6 +104,9 @@ public class ExportXMLApi {
list = new ArrayList();
i=0;
}
if (list.size()>0&&a==preproPersonEntityList.size()-1){
listList.add(list);
}
}
for (List list1 :listList) {
List<PreproPersonEntity> preproPersonEntityList1 = (List<PreproPersonEntity>)list1;
......@@ -116,32 +114,43 @@ public class ExportXMLApi {
FilesEntity filesEntity =filesEntities.get(0);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
filesEntity.setCreateTime(simpleDateFormat.format(new Date()));
String xml = null;
try {
fout = createToMakePackageXML(preproPersonEntityList1, filesEntity, "\\zhang");
xml = createToMakePackageXML(preproPersonEntityList1, filesEntity, "\\zhang");
} catch (IOException e) {
e.printStackTrace();
}
String outFile = dateTime + "制证数据包";
documentList.add(xml);
}
}
}
}
// -----制证包数据打包下载
String zipName = "myfile.zip";
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition","attachment; filename="+zipName);
ZipOutputStream out = null;
try {
FileInputStream fis = new FileInputStream(new File(fout));
byte[] b = new byte[fis.available()];
fis.read(b);
fis.close();
response.addHeader("Content-Disposition", "attachment;filename=" + outFile + ".xml");
return b;
} catch (FileNotFoundException e) {
e.printStackTrace();
out = new ZipOutputStream(response.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
try {
for(String document :documentList){
ZipUtils.doCompress(document, out);
response.flushBuffer();
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
......@@ -184,7 +193,7 @@ public class ExportXMLApi {
newFilesEntity.setVersionCode(filesEntity.getVersionCode());
newFilesEntity.setRecordNumber((long)preproPersonEntities.size());
long l = newFilesService.saveNewFiles(newFilesEntity);
newFilesEntity.setNewFileName(simpleDateFormat.format(new Date())+"-"+l);
newFilesEntity.setNewFileName(simpleDateFormat.format(new Date())+"-"+newFilesEntity.getId());
newFilesService.saveNewFiles(newFilesEntity);
int NO=1;
......@@ -242,7 +251,7 @@ public class ExportXMLApi {
preproPersonEntity.setNewFileId(newFilesEntity.getId());
}
preproPersonService.updatePreproPerson_NewFileName(preproPersonEntities);
String files_seq = querySequenceSercive.selectSequenceNextValue("FILES_SEQ");
String files_seq = newFilesEntity.getId()+"";
FileOutputStream fout = null;
try {
FileOutputStream fos = new FileOutputStream("D:\\XML\\" + simpleDateFormat.format(new Date())+"-"+files_seq+ ".xml");
......@@ -261,7 +270,10 @@ public class ExportXMLApi {
}
System.out.println("XML文件生成成功..." + new Date());
return "D:\\XML\\" + simpleDateFormat.format(new Date())+"-"+l+ ".xml";
// return document;
return "D:\\XML\\" + simpleDateFormat.format(new Date())+"-"+files_seq+ ".xml";
}
/**
......
......@@ -5,7 +5,7 @@ import java.util.Objects;
/**
* @auther zhangyusheng
* 2019/3/10 14:52
* 2019/3/12 11:05
*/
@Entity
@Table(name = "DETAIL_RECEIPT_LIST", schema = "YINGXIN", catalog = "")
......@@ -18,6 +18,7 @@ public class DetailReceiptListEntity {
private String cardId;
private String note;
private String signGovt;
private Long receiptId;
@Id
@Column(name = "ID")
......@@ -99,6 +100,16 @@ public class DetailReceiptListEntity {
this.signGovt = signGovt;
}
@Basic
@Column(name = "RECEIPT_ID")
public Long getReceiptId() {
return receiptId;
}
public void setReceiptId(Long receiptId) {
this.receiptId = receiptId;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
......@@ -111,11 +122,12 @@ public class DetailReceiptListEntity {
Objects.equals(policeCode, that.policeCode) &&
Objects.equals(cardId, that.cardId) &&
Objects.equals(note, that.note) &&
Objects.equals(signGovt, that.signGovt);
Objects.equals(signGovt, that.signGovt) &&
Objects.equals(receiptId, that.receiptId);
}
@Override
public int hashCode() {
return Objects.hash(id, uploadNo, acceptNo, name, policeCode, cardId, note, signGovt);
return Objects.hash(id, uploadNo, acceptNo, name, policeCode, cardId, note, signGovt, receiptId);
}
}
......@@ -13,6 +13,6 @@ import java.util.Map;
*/
@Mapper
public interface QuerySequenceMapper {
@Select("select #{sequenceName},#{sequenceName} as num2 from dual")
public List<Map<String,Object>> selectSequenceNextValue(@Param("sequenceName") String sequenceName);
@Select("select #{sequenceName} from dual")
public int selectSequenceNextValue(@Param("sequenceName") String sequenceName);
}
......@@ -17,8 +17,16 @@ public class QuerySequenceSercive {
private QuerySequenceMapper querySequenceMapper;
public String selectSequenceNextValue(String sequenceName){
List<Map<String, Object>> mapList = querySequenceMapper.selectSequenceNextValue(sequenceName + ".nextval");
return mapList.get(0).get("NUM2").toString();
// List<Map<String, Object>> mapList = querySequenceMapper.selectSequenceNextValue(sequenceName + ".nextval");
// System.out.println(mapList.get(0)+"--------");
// System.out.println(mapList.get(0).keySet());
// for (String string :mapList.get(0).keySet()){
//
// }
// return mapList.get(0).get("NUM2").toString();
int i = querySequenceMapper.selectSequenceNextValue(sequenceName + ".nextval");
System.out.println(i);
return null;
}
......
package com.yxproject.start.utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* @auther zhangyusheng
* 2019/3/12 12:27
*/
public class ZipUtils {
private ZipUtils(){
}
public static void doCompress(String srcFile, String zipFile) throws IOException {
doCompress(new File(srcFile), new File(zipFile));
}
/**
* 文件压缩
* @param srcFile 目录或者单个文件
* @param zipFile 压缩后的ZIP文件
*/
public static void doCompress(File srcFile, File zipFile) throws IOException {
ZipOutputStream out = null;
try {
out = new ZipOutputStream(new FileOutputStream(zipFile));
doCompress(srcFile, out);
} catch (Exception e) {
throw e;
} finally {
out.close();//记得关闭资源
}
}
public static void doCompress(String filelName, ZipOutputStream out) throws IOException{
doCompress(new File(filelName), out);
}
public static void doCompress(File file, ZipOutputStream out) throws IOException{
doCompress(file, out, "");
}
public static void doCompress(File inFile, ZipOutputStream out, String dir) throws IOException {
if ( inFile.isDirectory() ) {
File[] files = inFile.listFiles();
if (files!=null && files.length>0) {
for (File file : files) {
String name = inFile.getName();
if (!"".equals(dir)) {
name = dir + "/" + name;
}
ZipUtils.doCompress(file, out, name);
}
}
} else {
ZipUtils.doZip(inFile, out, dir);
}
}
public static void doZip(File inFile, ZipOutputStream out, String dir) throws IOException {
String entryName = null;
if (!"".equals(dir)) {
entryName = dir + "/" + inFile.getName();
} else {
entryName = inFile.getName();
}
ZipEntry entry = new ZipEntry(entryName);
out.putNextEntry(entry);
int len = 0 ;
byte[] buffer = new byte[1024];
FileInputStream fis = new FileInputStream(inFile);
while ((len = fis.read(buffer)) > 0) {
out.write(buffer, 0, len);
out.flush();
}
out.closeEntry();
fis.close();
}
}
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