From 4102e0706ca52421f2776905c6e0b72d9a71ed4b Mon Sep 17 00:00:00 2001
From: xusd <330628789@qq.com>
Date: Fri, 27 Jun 2025 22:21:47 +0800
Subject: [PATCH] Merge branch 'gzdyh_prod'

---
 dyh-service/dyh-sys/src/main/java/cn/huge/module/ai/AiChatController.java |  109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 109 insertions(+), 0 deletions(-)

diff --git a/dyh-service/dyh-sys/src/main/java/cn/huge/module/ai/AiChatController.java b/dyh-service/dyh-sys/src/main/java/cn/huge/module/ai/AiChatController.java
new file mode 100644
index 0000000..b0b75fd
--- /dev/null
+++ b/dyh-service/dyh-sys/src/main/java/cn/huge/module/ai/AiChatController.java
@@ -0,0 +1,109 @@
+package cn.huge.module.ai;
+
+import cn.huge.base.common.bo.R;
+import cn.huge.base.common.utils.HttpClientUtils;
+import cn.huge.base.common.utils.ReturnFailUtils;
+import cn.huge.base.common.utils.ReturnSucUtils;
+import cn.huge.module.ai.domain.AiBodyDto;
+import cn.huge.module.ai.domain.AiRequestVo;
+import cn.huge.module.sy.domain.po.SyTimeLimit;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.net.http.HttpClient;
+import java.util.HashMap;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/api/web/ai/chat")
+@Slf4j
+public class AiChatController {
+
+    private String url = "http://10.202.1.102:9002/";
+
+    @PostMapping("/risk")
+    public R<String> risk(@RequestBody AiRequestVo aiRequestVo) {
+        String postUrl = url + "v1/workflows/run";
+        initHead("Bearer app-8ylvZOHf2fOgTGfe28MYtHDD");
+        String s = "";
+        try {
+            s = HttpClientUtils.httpPostRaw(postUrl, JSON.toJSONString(aiRequestVo), initHead("Bearer app-8ylvZOHf2fOgTGfe28MYtHDD"), "utf-8");
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        JSONObject object = JSONObject.parseObject(s);
+        if (object != null) {
+            JSONObject data = object.getJSONObject("data");
+            if (data != null) {
+                JSONObject outputs = data.getJSONObject("outputs");
+                if (outputs != null) {
+                    JSONObject body = outputs.getJSONObject("body");
+                    if (body != null) {
+                        return R.ok(body.getJSONObject("data").getString("is_risk_ai"));
+                    }
+                }
+            }
+        }
+        log.info("xsd:{}", object);
+        return R.ok("0");
+    }
+
+    @PostMapping("/chat")
+    public R<AiBodyDto> chat(@RequestBody AiRequestVo aiRequestVo) {
+        String postUrl = url + "v1/chat-messages";
+        String s = "";
+        AiBodyDto aiBodyDto = new AiBodyDto();
+        try {
+            s = HttpClientUtils.httpPostRaw(postUrl, JSON.toJSONString(aiRequestVo), initHead("Bearer app-8naZjGyj8a129EuUP2Jb6n7T"), "utf-8");
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        JSONObject object = JSONObject.parseObject(s);
+        if (object != null) {
+            String conversation_id = object.getString("conversation_id");
+            String answer = object.getString("answer");
+            aiBodyDto.setAnswer(answer);
+            aiBodyDto.setConversationId(conversation_id);
+        }
+        log.info("xsd:{}", aiBodyDto);
+        return R.ok(aiBodyDto);
+    }
+
+    @PostMapping("/strategy")
+    public R<AiBodyDto> strategy(@RequestBody AiRequestVo aiRequestVo) {
+        String postUrl = url + "v1/workflows/run";
+        String s = "";
+        AiBodyDto aiBodyDto = new AiBodyDto();
+        try {
+            s = HttpClientUtils.httpPostRaw(postUrl, JSON.toJSONString(aiRequestVo), initHead("Bearer app-WMriHFsAozx0FECkopW2Z6X1"), "utf-8");
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        JSONObject object = JSONObject.parseObject(s);
+        if (object != null) {
+            JSONObject data = object.getJSONObject("data");
+            if (data != null) {
+                JSONObject outputs = data.getJSONObject("outputs");
+                if (outputs != null) {
+                    String text = outputs.getString("text");
+                    aiBodyDto.setAnswer(text);
+                }
+            }
+        }
+        log.info("xsd:{}", aiBodyDto);
+        return R.ok(aiBodyDto);
+    }
+
+    private Map<String, String> initHead(String token) {
+        Map<String, String> head = new HashMap<>();
+        head.put("Content-Type", "application/json");
+        head.put("Authorization", token);
+        return head;
+    }
+}

--
Gitblit v1.8.0