Browse Source

1,FileUploadController改名FileController 2,文件下载工具方法 3,配合步骤条接口增加了响应延迟

wucl 8 months ago
parent
commit
abb8279da5

+ 17 - 7
biz-base/src/main/java/com/dayou/controller/FileUploadController.java

@@ -1,7 +1,5 @@
 package com.dayou.controller;
 package com.dayou.controller;
 
 
-import cn.dev33.satoken.annotation.SaCheckLogin;
-import cn.dev33.satoken.annotation.SaCheckRole;
 import cn.hutool.core.lang.UUID;
 import cn.hutool.core.lang.UUID;
 import com.dayou.config.FileNetConfig;
 import com.dayou.config.FileNetConfig;
 import com.dayou.result.Result;
 import com.dayou.result.Result;
@@ -9,12 +7,12 @@ import com.dayou.result.Status;
 import com.dayou.utils.FileNetUtil;
 import com.dayou.utils.FileNetUtil;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.CrossOrigin;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartFile;
 
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
 import java.util.Map;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Objects;
 
 
@@ -25,7 +23,7 @@ import static com.dayou.constants.HouseGuarantyDoc.COLLECT1_XLSX;
 @Slf4j
 @Slf4j
 @CrossOrigin
 @CrossOrigin
 //@SaCheckLogin
 //@SaCheckLogin
-public class FileUploadController {
+public class FileController {
 
 
     @Autowired
     @Autowired
     private FileNetConfig fileNetConfig;
     private FileNetConfig fileNetConfig;
@@ -75,4 +73,16 @@ public class FileUploadController {
         }
         }
     }
     }
 
 
+    /**
+     * 下载房地产表单一
+     * @param request
+     * @param response
+     */
+    @GetMapping("/download/house/guaranty/collect1")
+    public void downloadHouseGuarantyCollect1(HttpServletRequest request, HttpServletResponse response){
+        String collect1Path = fileNetConfig.getBaseDir() + fileNetConfig.getHouseGuarantyTemplatePath() + COLLECT1_XLSX;
+        File collect1 = new File(collect1Path);
+        FileNetUtil.writeFile2Response(request,response,collect1,COLLECT1_XLSX);
+    }
+
 }
 }

+ 15 - 0
biz-base/src/main/java/com/dayou/controller/HouseGuarantyDocController.java

@@ -2,7 +2,9 @@ package com.dayou.controller;
 
 
 
 
 import com.dayou.dto.HouseGuarantyTableDTO;
 import com.dayou.dto.HouseGuarantyTableDTO;
+import com.dayou.entity.HouseGuarantyProcess;
 import com.dayou.result.Result;
 import com.dayou.result.Result;
+import com.dayou.service.HouseGuarantyProcessService;
 import com.dayou.service.HouseGuarantyService;
 import com.dayou.service.HouseGuarantyService;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -20,6 +22,9 @@ public class HouseGuarantyDocController {
     @Autowired
     @Autowired
     private HouseGuarantyService houseGuarantyService;
     private HouseGuarantyService houseGuarantyService;
 
 
+    @Autowired
+    private HouseGuarantyProcessService houseGuarantyProcessService;
+
     /**
     /**
      * 生成估价结果一览表的word文件
      * 生成估价结果一览表的word文件
      * @return 过程表id
      * @return 过程表id
@@ -49,4 +54,14 @@ public class HouseGuarantyDocController {
         return Result.build(houseGuarantyService.genConsignorLetter(id));
         return Result.build(houseGuarantyService.genConsignorLetter(id));
     }
     }
 
 
+    /**
+     * 获取过程信息
+     * @param id
+     * @return
+     */
+    @GetMapping("/{id}")
+    public Result<HouseGuarantyProcess> getHouseGuarantyProcess(@PathVariable("id") Long id){
+        return Result.build(houseGuarantyProcessService.getHouseGuarantyProcess(id));
+    }
+
 }
 }

+ 50 - 5
common/src/main/java/com/dayou/utils/FileNetUtil.java

@@ -2,21 +2,23 @@ package com.dayou.utils;
 
 
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.date.DateUtil;
 import com.dayou.exception.BusinessException;
 import com.dayou.exception.BusinessException;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.util.FileCopyUtils;
 import org.springframework.util.FileCopyUtils;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartFile;
 
 
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.net.URLEncoder;
 import java.util.Date;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Map;
 
 
