feat: 新增多条件查询评价明细接口

11111
winter 12 months ago
parent 327e399d5a
commit 1a18105096

@ -4,6 +4,7 @@ import cn.teammodel.common.IdRequest;
import cn.teammodel.common.R; import cn.teammodel.common.R;
import cn.teammodel.model.dto.weekDuty.*; import cn.teammodel.model.dto.weekDuty.*;
import cn.teammodel.model.entity.weekDuty.WeekDuty; import cn.teammodel.model.entity.weekDuty.WeekDuty;
import cn.teammodel.model.entity.weekDuty.WeekDutyRecord;
import cn.teammodel.service.DutyService; import cn.teammodel.service.DutyService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -73,7 +74,12 @@ public class DutyController {
return R.success(spots); return R.success(spots);
} }
@PostMapping("/findRecords")
@ApiOperation("多条件查询评价明细")
public R<List<WeekDutyRecord.WeekDutyItem>> findRecords(@RequestBody @Valid FindDutyRecordDto findDutyRecordDto) {
List<WeekDutyRecord.WeekDutyItem> items = dutyService.findRecords(findDutyRecordDto);
return R.success(items);
}

@ -0,0 +1,25 @@
package cn.teammodel.model.dto.weekDuty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* @author winter
* @create 2024-01-08 15:31
*/
@Data
public class FindDutyRecordDto {
@ApiModelProperty(value = "班级 id", notes = "若不携带默认不指定某个班级")
private String classId;
@ApiModelProperty(required = true)
@NotNull(message = "学年 id 不能为空")
private String academicYearId;
@ApiModelProperty(value = "是否加分", notes = "若不携带默认为全部")
private Boolean positive;
@ApiModelProperty(value = "起始时间", notes = "若不携带默认为当前周")
private Long startTime;
@ApiModelProperty(value = "结束时间", notes = "若不携带默认为当前周")
private Long endTime;
}

@ -43,6 +43,8 @@ public class WeekDutyRecord extends BaseItem {
* *
*/ */
private String note; private String note;
private String creator;
private String creatorId;
private Long createTime; private Long createTime;
} }
} }

