|
|
|
@ -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<String> 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<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
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|