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

develop
PL 8 months ago
parent b332503a9e
commit ccda6b3c12

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

Loading…
Cancel
Save