Browse Source

更新简历解析接口,增加文件大小限制

DESKTOP-VAEGFGM\zqc 7 tháng trước cách đây
mục cha
commit
d553102c76

+ 1 - 0
menduner/menduner-system-api/src/main/java/com/citu/module/menduner/system/enums/ErrorCodeConstants.java

@@ -46,6 +46,7 @@ public interface ErrorCodeConstants {
 
     ErrorCode MDE_PERSON_EMAIL_ERROR = new ErrorCode(1_100_001_012, "邮箱号不合法,请输入正确邮箱");
     ErrorCode MDE_PERSON_PHONE_ERROR = new ErrorCode(1_100_001_013, "手机号不合法,请输入正确手机号");
+    ErrorCode MDE_PERSON_RESUME_ERROR = new ErrorCode(1_100_001_014, "简历文件不可超过10MB!");
 
 
     // ========== 行业信息 1_100_002_000 ==========

+ 5 - 0
menduner/menduner-system-biz/src/main/java/com/citu/module/menduner/system/service/resume/OnlineResumeServiceImpl.java

@@ -4,6 +4,7 @@ import cn.hutool.core.codec.Base64;
 import cn.hutool.http.HttpUtil;
 import com.citu.framework.common.pojo.CommonResult;
 import com.citu.module.menduner.system.controller.base.resume.resumesdk.TemResumeResVo;
+import com.citu.module.menduner.system.enums.ErrorCodeConstants;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -19,6 +20,10 @@ public class OnlineResumeServiceImpl implements OnlineResumeService {
     public CommonResult<TemResumeResVo> resumeParser(String fileUrl) {
         String fileName = fileUrl.substring(fileUrl.lastIndexOf("/") + 1);
         byte[] bytes = HttpUtil.downloadBytes(fileUrl);
+        int mb10 = 10*1024*1024; // 直接大小
+        if(bytes.length >=mb10){
+            return CommonResult.error(ErrorCodeConstants.MDE_PERSON_RESUME_ERROR);
+        }
         Base64 base64 = new Base64();
         String fileContent = base64.encode(bytes);
         CommonResult<TemResumeResVo> commonResult =  tenResumeService.tenResumeService(fileName,fileContent);

+ 8 - 2
menduner/menduner-system-biz/src/main/java/com/citu/module/menduner/system/service/resume/TenResumeServiceImpl.java

@@ -39,6 +39,9 @@ public class TenResumeServiceImpl implements TenResumeService {
     @Value("${ten.resume.secretkey:HlKf8e7sDtBbm1Am05r0628y2SUYC5LxEz57odxY}")
     private String tenResumeSecretKey;
 
+
+
+
     @Value("${ten.resume.url:https://service-9wsy8usn-1302482110.bj.apigw.tencentcs.com/release/ResumeParser}")
     private String resumeReqUrl;
 
@@ -46,15 +49,18 @@ public class TenResumeServiceImpl implements TenResumeService {
     @Override
     public CommonResult<TemResumeResVo> tenResumeService(String fileName, String fileContent) {
         try {
+            // TODO 此处后续优化缓存功能,减少API调用次数
             TemResumeResVo resume = resume(fileName, fileContent, 1, 1, 1);
             return CommonResult.success(resume);
         }catch (Exception e){
             log.error("tenResumeService error:{}",e.getMessage());
-            throw  new RuntimeException("简历解析异常!");
+            throw  new RuntimeException("简历解析失败!");
         }
     }
 
     /**
+     *
+     *
      *
      * @param fileName  简历文件名。请务必带上正确的文件后缀名,否则部分简历可能解析失败。
      * @param fileCount 简历文件内容(以base64编码),其中:
@@ -101,7 +107,7 @@ public class TenResumeServiceImpl implements TenResumeService {
         HttpResponse execute = post.execute();
         String body = execute.body();
         log.info("parse resume  res->{}",body);
-        System.out.println(body);
+//        System.out.println(body);
         TemResumeResVo temResumeResVo = JSON.parseObject(body, TemResumeResVo.class);
         if(temResumeResVo.getStatus().getCode()!=200){
            throw  new RuntimeException("简历解析失败");