feat: 值周巡检投票

11111
winter 12 months ago
parent eec45f6921
commit 38699011e6

@ -1,5 +1,6 @@
package cn.teammodel.ai.listener; package cn.teammodel.ai.listener;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import cn.teammodel.ai.SseHelper; import cn.teammodel.ai.SseHelper;
import cn.teammodel.ai.domain.SparkChatResponse; import cn.teammodel.ai.domain.SparkChatResponse;
@ -64,7 +65,7 @@ public class SparkGptStreamListener extends WebSocketListener {
String msgSegment = sparkChatResponse.getPayload().getChoices().getText().get(0).getContent(); String msgSegment = sparkChatResponse.getPayload().getChoices().getText().get(0).getContent();
// 处理消息格式(空格和换行符) // 处理消息格式(空格和换行符)
// msgSegment = StrUtil.replace(msgSegment, " ", " ").replaceAll("\n", "&#92n"); // msgSegment = StrUtil.replace(msgSegment, " ", " ").replaceAll("\n", "&#92n");
// msgSegment = StrUtil.replace(msgSegment, " ", "&#32;").replaceAll("\n", "<br/>"); msgSegment = StrUtil.replace(msgSegment, " ", "&#32;").replaceAll("\n", "<br>");
answer += msgSegment; answer += msgSegment;
SseHelper.send(sseEmitter, msgSegment); SseHelper.send(sseEmitter, msgSegment);

@ -25,6 +25,7 @@ public interface PK {
String CLASS = "Class-%s"; String CLASS = "Class-%s";
String CHAT_SESSION = "ChatSession"; String CHAT_SESSION = "ChatSession";
String WEEK_DUTY = "Duty"; String WEEK_DUTY = "Duty";
String WEEK_DUTY_RECORD = "DutyRecord-%s";
/** /**
* *

@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.List;
/** /**
* @author winter * @author winter
@ -20,6 +21,8 @@ public class DutyVoteDto {
@NotNull @NotNull
@ApiModelProperty(value = "评价节点id", required = true) @ApiModelProperty(value = "评价节点id", required = true)
private String dutyNodeId; private String dutyNodeId;
@ApiModelProperty(value = "评分是否传播到学生")
private Boolean spread = false;
private String note; private String note;
private String[] attachments; private List<String> attachments;
} }

@ -10,4 +10,5 @@ import org.springframework.stereotype.Repository;
*/ */
@Repository @Repository
public interface DutyRecordRepository extends CosmosRepository<WeekDutyRecord, String> { public interface DutyRecordRepository extends CosmosRepository<WeekDutyRecord, String> {
WeekDutyRecord findByClassIdAndAcademicYearIdAndCode(String classId, String academicYearId, String code);
} }

@ -12,6 +12,7 @@ import cn.teammodel.model.entity.User;
import cn.teammodel.model.entity.school.ClassInfo; import cn.teammodel.model.entity.school.ClassInfo;
import cn.teammodel.model.entity.school.School; import cn.teammodel.model.entity.school.School;
import cn.teammodel.model.entity.weekDuty.WeekDuty; import cn.teammodel.model.entity.weekDuty.WeekDuty;
import cn.teammodel.model.entity.weekDuty.WeekDutyRecord;
import cn.teammodel.repository.ClassRepository; import cn.teammodel.repository.ClassRepository;
import cn.teammodel.repository.DutyRecordRepository; import cn.teammodel.repository.DutyRecordRepository;
import cn.teammodel.repository.DutyRepository; import cn.teammodel.repository.DutyRepository;
@ -19,6 +20,7 @@ import cn.teammodel.repository.SchoolRepository;
import cn.teammodel.security.utils.SecurityUtil; import cn.teammodel.security.utils.SecurityUtil;
import cn.teammodel.service.DutyService; import cn.teammodel.service.DutyService;
import cn.teammodel.utils.SchoolDateUtil; import cn.teammodel.utils.SchoolDateUtil;
import com.azure.cosmos.models.CosmosPatchOperations;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -27,6 +29,7 @@ import javax.annotation.Resource;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -193,7 +196,8 @@ public class DutyServiceImpl implements DutyService {
String spotId = dutyVoteDto.getSpotId(); String spotId = dutyVoteDto.getSpotId();
String dutyNodeId = dutyVoteDto.getDutyNodeId(); String dutyNodeId = dutyVoteDto.getDutyNodeId();
String note = dutyVoteDto.getNote(); String note = dutyVoteDto.getNote();
String[] attachments = dutyVoteDto.getAttachments(); boolean spread = dutyVoteDto.getSpread();
List<String> attachments = dutyVoteDto.getAttachments();
String schoolId = SecurityUtil.getLoginUser().getSchoolId(); String schoolId = SecurityUtil.getLoginUser().getSchoolId();
ClassInfo classInfo = classRepository.findClassByIdAndCode(classId, String.format(PK.CLASS, schoolId)); ClassInfo classInfo = classRepository.findClassByIdAndCode(classId, String.format(PK.CLASS, schoolId));
@ -213,8 +217,48 @@ public class DutyServiceImpl implements DutyService {
.findFirst() .findFirst()
.orElseThrow(() -> new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "评价节点不存在")); .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<WeekDutyRecord.WeekDutyItem> 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
);
}
} }
/** /**

Loading…
Cancel
Save