|
|
@@ -5,11 +5,17 @@ import com.siwei.apply.domain.vo.ConvergeFilterVo;
|
|
|
import com.siwei.apply.domain.vo.ConvergeUpdateVo;
|
|
|
import com.siwei.apply.mapper.ConvergeMapper;
|
|
|
import com.siwei.apply.service.ConvergeService;
|
|
|
+import com.siwei.apply.utils.ServiceFileUtil;
|
|
|
+import com.siwei.common.core.utils.uuid.IdUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -54,4 +60,56 @@ public class ConvergeServiceImpl implements ConvergeService {
|
|
|
public void batchDelete(List<String> ids) {
|
|
|
convergeMapper.batchDelete(ids);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void downConvergeFile(HttpServletResponse response, String ywh) {
|
|
|
+ try {
|
|
|
+ // 1. 创建临时目录
|
|
|
+ String tempDir = System.getProperty("java.io.tmpdir") + File.separator + IdUtils.fastSimpleUUID();
|
|
|
+ File dir = new File(tempDir);
|
|
|
+ if (!dir.exists()) dir.mkdirs();
|
|
|
+ String shpName = "test"+IdUtils.fastSimpleUUID();
|
|
|
+ File zipFile = new File(tempDir + File.separator + shpName + ".zip");
|
|
|
+
|
|
|
+ File file1 = new File(tempDir + File.separator + shpName + ".shp");
|
|
|
+ File file2 = new File(tempDir + File.separator + shpName + ".shx");
|
|
|
+ if(!file1.exists()){
|
|
|
+ file1.createNewFile();
|
|
|
+ }
|
|
|
+ if(!file2.exists()){
|
|
|
+ file2.createNewFile();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<File> filesToZip = Arrays.asList(
|
|
|
+ file1,
|
|
|
+ file2
|
|
|
+ );
|
|
|
+ ServiceFileUtil.zipFiles(filesToZip, zipFile);
|
|
|
+
|
|
|
+ // 4. 设置响应头并下载
|
|
|
+ response.setContentType("application/zip");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ String fileName = shpName + ".zip";
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
|
|
|
+
|
|
|
+ try (FileInputStream fis = new FileInputStream(zipFile)) {
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
+ int len;
|
|
|
+ while ((len = fis.read(buffer)) > 0) {
|
|
|
+ response.getOutputStream().write(buffer, 0, len);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ response.getOutputStream().flush();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("导出SHP文件失败", e);
|
|
|
+ throw new RuntimeException("导出SHP文件失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|