Commit ca5bdec9 authored by dahai's avatar dahai

修改下载XML包文件

parent e73699a3
......@@ -3,8 +3,10 @@ package com.yxproject.start.api;
import com.yxproject.start.entity.FilesEntity;
import com.yxproject.start.entity.NewFilesEntity;
import com.yxproject.start.entity.PreproPersonEntity;
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 org.apache.commons.lang.time.DateFormatUtils;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
......@@ -19,9 +21,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.*;
/**
* @auther zhangyusheng
......@@ -34,6 +34,11 @@ public class ExportXMLApi {
private PreproPersonService preproPersonService;
@Autowired
private NewFilesService newFilesService;
@Autowired
private FilesService filesService;
@Autowired
private QuerySequenceSercive querySequenceSercive;
/**
* 导出制证数据包
......@@ -46,39 +51,105 @@ public class ExportXMLApi {
String dateTime = DateFormatUtils.format(new Date(), "yyyyMMddHH");
//使用Servlet实现文件下载的时候,避免浏览器自动打开文件
String fout = null;
//todo 更改查询条件
List<PreproPersonEntity> preproPersonEntities = new ArrayList<>();
// List<PreproPersonEntity> preproPersonEntities = preproPersonService.selectPreproPerson(uploadNo, IDCard, oldFile, newFile, SSXQDM, cardType, state, uploadDate);
if (preproPersonEntities.size()>0){
List<PreproPersonEntity> preproPersonEntities = preproPersonService.selectAllPreproPerson(uploadNo, IDCard, oldFile, newFile, SSXQDM, cardType, state, uploadDate);
if (preproPersonEntities.size()>0){
//todo 查询制证数据包信息
FilesEntity filesEntity = new FilesEntity();
filesEntity.setVersionCode("3.00");
filesEntity.setDwdm("410600000000");
filesEntity.setDwmc("北京市公安局");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
filesEntity.setCreateTime(simpleDateFormat.format(new Date()));
try {
fout = createToMakePackageXML(preproPersonEntities, filesEntity, "\\zhang");
} catch (IOException e) {
e.printStackTrace();
}
String outFile = dateTime + "制证数据包";
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();
} catch (IOException e) {
e.printStackTrace();
}
}else {
//将制证详情详细划分
Map<Long,Object> map = new LinkedHashMap<>();
for (PreproPersonEntity preproPersonEntity:preproPersonEntities){
if (map!=null&&map.containsKey(preproPersonEntity.getCardTypeId())){
List<PreproPersonEntity> preproPersonEntityList = (List<PreproPersonEntity>)map.get(preproPersonEntity.getCardTypeId());
preproPersonEntityList.add(preproPersonEntity);
map.put(preproPersonEntity.getCardTypeId(),preproPersonEntityList);
}else {
List<PreproPersonEntity> preproPersonEntityList =new ArrayList<>();
preproPersonEntityList.add(preproPersonEntity);
map.put(preproPersonEntity.getCardTypeId(),preproPersonEntityList);
}
}
List<List<Map<Long,Object>>> lists = new ArrayList<>();
for (Long cardTypeId :map.keySet()){
List list = new ArrayList();
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());
preproPersonEntityListFileId.add(preproPersonEntity);
mapFileId.put(preproPersonEntity.getFileId(),preproPersonEntityListFileId);
}else {
List<PreproPersonEntity> preproPersonEntityListFileId =new ArrayList<>();
preproPersonEntityListFileId.add(preproPersonEntity);
mapFileId.put(preproPersonEntity.getFileId(),preproPersonEntityListFileId);
}
}
list.add(mapFileId);
lists.add(list);
}
//TODO
//执行生成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);
int i =0;
List<List> listList = new ArrayList<>();
List list = new ArrayList();
for (PreproPersonEntity preproPersonEntity : preproPersonEntityList){
list.add(preproPersonEntity);
i++;
if (i<80){
}else {
listList.add(list);
list = new ArrayList();
i=0;
}
}
for (List list1 :listList) {
List<PreproPersonEntity> preproPersonEntityList1 = (List<PreproPersonEntity>)list1;
List<FilesEntity> filesEntities = filesService.selectFilesEntityById(preproPersonEntityList1.get(0).getFileId().toString());
FilesEntity filesEntity =filesEntities.get(0);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
filesEntity.setCreateTime(simpleDateFormat.format(new Date()));
try {
fout = createToMakePackageXML(preproPersonEntityList1, filesEntity, "\\zhang");
} catch (IOException e) {
e.printStackTrace();
}
String outFile = dateTime + "制证数据包";
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();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
}
return null;
}
......@@ -89,7 +160,6 @@ public class ExportXMLApi {
* @throws IOException 可能出现文件写入不成功
*/
public String createToMakePackageXML(List<PreproPersonEntity> preproPersonEntities , FilesEntity filesEntity, String url) throws IOException {
//todo 添加生成新包 回写到个人制证信息表中
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyyMMddhhmmss");
Document document = DocumentHelper.createDocument();
......@@ -115,7 +185,7 @@ public class ExportXMLApi {
newFilesEntity.setRecordNumber((long)preproPersonEntities.size());
long l = newFilesService.saveNewFiles(newFilesEntity);
newFilesEntity.setNewFileName(simpleDateFormat.format(new Date())+"-"+l);
newFilesService.updateNewFileName(newFilesEntity);
newFilesService.saveNewFiles(newFilesEntity);
int NO=1;
for (PreproPersonEntity preproPersonEntity : preproPersonEntities) {
......@@ -169,12 +239,13 @@ public class ExportXMLApi {
Element SJR_TXDZ = RECORD.addElement("SJR_TXDZ");
SJR_TXDZ.setText(replaceNullString(preproPersonEntity.getSjrTxdz()));
NO++;
preproPersonEntity.setNewFileId(l);
preproPersonEntity.setNewFileId(newFilesEntity.getId());
}
preproPersonService.updatePreproPerson_NewFileName(preproPersonEntities);
String files_seq = querySequenceSercive.selectSequenceNextValue("FILES_SEQ");
FileOutputStream fout = null;
try {
FileOutputStream fos = new FileOutputStream("D:\\XML\\" + simpleDateFormat.format(new Date())+"-"+l+ ".xml");
FileOutputStream fos = new FileOutputStream("D:\\XML\\" + simpleDateFormat.format(new Date())+"-"+files_seq+ ".xml");
OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
OutputFormat of = new OutputFormat();
of.setEncoding("UTF-8");
......
......@@ -50,4 +50,12 @@ public interface FilesMapper {
"</script>"})
public List<CountDataEntity> selectFilesCount(@Param("importDate") String importDate);
/**
* 查询XML文件包详情
*
* @param fileId
* @return
*/
@Select("select * from files where id = #{fileId}")
public List<FilesEntity> selectFilesEntity(@Param("fileId")String fileId);
}
......@@ -17,6 +17,7 @@ public interface PersonPostMapper {
"( WAYBILL_NUMBER,BACK_WAYBILL_NUMBER,ORDER_NUMBER,CREATE_DATE,OPENID,WC_PLAY_ORDER_NUMBER,PLAY_STATE,ORDER_STATE,APPLICANT_NAME,SENDER_NAME,SENDER_PHONE,SENDER_ADDRESS,RECIPIENT_NAME,RECIPIENT_PHONE,RECIPIENT_ADDRESS,ORDER_BLANK_NUMBER,GET_TO_PROVINCE,GET_TO_CITY,GET_TO_COUNTY,BUSINESS_TYPE,LATTICE_MOUTH_INFORMATION,NATURE_OF_THE_INTERNAL,NATURE_OF_THE_INFORMATION,FIRST_WHITE,FILE_ID) " +
"values " +
"(#{waybillNumber},#{backWaybillNumber},#{orderNumber},#{createDate},#{openid},#{wcPlayOrderNumber},#{playState},#{orderState},#{applicantName},#{senderName},#{senderPhone},#{senderAddress},#{recipientName},#{recipientPhone},#{recipientAddress},#{orderBlankNumber},#{getToProvince},#{getToCity},#{getToCounty},#{businessType},#{latticeMouthInformation},#{natureOfTheInternal},#{natureOfTheInformation},#{firstWhite},#{fileId})")
@Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
public boolean savePersonPost(PersonPostEntity personPostEntity);
@Update("update prepro_person p set IS_POST=9 where p.JMSFZSLH in ( select p.JMSFZSLH from prepro_person p left join files files on p.file_id=files.ID \n" +
......
......@@ -4,6 +4,9 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;
/**
* @auther zhangyusheng
* 2019/3/1 15:01
......@@ -11,5 +14,5 @@ import org.apache.ibatis.annotations.Select;
@Mapper
public interface QuerySequenceMapper {
@Select("select #{sequenceName},#{sequenceName} as num2 from dual")
public Object[] selectSequenceNextValue(@Param("sequenceName") String sequenceName);
public List<Map<String,Object>> selectSequenceNextValue(@Param("sequenceName") String sequenceName);
}
package com.yxproject.start.service;
import com.yxproject.start.entity.FilesEntity;
import java.util.List;
/**
* @auther zhangyusheng
* 2019/3/11 15:08
*/
public interface FilesService {
public List<FilesEntity> selectFilesEntityById(String id);
}
package com.yxproject.start.service.impl;
import com.yxproject.start.entity.FilesEntity;
import com.yxproject.start.mapper.FilesMapper;
import com.yxproject.start.service.FilesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @auther zhangyusheng
* 2019/3/11 15:08
*/
@Service
public class FilesServiceImpl implements FilesService {
@Autowired
private FilesMapper filesMapper;
/**
* 查询xml原文件名详细信息
*
* @param id
* @return
*/
public List<FilesEntity> selectFilesEntityById(String id){
return filesMapper.selectFilesEntity(id);
}
}
......@@ -58,7 +58,8 @@ public class PreproPersonServiceImpl implements PreproPersonService {
*/
@Override
public List<PreproPersonEntity> selectAllPreproPerson(String uploadNo, String IDCard, String oldFile, String newFile, String SSXQDM, String cardType, String state, String uploadDate) {
return null;
List<PreproPersonEntity> preproPersonEntities = preproPersonMapper.selectPreproPersonCount(replace(uploadNo), replace(IDCard), replace(oldFile), replace(newFile), replace(SSXQDM), replace(cardType), replace(state), replace(uploadDate));
return preproPersonEntities;
}
/**
......
......@@ -4,6 +4,9 @@ import com.yxproject.start.mapper.QuerySequenceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
/**
* @auther zhangyusheng
* 2019/3/1 14:54
......@@ -12,9 +15,10 @@ import org.springframework.stereotype.Service;
public class QuerySequenceSercive {
@Autowired
private QuerySequenceMapper querySequenceMapper;
public String selectSequenceNextValue(String sequenceName){
Object[] objects = querySequenceMapper.selectSequenceNextValue(sequenceName + ".nextval");
return "";
List<Map<String, Object>> mapList = querySequenceMapper.selectSequenceNextValue(sequenceName + ".nextval");
return mapList.get(0).get("NUM2").toString();
}
......
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