|
|
|
|
@ -1,5 +1,6 @@ |
|
|
|
|
package org.springblade.desk.quality.service.impl; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
@ -177,6 +178,12 @@ public class DispatchConfigApprovalServiceImpl extends EnBaseServiceImpl<Dispatc |
|
|
|
|
// 更新状态为一级审批中
|
|
|
|
|
entity.setStatus(DispatchConfigApprovalConst.STATUS_LEVEL1_APPROVING); |
|
|
|
|
updateById(entity); |
|
|
|
|
|
|
|
|
|
// 删除当前节点的审批记录,以便重新审批
|
|
|
|
|
QueryWrapper<DispatchConfigApprovalRecord> deleteQuery = new QueryWrapper<>(); |
|
|
|
|
deleteQuery.eq("APPROVAL_ID", id); |
|
|
|
|
approvalRecordMapper.delete(deleteQuery); |
|
|
|
|
|
|
|
|
|
return R.success("提交审批成功"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -267,6 +274,10 @@ public class DispatchConfigApprovalServiceImpl extends EnBaseServiceImpl<Dispatc |
|
|
|
|
newRecord.setAuditResult(result); |
|
|
|
|
newRecord.setAuditRemark(remark); |
|
|
|
|
newRecord.setAuditTime(now); |
|
|
|
|
newRecord.setCreateTime(now); |
|
|
|
|
newRecord.setCreateUser(currentUserId); |
|
|
|
|
newRecord.setUpdateTime(now); |
|
|
|
|
newRecord.setUpdateUser(currentUserId); |
|
|
|
|
approvalRecordMapper.insert(newRecord); |
|
|
|
|
|
|
|
|
|
// 如果审批驳回,直接驳回到发起人,并删除审批记录
|
|
|
|
|
@ -275,11 +286,6 @@ public class DispatchConfigApprovalServiceImpl extends EnBaseServiceImpl<Dispatc |
|
|
|
|
entity.setUpdateUser(currentUserId); |
|
|
|
|
entity.setUpdateTime(now); |
|
|
|
|
updateById(entity); |
|
|
|
|
|
|
|
|
|
// 删除当前节点的审批记录,以便重新审批
|
|
|
|
|
QueryWrapper<DispatchConfigApprovalRecord> deleteQuery = new QueryWrapper<>(); |
|
|
|
|
deleteQuery.eq("APPROVAL_ID", id); |
|
|
|
|
approvalRecordMapper.delete(deleteQuery); |
|
|
|
|
|
|
|
|
|
return R.success("审批已驳回"); |
|
|
|
|
} |
|
|
|
|
@ -323,6 +329,7 @@ public class DispatchConfigApprovalServiceImpl extends EnBaseServiceImpl<Dispatc |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<DispatchConfigApprovalTimelineVO> getAuditTimeline(Long id) { |
|
|
|
|
|
|
|
|
|
DispatchConfigApproval entity = getById(id); |
|
|
|
|
if (entity == null) { |
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
@ -333,59 +340,91 @@ public class DispatchConfigApprovalServiceImpl extends EnBaseServiceImpl<Dispatc |
|
|
|
|
// 1. 添加提交记录
|
|
|
|
|
DispatchConfigApprovalTimelineVO submitNode = new DispatchConfigApprovalTimelineVO(); |
|
|
|
|
submitNode.setType("submit"); |
|
|
|
|
submitNode.setLabel("提交人:"); |
|
|
|
|
submitNode.setLabel("提交人"); |
|
|
|
|
submitNode.setValue(entity.getApplicantName() != null ? entity.getApplicantName() : "未知"); |
|
|
|
|
submitNode.setTime(entity.getApplicationTime() != null ? DateUtil.format(entity.getApplicationTime(), "yyyy-MM-dd HH:mm:ss") : ""); |
|
|
|
|
submitNode.setStatus("success"); |
|
|
|
|
submitNode.setApprovalNode(0); |
|
|
|
|
// 提交节点不需要children
|
|
|
|
|
DispatchConfigApprovalTimelineVO dispatchConfigApprovalTimelineVO = BeanUtil.copyProperties(submitNode, DispatchConfigApprovalTimelineVO.class); |
|
|
|
|
submitNode.setChildren(List.of(dispatchConfigApprovalTimelineVO)); |
|
|
|
|
timelineList.add(submitNode); |
|
|
|
|
|
|
|
|
|
// 2. 查询所有审批记录
|
|
|
|
|
// 2. 查询所有审批记录并按节点分组
|
|
|
|
|
List<DispatchConfigApprovalRecord> allRecords = approvalRecordMapper.selectByApprovalId(id); |
|
|
|
|
|
|
|
|
|
// 按审批节点分组
|
|
|
|
|
Map<Integer, List<DispatchConfigApprovalRecord>> nodeMap = allRecords.stream() |
|
|
|
|
.collect(Collectors.groupingBy(DispatchConfigApprovalRecord::getApprovalNode)); |
|
|
|
|
|
|
|
|
|
// 3. 添加一级审批节点(如果有审批记录)
|
|
|
|
|
if (nodeMap.containsKey(1)) { |
|
|
|
|
List<DispatchConfigApprovalRecord> level1Records = nodeMap.get(1); |
|
|
|
|
// 只展示第一个通过的审批人
|
|
|
|
|
DispatchConfigApprovalRecord firstRecord = level1Records.get(0); |
|
|
|
|
DispatchConfigApprovalTimelineVO node = new DispatchConfigApprovalTimelineVO(); |
|
|
|
|
node.setType("audit"); |
|
|
|
|
node.setLabel("一级审批:"); |
|
|
|
|
node.setValue("已通过"); |
|
|
|
|
node.setTime(firstRecord.getAuditTime() != null ? DateUtil.format(firstRecord.getAuditTime(), "yyyy-MM-dd HH:mm:ss") : ""); |
|
|
|
|
node.setApprovalNode(1); |
|
|
|
|
node.setStatus("success"); |
|
|
|
|
timelineList.add(node); |
|
|
|
|
// 3. 处理一级审批节点
|
|
|
|
|
buildApprovalNodes(nodeMap.getOrDefault(1, new ArrayList<>()), 1, timelineList,entity); |
|
|
|
|
|
|
|
|
|
// 4. 处理二级审批节点
|
|
|
|
|
buildApprovalNodes(nodeMap.getOrDefault(2, new ArrayList<>()), 2, timelineList,entity); |
|
|
|
|
|
|
|
|
|
return timelineList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 构建审批节点时间线记录 |
|
|
|
|
* |
|
|
|
|
* @param records 审批记录列表 |
|
|
|
|
* @param approvalNode 审批节点(1-一级审批,2-二级审批) |
|
|
|
|
* @param timelineList 时间线结果集 |
|
|
|
|
*/ |
|
|
|
|
private void buildApprovalNodes(List<DispatchConfigApprovalRecord> records, |
|
|
|
|
Integer approvalNode, |
|
|
|
|
List<DispatchConfigApprovalTimelineVO> timelineList, |
|
|
|
|
DispatchConfigApproval entity) { |
|
|
|
|
String status = "false"; |
|
|
|
|
if (1 == approvalNode && DispatchConfigApprovalConst.STATUS_LEVEL2_APPROVING.equals(entity.getStatus())) { |
|
|
|
|
status = "success"; |
|
|
|
|
} |
|
|
|
|
if (2 == approvalNode && DispatchConfigApprovalConst.STATUS_APPROVED.equals(entity.getStatus())) { |
|
|
|
|
status = "success"; |
|
|
|
|
} |
|
|
|
|
String label; |
|
|
|
|
if (1 == approvalNode) { |
|
|
|
|
label = "一级审批"; |
|
|
|
|
} else { |
|
|
|
|
label = " 二级审批"; |
|
|
|
|
} |
|
|
|
|
DispatchConfigApprovalTimelineVO submitNode = new DispatchConfigApprovalTimelineVO(); |
|
|
|
|
submitNode.setLabel(label); |
|
|
|
|
submitNode.setType("audit"); |
|
|
|
|
submitNode.setStatus(status); |
|
|
|
|
submitNode.setApprovalNode(approvalNode); |
|
|
|
|
|
|
|
|
|
if (records == null || records.isEmpty()) { |
|
|
|
|
timelineList.add(submitNode); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 4. 添加二级审批节点(如果有审批记录)
|
|
|
|
|
if (nodeMap.containsKey(2)) { |
|
|
|
|
List<DispatchConfigApprovalRecord> level2Records = nodeMap.get(2); |
|
|
|
|
// 只展示第一个通过的审批人
|
|
|
|
|
DispatchConfigApprovalRecord firstRecord = level2Records.get(0); |
|
|
|
|
// 为每个审批人创建一条时间线记录
|
|
|
|
|
List<DispatchConfigApprovalTimelineVO> childRecords = records.stream().map(record -> { |
|
|
|
|
DispatchConfigApprovalTimelineVO node = new DispatchConfigApprovalTimelineVO(); |
|
|
|
|
node.setType("audit"); |
|
|
|
|
node.setLabel("二级审批:"); |
|
|
|
|
node.setValue("已通过"); |
|
|
|
|
node.setTime(firstRecord.getAuditTime() != null ? DateUtil.format(firstRecord.getAuditTime(), "yyyy-MM-dd HH:mm:ss") : ""); |
|
|
|
|
node.setApprovalNode(2); |
|
|
|
|
node.setStatus("success"); |
|
|
|
|
timelineList.add(node); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 按时间倒序排列(最新的在前面)
|
|
|
|
|
timelineList.sort((a, b) -> { |
|
|
|
|
if (a.getTime() == null || b.getTime() == null) { |
|
|
|
|
return 0; |
|
|
|
|
node.setLabel("审批人"); |
|
|
|
|
|
|
|
|
|
// 根据审批结果设置状态和值
|
|
|
|
|
if (DispatchConfigApprovalConst.AUDIT_RESULT_PASS.equals(record.getAuditResult())) { |
|
|
|
|
node.setValue(record.getAuditorName() != null ? record.getAuditorName() : "未知"); |
|
|
|
|
node.setStatus("success"); |
|
|
|
|
} else if (DispatchConfigApprovalConst.AUDIT_RESULT_REJECT.equals(record.getAuditResult())) { |
|
|
|
|
node.setValue(record.getAuditorName() != null ? record.getAuditorName() : "未知"); |
|
|
|
|
node.setStatus("false"); |
|
|
|
|
} |
|
|
|
|
return b.getTime().compareTo(a.getTime()); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
return timelineList; |
|
|
|
|
node.setTime(record.getAuditTime() != null ? DateUtil.format(record.getAuditTime(), "yyyy-MM-dd HH:mm:ss") : ""); |
|
|
|
|
node.setApprovalNode(approvalNode); |
|
|
|
|
node.setRemark(record.getAuditRemark()); |
|
|
|
|
return node; |
|
|
|
|
}).sorted(Comparator.comparing(DispatchConfigApprovalTimelineVO::getTime, Comparator.nullsLast(Comparator.naturalOrder()))) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
submitNode.setChildren(childRecords); |
|
|
|
|
|
|
|
|
|
timelineList.add(submitNode); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|