feat: 撤回值周投票

11111
winter 12 months ago
parent d155efe947
commit 8c15427ff7

@ -4,7 +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.model.vo.weekDuty.DutyRecordVo;
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;
@ -60,6 +60,13 @@ public class DutyController {
return R.success("评价成功"); return R.success("评价成功");
} }
@PostMapping("/recallVote")
@ApiOperation("值周评价投票")
public R<String> recallVote(@RequestBody @Valid RecallDutyVoteDto recallDutyVoteDto) {
dutyService.recallVote(recallDutyVoteDto);
return R.success("撤回评价成功");
}
@PostMapping("/insertSpot") @PostMapping("/insertSpot")
@ApiOperation("插入值周评价地点") @ApiOperation("插入值周评价地点")
public R<List<WeekDuty.DutySpot>> insertSpot(@RequestBody @Valid InsertSpotDto insertSpotDto) { public R<List<WeekDuty.DutySpot>> insertSpot(@RequestBody @Valid InsertSpotDto insertSpotDto) {
@ -76,8 +83,8 @@ public class DutyController {
@PostMapping("/findRecords") @PostMapping("/findRecords")
@ApiOperation("多条件查询评价明细") @ApiOperation("多条件查询评价明细")
public R<List<WeekDutyRecord.WeekDutyItem>> findRecords(@RequestBody @Valid FindDutyRecordDto findDutyRecordDto) { public R<List<DutyRecordVo>> findRecords(@RequestBody @Valid FindDutyRecordDto findDutyRecordDto) {
List<WeekDutyRecord.WeekDutyItem> items = dutyService.findRecords(findDutyRecordDto); List<DutyRecordVo> items = dutyService.findRecords(findDutyRecordDto);
return R.success(items); return R.success(items);
} }

@ -0,0 +1,20 @@
package cn.teammodel.model.dto.weekDuty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* @author winter
* @create 2023-11-22 16:16
*/
@Data
public class RecallDutyVoteDto {
@NotNull
@ApiModelProperty(value = "值周记录的文档id", required = true)
String recordId;
@NotNull
@ApiModelProperty(value = "值周记录的具体节点id", required = true)
String nodeId;
}

@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.PositiveOrZero;
/** /**
* @author winter * @author winter
@ -18,7 +19,8 @@ public class UpdateDutyNodeDto {
private String id; private String id;
private String name; private String name;
private String desc; private String desc;
private Boolean positive = true;
private Integer order = 0; private Integer order = 0;
@PositiveOrZero(message = "分数不能为负数")
private Integer score = 0; private Integer score = 0;
// boolean positive;
} }

@ -0,0 +1,16 @@
package cn.teammodel.model.vo.weekDuty;
import cn.teammodel.model.entity.weekDuty.WeekDutyRecord;
import lombok.Data;
/**
* @author winter
* @create 2023-12-04 15:26
*/
@Data
public class DutyRecordVo {
private String recordId;
private String classId;
private String className;
private WeekDutyRecord.WeekDutyItem info;
}

@ -1,6 +1,7 @@
package cn.teammodel.repository; package cn.teammodel.repository;
import cn.teammodel.model.entity.weekDuty.WeekDutyRecord; import cn.teammodel.model.entity.weekDuty.WeekDutyRecord;
import cn.teammodel.model.vo.weekDuty.DutyRecordVo;
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 com.azure.spring.data.cosmos.repository.Query;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@ -15,7 +16,7 @@ import java.util.List;
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 " + @Query(value = "SELECT c.id as recordId, c.classId, c.className, n as info FROM c join n in c.nodes WHERE " +
"c.code = @code " + "c.code = @code " +
"AND c.academicYearId = @academicYearId " + "AND c.academicYearId = @academicYearId " +
"AND n.creatorId = @userId " + "AND n.creatorId = @userId " +
@ -23,6 +24,6 @@ public interface DutyRecordRepository extends CosmosRepository<WeekDutyRecord, S
"AND (IS_NULL(@positive) or n.dutyTreeNode.positive = @positive) " + "AND (IS_NULL(@positive) or n.dutyTreeNode.positive = @positive) " +
"AND (IS_NULL(@startTime) or n.createTime >= @startTime) " + "AND (IS_NULL(@startTime) or n.createTime >= @startTime) " +
"AND (IS_NULL(@endTime) or n.createTime <= @endTime)") "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); List<DutyRecordVo> findRecordsByConditions(String code, String academicYearId, String userId, String classId, Boolean positive, Long startTime, Long endTime);
} }

@ -2,7 +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 cn.teammodel.model.vo.weekDuty.DutyRecordVo;
import java.util.List; import java.util.List;
@ -25,5 +25,7 @@ public interface DutyService {
List<WeekDuty.DutySpot> deleteSpot(String id); List<WeekDuty.DutySpot> deleteSpot(String id);
List<WeekDutyRecord.WeekDutyItem> findRecords(FindDutyRecordDto findDutyRecordDto); List<DutyRecordVo> findRecords(FindDutyRecordDto findDutyRecordDto);
void recallVote(RecallDutyVoteDto recallDutyVoteDto);
} }

