From baac505052a5d9e63536eb7de32ba346d7e98ca7 Mon Sep 17 00:00:00 2001
From: p-honggang.li <p-honggang.li@pcitc.com>
Date: 星期六, 06 九月 2025 10:44:03 +0800
Subject: [PATCH] 修改审核订单查询获取正确taskid的问题

---
 src/main/java/com/webmanage/service/impl/OrderInfoServiceImpl.java | 1267 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 1,245 insertions(+), 22 deletions(-)

diff --git a/src/main/java/com/webmanage/service/impl/OrderInfoServiceImpl.java b/src/main/java/com/webmanage/service/impl/OrderInfoServiceImpl.java
index 92a9b54..b12d62b 100644
--- a/src/main/java/com/webmanage/service/impl/OrderInfoServiceImpl.java
+++ b/src/main/java/com/webmanage/service/impl/OrderInfoServiceImpl.java
@@ -8,33 +8,53 @@
 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瀹炵幇绫�
@@ -53,10 +73,25 @@
     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涓嶈兘涓虹┖");
@@ -76,10 +111,23 @@
             queryDTO.getCreateTimeEnd() != null ? queryDTO.getCreateTimeEnd().toString() : null,
             queryDTO.getOrderBy(), queryDTO.getOrderDirection()
         );
+        // 灏嗚鍗曚笌璇︽儏鑱旇〃灏佽鍒癡O
+        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(),
@@ -88,10 +136,10 @@
     }
 
     @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("鎻愪緵鑰匢D涓嶈兘涓虹┖");
         }
 
         // 鍒涘缓鍒嗛〉瀵硅薄
@@ -99,7 +147,7 @@
 
         // 鎵ц鍒嗛〉鏌ヨ
         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,
@@ -108,9 +156,23 @@
             queryDTO.getOrderBy(), queryDTO.getOrderDirection()
         );
 
+        // 灏嗚鍗曚笌璇︽儏鑱旇〃灏佽鍒癡O
+        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(),
@@ -119,9 +181,42 @@
     }
 
     @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(
@@ -129,12 +224,252 @@
             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
         );
 
+        // 灏嗚鍗曚笌璇︽儏鑱旇〃灏佽鍒癡O
+        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()) || StringUtils.hasText(queryDTO.getUnitProjectId()) ||
+            StringUtils.hasText(queryDTO.getProductTypeId()) || StringUtils.hasText(queryDTO.getProductSubTypeId())) {
+            productIds = reportResultSubmissionMapper.selectProductIdsByConditions(
+                queryDTO.getIndustryId(), queryDTO.getUnitProjectId(), 
+                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
+        );
+        // 灏嗚鍗曚笌璇︽儏鑱旇〃灏佽鍒癡O
+        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()) || StringUtils.hasText(queryDTO.getUnitProjectId()) ||
+            StringUtils.hasText(queryDTO.getProductTypeId()) || StringUtils.hasText(queryDTO.getProductSubTypeId())) {
+            productIds = reportResultSubmissionMapper.selectProductIdsByConditions(
+                queryDTO.getIndustryId(), queryDTO.getUnitProjectId(), 
+                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
+        );
+
+        // 灏嗚鍗曚笌璇︽儏鑱旇〃灏佽鍒癡O
+        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("鎻愪緵鑰匢D涓嶈兘涓虹┖");
+        }
+
+        // 鏍规嵁浜у搧鏉′欢鏌ヨ浜у搧ID鍒楄〃
+        List<String> productIds = null;
+        if (StringUtils.hasText(queryDTO.getIndustryId()) || StringUtils.hasText(queryDTO.getUnitProjectId()) ||
+            StringUtils.hasText(queryDTO.getProductTypeId()) || StringUtils.hasText(queryDTO.getProductSubTypeId())) {
+            productIds = reportResultSubmissionMapper.selectProductIdsByConditions(
+                queryDTO.getIndustryId(), queryDTO.getUnitProjectId(), 
+                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
+        );
+
+        // 灏嗚鍗曚笌璇︽儏鑱旇〃灏佽鍒癡O
+        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(),
@@ -190,12 +525,40 @@
 
     @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("璋冪敤宸ヤ綔娴佹帴鍙eけ璐ワ紝璁㈠崟ID: {}", orderId, e);
+            // 宸ヤ綔娴佽皟鐢ㄥけ璐ワ紝鎶涘嚭寮傚父瑙﹀彂浜嬪姟鍥炴粴
+            throw new BusinessException("宸ヤ綔娴佽皟鐢ㄥけ璐�: " + e.getMessage());
+        }
 
         // 璁$畻鎬婚噾棰�
         BigDecimal totalAmount = BigDecimal.ZERO;
