| | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.stream.Stream; |
| | | import java.util.stream.Collectors; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.StringUtils; |
| | | import com.sinata.appointment.util.UuidAssert; |
| | | |
| | | @Slf4j |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class MiniHandlerApprovalApplicationService { |
| | |
| | | private final ApprovalInstanceMapper approvalInstanceMapper; |
| | | private final AppointmentOrderMapper appointmentOrderMapper; |
| | | private final ApprovalEngineService approvalEngineService; |
| | | private final IntegrationWechatService integrationWechatService; |
| | | private final PostApprovalOrchestrationService postApprovalOrchestrationService; |
| | | private final BizApprovalNodeConfigMapper bizApprovalNodeConfigMapper; |
| | | private final MpPassAccessAreaMapper mpPassAccessAreaMapper; |
| | |
| | | if (ApprovalInstanceStatus.APPROVED.equals(latest.getStatus())) { |
| | | AppointmentOrder fresh = appointmentOrderMapper.selectById(order.getId()); |
| | | postApprovalOrchestrationService.onOrderFullyApproved(fresh); |
| | | return; |
| | | } |
| | | if (ApprovalInstanceStatus.IN_PROGRESS.equals(latest.getStatus())) { |
| | | try { |
| | | integrationWechatService.notifyCurrentApprovers(order, latest.getId()); |
| | | } catch (Exception ex) { |
| | | log.warn("notify current approvers failed, orderId={}", order.getId(), ex); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | String comment = req.getComment() == null ? null : req.getComment().trim(); |
| | | appendNoticeIdsIfNeeded(task, req.getNoticeIds()); |
| | | if (Boolean.FALSE.equals(req.getApprove())) { |
| | | String reason = StringUtils.hasText(comment) ? comment : "拒绝"; |
| | | task.setTaskStatus(ApprovalTaskStatus.REJECTED); |
| | |
| | | if (ApprovalInstanceStatus.APPROVED.equals(latest.getStatus())) { |
| | | AppointmentOrder fresh = appointmentOrderMapper.selectById(order.getId()); |
| | | postApprovalOrchestrationService.onOrderFullyApproved(fresh); |
| | | return; |
| | | } |
| | | if (ApprovalInstanceStatus.IN_PROGRESS.equals(latest.getStatus())) { |
| | | try { |
| | | integrationWechatService.notifyCurrentApprovers(order, latest.getId()); |
| | | } catch (Exception ex) { |
| | | log.warn("notify current approvers failed, orderId={}", order.getId(), ex); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void appendNoticeIdsIfNeeded(ApprovalTask task, List<Long> noticeIds) { |
| | | if (!ApprovalNodeCode.LEVEL3_LOCAL_DEPT_LEADER.equals(task.getNodeCode())) { |
| | | return; |
| | | } |
| | | List<Long> normalized = normalizeIds(noticeIds); |
| | | if (normalized.isEmpty()) { |
| | | return; |
| | | } |
| | | LinkedHashSet<Long> merged = new LinkedHashSet<>(parseNoticeIds(task.getNoticeIds())); |
| | | merged.addAll(normalized); |
| | | task.setNoticeIds(merged.stream().map(String::valueOf).collect(Collectors.joining(","))); |
| | | } |
| | | |
| | | private List<Long> parseNoticeIds(String raw) { |
| | | if (!StringUtils.hasText(raw)) { |
| | | return List.of(); |
| | | } |
| | | return Stream.of(raw.split(",")) |
| | | .filter(StringUtils::hasText) |
| | | .map(String::trim) |
| | | .map(value -> { |
| | | try { |
| | | return Long.parseLong(value); |
| | | } catch (NumberFormatException ex) { |
| | | return null; |
| | | } |
| | | }) |
| | | .filter(Objects::nonNull) |
| | | .filter(id -> id > 0) |
| | | .distinct() |
| | | .toList(); |
| | | } |
| | | |
| | | private Map<Long, AppointmentOrder> loadOrderMap(List<Long> orderIds) { |
| | | if (orderIds.isEmpty()) { |
| | | return Map.of(); |