Просмотр исходного кода

照片路径加一层节点类型

qinhouyu 1 год назад
Родитель
Сommit
1af1640895

+ 39 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zdsz/ZEngineeringIndustryController.java

@@ -11,6 +11,8 @@ import com.ruoyi.common.core.page.TableDataInfo;
 import com.ruoyi.common.core.validate.AddGroup;
 import com.ruoyi.common.core.validate.EditGroup;
 import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.file.FolderToZipUtil;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.zdsz.domain.bo.ZEngineeringIndustryBo;
 import com.ruoyi.zdsz.domain.vo.ZEngineeringIndustryTypeVo;
@@ -19,12 +21,15 @@ import com.ruoyi.zdsz.mapper.ZEngineeringCivilMapper;
 import com.ruoyi.zdsz.service.IZEngineeringIndustryService;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
 import javax.validation.constraints.NotEmpty;
 import javax.validation.constraints.NotNull;
+import java.io.File;
+import java.text.SimpleDateFormat;
 import java.util.Arrays;
 import java.util.LinkedList;
 import java.util.List;
@@ -124,10 +129,43 @@ public class ZEngineeringIndustryController extends BaseController {
      */
 //    @SaCheckPermission("zdsz:engineeringIndustry:query")
     @GetMapping("/{id}/{type}")
-    public R<ZEngineeringIndustryVo> query(@NotNull(message = "主键不能为空") @PathVariable String id, @PathVariable String type) {
+    public R<ZEngineeringIndustryVo> query(@PathVariable String id, @PathVariable String type) {
         return R.ok(iZEngineeringIndustryService.query(id, type));
     }
 
+    @Value("${filePath}")
+    private String filePath;
+
+    @GetMapping(value = "/downloadZip/{type}/{name}")
+    public void downloadZip(@PathVariable String type,@PathVariable String name,HttpServletResponse response) {
+//        File file = new File(zipPath);//创建指定目录和文件名称的文件对象
+        try {
+            // 创建最外层文件夹
+            byte[] fileNameBytes = filePath.getBytes("UTF-8");
+            // 使用UTF-8编码创建文件
+            File file = new File(new String(fileNameBytes, "UTF-8"));
+            if (!file.exists()) {
+                file.mkdirs();
+            }
+            byte[] typeFileNameBytes = (file.getPath() + "/" + type).getBytes("UTF-8");
+            // 使用UTF-8编码创建文件
+            File typeFile = new File(new String(typeFileNameBytes, "UTF-8"));
+            if (!typeFile.exists()) {
+                typeFile.mkdirs();
+            }
+            byte[] enginNameFileNameBytes = (typeFile.getPath() + "/" + name).getBytes("UTF-8");
+            // 使用UTF-8编码创建文件
+            File enginNameFile = new File(new String(enginNameFileNameBytes, "UTF-8"));
+            if (!enginNameFile.exists()) {
+                enginNameFile.mkdirs();
+            }
+            System.out.println(enginNameFile.getPath());
+            FolderToZipUtil.zip(enginNameFile.getPath(),name,response);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
     /**
      * 工业工程|市政工程根据工程类型查询工程名称
      */

+ 11 - 0
ruoyi-zdsz/src/main/java/com/ruoyi/zdsz/domain/bo/ZEngineeringInfoBo.java

@@ -93,6 +93,17 @@ public class ZEngineeringInfoBo extends BaseEntity {
      * 备注
      */
     private String remark;
+
+
+    public String getNodeName() {
+        return nodeName;
+    }
+
+    public void setNodeName(String nodeName) {
+        this.nodeName = nodeName;
+    }
+
+    private String nodeName;
     /**
      * 状态
      */

+ 13 - 2
ruoyi-zdsz/src/main/java/com/ruoyi/zdsz/service/impl/ZEngiineeringPhotoServiceImpl.java

@@ -339,10 +339,21 @@ public class ZEngiineeringPhotoServiceImpl implements IZEngiineeringPhotoService
                         if (!enginNameFile.exists()) {
                             enginNameFile.mkdirs();
                         }
-
+                        byte[] CreateTimeFileNameBytes;
+                       if (StringUtils.isNotBlank(item.getNodeName())){
+                           //节点类型
+                           byte[] nodeType = (enginNameFile.getPath() + "/" + item.getNodeName()).getBytes("UTF-8");
+                           // 使用UTF-8编码创建文件
+                           File f = new File(new String(nodeType, "UTF-8"));
+                           if (!f.exists()) {
+                               f.mkdirs();
+                           }
+                           CreateTimeFileNameBytes = (f.getPath() + "/" + new SimpleDateFormat("yyyy-MM-dd").format(item.getUpdateTime())).getBytes("UTF-8");
+                       }else {
+                           CreateTimeFileNameBytes = (enginNameFile.getPath() + "/" + new SimpleDateFormat("yyyy-MM-dd").format(item.getUpdateTime())).getBytes("UTF-8");
+                       }
                         // 时间
                         //                        File CreateTimeFile = new File(Type.getPath() + "/" + new SimpleDateFormat("yyyy-MM-dd").format(zEngineeringInfoBo.getCreateTime()) );
-                        byte[] CreateTimeFileNameBytes = (enginNameFile.getPath() + "/" + new SimpleDateFormat("yyyy-MM-dd").format(item.getUpdateTime())).getBytes("UTF-8");
                         // 使用UTF-8编码创建文件
                         File CreateTimeFile = new File(new String(CreateTimeFileNameBytes, "UTF-8"));
                         if (!CreateTimeFile.exists()) {