廖井涛
2025-05-09 c3fe22add66737e4ccd57299aa9eff02e47343b7
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
 
package com.example.erp.service.pp;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.erp.common.Constants;
import com.example.erp.entity.pp.FlowCard;
import com.example.erp.entity.sd.OrderDetail;
import com.example.erp.entity.sd.OrderGlassDetail;
import com.example.erp.entity.sd.OrderProcessDetail;
import com.example.erp.entity.userInfo.Log;
import com.example.erp.exception.ServiceException;
import com.example.erp.mapper.pp.FlowCardMapper;
import com.example.erp.mapper.sd.OrderGlassDetailMapper;
import com.example.erp.mapper.sd.OrderProcessDetailMapper;
import com.example.erp.service.userInfo.LogService;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Service;
 
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
 
import com.fasterxml.jackson.core.type.TypeReference;
import java.io.IOException;
 
 
import java.sql.Date;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
 
import static com.example.erp.service.sd.OrderService.getOrderProcessDetails;
 
@Service
@DS("pp")
public class FlowCardService {
    final
    FlowCardMapper flowCardMapper;
    final
    OrderGlassDetailMapper orderGlassDetailMapper;
    final
    OrderProcessDetailMapper orderProcessDetailMapper;
    final
    LogService logService;
 
    public FlowCardService(FlowCardMapper flowCardMapper, OrderGlassDetailMapper orderGlassDetailMapper, OrderProcessDetailMapper orderProcessDetailMapper, LogService logService) {
        this.flowCardMapper = flowCardMapper;
        this.orderGlassDetailMapper = orderGlassDetailMapper;
        this.orderProcessDetailMapper = orderProcessDetailMapper;
        this.logService = logService;
    }
 
    //流程卡管理查询
    public Map<String, Object> selectProcessCard(Integer pageNum, Integer pageSize,List<String> selectDate, FlowCard flowCard) {
        Integer offset = (pageNum - 1) * pageSize;
        String endDate = LocalDate.now().toString();
        String startDate = LocalDate.now().minusDays(15).toString();
        if(selectDate !=null && selectDate.size()==2){
            if(!selectDate.get(0).isEmpty()){
                startDate = selectDate.get(0);
            }
            if(!selectDate.get(1).isEmpty()){
                endDate = selectDate.get(1);
            }
        }
        Map<String, Object> map = new HashMap<>();
        map.put("data", flowCardMapper.selectFlowCard(offset, pageSize, startDate, endDate, flowCard));
        map.put("total", flowCardMapper.getPageTotal(offset, pageSize, startDate, endDate, flowCard));
        List<String> list = new ArrayList<>();
        list.add(startDate);
        list.add(endDate);
        map.put("selectDate",list);
        return map;
    }
 
    //分架查询
    public Map<String, Object> selectAddProcess(Date selectTime1, Date selectTime2, FlowCard flowCard) {
        Map<String, Object> map = new HashMap<>();
        map.put("data", flowCardMapper.selectFlowCardMp(selectTime1, selectTime2, flowCard));
        return map;
    }
 
    //分架明细查询
    public Map<String, Object> detailsSelectSv(String orderId, FlowCard flowCard) {
        Map<String, Object> map = new HashMap<>();
        map.put("data", flowCardMapper.detailsSelectMp(orderId, flowCard));
        return map;
    }
 
    //删除流程卡
    public Boolean deleteFlowCardSv(String orderId, String processId, String userId, String userName) {
        if (!orderId.isEmpty() && !processId.isEmpty()) {
            //判断该流程卡是否报工
            Integer count = flowCardMapper.reportingWorkCount(processId);
            if (count == 0) {
 
                //修改分架状态
                flowCardMapper.updateDeleteState(orderId, processId);
                //删除报工流程明细表数据
                flowCardMapper.deleteReportingWork(processId);
                //删除分架明细
                flowCardMapper.deleteFlowCardMp(orderId, processId);
                //删除排序表数据
                flowCardMapper.deleteflowCardSort(orderId, processId);
                //判断该订单流程卡是否全部删除
                Integer flowNumber = flowCardMapper.selectFlowCardCount(orderId);
                if (flowNumber == 0) {
                    //修改订单表分架状态为0,全部删除
                    flowCardMapper.updateProcessingCard(orderId, 0);
                } else {
                    //修改订单表分架状态为1,删除部分
                    flowCardMapper.updateProcessingCard(orderId, 1);
                }
 
                //保存日志
                Log log = new Log();
                log.setContent(orderId + processId);
                log.setFunction("deleteFlowCardSv流程卡删除");
                log.setOperatorId(userId);
                log.setOperator(userName);
                logService.saveLog(log);
                return true;
            } else {
                return false;
            }
 
        } else {
            return false;
        }
    }
 
    //分架新增明细查询
    public Map<String, Object> selectNoCardSv(String orderId, String productionId, FlowCard flowCard) {
        Map<String, Object> map = new HashMap<>();
        map.put("data", flowCardMapper.selectNoCardMp(orderId, productionId, flowCard));
        map.put("maxFlowCard", flowCardMapper.selectMaxFlowCard(orderId, productionId));
        map.put("orderOtherMoney", flowCardMapper.selectorderOtherMoney());
        return map;
    }
 
 
    //修改排版状态
    public Boolean updateLayoutStatusSv(String processId, Integer state) {
 
        if (!processId.isEmpty()) {
            flowCardMapper.updateLayoutStatusMp(processId, state);
            return true;
        } else {
            return false;
        }
    }
 
