Commit 4a4c9824 authored by 何金镒's avatar 何金镒

优化场景推荐

parent 38c91ae9
......@@ -2,6 +2,7 @@ package com.ikonke.konkeaialibabamcp.controller;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
......@@ -268,8 +269,6 @@ public class DifyControllerV2 {
tokenService.save(bySn);
}
}
String answer = difyStreamResponse.getAnswer();
if(StrUtil.isBlank(answer)){
return "";
......
package com.ikonke.konkeaialibabamcp.controller.open;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.ikonke.konkeaialibabamcp.controller.param.ResultResp;
import com.ikonke.konkeaialibabamcp.service.SycDeviceService;
import com.ikonke.konkeaialibabamcp.utils.CcuUtils;
import com.ikonke.konkeaialibabamcp.utils.KonkeIotUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@Slf4j
@RestController
@RequestMapping("/device")
public class DeviceController2 {
@Autowired
private SycDeviceService sycDeviceService;
@Autowired
private KonkeIotUtils konkeIotServer;
@GetMapping("/triggerScene")
public ResultResp triggerScene(@RequestParam(value = "ccuName")String ccuName,
@RequestParam(value = "sceneId")String sceneId){
log.info("triggerScene--->根据主机号和场景ID触发场景....ccuName:{},sceneId:{}",ccuName,sceneId);
return ResultResp.setDate(konkeIotServer.optScene(CcuUtils.getCcuName(ccuName), sceneId));
}
@PostMapping("/saveTemporaryScene")
public ResultResp saveTemporaryScene(@RequestParam(value = "ccuName") String ccuName,
@RequestParam(value = "temporarySceneId") String temporarySceneId) {
log.info("saveTemporaryScene..临时场景存储..ccuName:{},temporarySceneId:{}",ccuName,temporarySceneId);
if(konkeIotServer.saveTemporaryScene(ccuName, temporarySceneId)){
return ResultResp.setDate("保存成功");
}else{
return ResultResp.setBadDate("保存失败");
}
}
}
package com.ikonke.konkeaialibabamcp.controller.param;
import lombok.Data;
@Data
public class ResultResp<T> {
/**
* response error code to client
*/
private int code = 0;
/**
* response error message to client
*/
private String info = "";
/**
* response data to client.
*/
private T data = null;
private String messageId;
public ResultResp() {
this(200, "SUCCESS");
}
public ResultResp(Integer code, String info) {
setCode(code);
setInfo(info);
}
public static ResultResp badRequest() {
ResultResp resp = new ResultResp(400, "bad request.");
return resp;
}
public static ResultResp setBadDate(Object t){
ResultResp resp = new ResultResp(400, "bad request.");
resp.setData(t);
return resp;
}
public static ResultResp setDate(Object t){
ResultResp resp = new ResultResp();
resp.setCode(200);
resp.setInfo("SUCCESS");
resp.setData(t);
return resp;
}
}
package com.ikonke.konkeaialibabamcp.event.listener;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ikonke.konkeaialibabamcp.entity.mysql.CDCToken;
import com.ikonke.konkeaialibabamcp.event.mode.DifyChatSteamEvent;
......@@ -54,19 +56,31 @@ public class DifyChatSteamEventListener {
.timeout(600000)
.execute().body();
log.info("【{}】:dify请求返回:{}",event.getSn(),ai_result);
log.info("dify请求返回11--->:{}",ai_result);
ai_result = ai_result.replaceAll("\n", "").trim();
log.info("dify请求返回22--->:{}",ai_result);
// String result_end = ai_result.replaceAll("(?m)^\\s*$[\r\n]*", "").replaceAll("[\r\n]+", "\n").replaceAll("[\r\n]", "").trim();
// log.info("dify请求返回2--->:{}",result_end);
JSONObject json = new JSONObject();
if(!JSONUtil.isTypeJSON(ai_result)){
json.put("msg", ai_result);
json.put("type", "other");
}else{
json = JSONUtil.parseObj(ai_result);
if(!json.containsKey("type")){
json.put("type", "other");
}
}
log.info("【{}】:dify请求返回:{}",event.getSn(),json);
// 通过WebSocket发送消息给屏端
webSocketUtil.sendToSingle(event.getSn(), ai_result);
webSocketUtil.sendToSingle(event.getSn(), json.toString());
log.info("【{}】:dify异步请求耗时--->:{}",event.getSn(),System.currentTimeMillis() - startTime);
}
} catch (Exception e) {
Thread.currentThread().interrupt();
e.printStackTrace();
Thread.currentThread().interrupt();
}
}
......
......@@ -34,8 +34,9 @@ logging:
file:
path: ./log/${server.port}
pattern:
file: '%d{yyyy/MM/dd HH:mm:ss.SSS} %-5level [%X{traceId:-}][%thread] %logger{15} : %msg%n'
console: '%d{yyyy/MM/dd HH:mm:ss.SSS} %clr(%-5level) [%X{traceId:-}][%magenta(%thread)] %cyan(%logger{15}) : %msg%n'
file: '%d{yyyy/MM/dd HH:mm:ss.SSS} %-5level [%X{traceId:-},%X{spanId:-}][%thread] %logger{15} : %msg%n'
console: '%d{yyyy/MM/dd HH:mm:ss.SSS} %clr(%-5level) [%X{traceId:-},%X{spanId:-}][%magenta(%thread)] %cyan(%logger{15}) : %msg%n'
# level: "%5p [${spring.application.name},%X{traceId},%X{spanId}]"
logback:
rollingpolicy:
max-history: 30
......@@ -59,4 +60,4 @@ cdc:
mcpAuthorization: Bearer mcp_client_konke_RTbMcnztTce6lxP6blB24zlK26H0XJHx
timeout: 20000
url: http://community.jfzhtest.com/prod-api
difyChatSteamMessages: http://172.17.12.12:${server.port}
difyChatSteamMessages: http://127.0.0.1:${server.port}
......@@ -4,7 +4,7 @@ server:
spring:
profiles:
active: prod
active: test
ai:
mcp:
server:
......
......@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.ikonke.konkeaialibabamcp.constant.RedisKeys;
import com.ikonke.konkeaialibabamcp.service.cdc.spaces.SpacesService;
import com.ikonke.konkeaialibabamcp.utils.CDCUtils;
......@@ -47,6 +48,46 @@ class KonkeAiAlibabaMcpApplicationTests {
// }
// }
// @Test
// void testJSOn(){
// String ai_result = "{\n" +
// "\"msg\":\"场景名称:睡眠模式" +
// "场景动作:" +
// "主灯:关闭" +
// "单路调光面板:关闭" +
// "智能灯带:关闭\"," +
// "\"sceneid\":\"1\"," +
// "\"type\":\"scene\"" +
// "}";
//
//
// JSONObject json = new JSONObject();
// if(!JSONUtil.isTypeJSON(ai_result)){
// json.put("msg", ai_result);
// json.put("type", "other");
// }else{
// json = JSONUtil.parseObj(ai_result);
// if(!json.containsKey("type")){
// json.put("type", "other");
// }
// }
//
//
// System.out.println("---->"+json);
// }
// @Test
// void testSpacesService() {
// JSONObject appointmentTimeByRoomId = spacesService.getAppointmentTimeByRoomId(sn, date, roomId, subspaceId);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment