|
@@ -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();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|