    //保存流程卡数据
    public Boolean addFlowCardSv(String orderId, Map<String, Object> object) {
        String userName = "";
        if (object.get("userName") != null) {
            userName = object.get("userName").toString();
        }
        String productionId = "";
        if (object.get("productionId") != null) {
            productionId = object.get("productionId").toString();
        }
 
        List<FlowCard> FlowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("flowCard")), FlowCard.class);
        if (!FlowCardList.isEmpty()) {
            for (FlowCard flowCard : FlowCardList) {
                //查询每个序号的层数
                Integer layer = flowCardMapper.selectLayer(productionId, flowCard.getOrderNumber());
                //添加流程卡数据
                flowCardMapper.addFlowCardMp(flowCard.getProcessId(), flowCard.getOrderNumber(), flowCard.getLandingSequence(), flowCard.getQuantity(), productionId, userName, layer);
                //修改分架状态,将状态改为1
                flowCardMapper.updateFlowState(productionId, flowCard.getOrderNumber());
                //查询该订单未分架数量
                Integer FlowCount = flowCardMapper.selectFlowCount(orderId);
                if (FlowCount == 0) {
                    //修改订单表分架状态为2
                    flowCardMapper.updateProcessingCard(orderId, 2);
                } else {
                    //修改订单表分架状态为1,未全部分架完成
                    flowCardMapper.updateProcessingCard(orderId, 1);
                }
                //查询订单小片表获取工艺传入小片工艺表
                List<OrderGlassDetail> orderGlassDetailList =
                        orderGlassDetailMapper.selectList(
                                new QueryWrapper<OrderGlassDetail>()
                                        .eq("order_id", orderId)
                                        .eq("order_number", flowCard.getOrderNumber())
                        );
                List<OrderProcessDetail> orderProcessDetailList = getOrderProcessDetails(orderGlassDetailList);
                orderProcessDetailList.forEach(
                        orderGlassDetail -> orderGlassDetail.setProcessId(flowCard.getProcessId()));
 
                //赋值订单工艺表
                orderProcessDetailMapper.insertOrderProcessDetail(orderProcessDetailList);
            }
            //保存日志
            Log log = new Log();
            log.setContent(object.toString());
            log.setFunction("addFlowCardSv流程卡新增");
            log.setOperatorId((String) object.get("userId"));
            log.setOperator((String) object.get("userName"));
            logService.saveLog(log);
            return true;
        } else {
            return false;
        }
    }
 
    public Map<String, Object> selectSchedulingSv(String selectTime1, String selectTime2, String orderId, String processes, Integer state, FlowCard flowCard) {
        Map<String, Object> map = new HashMap<>();
        if (state == 2) {//已排产
            map.put("data", flowCardMapper.selectOkSchedulingMp(selectTime1, selectTime2, orderId, processes, flowCard));
 
        } else if (state == 1) {//未排产
            map.put("data", flowCardMapper.selectNoSchedulingMp(selectTime1, selectTime2, orderId, processes, flowCard));
 
        }
        return map;
    }
 
 
    //首次查询排版数据
    public Map<String, Object> selectLastScheduling(String selectTime1, String selectTime2, FlowCard flowCard) {
        Map<String, Object> map = new HashMap<>();
        map.put("data", flowCardMapper.selectLastSchedulingMp(selectTime1, selectTime2, flowCard));
        return map;
    }
 
    public Object flowCardDetailSv(String processId, FlowCard flowCard) {
        Map<String, Object> map = new HashMap<>();
        map.put("data", flowCardMapper.flowCardDetailMp(processId, flowCard));
        map.put("merge", flowCardMapper.flowCardDetailMergeMp(processId));
        return map;
    }
 
    public Object selectPrintFlowCardSv(Date selectTime1, Date selectTime2, String orderId, String project, String userId, Integer state, FlowCard flowCard) {
        if ("null".equals(orderId)) {
            orderId = "";
        }
        if ("null".equals(project)) {
            project = "";
        }
        Map<String, Object> map = new HashMap<>();
        map.put("data", flowCardMapper.selectPrintFlowCardMp(selectTime1, selectTime2, orderId, project,state, flowCard));
        String roleId = flowCardMapper.selectUserMp(userId);
        map.put("user", roleId);
        return map;
    }
 
    public Object selectPrintFlowCard(Date selectTime1, Date selectTime2) {
        Map<String, Object> map = new HashMap<>();
        map.put("data", flowCardMapper.selectPrintFlowCard(selectTime1, selectTime2));
        return map;
    }
 
    public Object selectPrintSv(Map<String, Object> object, String inquiryMode) {
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();//最终结果
        List<FlowCard> flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("printList")), FlowCard.class);
        if (!flowCardList.isEmpty()) {
            for (FlowCard flowCard : flowCardList) {
                Map<String, Object> itemmap = new HashMap<>();
                if ("1".equals(inquiryMode)) {//合并流程卡
                    itemmap.put("detail", flowCardMapper.selectPrintMp(flowCard.getOrderId()));
                } else if ("3".equals(inquiryMode)) {//合并流程卡不按配置显示
                    itemmap.put("detail", flowCardMapper.selectPrintAllMp(flowCard.getOrderId()));
                } else {//非合并流程卡
                    itemmap.put("detail", flowCardMapper.selectPrintNotMp(flowCard.getOrderId()));
                }
 
                list.add(itemmap);
            }
        }
        map.put("data", list);
        map.put("type", flowCardMapper.selectType());
        return map;
    }
 
    private static Map<String, Object> parseJson(String json) {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            return objectMapper.readValue(json, new TypeReference<Map<String, Object>>() {
            });
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
 
    public Map<String, Object> getSelectPrintingSv(Map<String, Object> object, String printMerge, String printLike, String merge) {
        if (printMerge == null) {
            printMerge = "";
        }
        if (printLike == null) {
            printLike = "";
        }
        if (merge == null) {
            merge = "";
        }
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();//最终结果
        List<FlowCard> flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("printList")), FlowCard.class);
        if (!flowCardList.isEmpty()) {
            Set<String> processedProcessIds = new HashSet<>();  // 用来存放已处理过的 processId
            for (FlowCard flowCard : flowCardList) {
                Map<String, Object> itemmap = new HashMap<>();
                //流程卡表头表尾数据
                //是否传入合并层数
                if (printMerge.equals("") || printMerge.equals("null")) {
                    //是否包含切割
                    //boolean containsCutting = flowCard.getProcess().contains("切割");
                    String processSub = flowCard.getProcess().substring(0, 2);
                    if (processSub.equals("夹胶") || processSub.equals("中空")) {//工艺是否包含夹胶中空
                        itemmap.put("detail", flowCardMapper.getPrimaryListLimt(flowCard.getProcessId(), String.valueOf(flowCard.getTechnologyNumber()), flowCard.getGlassChild(), flowCard.getProcess(), flowCard.getOrderId()));
 
                        List<Map<String, Object>> detailList = flowCardMapper.getDetailList(flowCard.getProcessId(), flowCard.getTechnologyNumber(), flowCard.getProcess());
                        itemmap.put("detailList", detailList);
                    } else {
                        if (merge.equals("1") && flowCard.getMerge().equals(1)) {
                            // 检查是否已经处理过该 processId,如果处理过则跳过
                            if (processedProcessIds.contains(flowCard.getProcessId())) {
                                continue;
                            }
                            // 将该 processId 加入已处理集合
                            processedProcessIds.add(flowCard.getProcessId());
                            itemmap.put("detail", flowCardMapper.getPrimaryList(flowCard.getProcessId(), String.valueOf(flowCard.getTechnologyNumber()), flowCard.getGlassChild(), flowCard.getProcess(), flowCard.getOrderId()));
 
                            List<Map<String, Object>> detailList = flowCardMapper.getDetailListMerge(flowCard.getProcessId(), flowCard.getProcess());
                            itemmap.put("detailList", detailList);
                        } else {
                            itemmap.put("detail", flowCardMapper.getPrimaryList(flowCard.getProcessId(), String.valueOf(flowCard.getTechnologyNumber()), flowCard.getGlassChild(), flowCard.getProcess(), flowCard.getOrderId()));
 
                            List<Map<String, Object>> detailList = flowCardMapper.getDetailListLike(flowCard.getProcessId(), String.valueOf(flowCard.getTechnologyNumber()), flowCard.getProcess());
                            itemmap.put("detailList", detailList);
                        }
 
                    }
 
                } else {
                    //流程卡明细数据
                    if (printLike.equals("") || printLike.equals("null")) {
                        itemmap.put("detail", flowCardMapper.getPrimaryListMerge(flowCard.getProcessId(), printMerge, flowCard.getOrderId()));
 
                        List<Map<String, Object>> detailList = flowCardMapper.getDetailList(flowCard.getProcessId(), flowCard.getTechnologyNumber(), flowCard.getProcess());
                        itemmap.put("detailList", detailList);
                    } else {
                        itemmap.put("detail", flowCardMapper.getPrimaryList(flowCard.getProcessId(), String.valueOf(flowCard.getTechnologyNumber()), flowCard.getGlassChild(), flowCard.getProcess(), flowCard.getOrderId()));
 
                        List<Map<String, Object>> detailList = flowCardMapper.getDetailListLike(flowCard.getProcessId(), printMerge, flowCard.getProcess());
                        itemmap.put("detailList", detailList);
                    }
                }
 
                //工艺流程
                //List<Map<String, Object>> processList = flowCardMapper.getProcessList(flowCard.getProcessId(), flowCard.getTechnologyNumber());
                String input = flowCard.getProcess();
                String delimiter = "->";
 
                // 分割字符串
                String[] parts = input.split(delimiter);
 
                // 创建 List<Map<String, Object>>
                List<Map<String, Object>> processList = new ArrayList<>();
 
                // 遍历分割后的部分并将其存入 List<Map<String, Object>>
                for (int i = 0; i < parts.length; i++) {
                    Map<String, Object> maps = new HashMap<>();
                    maps.put("id", i); // 添加一个索引字段
                    maps.put("process", parts[i]); // 添加实际的值
 
                    processList.add(maps);
                }
 
                itemmap.put("processList", processList);
                //  itemmap.put("numberList", numberList);
                itemmap.put("count", flowCardMapper.countFlowCard(flowCard.getOrderId()));
                itemmap.put("remarkList", flowCardMapper.remakList(flowCard.getProcessId()));
                list.add(itemmap);
 
            }
        }
 
        map.put("data", list);
        //初始化值
        printLike = null;
        return map;
    }
 
    public Map<String, Object> getSelectPrintProject(String printProject, String merge) {
 
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();//最终结果
        if (merge == null) {
            merge = "";
        }
        List<FlowCard> flowCardList = flowCardMapper.getFlowCardListPrintProject(printProject);
        if (!flowCardList.isEmpty()) {
            Set<String> processedProcessIds = new HashSet<>();  // 用来存放已处理过的 processId
            for (FlowCard flowCard : flowCardList) {
                Map<String, Object> itemmap = new HashMap<>();
 
 
                //是否包含切割
                //boolean containsCutting = flowCard.getProcess().contains("切割");
                String processSub = flowCard.getProcess().substring(0, 2);
                if (processSub.equals("夹胶") || processSub.equals("中空")) {
                    itemmap.put("detail", flowCardMapper.getPrimaryListLimt(flowCard.getProcessId(), String.valueOf(flowCard.getTechnologyNumber()), flowCard.getGlassChild(), flowCard.getProcess(), flowCard.getOrderId()));
                    if (flowCard.getPatchState().equals(0)) {
                        List<Map<String, Object>> detailList = flowCardMapper.getDetailList(flowCard.getProcessId(), flowCard.getTechnologyNumber(), flowCard.getProcess());
                        itemmap.put("detailList", detailList);
                    } else {
                        List<Map<String, Object>> detailList = flowCardMapper.getDetailLists(flowCard.getProcessId(), flowCard.getTechnologyNumber(), flowCard.getProcess(), flowCard.getOrderNumber());
                        itemmap.put("detailList", detailList);
                    }
 
                } else {
 
                    if (flowCard.getPatchState().equals(0)) {
                        if (merge.equals("1") && flowCard.getMerge().equals(1)) {
                            // 检查是否已经处理过该 processId,如果处理过则跳过
                            if (processedProcessIds.contains(flowCard.getProcessId())) {
                                continue;
                            }
                            // 将该 processId 加入已处理集合
                            processedProcessIds.add(flowCard.getProcessId());
                            itemmap.put("detail", flowCardMapper.getPrimaryList(flowCard.getProcessId(), String.valueOf(flowCard.getTechnologyNumber()), flowCard.getGlassChild(), flowCard.getProcess(), flowCard.getOrderId()));
 
                            List<Map<String, Object>> detailList = flowCardMapper.getDetailListMerge(flowCard.getProcessId(), flowCard.getProcess());
                            itemmap.put("detailList", detailList);
                        } else {
                            itemmap.put("detail", flowCardMapper.getPrimaryList(flowCard.getProcessId(), String.valueOf(flowCard.getTechnologyNumber()), flowCard.getGlassChild(), flowCard.getProcess(), flowCard.getOrderId()));
                            List<Map<String, Object>> detailList = flowCardMapper.getDetailListLike(flowCard.getProcessId(), String.valueOf(flowCard.getTechnologyNumber()), flowCard.getProcess());
                            itemmap.put("detailList", detailList);
                        }
 
                    } else {
                        itemmap.put("detail", flowCardMapper.getPrimaryLists(flowCard.getProcessId(), String.valueOf(flowCard.getTechnologyNumber()), flowCard.getGlassChild(), flowCard.getProcess(), flowCard.getOrderId(), flowCard.getQuantity()));
                        List<Map<String, Object>> detailList = flowCardMapper.getDetailListLikes(flowCard.getProcessId(), String.valueOf(flowCard.getTechnologyNumber()), flowCard.getProcess(), printProject, flowCard.getQuantity());
                        itemmap.put("detailList", detailList);
                    }
 
 
                }
 
 
                //工艺流程
                //List<Map<String, Object>> processList = flowCardMapper.getProcessList(flowCard.getProcessId(), flowCard.getTechnologyNumber());
                String input = flowCard.getProcess();
                String delimiter = "->";
 
                // 分割字符串
                String[] parts = input.split(delimiter);
 
                // 创建 List<Map<String, Object>>
                List<Map<String, Object>> processList = new ArrayList<>();
 
                // 遍历分割后的部分并将其存入 List<Map<String, Object>>
                for (int i = 0; i < parts.length; i++) {
                    Map<String, Object> maps = new HashMap<>();
                    maps.put("id", i); // 添加一个索引字段
                    maps.put("process", parts[i]); // 添加实际的值
 
                    processList.add(maps);
                }
 
                itemmap.put("processList", processList);
                //  itemmap.put("numberList", numberList);
 
                if (flowCard.getPatchState().equals(0)) {
                    itemmap.put("count", flowCardMapper.countFlowCard(flowCard.getOrderId()));
                } else {
                    itemmap.put("count", flowCardList.size());
                }
                itemmap.put("state", flowCard.getPatchState());
                itemmap.put("remarkList", flowCardMapper.remakList(flowCard.getProcessId()));
                list.add(itemmap);
 
            }
        }
 
        map.put("data", list);
        return map;
    }
 
    public Boolean updateComposingSv(Map<String, Object> object) {
        List<FlowCard> flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("composing")), FlowCard.class);
        if (!flowCardList.isEmpty()) {
            for (FlowCard flowCard : flowCardList) {
                flowCardMapper.updateComposing(flowCard.getProcessId());
            }
            return true;
        } else {
            return false;
 
        }
    }
 
    public Boolean updateProcessCardRack(Map<String, Object> object) {
        List<FlowCard> flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("composing")), FlowCard.class);
        if (!flowCardList.isEmpty()) {
            for (FlowCard flowCard : flowCardList) {
                flowCardMapper.updateProcessCardRack(flowCard.getProcessId(), flowCard.getTechnologyNumber(), flowCard.getRack());
            }
            return true;
        } else {
            return false;
 
        }
    }
 
    public Map<String, Object> getSelectPrintLabelSv(String projectNo, String type) {
        Map<String, Object> map = new HashMap<>();
        if (Objects.equals(type, "1")) {
            map.put("data", flowCardMapper.getPrintLabel(projectNo));
        } else if (Objects.equals(type, "2")) {
            map.put("data", flowCardMapper.getPrintLabel2(projectNo));
        } else if (Objects.equals(type, "3")) {
            map.put("data", flowCardMapper.getPrintLabel3(projectNo));
        }
 
        return map;
    }
 
    public Map<String, Object> getSelectPrintLabelSv1(Map<String, Object> object) {
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();//最终结果
        List<FlowCard> flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("printList")), FlowCard.class);
        if (!flowCardList.isEmpty()) {
            for (FlowCard flowCard : flowCardList) {
                Map<String, Object> itemmap = new HashMap<>();
                itemmap.put("data", flowCardMapper.getPrintLabel1(flowCard.getProcessId(), flowCard.getTechnologyNumber()));
                list.add(itemmap);
            }
        }
        map.put("data", list);
 
        return map;
    }
 
    public Map<String, Object> getSelectPrintLabelDetails(Map<String, Object> object) {
        Map<String, Object> map = new HashMap<>();
 
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();//最终结果
        List<FlowCard> flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("printList")), FlowCard.class);
        if (!flowCardList.isEmpty()) {
            for (FlowCard flowCard : flowCardList) {
                Map<String, Object> itemmap = new HashMap<>();
                itemmap.put("data", flowCardMapper.getPrintLabelDetail(flowCard));
                list.add(itemmap);
            }
        }
        map.put("data", list);
 
        return map;
    }
 
    public Map<String, Object> printFlowCardDetailsSv(String processId, String technologyNumber, String process, FlowCard flowCard) {
        Map<String, Object> map = new HashMap<>();
        map.put("data", flowCardMapper.printFlowCardDetailsMp(processId, technologyNumber, process, flowCard));
        return map;
    }
 
    public Boolean printSortSv(Map<String, Object> object) {
        List<FlowCard> FlowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("flowCard")), FlowCard.class);
        if (!FlowCardList.isEmpty()) {
            for (FlowCard flowCard : FlowCardList) {
                //判断保存的数据是否已存在
                Integer count = flowCardMapper.printAddSortCountMp(flowCard.getProcessId(), flowCard.getOrderNumber(), flowCard.getTechnologyNumber(), flowCard.getSort(), flowCard.getProcess());
                if (count > 0) {
                    flowCardMapper.printUpdateSortMp(flowCard.getProcessId(), flowCard.getOrderNumber(), flowCard.getTechnologyNumber(), flowCard.getSort(), flowCard.getProcess());
                } else {
                    flowCardMapper.printAddSortMp(flowCard.getProcessId(), flowCard.getOrderNumber(), flowCard.getTechnologyNumber(), flowCard.getSort(), flowCard.getProcess());
                }
            }
        }
        return true;
    }
 
 
    public Map<String, Object> getSelectPrintCustomLabelSv(String type, Integer lableType, Map<String, Object> object) {
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();//最终结果
        List<FlowCard> flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("printList")), FlowCard.class);
        if (!flowCardList.isEmpty()) {
            Set<String> processedProcessIds = new HashSet<>();  // 用来存放已处理过的 processId
 
            if (lableType != 2) {//成品标签
                for (FlowCard flowCard : flowCardList) {
                    String processId = flowCard.getProcessId();
 
                    // 检查是否已经处理过该 processId,如果处理过则跳过
                    if (processedProcessIds.contains(processId)) {
                        continue;
                    }
                    Map<String, Object> itemmap = new HashMap<>();
                    itemmap.put("data", flowCardMapper.getPrintCustomData(flowCard.getProcessId(), flowCard.getOrderNumber()));
                    list.add(itemmap);
 
                    // 将该 processId 加入已处理集合
                    processedProcessIds.add(processId);
                }
            } else {//小片标签
                for (FlowCard flowCard : flowCardList) {
                    Map<String, Object> itemmap = new HashMap<>();
                    itemmap.put("data", flowCardMapper.getPrintCustomDataSemi(flowCard.getProcessId(), flowCard.getTechnologyNumber(), flowCard.getProcess()));
                    list.add(itemmap);
                }
            }
        }
        map.put("data", list);
        map.put("title", flowCardMapper.getPrintTitle(type));
        return map;
    }
 
    public Map<String, Object> getSelectPrintCustomLabelSv2(String type, Integer lableType, Map<String, Object> object) {
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();//最终结果
        List<FlowCard> flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("printList")), FlowCard.class);
        if (!flowCardList.isEmpty()) {
            Set<String> processedProcessIds = new HashSet<>();  // 用来存放已处理过的 processId
 
            if (lableType != 2) {//成品标签
                for (FlowCard flowCard : flowCardList) {
                    String processId = flowCard.getProcessId();
 
                    // 检查是否已经处理过该 processId,如果处理过则跳过
                    if (processedProcessIds.contains(processId)) {
                        continue;
                    }
                    Map<String, Object> itemmap = new HashMap<>();
                    itemmap.put("data", flowCardMapper.getPrintCustomData2(flowCard.getProcessId()));
                    list.add(itemmap);
 
                    // 将该 processId 加入已处理集合
                    processedProcessIds.add(processId);
                }
            } else {//小片标签
                for (FlowCard flowCard : flowCardList) {
                    Map<String, Object> itemmap = new HashMap<>();
                    itemmap.put("data", flowCardMapper.getPrintCustomDataSemi(flowCard.getProcessId(), flowCard.getTechnologyNumber(), flowCard.getProcess()));
                    list.add(itemmap);
                }
            }
        }
        map.put("data", list);
        map.put("title", flowCardMapper.getPrintTitle(type));
        return map;
    }
 
    public Object getCustomLabelDetailSv(String name, String form, String id, FlowCard flowCard) {
        Map<String, Object> map = new HashMap<>();
        map.put("data", flowCardMapper.getCustomLabelDetailMp(name, form, id, flowCard));
        return map;
    }
 
    public Boolean updatePrintStateSv(Integer printState, Map<String, Object> object) {
        List<FlowCard> flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("printList")), FlowCard.class);
        if (!flowCardList.isEmpty()) {
            for (FlowCard flowCard : flowCardList) {
                // 更新打印状态
                flowCardMapper.updatePrintStateMp(printState, flowCard.getProcessId(), flowCard.getTechnologyNumber());
            }
            return true;
        } else {
            return false;
        }
 
    }
 
    public Map<String, Object> printFlowCardOrderSortSv(String orderId, FlowCard flowCard) {
        Map<String, Object> map = new HashMap<>();
        map.put("data", flowCardMapper.printFlowCardOrderSortMp(orderId, flowCard));
        return map;
    }
 
    public Boolean printOrderSort(Map<String, Object> object) {
        List<FlowCard> FlowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("flowCard")), FlowCard.class);
        if (!FlowCardList.isEmpty()) {
            for (FlowCard flowCard : FlowCardList) {
                flowCardMapper.printOrderSortMp(flowCard.getProcessId(), flowCard.getOrderNumber(), flowCard.getTechnologyNumber(), flowCard.getSort());
            }
        }
        return true;
    }
 
    public Map<String, Object> getSelectPrintingRefundSv(Map<String, Object> object, String printMerge, String printLike, String mergeTechnologyNumber) {
        if (printMerge == null) {
            printMerge = "";
        }
        if (printLike == null) {
            printLike = "";
        }
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();//最终结果
        List<FlowCard> flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("printList")), FlowCard.class);
        if (!flowCardList.isEmpty()) {
            for (FlowCard flowCard : flowCardList) {
                Map<String, Object> itemmap = new HashMap<>();
                //流程卡表头表尾数据
                //是否传入合并层数
                if (printMerge.equals("") || printMerge.equals("null")) {
                    itemmap.put("detail", flowCardMapper.getPrimaryListRefund(flowCard.getProcessId(), String.valueOf(flowCard.getTechnologyNumber()), flowCard.getOrderNumber(), flowCard.getReportingWorkId(), mergeTechnologyNumber, flowCard.getPatchReason(), flowCard.getOrderId()));
                    List<Map<String, Object>> detailList = flowCardMapper.getDetailListRefund(flowCard.getProcessId(), flowCard.getTechnologyNumber(), flowCard.getOrderNumber(), flowCard.getReportingWorkId(), flowCard.getPatchReason());
                    itemmap.put("detailList", detailList);
                } else {
 
                    //流程卡明细数据
                    if (printLike.equals("") || printLike.equals("null")) {
                        itemmap.put("detail", flowCardMapper.getPrimaryListMergeRefund(flowCard.getProcessId(), printMerge, flowCard.getOrderNumber(), flowCard.getOrderId()));
 
                        List<Map<String, Object>> detailList = flowCardMapper.getDetailListRefund(flowCard.getProcessId(), flowCard.getTechnologyNumber(), flowCard.getOrderNumber(), flowCard.getReportingWorkId(), flowCard.getPatchReason());
                        itemmap.put("detailList", detailList);
                    } else {
                        itemmap.put("detail", flowCardMapper.getPrimaryListRefund(flowCard.getProcessId(), String.valueOf(flowCard.getTechnologyNumber()), flowCard.getOrderNumber(), flowCard.getReportingWorkId(), mergeTechnologyNumber, flowCard.getPatchReason(), flowCard.getOrderId()));
 
                        List<Map<String, Object>> detailList = flowCardMapper.getDetailListLikeRefund(flowCard.getProcessId(), printMerge, flowCard.getOrderNumber(), flowCard.getReportingWorkId());
                        itemmap.put("detailList", detailList);
                    }
                }
 
                //工艺流程
                List<Map<String, Object>> processList = flowCardMapper.getProcessList(flowCard.getProcessId(), flowCard.getTechnologyNumber());
 
                itemmap.put("processList", processList);
                //  itemmap.put("numberList", numberList);
                list.add(itemmap);
 
            }
        }
        map.put("data", list);
        //初始化值
        printLike = null;
        return map;
    }
 
    public Map<String, Object> getSelectPrinReworkSv(Map<String, Object> object, String printMerge, String printLike) {
        if (printMerge == null) {
            printMerge = "";
        }
        if (printLike == null) {
            printLike = "";
        }
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();//最终结果
        List<FlowCard> flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("printList")), FlowCard.class);
        if (!flowCardList.isEmpty()) {
            for (FlowCard flowCard : flowCardList) {
                Map<String, Object> itemmap = new HashMap<>();
                //流程卡表头表尾数据
                //是否传入合并层数
                if (printMerge.equals("") || printMerge.equals("null")) {
                    itemmap.put("detail", flowCardMapper.getPrimaryListRework(flowCard.getProcessId(), String.valueOf(flowCard.getTechnologyNumber()), flowCard.getOrderNumber(), flowCard.getReportingWorkId(), flowCard.getOrderId()));
                    List<Map<String, Object>> detailList = flowCardMapper.getDetailListRework(flowCard.getProcessId(), flowCard.getTechnologyNumber(), flowCard.getOrderNumber(), flowCard.getReportingWorkId());
                    itemmap.put("detailList", detailList);
                } else {
 
                    //流程卡明细数据
                    if (printLike.equals("") || printLike.equals("null")) {
                        itemmap.put("detail", flowCardMapper.getPrimaryListMergeRework(flowCard.getProcessId(), printMerge, flowCard.getOrderNumber(), flowCard.getOrderId()));
 
                        List<Map<String, Object>> detailList = flowCardMapper.getDetailListRework(flowCard.getProcessId(), flowCard.getTechnologyNumber(), flowCard.getOrderNumber(), flowCard.getReportingWorkId());
                        itemmap.put("detailList", detailList);
                    } else {
                        itemmap.put("detail", flowCardMapper.getPrimaryListRework(flowCard.getProcessId(), String.valueOf(flowCard.getTechnologyNumber()), flowCard.getOrderNumber(), flowCard.getReportingWorkId(), flowCard.getOrderId()));
 
                        List<Map<String, Object>> detailList = flowCardMapper.getDetailListLikeRework(flowCard.getProcessId(), printMerge, flowCard.getOrderNumber(), flowCard.getReportingWorkId());
                        itemmap.put("detailList", detailList);
                    }
                }
 
                //工艺流程
                List<Map<String, Object>> processList = flowCardMapper.getProcessList(flowCard.getProcessId(), flowCard.getTechnologyNumber());
 
                itemmap.put("processList", processList);
                //  itemmap.put("numberList", numberList);
                list.add(itemmap);
 
            }
        }
        map.put("data", list);
        //初始化值
        printLike = null;
        return map;
    }
 
    public Object selectPrintDetailsSv(Map<String, Object> object, String inquiryMode, Integer type) {
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();//最终结果
        List<FlowCard> flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("printList")), FlowCard.class);
        if (!flowCardList.isEmpty()) {
            for (FlowCard flowCard : flowCardList) {
                Map<String, Object> itemmap = new HashMap<>();
                if (type == 1) {//明细打印
                    itemmap.put("detail", flowCardMapper.selectPrintDetailsMp(flowCard.getOrderId()));
                } else if (type == 2) {//明细分架打印
                    itemmap.put("detail", flowCardMapper.selectPrintDetailsMp1(flowCard.getOrderId()));
                }else if (type == 3) {//订单打印
                    itemmap.put("detail", flowCardMapper.selectPrintDetailsMp2(flowCard.getOrderId()));
                }
 
                list.add(itemmap);
            }
        }
        map.put("data", list);
        map.put("type", flowCardMapper.selectType());
        return map;
    }
 
    public Map<String, Object> getSelectPrintCustomLabelDetailsSv(String type, Integer lableType, Map<String, Object> object) {
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();//最终结果
        List<FlowCard> flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("printList")), FlowCard.class);
        if (!flowCardList.isEmpty()) {
            Set<String> processedKeys = new HashSet<>();
 
            if (lableType != 2) {//成品标签
                for (FlowCard flowCard : flowCardList) {
                    String orderId = flowCard.getOrderId();
                    String processId = flowCard.getProcessId();
                    String orderNumber = flowCard.getOrderNumber().toString();
                    String uniqueKey = processId + "|" + orderNumber;  // 用特殊字符连接防止冲突
                       if (processId!=null){
                           // 检查是否已经处理过该 processId,如果处理过则跳过
                           if (processedKeys.contains(uniqueKey)) {
                               continue;
                           }
                           Map<String, Object> itemmap = new HashMap<>();
                           itemmap.put("data", flowCardMapper.getPrintCustomDataDetails(flowCard.getProcessId(), flowCard.getOrderNumber(), flowCard.getPrintQuantity()));
                           list.add(itemmap);
 
                           // 将该 processId 加入已处理集合
                           processedKeys.add(uniqueKey);
                       } else{
 
                           Map<String, Object> itemmap = new HashMap<>();
                           itemmap.put("data", flowCardMapper.getPrintOrderDataDetails(flowCard.getOrderId(), flowCard.getOrderNumber(), flowCard.getPrintQuantity()));
                           list.add(itemmap);
                       }
 
                }
            } else {//小片标签
                for (FlowCard flowCard : flowCardList) {
                    Map<String, Object> itemmap = new HashMap<>();
                    itemmap.put("data", flowCardMapper.getPrintCustomDataSemi(flowCard.getProcessId(), flowCard.getTechnologyNumber(), flowCard.getProcess()));
                    list.add(itemmap);
                }
            }
        }
        map.put("data", list);
        map.put("title", flowCardMapper.getPrintTitle(type));
        return map;
    }
 
    public Map<String, Object> getPrintCustomDataProjectNo(String type, String projectNo) {
        Map<String, Object> map = new HashMap<>();
        map.put("data", flowCardMapper.getPrintCustomDataProjectNo(projectNo));
        map.put("title", flowCardMapper.getPrintTitle(type));
        return map;
    }
 
    public Object selectSortTableSv(Map<String, Object> object) {
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();//最终结果
        List<FlowCard> flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("printList")), FlowCard.class);
        if (!flowCardList.isEmpty()) {
            for (FlowCard flowCard : flowCardList) {
                Map<String, Object> itemmap = new HashMap<>();
                itemmap.put("data", flowCardMapper.selectSortTableMp(flowCard.getOrderId()));
                list.add(itemmap);
 
            }
        }
        map.put("data", list);
 
        return map;
 
 
    }
 
    public String mergeFlowCard(Map<String, Object> object, Integer merge) {
        String returns = "false";
        List<FlowCard> flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("flowCard")), FlowCard.class);
        if (!flowCardList.isEmpty()) {
            List<Map<String, Object>> flowCardList1 = flowCardMapper.selectFlowCardMerge(flowCardList.get(0).getProcessId());
            if (merge == 0){
                int index = 1;
                for (int i = 0; i < flowCardList1.size(); i++) {
                    if (Integer.valueOf(flowCardList1.get(i).get("count2").toString()) > 1) {
                        List<Integer> technologyNumber = Arrays.stream(flowCardList1.get(i).get("count1").toString().split(","))
                                .map(Integer::parseInt)
                                .collect(Collectors.toList());
                        flowCardMapper.updateFlowCardMerge(flowCardList.get(0).getProcessId(), technologyNumber, index);
                        index += 1;
                        returns = "true";
                    }
                }
            }else {//取消合并
                flowCardMapper.updateFlowCardIsMerge(flowCardList.get(0).getProcessId());
                returns = "true";
            }
 
        }
 
        return returns;
 
 
    }
 
    public List<FlowCard> getProcessCard(Map<String, String> processCards) {
        String processCard = processCards.get("processCard");
        if (!processCard.contains("/")) {
            throw new ServiceException(Constants.Code_600, "错误的流程卡号,请检查!");
        }
 
        String[] processCardList = processCard.split("/");
        List<String> result = IntStream.range(0, processCardList[1].length())
                .mapToObj(i -> String.valueOf(processCardList[1].charAt(i)))
                .collect(Collectors.toList());
 
        List<FlowCard> flowCardList = flowCardMapper.selectList(
                new QueryWrapper<FlowCard>()
                        .eq("process_id", processCardList[0])
                        .in("technology_number", result)
        );
        for (FlowCard flowCard : flowCardList) {
            flowCard.setOrderGlassDetail(
                    orderGlassDetailMapper.selectOne(
                            new QueryWrapper<OrderGlassDetail>()
                                    .eq("order_id", flowCard.getOrderId())
                                    .eq("order_number", flowCard.getOrderNumber())
                                    .eq("technology_number", flowCard.getTechnologyNumber())
                    )
            );
            String str = flowCard.getOrderGlassDetail().getGlassChild();
            String delimiter = "mm";
            int index = str.indexOf(delimiter);
            Integer subString = Integer.valueOf(str.substring(0, index).trim());
            flowCard.getOrderGlassDetail().setThickness(subString);
        }
        return flowCardList;
    }
 
    public Boolean checkboxDeleteSv(Map<String, Object> object) {
        String userName = "";
        if (object.get("userName") != null) {
            userName = object.get("userName").toString();
        }
        String userId = "";
        if (object.get("userId") != null) {
            userId = object.get("userId").toString();
        }
        List<FlowCard> flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("composing")), FlowCard.class);
        for (FlowCard flowCard : flowCardList) {
            //查询是否报工
            Integer count = flowCardMapper.reportingWorkCount(flowCard.getProcessId());
            if (count == 0) {
                //修改分架状态
                flowCardMapper.updateDeleteState(flowCard.getOrderId(), flowCard.getProcessId());
                //删除报工流程明细表数据
                flowCardMapper.deleteReportingWork(flowCard.getProcessId());
                //删除分架明细
                flowCardMapper.deleteFlowCardMp(flowCard.getOrderId(), flowCard.getProcessId());
                //删除排序表数据
                flowCardMapper.deleteflowCardSort(flowCard.getOrderId(), flowCard.getProcessId());
                //判断该订单流程卡是否全部删除
                Integer flowNumber = flowCardMapper.selectFlowCardCount(flowCard.getOrderId());
                if (flowNumber == 0) {
                    //修改订单表分架状态为0,全部删除
                    flowCardMapper.updateProcessingCard(flowCard.getOrderId(), 0);
                } else {
                    //修改订单表分架状态为1,删除部分
                    flowCardMapper.updateProcessingCard(flowCard.getOrderId(), 1);
                }
 
                //保存日志
                Log log = new Log();
                log.setContent(flowCard.getOrderId() + flowCard.getProcessId());
                log.setFunction("checkboxDeleteSv流程卡删除");
                log.setOperatorId(userId);
                log.setOperator(userName);
                logService.saveLog(log);
            } else {
                return false;
            }
        }
        return true;
 
 
    }
 
    public Map<String, Object> getPrintProjectDetails(String projectNo) {
        Map<String, Object> map = new HashMap<>();
        map.put("data", flowCardMapper.getPrintProjectDetailsMp(projectNo));
        return map;
    }
 
    public Map<String, Object> getPrintCustomDataProjectNoDetailSv(String type, Integer detailType, Map<String, Object> object) {
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();//最终结果
        List<FlowCard> flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("printList")), FlowCard.class);
        if (!flowCardList.isEmpty()) {
            Set<String> processedProcessIds = new HashSet<>();  // 用来存放已处理过的 processId
            for (FlowCard flowCard : flowCardList) {
                Map<String, Object> itemmap = new HashMap<>();
                //是否是工程明细打印
                if (detailType == 0) {//工程打印明细
                    itemmap.put("data", flowCardMapper.getPrintCustomDataProjectDetail(flowCard.getProjectNo(), flowCard.getStockId()));
 
                }
                //非工程打印
                else if (detailType == 1) {
                    itemmap.put("data", flowCardMapper.getPrintCustomDataProject(flowCard.getProjectNo()));
 
                } else {
                    itemmap.put("data", flowCardMapper.getPrintCustomDataProject(flowCard.getProjectNo()));
 
                }
                list.add(itemmap);
            }
        }
        map.put("data", list);
        map.put("title", flowCardMapper.getPrintTitle(type));
        return map;
    }
 
    public Boolean updateProcessSv(String processId, String technologyNumber, String orderId, String Orderprocess, Map<String, Object> object) {
 
        //判断该流程卡是否报工
        Integer count = flowCardMapper.reportingWorkCount(processId);
        if (count == 0) {
            //删除小片工艺表对应的数据
            flowCardMapper.deleteProcessMp(processId, technologyNumber);
            //重新插入修改好工艺流程卡的数据
            List<String> newCraftList = (List<String>) object.get("newCraft");
            List<String> numberList = (List<String>) object.get("technologyNumber");
            // 判断 newCraftList 是否为空
            if (newCraftList != null) {
                for (String number : numberList) {
                    //修改订单小片表工艺流程
                    flowCardMapper.updateOrderProcessMp(orderId, number, technologyNumber, Orderprocess);
                    for (String process : newCraftList) {
                        flowCardMapper.updateProcessMp(processId, technologyNumber, process, number);
                    }
                }
            }
 
            return true;
        } else {
            return false;
        }
 
 
    }
 
    public Integer updateProjectLabelPrintCount(String projectNo) {
        flowCardMapper.updateProjectLabelPrintCount(projectNo);
        return flowCardMapper.selectProjectLabelPrintCount(projectNo);
    }
 
    public Integer updateProjectProcessPrintCount(String projectNo) {
        flowCardMapper.updateProjectProcessPrintCount(projectNo);
        return flowCardMapper.selectProjectProcessPrintCount(projectNo);
    }
 
 
    public Map<String, Object> flowCardDetail(Map<String, Object> object) {
 
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();//最终结果
        List<FlowCard> flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("printList")), FlowCard.class);
        if (!flowCardList.isEmpty()) {
 
            for (FlowCard flowCard : flowCardList) {
                Map<String, Object> itemmap = new HashMap<>();
                itemmap.put("detail", flowCardMapper.getFlowCardDetail(flowCard.getProcessId()));
                list.add(itemmap);
 
            }
        }
 
        map.put("data", list);
        return map;
    }
 
    public Object processCardAutoRack(Map<String, Object> object) {
        String orderId = object.get("orderId").toString();
        String productionId = object.get("productionId").toString();
        Integer inMaxQuantity = Integer.parseInt(object.get("inMaxQuantity").toString());
        Float inWeight =  Float.parseFloat(object.get("inWeight").toString());
        Float shelfThickness =  Float.parseFloat(object.get("shelfThickness").toString());
        Float spacerThickness =  Float.parseFloat(object.get("spacerThickness").toString());
        Float inLenMax = Float.parseFloat(object.get("inLenMax").toString());
        Float inLenMin = Float.parseFloat(object.get("inLenMin").toString());
        Float inShortMax = Float.parseFloat(object.get("inShortMax").toString());
        Float inShortMin = Float.parseFloat(object.get("inShortMin").toString());
 
        /*String orderId = "NG25000004";
        String productionId = "NG25000004A";
        Integer inMaxQuantity = 1;
        Float inWeight = 4000.0f;
        Float shelfThickness = 2000.0f;
        Float maxHeight = 1520.0f;
        Float maxWid = 400.0f;
        Float spacerThickness = 0.0f;//垫片厚度*/
 
 
        Map<String, Object> thickness = flowCardMapper.getGlassThicknessByProdutionId(orderId, productionId);
 
        //成品玻璃总厚度
        Float glassTotalThickness = Float.parseFloat(thickness.get("totalThickness").toString());
        //成品玻璃厚度
        Float glassThickness = Float.parseFloat(thickness.get("thickness").toString());
 
        //获取此工程号订单明细信息
        List<OrderDetail> orderDetails = flowCardMapper.getOrderDetailByProductionId(orderId, productionId,"scope",inLenMax,inLenMin,inShortMax,inShortMin,glassThickness);
        List<OrderDetail> orderDetailsNotScope = flowCardMapper.getOrderDetailByProductionId(orderId, productionId,"notScope",inLenMax,inLenMin,inShortMax,inShortMin,glassThickness);
 
        //根据玻璃厚度和垫片厚度当前架子最大可放数量
        Integer shelfMaxQuantityByThickness = (int) (shelfThickness / (glassTotalThickness + spacerThickness));
 
        //用于接收最终生成的流程卡
        List<OrderDetail> orderDetailList = new ArrayList<>();
 
        //流程卡自增符号
        int flowCardNo = 1;
        // 当前架子剩余可放数量
        Integer shelfQuantity = 0;
        for (OrderDetail orderDetail : orderDetails) {
            //架子根据尺寸重量最大能放多少
            int shelfQuantityByWeight = (int) (inWeight /
                    (orderDetail.getHeight()
                            * orderDetail.getWidth()
                            * glassThickness
                            * 2.5 / 1000000)
            );
            //当前订单明细剩余数量
            if (shelfQuantity == 0) {
                shelfQuantity =Math.min( Math.min(shelfMaxQuantityByThickness,inMaxQuantity),shelfQuantityByWeight);
            }else if(shelfQuantity>0){//架子剩余数量大于0时,判断当前架子剩余重量,是否支持最新序号的的成品重量
                String FlowCardId = orderDetailList.get(orderDetailList.size() - 1).getProcessId();
                double flowCardWeight = 0.0;
                for (OrderDetail orderDetail1 : orderDetailList) {
                    if (orderDetail1.getProcessId().equals(FlowCardId)) {
                        flowCardWeight += orderDetail1.getHeight()*orderDetail1.getQuantity()* orderDetail1.getWidth()* glassThickness* 2.5 / 1000000;
                    }
                }
                if(flowCardWeight>0){
                    flowCardWeight = inWeight - flowCardWeight;
                    //按照当前流程卡剩余重量,计算当前流程卡剩余数量
                    int remainingQuantity = (int) (flowCardWeight /
                            (orderDetail.getHeight()
                                    * orderDetail.getWidth()
                                    * glassThickness
                                    * 2.5 / 1000000));
                    shelfQuantity =Math.min(Math.min(Math.min(shelfQuantityByWeight, Math.min(inMaxQuantity, shelfMaxQuantityByThickness)),shelfQuantity),remainingQuantity);
                    if (shelfQuantity == 0) {
                        shelfQuantity = Math.min(shelfQuantityByWeight, Math.min(inMaxQuantity, shelfMaxQuantityByThickness));
                        flowCardNo += 1;
                    }
                }
 
            }
            //取最小值
            //Integer maxQuantity = 0;
            while (orderDetail.getQuantity() > 0) {
                OrderDetail newOrderDetail = new OrderDetail();
                //当死循环中,当前架子剩余数量为0时,重新计算架子剩余数量
                if (shelfQuantity == 0) {
                    shelfQuantity = Math.min(Math.min(shelfMaxQuantityByThickness,inMaxQuantity),shelfQuantityByWeight);
                }
                String processId = productionId + String.format("%03d", flowCardNo);
                //取最小值
                //maxQuantity = Math.min(shelfQuantity, Math.min(inMaxQuantity, shelfMaxQuantityByThickness));
                //maxQuantity = Math.min(shelfQuantity,  shelfMaxQuantityByThickness);
 
                /*System.out.println("订单序号:"+orderDetail.getOrderNumber());
                System.out.println(shelfQuantity + ","  + "," + shelfMaxQuantityByThickness);
                System.out.println(flowCardNo + "," + maxQuantity);
                System.out.println("------");*/
                if(shelfQuantity<=0){
                    return false;
                }
 
                if (orderDetail.getQuantity() > shelfQuantity) {
                    newOrderDetail.setProcessId(processId);
                    newOrderDetail.setQuantity(Long.valueOf(shelfQuantity));
                    newOrderDetail.setHeight(orderDetail.getHeight());
                    newOrderDetail.setWidth(orderDetail.getWidth());
                    newOrderDetail.setOrderNumber(orderDetail.getOrderNumber());
                    newOrderDetail.setShape(orderDetail.getShape());
                    newOrderDetail.setLandingSequence(flowCardNo);
                    orderDetailList.add(newOrderDetail);
                    orderDetail.setQuantity(orderDetail.getQuantity() - shelfQuantity);
                    orderDetail.setBaiscQuantity(String.valueOf(Integer.valueOf(orderDetail.getBaiscQuantity())-shelfQuantity));
                    flowCardNo += 1;
                    shelfQuantity = shelfQuantity - shelfQuantity;
                } else {
                    newOrderDetail.setProcessId(processId);
                    newOrderDetail.setQuantity(orderDetail.getQuantity());
                    newOrderDetail.setHeight(orderDetail.getHeight());
                    newOrderDetail.setWidth(orderDetail.getWidth());
                    newOrderDetail.setOrderNumber(orderDetail.getOrderNumber());
                    newOrderDetail.setShape(orderDetail.getShape());
                    newOrderDetail.setLandingSequence(flowCardNo);
                    newOrderDetail.setBaiscQuantity(String.valueOf(orderDetail.getBaiscQuantity()));
                    orderDetailList.add(newOrderDetail);
                    //当前架子剩余数量
                    shelfQuantity = shelfQuantity - Math.toIntExact(orderDetail.getQuantity());
                    if (shelfQuantity == 0) {
                        flowCardNo += 1;
                    }
                    orderDetail.setQuantity(0L);
                }
            }
 
        }
        Map<String, Object> map = new HashMap<>();
        Collections.reverse(orderDetailList);
        map.put("orderDetailList", orderDetailList);
        map.put("orderDetailsNotScope", orderDetailsNotScope);
        return map;
    }
 
 
    public Boolean revokeComposingSv(Map<String, Object> object) {
        List<FlowCard> flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("composing")), FlowCard.class);
        if (!flowCardList.isEmpty()) {
            for (FlowCard flowCard : flowCardList) {
                //获取没有工程号的条数,已生成工程号不能撤回
              Integer count =  flowCardMapper.selectProjectNo(flowCard.getProcessId());
              if (count == 0){
                  flowCardMapper.revokeComposing(flowCard.getProcessId());
              } else {
                  return false;
              }
 
            }
            return true;
        } else {
            return false;
 
        }
    }
}