| | |
| | | import com.webmanage.mapper.OrderDetailMapper; |
| | | import com.webmanage.mapper.OrderEvaluationMapper; |
| | | import com.webmanage.mapper.OrderInfoMapper; |
| | | import com.webmanage.mapper.ReportResultSubmissionMapper; |
| | | import com.webmanage.service.OrderInfoService; |
| | | import com.webmanage.service.OrderNoService; |
| | | import com.webmanage.service.MinioService; |
| | | import com.webmanage.config.WorkflowProperties; |
| | | import com.webmanage.vo.OrderAttachmentVO; |
| | | import com.webmanage.vo.OrderDetailItemVO; |
| | | import com.webmanage.vo.OrderDetailVO; |
| | | import com.webmanage.vo.OrderEvaluationVO; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.client.RestTemplate; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.core.ParameterizedTypeReference; |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.http.HttpEntity; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.http.HttpHeaders; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.util.List; |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * 订单信息Service实现类 |
| | |
| | | @Resource |
| | | private MinioService minioService; |
| | | |
| | | @Resource |
| | | private ReportResultSubmissionMapper reportResultSubmissionMapper; |
| | | |
| | | @Autowired |
| | | private RestTemplate restTemplate; |
| | | |
| | | @Autowired |
| | | private WorkflowProperties workflowProperties; |
| | | |
| | | @Override |
| | | public PageResult<OrderInfo> getBuyerOrderPage(OrderQueryDTO queryDTO) { |
| | | public PageResult<OrderDetailVO> getBuyerOrderPage(OrderQueryDTO queryDTO) { |
| | | // 参数校验 |
| | | if (queryDTO.getUserId() == null) { |
| | | throw new BusinessException("用户ID不能为空"); |
| | |
| | | queryDTO.getCreateTimeEnd() != null ? queryDTO.getCreateTimeEnd().toString() : null, |
| | | queryDTO.getOrderBy(), queryDTO.getOrderDirection() |
| | | ); |
| | | // 将订单与详情联表封装到VO |
| | | List<OrderDetailVO> voList = result.getRecords().stream().map(order -> { |
| | | OrderDetailVO vo = new OrderDetailVO(); |
| | | BeanUtils.copyProperties(order, vo); |
| | | List<OrderDetail> details = orderDetailMapper.selectByOrderId(order.getOrderId()); |
| | | List<OrderDetailItemVO> items = details.stream().map(d -> { |
| | | OrderDetailItemVO item = new OrderDetailItemVO(); |
| | | BeanUtils.copyProperties(d, item); |
| | | return item; |
| | | }).collect(java.util.stream.Collectors.toList()); |
| | | vo.setOrderDetails(items); |
| | | return vo; |
| | | }).collect(java.util.stream.Collectors.toList()); |
| | | |
| | | // 构建返回结果 |
| | | return new PageResult<OrderInfo>( |
| | | result.getRecords(), |
| | | return new PageResult<OrderDetailVO>( |
| | | voList, |
| | | result.getTotal(), |
| | | queryDTO.getPageNum().longValue(), |
| | | queryDTO.getPageSize().longValue(), |
| | |
| | | } |
| | | |
| | | @Override |
| | | public PageResult<OrderInfo> getSellerOrderPage(OrderQueryDTO queryDTO) { |
| | | public PageResult<OrderDetailVO> getSellerOrderPage(OrderQueryDTO queryDTO) { |
| | | // 参数校验 |
| | | if (queryDTO.getProviderId() == null) { |
| | | throw new BusinessException("提供者ID不能为空"); |
| | |
| | | queryDTO.getOrderBy(), queryDTO.getOrderDirection() |
| | | ); |
| | | |
| | | // 将订单与详情联表封装到VO |
| | | List<OrderDetailVO> voList = result.getRecords().stream().map(order -> { |
| | | OrderDetailVO vo = new OrderDetailVO(); |
| | | BeanUtils.copyProperties(order, vo); |
| | | List<OrderDetail> details = orderDetailMapper.selectByOrderId(order.getOrderId()); |
| | | List<OrderDetailItemVO> items = details.stream().map(d -> { |
| | | OrderDetailItemVO item = new OrderDetailItemVO(); |
| | | BeanUtils.copyProperties(d, item); |
| | | return item; |
| | | }).collect(java.util.stream.Collectors.toList()); |
| | | vo.setOrderDetails(items); |
| | | return vo; |
| | | }).collect(java.util.stream.Collectors.toList()); |
| | | |
| | | // 构建返回结果 |
| | | return new PageResult<OrderInfo>( |
| | | result.getRecords(), |
| | | return new PageResult<OrderDetailVO>( |
| | | voList, |
| | | result.getTotal(), |
| | | queryDTO.getPageNum().longValue(), |
| | | queryDTO.getPageSize().longValue(), |
| | |
| | | } |
| | | |
| | | @Override |
| | | public PageResult<OrderInfo> getPendingApprovalOrderPage(OrderQueryDTO queryDTO) { |
| | | public PageResult<OrderDetailVO> getPendingApprovalOrderPage(OrderQueryDTO queryDTO) { |
| | | // 创建分页对象 |
| | | Page<OrderInfo> page = new Page<>(queryDTO.getPageNum(), queryDTO.getPageSize()); |
| | | |
| | | // 基于workFlowType查询流程实例ID集合 |
| | | List<Object> workFlowsList = fetchWorkflowProcessInstanceIds( |
| | | queryDTO.getWorkFlowType(), |
| | | queryDTO.getUserId(), |
| | | queryDTO.getDepartmentId(), |
| | | queryDTO.getBusinessType(), |
| | | queryDTO.getPageNum(), |
| | | queryDTO.getPageSize() |
| | | ); |
| | | |
| | | // 如果没有任何流程ID,直接返回空分页 |
| | | if (workFlowsList == null || workFlowsList.isEmpty()) { |
| | | return new PageResult<OrderDetailVO>( |
| | | java.util.Collections.emptyList(), |
| | | 0L, |
| | | queryDTO.getPageNum().longValue(), |
| | | queryDTO.getPageSize().longValue(), |
| | | 0L |
| | | ); |
| | | } |
| | | |
| | | List<String> workFlowIds = workFlowsList.stream() |
| | | .filter(item -> item instanceof Map) |
| | | .map(item -> (Map<?, ?>) item) |
| | | .map(m -> m.get("processInstanceId")) |
| | | .filter(Objects::nonNull) |
| | | .map(Object::toString) |
| | | .collect(Collectors.toList()); |
| | | |
| | | log.info("从工作流服务获取的原始数据: {}", workFlowsList); |
| | | log.info("提取的工作流ID列表: {}", workFlowIds); |
| | | |
| | | Map<String,String> workFlowIdAndTaskIdMap = workFlowsList.stream() |
| | | .filter(item -> item instanceof Map) |
| | | .map(item -> (Map<?, ?>) item).collect(Collectors.toMap(m -> m.get("processInstanceId").toString(), m -> m.get("taskId").toString(),(k1,k2) -> k2)); |
| | | |
| | | // 执行分页查询 |
| | | log.info("执行待审批订单查询,工作流ID列表: {}, 订单状态: {}, 产品名称: {}", workFlowIds, queryDTO.getOrderStatus(), queryDTO.getProductName()); |
| | | IPage<OrderInfo> result = baseMapper.selectPendingApprovalOrderPage( |
| | | page, queryDTO.getOrderStatus(), queryDTO.getProductName(), queryDTO.getProviderName(), |
| | | queryDTO.getOrderId(), |
| | | queryDTO.getApplyTimeStart() != null ? queryDTO.getApplyTimeStart().toString() : null, |
| | | queryDTO.getApplyTimeEnd() != null ? queryDTO.getApplyTimeEnd().toString() : null, |
| | | queryDTO.getOrderBy(), queryDTO.getOrderDirection() |
| | | queryDTO.getOrderBy(), queryDTO.getOrderDirection(), workFlowIds |
| | | ); |
| | | log.info("查询结果总数: {}, 当前页记录数: {}", result.getTotal(), result.getRecords().size()); |
| | | |
| | | // 将订单与详情联表封装到VO |
| | | List<OrderDetailVO> voList = result.getRecords().stream().map(order -> { |
| | | OrderDetailVO vo = new OrderDetailVO(); |
| | | BeanUtils.copyProperties(order, vo); |
| | | List<OrderDetail> details = orderDetailMapper.selectByOrderId(order.getOrderId()); |
| | | List<OrderDetailItemVO> items = details.stream().map(d -> { |
| | | OrderDetailItemVO item = new OrderDetailItemVO(); |
| | | BeanUtils.copyProperties(d, item); |
| | | return item; |
| | | }).collect(java.util.stream.Collectors.toList()); |
| | | vo.setOrderDetails(items); |
| | | vo.setTaskId(workFlowIdAndTaskIdMap.get(vo.getWorkflowId())); |
| | | return vo; |
| | | }).collect(java.util.stream.Collectors.toList()); |
| | | |
| | | // 构建返回结果 |
| | | return new PageResult<OrderInfo>( |
| | | result.getRecords(), |
| | | return new PageResult<OrderDetailVO>( |
| | | voList, |
| | | result.getTotal(), |
| | | queryDTO.getPageNum().longValue(), |
| | | queryDTO.getPageSize().longValue(), |
| | | result.getPages() |
| | | ); |
| | | } |
| | | |
| | | @Override |
| | | public PageResult<OrderDetailVO> getPendingApprovalOrderPageWithProductConditions(OrderQueryDTO queryDTO) { |
| | | // 根据产品条件查询产品ID列表 |
| | | List<String> productIds = null; |
| | | if (StringUtils.hasText(queryDTO.getIndustryId()) || queryDTO.getUnitProjectId() != null || |
| | | StringUtils.hasText(queryDTO.getProductTypeId()) || StringUtils.hasText(queryDTO.getProductSubTypeId())) { |
| | | productIds = reportResultSubmissionMapper.selectProductIdsByConditions( |
| | | queryDTO.getIndustryId(), queryDTO.getUnitProjectId(), queryDTO.getImportantDistrictId(), |
| | | queryDTO.getProductTypeId(), queryDTO.getProductSubTypeId() |
| | | ); |
| | | |
| | | // 如果没有找到匹配的产品,直接返回空结果 |
| | | if (CollectionUtils.isEmpty(productIds)) { |
| | | return new PageResult<OrderDetailVO>( |
| | | java.util.Collections.emptyList(), |
| | | 0L, |
| | | queryDTO.getPageNum().longValue(), |
| | | queryDTO.getPageSize().longValue(), |
| | | 0L |
| | | ); |
| | | } |
| | | } |
| | | |
| | | // 创建分页对象 |
| | | Page<OrderInfo> page = new Page<>(queryDTO.getPageNum(), queryDTO.getPageSize()); |
| | | |
| | | // 执行分页查询 |
| | | // 基于workFlowType查询流程实例ID集合 |
| | | List<?> workFlowList = fetchWorkflowProcessInstanceIds( |
| | | queryDTO.getWorkFlowType(), |
| | | queryDTO.getUserId(), |
| | | queryDTO.getDepartmentId(), |
| | | queryDTO.getBusinessType(), |
| | | queryDTO.getPageNum(), |
| | | queryDTO.getPageSize() |
| | | ); |
| | | // 如果没有任何流程ID,直接返回空分页 |
| | | if (workFlowList == null || workFlowList.isEmpty()) { |
| | | return new PageResult<OrderDetailVO>( |
| | | java.util.Collections.emptyList(), |
| | | 0L, |
| | | queryDTO.getPageNum().longValue(), |
| | | queryDTO.getPageSize().longValue(), |
| | | 0L |
| | | ); |
| | | } |
| | | |
| | | List<String> workFlowIds = workFlowList.stream() |
| | | .filter(item -> item instanceof Map) |
| | | .map(item -> (Map<?, ?>) item) |
| | | .map(m -> m.get("processInstanceId")) |
| | | .filter(Objects::nonNull) |
| | | .map(Object::toString) |
| | | .collect(Collectors.toList()); |
| | | |
| | | Map<String,String> workFlowIdAndTaskIdMap = workFlowList.stream() |
| | | .filter(item -> item instanceof Map) |
| | | .map(item -> (Map<?, ?>) item).collect(Collectors.toMap(m -> m.get("processInstanceId").toString(), m -> m.get("taskId").toString(),(k1,k2) -> k2)); |
| | | |
| | | |
| | | IPage<OrderInfo> result = baseMapper.selectPendingApprovalOrderPageWithProductConditions( |
| | | page, queryDTO.getOrderStatus(), queryDTO.getProductName(), queryDTO.getProviderName(), |
| | | queryDTO.getOrderId(), |
| | | queryDTO.getApplyTimeStart() != null ? queryDTO.getApplyTimeStart().toString() : null, |
| | | queryDTO.getApplyTimeEnd() != null ? queryDTO.getApplyTimeEnd().toString() : null, |
| | | queryDTO.getOrderBy(), queryDTO.getOrderDirection(), productIds, workFlowIds |
| | | ); |
| | | // 将订单与详情联表封装到VO |
| | | List<OrderDetailVO> voList = result.getRecords().stream().map(order -> { |
| | | OrderDetailVO vo = new OrderDetailVO(); |
| | | BeanUtils.copyProperties(order, vo); |
| | | List<OrderDetail> details = orderDetailMapper.selectByOrderId(order.getOrderId()); |
| | | List<OrderDetailItemVO> items = details.stream().map(d -> { |
| | | OrderDetailItemVO item = new OrderDetailItemVO(); |
| | | BeanUtils.copyProperties(d, item); |
| | | return item; |
| | | }).collect(java.util.stream.Collectors.toList()); |
| | | vo.setOrderDetails(items); |
| | | vo.setTaskId(workFlowIdAndTaskIdMap.get(vo.getWorkflowId())); |
| | | return vo; |
| | | }).collect(java.util.stream.Collectors.toList()); |
| | | |
| | | // 构建返回结果 |
| | | return new PageResult<OrderDetailVO>( |
| | | voList, |
| | | result.getTotal(), |
| | | queryDTO.getPageNum().longValue(), |
| | | queryDTO.getPageSize().longValue(), |
| | | result.getPages() |
| | | ); |
| | | } |
| | | |
| | | @Override |
| | | public PageResult<OrderDetailVO> getBuyerOrderPageWithProductConditions(OrderQueryDTO queryDTO) { |
| | | // 参数校验 |
| | | if (queryDTO.getUserId() == null) { |
| | | throw new BusinessException("用户ID不能为空"); |
| | | } |
| | | |
| | | // 根据产品条件查询产品ID列表 |
| | | List<String> productIds = null; |
| | | if (StringUtils.hasText(queryDTO.getIndustryId()) || queryDTO.getUnitProjectId() != null || |
| | | StringUtils.hasText(queryDTO.getProductTypeId()) || StringUtils.hasText(queryDTO.getProductSubTypeId())) { |
| | | productIds = reportResultSubmissionMapper.selectProductIdsByConditions( |
| | | queryDTO.getIndustryId(), queryDTO.getUnitProjectId(), queryDTO.getImportantDistrictId(), |
| | | queryDTO.getProductTypeId(), queryDTO.getProductSubTypeId() |
| | | ); |
| | | |
| | | // 如果没有找到匹配的产品,直接返回空结果 |
| | | if (CollectionUtils.isEmpty(productIds)) { |
| | | return new PageResult<OrderDetailVO>( |
| | | java.util.Collections.emptyList(), |
| | | 0L, |
| | | queryDTO.getPageNum().longValue(), |
| | | queryDTO.getPageSize().longValue(), |
| | | 0L |
| | | ); |
| | | } |
| | | } |
| | | |
| | | // 创建分页对象 |
| | | Page<OrderInfo> page = new Page<>(queryDTO.getPageNum(), queryDTO.getPageSize()); |
| | | |
| | | // 执行分页查询 |
| | | IPage<OrderInfo> result = baseMapper.selectBuyerOrderPageWithProductConditions( |
| | | page, queryDTO.getUserId(), queryDTO.getUnitId(), queryDTO.getOrderStatus(), |
| | | queryDTO.getPaymentStatus(), queryDTO.getPaymentType(), queryDTO.getProductName(), |
| | | queryDTO.getProviderName(), queryDTO.getOrderId(), |
| | | queryDTO.getApplyTimeStart() != null ? queryDTO.getApplyTimeStart().toString() : null, |
| | | queryDTO.getApplyTimeEnd() != null ? queryDTO.getApplyTimeEnd().toString() : null, |
| | | queryDTO.getCreateTimeStart() != null ? queryDTO.getCreateTimeStart().toString() : null, |
| | | queryDTO.getCreateTimeEnd() != null ? queryDTO.getCreateTimeEnd().toString() : null, |
| | | queryDTO.getOrderBy(), queryDTO.getOrderDirection(), productIds |
| | | ); |
| | | |
| | | // 将订单与详情联表封装到VO |
| | | List<OrderDetailVO> voList = result.getRecords().stream().map(order -> { |
| | | OrderDetailVO vo = new OrderDetailVO(); |
| | | BeanUtils.copyProperties(order, vo); |
| | | List<OrderDetail> details = orderDetailMapper.selectByOrderId(order.getOrderId()); |
| | | List<OrderDetailItemVO> items = details.stream().map(d -> { |
| | | OrderDetailItemVO item = new OrderDetailItemVO(); |
| | | BeanUtils.copyProperties(d, item); |
| | | return item; |
| | | }).collect(java.util.stream.Collectors.toList()); |
| | | vo.setOrderDetails(items); |
| | | return vo; |
| | | }).collect(java.util.stream.Collectors.toList()); |
| | | |
| | | // 构建返回结果 |
| | | return new PageResult<OrderDetailVO>( |
| | | voList, |
| | | result.getTotal(), |
| | | queryDTO.getPageNum().longValue(), |
| | | queryDTO.getPageSize().longValue(), |
| | | result.getPages() |
| | | ); |
| | | } |
| | | |
| | | @Override |
| | | public PageResult<OrderDetailVO> getSellerOrderPageWithProductConditions(OrderQueryDTO queryDTO) { |
| | | // 参数校验 |
| | | if (queryDTO.getProviderId() == null) { |
| | | throw new BusinessException("提供者ID不能为空"); |
| | | } |
| | | |
| | | // 根据产品条件查询产品ID列表 |
| | | List<String> productIds = null; |
| | | if (StringUtils.hasText(queryDTO.getIndustryId()) || queryDTO.getUnitProjectId()!= null || |
| | | StringUtils.hasText(queryDTO.getProductTypeId()) || StringUtils.hasText(queryDTO.getProductSubTypeId())) { |
| | | productIds = reportResultSubmissionMapper.selectProductIdsByConditions( |
| | | queryDTO.getIndustryId(), queryDTO.getUnitProjectId(), queryDTO.getImportantDistrictId(), |
| | | queryDTO.getProductTypeId(), queryDTO.getProductSubTypeId() |
| | | ); |
| | | |
| | | // 如果没有找到匹配的产品,直接返回空结果 |
| | | if (CollectionUtils.isEmpty(productIds)) { |
| | | return new PageResult<OrderDetailVO>( |
| | | java.util.Collections.emptyList(), |
| | | 0L, |
| | | queryDTO.getPageNum().longValue(), |
| | | queryDTO.getPageSize().longValue(), |
| | | 0L |
| | | ); |
| | | } |
| | | } |
| | | |
| | | // 创建分页对象 |
| | | Page<OrderInfo> page = new Page<>(queryDTO.getPageNum(), queryDTO.getPageSize()); |
| | | |
| | | // 执行分页查询 |
| | | IPage<OrderInfo> result = baseMapper.selectSellerOrderPageWithProductConditions( |
| | | page, queryDTO.getProviderId(), queryDTO.getOrderStatus(), queryDTO.getPaymentStatus(), |
| | | queryDTO.getProductName(), queryDTO.getOrderId(), |
| | | queryDTO.getApplyTimeStart() != null ? queryDTO.getApplyTimeStart().toString() : null, |
| | | queryDTO.getApplyTimeEnd() != null ? queryDTO.getApplyTimeEnd().toString() : null, |
| | | queryDTO.getCreateTimeStart() != null ? queryDTO.getCreateTimeStart().toString() : null, |
| | | queryDTO.getCreateTimeEnd() != null ? queryDTO.getCreateTimeEnd().toString() : null, |
| | | queryDTO.getOrderBy(), queryDTO.getOrderDirection(), productIds |
| | | ); |
| | | |
| | | // 将订单与详情联表封装到VO |
| | | List<OrderDetailVO> voList = result.getRecords().stream().map(order -> { |
| | | OrderDetailVO vo = new OrderDetailVO(); |
| | | BeanUtils.copyProperties(order, vo); |
| | | List<OrderDetail> details = orderDetailMapper.selectByOrderId(order.getOrderId()); |
| | | List<OrderDetailItemVO> items = details.stream().map(d -> { |
| | | OrderDetailItemVO item = new OrderDetailItemVO(); |
| | | BeanUtils.copyProperties(d, item); |
| | | return item; |
| | | }).collect(java.util.stream.Collectors.toList()); |
| | | vo.setOrderDetails(items); |
| | | return vo; |
| | | }).collect(java.util.stream.Collectors.toList()); |
| | | |
| | | // 构建返回结果 |
| | | return new PageResult<OrderDetailVO>( |
| | | voList, |
| | | result.getTotal(), |
| | | queryDTO.getPageNum().longValue(), |
| | | queryDTO.getPageSize().longValue(), |
| | |
| | | } |
| | | // 生成订单编号 |
| | | String orderId = orderNoService.generateOrderNo(); |
| | | |
| | | // 先调用工作流接口,获取工作流ID |
| | | String workflowId = null; |
| | | String taskId = null; |
| | | try { |
| | | // 检查是否有价格类型为"协议"的明细项 |
| | | boolean hasAgreementPrice = createOrderDTO.getItems().stream() |
| | | .anyMatch(item -> "协议".equals(item.getPriceType())); |
| | | |
| | | // 根据是否包含协议确定type值 |
| | | String type = hasAgreementPrice ? "trade_agreement" : "trade_point"; |
| | | |
| | | // 调用获取流程模板ID的接口 |
| | | // String processTemplateId = getProcessTemplateId(type); |
| | | |
| | | if (createOrderDTO.getProcessdefId() != null) { |
| | | // 调用发起工作流的接口 |
| | | Map<String,Object> resMap = startWorkflowProcess(createOrderDTO.getProcessdefId(), createOrderDTO.getUserId(), type); |
| | | workflowId = resMap.get("processinstId").toString(); |
| | | taskId = resMap.get("taskId").toString(); |
| | | } else { |
| | | throw new BusinessException("流程定义Id为空!"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("调用工作流接口失败,订单ID: {}", orderId, e); |
| | | // 工作流调用失败,抛出异常触发事务回滚 |
| | | throw new BusinessException("工作流调用失败: " + e.getMessage()); |
| | | } |
| | | |
| | | // 计算总金额 |
| | | BigDecimal totalAmount = BigDecimal.ZERO; |
| | |
| | | orderInfo.setPaymentType(createOrderDTO.getPaymentType()); |
| | | orderInfo.setPaymentStatus("未支付"); |
| | | orderInfo.setBuyerRemarks(createOrderDTO.getBuyerRemarks()); |
| | | orderInfo.setIsEvaluate("未评价"); |
| | | orderInfo.setWorkflowId(workflowId); // 设置工作流ID |
| | | orderInfo.setTaskId(taskId); |
| | | orderInfo.setCreatedAt(LocalDateTime.now()); |
| | | orderInfo.setUpdatedAt(LocalDateTime.now()); |
| | | |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long uploadOrderAttachment(String orderId, String fileName, String originalName, |
| | | String fileType, Long fileSize, String fileUrl, |
| | | String bucketName, String objectName, Long uploadUserId, |
| | | String bucketName, String objectName, String uploadUserId, |
| | | String uploadUserName, String attachmentType, String description) { |
| | | // 参数校验 |
| | | if (!StringUtils.hasText(orderId)) { |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean addOrderEvaluation(String orderId, Long evaluatorId, String evaluatorName, |
| | | public boolean addOrderEvaluation(String orderId, String evaluatorId, String evaluatorName, |
| | | String evaluatorType, String content, Integer rating, |
| | | Integer serviceRating, Integer qualityRating, Integer deliveryRating, |
| | | Boolean isAnonymous) { |
| | |
| | | throw new BusinessException("插入审批记录失败"); |
| | | } |
| | | |
| | | // 更新交易信息备注(只更新remarks,不更新订单状态) |
| | | // 只更新订单详情备注,不更新订单状态 |
| | | if(orderApprovalDTO.getOrderDetails() != null) { |
| | | for (UpdateOrderDetailDTO.UpdateOrderDetailItemDTO itemDTO : orderApprovalDTO.getOrderDetails()) { |
| | | if (itemDTO.getId() == null) { |
| | | continue; |
| | | } |
| | | |
| | | OrderDetail orderDetail = orderDetailMapper.selectById(itemDTO.getId()); |
| | | if (orderDetail == null) { |
| | | log.warn("订单详情不存在,ID: {}", itemDTO.getId()); |
| | | continue; |
| | | } |
| | | |
| | | // 更新备注 |
| | | orderDetail.setRemarks(itemDTO.getRemarks()); |
| | | orderDetail.setUpdatedAt(LocalDateTime.now()); |
| | | |
| | | int detailUpdated = orderDetailMapper.updateById(orderDetail); |
| | | if (detailUpdated <= 0) { |
| | | log.warn("更新订单详情失败,ID: {}", itemDTO.getId()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 先调用工作流,再依据结果决定是否流转订单状态 |
| | | String currentStatus = orderInfo.getOrderStatus(); |
| | | if (!StringUtils.hasText(currentStatus)) { |
| | | throw new BusinessException("订单当前状态为空"); |
| | | } |
| | | boolean isReject = orderApprovalDTO.getApprovalResult().contains("驳回"); |
| | | |
| | | // 根据审批结果调用提交或驳回接口 |
| | | String comment = isReject ? "审核驳回" : "审核通过"; |
| | | boolean workflowEnded = false; |
| | | if (isReject) { |
| | | // 驳回:调用工作流驳回,并将订单状态回退到上一个状态 |
| | | rejectWorkflowTask(orderApprovalDTO.getTaskId(), String.valueOf(orderApprovalDTO.getApproverId()), orderApprovalDTO.getApprovalOpinion()); |
| | | String previousStatus = getPreviousOrderStatus(currentStatus); |
| | | if (previousStatus == null) { |
| | | throw new BusinessException("已是初始状态,无法回退"); |
| | | } |
| | | orderInfo.setOrderStatus(previousStatus); |
| | | orderInfo.setUpdatedAt(LocalDateTime.now()); |
| | | |
| | | int updated = this.baseMapper.updateById(orderInfo); |
| | | if (updated <= 0) { |
| | | throw new BusinessException("更新订单状态失败"); |
| | | } |
| | | log.info("订单状态回退成功,订单ID: {}, 从 {} 回退为 {}", orderInfo.getOrderId(), currentStatus, previousStatus); |
| | | } else { |
| | | // 通过:调用完成任务,并读取工作流是否结束 |
| | | workflowEnded = completeWorkflowTask(orderApprovalDTO.getTaskId(), String.valueOf(orderApprovalDTO.getApproverId()), orderApprovalDTO.getApprovalOpinion()); |
| | | // 按需流转订单状态:仅当是通过且工作流已结束时,推进到下一个状态 |
| | | if (workflowEnded) { |
| | | String targetStatus = getNextOrderStatus(currentStatus); |
| | | if (targetStatus == null) { |
| | | throw new BusinessException("已是最终状态,无法继续流转"); |
| | | } |
| | | orderInfo.setOrderStatus(targetStatus); |
| | | orderInfo.setUpdatedAt(LocalDateTime.now()); |
| | | |
| | | int updated = this.baseMapper.updateById(orderInfo); |
| | | if (updated <= 0) { |
| | | throw new BusinessException("更新订单状态失败"); |
| | | } |
| | | log.info("订单状态更新成功,订单ID: {}, 从 {} 更新为 {}", orderInfo.getOrderId(), currentStatus, targetStatus); |
| | | } else { |
| | | log.info("未推进订单状态,原因:isReject={}, workflowEnded={}", isReject, workflowEnded); |
| | | } |
| | | } |
| | | |
| | | log.info("审批记录添加成功,订单ID: {}, 审批类型: {}, 审批结果: {}, 审批人: {}, 审批意见: {}", |
| | | orderApprovalDTO.getOrderId(), |
| | | orderApprovalDTO.getApprovalType(), |
| | |
| | | private String getNextOrderStatus(String currentStatus) { |
| | | switch (currentStatus) { |
| | | case "待上传文件": |
| | | return "待授权"; |
| | | return "待审批授权"; |
| | | case "待审批授权": |
| | | case "待授权": |
| | | return "待交易确认"; |
| | | return "待交易确认"; |
| | | case "待交易确认": |
| | | return "已完成"; |
| | | case "已完成": |
| | |
| | | switch (currentStatus) { |
| | | case "待上传文件": |
| | | return null; // 初始状态 |
| | | case "待授权": |
| | | case "待审批授权": |
| | | return "待上传文件"; |
| | | case "待交易确认": |
| | | return "待授权"; |
| | |
| | | try { |
| | | // 1. 删除订单附件(包括MinIO文件和数据库记录) |
| | | log.info("开始删除订单附件,订单ID: {}", orderId); |
| | | List<OrderAttachment> attachments = orderAttachmentMapper.selectByOrderId(orderId); |
| | | for (OrderAttachment attachment : attachments) { |
| | | try { |
| | | // 删除MinIO中的文件 |
| | | if (StringUtils.hasText(attachment.getObjectName())) { |
| | | log.info("删除MinIO文件,对象名称: {}", attachment.getObjectName()); |
| | | minioService.deleteFile(attachment.getObjectName()); |
| | | } |
| | | // 删除数据库记录 |
| | | orderAttachmentMapper.deleteById(attachment.getId()); |
| | | log.info("删除附件记录成功,附件ID: {}", attachment.getId()); |
| | | } catch (Exception e) { |
| | | log.error("删除附件失败,附件ID: {}, 错误: {}", attachment.getId(), e.getMessage()); |
| | | // 继续删除其他附件,不中断整个流程 |
| | | } |
| | | } |
| | | // List<OrderAttachment> attachments = orderAttachmentMapper.selectByOrderId(orderId); |
| | | // for (OrderAttachment attachment : attachments) { |
| | | // try { |
| | | // // 删除MinIO中的文件 |
| | | // if (StringUtils.hasText(attachment.getObjectName())) { |
| | | // log.info("删除MinIO文件,对象名称: {}", attachment.getObjectName()); |
| | | // minioService.deleteFile(attachment.getObjectName()); |
| | | // } |
| | | // // 删除数据库记录 |
| | | // orderAttachmentMapper.deleteById(attachment.getId()); |
| | | // log.info("删除附件记录成功,附件ID: {}", attachment.getId()); |
| | | // } catch (Exception e) { |
| | | // log.error("删除附件失败,附件ID: {}, 错误: {}", attachment.getId(), e.getMessage()); |
| | | // // 继续删除其他附件,不中断整个流程 |
| | | // } |
| | | // } |
| | | |
| | | // 2. 逻辑删除订单详情 |
| | | log.info("开始逻辑删除订单详情,订单ID: {}", orderId); |
| | | // log.info("开始逻辑删除订单详情,订单ID: {}", orderId); |
| | | // 先查询订单详情列表,然后逐个逻辑删除 |
| | | List<OrderDetail> orderDetails = orderDetailMapper.selectByOrderId(orderId); |
| | | int detailDeleted = 0; |
| | | for (OrderDetail detail : orderDetails) { |
| | | int result = orderDetailMapper.deleteById(detail.getId()); |
| | | if (result > 0) { |
| | | detailDeleted++; |
| | | } |
| | | } |
| | | log.info("逻辑删除订单详情完成,影响行数: {}", detailDeleted); |
| | | // List<OrderDetail> orderDetails = orderDetailMapper.selectByOrderId(orderId); |
| | | // int detailDeleted = 0; |
| | | // for (OrderDetail detail : orderDetails) { |
| | | // int result = orderDetailMapper.deleteById(detail.getId()); |
| | | // if (result > 0) { |
| | | // detailDeleted++; |
| | | // } |
| | | // } |
| | | // log.info("逻辑删除订单详情完成,影响行数: {}", detailDeleted); |
| | | |
| | | // 3. 删除订单信息(逻辑删除) |
| | | log.info("开始删除订单信息,订单ID: {}", orderId); |
| | | int orderDeleted = this.baseMapper.deleteById(orderId); |
| | | log.info("删除订单信息完成,影响行数: {}", orderDeleted); |
| | | // log.info("开始删除订单信息,订单ID: {}", orderId); |
| | | // int orderDeleted = this.baseMapper.deleteById(orderId); |
| | | // log.info("删除订单信息完成,影响行数: {}", orderDeleted); |
| | | // 更新订单状态为已完成 |
| | | orderInfo.setOrderStatus("已取消"); |
| | | orderInfo.setUpdatedAt(LocalDateTime.now()); |
| | | int orderDeleted = this.baseMapper.updateById(orderInfo); |
| | | |
| | | if (orderDeleted > 0) { |
| | | log.info("订单取消成功,订单ID: {}", orderId); |
| | | return true; |
| | | } else { |
| | | log.error("删除订单信息失败,影响行数为0,订单ID: {}", orderId); |
| | | log.error("更新订单信息失败,影响行数为0,订单ID: {}", orderId); |
| | | throw new BusinessException("删除订单信息失败"); |
| | | } |
| | | } catch (Exception e) { |
| | |
| | | throw new BusinessException("取消订单失败:" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean updateWorkflowId(String orderId, String workflowId) { |
| | | if (!StringUtils.hasText(orderId)) { |
| | | throw new BusinessException("订单ID不能为空"); |
| | | } |
| | | if (!StringUtils.hasText(workflowId)) { |
| | | throw new BusinessException("工作流ID不能为空"); |
| | | } |
| | | |
| | | OrderInfo orderInfo = this.getById(orderId); |
| | | if (orderInfo == null) { |
| | | throw new BusinessException("订单不存在"); |
| | | } |
| | | |
| | | orderInfo.setWorkflowId(workflowId); |
| | | orderInfo.setUpdatedAt(LocalDateTime.now()); |
| | | return this.updateById(orderInfo); |
| | | } |
| | | |
| | | @Override |
| | | public boolean existsCompletedNotCancelledOrderByProductId(String productId) { |
| | | if (!StringUtils.hasText(productId)) { |
| | | throw new BusinessException("产品ID不能为空"); |
| | | } |
| | | QueryWrapper<OrderInfo> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("product_id", productId); |
| | | // 未取消:逻辑未删除 |
| | | wrapper.eq("deleted", 0); |
| | | // 审核中:状态不为 已完成 或 已取消 |
| | | wrapper.notIn("order_status", Arrays.asList("已完成", "已取消")); |
| | | Long count = this.baseMapper.selectCount(wrapper); |
| | | return count != null && count > 0; |
| | | } |
| | | |
| | | @Override |
| | | public boolean updateOrderIsEvaluate(String orderId) { |
| | | if (!StringUtils.hasText(orderId)) { |
| | | throw new BusinessException("订单ID不能为空"); |
| | | } |
| | | OrderInfo orderInfo = this.getById(orderId); |
| | | if (orderInfo == null) { |
| | | throw new BusinessException("订单不存在"); |
| | | } |
| | | orderInfo.setIsEvaluate("已评价"); |
| | | return this.updateById(orderInfo); |
| | | } |
| | | |
| | | /** |
| | | * 获取流程模板ID |
| | | * @param type 类型参数 |
| | | * @return 流程模板ID |
| | | */ |
| | | private String getProcessTemplateId(String type) { |
| | | try { |
| | | String url = workflowProperties.getApproval().getBaseUrl() + workflowProperties.getApproval().getTemplateRelationUrl(); |
| | | |
| | | // 构建请求参数 |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("type", type); |
| | | params.put("unitId", workflowProperties.getApproval().getUnitId()); |
| | | |
| | | // 发送POST请求 |
| | | ResponseEntity<Map<String, Object>> response = restTemplate.exchange( |
| | | url, |
| | | HttpMethod.POST, |
| | | new HttpEntity<>(params), |
| | | new ParameterizedTypeReference<Map<String, Object>>() {} |
| | | ); |
| | | |
| | | if (response.getStatusCode().is2xxSuccessful() && response.getBody() != null) { |
| | | Map<String, Object> responseBody = response.getBody(); |
| | | return (String) responseBody.get("processTemplateId"); |
| | | } else { |
| | | log.warn("获取流程模板ID失败,响应状态: {}", response.getStatusCode()); |
| | | return null; |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("调用获取流程模板ID接口失败", e); |
| | | throw new BusinessException("获取流程模板ID失败: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 启动工作流流程 |
| | | * @param processTemplateId 流程模板ID |
| | | * @param userId 用户ID |
| | | * @param businessKey 业务键(订单ID) |
| | | * @return 流程实例ID |
| | | */ |
| | | private Map<String,Object> startWorkflowProcess(String processTemplateId, String userId, String businessKey) { |
| | | try { |
| | | String url = workflowProperties.getProcess().getBaseUrl() + workflowProperties.getProcess().getStartProcessUrl(); |
| | | |
| | | // 构建请求参数 |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("processdefId", processTemplateId); |
| | | params.put("userid", userId); |
| | | params.put("businessKey", businessKey); |
| | | |
| | | // 发送POST请求 |
| | | ResponseEntity<Map<String, Object>> response = restTemplate.exchange( |
| | | url, |
| | | HttpMethod.POST, |
| | | new HttpEntity<>(params), |
| | | new ParameterizedTypeReference<Map<String, Object>>() {} |
| | | ); |
| | | |
| | | if (response.getStatusCode().is2xxSuccessful() && response.getBody() != null) { |
| | | Object code = response.getBody().get("code"); |
| | | boolean ok = (code instanceof Number && ((Number) code).intValue() == 200) || "200".equals(String.valueOf(code)); |
| | | if (!ok) { |
| | | throw new BusinessException("工作流启动任务失败,返回码: " + code); |
| | | } |
| | | Map<String, Object> data = (Map<String, Object>) response.getBody().get("data"); |
| | | if (data == null) { |
| | | throw new BusinessException("工作流启动任务失败,返回数据为空"); |
| | | } |
| | | return data; |
| | | } else { |
| | | throw new BusinessException("启动工作流失败,响应状态:"+response.getStatusCode()); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("调用启动工作流接口失败", e); |
| | | throw new BusinessException("启动工作流失败: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 提交流程任务 |
| | | * @param taskId 任务ID(使用订单的workflowId) |
| | | * @param userId 用户ID |
| | | * @param comment 审批意见(如:审核通过) |
| | | */ |
| | | private boolean completeWorkflowTask(String taskId, String userId, String comment) { |
| | | try { |
| | | String url = workflowProperties.getProcess().getBaseUrl() + workflowProperties.getProcess().getCompleteUrl(); |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("taskId", taskId); |
| | | params.put("userid", userId); |
| | | params.put("commponet", comment); |
| | | |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.APPLICATION_JSON); |
| | | HttpEntity<Map<String, Object>> entity = new HttpEntity<>(params, headers); |
| | | |
| | | ResponseEntity<Map<String, Object>> response = restTemplate.exchange( |
| | | url, |
| | | HttpMethod.POST, |
| | | entity, |
| | | new ParameterizedTypeReference<Map<String, Object>>() {} |
| | | ); |
| | | |
| | | if (response.getStatusCode().is2xxSuccessful() && response.getBody() != null) { |
| | | Object code = response.getBody().get("code"); |
| | | boolean ok = (code instanceof Number && ((Number) code).intValue() == 200) || "200".equals(String.valueOf(code)); |
| | | if (!ok) { |
| | | throw new BusinessException("工作流完成任务失败,返回码: " + code); |
| | | } |
| | | Map<?, ?> data = (Map<?, ?>) response.getBody().get("data"); |
| | | if (data == null) { |
| | | throw new BusinessException("工作流完成任务失败,返回数据为空"); |
| | | } |
| | | Object isEndedObj = data.get("isEnded"); |
| | | boolean isEnded = false; |
| | | if (isEndedObj instanceof Boolean) { |
| | | isEnded = (Boolean) isEndedObj; |
| | | } else if (isEndedObj != null) { |
| | | isEnded = "true".equalsIgnoreCase(String.valueOf(isEndedObj)); |
| | | } |
| | | log.info("完成工作流任务成功,processinstId: {}, isEnded: {}", data.get("processinstId"), isEnded); |
| | | return isEnded; |
| | | } else { |
| | | throw new BusinessException("工作流完成任务接口调用失败,HTTP状态: " + response.getStatusCode()); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("提交工作流失败", e); |
| | | throw new BusinessException("提交工作流失败: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 驳回流程任务 |
| | | */ |
| | | private void rejectWorkflowTask(String taskId, String userId, String comment) { |
| | | try { |
| | | String url = workflowProperties.getProcess().getBaseUrl() + workflowProperties.getProcess().getRejectUrl(); |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("taskId", taskId); |
| | | params.put("userid", userId); |
| | | params.put("commponet", comment); |
| | | |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.APPLICATION_JSON); |
| | | HttpEntity<Map<String, Object>> entity = new HttpEntity<>(params, headers); |
| | | |
| | | ResponseEntity<Map<String, Object>> response = restTemplate.exchange( |
| | | url, |
| | | HttpMethod.POST, |
| | | entity, |
| | | new ParameterizedTypeReference<Map<String, Object>>() {} |
| | | ); |
| | | |
| | | if (response.getStatusCode().is2xxSuccessful() && response.getBody() != null) { |
| | | Object code = response.getBody().get("code"); |
| | | boolean ok = (code instanceof Number && ((Number) code).intValue() == 200) || "200".equals(String.valueOf(code)); |
| | | if (!ok) { |
| | | throw new BusinessException("工作流驳回任务失败,返回码: " + code); |
| | | } |
| | | Map<?, ?> data = (Map<?, ?>) response.getBody().get("data"); |
| | | if (data == null) { |
| | | throw new BusinessException("工作流驳回任务失败,返回数据为空"); |
| | | } |
| | | log.info("驳回工作流任务成功,processinstId: {}", data.get("processinstId")); |
| | | } else { |
| | | throw new BusinessException("工作流驳回任务接口调用失败,HTTP状态: " + response.getStatusCode()); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("驳回工作流失败", e); |
| | | throw new BusinessException("驳回工作流失败: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 按照workFlowType查询流程实例ID集合 |
| | | * workFlowType: 0=代办,1=已办 |
| | | */ |
| | | private List<Object> fetchWorkflowProcessInstanceIds(Integer workFlowType, String userId, String depId,String businessKey,Integer pageIndex, Integer pageSize) { |
| | | try { |
| | | if (workFlowType == null) { |
| | | return java.util.Collections.emptyList(); |
| | | } |
| | | |
| | | String base = workflowProperties.getProcess().getBaseUrl(); |
| | | |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("userid", userId); |
| | | params.put("businessKey", businessKey); |
| | | params.put("pageIndex", pageIndex != null ? pageIndex : 1); |
| | | params.put("pageSize", pageSize != null ? pageSize : 10); |
| | | |
| | | String url; |
| | | if (workFlowType != null && workFlowType == 0) { |
| | | // 代办 |
| | | url = base + workflowProperties.getProcess().getFindTodoUrl(); |
| | | params.put("depid", depId); |
| | | } else { |
| | | // 已办 |
| | | url = base + workflowProperties.getProcess().getFindDoneUrl(); |
| | | } |
| | | |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.APPLICATION_JSON); |
| | | HttpEntity<Map<String, Object>> entity = new HttpEntity<>(params, headers); |
| | | |
| | | ResponseEntity<Map<String, Object>> response = restTemplate.exchange( |
| | | url, |
| | | HttpMethod.POST, |
| | | entity, |
| | | new ParameterizedTypeReference<Map<String, Object>>() {} |
| | | ); |
| | | |
| | | if (!response.getStatusCode().is2xxSuccessful() || response.getBody() == null) { |
| | | return java.util.Collections.emptyList(); |
| | | } |
| | | Object dataObj = response.getBody().get("data"); |
| | | |
| | | if (workFlowType != null && workFlowType == 0) { |
| | | if (!(dataObj instanceof java.util.List)) { |
| | | return java.util.Collections.emptyList(); |
| | | } |
| | | java.util.List<Object> list = (java.util.List<Object>) dataObj; |
| | | return list; |
| | | // list.stream() |
| | | // .filter(item -> item instanceof Map) |
| | | // .map(item -> (Map<?, ?>) item) |
| | | // .map(m -> m.get("processInstanceId")) |
| | | // .filter(Objects::nonNull) |
| | | // .map(Object::toString) |
| | | // .collect(Collectors.toList()); |
| | | }else { |
| | | if (!(dataObj instanceof Map)) { |
| | | return java.util.Collections.emptyList(); |
| | | } |
| | | Map<?,?> map = (Map<?,?>) dataObj; |
| | | Object dataObj1 = ((Map<?, ?>) dataObj).get("list"); |
| | | java.util.List<Object> list = (java.util.List<Object>) dataObj1; |
| | | return list; |
| | | // list.stream() |
| | | // .filter(item -> item instanceof Map) |
| | | // .map(item -> (Map<?, ?>) item) |
| | | // .map(m -> m.get("processInstanceId")) |
| | | // .filter(Objects::nonNull) |
| | | // .map(Object::toString) |
| | | // .collect(Collectors.toList()); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.error("查询工作流实例ID失败", e); |
| | | return java.util.Collections.emptyList(); |
| | | } |
| | | } |
| | | } |