| | |
| | | import com.webmanage.common.PageResult; |
| | | import com.webmanage.dto.CreateOrderDTO; |
| | | import com.webmanage.dto.CreateOrderItemDTO; |
| | | import com.webmanage.dto.FileCheckDTO; |
| | | import com.webmanage.dto.OrderApprovalDTO; |
| | | import com.webmanage.dto.OrderQueryDTO; |
| | | import com.webmanage.dto.UpdateOrderDetailDTO; |
| | | import com.webmanage.entity.OrderApproval; |
| | | import com.webmanage.entity.OrderAttachment; |
| | | import com.webmanage.entity.OrderDetail; |
| | | import com.webmanage.entity.OrderEvaluation; |
| | | import com.webmanage.entity.OrderInfo; |
| | | import com.webmanage.mapper.OrderApprovalMapper; |
| | | import com.webmanage.mapper.OrderAttachmentMapper; |
| | | 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实现类 |
| | |
| | | private OrderEvaluationMapper orderEvaluationMapper; |
| | | |
| | | @Resource |
| | | private OrderApprovalMapper orderApprovalMapper; |
| | | |
| | | @Resource |
| | | private OrderNoService orderNoService; |
| | | |
| | | @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.getUserId() == null) { |
| | | throw new BusinessException("用户ID不能为空"); |
| | | if (queryDTO.getProviderId() == null) { |
| | | throw new BusinessException("提供者ID不能为空"); |
| | | } |
| | | |
| | | // 创建分页对象 |
| | |
| | | |
| | | // 执行分页查询 |
| | | IPage<OrderInfo> result = baseMapper.selectSellerOrderPage( |
| | | page, queryDTO.getUserId(), queryDTO.getOrderStatus(), queryDTO.getPaymentStatus(), |
| | | 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.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()); |
| | | |
| | | 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)); |
| | | |
| | | // 执行分页查询 |
| | | IPage<OrderInfo> result = baseMapper.selectPendingApprovalOrderPage( |
| | |
| | | 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 |
| | | ); |
| | | |
| | | // 将订单与详情联表封装到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(), |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public String createOrder(CreateOrderDTO createOrderDTO) { |
| | | public OrderInfo createOrder(CreateOrderDTO createOrderDTO) { |
| | | if (createOrderDTO == null || CollectionUtils.isEmpty(createOrderDTO.getItems())) { |
| | | throw new BusinessException("订单信息不完整"); |
| | | } |
| | | // 生成订单编号 |
| | | 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.setUserId(createOrderDTO.getUserId()); |
| | | orderInfo.setUnitId(createOrderDTO.getUnitId()); |
| | | orderInfo.setApplyTime(LocalDateTime.now()); |
| | | orderInfo.setOrderStatus("待审批"); |
| | | |
| | | // 根据订单明细中是否包含协议价格类型来决定初始状态 |
| | | String initialStatus = determineInitialOrderStatus(createOrderDTO.getItems()); |
| | | orderInfo.setOrderStatus(initialStatus); |
| | | |
| | | orderInfo.setTotalAmount(createOrderDTO.getTotalAmount() != null ? createOrderDTO.getTotalAmount() : totalAmount); |
| | | 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()); |
| | | |
| | |
| | | orderDetailMapper.insert(detail); |
| | | } |
| | | |
| | | return orderId; |
| | | return orderInfo; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean uploadOrderAttachment(String orderId, String fileName, String originalName, |
| | | String fileType, Long fileSize, String fileUrl, |
| | | String bucketName, String objectName, Long uploadUserId, |
| | | String uploadUserName, String attachmentType, String description) { |
| | | public Long uploadOrderAttachment(String orderId, String fileName, String originalName, |
| | | String fileType, Long fileSize, String fileUrl, |
| | | String bucketName, String objectName, String uploadUserId, |
| | | String uploadUserName, String attachmentType, String description) { |
| | | // 参数校验 |
| | | if (!StringUtils.hasText(orderId)) { |
| | | throw new BusinessException("订单ID不能为空"); |
| | |
| | | attachment.setAttachmentType(attachmentType); |
| | | attachment.setDescription(description); |
| | | |
| | | // 保存附件 |
| | | return orderAttachmentMapper.insert(attachment) > 0; |
| | | // 保存附件并返回附件ID |
| | | int result = orderAttachmentMapper.insert(attachment); |
| | | if (result > 0) { |
| | | return attachment.getId(); |
| | | } else { |
| | | throw new BusinessException("保存附件失败"); |
| | | } |
| | | } |
| | | |
| | | @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) { |
| | |
| | | // 保存评价 |
| | | return orderEvaluationMapper.updateById(evaluation) > 0; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean updateOrderDetail(UpdateOrderDetailDTO updateOrderDetailDTO) { |
| | | // 参数校验 |
| | | if (updateOrderDetailDTO == null) { |
| | | throw new BusinessException("更新参数不能为空"); |
| | | } |
| | | if (!StringUtils.hasText(updateOrderDetailDTO.getOrderId())) { |
| | | throw new BusinessException("订单ID不能为空"); |
| | | } |
| | | if (!StringUtils.hasText(updateOrderDetailDTO.getOrderStatus())) { |
| | | throw new BusinessException("订单状态不能为空"); |
| | | } |
| | | if (CollectionUtils.isEmpty(updateOrderDetailDTO.getOrderDetails())) { |
| | | throw new BusinessException("订单详情列表不能为空"); |
| | | } |
| | | |
| | | // 查询订单信息 |
| | | OrderInfo orderInfo = this.getById(updateOrderDetailDTO.getOrderId()); |
| | | if (orderInfo == null) { |
| | | throw new BusinessException("订单不存在"); |
| | | } |
| | | |
| | | // 更新订单状态 |
| | | orderInfo.setOrderStatus(updateOrderDetailDTO.getOrderStatus()); |
| | | orderInfo.setUpdatedAt(LocalDateTime.now()); |
| | | int orderUpdated = this.baseMapper.updateById(orderInfo); |
| | | if (orderUpdated <= 0) { |
| | | throw new BusinessException("更新订单状态失败"); |
| | | } |
| | | |
| | | // 更新订单详情备注 |
| | | for (UpdateOrderDetailDTO.UpdateOrderDetailItemDTO itemDTO : updateOrderDetailDTO.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()); |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean checkFiles(FileCheckDTO fileCheckDTO) { |
| | | // 参数校验 |
| | | if (fileCheckDTO == null) { |
| | | throw new BusinessException("文件核查参数不能为空"); |
| | | } |
| | | if (!StringUtils.hasText(fileCheckDTO.getOrderId())) { |
| | | throw new BusinessException("订单ID不能为空"); |
| | | } |
| | | if (fileCheckDTO.getIsApprove() == null) { |
| | | throw new BusinessException("审批结果不能为空"); |
| | | } |
| | | if (fileCheckDTO.getApproverId() == null) { |
| | | throw new BusinessException("审批人ID不能为空"); |
| | | } |
| | | if (!StringUtils.hasText(fileCheckDTO.getApproverName())) { |
| | | throw new BusinessException("审批人姓名不能为空"); |
| | | } |
| | | |
| | | // 查询订单信息 |
| | | OrderInfo orderInfo = this.getById(fileCheckDTO.getOrderId()); |
| | | if (orderInfo == null) { |
| | | throw new BusinessException("订单不存在"); |
| | | } |
| | | |
| | | // 检查订单状态是否为"待授权" |
| | | if (!"待授权".equals(orderInfo.getOrderStatus())) { |
| | | throw new BusinessException("订单状态不正确,当前状态为:" + orderInfo.getOrderStatus()); |
| | | } |
| | | |
| | | // 更新订单状态 |
| | | if (fileCheckDTO.getIsApprove()) { |
| | | // 通过:更新为"待交易确认" |
| | | orderInfo.setOrderStatus("待交易确认"); |
| | | } else { |
| | | // 驳回:更新为"待上传文件"(需要重新上传) |
| | | orderInfo.setOrderStatus("待上传文件"); |
| | | } |
| | | orderInfo.setUpdatedAt(LocalDateTime.now()); |
| | | |
| | | // 保存订单 |
| | | int updated = this.baseMapper.updateById(orderInfo); |
| | | if (updated <= 0) { |
| | | throw new BusinessException("更新订单状态失败"); |
| | | } |
| | | |
| | | log.info("文件核查完成,订单ID: {}, 审批结果: {}, 审批人: {}, 审批意见: {}", |
| | | fileCheckDTO.getOrderId(), |
| | | fileCheckDTO.getIsApprove() ? "通过" : "驳回", |
| | | fileCheckDTO.getApproverName(), |
| | | fileCheckDTO.getApprovalOpinion()); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean approveOrder(OrderApprovalDTO orderApprovalDTO) { |
| | | // 参数校验 |
| | | if (orderApprovalDTO == null) { |
| | | throw new BusinessException("审批参数不能为空"); |
| | | } |
| | | if (!StringUtils.hasText(orderApprovalDTO.getOrderId())) { |
| | | throw new BusinessException("订单ID不能为空"); |
| | | } |
| | | if (!StringUtils.hasText(orderApprovalDTO.getApprovalOpinion())) { |
| | | throw new BusinessException("审批意见不能为空"); |
| | | } |
| | | if (orderApprovalDTO.getApproverId() == null) { |
| | | throw new BusinessException("审批人ID不能为空"); |
| | | } |
| | | if (!StringUtils.hasText(orderApprovalDTO.getApproverName())) { |
| | | throw new BusinessException("审批人姓名不能为空"); |
| | | } |
| | | if (!StringUtils.hasText(orderApprovalDTO.getApprovalType())) { |
| | | throw new BusinessException("审批类型不能为空"); |
| | | } |
| | | if (!StringUtils.hasText(orderApprovalDTO.getApprovalResult())) { |
| | | throw new BusinessException("审批结果不能为空"); |
| | | } |
| | | |
| | | // 查询订单信息 |
| | | OrderInfo orderInfo = this.getById(orderApprovalDTO.getOrderId()); |
| | | if (orderInfo == null) { |
| | | throw new BusinessException("订单不存在"); |
| | | } |
| | | |
| | | // 创建审批记录 |
| | | OrderApproval orderApproval = new OrderApproval(); |
| | | orderApproval.setOrderId(orderApprovalDTO.getOrderId()); |
| | | orderApproval.setApprovalStep("审批授权"); |
| | | orderApproval.setApprovalType(orderApprovalDTO.getApprovalType()); |
| | | orderApproval.setApprovalResult(orderApprovalDTO.getApprovalResult()); |
| | | orderApproval.setApproverId(orderApprovalDTO.getApproverId()); |
| | | orderApproval.setApproverName(orderApprovalDTO.getApproverName()); |
| | | orderApproval.setApprovalOpinion(orderApprovalDTO.getApprovalOpinion()); |
| | | orderApproval.setApprovalTime(LocalDateTime.now()); |
| | | |
| | | // 插入审批记录 |
| | | int insertResult = orderApprovalMapper.insert(orderApproval); |
| | | if (insertResult <= 0) { |
| | | 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 targetStatus = isReject ? getPreviousOrderStatus(currentStatus) : getNextOrderStatus(currentStatus); |
| | | if (targetStatus == null) { |
| | | throw new BusinessException((isReject ? "已是初始状态,无法回退" : "已是最终状态,无法继续流转")); |
| | | } |
| | | 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); |
| | | // 根据审批结果调用提交或驳回接口 |
| | | String comment = orderApprovalDTO.getApprovalResult().contains("驳回") ? "审核驳回" : "审核通过"; |
| | | if ("审核驳回".equals(comment)) { |
| | | rejectWorkflowTask(orderApprovalDTO.getTaskId(), String.valueOf(orderApprovalDTO.getApproverId()), orderApprovalDTO.getApprovalOpinion()); |
| | | } else { |
| | | completeWorkflowTask(orderApprovalDTO.getTaskId(), String.valueOf(orderApprovalDTO.getApproverId()), orderApprovalDTO.getApprovalOpinion()); |
| | | } |
| | | |
| | | log.info("审批记录添加成功,订单ID: {}, 审批类型: {}, 审批结果: {}, 审批人: {}, 审批意见: {}", |
| | | orderApprovalDTO.getOrderId(), |
| | | orderApprovalDTO.getApprovalType(), |
| | | orderApprovalDTO.getApprovalResult(), |
| | | orderApprovalDTO.getApproverName(), |
| | | orderApprovalDTO.getApprovalOpinion()); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean updateOrderStatusToNext(String orderId) { |
| | | // 参数校验 |
| | | if (!StringUtils.hasText(orderId)) { |
| | | throw new BusinessException("订单ID不能为空"); |
| | | } |
| | | |
| | | // 查询订单信息 |
| | | OrderInfo orderInfo = this.getById(orderId); |
| | | if (orderInfo == null) { |
| | | throw new BusinessException("订单不存在"); |
| | | } |
| | | |
| | | // 获取当前状态 |
| | | String currentStatus = orderInfo.getOrderStatus(); |
| | | if (!StringUtils.hasText(currentStatus)) { |
| | | throw new BusinessException("订单当前状态为空"); |
| | | } |
| | | |
| | | // 获取下一个状态 |
| | | String nextStatus = getNextOrderStatus(currentStatus); |
| | | if (nextStatus == null) { |
| | | throw new BusinessException("当前状态 " + currentStatus + " 已是最终状态,无法继续流转"); |
| | | } |
| | | |
| | | // 更新订单状态 |
| | | orderInfo.setOrderStatus(nextStatus); |
| | | orderInfo.setUpdatedAt(LocalDateTime.now()); |
| | | |
| | | int updated = this.baseMapper.updateById(orderInfo); |
| | | if (updated <= 0) { |
| | | throw new BusinessException("更新订单状态失败"); |
| | | } |
| | | |
| | | log.info("订单状态更新成功,订单ID: {}, 从 {} 更新为 {}", orderId, currentStatus, nextStatus); |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean updateOrderStatusToPrevious(String orderId) { |
| | | // 参数校验 |
| | | if (!StringUtils.hasText(orderId)) { |
| | | throw new BusinessException("订单ID不能为空"); |
| | | } |
| | | |
| | | // 查询订单信息 |
| | | OrderInfo orderInfo = this.getById(orderId); |
| | | if (orderInfo == null) { |
| | | throw new BusinessException("订单不存在"); |
| | | } |
| | | |
| | | // 获取当前状态 |
| | | String currentStatus = orderInfo.getOrderStatus(); |
| | | if (!StringUtils.hasText(currentStatus)) { |
| | | throw new BusinessException("订单当前状态为空"); |
| | | } |
| | | |
| | | // 获取上一个状态 |
| | | String previousStatus = getPreviousOrderStatus(currentStatus); |
| | | if (previousStatus == null) { |
| | | throw new BusinessException("当前状态 " + currentStatus + " 已是初始状态,无法回退"); |
| | | } |
| | | |
| | | // 更新订单状态 |
| | | orderInfo.setOrderStatus(previousStatus); |
| | | orderInfo.setUpdatedAt(LocalDateTime.now()); |
| | | |
| | | int updated = this.baseMapper.updateById(orderInfo); |
| | | if (updated <= 0) { |
| | | throw new BusinessException("更新订单状态失败"); |
| | | } |
| | | |
| | | log.info("订单状态更新成功,订单ID: {}, 从 {} 回退为 {}", orderId, currentStatus, previousStatus); |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 根据订单明细确定初始订单状态 |
| | | * @param items 订单明细列表 |
| | | * @return 初始状态 |
| | | */ |
| | | private String determineInitialOrderStatus(List<CreateOrderItemDTO> items) { |
| | | // 检查是否有价格类型为"协议"的明细项 |
| | | boolean hasAgreementPrice = items.stream() |
| | | .anyMatch(item -> "协议".equals(item.getPriceType())); |
| | | |
| | | // 如果有协议价格,从"待上传文件"开始,否则从"待授权"开始 |
| | | String initialStatus = hasAgreementPrice ? "待上传文件" : "待授权"; |
| | | |
| | | log.info("订单初始状态确定为: {}, 是否包含协议价格: {}", initialStatus, hasAgreementPrice); |
| | | return initialStatus; |
| | | } |
| | | |
| | | /** |
| | | * 获取下一个订单状态 |
| | | * @param currentStatus 当前状态 |
| | | * @return 下一个状态,如果是最终状态则返回null |
| | | */ |
| | | private String getNextOrderStatus(String currentStatus) { |
| | | switch (currentStatus) { |
| | | case "待上传文件": |
| | | return "待审批授权"; |
| | | case "待审批授权": |
| | | case "待授权": |
| | | return "待交易确认"; |
| | | case "待交易确认": |
| | | return "已完成"; |
| | | case "已完成": |
| | | return "已评价"; |
| | | case "已评价": |
| | | return null; // 最终状态 |
| | | default: |
| | | throw new BusinessException("未知的订单状态:" + currentStatus); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取上一个订单状态 |
| | | * @param currentStatus 当前状态 |
| | | * @return 上一个状态,如果是初始状态则返回null |
| | | */ |
| | | private String getPreviousOrderStatus(String currentStatus) { |
| | | switch (currentStatus) { |
| | | case "待上传文件": |
| | | return null; // 初始状态 |
| | | case "待审批授权": |
| | | return "待上传文件"; |
| | | case "待交易确认": |
| | | return "待授权"; |
| | | case "已完成": |
| | | return "待交易确认"; |
| | | case "已评价": |
| | | return "已完成"; |
| | | default: |
| | | throw new BusinessException("未知的订单状态:" + currentStatus); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public boolean hasAgreementPriceType(String orderId) { |
| | | // 参数校验 |
| | | if (!StringUtils.hasText(orderId)) { |
| | | throw new BusinessException("订单ID不能为空"); |
| | | } |
| | | |
| | | // 查询订单详情,检查是否有价格类型为"协议"的子订单 |
| | | QueryWrapper<OrderDetail> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("order_id", orderId); |
| | | queryWrapper.eq("price_type", "协议"); |
| | | queryWrapper.eq("deleted", 0); |
| | | |
| | | List<OrderDetail> agreementDetails = orderDetailMapper.selectList(queryWrapper); |
| | | |
| | | boolean hasAgreement = !CollectionUtils.isEmpty(agreementDetails); |
| | | log.info("检查订单协议类型,订单ID: {}, 是否包含协议类型: {}", orderId, hasAgreement); |
| | | |
| | | return hasAgreement; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean updateOrderDetailRemarksOnly(UpdateOrderDetailDTO.UpdateOrderDetailRemarksOnlyDTO updateOrderDetailDTO) { |
| | | // 参数校验 |
| | | if (updateOrderDetailDTO == null) { |
| | | throw new BusinessException("更新参数不能为空"); |
| | | } |
| | | if (!StringUtils.hasText(updateOrderDetailDTO.getOrderId())) { |
| | | throw new BusinessException("订单ID不能为空"); |
| | | } |
| | | if (CollectionUtils.isEmpty(updateOrderDetailDTO.getOrderDetails())) { |
| | | throw new BusinessException("订单详情列表不能为空"); |
| | | } |
| | | |
| | | // 查询订单信息(验证订单存在) |
| | | OrderInfo orderInfo = this.getById(updateOrderDetailDTO.getOrderId()); |
| | | if (orderInfo == null) { |
| | | throw new BusinessException("订单不存在"); |
| | | } |
| | | |
| | | // 只更新订单详情备注,不更新订单状态 |
| | | for (UpdateOrderDetailDTO.UpdateOrderDetailItemDTO itemDTO : updateOrderDetailDTO.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()); |
| | | } |
| | | } |
| | | |
| | | log.info("订单详情备注更新成功,订单ID: {}", updateOrderDetailDTO.getOrderId()); |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean deleteOrderAttachment(Long attachmentId) { |
| | | // 参数校验 |
| | | if (attachmentId == null) { |
| | | throw new BusinessException("附件ID不能为空"); |
| | | } |
| | | |
| | | log.info("开始删除订单附件,附件ID: {}", attachmentId); |
| | | |
| | | // 查询附件信息 |
| | | OrderAttachment attachment = orderAttachmentMapper.selectById(attachmentId); |
| | | if (attachment == null) { |
| | | log.error("附件不存在,附件ID: {}", attachmentId); |
| | | throw new BusinessException("附件不存在"); |
| | | } |
| | | |
| | | log.info("查询到附件信息: ID={}, 文件名={}, 对象名称={}, 当前删除状态={}", |
| | | attachment.getId(), attachment.getFileName(), attachment.getObjectName(), attachment.getDeleted()); |
| | | |
| | | try { |
| | | // 1. 删除MinIO中的文件 |
| | | if (StringUtils.hasText(attachment.getObjectName())) { |
| | | log.info("开始删除MinIO文件,对象名称: {}", attachment.getObjectName()); |
| | | minioService.deleteFile(attachment.getObjectName()); |
| | | log.info("MinIO文件删除成功,对象名称: {}", attachment.getObjectName()); |
| | | } else { |
| | | log.warn("附件对象名称为空,跳过MinIO文件删除"); |
| | | } |
| | | |
| | | // 2. 删除数据库中的附件记录(逻辑删除) |
| | | log.info("开始逻辑删除数据库记录,附件ID: {}", attachmentId); |
| | | |
| | | // 使用MyBatis-Plus的逻辑删除方法 |
| | | int result = orderAttachmentMapper.deleteById(attachmentId); |
| | | log.info("数据库逻辑删除结果: 影响行数={}", result); |
| | | |
| | | if (result > 0) { |
| | | log.info("订单附件删除成功,附件ID: {}, 文件名: {}", attachmentId, attachment.getFileName()); |
| | | return true; |
| | | } else { |
| | | log.error("数据库更新失败,影响行数为0,附件ID: {}", attachmentId); |
| | | throw new BusinessException("删除附件记录失败"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("删除订单附件失败,附件ID: {}", attachmentId, e); |
| | | throw new BusinessException("删除订单附件失败:" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean cancelOrder(String orderId) { |
| | | // 参数校验 |
| | | if (!StringUtils.hasText(orderId)) { |
| | | throw new BusinessException("订单ID不能为空"); |
| | | } |
| | | |
| | | log.info("开始取消订单,订单ID: {}", orderId); |
| | | |
| | | // 查询订单信息 |
| | | OrderInfo orderInfo = this.getById(orderId); |
| | | if (orderInfo == null) { |
| | | throw new BusinessException("订单不存在"); |
| | | } |
| | | |
| | | // 检查订单状态,只有"已完成"状态前的订单才能取消 |
| | | String currentStatus = orderInfo.getOrderStatus(); |
| | | if ("已完成".equals(currentStatus) || "已评价".equals(currentStatus)) { |
| | | throw new BusinessException("已完成或已评价的订单不能取消"); |
| | | } |
| | | |
| | | 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()); |
| | | // // 继续删除其他附件,不中断整个流程 |
| | | // } |
| | | // } |
| | | |
| | | // 2. 逻辑删除订单详情 |
| | | // 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); |
| | | |
| | | // 3. 删除订单信息(逻辑删除) |
| | | // 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); |
| | | throw new BusinessException("删除订单信息失败"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("取消订单失败,订单ID: {}", orderId, 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 void 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("工作流完成任务失败,返回数据为空"); |
| | | } |
| | | log.info("完成工作流任务成功,processinstId: {}", data.get("processinstId")); |
| | | } 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(); |
| | | } |
| | | } |
| | | } |