whycxzp
2024-01-03 d2ba7ed50955701234b1b50ceaf04fe36b86c61d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.whyc.service;
 
import com.whyc.dto.FileDirPath;
import com.whyc.dto.Response;
import com.whyc.pojo.FileMessage;
import com.whyc.util.FileUtil;
import com.whyc.util.ZipAndRarUtil;
import org.springframework.stereotype.Service;
 
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
 
@Service
public class ZipAndRarService {
 
 
    //产品查看原来压缩包中文件信息(文件目录和时间)
    public Response getzipAndRarInfo(String fileUrl) {
        String fileDirName = FileDirPath.getFileDirName();
        List<FileMessage> list=new ArrayList<>();
        try {
            if(fileUrl.contains("zip")){
                //list=ZipAndRarUtil.getZipFileList(fileDirName+fileUrl);
                list=ZipAndRarUtil.unZipFiles(fileDirName+fileUrl);
            }else if(fileUrl.contains("rar")){
                list=ZipAndRarUtil.getRarList(fileDirName+fileUrl);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return new Response().setII(1,list!=null,list,"压缩文件信息");
    }
 
    public Response decompress(String compressedFileUrl) {
        String fileSuffix = (compressedFileUrl.substring(compressedFileUrl.lastIndexOf(".")+1));
        List<String> resList = new LinkedList<>();
        if(fileSuffix.equals("zip")||fileSuffix.equals("rar")) {
            List<String> decompressList = FileUtil.decompress(compressedFileUrl);
            for (String decompress : decompressList) {
                resList.add(decompress.substring(decompress.indexOf("doc_file")));
            }
        }else{
            return new Response().set(1,false,fileSuffix+"类型压缩包暂不支持解压");
        }
 
 
        return new Response().setII(1,true, resList,null);
    }
}