Bladeren bron

下载模板和智能打标结果设置默认值

2507040827 1 dag geleden
bovenliggende
commit
ae2b461941

+ 41 - 1
server/yusp-tagging-core/src/main/java/cn/com/yusys/yusp/controller/AitagTagInfoController.java

@@ -14,12 +14,21 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.UrlResource;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
-import java.util.Arrays;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.List;
 import java.util.Map;
 
@@ -188,5 +197,36 @@ public class AitagTagInfoController {
         return ResultDto.success(aitagTagInfoService.generateRegex(regexVo));
     }
 
+    /**
+     * 批量导入模板下载
+     *
+     * @return ResultDto
+     */
+    @ApiOperation("批量导入模板下载")
+    @GetMapping("/downloadFile")
+    public ResponseEntity<Resource> downloadFile( ) throws IOException {
+
+        // 1. 构造文件路径并进行规范化,防止路径遍历攻击 (如 ../../恶意路径)
+        Path filePath = Paths.get("template").resolve("tag_batch_Import_template.xlsx").normalize();
+        ClassPathResource resource = new ClassPathResource(filePath.toString());
+
+        // 2. 校验文件是否存在且可读
+        if (resource.exists() && resource.isReadable()) {
+            // 3. 推断文件的 MediaType (MIME type)
+            String contentType = MediaType.APPLICATION_OCTET_STREAM_VALUE;
+            contentType = Files.probeContentType(filePath);
+            // 4. 返回 ResponseEntity,设置响应头
+            return ResponseEntity.ok()
+                    .contentType(MediaType.parseMediaType(contentType))
+                    // 告知浏览器以附件形式下载,并指定文件名
+                    // 使用 URLEncoder.encode 处理中文文件名乱码问题
+                    .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\""
+                            + URLEncoder.encode("tag_batch_Import_template.xlsx", StandardCharsets.UTF_8.toString()) + "\"")
+                    .body(resource);
+        } else {
+            // 文件不存在或不可读,返回 404
+            return ResponseEntity.notFound().build();
+        }
+    }
 
 }

+ 12 - 0
server/yusp-tagging-core/src/main/java/cn/com/yusys/yusp/domain/vo/SmartTaggingResultVo.java

@@ -2,6 +2,8 @@ package cn.com.yusys.yusp.domain.vo;
 
 
 import cn.com.yusys.yusp.commons.module.adapter.query.PageQuery;
+import cn.com.yusys.yusp.commons.util.date.DateUtils;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import lombok.Data;
 
 /**
@@ -29,4 +31,14 @@ public class SmartTaggingResultVo extends PageQuery {
      * 标签类别
      */
     private String categoryCode;
+
+
+    public String getStartTaggingTime() {
+        return StringUtils.isBlank(startTaggingTime)? DateUtils.getCurrYear()+"-01-01 00:00:00":startTaggingTime;
+    }
+
+    public String getEndTaggingTime() {
+        return StringUtils.isBlank(endTaggingTime)? DateUtils.getCurrDateTimeStr():endTaggingTime;
+    }
+
 }

+ 1 - 0
server/yusp-tagging-core/src/main/java/cn/com/yusys/yusp/service/impl/AitagTagLogServiceImpl.java

@@ -23,6 +23,7 @@ import org.springframework.stereotype.Service;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.net.URL;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 

BIN
server/yusp-tagging-core/src/main/resources/template/tag_batch_Import_template.xlsx