From 38699011e6c1e4e269002e004f4ae47dc466a380 Mon Sep 17 00:00:00 2001 From: winter <2436197699@qq.com> Date: Fri, 5 Jan 2024 11:27:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=80=BC=E5=91=A8=E5=B7=A1=E6=A3=80?= =?UTF-8?q?=E6=8A=95=E7=A5=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ai/listener/SparkGptStreamListener.java | 3 +- src/main/java/cn/teammodel/common/PK.java | 1 + .../model/dto/weekDuty/DutyVoteDto.java | 5 +- .../repository/DutyRecordRepository.java | 1 + .../service/impl/DutyServiceImpl.java | 50 +++++++++++++++++-- 5 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/main/java/cn/teammodel/ai/listener/SparkGptStreamListener.java b/src/main/java/cn/teammodel/ai/listener/SparkGptStreamListener.java index a557e12..4369181 100644 --- a/src/main/java/cn/teammodel/ai/listener/SparkGptStreamListener.java +++ b/src/main/java/cn/teammodel/ai/listener/SparkGptStreamListener.java @@ -1,5 +1,6 @@ package cn.teammodel.ai.listener; +import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; import cn.teammodel.ai.SseHelper; import cn.teammodel.ai.domain.SparkChatResponse; @@ -64,7 +65,7 @@ public class SparkGptStreamListener extends WebSocketListener { String msgSegment = sparkChatResponse.getPayload().getChoices().getText().get(0).getContent(); // 处理消息格式(空格和换行符) // msgSegment = StrUtil.replace(msgSegment, " ", " ").replaceAll("\n", "\n"); -// msgSegment = StrUtil.replace(msgSegment, " ", " ").replaceAll("\n", "
"); + msgSegment = StrUtil.replace(msgSegment, " ", " ").replaceAll("\n", "
"); answer += msgSegment; SseHelper.send(sseEmitter, msgSegment); diff --git a/src/main/java/cn/teammodel/common/PK.java b/src/main/java/cn/teammodel/common/PK.java index 877d43b..80a6ff7 100644 --- a/src/main/java/cn/teammodel/common/PK.java +++ b/src/main/java/cn/teammodel/common/PK.java @@ -25,6 +25,7 @@ public interface PK { String CLASS = "Class-%s"; String CHAT_SESSION = "ChatSession"; String WEEK_DUTY = "Duty"; + String WEEK_DUTY_RECORD = "DutyRecord-%s"; /** * 构建分区键 diff --git a/src/main/java/cn/teammodel/model/dto/weekDuty/DutyVoteDto.java b/src/main/java/cn/teammodel/model/dto/weekDuty/DutyVoteDto.java index 449f205..27a0323 100644 --- a/src/main/java/cn/teammodel/model/dto/weekDuty/DutyVoteDto.java +++ b/src/main/java/cn/teammodel/model/dto/weekDuty/DutyVoteDto.java @@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import javax.validation.constraints.NotNull; +import java.util.List; /** * @author winter @@ -20,6 +21,8 @@ public class DutyVoteDto { @NotNull @ApiModelProperty(value = "评价节点id", required = true) private String dutyNodeId; + @ApiModelProperty(value = "评分是否传播到学生") + private Boolean spread = false; private String note; - private String[] attachments; + private List attachments; } diff --git a/src/main/java/cn/teammodel/repository/DutyRecordRepository.java b/src/main/java/cn/teammodel/repository/DutyRecordRepository.java index dab276c..7395333 100644 --- a/src/main/java/cn/teammodel/repository/DutyRecordRepository.java +++ b/src/main/java/cn/teammodel/repository/DutyRecordRepository.java @@ -10,4 +10,5 @@ import org.springframework.stereotype.Repository; */ @Repository public interface DutyRecordRepository extends CosmosRepository { + WeekDutyRecord findByClassIdAndAcademicYearIdAndCode(String classId, String academicYearId, String code); } diff --git a/src/main/java/cn/teammodel/service/impl/DutyServiceImpl.java b/src/main/java/cn/teammodel/service/impl/DutyServiceImpl.java index 50233b9..a381090 100644 --- a/src/main/java/cn/teammodel/service/impl/DutyServiceImpl.java +++ b/src/main/java/cn/teammodel/service/impl/DutyServiceImpl.java @@ -12,6 +12,7 @@ import cn.teammodel.model.entity.User; import cn.teammodel.model.entity.school.ClassInfo; import cn.teammodel.model.entity.school.School; import cn.teammodel.model.entity.weekDuty.WeekDuty; +import cn.teammodel.model.entity.weekDuty.WeekDutyRecord; import cn.teammodel.repository.ClassRepository; import cn.teammodel.repository.DutyRecordRepository; import cn.teammodel.repository.DutyRepository; @@ -19,6 +20,7 @@ import cn.teammodel.repository.SchoolRepository; import cn.teammodel.security.utils.SecurityUtil; import cn.teammodel.service.DutyService; import cn.teammodel.utils.SchoolDateUtil; +import com.azure.cosmos.models.CosmosPatchOperations; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; @@ -27,6 +29,7 @@ import javax.annotation.Resource; import java.time.Instant; import java.time.LocalDate; import java.util.ArrayList; +import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -193,7 +196,8 @@ public class DutyServiceImpl implements DutyService { String spotId = dutyVoteDto.getSpotId(); String dutyNodeId = dutyVoteDto.getDutyNodeId(); String note = dutyVoteDto.getNote(); - String[] attachments = dutyVoteDto.getAttachments(); + boolean spread = dutyVoteDto.getSpread(); + List attachments = dutyVoteDto.getAttachments(); String schoolId = SecurityUtil.getLoginUser().getSchoolId(); ClassInfo classInfo = classRepository.findClassByIdAndCode(classId, String.format(PK.CLASS, schoolId)); @@ -213,8 +217,48 @@ public class DutyServiceImpl implements DutyService { .findFirst() .orElseThrow(() -> new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "评价节点不存在")); - - + WeekDuty.DutySpot spot = duty.getSpots().stream() + .filter(x -> spotId.equals(x.getId())) + .findFirst() + .orElseThrow(() -> new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "值周评价地点不存在")); + WeekDutyRecord weekDutyRecord = dutyRecordRepository.findByClassIdAndAcademicYearIdAndCode( + classId, + academicYearId, + String.format(PK.WEEK_DUTY_RECORD, schoolId) + ); + + WeekDutyRecord.WeekDutyItem newItem = new WeekDutyRecord.WeekDutyItem(); + newItem.setId(UUID.randomUUID().toString()); + newItem.setDutyTreeNode(dutyNode); + newItem.setSpotId(spot.getId()); + newItem.setSpotName(spot.getName()); + newItem.setSpread(spread); + newItem.setAttachments(attachments); + newItem.setNote(note); + newItem.setCreateTime(Instant.now().toEpochMilli()); + // 不存在则创建 + if (weekDutyRecord == null) { + List nodes = Collections.singletonList(newItem); + weekDutyRecord = new WeekDutyRecord(); + weekDutyRecord.setClassId(classId); + weekDutyRecord.setClassName(className); + weekDutyRecord.setAcademicYearId(academicYearId); + weekDutyRecord.setScore(0); + weekDutyRecord.setNodes(nodes); + weekDutyRecord.setCode(String.format(PK.WEEK_DUTY_RECORD, schoolId)); + weekDutyRecord.setCreateTime(Instant.now().toEpochMilli()); + dutyRecordRepository.save(weekDutyRecord); + } else { + CosmosPatchOperations operations = CosmosPatchOperations.create(); + operations.add("/nodes/-", newItem); + operations.increment("/score", dutyNode.getScore()); + dutyRecordRepository.save( + weekDutyRecord.getId(), + PK.buildOf(PK.WEEK_DUTY_RECORD, schoolId), + WeekDutyRecord.class, + operations + ); + } } /**