排查测试无异常,正式站访问异常问题

develop
PL 8 months ago
parent b332503a9e
commit ccda6b3c12

@ -74,6 +74,7 @@ public class ChatMessageServiceImpl implements ChatMessageService {
*/ */
@Override @Override
public SseEmitter chatComments(ChatCommentsDto chatCommentsDto, String userId, String userName) { public SseEmitter chatComments(ChatCommentsDto chatCommentsDto, String userId, String userName) {
try {
// 目前仅使用讯飞星火大模型 // 目前仅使用讯飞星火大模型
String appId = chatCommentsDto.getAppId(); String appId = chatCommentsDto.getAppId();
String text = commentsTemplate(chatCommentsDto); String text = commentsTemplate(chatCommentsDto);
@ -94,6 +95,9 @@ public class ChatMessageServiceImpl implements ChatMessageService {
sseEmitter = completionByApp(chatCompletionReqDto, false); sseEmitter = completionByApp(chatCompletionReqDto, false);
} }
return sseEmitter; return sseEmitter;
} catch (Exception e) {
throw new ServiceException(ErrorCode.OPERATION_ERROR.getCode(), e.getMessage());
}
} }
/** /**
@ -290,47 +294,45 @@ public class ChatMessageServiceImpl implements ChatMessageService {
/** /**
* *
* *
*
* @return * @return
*/ */
private String commentsTemplate(ChatCommentsDto chatCommentsDto) { private String commentsTemplate(ChatCommentsDto chatCommentsDto) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
String strData = JSON.toJSONString(chatCommentsDto.getData()); String strData = JSON.toJSONString(chatCommentsDto.getData());
List<ChatModelDto> chatModels = new ArrayList<>();
ChatModelDto chatModel = null;
try {
File file = new File(ClassLoader.getSystemResource("Json/ChatModel.json").getPath()); //相对路径获取文件信息 File file = new File(ClassLoader.getSystemResource("Json/ChatModel.json").getPath()); //相对路径获取文件信息
//File file = new File("src/main/resources/Json/ChatModel.json"); //绝对路径获取文件信息 //File file = new File("src/main/resources/Json/ChatModel.json"); //绝对路径获取文件信息
List<ChatModelDto> chatModels = new ArrayList<>();
ChatModelDto chatModel = null;
//chatModel = readerMethod(file); //chatModel = readerMethod(file);
chatModels = readerMethod(file); chatModels = readerMethod(file);
if(chatModels.size() <= 0) } catch (Exception e) {
{ throw new ServiceException(ErrorCode.OPERATION_ERROR.getCode(), e.getMessage());
throw new ServiceException(ErrorCode.NOT_FOUND_ERROR.getCode(), "评语模版未配置");
} }
//循环查找对应的模型数据 //循环查找对应的模型数据
for(ChatModelDto chatModelTemp : chatModels) for (ChatModelDto chatModelTemp : chatModels) {
{
//判断评语类型 //判断评语类型
if(chatCommentsDto.getType().equals(chatModelTemp.getType())) if (chatCommentsDto.getType().equals(chatModelTemp.getType())) {
{
chatModel = chatModelTemp; chatModel = chatModelTemp;
break; break;
} }
} }
if(chatModel != null) 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; ChatModelDto finalChatModel = chatModel;
//模版 //模版
switch (chatCommentsDto.getType()) { switch (chatCommentsDto.getType()) {
//智育 总体评语模版 //智育 总体评语模版
case "wisdom": case "wisdom": {
{
WisdomCommentsDto wisdomComments; WisdomCommentsDto wisdomComments;
//转换问题 //转换问题
try { try {
@ -339,8 +341,7 @@ public class ChatMessageServiceImpl implements ChatMessageService {
} catch (Exception e) { } catch (Exception e) {
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "类型转换失败"); throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "类型转换失败");
} }
if(wisdomComments.getName() == null) if (wisdomComments.getName() == null) {
{
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "请求参数异常"); throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "请求参数异常");
} }
@ -384,63 +385,66 @@ public class ChatMessageServiceImpl implements ChatMessageService {
item.data[4] item.data[4]
)); ));
}); });
builder.append(String.format(finalChatModel.getEnd(),wisdomComments.getName())); builder.append(String.format(finalChatModel.getEnd(), wisdomComments.getName()));
break; break;
} }
//智育 表现模版 //智育 表现模版
case "wisdomExam": case "wisdomExam": {
{
List<WisdomExamCommentsDto> examComments = new ArrayList<>(); List<WisdomExamCommentsDto> examComments = new ArrayList<>();
try { try {
examComments = JSON.parseObject(strData, new TypeReference<List<WisdomExamCommentsDto>>() {}); examComments = JSON.parseObject(strData, new TypeReference<List<WisdomExamCommentsDto>>() {
});
} catch (Exception e) { } catch (Exception e) {
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "类型转换失败"); throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "类型转换失败");
} }
if(examComments.size() <= 1){ if (examComments.size() <= 1) {
if (examComments.isEmpty()){ if (examComments.isEmpty()) {
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "请求参数异常"); throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "请求参数异常");
} }
if (examComments.get(0).name == null){ if (examComments.get(0).name == null) {
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "请求参数异常"); throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "请求参数异常");
} }
} }
int count = 1; int count = 1;
for (WisdomExamCommentsDto examComment : examComments) { for (WisdomExamCommentsDto examComment : examComments) {
builder.append(String.format(finalChatModel.getCycleChats().get(0), count, examComment.getName(), examComment.getTime(), examComment.getScore(), examComment.getScoreRate(), examComment.getRanking())); builder.append(String.format(finalChatModel.getCycleChats().get(0), count, examComment.getName(),
if (count < examComments.size()) examComment.getTime(), examComment.getScore(), examComment.getScoreRate(),
{ examComment.getRanking()));
if (count < examComments.size()) {
count++; count++;
} }
} }
builder.append(String.format(finalChatModel.getEnd(),count)); builder.append(String.format(finalChatModel.getEnd(), count));
break; break;
} }
// 智育 学科评语模版 // 智育 学科评语模版
case "windomSubject": case "windomSubject": {
{
List<WisdomSubjectComments> subjectComments; List<WisdomSubjectComments> subjectComments;
try { try {
subjectComments = JSON.parseObject(strData, new TypeReference<List<WisdomSubjectComments>>() {}); subjectComments = JSON.parseObject(strData, new TypeReference<List<WisdomSubjectComments>>() {
} });
catch (Exception e) { } catch (Exception e) {
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "请求参数异常"); throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "请求参数异常");
} }
if(subjectComments.size() <= 1){ if (subjectComments.size() <= 1) {
if (subjectComments.isEmpty()){ if (subjectComments.isEmpty()) {
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "请求参数异常"); throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "请求参数异常");
} }
} }
builder.append(finalChatModel.getChat()); builder.append(finalChatModel.getChat());
//拼接学科数组 //拼接学科数组
for (WisdomSubjectComments comments : subjectComments){ for (WisdomSubjectComments comments : subjectComments) {
builder.append(String.format(finalChatModel.getCycleChats().get(0), comments.subjectName)); builder.append(String.format(finalChatModel.getCycleChats().get(0), comments.subjectName));
for (WisdomSubjectComments.StuInfo stuInfo : comments.getRankings()){ for (WisdomSubjectComments.StuInfo stuInfo : comments.getRankings()) {
builder.append(String.format(finalChatModel.getCycleChats().get(1), stuInfo.ranking, stuInfo.name, stuInfo.scoreRate)); builder.append(String.format(finalChatModel.getCycleChats().get(1), stuInfo.ranking,
stuInfo.name, stuInfo.scoreRate));
} }
builder.append(String.format(finalChatModel.getCycleChats().get(2), comments.getClaasRanking().ranking, comments.getClaasRanking().scoreRate,comments.getClaasRanking().average)); builder.append(String.format(finalChatModel.getCycleChats().get(2),
comments.getClaasRanking().ranking, comments.getClaasRanking().scoreRate,
comments.getClaasRanking().average));
} }
builder.append(String.format(finalChatModel.getEnd(),subjectComments.size())); builder.append(String.format(finalChatModel.getEnd(), subjectComments.size()));
break; break;
} }
//艺术 考核指标纬度评语 //艺术 考核指标纬度评语
@ -462,11 +466,11 @@ public class ChatMessageServiceImpl implements ChatMessageService {
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "评语类型异常"); throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "评语类型异常");
} }
if (chatCommentsDto.getSize() > 0 ){ if (chatCommentsDto.getSize() > 0) {
builder.append("字数限制在:") builder.append("字数限制在:")
.append(chatCommentsDto.getSize()) .append(chatCommentsDto.getSize())
.append("字左右"); .append("字左右");
}else { } else {
builder.append("字数限制在200字左右"); builder.append("字数限制在200字左右");
} }
@ -475,13 +479,14 @@ public class ChatMessageServiceImpl implements ChatMessageService {
/** /**
* *
*
* @param file * @param file
* @return * @return
*/ */
private static List<ChatModelDto> readerMethod(File file) { private static List<ChatModelDto> readerMethod(File file) {
//读取文件信息并返回string字符串 并改成json格式 //读取文件信息并返回string字符串 并改成json格式
String fileTxt = FileUtil.readFile(file); String fileTxt = FileUtil.readFile(file);
String strData =JSON.toJSONString(fileTxt); String strData = JSON.toJSONString(fileTxt);
//获取聊天字段中的数据 //获取聊天字段中的数据
Object str = JSON.parseObject(strData).get("chatModel"); Object str = JSON.parseObject(strData).get("chatModel");
@ -491,7 +496,8 @@ public class ChatMessageServiceImpl implements ChatMessageService {
//转换问题 //转换问题
try { try {
//转换方式 //转换方式
chatModelDtos = JSON.parseObject(strData2, new TypeReference<List<ChatModelDto>>() {}); chatModelDtos = JSON.parseObject(strData2, new TypeReference<List<ChatModelDto>>() {
});
} catch (Exception e) { } catch (Exception e) {
throw new ServiceException(ErrorCode.OPERATION_ERROR.getCode(), "类型转换失败"); throw new ServiceException(ErrorCode.OPERATION_ERROR.getCode(), "类型转换失败");
} }

Loading…
Cancel
Save