@ -10,6 +10,7 @@ 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.model.entity.weekDuty.WeekDutyRecord;
import cn.teammodel.model.vo.weekDuty.DutyRecordVo;
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;
@ -25,10 +26,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.*; import java.time.*;
import java.time.temporal.TemporalAdjusters; import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList; import java.util.*;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -158,6 +156,7 @@ public class DutyServiceImpl implements DutyService {
String newNodeName = updateDutyNodeDto.getName(); String newNodeName = updateDutyNodeDto.getName();
Integer newScore = updateDutyNodeDto.getScore(); Integer newScore = updateDutyNodeDto.getScore();
String desc = updateDutyNodeDto.getDesc(); String desc = updateDutyNodeDto.getDesc();
Boolean positive = updateDutyNodeDto.getPositive();
String schoolId = SecurityUtil.getLoginUser().getSchoolId(); String schoolId = SecurityUtil.getLoginUser().getSchoolId();
WeekDuty duty = dutyRepository.findBySchoolIdAndCode(schoolId, PK.WEEK_DUTY); WeekDuty duty = dutyRepository.findBySchoolIdAndCode(schoolId, PK.WEEK_DUTY);
@ -173,7 +172,7 @@ public class DutyServiceImpl implements DutyService {
nodeToUpdate.setName(newNodeName); nodeToUpdate.setName(newNodeName);
nodeToUpdate.setOrder(updateDutyNodeDto.getOrder()); nodeToUpdate.setOrder(updateDutyNodeDto.getOrder());
// 如果是一级,二级需同步更新三级节点的 path // 一级,二级需同步更新三级节点的 path
if (nodeToUpdate.getPath() == null || nodeToUpdate.getPath().length == 0) { if (nodeToUpdate.getPath() == null || nodeToUpdate.getPath().length == 0) {
int index = StringUtils.isEmpty(nodeToUpdate.getPid()) ? 0 : 1; int index = StringUtils.isEmpty(nodeToUpdate.getPid()) ? 0 : 1;
nodes.forEach(x -> { nodes.forEach(x -> {
@ -188,9 +187,10 @@ public class DutyServiceImpl implements DutyService {
} }
}); });
} else { } else {
nodeToUpdate.setScore(newScore); // 三级节点
nodeToUpdate.setScore(positive ? newScore : -newScore);
nodeToUpdate.setDesc(desc); nodeToUpdate.setDesc(desc);
nodeToUpdate.setPositive(newScore >= 0); nodeToUpdate.setPositive(newScore.equals(0) || positive);
nodeToUpdate.getPath()[2] = newNodeName; nodeToUpdate.getPath()[2] = newNodeName;
} }
@ -312,7 +312,7 @@ public class DutyServiceImpl implements DutyService {
} }
@Override @Override
public List<WeekDutyRecord.WeekDutyItem> findRecords(FindDutyRecordDto findDutyRecordDto) { public List<DutyRecordVo> findRecords(FindDutyRecordDto findDutyRecordDto) {
String classId = StringUtils.isEmpty(findDutyRecordDto.getClassId()) ? null : findDutyRecordDto.getClassId(); String classId = StringUtils.isEmpty(findDutyRecordDto.getClassId()) ? null : findDutyRecordDto.getClassId();
String academicYearId = findDutyRecordDto.getAcademicYearId(); String academicYearId = findDutyRecordDto.getAcademicYearId();
Boolean positive = findDutyRecordDto.getPositive(); Boolean positive = findDutyRecordDto.getPositive();
@ -331,7 +331,7 @@ public class DutyServiceImpl implements DutyService {
startTime = mondayOfCurWeek.atZone(ZoneOffset.systemDefault()).toInstant().toEpochMilli(); startTime = mondayOfCurWeek.atZone(ZoneOffset.systemDefault()).toInstant().toEpochMilli();
endTime = Instant.now().toEpochMilli(); endTime = Instant.now().toEpochMilli();
} }
List<WeekDutyRecord.WeekDutyItem> records = dutyRecordRepository.findRecordsByConditions( List<DutyRecordVo> records = dutyRecordRepository.findRecordsByConditions(
String.format(PK.WEEK_DUTY_RECORD, schoolId), String.format(PK.WEEK_DUTY_RECORD, schoolId),
academicYearId, academicYearId,
userId, userId,
@ -339,9 +339,32 @@ public class DutyServiceImpl implements DutyService {
positive, positive,
startTime, startTime,
endTime); endTime);
records = records.stream().sorted((o1, o2) -> o2.getInfo().getCreateTime().compareTo(o1.getInfo().getCreateTime())).collect(Collectors.toList());
return records; return records;
} }
@Override
public void recallVote(RecallDutyVoteDto recallDutyVoteDto) {
String recordId = recallDutyVoteDto.getRecordId();
String nodeId = recallDutyVoteDto.getNodeId();
User user = SecurityUtil.getLoginUser();
String schoolId = user.getSchoolId();
String userId = user.getId();
Optional<WeekDutyRecord> optional = dutyRecordRepository.findById(recordId, PK.of(String.format(PK.WEEK_DUTY_RECORD, schoolId)));
WeekDutyRecord weekDutyRecord = optional.orElseThrow(() -> new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "评价记录不存在"));
WeekDutyRecord.WeekDutyItem item = weekDutyRecord.getNodes().stream()
.filter(x -> nodeId.equals(x.getDutyTreeNode().getId()))
.findFirst().
orElseThrow(() -> new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "评价记录不存在"));
if (!userId.equals(item.getCreatorId())) {
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "只能撤回自己的评价");
}
weekDutyRecord.setScore(weekDutyRecord.getScore() - item.getDutyTreeNode().getScore());
weekDutyRecord.getNodes().remove(item);
dutyRecordRepository.save(weekDutyRecord);
}
/** /**
* spots id * spots id
*/ */

Loading…
Cancel
Save