@@ -219,11 +582,18 @@
         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); // 璁剧疆宸ヤ綔娴両D
+        orderInfo.setTaskId(taskId);
         orderInfo.setCreatedAt(LocalDateTime.now());
         orderInfo.setUpdatedAt(LocalDateTime.now());
 
@@ -258,15 +628,15 @@
             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, Long uploadUserId, 
+                                    String uploadUserName, String attachmentType, String description) {
         // 鍙傛暟鏍¢獙
         if (!StringUtils.hasText(orderId)) {
             throw new BusinessException("璁㈠崟ID涓嶈兘涓虹┖");
@@ -296,8 +666,13 @@
         attachment.setAttachmentType(attachmentType);
         attachment.setDescription(description);
 
-        // 淇濆瓨闄勪欢
-        return orderAttachmentMapper.insert(attachment) > 0;
+        // 淇濆瓨闄勪欢骞惰繑鍥為檮浠禝D
+        int result = orderAttachmentMapper.insert(attachment);
+        if (result > 0) {
+            return attachment.getId();
+        } else {
+            throw new BusinessException("淇濆瓨闄勪欢澶辫触");
+        }
     }
 
     @Override
@@ -419,4 +794,852 @@
         // 淇濆瓨璇勪环
         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("鏇存柊璁㈠崟璇︽儏澶辫触锛孖D: {}", 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("瀹℃壒浜篒D涓嶈兘涓虹┖");
+        }
+        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("璁㈠崟鐘舵�佷笉姝g‘锛屽綋鍓嶇姸鎬佷负锛�" + 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("鏂囦欢鏍告煡瀹屾垚锛岃鍗旾D: {}, 瀹℃壒缁撴灉: {}, 瀹℃壒浜�: {}, 瀹℃壒鎰忚: {}", 
+                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("瀹℃壒浜篒D涓嶈兘涓虹┖");
+        }
+        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("鏇存柊璁㈠崟璇︽儏澶辫触锛孖D: {}", 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()), comment);
+        } else {
+            completeWorkflowTask(orderApprovalDTO.getTaskId(), String.valueOf(orderApprovalDTO.getApproverId()), comment);
+        }
+
+        log.info("瀹℃壒璁板綍娣诲姞鎴愬姛锛岃鍗旾D: {}, 瀹℃壒绫诲瀷: {}, 瀹℃壒缁撴灉: {}, 瀹℃壒浜�: {}, 瀹℃壒鎰忚: {}", 
+                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("鏇存柊璁㈠崟璇︽儏澶辫触锛孖D: {}", itemDTO.getId());
+            }
+        }
+
+        log.info("璁㈠崟璇︽儏澶囨敞鏇存柊鎴愬姛锛岃鍗旾D: {}", 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("寮�濮嬪垹闄inIO鏂囦欢锛屽璞″悕绉�: {}", attachment.getObjectName());
+                minioService.deleteFile(attachment.getObjectName());
+                log.info("MinIO鏂囦欢鍒犻櫎鎴愬姛锛屽璞″悕绉�: {}", attachment.getObjectName());
+            } else {
+                log.warn("闄勪欢瀵硅薄鍚嶇О涓虹┖锛岃烦杩嘙inIO鏂囦欢鍒犻櫎");
+            }
+
+            // 2. 鍒犻櫎鏁版嵁搴撲腑鐨勯檮浠惰褰曪紙閫昏緫鍒犻櫎锛�
+            log.info("寮�濮嬮�昏緫鍒犻櫎鏁版嵁搴撹褰曪紝闄勪欢ID: {}", attachmentId);
+            
+            // 浣跨敤MyBatis-Plus鐨勯�昏緫鍒犻櫎鏂规硶
+            int result = orderAttachmentMapper.deleteById(attachmentId);
+            log.info("鏁版嵁搴撻�昏緫鍒犻櫎缁撴灉: 褰卞搷琛屾暟={}", result);
+            
+            if (result > 0) {
+                log.info("璁㈠崟闄勪欢鍒犻櫎鎴愬姛锛岄檮浠禝D: {}, 鏂囦欢鍚�: {}", attachmentId, attachment.getFileName());
+                return true;
+            } else {
+                log.error("鏁版嵁搴撴洿鏂板け璐ワ紝褰卞搷琛屾暟涓�0锛岄檮浠禝D: {}", attachmentId);
+                throw new BusinessException("鍒犻櫎闄勪欢璁板綍澶辫触");
+            }
+        } catch (Exception e) {
+            log.error("鍒犻櫎璁㈠崟闄勪欢澶辫触锛岄檮浠禝D: {}", 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. 鍒犻櫎璁㈠崟闄勪欢锛堝寘鎷琈inIO鏂囦欢鍜屾暟鎹簱璁板綍锛�
+            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("鍒犻櫎闄勪欢璁板綍鎴愬姛锛岄檮浠禝D: {}", attachment.getId());
+                } catch (Exception e) {
+                    log.error("鍒犻櫎闄勪欢澶辫触锛岄檮浠禝D: {}, 閿欒: {}", attachment.getId(), e.getMessage());
+                    // 缁х画鍒犻櫎鍏朵粬闄勪欢锛屼笉涓柇鏁翠釜娴佺▼
+                }
+            }
+
+            // 2. 閫昏緫鍒犻櫎璁㈠崟璇︽儏
+            log.info("寮�濮嬮�昏緫鍒犻櫎璁㈠崟璇︽儏锛岃鍗旾D: {}", 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);
+
+            if (orderDeleted > 0) {
+                log.info("璁㈠崟鍙栨秷鎴愬姛锛岃鍗旾D: {}", orderId);
+                return true;
+            } else {
+                log.error("鍒犻櫎璁㈠崟淇℃伅澶辫触锛屽奖鍝嶈鏁颁负0锛岃鍗旾D: {}", orderId);
+                throw new BusinessException("鍒犻櫎璁㈠崟淇℃伅澶辫触");
+            }
+        } catch (Exception e) {
+            log.error("鍙栨秷璁㈠崟澶辫触锛岃鍗旾D: {}", 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("宸ヤ綔娴両D涓嶈兘涓虹┖");
+        }
+
+        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());
+            
+            // 鍙戦�丳OST璇锋眰
+            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);
+            
+            // 鍙戦�丳OST璇锋眰
+            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け璐�", 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("宸ヤ綔娴佸畬鎴愪换鍔℃帴鍙h皟鐢ㄥけ璐ワ紝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("宸ヤ綔娴侀┏鍥炰换鍔℃帴鍙h皟鐢ㄥけ璐ワ紝HTTP鐘舵��: " + response.getStatusCode());
+            }
+        } catch (Exception e) {
+            log.error("椹冲洖宸ヤ綔娴佸け璐�", e);
+            throw new BusinessException("椹冲洖宸ヤ綔娴佸け璐�: " + e.getMessage());
+        }
+    }
+
+    /**
+     * 鎸夌収workFlowType鏌ヨ娴佺▼瀹炰緥ID闆嗗悎
+     * workFlowType: 0=浠e姙锛�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) {
+                // 浠e姙
+                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("鏌ヨ宸ヤ綔娴佸疄渚婭D澶辫触", e);
+            return java.util.Collections.emptyList();
+        }
+    }
 }

--
Gitblit v1.8.0