Kaynağa Gözat

linux文件路径

lem 4 yıl önce
ebeveyn
işleme
13410db514

+ 14 - 0
src/main/java/com/jeeplus/common/config/Global.java

@@ -351,4 +351,18 @@ public class Global {
     }
 
 
+    public static String getPath() {
+        SystemAuthorizingRealm.Principal principal = (SystemAuthorizingRealm.Principal) UserUtils.getPrincipal();
+        String dir = "";
+        String FILE_PREFIX = loader.getProperty("linux.file.store.prefix");
+        if (SYS_TYPE.equals("1")) {
+            dir = Global.getUserfilesBaseDir() + Global.FILES_FILESERVER;
+        } else {
+            //liunx file store prefix
+            dir = FILE_PREFIX;
+        }
+
+        FileUtils.createDirectory(dir);
+        return dir;
+    }
 }

+ 88 - 4
src/main/java/com/jeeplus/modules/filing/filingImages/service/FilingImagesService.java

@@ -16,6 +16,10 @@ import com.jeeplus.modules.filing.approvalStage.mapper.EarlyStageMapper;
 import com.jeeplus.modules.filing.approvalStage.mapper.StudyStageMapper;
 import com.jeeplus.modules.filing.basicInformation.entity.BasicInformation;
 import com.jeeplus.modules.filing.basicInformation.mapper.BasicInformationMapper;
+import com.jeeplus.modules.filing.earlyEngineering.entity.DesignStage;
+import com.jeeplus.modules.filing.earlyEngineering.entity.ReviewStage;
+import com.jeeplus.modules.filing.earlyEngineering.mapper.DesignStageMapper;
+import com.jeeplus.modules.filing.earlyEngineering.mapper.ReviewStageMapper;
 import com.jeeplus.modules.filing.filingImages.entity.FilingImages;
 import com.jeeplus.modules.filing.filingImages.mapper.FilingImagesMapper;
 import com.jeeplus.modules.filing.filingImages.utils.ZipCompressUtil;
@@ -56,6 +60,12 @@ public class FilingImagesService extends CrudService<FilingImagesMapper, FilingI
     @Autowired
     private StudyStageMapper studyStageMapper;
 
+    @Autowired
+    private DesignStageMapper designStageMapper;
+
+    @Autowired
+    private ReviewStageMapper reviewStageMapper;
+
     public List<FilingImages> findByProjectId(String id) {
         return mapper.findByProjectId(id);
     }
@@ -72,7 +82,7 @@ public class FilingImagesService extends CrudService<FilingImagesMapper, FilingI
         long timeMillis = System.currentTimeMillis();
         String fileLocality = "项目附件_" + timeMillis;
         //判定当前系统
-        String path = Global.getAttachmentDir2();
+        String path = Global.getPath();
         path = path + "/" + fileLocality;
         //检查该路径对应的目录是否存在. 如果不存在则创建目录
         File dir = new File(path);
@@ -130,7 +140,7 @@ public class FilingImagesService extends CrudService<FilingImagesMapper, FilingI
         long timeMillis = System.currentTimeMillis();
         String fileLocality = "项目附件_" + timeMillis;
         //判定当前系统
-        String path = Global.getAttachmentDir2();
+        String path = Global.getPath();
         path = path + "/" + fileLocality;
         //检查该路径对应的目录是否存在. 如果不存在则创建目录
         File dir = new File(path);
@@ -203,7 +213,7 @@ public class FilingImagesService extends CrudService<FilingImagesMapper, FilingI
         long timeMillis = System.currentTimeMillis();
         String fileLocality = "项目附件_" + timeMillis;
         //判定当前系统
-        String path = Global.getAttachmentDir2();
+        String path = Global.getPath();
         path = path + "/" + fileLocality;
         //检查该路径对应的目录是否存在. 如果不存在则创建目录
         File dir = new File(path);
@@ -360,7 +370,7 @@ public class FilingImagesService extends CrudService<FilingImagesMapper, FilingI
         long timeMillis = System.currentTimeMillis();
         String fileLocality = "项目附件_" + timeMillis;
         //判定当前系统
