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

11111
winter 12 months ago
parent 38699011e6
commit 9f77aa9ede

@ -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;

@ -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;

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

@ -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<WeekDuty.DutyTreeNode> 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());

Loading…
Cancel
Save