Jelajahi Sumber

不动产前序附件下载

chenendian 1 bulan lalu
induk
melakukan
25f9f18571

+ 0 - 3
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/controller/NodeAttachmentController.java

@@ -205,7 +205,6 @@ public class NodeAttachmentController extends BaseController {
 
 
 
 
 
 
-
     /**
     /**
      * 根据节点ID删除附件信息
      * 根据节点ID删除附件信息
      *
      *
@@ -218,9 +217,7 @@ public class NodeAttachmentController extends BaseController {
             if (nodeId == null || nodeId.trim().isEmpty()) {
             if (nodeId == null || nodeId.trim().isEmpty()) {
                 return R.fail("nodeId不能为空");
                 return R.fail("nodeId不能为空");
             }
             }
-
             nodeAttachmentService.deleteByNodeId(nodeId);
             nodeAttachmentService.deleteByNodeId(nodeId);
-
             Map<String, Object> responseData = new java.util.HashMap<>();
             Map<String, Object> responseData = new java.util.HashMap<>();
             responseData.put("nodeId", nodeId);
             responseData.put("nodeId", nodeId);
             responseData.put("success", true);
             responseData.put("success", true);

+ 187 - 1
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/controller/third/OfferDataController.java

@@ -1,25 +1,49 @@
 package com.siwei.apply.controller.third;
 package com.siwei.apply.controller.third;
 
 
 import com.siwei.apply.domain.LandOneCode;
 import com.siwei.apply.domain.LandOneCode;
+import com.siwei.apply.domain.NodeAttachment;
+import com.siwei.apply.domain.vo.AttachmentParamVo;
 import com.siwei.apply.service.third.OfferDataService;
 import com.siwei.apply.service.third.OfferDataService;
+import com.siwei.apply.utils.ServiceUtil;
 import com.siwei.common.core.domain.R;
 import com.siwei.common.core.domain.R;
 import com.siwei.common.core.web.controller.BaseController;
 import com.siwei.common.core.web.controller.BaseController;
+import com.siwei.common.redis.service.RedisService;
 import lombok.RequiredArgsConstructor;
 import lombok.RequiredArgsConstructor;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.core.io.Resource;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
 
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.net.URLEncoder;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.Map;
 import java.util.Map;
+import java.util.Objects;
 
 
 /**
 /**
  *
  *
  *
  *
  */
  */
 @RestController
 @RestController
-@RequestMapping("/public/third2")
+@RequestMapping("/public/offer")
 @RequiredArgsConstructor
 @RequiredArgsConstructor
 public class OfferDataController extends BaseController {
 public class OfferDataController extends BaseController {
 
 
     private final OfferDataService offerDataService;
     private final OfferDataService offerDataService;
 
 
+    @Autowired
+    private RedisService redisService;
+
+
     /**
     /**
      * 新增
      * 新增
      */
      */
@@ -47,6 +71,7 @@ public class OfferDataController extends BaseController {
     }
     }
 
 
 
 
+
     @PostMapping("/addEntity")
     @PostMapping("/addEntity")
     public R<String> addEntity(@RequestBody LandOneCode body) {
     public R<String> addEntity(@RequestBody LandOneCode body) {
         try {
         try {
@@ -57,4 +82,165 @@ public class OfferDataController extends BaseController {
     }
     }
 
 
 
 
+
+    /**
+     *
+     * 获取前序资料的接口API
+     *
+     * @param
+     * @return
+     */
+    @PostMapping("/attachmentList")
+    public R<NodeAttachment> attachmentList(@RequestBody AttachmentParamVo paramVo) {
+        try {
+            String projectId = paramVo.getYwbh();
+            String immobileCode = paramVo.getYfbdcdyh();
+            String dqjd = paramVo.getDqjd();
+            if(StringUtils.isBlank(immobileCode)){
+                return R.fail(502,"不动产号为空,请填充");
+            }
+            if(StringUtils.isBlank(dqjd)){
+                return R.fail(502,"标识阶段为空,请填充");
+            }
+            if(StringUtils.isBlank(projectId)){
+                return R.fail(502,"项目id为空,请填充");
+            }
+            NodeAttachment nodeAttachment = offerDataService.getThirdNodeAttachment(immobileCode,projectId,dqjd);
+            return R.ok(nodeAttachment);
+        } catch (Exception e) {
+            return R.fail(502,"获取附件材料失败");
+        }
+    }
+
+
+
+
+    /**
+     * 文件下载
+     *
+     * @param request
+     * @param response
+     * @return
+     */
+    @GetMapping("/download/{signature}/{expireTime}/{attachmentId}/{dirName}/{fileName}")
+    public ResponseEntity<Resource> uploadAttachment(@PathVariable("signature") String signature,@PathVariable("expireTime") String expireTime,
+                                                     @PathVariable("attachmentId") String attachmentId,@PathVariable("dirName") String dirName,
+                                                     @PathVariable("fileName") String fileName,
+                                                     HttpServletRequest request, HttpServletResponse response) {
+
+        try {
+            if(StringUtils.isBlank(signature) || Objects.isNull(expireTime) || StringUtils.isBlank(attachmentId)
+                    ||StringUtils.isBlank(dirName) ||StringUtils.isBlank(fileName)){
+                return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
+            }
+
+            //过期时间和签名校验
+            String signaturePath = attachmentId+"/"+dirName+"/"+fileName;
+            if(!ServiceUtil.isUrlValid(signaturePath,signature,Long.valueOf(expireTime))){
+                return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
+            }
+
+            // 写一个方法,通过id,和文件名称,文件目录,获取当前文件路径。
+            String fullFilePath = offerDataService.getTheFile(attachmentId,dirName,fileName);
+            if(StringUtils.isBlank(fullFilePath)){
+                return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
+            }
+
+            //获取地址:
+            //String uploadFile = "D:\\home\\siwei\\uploadPath\\2025\\11\\26\\测试工具列表222_20251106083212A098.xls";
+            // 构建文件的完整路径
+            Path filePath = Paths.get(fullFilePath);
+            File file = filePath.toFile();
+            Resource resource = new FileSystemResource(file);
+            // 如果资源不存在,返回404
+            if (!resource.exists()) {
+                return ResponseEntity.notFound().build();
+            }
+            // 获取文件MIME类型
+            String contentType = Files.probeContentType(filePath);
+            if (contentType == null) {
+                // 如果无法确定MIME类型,则使用默认值
+                contentType = MediaType.APPLICATION_OCTET_STREAM_VALUE;
+            }
+            String d0_name = file.getName();
+            String d1_name = URLEncoder.encode(d0_name, "UTF-8");
+            // 设置HTTP头部信息
+            HttpHeaders headers = new HttpHeaders();
+            headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + d1_name);
+            headers.setContentType(MediaType.parseMediaType(contentType));
+//            headers.setAccessControlAllowOrigin("*");
+            // 返回文件资源
+            return ResponseEntity.ok().headers(headers).contentLength(Files.size(filePath))  // 可选:设置内容长度
+                    .body(resource);
+        } catch (Exception e) {
+            // 处理IO异常,例如文件不存在或无法读取
+            return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
+        }
+    }
+
+
+
+
+
+
+
+
+
+
+    /**
+     * 文件下载
+     *
+     * @param request
+     * @param response
+     * @return
+     */
+    @GetMapping("/download/file222/{id}/{uploadId}")
+    public ResponseEntity<Resource> uploadAttachment222(@PathVariable("id") String id, @PathVariable("uploadId") String uploadId, HttpServletRequest request, HttpServletResponse response) {
+        try {
+            String upload_id = "upliad_" + id + "_" + uploadId;
+            String uploadFile = redisService.getCacheObject(upload_id);
+            if (StringUtils.isEmpty(uploadFile)) {
+                return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
+            }
+            // 构建文件的完整路径
+            Path filePath = Paths.get(uploadFile);
+            File file = filePath.toFile();
+            Resource resource = new FileSystemResource(file);
+            // 如果资源不存在,返回404
+            if (!resource.exists()) {
+                return ResponseEntity.notFound().build();
+            }
+            // 获取文件MIME类型
+            String contentType = Files.probeContentType(filePath);
+            if (contentType == null) {
+                // 如果无法确定MIME类型,则使用默认值
+                contentType = MediaType.APPLICATION_OCTET_STREAM_VALUE;
+            }
+            String d0_name = file.getName();
+            String d1_name = URLEncoder.encode(d0_name, "UTF-8");
+            // 设置HTTP头部信息
+            HttpHeaders headers = new HttpHeaders();
+            headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + d1_name);
+            headers.setContentType(MediaType.parseMediaType(contentType));
+//            headers.setAccessControlAllowOrigin("*");
+            // 返回文件资源
+            return ResponseEntity.ok().headers(headers).contentLength(Files.size(filePath))  // 可选:设置内容长度
+                    .body(resource);
+        } catch (Exception e) {
+            // 处理IO异常,例如文件不存在或无法读取
+//            e.printStackTrace();
+            return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
+        }
+    }
+
+
+
+
+
+
+
+
+
+
+
 }
 }

+ 1 - 1
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/controller/third/TakeDataController.java

@@ -17,7 +17,7 @@ import java.util.Map;
  * 获取不动产数据
  * 获取不动产数据
  */
  */
 @RestController
 @RestController
-@RequestMapping("/public/third")
+@RequestMapping("/public/take")
 @RequiredArgsConstructor
 @RequiredArgsConstructor
 public class TakeDataController extends BaseController {
 public class TakeDataController extends BaseController {
     protected final Logger logger = LoggerFactory.getLogger(this.getClass());
     protected final Logger logger = LoggerFactory.getLogger(this.getClass());

+ 0 - 1
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/domain/Tdgy.java

@@ -5,7 +5,6 @@ import lombok.Data;
 
 
 import java.util.Date;
 import java.util.Date;
 import java.util.Map;
 import java.util.Map;
-import java.util.UUID;
 
 
 /**
 /**
  * 土地供应对象 t_tdgy
  * 土地供应对象 t_tdgy

+ 14 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/domain/vo/AttachmentParamVo.java

@@ -0,0 +1,14 @@
+package com.siwei.apply.domain.vo;
+
+import lombok.Data;
+
+/**
+ *
+ * 前序节点附件入参
+ */
+@Data
+public class AttachmentParamVo {
+    private String yfbdcdyh;   // 不动产码
+    private String ywbh;   // 业务码(项目码id)
+    private String dqjd;    //所属阶段(当前阶段(登记阶段标识:00:国有建设用地使用权首次登记;01: 国有建设用地使用权及房屋所有权首次登记))
+}

+ 3 - 3
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/third/OfferDataService.java

@@ -1,8 +1,6 @@
 package com.siwei.apply.service.third;
 package com.siwei.apply.service.third;
 
 
-import com.siwei.apply.domain.res.GyjsydscdjRes;
-import com.siwei.apply.domain.res.GyjsydscdjSinglRes;
-import com.siwei.apply.domain.vo.GyjsydscdjUpdateVo;
+import com.siwei.apply.domain.NodeAttachment;
 
 
 import java.util.Map;
 import java.util.Map;
 
 
@@ -26,7 +24,9 @@ public interface OfferDataService {
      */
      */
     Map<String,String> getById(String id);
     Map<String,String> getById(String id);
 
 
+    String  getTheFile(String attachmentId, String dirName,String fileName) ;
 
 
+    NodeAttachment getThirdNodeAttachment(String immobileCode, String projectId, String dqjd) throws Exception;
 
 
 
 
 }
 }

+ 63 - 1
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/third/impl/OfferDataServiceImpl.java

@@ -1,11 +1,18 @@
 package com.siwei.apply.service.third.impl;
 package com.siwei.apply.service.third.impl;
 
 
+import com.siwei.apply.domain.NodeAttachment;
+import com.siwei.apply.domain.ProjectWorkflow;
+import com.siwei.apply.enums.AloneWorkFlowEnum;
+import com.siwei.apply.mapper.ProjectWorkflowMapper;
+import com.siwei.apply.service.NodeAttachmentService;
 import com.siwei.apply.service.third.OfferDataService;
 import com.siwei.apply.service.third.OfferDataService;
+import com.siwei.apply.utils.ServiceUtil;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 
 
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
-import java.util.Map;
+import java.util.*;
 
 
 
 
 /**
 /**
@@ -16,6 +23,12 @@ import java.util.Map;
 public class OfferDataServiceImpl implements OfferDataService {
 public class OfferDataServiceImpl implements OfferDataService {
 
 
 
 
+    @Autowired
+    private NodeAttachmentService nodeAttachmentService;
+
+    @Autowired
+    private ProjectWorkflowMapper projectWorkflowMapper;
+
     @Override
     @Override
     public Map<String, String> get(String projectId) {
     public Map<String, String> get(String projectId) {
         return Map.of();
         return Map.of();
@@ -25,4 +38,53 @@ public class OfferDataServiceImpl implements OfferDataService {
     public Map<String, String> getById(String id) {
     public Map<String, String> getById(String id) {
         return Map.of();
         return Map.of();
     }
     }
+
+
+    @Override
+    public String  getTheFile(String attachmentId, String dirName,String fileName) {
+        String fileAndPath = "";
+        NodeAttachment nodeAttachment = nodeAttachmentService.getById(attachmentId);
+        nodeAttachment = nodeAttachmentService.getNodeAttachmentData(nodeAttachment.getNodeId(),null);
+
+        if(Objects.nonNull(nodeAttachment)){
+            List<Map <String,String>>  fileList = ServiceUtil.getDirChildrenList(dirName,nodeAttachment);
+            if(Objects.nonNull(fileList)){
+                Optional<Map<String, String>> result = fileList.stream().filter(s->s.get("name").equalsIgnoreCase(fileName)).findFirst();
+                if(result.isPresent()){
+                    fileAndPath = result.get().get("path");
+                }
+            }
+        }
+        return fileAndPath;
+    }
+
+    @Override
+    public NodeAttachment  getThirdNodeAttachment(String immobileCode, String projectId,String dqjd) throws Exception{
+        String nodeTableName = dqjd.equals("00") ? AloneWorkFlowEnum.NODE_2.getTableName() : dqjd.equals("01") ? AloneWorkFlowEnum.NODE_6.getTableName() :"";
+        NodeAttachment nodeAttachment = null;
+        List<ProjectWorkflow> projectWorkflows = projectWorkflowMapper.selectByProjectIdAndNodeTableName(projectId, nodeTableName);
+        Optional<ProjectWorkflow> res = projectWorkflows.stream().findFirst();
+        if(res.isPresent()){
+            String nodeId = res.get().getNodeId();
+            log.info("-------getAttachmentByProjectIdAndTable-----"+nodeId);
+            nodeAttachment = nodeAttachmentService.getNodeAttachmentData(nodeId,null);
+            //这里获取到所有附件文件路径进行转化拼接为新的
+            ServiceUtil.convertFilePath(nodeAttachment);
+        }
+        return nodeAttachment;
+    }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 }
 }

+ 121 - 8
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/utils/ServiceUtil.java

@@ -4,20 +4,29 @@ import com.siwei.apply.domain.NodeAttachment;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
 
 
+import java.net.URI;
+import java.security.MessageDigest;
 import java.util.*;
 import java.util.*;
 
 
 /**
 /**
  * 服务类工具
  * 服务类工具
  */
  */
 public class ServiceUtil {
 public class ServiceUtil {
+
+    private static final long EXPIRY_TIME = 10 * 60 * 1000;  // 10 minutes in milliseconds
+    private static final String SECRET_KEY = "siwei";  // Secret key for signature
+    private static final String TIME_KEY = "?time=";  // time
+    private static final String DOMAN = "http://192.168.60.219/prod-api/apply";  // doman
+
     /**
     /**
      * 获取指定目录下的子children list
      * 获取指定目录下的子children list
-     * @param dirName 目录名称
+     *
+     * @param dirName        目录名称
      * @param nodeAttachment 附件信息
      * @param nodeAttachment 附件信息
      * @return
      * @return
      */
      */
-    public static   List<Map <String,String>>  getDirChildrenList(String dirName, NodeAttachment nodeAttachment) {
-        List<Map <String,String>> list = new  ArrayList<>();
+    public static List<Map<String, String>> getDirChildrenList(String dirName, NodeAttachment nodeAttachment) {
+        List<Map<String, String>> list = new ArrayList<>();
         if (Objects.nonNull(nodeAttachment) && Objects.nonNull(nodeAttachment.getAttachment())) {
         if (Objects.nonNull(nodeAttachment) && Objects.nonNull(nodeAttachment.getAttachment())) {
             Map<String, Object> attachment = nodeAttachment.getAttachment();
             Map<String, Object> attachment = nodeAttachment.getAttachment();
             //第一曾经children 所有目录list
             //第一曾经children 所有目录list
@@ -33,15 +42,15 @@ public class ServiceUtil {
                 }
                 }
             }
             }
         }
         }
-        return  list;
+        return list;
     }
     }
 
 
 
 
-    public static   Map<String,Object>  getDirChildrenMap(String dirName, NodeAttachment nodeAttachment) {
-        Map<String,Object> retMap = null;
+    public static Map<String, Object> getDirChildrenMap(String dirName, NodeAttachment nodeAttachment) {
+        Map<String, Object> retMap = null;
         if (Objects.nonNull(nodeAttachment) && Objects.nonNull(nodeAttachment.getAttachment())) {
         if (Objects.nonNull(nodeAttachment) && Objects.nonNull(nodeAttachment.getAttachment())) {
             Map<String, Object> attachment = nodeAttachment.getAttachment();
             Map<String, Object> attachment = nodeAttachment.getAttachment();
-            //第一曾经children 所有目录list
+            //第一层级children 所有目录list
             List<Map> childrenList = (List<Map>) attachment.get("children");
             List<Map> childrenList = (List<Map>) attachment.get("children");
             if (CollectionUtils.isNotEmpty(childrenList)) {
             if (CollectionUtils.isNotEmpty(childrenList)) {
                 for (Map childMap : childrenList) {
                 for (Map childMap : childrenList) {
@@ -53,13 +62,117 @@ public class ServiceUtil {
                 }
                 }
             }
             }
         }
         }
-        return  retMap;
+        return retMap;
+    }
+
+
+    /**
+     *
+     * @param nodeAttachment
+     * @throws Exception
+     */
+    public static void convertFilePath(NodeAttachment nodeAttachment) throws Exception {
+        String attachmentId = nodeAttachment.getId();
+        String timestamp = String.valueOf(System.currentTimeMillis());
+        if (Objects.nonNull(nodeAttachment.getAttachment())) {
+            Map<String, Object> attachment = nodeAttachment.getAttachment();
+            //第一层级children 所有目录list
+            List<Map> childrenList = (List<Map>) attachment.get("children");
+            if (CollectionUtils.isNotEmpty(childrenList)) {
+                for (Map childMap : childrenList) {
+                    String childName = (String) childMap.get("name");
+                    List<Map<String, String>> list = (List<Map<String, String>>) childMap.get("children");
+                    for (Map<String, String> map : list) {
+                        String fileName = map.get("name");
+                        if(StringUtils.isNotBlank(fileName)){
+                            String SignedUrl = attachmentId + "/" + childName + "/" + fileName;
+                            String signedRes = fileUrlSigned(SignedUrl, timestamp);
+                            String path =  DOMAN+ "/public/offer/download/"+signedRes+"/"+timestamp+"/"+attachmentId+"/"+childName+"/"+fileName;
+                            map.put("path", path);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+
+
+
+
+    // Validate the URL by checking its timestamp and signature
+    public static boolean isUrlValid222(String url, long originalTimestamp) {
+        try {
+            // Extract the timestamp and signature from the URL
+            URI uri = URI.create(url);
+            String query = uri.getQuery();
+            String[] params = query.split("&");
+            long timestamp = 0;
+            String signature = null;
+
+            // Parse timestamp and signature
+            for (String param : params) {
+                if (param.startsWith("timestamp=")) {
+                    timestamp = Long.parseLong(param.split("=")[1]);
+                } else if (param.startsWith("signature=")) {
+                    signature = param.split("=")[1];
+                }
+            }
+
+            // Check if the link is expired (10 minutes expiry)
+            if (System.currentTimeMillis() - timestamp > EXPIRY_TIME) {
+                return false;
+            }
+            // Verify the signature
+            String originalUrl = url.split("&signature=")[0];
+            String expectedSignature = generateSignature(originalUrl);
+            return expectedSignature.equals(signature);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return false;
+        }
     }
     }
 
 
 
 
+    // Validate the URL by checking its timestamp and signature
+    public static boolean isUrlValid(String originalUrl, String signature, Long originalTimestamp) {
+        try {
+            originalUrl += TIME_KEY + originalTimestamp;
+            // Check if the link is expired (10 minutes expiry)
+            if (System.currentTimeMillis() - originalTimestamp > EXPIRY_TIME) {
+                return false;
+            }
+            String expectedSignature = generateSignature(originalUrl);
+            return expectedSignature.equals(signature);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return false;
+        }
+    }
 
 
 
 
+    // Convert byte array to Hex
+    private static String bytesToHex(byte[] bytes) {
+        StringBuilder sb = new StringBuilder();
+        for (byte b : bytes) {
+            sb.append(String.format("%02x", b));
+        }
+        return sb.toString();
+    }
 
 
+    // Generate a hash-based signature for the URL
+    private static String generateSignature(String data) throws Exception {
+        MessageDigest digest = MessageDigest.getInstance("SHA-256");
+        byte[] hash = digest.digest((data + SECRET_KEY).getBytes("UTF-8"));
+        return bytesToHex(hash);
+    }
+
+
+    // Generate the signed URL
+    public static String fileUrlSigned(String baseUrl, String timestamp) throws Exception {
+        String urlWithTimestamp = baseUrl + TIME_KEY + timestamp;
+        return generateSignature(urlWithTimestamp);
+    }
 
 
 
 
 }
 }