-import java.io.BufferedInputStream;
 import java.net.HttpURLConnection;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.net.URL;
 
 
+@Slf4j
 public class FileNetUtil {
 public class FileNetUtil {
 
 
     /**
     /**
@@ -116,6 +118,10 @@ public class FileNetUtil {
         }
         }
     }
     }
 
 
+    /**
+     * 创建日期目录
+     * @return
+     */
     public static String createDateFolder() {
     public static String createDateFolder() {
         Date now = new Date();
         Date now = new Date();
         String year = DateUtil.format(now, "yyyy");
         String year = DateUtil.format(now, "yyyy");
@@ -127,4 +133,43 @@ public class FileNetUtil {
         return index;
         return index;
     }
     }
 
 
+    /**
+     * 下载本地文件
+     * @param request
+     * @param response
+     * @param file
+     * @param fileName
+     */
+    public static void writeFile2Response(HttpServletRequest request, HttpServletResponse response, File file,
+                                     String fileName) {
+        try {
+            OutputStream out = response.getOutputStream();
+            if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0) {
+                fileName = URLEncoder.encode(fileName, "UTF-8");
+            } else {
+                fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1");
+            }
+            response.setHeader("Content-Type", "application/octet-stream");
+            response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
+            InputStream is = new FileInputStream(file);
+
+            int b = 0;
+            byte[] buffer = new byte[1024];
+            while (b != -1) {
+                b = is.read(buffer);
+                if (b != -1) {
+                    out.write(buffer, 0, b);
+                }
+            }
+            is.close();
+
+            response.setStatus(HttpServletResponse.SC_OK);
+            response.flushBuffer();
+            out.close();
+        } catch (Exception e) {
+            log.error("下载" + fileName + "错误", e);
+            throw new RuntimeException(e);
+        }
+    }
+
 }
 }

+ 2 - 0
service/src/main/java/com/dayou/service/HouseGuarantyProcessService.java

@@ -12,4 +12,6 @@ import com.dayou.entity.HouseGuarantyProcess;
  * @since 2024-11-07
  * @since 2024-11-07
  */
  */
 public interface HouseGuarantyProcessService extends IService<HouseGuarantyProcess> {
 public interface HouseGuarantyProcessService extends IService<HouseGuarantyProcess> {
+
+    HouseGuarantyProcess getHouseGuarantyProcess(Long id);
 }
 }

+ 14 - 0
service/src/main/java/com/dayou/service/impl/HouseGuarantyProcessServiceImpl.java

@@ -1,13 +1,27 @@
 package com.dayou.service.impl;
 package com.dayou.service.impl;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.dayou.common.BaseEntity;
+import com.dayou.entity.DocumentProduction;
 import com.dayou.entity.HouseGuarantyProcess;
 import com.dayou.entity.HouseGuarantyProcess;
 import com.dayou.mapper.HouseGuarantyProcessMapper;
 import com.dayou.mapper.HouseGuarantyProcessMapper;
+import com.dayou.service.DocumentProductionService;
 import com.dayou.service.HouseGuarantyProcessService;
 import com.dayou.service.HouseGuarantyProcessService;
 import com.dayou.service.HouseGuarantyService;
 import com.dayou.service.HouseGuarantyService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 @Service
 @Service
 public class HouseGuarantyProcessServiceImpl extends ServiceImpl<HouseGuarantyProcessMapper, HouseGuarantyProcess> implements HouseGuarantyProcessService {
 public class HouseGuarantyProcessServiceImpl extends ServiceImpl<HouseGuarantyProcessMapper, HouseGuarantyProcess> implements HouseGuarantyProcessService {
 
 
+    @Autowired
+    private DocumentProductionService documentProductionService;
+
+    @Override
+    public HouseGuarantyProcess getHouseGuarantyProcess(Long id) {
+        DocumentProduction dp = documentProductionService.getOne(new LambdaQueryWrapper<DocumentProduction>()
+                .select(DocumentProduction::getBusinessId).eq(BaseEntity::getId, id));
+        return this.getById(dp.getBusinessId());
+    }
 }
 }

