From 9f77aa9edea9f9889f869c73cdeb4df1c49c755c Mon Sep 17 00:00:00 2001 From: winter <2436197699@qq.com> Date: Mon, 8 Jan 2024 11:50:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=9D=E6=AD=A5=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E5=80=BC=E5=91=A8=E5=B7=A1=E6=A3=80=E6=A0=91=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E8=AF=84=E4=BB=B7=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/dto/weekDuty/InsertDutyNodeDto.java | 1 + .../model/dto/weekDuty/UpdateDutyNodeDto.java | 1 + .../model/entity/weekDuty/WeekDuty.java | 3 +- .../service/impl/DutyServiceImpl.java | 34 +++++++++++++------ 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/main/java/cn/teammodel/model/dto/weekDuty/InsertDutyNodeDto.java b/src/main/java/cn/teammodel/model/dto/weekDuty/InsertDutyNodeDto.java index 19cfc1b..760bc4a 100644 --- a/src/main/java/cn/teammodel/model/dto/weekDuty/InsertDutyNodeDto.java +++ b/src/main/java/cn/teammodel/model/dto/weekDuty/InsertDutyNodeDto.java @@ -17,6 +17,7 @@ public class InsertDutyNodeDto { @ApiModelProperty(value = "节点名称", required = true) @NotBlank(message = "name 不能为空") String name; + String desc; Integer order = 0; Integer score = 0; // Boolean positive = true; diff --git a/src/main/java/cn/teammodel/model/dto/weekDuty/UpdateDutyNodeDto.java b/src/main/java/cn/teammodel/model/dto/weekDuty/UpdateDutyNodeDto.java index c1c4c6e..2d3190b 100644 --- a/src/main/java/cn/teammodel/model/dto/weekDuty/UpdateDutyNodeDto.java +++ b/src/main/java/cn/teammodel/model/dto/weekDuty/UpdateDutyNodeDto.java @@ -17,6 +17,7 @@ public class UpdateDutyNodeDto { @NotNull private String id; private String name; + private String desc; private Integer order = 0; private Integer score = 0; // boolean positive; diff --git a/src/main/java/cn/teammodel/model/entity/weekDuty/WeekDuty.java b/src/main/java/cn/teammodel/model/entity/weekDuty/WeekDuty.java index fdafe5e..088029c 100644 --- a/src/main/java/cn/teammodel/model/entity/weekDuty/WeekDuty.java +++ b/src/main/java/cn/teammodel/model/entity/weekDuty/WeekDuty.java @@ -32,12 +32,13 @@ public class WeekDuty extends BaseItem { private String id; private String pid; private String name; + private String desc; private Integer score; private Integer order; /** * 加分还是减分 */ - private boolean positive; + private Boolean positive; /** * 只有三级有 */ diff --git a/src/main/java/cn/teammodel/service/impl/DutyServiceImpl.java b/src/main/java/cn/teammodel/service/impl/DutyServiceImpl.java index a381090..3c57f6d 100644 --- a/src/main/java/cn/teammodel/service/impl/DutyServiceImpl.java +++ b/src/main/java/cn/teammodel/service/impl/DutyServiceImpl.java @@ -65,7 +65,7 @@ public class DutyServiceImpl implements DutyService { duty.setSchoolId(schoolId); // 刷新值周树和 spots 的 id refreshDuty(duty); - dutyRepository.save(duty); + duty = dutyRepository.save(duty); } return this.buildTree(duty); @@ -77,6 +77,7 @@ public class DutyServiceImpl implements DutyService { String name = insertDutyNodeDto.getName(); Integer order = insertDutyNodeDto.getOrder(); Integer score = insertDutyNodeDto.getScore(); + String desc = insertDutyNodeDto.getDesc(); User user = SecurityUtil.getLoginUser(); String schoolId = user.getSchoolId(); @@ -87,37 +88,41 @@ public class DutyServiceImpl implements DutyService { WeekDuty.DutyTreeNode newNode = new WeekDuty.DutyTreeNode(); List nodes = duty.getNodes(); + // 只有三级节点需要 positive + newNode.setPositive(null); // 非根节点(需考虑填充 path) if (StringUtils.isNotEmpty(pid)) { WeekDuty.DutyTreeNode parent = nodes.stream().filter(x -> pid.equals(x.getId())) .findFirst() .orElseThrow(() -> new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "pid 无效")); String level2 = parent.getName(); + // 新节点是三级节点(二级节点不用特殊处理 - String ppid = parent.getId(); - if (ppid != null) { + String ppid = parent.getPid(); + if (StringUtils.isNotEmpty(ppid)) { String[] path = new String[3]; WeekDuty.DutyTreeNode root = nodes.stream().filter(x -> ppid.equals(x.getId())) .findFirst() .orElseThrow(() -> new ServiceException(ErrorCode.SYSTEM_ERROR.getCode(), "值周树结构错误")); // 层数不为三级,抛出异常 - if (root.getPid() != null) { + if (StringUtils.isNotEmpty(root.getPid())) { throw new ServiceException(ErrorCode.SYSTEM_ERROR.getCode(), "值周树结构错误"); } String level1 = root.getName(); path[0] = level1; path[1] = level2; path[2] = name; + newNode.setDesc(desc); newNode.setPath(path); + newNode.setScore(score); + newNode.setPositive(score >= 0); } } newNode.setId(UUID.randomUUID().toString()); newNode.setPid(pid); newNode.setName(name); - newNode.setScore(score); newNode.setOrder(order); - newNode.setPositive(score >= 0); newNode.setCreator(user.getName()); newNode.setCreatorId(user.getId()); newNode.setCreateTime(Instant.now().toEpochMilli()); @@ -154,6 +159,7 @@ public class DutyServiceImpl implements DutyService { String nodeId = updateDutyNodeDto.getId(); String newNodeName = updateDutyNodeDto.getName(); Integer newScore = updateDutyNodeDto.getScore(); + String desc = updateDutyNodeDto.getDesc(); String schoolId = SecurityUtil.getLoginUser().getSchoolId(); WeekDuty duty = dutyRepository.findBySchoolIdAndCode(schoolId, PK.WEEK_DUTY); @@ -167,13 +173,11 @@ public class DutyServiceImpl implements DutyService { String originNodeName = nodeToUpdate.getName(); // 更新当前节点 nodeToUpdate.setName(newNodeName); - nodeToUpdate.setScore(newScore); nodeToUpdate.setOrder(updateDutyNodeDto.getOrder()); - nodeToUpdate.setPositive(newScore >= 0); // 如果是一级,二级需同步更新三级节点的 path - if (nodeToUpdate.getPath() != null) { - int index = nodeToUpdate.getPid() == null ? 0 : 1; + if (nodeToUpdate.getPath() == null || nodeToUpdate.getPath().length == 0) { + int index = StringUtils.isEmpty(nodeToUpdate.getPid()) ? 0 : 1; nodes.forEach(x -> { // 修改三级节点的 path if (x.getPath() == null) { @@ -185,6 +189,11 @@ public class DutyServiceImpl implements DutyService { x.setPath(path); } }); + } else { + nodeToUpdate.setScore(newScore); + nodeToUpdate.setDesc(desc); + nodeToUpdate.setPositive(newScore >= 0); + nodeToUpdate.getPath()[2] = newNodeName; } return buildTree(dutyRepository.save(duty)); @@ -217,6 +226,9 @@ public class DutyServiceImpl implements DutyService { .findFirst() .orElseThrow(() -> new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "评价节点不存在")); + if (dutyNode.getPath() == null || dutyNode.getPath().length == 0) { + throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "只能评价三级节点"); + } WeekDuty.DutySpot spot = duty.getSpots().stream() .filter(x -> spotId.equals(x.getId())) .findFirst() @@ -243,7 +255,7 @@ public class DutyServiceImpl implements DutyService { weekDutyRecord.setClassId(classId); weekDutyRecord.setClassName(className); weekDutyRecord.setAcademicYearId(academicYearId); - weekDutyRecord.setScore(0); + weekDutyRecord.setScore(dutyNode.getScore()); weekDutyRecord.setNodes(nodes); weekDutyRecord.setCode(String.format(PK.WEEK_DUTY_RECORD, schoolId)); weekDutyRecord.setCreateTime(Instant.now().toEpochMilli());