陈昶聿
12 小时以前 f3434f830cfee5838211e58a3a361c73f7166342
【丽水】外链测试接口
已修改2个文件
已添加1个文件
108 ■■■■■ 文件已修改
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/SmsController.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/DeepSeekApi.java 75 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/resources/mapper/smartor/ServiceOutPathMapper.xml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/SmsController.java
@@ -217,5 +217,36 @@
        return AjaxResult.success(sendMsg);
    }
    /**
     * @param
     * @return
     */
    @ApiOperation("生成外链")
    @PostMapping("/getUrl")
    public AjaxResult getUrl(@RequestBody smsVO vo) throws UnsupportedEncodingException {
        String content = "";
        if (StringUtils.isNotEmpty(vo.getTaskId()) && StringUtils.isNotEmpty(vo.getPatId()) && StringUtils.isNotEmpty(vo.getSubId())) {
            RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample();
            String taskId = rsaPublicKeyExample.encryptedData(vo.getTaskId().toString(), pub_key);
            String patid = rsaPublicKeyExample.encryptedData(vo.getPatId().toString(), pub_key);
            String subId = rsaPublicKeyExample.encryptedData(vo.getSubId().toString(), pub_key);
            Integer radix = iServiceOutPathService.selectAutoId();
            String format = String.format("%03X", radix);
            ServiceOutPath serviceOutPath = new ServiceOutPath();
            serviceOutPath.setParam1(taskId);
            serviceOutPath.setParam2(patid);
            serviceOutPath.setParam3(vo.getTaskName());
            serviceOutPath.setParam6(subId);
            serviceOutPath.setRadix(format);
            serviceOutPath.setCreateTime(new Date());
            serviceOutPath.setOrgid(vo.getOrgid());
            String url = ip + ":" + req_path + "/wt?p=" + format;
//            content = "您好,邀请您填写出院调查表,请点击" + url + "填写。感谢您配合!";
            content = url;
            serviceOutPath.setUrl(url);
            iServiceOutPathService.insertServiceOutPath(serviceOutPath);
        }
        return AjaxResult.success(content);
    }
}
smartor/src/main/java/com/smartor/DeepSeekApi.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,75 @@
package com.smartor;
;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import okhttp3.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class DeepSeekApi {
    // æ›¿æ¢ä¸ºä½ è‡ªå·±çš„key
    private static final String API_KEY = "sk-";
    private static final String API_URL = "https://api.deepseek.com/v1/chat/completions";
    public static void main(String[] args) {
        String resp = chatCompletion("用Java写一个冒泡排序");
        System.out.println("DeepSeek返回结果:\n" + resp);
    }
    public static String chatCompletion(String userPrompt) {
        OkHttpClient client = new OkHttpClient();
        // 1. ç»„装消息体
        List<Map<String, String>> messages = new ArrayList<>();
        // ç³»ç»Ÿè§’色(可选,用于设定AI身份)
        Map<String, String> sysMsg = new HashMap<>();
        sysMsg.put("role", "system");
        sysMsg.put("content", "你是专业Java开发工程师,回答简洁规范");
        messages.add(sysMsg);
        // ç”¨æˆ·æé—®
        Map<String, String> userMsg = new HashMap<>();
        userMsg.put("role", "user");
        userMsg.put("content", userPrompt);
        messages.add(userMsg);
        // 2. è¯·æ±‚参数
        Map<String, Object> requestBody = new HashMap<>();
        requestBody.put("model", "deepseek-chat");
        requestBody.put("messages", messages);
        requestBody.put("temperature", 0.7); // éšæœºæ€§0~1,越低越严谨
        requestBody.put("max_tokens", 1024);
        // 3. æž„建请求
        String jsonBody = JSON.toJSONString(requestBody);
        RequestBody body = RequestBody.create(MediaType.parse("application/json"), jsonBody);
        Request request = new Request.Builder()
                .url(API_URL)
                .header("Authorization", "Bearer " + API_KEY)
                .header("Content-Type", "application/json")
                .post(body)
                .build();
        // 4. å‘送请求
        try (Response response = client.newCall(request).execute()) {
            if (!response.isSuccessful()) {
                return "请求失败,状态码:" + response.code() + ",错误信息:" + response.body().string();
            }
            String resJson = response.body().string();
            JSONObject jsonObj = JSON.parseObject(resJson);
            // æå–AI回答内容
            return jsonObj.getJSONArray("choices")
                    .getJSONObject(0)
                    .getJSONObject("message")
                    .getString("content");
        } catch (IOException e) {
            e.printStackTrace();
            return "接口调用异常:" + e.getMessage();
        }
    }
}
smartor/src/main/resources/mapper/smartor/ServiceOutPathMapper.xml
@@ -229,7 +229,7 @@
        FROM INFORMATION_SCHEMA.TABLES
        WHERE TABLE_NAME = 'service_out_path'
          AND table_schema = DATABASE()
          and onorgid
--           and onorgid
    </select>
</mapper>