+ 20 - 4
service/src/main/java/com/dayou/service/impl/HouseGuarantyServiceImpl.java

@@ -36,6 +36,7 @@ import java.util.stream.Collectors;
 
 
 import static com.dayou.constants.HouseGuarantyDoc.*;
 import static com.dayou.constants.HouseGuarantyDoc.*;
 import static com.dayou.enums.HouseTargetTableColumn.ID;
 import static com.dayou.enums.HouseTargetTableColumn.ID;
+import static java.lang.Thread.sleep;
 
 
 @Service
 @Service
 public class HouseGuarantyServiceImpl implements HouseGuarantyService {
 public class HouseGuarantyServiceImpl implements HouseGuarantyService {
@@ -55,19 +56,29 @@ public class HouseGuarantyServiceImpl implements HouseGuarantyService {
 
 
     @Override
     @Override
     public Long createTableWord(HouseGuarantyTableDTO houseGuarantyTableDTO) {
     public Long createTableWord(HouseGuarantyTableDTO houseGuarantyTableDTO) {
+        try {
+            sleep(500);
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
         String html = houseGuarantyTableDTO.getHtml();
         String html = houseGuarantyTableDTO.getHtml();
         String homePath = houseGuarantyTableDTO.getHomePath();
         String homePath = houseGuarantyTableDTO.getHomePath();
-        html = wordTableHelper.htmlTableFormat(html);
+        String xHtml = wordTableHelper.htmlTableFormat(html);
         HouseGuarantyProcess hgp = new HouseGuarantyProcess();
         HouseGuarantyProcess hgp = new HouseGuarantyProcess();
         hgp.setHome(homePath);
         hgp.setHome(homePath);
         hgp.setTargetsHtml(html);
         hgp.setTargetsHtml(html);
         houseGuarantyProcessService.save(hgp);
         houseGuarantyProcessService.save(hgp);
-        wordTableHelper.createTableWord(html, fileNetConfig.getBaseDir() + homePath);
+        wordTableHelper.createTableWord(xHtml, fileNetConfig.getBaseDir() + homePath);
         return hgp.getId();
         return hgp.getId();
     }
     }
 
 
     @Override
     @Override
     public Boolean analysisCollect1(Long id) {
     public Boolean analysisCollect1(Long id) {
+        try {
+            sleep(1000);
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
         HouseGuarantyProcess process = houseGuarantyProcessService.getById(id);
         HouseGuarantyProcess process = houseGuarantyProcessService.getById(id);
         String home = fileNetConfig.getBaseDir() + process.getHome();
         String home = fileNetConfig.getBaseDir() + process.getHome();
         try {
         try {
@@ -87,6 +98,11 @@ public class HouseGuarantyServiceImpl implements HouseGuarantyService {
 
 
     @Override
     @Override
     public String genConsignorLetter(Long id) {
     public String genConsignorLetter(Long id) {
+        try {
+            sleep(2000);
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
         HouseGuarantyProcess process = houseGuarantyProcessService.getById(id);
         HouseGuarantyProcess process = houseGuarantyProcessService.getById(id);
         String home = fileNetConfig.getBaseDir() + process.getHome();
         String home = fileNetConfig.getBaseDir() + process.getHome();
         try {
         try {
@@ -193,8 +209,8 @@ public class HouseGuarantyServiceImpl implements HouseGuarantyService {
 
 
     private DocumentProduction buildDocumentProduction(Long id,String docName,String docNo,String docUrl,String consignor){
     private DocumentProduction buildDocumentProduction(Long id,String docName,String docNo,String docUrl,String consignor){
         DocumentProduction dp = new DocumentProduction();
         DocumentProduction dp = new DocumentProduction();
-        dp.setBusinessType(MainBusiness.HOUSE.getCode());
-        dp.setBusinessCate(MainBusiness.HouseSubBusiness.GUARANTY.getCode());
+        dp.setBusinessType(MainBusiness.HOUSE.getMsg());
+        dp.setBusinessCate(MainBusiness.HouseSubBusiness.GUARANTY.getMsg());
         dp.setBusinessId(id);
         dp.setBusinessId(id);
         dp.setDocName(docName);
         dp.setDocName(docName);
         dp.setDocType(DocumentType.REPORT.getName());
         dp.setDocType(DocumentType.REPORT.getName());