p-honggang.li
7 天以前 baac505052a5d9e63536eb7de32ba346d7e98ca7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
package com.webmanage.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.webmanage.common.BusinessException;
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实现类
 */
@Slf4j
@Service
public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo> implements OrderInfoService {
 
    @Resource
    private OrderDetailMapper orderDetailMapper;
 
    @Resource
    private OrderAttachmentMapper orderAttachmentMapper;
 
    @Resource
    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<OrderDetailVO> getBuyerOrderPage(OrderQueryDTO queryDTO) {
        // 参数校验
        if (queryDTO.getUserId() == null) {
            throw new BusinessException("用户ID不能为空");
        }
 
        // 创建分页对象
        Page<OrderInfo> page = new Page<>(queryDTO.getPageNum(), queryDTO.getPageSize());
 
        // 执行分页查询
        IPage<OrderInfo> result = baseMapper.selectBuyerOrderPage(
            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()
        );
        // 将订单与详情联表封装到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> getSellerOrderPage(OrderQueryDTO queryDTO) {
        // 参数校验
        if (queryDTO.getProviderId() == null) {
            throw new BusinessException("提供者ID不能为空");
        }
 
        // 创建分页对象
        Page<OrderInfo> page = new Page<>(queryDTO.getPageNum(), queryDTO.getPageSize());
 
        // 执行分页查询
        IPage<OrderInfo> result = baseMapper.selectSellerOrderPage(
            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()
        );
 
        // 将订单与详情联表封装到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> 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(
            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(), 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> 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
        );
        // 将订单与详情联表封装到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()) || 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
        );
 
        // 将订单与详情联表封装到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()) || 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
        );
 
        // 将订单与详情联表封装到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 OrderDetailVO getOrderDetail(String orderId) {
        // 参数校验
        if (!StringUtils.hasText(orderId)) {
            throw new BusinessException("订单ID不能为空");
        }
 
        // 查询订单基本信息
        OrderInfo orderInfo = this.getById(orderId);
        if (orderInfo == null) {
            throw new BusinessException("订单不存在");
        }
 
        // 构建订单详情VO
        OrderDetailVO orderDetailVO = new OrderDetailVO();
        BeanUtils.copyProperties(orderInfo, orderDetailVO);
 
        // 查询订单详情列表
        List<OrderDetail> orderDetails = orderDetailMapper.selectByOrderId(orderId);
        List<OrderDetailItemVO> orderDetailItemVOs = orderDetails.stream().map(detail -> {
            OrderDetailItemVO itemVO = new OrderDetailItemVO();
            BeanUtils.copyProperties(detail, itemVO);
            return itemVO;
        }).collect(Collectors.toList());
        orderDetailVO.setOrderDetails(orderDetailItemVOs);
 
        // 查询订单附件列表
        List<OrderAttachment> attachments = orderAttachmentMapper.selectByOrderId(orderId);
        List<OrderAttachmentVO> attachmentVOs = attachments.stream().map(attachment -> {
            OrderAttachmentVO attachmentVO = new OrderAttachmentVO();
            BeanUtils.copyProperties(attachment, attachmentVO);
            return attachmentVO;
        }).collect(Collectors.toList());
        orderDetailVO.setAttachments(attachmentVOs);
 
        // 查询订单评价
        OrderEvaluation evaluation = orderEvaluationMapper.selectByOrderId(orderId);
        if (evaluation != null) {
            OrderEvaluationVO evaluationVO = new OrderEvaluationVO();
            BeanUtils.copyProperties(evaluation, evaluationVO);
            orderDetailVO.setEvaluation(evaluationVO);
        }
 
        return orderDetailVO;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    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;
        for (CreateOrderItemDTO item : createOrderDTO.getItems()) {
            BigDecimal unitPrice = item.getUnitPrice();
            Integer quantity = item.getQuantity();
            if (unitPrice == null || quantity == null || quantity <= 0) {
                throw new BusinessException("明细项单价或数量不合法");
            }
            BigDecimal lineAmount = unitPrice.multiply(BigDecimal.valueOf(quantity));
            totalAmount = totalAmount.add(lineAmount);
        }
 
        // 保存订单头
        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setOrderId(orderId);
        orderInfo.setProductId(createOrderDTO.getItems().get(0).getProductId());
        orderInfo.setProductName(createOrderDTO.getProductName());
        orderInfo.setProviderId(createOrderDTO.getProviderId());
        orderInfo.setProviderName(createOrderDTO.getProviderName());
        orderInfo.setUserId(createOrderDTO.getUserId());
        orderInfo.setUnitId(createOrderDTO.getUnitId());
        orderInfo.setApplyTime(LocalDateTime.now());
        
        // 根据订单明细中是否包含协议价格类型来决定初始状态
        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());
 
        int inserted = this.baseMapper.insert(orderInfo);
        if (inserted <= 0) {
            throw new BusinessException("保存订单失败");
        }
 
        // 保存订单明细
        for (CreateOrderItemDTO item : createOrderDTO.getItems()) {
            OrderDetail detail = new OrderDetail();
            detail.setOrderId(orderId);
            detail.setPricingId(item.getPricingId());
            detail.setProductId(item.getProductId());
            detail.setSuiteName(item.getSuiteName());
            detail.setSalesForm(item.getSalesForm());
            detail.setCustomerType(item.getCustomerType());
            detail.setAccountLimit(item.getAccountLimit());
            detail.setConcurrentNodes(item.getConcurrentNodes());
            detail.setPriceType(item.getPriceType());
            detail.setPriceUnit(item.getPriceUnit());
            detail.setUnitPrice(item.getUnitPrice());
            detail.setQuantity(item.getQuantity());
            detail.setDuration(item.getDuration());
            BigDecimal lineAmount = item.getUnitPrice().multiply(BigDecimal.valueOf(item.getQuantity()));
            detail.setTotalPrice(item.getTotalPrice() != null ? item.getTotalPrice() : lineAmount);
            detail.setProviderId(item.getProviderId());
            detail.setProviderName(item.getProviderName());
            detail.setRemarks(item.getRemarks());
            detail.setCreatedAt(LocalDateTime.now());
            detail.setUpdatedAt(LocalDateTime.now());
            orderDetailMapper.insert(detail);
        }
 
        return orderInfo;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long uploadOrderAttachment(String orderId, String fileName, String originalName, 
                                    String fileType, Long fileSize, String fileUrl, 
                                    String bucketName, String objectName, Long uploadUserId, 
                                    String uploadUserName, String attachmentType, String description) {
        // 参数校验
        if (!StringUtils.hasText(orderId)) {
            throw new BusinessException("订单ID不能为空");
        }
        if (!StringUtils.hasText(fileName)) {
            throw new BusinessException("文件名不能为空");
        }
 
        // 检查订单是否存在
        OrderInfo orderInfo = this.getById(orderId);
        if (orderInfo == null) {
            throw new BusinessException("订单不存在");
        }
 
        // 创建订单附件
        OrderAttachment attachment = new OrderAttachment();
        attachment.setOrderId(orderId);
        attachment.setFileName(fileName);
        attachment.setOriginalName(originalName);
        attachment.setFileType(fileType);
        attachment.setFileSize(fileSize);
        attachment.setFileUrl(fileUrl);
        attachment.setBucketName(bucketName);
        attachment.setObjectName(objectName);
        attachment.setUploadUserId(uploadUserId);
        attachment.setUploadUserName(uploadUserName);
        attachment.setAttachmentType(attachmentType);
        attachment.setDescription(description);
 
        // 保存附件并返回附件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, 
                                   String evaluatorType, String content, Integer rating, 
                                   Integer serviceRating, Integer qualityRating, Integer deliveryRating, 
                                   Boolean isAnonymous) {
        // 参数校验
        if (!StringUtils.hasText(orderId)) {
            throw new BusinessException("订单ID不能为空");
        }
        if (evaluatorId == null) {
            throw new BusinessException("评价人ID不能为空");
        }
        if (!StringUtils.hasText(content)) {
            throw new BusinessException("评价内容不能为空");
        }
        if (rating == null || rating < 1 || rating > 5) {
            throw new BusinessException("评分必须在1-5之间");
        }
 
        // 检查订单是否存在
        OrderInfo orderInfo = this.getById(orderId);
        if (orderInfo == null) {
            throw new BusinessException("订单不存在");
        }
 
        // 检查是否已经评价过
        OrderEvaluation existingEvaluation = orderEvaluationMapper.selectByOrderId(orderId);
        if (existingEvaluation != null) {
            throw new BusinessException("该订单已经评价过了");
        }
 
        // 创建订单评价
        OrderEvaluation evaluation = new OrderEvaluation();
        evaluation.setOrderId(orderId);
        evaluation.setEvaluatorId(evaluatorId);
        evaluation.setEvaluatorName(evaluatorName);
        evaluation.setEvaluatorType(evaluatorType);
        evaluation.setContent(content);
        evaluation.setRating(rating);
        evaluation.setServiceRating(serviceRating);
        evaluation.setQualityRating(qualityRating);
        evaluation.setDeliveryRating(deliveryRating);
        evaluation.setIsAnonymous(isAnonymous != null ? isAnonymous : false);
 
        // 保存评价
        return orderEvaluationMapper.insert(evaluation) > 0;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean confirmTransaction(String orderId, Long userId) {
        // 参数校验
        if (!StringUtils.hasText(orderId)) {
            throw new BusinessException("订单ID不能为空");
        }
        if (userId == null) {
            throw new BusinessException("用户ID不能为空");
        }
 
        // 查询订单信息
        OrderInfo orderInfo = this.getById(orderId);
        if (orderInfo == null) {
            throw new BusinessException("订单不存在");
        }
 
        // 检查订单状态
        if (!"待交易确认".equals(orderInfo.getOrderStatus())) {
            throw new BusinessException("订单状态不正确,无法确认交易");
        }
 
        // 检查用户权限
        if (!userId.equals(orderInfo.getUserId())) {
            throw new BusinessException("无权限操作此订单");
        }
 
        // 更新订单状态
        orderInfo.setOrderStatus("已完成");
        orderInfo.setUpdatedAt(LocalDateTime.now());
 
        // 如果是积分交易,需要扣除积分
        if ("积分".equals(orderInfo.getPaymentType())) {
            // TODO: 实现积分扣除逻辑
            log.info("积分交易确认,订单ID: {}, 需要扣除积分", orderId);
        }
 
        // 保存订单
        return this.updateById(orderInfo);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean replyEvaluation(Long evaluationId, String replyContent, Long replyUserId) {
        // 参数校验
        if (evaluationId == null) {
            throw new BusinessException("评价ID不能为空");
        }
        if (!StringUtils.hasText(replyContent)) {
            throw new BusinessException("回复内容不能为空");
        }
        if (replyUserId == null) {
            throw new BusinessException("回复用户ID不能为空");
        }
 
        // 查询评价信息
        OrderEvaluation evaluation = orderEvaluationMapper.selectById(evaluationId);
        if (evaluation == null) {
            throw new BusinessException("评价不存在");
        }
 
        // 更新回复信息
        evaluation.setReplyContent(replyContent);
        evaluation.setReplyUserId(replyUserId);
        evaluation.setReplyTime(LocalDateTime.now());
        evaluation.setUpdatedAt(LocalDateTime.now());
 
        // 保存评价
        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()), comment);
        } else {
            completeWorkflowTask(orderApprovalDTO.getTaskId(), String.valueOf(orderApprovalDTO.getApproverId()), comment);
        }
 
        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);
 
            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();
        }
    }
}