Browse Source

简历附件上传调整通过moonshot解析调整

zjc 9 months ago
parent
commit
dce9333466

+ 6 - 3
ruoyi-admin/src/main/java/com/ruoyi/web/controller/moonshot/MoonshotFileController.java

@@ -69,9 +69,12 @@ public class MoonshotFileController extends BaseController {
             tUnifyFile.setCreateBy(getNickName());
 
             //moonshot AI 附件上传返回附件信息
-
-
-
+            if(null != resuat.getError()){
+                ajax.put("message", resuat.getError().getMessage());
+                tUnifyFile.setStatus_details(resuat.getError().getMessage());
+            }else if(resuat.getStatus().equals("ok")) {
+                tUnifyFile.copyFrom(resuat,true);
+            }
 
             tUnifyFileService.insertTUnifyFile(tUnifyFile);
 

+ 39 - 2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/TUnifyFileController.java

@@ -1,5 +1,6 @@
 package com.ruoyi.web.controller.tool;
 
+import cn.moonshot.platform.util.MoonshotAiUtils;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.config.RuoYiConfig;
 import com.ruoyi.common.core.controller.BaseController;
@@ -10,6 +11,8 @@ import com.ruoyi.common.enums.FileType;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.file.FileUploadUtils;
 import com.ruoyi.common.utils.file.FileUtils;
+import com.ruoyi.common.utils.moonshot.Client;
+import com.ruoyi.common.utils.moonshot.vo.FileUploadResult;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.framework.config.ServerConfig;
 import com.ruoyi.tool.domain.TUnifyFile;
@@ -19,6 +22,7 @@ import io.swagger.annotations.ApiOperation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
@@ -49,6 +53,9 @@ public class TUnifyFileController extends BaseController
     @Autowired
     private ServerConfig serverConfig;
 
+    @Value("${moonshot.api_key}")
+    private String API_KEY;
+
     /**
      * 查询附件列表
      */
@@ -126,12 +133,23 @@ public class TUnifyFileController extends BaseController
     @PostMapping("/uploads")
     public AjaxResult uploadFiles(List<MultipartFile> files)
     {
+        AjaxResult ajax = AjaxResult.success();
         try
         {
             // 上传文件路径
             String filePath = RuoYiConfig.getUploadPath();
             for (MultipartFile file : files)
             {
+
+                if (API_KEY == null) {
+                    System.out.println("Please set MOONSHOT_API_KEY env");
+                    ajax.put("API_KEY","接口API_KEY不存在");
+                    return ajax;
+                }
+                Client client = new Client(API_KEY);
+
+                FileUploadResult resuat = client.uploadFile(file);
+
                 // 上传并返回新文件名称
                 String fileName = FileUploadUtils.upload(filePath, file);
                 String url = serverConfig.getUrl() + fileName;
@@ -140,11 +158,30 @@ public class TUnifyFileController extends BaseController
                 tUnifyFile.setUploadName(fileName);
                 tUnifyFile.setNewUploadName(FileUtils.getName(fileName));
                 tUnifyFile.setUploadFormat(file.getOriginalFilename());
-                tUnifyFile.setUploadType(String.valueOf(FileType.OTHER.ordinal()));//其他
+                tUnifyFile.setUploadType(String.valueOf(FileType.RESUME.ordinal()));//简历附件
                 tUnifyFile.setCreateBy(getNickName());
+
+                //moonshot AI 附件上传返回附件信息
+                if(null != resuat.getError()){
+                    tUnifyFile.setStatus_details(resuat.getError().getMessage());
+                }else if(resuat.getStatus().equals("ok")) {
+                    tUnifyFile.copyFrom(resuat,true);
+
+                    /**
+                     * 根据moonshot获取附件解析内容
+                     */
+                    if(StringUtils.isNotEmpty(tUnifyFile.getFileId())){
+                        tUnifyFile.setContent(MoonshotAiUtils.getFileContent(tUnifyFile.getFileId(),client.getApiKey()));
+                    }
+
+                }
+
                 tUnifyFileService.insertTUnifyFile(tUnifyFile);
+
+                //根据上传附件已经moonshot返回上传内容
+                ajax.put(tUnifyFile.getFileId(),tUnifyFile);
             }
-            return  AjaxResult.success();
+            return ajax;
         }
         catch (Exception e)
         {

+ 124 - 0
ruoyi-system/src/main/java/com/ruoyi/tool/domain/TUnifyFile.java

@@ -2,6 +2,8 @@ package com.ruoyi.tool.domain;
 
 import com.ruoyi.common.annotation.Excel;
 import com.ruoyi.common.core.domain.BaseEntity;
+import com.ruoyi.common.utils.moonshot.vo.FileUploadResult;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.apache.commons.lang3.builder.ToStringStyle;
 
@@ -49,6 +51,29 @@ public class TUnifyFile extends BaseEntity
     @Excel(name = "附件业务ID")
     private String fileBusinessId;
 
+    /**
+     * moonshot AI 参数
+     */
+    private String object;
+
+    private String bytes;
+
+    private String created_at;
+
+    private String filename;
+
+    private String purpose;
+
+    private String status;
+
+    private String status_details;
+
+    /**
+     * 附件内容
+     */
+    private String content;
+
+
     public void setId(String id) 
     {
         this.id = id;
@@ -131,6 +156,70 @@ public class TUnifyFile extends BaseEntity
         return fileBusinessId;
     }
 
+    public String getObject() {
+        return object;
+    }
+
+    public void setObject(String object) {
+        this.object = object;
+    }
+
+    public String getBytes() {
+        return bytes;
+    }
+
+    public void setBytes(String bytes) {
+        this.bytes = bytes;
+    }
+
+    public String getCreated_at() {
+        return created_at;
+    }
+
+    public void setCreated_at(String created_at) {
+        this.created_at = created_at;
+    }
+
+    public String getFilename() {
+        return filename;
+    }
+
+    public void setFilename(String filename) {
+        this.filename = filename;
+    }
+
+    public String getPurpose() {
+        return purpose;
+    }
+
+    public void setPurpose(String purpose) {
+        this.purpose = purpose;
+    }
+
+    public String getStatus() {
+        return this.status;
+    }
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
+
+    public String getStatus_details() {
+        return status_details;
+    }
+
+    public void setStatus_details(String status_details) {
+        this.status_details = status_details;
+    }
+
+    public String getContent() {
+        return content;
+    }
+
+    public void setContent(String content) {
+        this.content = content;
+    }
+
     @Override
     public String toString() {
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
@@ -149,4 +238,39 @@ public class TUnifyFile extends BaseEntity
             .append("updateTime", getUpdateTime())
             .toString();
     }
+
+
+    /**
+     * 自定义的复制方法,忽略空值
+     * @param other
+     * @param ignoreNulls
+     */
+    public void copyFrom(FileUploadResult other, boolean ignoreNulls) {
+        if (other == null) {
+            throw new IllegalArgumentException("Other object cannot be null");
+        }
+        if (ignoreNulls) {
+            this.setFileId(other.getId() != null && StringUtils.isNotEmpty(other.getId()) ? other.getId() : this.getFileId());
+            this.setObject(other.getObject() != null && StringUtils.isNotEmpty(other.getObject()) ? other.getObject() : this.getObject());
+            this.setBytes(other.getBytes() != null && StringUtils.isNotEmpty(other.getBytes()) ? other.getBytes() : this.getBytes());
+            this.setCreated_at(other.getCreated_at() != null && StringUtils.isNotEmpty(other.getCreated_at()) ? other.getCreated_at() : this.getCreated_at());
+            this.setFilename(other.getFilename() != null && StringUtils.isNotEmpty(other.getFilename()) ? other.getFilename() : this.getFilename());
+            this.setPurpose(other.getPurpose() != null && StringUtils.isNotEmpty(other.getPurpose()) ? other.getPurpose() : this.getPurpose());
+            this.setStatus(other.getStatus() != null && StringUtils.isNotEmpty(other.getStatus()) ? other.getStatus() : this.getStatus());
+            this.setStatus_details(other.getStatus_details() != null && StringUtils.isNotEmpty(other.getStatus_details()) ? other.getStatus_details() : this.getStatus_details());
+
+        } else {
+            // 如果不忽略空值,则直接复制
+            this.setFileId(other.getId());
+            this.setObject(other.getObject());
+            this.setBytes(other.getBytes());
+            this.setCreated_at(other.getCreated_at());
+            this.setFilename(other.getFilename());
+            this.setPurpose(other.getPurpose());
+            this.setStatus(other.getStatus());
+            this.setStatus_details(other.getStatus_details());
+
+        }
+    }
+
 }

+ 172 - 0
ruoyi-system/src/main/resources/mapper/tool/TUnifyFileMapper.xml

@@ -0,0 +1,172 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ruoyi.tool.mapper.TUnifyFileMapper">
+    
+    <resultMap type="TUnifyFile" id="TUnifyFileResult">
+        <result property="id"    column="id"    />
+        <result property="fileId"    column="file_id"    />
+        <result property="uploadName"    column="upload_name"    />
+        <result property="uploadType"    column="upload_type"    />
+        <result property="uploadPath"    column="upload_path"    />
+        <result property="uploadFormat"    column="upload_format"    />
+        <result property="newUploadName"    column="new_upload_name"    />
+        <result property="delFlag"    column="del_flag"    />
+        <result property="fileBusinessId"    column="file_business_id"    />
+        <result property="object"    column="object"    />
+        <result property="bytes"    column="bytes"    />
+        <result property="created_at"    column="created_at"    />
+        <result property="filename"    column="filename"    />
+        <result property="purpose"    column="purpose"    />
+        <result property="status"    column="status"    />
+        <result property="status_details"    column="status_details"    />
+        <result property="content"    column="content"    />
+        <result property="createBy"    column="create_by"    />
+        <result property="createTime"    column="create_time"    />
+        <result property="updateBy"    column="update_by"    />
+        <result property="updateTime"    column="update_time"    />
+    </resultMap>
+
+    <sql id="selectTUnifyFileVo">
+        select id, file_id, upload_name, upload_type, upload_path, upload_format, new_upload_name, del_flag, object, bytes, created_at, filename, purpose, status, status_details, content, file_business_id, create_by, create_time, update_by, update_time from t_unify_file
+    </sql>
+
+    <select id="selectTUnifyFileList" parameterType="TUnifyFile" resultMap="TUnifyFileResult">
+        <include refid="selectTUnifyFileVo"/>
+        <where>
+            del_flag = 0
+            <if test="fileId != null  and fileId != ''"> and file_id = #{fileId}</if>
+            <if test="uploadName != null  and uploadName != ''"> and upload_name like concat('%', #{uploadName}, '%')</if>
+            <if test="uploadType != null  and uploadType != ''"> and upload_type = #{uploadType}</if>
+            <if test="uploadPath != null  and uploadPath != ''"> and upload_path = #{uploadPath}</if>
+            <if test="uploadFormat != null  and uploadFormat != ''"> and upload_format = #{uploadFormat}</if>
+            <if test="newUploadName != null  and newUploadName != ''"> and new_upload_name like concat('%', #{newUploadName}, '%')</if>
+            <if test="fileBusinessId != null  and fileBusinessId != ''"> and file_business_id = #{fileBusinessId}</if>
+        </where>
+    </select>
+    
+    <select id="selectTUnifyFileById" parameterType="String" resultMap="TUnifyFileResult">
+        <include refid="selectTUnifyFileVo"/>
+        where id = #{id}
+    </select>
+        
+    <insert id="insertTUnifyFile" parameterType="TUnifyFile">
+        insert into t_unify_file
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="id != null">id,</if>
+            <if test="fileId != null">file_id,</if>
+            <if test="uploadName != null">upload_name,</if>
+            <if test="uploadType != null">upload_type,</if>
+            <if test="uploadPath != null">upload_path,</if>
+            <if test="uploadFormat != null">upload_format,</if>
+            <if test="newUploadName != null">new_upload_name,</if>
+            <if test="delFlag != null">del_flag,</if>
+            <if test="fileBusinessId != null">file_business_id,</if>
+            <if test="object != null">object,</if>
+            <if test="bytes != null">bytes,</if>
+            <if test="created_at != null">created_at,</if>
+            <if test="filename != null">filename,</if>
+            <if test="purpose != null">purpose,</if>
+            <if test="status != null">status,</if>
+            <if test="status_details != null">status_details,</if>
+            <if test="content != null">content,</if>
+            <if test="createBy != null">create_by,</if>
+            <if test="createTime != null">create_time,</if>
+            <if test="updateBy != null">update_by,</if>
+            <if test="updateTime != null">update_time,</if>
+         </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="id != null">#{id},</if>
+            <if test="fileId != null">#{fileId},</if>
+            <if test="uploadName != null">#{uploadName},</if>
+            <if test="uploadType != null">#{uploadType},</if>
+            <if test="uploadPath != null">#{uploadPath},</if>
+            <if test="uploadFormat != null">#{uploadFormat},</if>
+            <if test="newUploadName != null">#{newUploadName},</if>
+            <if test="delFlag != null">#{delFlag},</if>
+            <if test="fileBusinessId != null">#{fileBusinessId},</if>
+            <if test="object != null">#{object},</if>
+            <if test="bytes != null">#{bytes},</if>
+            <if test="created_at != null">#{created_at},</if>
+            <if test="filename != null">#{filename},</if>
+            <if test="purpose != null">#{purpose},</if>
+            <if test="status != null">#{status},</if>
+            <if test="status_details != null">#{status_details},</if>
+            <if test="content != null">#{content},</if>
+            <if test="createBy != null">#{createBy},</if>
+            <if test="createTime != null">#{createTime},</if>
+            <if test="updateBy != null">#{updateBy},</if>
+            <if test="updateTime != null">#{updateTime},</if>
+         </trim>
+    </insert>
+
+    <update id="updateTUnifyFile" parameterType="TUnifyFile">
+        update t_unify_file
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="fileId != null">file_id = #{fileId},</if>
+            <if test="uploadName != null">upload_name = #{uploadName},</if>
+            <if test="uploadType != null">upload_type = #{uploadType},</if>
+            <if test="uploadPath != null">upload_path = #{uploadPath},</if>
+            <if test="uploadFormat != null">upload_format = #{uploadFormat},</if>
+            <if test="newUploadName != null">new_upload_name = #{newUploadName},</if>
+            <if test="delFlag != null">del_flag = #{delFlag},</if>
+            <if test="fileBusinessId != null">file_business_id = #{fileBusinessId},</if>
+            <if test="object != null">object = #{object},</if>
+            <if test="bytes != null">bytes = #{bytes},</if>
+            <if test="created_at != null">created_at = #{created_at},</if>
+            <if test="filename != null">filename = #{filename},</if>
+            <if test="purpose != null">purpose = #{purpose},</if>
+            <if test="status != null">status = #{status},</if>
+            <if test="status_details != null">status_details = #{status_details},</if>
+            <if test="content != null">content = #{content},</if>
+            <if test="createBy != null">create_by = #{createBy},</if>
+            <if test="createTime != null">create_time = #{createTime},</if>
+            <if test="updateBy != null">update_by = #{updateBy},</if>
+            <if test="updateTime != null">update_time = #{updateTime},</if>
+        </trim>
+        where id = #{id}
+    </update>
+
+    <delete id="deleteTUnifyFileById" parameterType="String">
+        delete from t_unify_file where id = #{id}
+    </delete>
+
+    <delete id="deleteTUnifyFileByIds" parameterType="String">
+        delete from t_unify_file where id in 
+        <foreach item="id" collection="array" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </delete>
+
+    <update id="updateTUnifyFileByIds" parameterType="String">
+        update t_unify_file
+        set del_flag = 1
+        where id in
+        <foreach item="id" collection="array" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </update>
+
+    <update id="updateTUnifyFileBusinessIds" parameterType="String">
+        update t_unify_file
+        set del_flag = 1
+        where file_business_id in
+        <foreach item="id" collection="array" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </update>
+
+    <select id="selectTUnifyFileByBusinessIdList" parameterType="String" resultMap="TUnifyFileResult">
+        <include refid="selectTUnifyFileVo"/>
+        where file_business_id = #{fileBusinessId} and del_flag = 0
+        <if test="uploadType != null  and uploadType != ''"> and upload_type = #{uploadType}</if>
+    </select>
+
+    <select id="listFileId" parameterType="String" resultMap="TUnifyFileResult">
+        <include refid="selectTUnifyFileVo"/>
+        where file_id = #{fileId} and del_flag = 0
+        order by create_time
+    </select>
+
+</mapper>