|
|
@@ -29,6 +29,7 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.cglib.beans.BeanMap;
|
|
|
+import org.springframework.core.io.UrlResource;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
@@ -36,6 +37,7 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.*;
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
import java.net.HttpURLConnection;
|
|
|
+import java.net.MalformedURLException;
|
|
|
import java.net.URL;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
@@ -99,6 +101,8 @@ public class FinanceRecordController extends BaseController {
|
|
|
private IZcFinanceProComRelService iZcFinanceProComRelService;
|
|
|
@Autowired
|
|
|
private ApprovalService approvalService;
|
|
|
+ @Autowired
|
|
|
+ private IZcFinanceRecordFileRelService financeRecordFileRelService;
|
|
|
// 开始流程
|
|
|
public final static String STRART_FLOW = "flow/strartFlow";
|
|
|
|
|
|
@@ -582,6 +586,8 @@ public class FinanceRecordController extends BaseController {
|
|
|
List<PubFileInf> otherFileList = new ArrayList<>();
|
|
|
//融信相关文件
|
|
|
List<PubFileInf> financeFileList = new ArrayList<>();
|
|
|
+ //融资相关文件
|
|
|
+ List<PubFileInf> recordFileList = new ArrayList<>();
|
|
|
//提取收付款编号
|
|
|
List<String> zbiIdList = CommonUtil.getIdFromList(billInfList,"zbiId");
|
|
|
//发票与收付款相关
|
|
|
@@ -637,18 +643,30 @@ public class FinanceRecordController extends BaseController {
|
|
|
}
|
|
|
//融信附件关联表
|
|
|
LambdaQueryWrapper<ZcFinanceFileRel> financeFileRelWrapper = new LambdaQueryWrapper<>();
|
|
|
- financeFileRelWrapper.in(ZcFinanceFileRel::getZffrFinanceId,zbiIdList);
|
|
|
+ financeFileRelWrapper.in(ZcFinanceFileRel::getZffrFinanceId,zfrFinanceId);
|
|
|
List<ZcFinanceFileRel> fileRelList = iZcFinanceFileRelService.findZcFinanceFileRels(financeFileRelWrapper);
|
|
|
//不为空
|
|
|
if (fileRelList.size() > 0){
|
|
|
//提取文件编号
|
|
|
- List<String> idList = CommonUtil.getIdFromList(fileRelList,"zbfrFileId");
|
|
|
+ List<String> idList = CommonUtil.getIdFromList(fileRelList,"zffrFileId");
|
|
|
LambdaQueryWrapper<PubFileInf> fileInfLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
fileInfLambdaQueryWrapper.in(PubFileInf::getPfiFileId,idList);
|
|
|
fileInfLambdaQueryWrapper.eq(PubFileInf::getPfiIsDel,"00");
|
|
|
financeFileList = fileInfService.findPubFileInfs(fileInfLambdaQueryWrapper);
|
|
|
}
|
|
|
- String directory = configService.selectConfigByKey("zc_record_file").getMsg();
|
|
|
+ //融资附件关联表
|
|
|
+ LambdaQueryWrapper<ZcFinanceRecordFileRel> recordFileRelWrapper = new LambdaQueryWrapper<>();
|
|
|
+ recordFileRelWrapper.in(ZcFinanceRecordFileRel::getZfrfrFinanceId,zfrFinanceId);
|
|
|
+ List<ZcFinanceRecordFileRel> recordRelList = financeRecordFileRelService.findZcFinanceRecordFileRels(recordFileRelWrapper);
|
|
|
+ //不为空
|
|
|
+ if (recordRelList.size() > 0){
|
|
|
+ //提取文件编号
|
|
|
+ List<String> idList = CommonUtil.getIdFromList(recordRelList,"zfrfrFileId");
|
|
|
+ LambdaQueryWrapper<PubFileInf> fileInfLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ fileInfLambdaQueryWrapper.in(PubFileInf::getPfiFileId,idList);
|
|
|
+ fileInfLambdaQueryWrapper.eq(PubFileInf::getPfiIsDel,"00");
|
|
|
+ recordFileList = fileInfService.findPubFileInfs(fileInfLambdaQueryWrapper);
|
|
|
+ }
|
|
|
|
|
|
for (int i = 0; i < otherFileList.size(); i++) {
|
|
|
Map map = new HashMap();
|
|
|
@@ -691,17 +709,89 @@ public class FinanceRecordController extends BaseController {
|
|
|
map.put("pfiFileName",pfiFileName);
|
|
|
list.add(map);
|
|
|
}
|
|
|
+ for (int z = 0; z < recordFileList.size(); z++) {
|
|
|
+ Map map = new HashMap();
|
|
|
+ //文件路径
|
|
|
+ String pfiFileUrl = recordFileList.get(z).getPfiFileUrl();
|
|
|
+ //文件名称
|
|
|
+ String pfiFileName = recordFileList.get(z).getPfiFileName();
|
|
|
+ map.put("pfiFileUrl",pfiFileUrl);
|
|
|
+ map.put("pfiFileName",pfiFileName);
|
|
|
+ list.add(map);
|
|
|
+ }
|
|
|
+ String directory = configService.selectConfigByKey("zc_record_file").getMsg();
|
|
|
for (int l = 0; l < list.size(); l++) {
|
|
|
String files = list.get(l).get("pfiFileUrl");
|
|
|
String names = list.get(l).get("pfiFileName");
|
|
|
- downloadFile(files, directory+ names,directory);
|
|
|
+// downloadFile(files, directory+ names,directory);
|
|
|
+ }
|
|
|
+ //存放--服务器上zip文件的目录
|
|
|
+ File directoryFile=new File(directory);
|
|
|
+ if(!directoryFile.isDirectory() && !directoryFile.exists()){
|
|
|
+ directoryFile.mkdirs();
|
|
|
+ }
|
|
|
+ String zipFileName = "rzgl"+DateUtils.dateTimeNow()+ ".zip";
|
|
|
+ String strZipPath = directory+zipFileName;
|
|
|
+ //输出流
|
|
|
+ ZipOutputStream zipStream = null;
|
|
|
+ //新建
|
|
|
+ File zipFile = new File(strZipPath);
|
|
|
+ //文件压缩
|
|
|
+ try{
|
|
|
+ //构造最终压缩包的输出流
|
|
|
+ zipStream = new ZipOutputStream(new FileOutputStream(zipFile));
|
|
|
+ //TODO:未对文件不存在时进行操作,后期优化。
|
|
|
+
|
|
|
+ for (Map crete : list) {
|
|
|
+// File file = new File();
|
|
|
+ if(new UrlResource(CommonUtil.objToString(crete.get("pfiFileUrl"))).exists()) {
|
|
|
+// FileInputStream zipSource = new FileInputStream(crete.get("pfiFileUrl")+"");//将需要压缩的文件格式化为输入流
|
|
|
+ InputStream zipSource = getFileInputStream(crete.get("pfiFileUrl")+"");
|
|
|
+ /**
|
|
|
+ * 压缩条目不是具体独立的文件,而是压缩包文件列表中的列表项,称为条目,就像索引一样这里的name就是文件名,
|
|
|
+ * 文件名和之前的重复就会导致文件被覆盖
|
|
|
+ */
|
|
|
+ //在压缩目录中文件的名字
|
|
|
+ ZipEntry zipEntry = new ZipEntry(CommonUtil.objToString(crete.get("pfiFileName")));
|
|
|
+ //定位该压缩条目位置,开始写入文件到压缩包中
|
|
|
+ zipStream.putNextEntry(zipEntry);
|
|
|
+ BufferedInputStream bufferStream = new BufferedInputStream(zipSource, 1024 * 10);
|
|
|
+ int read = 0;
|
|
|
+ byte[] buf = new byte[1024 * 10];
|
|
|
+ while ((read = bufferStream.read(buf, 0, 1024 * 10)) != -1) {
|
|
|
+ zipStream.write(buf, 0, read);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(null != bufferStream){
|
|
|
+ bufferStream.close();
|
|
|
+ }
|
|
|
+ if(null != zipSource){
|
|
|
+ zipSource.close();
|
|
|
+ }
|
|
|
+// file.delete();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("aaaaaaaaaaaaaaa");
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ //关闭流
|
|
|
+ try {
|
|
|
+ if(null != zipStream){
|
|
|
+ zipStream.flush();
|
|
|
+ zipStream.close();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
/** 压缩方法 */
|
|
|
- FileOutputStream fos1= new FileOutputStream(new File(directory + "rzgl"+DateUtils.dateTimeNow()+ ".zip"));
|
|
|
- toZip(directory,fos1 ,true);
|
|
|
- File zipFile = new File(directory + "rzgl"+DateUtils.dateTimeNow()+ ".zip");
|
|
|
+// generateFile(directory,"zip");
|
|
|
+// FileOutputStream fos1= new FileOutputStream(new File(directory + "rzgl"+DateUtils.dateTimeNow()+ ".zip"));
|
|
|
+// toZip(directory,fos1 ,true);
|
|
|
+// File zipFile = new File(directory + "rzgl"+DateUtils.dateTimeNow()+ ".zip");
|
|
|
if(zipFile.exists()) {
|
|
|
- down(response, "rzgl" + DateUtils.dateTimeNow() + ".zip", directory);
|
|
|
+ down(response, zipFileName, directory);
|
|
|
zipFile.delete();
|
|
|
}
|
|
|
return null;
|
|
|
@@ -721,6 +811,7 @@ public class FinanceRecordController extends BaseController {
|
|
|
//创建缓冲输入流
|
|
|
BufferedInputStream bis = null;
|
|
|
OutputStream outputStream = null;
|
|
|
+
|
|
|
try {
|
|
|
outputStream = response.getOutputStream();
|
|
|
|
|
|
@@ -754,142 +845,20 @@ public class FinanceRecordController extends BaseController {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- /**
|
|
|
- * 下载远程文件并保存到本地
|
|
|
- * @param remoteFilePath 远程文件路径
|
|
|
- * @param localFilePath 本地文件路径(带文件名)
|
|
|
- * @param directory 本地文件夹
|
|
|
- */
|
|
|
- public static String downloadFile(String remoteFilePath, String localFilePath,String directory)
|
|
|
- {
|
|
|
- URL urlfile = null;
|
|
|
- HttpURLConnection httpUrl = null;
|
|
|
- BufferedInputStream bis = null;
|
|
|
- BufferedOutputStream bos = null;
|
|
|
|
|
|
- File path = new File(directory);
|
|
|
- //判断文件是否存在
|
|
|
- if(!path.exists()){
|
|
|
- path.mkdirs();
|
|
|
- }
|
|
|
- File f = new File( localFilePath );
|
|
|
- try
|
|
|
- {
|
|
|
- urlfile = new URL(remoteFilePath);
|
|
|
- httpUrl = (HttpURLConnection)urlfile.openConnection();
|
|
|
- httpUrl.connect();
|
|
|
- bis = new BufferedInputStream(httpUrl.getInputStream());
|
|
|
- bos = new BufferedOutputStream(new FileOutputStream(f));
|
|
|
- int len = 2048;
|
|
|
- byte[] b = new byte[len];
|
|
|
- while ((len = bis.read(b)) != -1)
|
|
|
- {
|
|
|
- bos.write(b, 0, len);
|
|
|
- }
|
|
|
- bos.flush();
|
|
|
- bis.close();
|
|
|
- httpUrl.disconnect();
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- finally
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- bis.close();
|
|
|
- bos.close();
|
|
|
- }
|
|
|
- catch (IOException e)
|
|
|
- {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- return f.getAbsolutePath();
|
|
|
- }
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 压缩成ZIP 方法 * @param srcDir 压缩文件夹路径
|
|
|
- * @param out 压缩文件输出流
|
|
|
- * @param KeepDirStructure 是否保留原来的目录结构,true:保留目录结构;
|
|
|
- * false:所有文件跑到压缩包根目录下(注意:不保留目录结构可能会出现同名文件,会压缩失败)
|
|
|
- * @throws RuntimeException 压缩失败会抛出运行时异常
|
|
|
- */
|
|
|
- public static void toZip(String srcDir, OutputStream out, boolean KeepDirStructure) throws RuntimeException{
|
|
|
- long start = System.currentTimeMillis();
|
|
|
- ZipOutputStream zos = null ;
|
|
|
- try {
|
|
|
- zos = new ZipOutputStream(out);
|
|
|
- File sourceFile = new File(srcDir);
|
|
|
- compress(sourceFile,zos,sourceFile.getName(),KeepDirStructure);
|
|
|
- long end = System.currentTimeMillis();
|
|
|
- System.out.println("压缩完成,耗时:" + (end - start) +" ms");
|
|
|
- } catch (Exception e) {
|
|
|
- throw new RuntimeException("zip error from ZipUtils",e);
|
|
|
- }finally{
|
|
|
- if(zos != null){
|
|
|
- try {
|
|
|
- zos.flush();
|
|
|
- zos.close();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ public static InputStream getFileInputStream(String path) throws Exception {
|
|
|
+ URL url = null;
|
|
|
+ url = new URL(path);
|
|
|
+ HttpURLConnection conn = (HttpURLConnection)url.openConnection();
|
|
|
+ //设置超时间为3秒
|
|
|
+ conn.setConnectTimeout(3*1000);
|
|
|
+ //防止屏蔽程序抓取而返回403错误
|
|
|
+ conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
|
|
|
+ //得到输入流
|
|
|
+ return conn.getInputStream();
|
|
|
}
|
|
|
- /**
|
|
|
- * 递归压缩方法
|
|
|
- * @param sourceFile 源文件
|
|
|
- * @param zos zip输出流
|
|
|
- * @param name 压缩后的名称
|
|
|
- * @param KeepDirStructure 是否保留原来的目录结构,true:保留目录结构;
|
|
|
- * false:所有文件跑到压缩包根目录下(注意:不保留目录结构可能会出现同名文件,会压缩失败)
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- private static void compress(File sourceFile, ZipOutputStream zos, String name,
|
|
|
- boolean KeepDirStructure) throws Exception{
|
|
|
- byte[] buf = new byte[2 * 1024];
|
|
|
- if(sourceFile.isFile()){
|
|
|
- // 向zip输出流中添加一个zip实体,构造器中name为zip实体的文件的名字
|
|
|
- zos.putNextEntry(new ZipEntry(name));
|
|
|
- // copy文件到zip输出流中
|
|
|
- int len;
|
|
|
- FileInputStream in = new FileInputStream(sourceFile);
|
|
|
- while ((len = in.read(buf)) != -1){
|
|
|
- zos.write(buf, 0, len);
|
|
|
- }
|
|
|
- // Complete the entry
|
|
|
- zos.closeEntry();
|
|
|
- in.close();
|
|
|
- } else {
|
|
|
- //是文件夹
|
|
|
- File[] listFiles = sourceFile.listFiles();
|
|
|
- if(listFiles == null || listFiles.length == 0){
|
|
|
- // 需要保留原来的文件结构时,需要对空文件夹进行处理
|
|
|
- if(KeepDirStructure){
|
|
|
- // 空文件夹的处理
|
|
|
- zos.putNextEntry(new ZipEntry(name + "/"));
|
|
|
- // 没有文件,不需要文件的copy
|
|
|
- zos.closeEntry();
|
|
|
- }
|
|
|
|
|
|
- }else {
|
|
|
- for (File file : listFiles) {
|
|
|
- // 判断是否需要保留原来的文件结构
|
|
|
- if (KeepDirStructure) {
|
|
|
- // 注意:file.getName()前面需要带上父文件夹的名字加一斜杠,
|
|
|
- // 不然最后压缩包中就不能保留原来的文件结构,即:所有文件都跑到压缩包根目录下了
|
|
|
- compress(file, zos, name + "/" + file.getName(),KeepDirStructure);
|
|
|
- } else {
|
|
|
- compress(file, zos, file.getName(),KeepDirStructure);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
|