diff --git a/src/main/java/cn/teammodel/service/impl/ChatMessageServiceImpl.java b/src/main/java/cn/teammodel/service/impl/ChatMessageServiceImpl.java index aed57fa..40a8682 100644 --- a/src/main/java/cn/teammodel/service/impl/ChatMessageServiceImpl.java +++ b/src/main/java/cn/teammodel/service/impl/ChatMessageServiceImpl.java @@ -312,30 +312,25 @@ public class ChatMessageServiceImpl implements ChatMessageService { ChatModelDto chatModel = null; //验证获取模型数据 异常问题 - File file = null; try { String fileText = FileUtil.getFileText("Json/ChatModel.json"); - //转换问题 - try { - //String strData01 = JSON.toJSONString(fileText); - //获取聊天字段中的数据 - Object str = JSON.parseObject(fileText).get("chatModel"); - String strData1 = JSON.toJSONString(str); - //转换方式 - chatModels = JSON.parseObject(strData1, new TypeReference>() { }); - } catch (Exception e) { - throw new ServiceException(ErrorCode.OPERATION_ERROR.getCode(), "类型转换失败"); - } + String jsonData = JSON.toJSONString(fileText); + //获取聊天字段中的数据 + Object obj = JSON.parseObject(jsonData).get("chatModel"); + String jsonData01 = JSON.toJSONString(obj); + //转换方式 + chatModels = JSON.parseObject(jsonData01, new TypeReference>() {}); - //chatModels = readResourceFile("Json/ChatModel.json"); - //String str = readResourceFile("Json/ChatModel.json"); - //file = new File(ClassLoader.getSystemResource("Json/ChatModel.json").getPath()); //相对路径获取文件信息 - //File file = new File("src/main/resources/Json/ChatModel.json"); //绝对路径获取文件信息 + log.info("获取地址fileText:"+fileText+"----文件内容Data:"+ jsonData +"----获取模型集合Object:" + obj +"----获取模型集合String:"+ jsonData01 +"----获取模型集合机构:"+chatModels); } catch (Exception e) { throw new ServiceException(ErrorCode.OPERATION_ERROR.getCode(), "读取文件" + Arrays.toString(e.getStackTrace()) + e.getMessage()); } + /*try { - //chatModel = readerMethod(file); + //File file = null; + //chatModels = readResourceFile("Json/ChatModel.json"); + //file = new File(ClassLoader.getSystemResource("Json/ChatModel.json").getPath()); //相对路径获取文件信息 + //File file = new File("src/main/resources/Json/ChatModel.json"); //绝对路径获取文件信息 chatModels = readerMethod(file); } catch (Exception e) { throw new ServiceException(ErrorCode.OPERATION_ERROR.getCode(), "读取文件并转换实体类" + Arrays.toString(e.getStackTrace())); @@ -352,8 +347,7 @@ public class ChatMessageServiceImpl implements ChatMessageService { if (chatModel != null) { //角色条件 - builder.append(String.format(chatModel.getRole(), chatCommentsDto.getPeriod(), - chatCommentsDto.getSubject())); + builder.append(String.format(chatModel.getRole(), chatCommentsDto.getPeriod(), chatCommentsDto.getSubject())); } ChatModelDto finalChatModel = chatModel;