-        String path = Global.getAttachmentDir2();
+        String path = Global.getPath();
         path = path + "/" + fileLocality;
         //检查该路径对应的目录是否存在. 如果不存在则创建目录
         File dir = new File(path);
@@ -446,4 +456,78 @@ public class FilingImagesService extends CrudService<FilingImagesMapper, FilingI
         return file.getPath();
     }
 
+
+    /**
+     * 通过项目id导出项目的初设阶段
+     *
+     * @param idList
+     */
+    public String exportDesignStage(List<String> idList) throws Exception {
+        //设置下载的压缩包名(固定字符+时间戳)
+        long timeMillis = System.currentTimeMillis();
+        String fileLocality = "项目附件_" + timeMillis;
+        //判定当前系统
+        String path = Global.getPath();
+        path = path + "/" + fileLocality;
+        //检查该路径对应的目录是否存在. 如果不存在则创建目录
+        File dir = new File(path);
+        if (!dir.exists()) {
+            dir.mkdirs();
+        }
+
+        List<DesignStage> allList = new ArrayList<>();
+        //通过id查询出所有的项目信息
+        List<DesignStage> byIdList = designStageMapper.findAll(idList);
+
+        for (DesignStage a :
+                byIdList) {
+            allList.add(a);
+            List<DesignStage> childList = designStageMapper.findChildList(a);
+            if (childList.size() > 0) {
+                for (DesignStage b :
+                        childList) {
+                    allList.add(b);
+                }
+            }
+        }
+        //循环遍历,判断项目是否存在
+        for (DesignStage a :
+                allList) {
+            File dirFile = null;
+            List<FilingImages> filingImagesList = null;
+            List<FilingImages> exportList = new ArrayList<>();
+            String downloadPath = path + "/" + a.getProjectCode();
+            String designAnnex = a.getPreDesignAnnex();
+            if (null!=designAnnex && !"".equals(designAnnex)) {
+                dirFile = new File(downloadPath + "/初设阶段");
+                if (designAnnex.contains("|")) {
+                    String[] split = designAnnex.split("\\|");
+                    for (int i = 0; i < split.length; i++) {
+                        FilingImages filingImages = new FilingImages();
+                        filingImages.setImgPath(split[i]);
+                        filingImages.setProjectCode(a.getProjectCode());
+                        filingImages.setPurpose("初设附件");
+                        exportList.add(filingImages);
+                    }
+                } else {
+                    FilingImages filingImages = new FilingImages();
+                    filingImages.setImgPath(designAnnex);
+                    filingImages.setProjectCode(a.getProjectCode());
+                    filingImages.setPurpose("初设附件");
+                    exportList.add(filingImages);
+                }
+            }
+
+            if (exportList.size() > 0) {
+                this.disposeFileList(exportList, dirFile.getPath());
+            }
+
+        }
+        //处理完之后进行打包压缩并删除之前的文件
+        ZipCompressUtil zipUtil = new ZipCompressUtil();
+        File resultFile = new File(path);
+        File file = zipUtil.zipCompress(resultFile, true);
+        return file.getPath();
+    }
+
 }

+ 26 - 0
src/main/java/com/jeeplus/modules/filing/filingImages/web/FilingImagesController.java

@@ -150,4 +150,30 @@ public class FilingImagesController extends BaseController {
 		}
 		return "redirect:"+Global.getAdminPath()+"/filing/earlyStage/";
 	}
+
+
+	/**
+	 * 项目相应文件批量下载并压缩
+	 */
+	@RequestMapping(value = "exportDesignStage")
+	public String exportDesignStage(HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
+		String listIds = request.getParameter("ids");
+		List<String> idList = new ArrayList<>();
+		if (null != listIds && !"".equals(listIds)) {
+			idList = Arrays.asList(listIds.split(","));
+		} else {
+			idList = basicInformationService.findAllId();
+		}
+		try {
+			String filePath = filingImagesService.exportDesignStage(idList);
+			filingImagesService.downloadZipFile(filePath,response);
+			return null;
+		} catch (Exception e) {
+			addMessage(redirectAttributes, "批量下载项目文件失败!");
+		}
+		return "redirect:"+Global.getAdminPath()+"/filing/designStage/";
+	}
+
+
+
 }