feat: 初步实现值周巡检树以及评价接口

11111
winter 12 months ago
parent 38699011e6
commit 9f77aa9ede

@ -17,6 +17,7 @@ public class InsertDutyNodeDto {
@ApiModelProperty(value = "节点名称", required = true) @ApiModelProperty(value = "节点名称", required = true)
@NotBlank(message = "name 不能为空") @NotBlank(message = "name 不能为空")
String name; String name;
String desc;
Integer order = 0; Integer order = 0;
Integer score = 0; Integer score = 0;
// Boolean positive = true; // Boolean positive = true;

@ -17,6 +17,7 @@ public class UpdateDutyNodeDto {
@NotNull @NotNull
private String id; private String id;
private String name; private String name;
private String desc;
private Integer order = 0; private Integer order = 0;
private Integer score = 0; private Integer score = 0;
// boolean positive; // boolean positive;

@ -32,12 +32,13 @@ public class WeekDuty extends BaseItem {
private String id; private String id;
private String pid; private String pid;
private String name; private String name;
private String desc;
private Integer score; private Integer score;
private Integer order; private Integer order;
/** /**
* *
*/ */
private boolean positive; private Boolean positive;
/** /**
* *
*/ */

@ -65,7 +65,7 @@ public class DutyServiceImpl implements DutyService {
duty.setSchoolId(schoolId); duty.setSchoolId(schoolId);
// 刷新值周树和 spots 的 id // 刷新值周树和 spots 的 id
refreshDuty(duty); refreshDuty(duty);
dutyRepository.save(duty); duty = dutyRepository.save(duty);
} }
return this.buildTree(duty); return this.buildTree(duty);
@ -77,6 +77,7 @@ public class DutyServiceImpl implements DutyService {
String name = insertDutyNodeDto.getName(); String name = insertDutyNodeDto.getName();
Integer order = insertDutyNodeDto.getOrder(); Integer order = insertDutyNodeDto.getOrder();
Integer score = insertDutyNodeDto.getScore(); Integer score = insertDutyNodeDto.getScore();
String desc = insertDutyNodeDto.getDesc();
User user = SecurityUtil.getLoginUser(); User user = SecurityUtil.getLoginUser();
String schoolId = user.getSchoolId(); String schoolId = user.getSchoolId();
@ -87,37 +88,41 @@ public class DutyServiceImpl implements DutyService {
WeekDuty.DutyTreeNode newNode = new WeekDuty.DutyTreeNode(); WeekDuty.DutyTreeNode newNode = new WeekDuty.DutyTreeNode();
List<WeekDuty.DutyTreeNode> nodes = duty.getNodes(); List<WeekDuty.DutyTreeNode> nodes = duty.getNodes();
// 只有三级节点需要 positive
newNode.setPositive(null);
// 非根节点(需考虑填充 path) // 非根节点(需考虑填充 path)
if (StringUtils.isNotEmpty(pid)) { if (StringUtils.isNotEmpty(pid)) {
WeekDuty.DutyTreeNode parent = nodes.stream().filter(x -> pid.equals(x.getId())) WeekDuty.DutyTreeNode parent = nodes.stream().filter(x -> pid.equals(x.getId()))
.findFirst() .findFirst()
.orElseThrow(() -> new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "pid 无效")); .orElseThrow(() -> new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "pid 无效"));
String level2 = parent.getName(); String level2 = parent.getName();
// 新节点是三级节点(二级节点不用特殊处理 // 新节点是三级节点(二级节点不用特殊处理
String ppid = parent.getId(); String ppid = parent.getPid();
if (ppid != null) { if (StringUtils.isNotEmpty(ppid)) {
String[] path = new String[3]; String[] path = new String[3];
WeekDuty.DutyTreeNode root = nodes.stream().filter(x -> ppid.equals(x.getId())) WeekDuty.DutyTreeNode root = nodes.stream().filter(x -> ppid.equals(x.getId()))
.findFirst() .findFirst()
.orElseThrow(() -> new ServiceException(ErrorCode.SYSTEM_ERROR.getCode(), "值周树结构错误")); .orElseThrow(() -> new ServiceException(ErrorCode.SYSTEM_ERROR.getCode(), "值周树结构错误"));
// 层数不为三级,抛出异常 // 层数不为三级,抛出异常
if (root.getPid() != null) { if (StringUtils.isNotEmpty(root.getPid())) {
throw new ServiceException(ErrorCode.SYSTEM_ERROR.getCode(), "值周树结构错误"); throw new ServiceException(ErrorCode.SYSTEM_ERROR.getCode(), "值周树结构错误");
} }
String level1 = root.getName(); String level1 = root.getName();
path[0] = level1; path[0] = level1;
path[1] = level2; path[1] = level2;
path[2] = name; path[2] = name;
newNode.setDesc(desc);
newNode.setPath(path); newNode.setPath(path);
newNode.setScore(score);
newNode.setPositive(score >= 0);
} }
} }
newNode.setId(UUID.randomUUID().toString()); newNode.setId(UUID.randomUUID().toString());
newNode.setPid(pid); newNode.setPid(pid);
newNode.setName(name); newNode.setName(name);
newNode.setScore(score);
newNode.setOrder(order); newNode.setOrder(order);
newNode.setPositive(score >= 0);
newNode.setCreator(user.getName()); newNode.setCreator(user.getName());
newNode.setCreatorId(user.getId()); newNode.setCreatorId(user.getId());
newNode.setCreateTime(Instant.now().toEpochMilli()); newNode.setCreateTime(Instant.now().toEpochMilli());
@ -154,6 +159,7 @@ public class DutyServiceImpl implements DutyService {
String nodeId = updateDutyNodeDto.getId(); String nodeId = updateDutyNodeDto.getId();
String newNodeName = updateDutyNodeDto.getName(); String newNodeName = updateDutyNodeDto.getName();
Integer newScore = updateDutyNodeDto.getScore(); Integer newScore = updateDutyNodeDto.getScore();
String desc = updateDutyNodeDto.getDesc();
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);
@ -167,13 +173,11 @@ public class DutyServiceImpl implements DutyService {
String originNodeName = nodeToUpdate.getName(); String originNodeName = nodeToUpdate.getName();
// 更新当前节点 // 更新当前节点
nodeToUpdate.setName(newNodeName); nodeToUpdate.setName(newNodeName);
nodeToUpdate.setScore(newScore);
nodeToUpdate.setOrder(updateDutyNodeDto.getOrder()); nodeToUpdate.setOrder(updateDutyNodeDto.getOrder());
nodeToUpdate.setPositive(newScore >= 0);
// 如果是一级,二级需同步更新三级节点的 path // 如果是一级,二级需同步更新三级节点的 path
if (nodeToUpdate.getPath() != null) { if (nodeToUpdate.getPath() == null || nodeToUpdate.getPath().length == 0) {
int index = nodeToUpdate.getPid() == null ? 0 : 1; int index = StringUtils.isEmpty(nodeToUpdate.getPid()) ? 0 : 1;
nodes.forEach(x -> { nodes.forEach(x -> {
// 修改三级节点的 path // 修改三级节点的 path
if (x.getPath() == null) { if (x.getPath() == null) {
@ -185,6 +189,11 @@ public class DutyServiceImpl implements DutyService {
x.setPath(path); x.setPath(path);
} }
}); });
} else {
nodeToUpdate.setScore(newScore);
nodeToUpdate.setDesc(desc);
nodeToUpdate.setPositive(newScore >= 0);
nodeToUpdate.getPath()[2] = newNodeName;
} }
return buildTree(dutyRepository.save(duty)); return buildTree(dutyRepository.save(duty));
@ -217,6 +226,9 @@ public class DutyServiceImpl implements DutyService {
.findFirst() .findFirst()
.orElseThrow(() -> new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "评价节点不存在")); .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() WeekDuty.DutySpot spot = duty.getSpots().stream()
.filter(x -> spotId.equals(x.getId())) .filter(x -> spotId.equals(x.getId()))
.findFirst() .findFirst()
@ -243,7 +255,7 @@ public class DutyServiceImpl implements DutyService {
weekDutyRecord.setClassId(classId); weekDutyRecord.setClassId(classId);
weekDutyRecord.setClassName(className); weekDutyRecord.setClassName(className);
weekDutyRecord.setAcademicYearId(academicYearId); weekDutyRecord.setAcademicYearId(academicYearId);
weekDutyRecord.setScore(0); weekDutyRecord.setScore(dutyNode.getScore());
weekDutyRecord.setNodes(nodes); weekDutyRecord.setNodes(nodes);
weekDutyRecord.setCode(String.format(PK.WEEK_DUTY_RECORD, schoolId)); weekDutyRecord.setCode(String.format(PK.WEEK_DUTY_RECORD, schoolId));
weekDutyRecord.setCreateTime(Instant.now().toEpochMilli()); weekDutyRecord.setCreateTime(Instant.now().toEpochMilli());

Loading…
Cancel
Save