@ -2,8 +2,11 @@ package cn.teammodel.repository;
import cn.teammodel.model.entity.weekDuty.WeekDutyRecord; import cn.teammodel.model.entity.weekDuty.WeekDutyRecord;
import com.azure.spring.data.cosmos.repository.CosmosRepository; import com.azure.spring.data.cosmos.repository.CosmosRepository;
import com.azure.spring.data.cosmos.repository.Query;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
/** /**
* @author winter * @author winter
* @create 2024-01-04 17:23 * @create 2024-01-04 17:23
@ -11,4 +14,15 @@ 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); WeekDutyRecord findByClassIdAndAcademicYearIdAndCode(String classId, String academicYearId, String code);
@Query(value = "SELECT value n FROM c join n in c.nodes WHERE " +
"c.code = @code " +
"AND c.academicYearId = @academicYearId " +
"AND n.creatorId = @userId " +
"AND (IS_NULL(@classId) or c.classId = @classId) " +
"AND (IS_NULL(@positive) or n.dutyTreeNode.positive = @positive) " +
"AND (IS_NULL(@startTime) or n.createTime >= @startTime) " +
"AND (IS_NULL(@endTime) or n.createTime <= @endTime)")
List<WeekDutyRecord.WeekDutyItem> findRecordsByConditions(String code, String academicYearId, String userId, String classId, Boolean positive, Long startTime, Long endTime);
} }

@ -2,6 +2,7 @@ package cn.teammodel.service;
import cn.teammodel.model.dto.weekDuty.*; import cn.teammodel.model.dto.weekDuty.*;
import cn.teammodel.model.entity.weekDuty.WeekDuty; import cn.teammodel.model.entity.weekDuty.WeekDuty;
import cn.teammodel.model.entity.weekDuty.WeekDutyRecord;
import java.util.List; import java.util.List;
@ -23,4 +24,6 @@ public interface DutyService {
List<WeekDuty.DutySpot> insertSpot(InsertSpotDto insertSpotDto); List<WeekDuty.DutySpot> insertSpot(InsertSpotDto insertSpotDto);
List<WeekDuty.DutySpot> deleteSpot(String id); List<WeekDuty.DutySpot> deleteSpot(String id);
List<WeekDutyRecord.WeekDutyItem> findRecords(FindDutyRecordDto findDutyRecordDto);
} }

@ -23,8 +23,8 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.Instant; import java.time.*;
import java.time.LocalDate; import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
@ -205,8 +205,9 @@ public class DutyServiceImpl implements DutyService {
String note = dutyVoteDto.getNote(); String note = dutyVoteDto.getNote();
boolean spread = dutyVoteDto.getSpread(); boolean spread = dutyVoteDto.getSpread();
List<String> attachments = dutyVoteDto.getAttachments(); List<String> attachments = dutyVoteDto.getAttachments();
User user = SecurityUtil.getLoginUser();
String schoolId = user.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));
if (classInfo == null) { if (classInfo == null) {
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "目标班级不存在"); throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "目标班级不存在");
@ -227,6 +228,11 @@ public class DutyServiceImpl implements DutyService {
if (dutyNode.getPath() == null || dutyNode.getPath().length == 0) { if (dutyNode.getPath() == null || dutyNode.getPath().length == 0) {
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "只能评价三级节点"); throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "只能评价三级节点");
} }
// dutynode 剪枝
dutyNode.setCreator(null);
dutyNode.setCreatorId(null);
dutyNode.setCreateTime(null);
WeekDuty.DutySpot spot = duty.getSpots().stream() WeekDuty.DutySpot spot = duty.getSpots().stream()
.filter(x -> spotId.equals(x.getId())) .filter(x -> spotId.equals(x.getId()))
.findFirst() .findFirst()
@ -246,6 +252,8 @@ public class DutyServiceImpl implements DutyService {
newItem.setAttachments(attachments); newItem.setAttachments(attachments);
newItem.setNote(note); newItem.setNote(note);
newItem.setCreateTime(Instant.now().toEpochMilli()); newItem.setCreateTime(Instant.now().toEpochMilli());
newItem.setCreator(user.getName());
newItem.setCreatorId(user.getId());
// 不存在则创建 // 不存在则创建
if (weekDutyRecord == null) { if (weekDutyRecord == null) {
List<WeekDutyRecord.WeekDutyItem> nodes = Collections.singletonList(newItem); List<WeekDutyRecord.WeekDutyItem> nodes = Collections.singletonList(newItem);
@ -303,6 +311,37 @@ public class DutyServiceImpl implements DutyService {
return duty.getSpots(); return duty.getSpots();
} }
@Override
public List<WeekDutyRecord.WeekDutyItem> findRecords(FindDutyRecordDto findDutyRecordDto) {
String classId = StringUtils.isEmpty(findDutyRecordDto.getClassId()) ? null : findDutyRecordDto.getClassId();
String academicYearId = findDutyRecordDto.getAcademicYearId();
Boolean positive = findDutyRecordDto.getPositive();
Long startTime = findDutyRecordDto.getStartTime();
Long endTime = findDutyRecordDto.getEndTime();
User user = SecurityUtil.getLoginUser();
String schoolId = user.getSchoolId();
String userId = user.getId();
if (startTime == null || endTime == null) {
LocalDateTime mondayOfCurWeek = LocalDateTime.now().with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY))
.withHour(0)
.withMinute(0)
.withSecond(0)
.withNano(0);
startTime = mondayOfCurWeek.atZone(ZoneOffset.systemDefault()).toInstant().toEpochMilli();
endTime = Instant.now().toEpochMilli();
}
List<WeekDutyRecord.WeekDutyItem> records = dutyRecordRepository.findRecordsByConditions(
String.format(PK.WEEK_DUTY_RECORD, schoolId),
academicYearId,
userId,
classId,
positive,
startTime,
endTime);
return records;
}
/** /**
* spots id * spots id
*/ */

Loading…
Cancel
Save