xiaoyong931011
2021-08-25 461a737f9b4c935213698feddc12b535a588b832
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
package com.xzx.gc.order.controller;
 
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import cn.jpush.api.push.model.audience.Audience;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xzx.gc.common.Result;
import com.xzx.gc.common.constant.*;
import com.xzx.gc.common.dto.CommonDto;
import com.xzx.gc.common.dto.SimplePage;
import com.xzx.gc.common.dto.log.OperationAppLog;
import com.xzx.gc.common.exception.RestException;
import com.xzx.gc.common.request.BaseController;
import com.xzx.gc.common.utils.*;
import com.xzx.gc.entity.*;
import com.xzx.gc.model.FileExportDTO;
import com.xzx.gc.model.JsonResult;
import com.xzx.gc.model.admin.*;
import com.xzx.gc.model.order.*;
import com.xzx.gc.model.system.ConfigInfoReq;
import com.xzx.gc.model.system.ConfigInfoVo;
import com.xzx.gc.model.user.UserGatherOrderParam;
import com.xzx.gc.model.user.UserGatherOrderRes;
import com.xzx.gc.model.user.UserGatherOrderSureListParam;
import com.xzx.gc.model.user.UserGatherOrderSureParam;
import com.xzx.gc.order.dto.*;
import com.xzx.gc.order.mapper.*;
import com.xzx.gc.order.service.*;
import com.xzx.gc.order.vo.InviteUserOrderVo;
import com.xzx.gc.util.DoubleUtil;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @author:andylei
 * @title
 * @Description
 * @date 2018/11/22/022
 * @修改历史
 */
@Api(tags = "订单管理")
@RestController
@Slf4j
public class OrderController extends BaseController {
 
    @Autowired
    private OrderDetailService orderDetailService;
 
    @Autowired
    private OtherUserService otherUserService;
    @Autowired
    private MqUtil mqUtil;
 
    @Autowired
    private OrderService orderService;
 
    @Autowired
    private OrderClockInMapper orderClockInMapper;
 
    @Autowired
    private AddressMapper addressMapper;
 
    @Autowired
    private OrderMapper orderMapper;
 
    @Autowired
    private ConfigService configService;
 
    @Autowired
    private StorageService storageService;
 
    @Autowired
    private OtherUserMapper otherUserMapper;
 
 
    @Autowired
    private OrderClockInService orderClockInService;
 
 
    @Autowired
    private RuleService ruleService;
 
    @Autowired
    private StoreInfoMapper storeInfoMapper;
 
    @Autowired
    private FenceService fenceService;
 
    @Autowired
    private BusinessUtil businessUtil;
 
    @Autowired
    private PartnerGaodeService partnerGaodeService;
 
    @Autowired
    private AddressService addressService;
 
    @Autowired
    private PartnerFenceService partnerFenceService;
 
    @Autowired
    private JGPushUtil jgPushUtil;
 
    @Autowired
    private UserService userService;
 
    @Autowired
    private AddressLevelService addressLevelService;
 
    @Autowired
    private PartnerFenceMapper partnerFenceMapper;
 
 
    @Value("${jg.appkey}")
    private String JG_APP_KEY;
    @Value("${jg.secret}")
    private String JG_SECRET;
 
    @Autowired
    private CityPartnerService cityPartnerService;
 
    @Autowired
    private UserMapper userMapper;
 
    /**
     * 订单增加
     *
     * @param orderInfoReq
     */
    @ApiOperation(value = "下单")
    @PostMapping("/order/add")
    public Result<String> orderAdd(HttpServletRequest request, @Validated @RequestBody OrderInfoReq orderInfoReq) {
 
 
        //截取经纬度为小数点后6位
        if (StrUtil.isNotBlank(orderInfoReq.getLatitude())) {
            Double aDouble = Convert.toDouble(NumberUtil.roundStr(orderInfoReq.getLatitude(), 6, RoundingMode.DOWN));
            orderInfoReq.setLatitude(Convert.toStr(aDouble));
        }
 
        if (StrUtil.isNotBlank(orderInfoReq.getLongitude())) {
            Double aDouble = Convert.toDouble(NumberUtil.roundStr(orderInfoReq.getLongitude(), 6, RoundingMode.DOWN));
            orderInfoReq.setLongitude(Convert.toStr(aDouble));
        }
 
        if (StringUtils.isNotBlank(orderInfoReq.getCreateUserName())) {
            if (!StringUtils.isBase64(orderInfoReq.getCreateUserName())) {
                orderInfoReq.setCreateUserName(Base64.encode(orderInfoReq.getCreateUserName()));
            }
        }
 
        if (OrderEnum.待接单.getValue().equals(orderInfoReq.getOrderStatus())) {
            Validator.validateNotEmpty(orderInfoReq.getAddress(), "详细地址不能为空");
        }
 
        String reserveTime = orderInfoReq.getReserveTime();
 
        //正常下单
        if (orderInfoReq.getStoreId() == null) {
            if (StrUtil.isBlank(reserveTime)) {
                throw new RestException(-1, "预约时间不能为空");
            } else {
                try {
                    DateUtil.parse(reserveTime, "yyyy-MM-dd HH:mm");
                } catch (Exception e) {
                    throw new RestException(-1, "预约时间格式不正确");
                }
            }
        } else {
            //门店下单
            StoreInfo storeInfo = storeInfoMapper.selectByPrimaryKey(orderInfoReq.getStoreId());
            if (storeInfo != null) {
                if (Constants.DEL_FLAG == Convert.toInt(storeInfo.getDelFlag(), Constants.DEL_FLAG) || Constants.CLOSE.equals(storeInfo.getFlag())) {
                    throw new RestException(-1, "门店已关闭");
                }
                //单位米
                double distance = LocationUtils.getDistance(Convert.toDouble(storeInfo.getLatitude()), Convert.toDouble(storeInfo.getLongitude()), Convert.toDouble(orderInfoReq.getLatitude()), Convert.toDouble(orderInfoReq.getLongitude()));
                if (NumberUtil.compare(distance, Convert.toDouble(5000)) > 0) {
                    throw new RestException(-1, "您当前下单位置超出门店服务范围");
                }
            } else {
                throw new RestException(-1, "门店不存在");
            }
 
        }
 
 
        orderInfoReq.setVersion(getVersion(request));
 
        if (orderInfoReq.getType() == 1) {
            //预约时间不对或者是定点下单的情况
            if ("0000-00-00 00:00".equals(orderInfoReq.getReserveTime()) || ":00".equals(orderInfoReq.getReserveTime())) {
                orderInfoReq.setReserveTime(DateUtil.format(new Date(), DateUtils.DATE_FORMAT_YMDHM));
            }
        }
 
        //下单用户手机号码不能在平台存在别的身份
        String mobile = orderInfoReq.getType() == 0 ? orderInfoReq.getMobilePhone() : orderInfoReq.getRelaPhone();
        if (!SpringUtil.isDev()) {
            List<OtherUserInfo> byMobileForBidden = otherUserService.findByMobileAndTypeForBidden(mobile, CommonEnum.回收员.getValue());
            if (CollUtil.isNotEmpty(byMobileForBidden)) {
                throw new RestException(-1, "您是平台骑手,暂不支持下单操作");
            }
        }
 
        String orderId = orderService.orderAdd(orderInfoReq);
 
 
        OperationAppLog build = OperationAppLog.builder().appPrograme(getFrontClient(request)).opreateName(mobile)
                .methodName(Constants.ORDER_MODUL_NAME).operateAction("下单-" + orderId).build();
        mqUtil.sendApp(build);
 
        return Result.success();
    }
 
 
    @ApiOperation(value = "重新指派")
    @PostMapping("/order/point")
    public Result<String> point(HttpServletRequest request, @RequestBody OrderPointDto orderPointDto) {
        Result point = orderService.point(orderPointDto);
        if (point.getCode() == 0) {
            String mobilePhone = userService.findOtherByUserId(getUserId(request), 1);
            OperationAppLog build = OperationAppLog.builder().appPrograme(getFrontClient(request)).opreateName(mobilePhone)
                    .methodName(Constants.ORDER_MODUL_NAME).operateAction("重新指派-" + orderPointDto.getOrderId()).build();
            mqUtil.sendApp(build);
        }
        return point;
    }
 
 
    @ApiOperation(value = "修改订单地址")
    @PostMapping("/order/updateAddress")
    public Result updateAddress(HttpServletRequest request, @RequestBody OrderUpdateAddressDto orderUpdateAddress) {
 
        //截取经纬度为小数点后6位
        if (StrUtil.isNotBlank(orderUpdateAddress.getLatitude())) {
            Double aDouble = Convert.toDouble(NumberUtil.roundStr(orderUpdateAddress.getLatitude(), 6, RoundingMode.DOWN));
            orderUpdateAddress.setLatitude(Convert.toStr(aDouble));
        }
 
        if (StrUtil.isNotBlank(orderUpdateAddress.getLongitude())) {
            Double aDouble = Convert.toDouble(NumberUtil.roundStr(orderUpdateAddress.getLongitude(), 6, RoundingMode.DOWN));
            orderUpdateAddress.setLongitude(Convert.toStr(aDouble));
        }
 
 
//        String townId=orderService.getFenceId(orderUpdateAddress.getLongitude(), orderUpdateAddress.getLatitude(),orderUpdateAddress.getAddressId().toString(),orderUpdateAddress.getOrderId(),0);
 
        Long addressId = orderUpdateAddress.getAddressId();
        AddressInfo byId1 = addressService.findById(addressId.toString());
        FenceDto fence = fenceService.getFence(byId1.getTownshipId(), false, orderUpdateAddress.getLongitude(), orderUpdateAddress.getLatitude(), true);
        if (StrUtil.isBlank(fence.getFenceId())) {
            throw new RestException(-3, "所选位置暂未开通服务");
        }
 
        orderUpdateAddress.setTownId(fence.getFenceId());
        OrderInfo orderInfo = new OrderInfo();
        BeanUtils.copyProperties(orderUpdateAddress, orderInfo);
        orderService.updateOrderById(orderInfo);
 
        OrderDetailInfo orderDetailInfo = new OrderDetailInfo();
        BeanUtils.copyProperties(orderUpdateAddress, orderDetailInfo);
        orderDetailService.update(orderDetailInfo);
 
        String mobilePhone = userService.findOtherByUserId(getUserId(request), 1);
        OperationAppLog build = OperationAppLog.builder().appPrograme(getFrontClient(request)).opreateName(mobilePhone)
                .methodName(Constants.ORDER_MODUL_NAME).operateAction("更新订单地址-" + orderUpdateAddress.getOrderId()).build();
        mqUtil.sendApp(build);
 
 
        return Result.success();
    }
 
 
    @ApiOperation(value = "更新订单")
    @PostMapping("/order/update")
    public Result<String> updateOrder(HttpServletRequest request, @RequestBody OrderInfoReq orderInfoReq) {
        Result result = orderService.updateOrder(orderInfoReq);
        if (result.getCode() == 0) {
            String mobilePhone;
            if (StrUtil.isNotBlank(orderInfoReq.getReceiver())) {
                mobilePhone = userService.findOtherByUserId(getUserId(request), 1);
            } else {
                mobilePhone = userService.findOtherByUserId(getUserId(request), 0);
            }
            OperationAppLog build = OperationAppLog.builder().appPrograme(getFrontClient(request)).opreateName(mobilePhone)
                    .methodName(Constants.ORDER_MODUL_NAME).operateAction("更新订单-" + orderInfoReq.getOrderId()).build();
            mqUtil.sendApp(build);
        }
        return result;
    }
 
    @ApiOperation(value = "催单")
    @PostMapping("/order/reminder")
    public Result<String> reminder(HttpServletRequest request, @RequestBody OrderReminderDto orderReminderDto) {
        OrderDetailInfo orderInfo = new OrderDetailInfo();
        BeanUtil.copyProperties(orderReminderDto, orderInfo);
        orderInfo.setOrderFastFlag(Convert.toShort(0));
        orderDetailService.update(orderInfo);
        //根据订单ID查找所属合伙运营员 进行推送
        OrderInfo byId = orderService.findById(orderReminderDto.getOrderId());
        String townId = byId.getTownId();
        String partnerIdByFenceId = partnerFenceService.findPartnerIdByFenceId(townId);
        if (StrUtil.isNotBlank(partnerIdByFenceId)) {
            //推送
            jgPushUtil.pushRemindOrder(partnerIdByFenceId);
        }
 
        String mobilePhone = userService.findOtherByUserId(getUserId(request), 0);
        OperationAppLog build = OperationAppLog.builder().appPrograme(getFrontClient(request)).opreateName(mobilePhone)
                .methodName(Constants.ORDER_MODUL_NAME).operateAction("催单-" + orderReminderDto.getOrderId()).build();
        mqUtil.sendApp(build);
        return Result.success();
    }
 
 
    /**
     * 更新订单取消原因
     *
     * @param orderInfoReq
     */
    @ApiOperation(value = "修改订单取消原因")
    @PostMapping("/order/update/cancelreason")
    public Result<String> updateOrderCancelReason(HttpServletRequest request, @RequestBody OrderInfoReq orderInfoReq) {
        LogUtils.setTraceId(LogUtils.TRACE_ORDER_ID, orderInfoReq.getOrderId());
        orderService.updateOrderCancelReason(orderInfoReq);
 
        String mobilePhone = userService.findOtherByUserId(getUserId(request), 0);
        OperationAppLog build = OperationAppLog.builder().appPrograme(getFrontClient(request)).opreateName(mobilePhone)
                .methodName(Constants.ORDER_MODUL_NAME).operateAction("更新订单取消原因-" + orderInfoReq.getOrderId()).build();
        mqUtil.sendApp(build);
        return Result.success();
    }
 
    @ApiOperation(value = "订单列表查询")
    @PostMapping("/order/list/query")
    public Result<PageInfo<OrderInfoVo>> orderListQuery(HttpServletRequest request, @RequestBody OrderInfoReq orderInfoReq) {
 
        Result<PageInfo<OrderInfoVo>> result = new Result();
        String userId = getUserId(request);
        if (!CommonEnum.普通用户.getValue().equals(orderInfoReq.getUserType())) {
            OtherUserInfo otherUserInfo = otherUserMapper.selectByPrimaryKey(userId);
            String leaveStartTime = otherUserInfo.getLeaveStartTime();
            String leaveEndTime = otherUserInfo.getLeaveEndTime();
            //可能请假
            if (StrUtil.isNotBlank(leaveStartTime) && OrderEnum.待接单.getValue().equals(orderInfoReq.getOrderStatus())) {
                if (DateUtil.compare(new Date(), DateUtil.parse(leaveStartTime)) >= 0 && DateUtil.compare(new Date(), DateUtil.parse(leaveEndTime)) <= 0) {
                    return Result.success(new PageInfo<>(new ArrayList<>()));
                }
            }
 
 
            orderInfoReq.setUserType(otherUserInfo.getUserType());
            orderInfoReq.setLoginUserPhone(otherUserInfo.getMobilePhone());
 
            //查询回收员是否绑定门店
            //如果回收员绑定了门店,则按门店的经纬度 ,否则是动态的传过来的经纬度
//            Example example=new Example(StoreInfo.class);
//            Example.Criteria criteria = example.createCriteria();
//            criteria.andEqualTo("userId",otherUserInfo.getUserId());
//            criteria.andEqualTo("delFlag",Constants.DEL_NOT_FLAG+"");
//            criteria.andEqualTo("flag",Constants.OPEN);
//            List<StoreInfo> select = storeInfoMapper.selectByExample(example);
//            if(CollUtil.isNotEmpty(select)){
//                  StoreInfo storeInfo1=select.get(0);
//                  orderInfoReq.setLatitude(storeInfo1.getLatitude());
//                  orderInfoReq.setLongitude(storeInfo1.getLongitude());
//                  orderInfoReq.setStoreId(storeInfo1.getId());
//            }
 
 
            //回收员只能看到自己负责的区域的单
            boolean exclude = false;
            //指定要排除指定骑手的合伙人
            String configValue = configService.findByCode(SysConfigConstant.EXCLUDE_OTHER_PARTNER).getConfigValue();
            if (StrUtil.isNotBlank(configValue)) {
                List<String> partnerIdlist = Arrays.asList(configValue.split(","));
                String partnerId = otherUserInfo.getPartnerId();
                if (partnerIdlist.contains(partnerId)) {
                    exclude = true;
                }
            }
 
            //
            if (!exclude) {
                orderInfoReq.setReceiver(otherUserInfo.getUserId());
            }
 
            orderInfoReq.setTownId(otherUserInfo.getTownId());
 
            if (!orderClockInService.notClock(userId)) {
                ConfigInfoReq configInfoReq = new ConfigInfoReq();
                configInfoReq.setConfigTypeCode("CODE_SCAN_RK");
                List<ConfigInfoVo> configInfoVos = configService.configInfoQuery(configInfoReq);
                configValue = configInfoVos.get(0).getConfigValue();
 
                if (OrderEnum.未开放入库扫码.getValue().equals(configValue)) {
                    //用户有未进行空车打卡操作
                    OrderClockIn today = orderClockInMapper.findToday(userId, StrUtil.split(DateUtil.now(), " ")[0]);
                    if (today == null) {
                        result.setCode(-1);
                        result.setMsg("您今日还未进行打卡");
                        return result;
                    }
                }
            }
 
            orderInfoReq.setOrderTypeList(CollUtil.newArrayList("1","2"));
        } else {
            orderInfoReq.setUserType(CommonEnum.普通用户.getValue());
            orderInfoReq.setOrderTypeList(CollUtil.newArrayList("1", "2", "3", "4", "5"));
        }
        PageInfo<OrderInfoVo> pageInfo = orderService.orderListQuery(orderInfoReq);
        result.setData(pageInfo);
        return result;
    }
 
 
    @ApiOperation(value = "管理员订单列表查询")
    @PostMapping("/order/list/queryForAdmin")
    public Result<PageInfo<OrderInfoVo>> queryForAdmin(HttpServletRequest request, @RequestBody OrderInfoReq orderInfoReq) {
        Result<PageInfo<OrderInfoVo>> result = new Result();
        String userId = getUserId(request);
        OtherUserInfo otherUserInfo = otherUserMapper.selectByPrimaryKey(userId);
 
 
        orderInfoReq.setUserType(otherUserInfo.getUserType());
        // 所有的角色
        List<OtherUserInfo> select = otherUserService.findByMobile(otherUserInfo.getMobilePhone());
        String roleIds = select.stream().map(OtherUserInfo::getRoleIds).collect(Collectors.joining(","));
        orderInfoReq.setRoleIds(roleIds);
        //所有身份类型
        List<String> userTypeList = select.stream().map(OtherUserInfo::getUserType).collect(Collectors.toList());
 
        orderInfoReq.setLoginUserPhone(otherUserInfo.getMobilePhone());
 
 
        if (userTypeList.contains(CommonEnum.运营员.getValue()) || userTypeList.contains(CommonEnum.骑手组长.getValue())) {
            String partnerId = otherUserInfo.getPartnerId();
            List<String> collect = partnerFenceService.findFences(partnerId);
            orderInfoReq.setFenceIds(collect);
            orderInfoReq.setPartnerId(partnerId);
        }
 
        PageInfo<OrderInfoVo> pageInfo = orderService.orderListQueryForAdmin(orderInfoReq);
        result.setData(pageInfo);
        return result;
    }
 
 
    @ApiOperation(value = "家电骑手订单列表查询")
    @PostMapping("/order/list/queryForHomeAppliance")
    public Result<PageInfo<OrderInfoVo>> queryForHomeAppliance(HttpServletRequest request, @RequestBody OrderInfoReq orderInfoReq) {
 
        Result<PageInfo<OrderInfoVo>> result = new Result();
        String userId = getUserId(request);
        OtherUserInfo otherUserInfo = otherUserMapper.selectByPrimaryKey(userId);
        String leaveStartTime = otherUserInfo.getLeaveStartTime();
        String leaveEndTime = otherUserInfo.getLeaveEndTime();
        //可能请假
        if (StrUtil.isNotBlank(leaveStartTime) && OrderEnum.待接单.getValue().equals(orderInfoReq.getOrderStatus())) {
            if (DateUtil.compare(new Date(), DateUtil.parse(leaveStartTime)) >= 0 && DateUtil.compare(new Date(), DateUtil.parse(leaveEndTime)) <= 0) {
                return Result.success(new PageInfo<>(new ArrayList<>()));
            }
        }
        PageInfo<OrderInfoVo> pageInfo = orderService.queryForHomeAppliance(orderInfoReq, otherUserInfo);
        result.setData(pageInfo);
        return result;
    }
 
    /**
     * 订单列表查询
     */
    @ApiOperation(value = "已完成订单列表查询", notes = "extra:rk代表入库员查询,不传则是回收员查询")
    @PostMapping("/order/list/complete/query")
    public Result<PageInfo<OrderStorageInfo>> orderListCompleteQuery(HttpServletRequest request, @RequestBody SimplePage simplePage) {
        Result<PageInfo<OrderStorageInfo>> result = new Result();
        List<OrderStorageInfo> completeOrder = storageService.findCompleteOrder(simplePage, getUserId(request));
        PageInfo<OrderStorageInfo> pageInfo = new PageInfo<>(completeOrder);
        int i = storageService.countStorageOrder(getUserId(request));
        pageInfo.setNavigatePages(i);
        result.setData(pageInfo);
        return result;
    }
 
    /**
     * 入库明细查询
     *
     * @param
     */
    @ApiOperation(value = "入库详情", notes = "id:入库Id")
    @PostMapping("/order/storage/complete/detail")
    public Result<StorageDetailBatchDto> orderStorageCompleteDetailQuery(HttpServletRequest request, @RequestBody CommonDto commonDto) {
        String storageId = commonDto.getId();
        LogUtils.setTraceId(LogUtils.TRACE_ORDER_ID, storageId);
        Result<StorageDetailBatchDto> result = new Result();
        StorageDetailBatchDto storageDetailBatchDto = storageService.detail(storageId);
        result.setData(storageDetailBatchDto);
        return result;
 
    }
 
 
    @ApiOperation(value = "查看回收订单", notes = "id:入库ID")
    @PostMapping("/order/storage/recyle/detail")
    public Result<List<OrderDetailInfo>> orderRecyleCompleteDetailQuery(HttpServletRequest request, @RequestBody CommonDto commonDto) {
        Result<List<OrderDetailInfo>> result = new Result();
        String storageId = commonDto.getId();
        LogUtils.setTraceId(LogUtils.TRACE_ORDER_ID, storageId);
        List<OrderDetailInfo> list = storageService.recyledDetail(storageId);
        result.setData(list);
        return result;
 
    }
 
    @ApiOperation(value = "订单详情")
    @PostMapping("/order/detail/query")
    public Result<List<OrderInfoVo>> orderDetailQuery(HttpServletRequest request, @RequestBody OrderInfoReq orderInfoReq) {
        Result<List<OrderInfoVo>> result = new Result();
        LogUtils.setTraceId(LogUtils.TRACE_ORDER_ID, orderInfoReq.getOrderId());
        List<OrderInfoVo> list = orderService.orderDetailQuery(orderInfoReq);
        result.setData(list);
        return result;
    }
 
 
    @ApiOperation(value = "入库列表查询")
    @PostMapping("/order/storage/list")
    public Result<List<OrderStorageVo>> orderStorageListQuery(@RequestBody OrderStorageReq orderStorageReq) {
        Result<List<OrderStorageVo>> result = new Result();
 
        List<OrderStorageVo> list = orderService.orderStorageListQuery(orderStorageReq);
 
        result.setData(list);
 
        return result;
 
    }
 
    /**
     * 入库明细查询
     *
     * @param
     */
    @ApiOperation(value = "入库明细查询")
    @PostMapping("/order/storage/detail")
    public Result<List<OrderStorageVo>> orderStorageDetailQuery(HttpServletRequest request, @RequestBody OrderStorageReq orderStorageReq) {
        Result<List<OrderStorageVo>> result = new Result();
        List<OrderStorageVo> list = orderService.orderStorageDetailQuery(orderStorageReq);
        result.setData(list);
        return result;
 
    }
 
 
    /**
     * 获取默认预约时间
     */
    @ApiOperation(value = "获取默认预约时间", notes = "extra:0代表普通用户 1:平台用户 2集货员")
    @PostMapping("/order/reserveTime")
    public Result<OrderReserveResDto> getReserveTimeNew(HttpServletRequest request, @RequestBody CommonDto commonDto) {
        Result<OrderReserveResDto> result = new Result<>();
        OrderReserveResDto orderReserveResDto = new OrderReserveResDto();
        //2集货员
        if ("2".equals(commonDto.getExtra())) {
            String timeInterval = "0";
            List<ConfigInfo> orderTime = configService.findByGroup(SysConfigConstant.GATHER_ORDER_TIME);
            for (ConfigInfo configInfo : orderTime) {
                if (configInfo.getConfigTypeCode().equals(SysConfigConstant.GATHER_INTERVAL_TIME)) {
                    //分钟
                    timeInterval = configInfo.getConfigValue();
                } else if (configInfo.getConfigTypeCode().equals(SysConfigConstant.GATHER_START_TIME)) {
                    orderReserveResDto.setStartTime(configInfo.getConfigValue());
                } else if (configInfo.getConfigTypeCode().equals(SysConfigConstant.GATHER_END_TIME)) {
                    orderReserveResDto.setEndTime(configInfo.getConfigValue());
                }
            }
            //获取时间间隔后的时间
            String reserveTime = DateUtil.offsetMinute(new Date(), Convert.toInt(timeInterval)).toString(DateUtils.DATE_FORMAT_YMDHMS);
            orderReserveResDto.setReserveTime(reserveTime);
        } else {
            String partnerId = partnerGaodeService.findPartnerIdByUserId(getUserId(request), Convert.toInt(commonDto.getExtra()));
            RuleDto stepRebate = ruleService.findWeightRebate(getUserId(request), false, partnerId);
            orderReserveResDto.setList(stepRebate.getRebateRules());
            stepRebate = ruleService.findStepRebate(getUserId(request), false, partnerId);
            orderReserveResDto.setScale(stepRebate.getScale());
            //预约时间
            orderService.getReserveTimeNew(orderReserveResDto, partnerId);
        }
        result.setData(orderReserveResDto);
        return result;
    }
 
    /**
     * 获取各状态的订单列表数
     *
     * @param orderInfoReq
     */
    @ApiOperation(value = "获取各状态的订单列表数")
    @PostMapping("/order/status/count")
    public Result<OrderStatusCountVo> getReserveTime(HttpServletRequest request, @RequestBody OrderInfoReq orderInfoReq) {
        Result<OrderStatusCountVo> result = new Result<>();
        OrderStatusCountVo orderStatusCount = orderService.orderListCount(orderInfoReq);
        result.setData(orderStatusCount);
        return result;
    }
 
 
    @ApiOperation(value = "自助下单列表查询")
    @PostMapping("/order/customer/find")
    public Result<PageInfo<OrderCustomDto>> customerFind(HttpServletRequest request, @RequestBody SimplePage simplePage) {
        Result result = new Result();
        String userId = getUserId(request);
        PageHelper.startPage(simplePage.getPageNo(), simplePage.getPageSize());
        List<OrderCustomDto> list = orderService.customerFind(userId);
        PageInfo<OrderCustomDto> pageInfo = new PageInfo<>(list);
        result.setData(pageInfo);
        return result;
    }
 
 
    @ApiOperation(value = "根据订单id删除自助下单")
    @PostMapping("/order/customer/delete")
    public Result customerdel(HttpServletRequest request, @RequestBody CommonDto commonDto) {
        String orderId = commonDto.getId();
        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setOrderId(orderId);
        orderInfo.setDelFlag(Convert.toShort(Constants.DEL_FLAG));
        orderMapper.updateByPrimaryKeySelective(orderInfo);
 
        String mobilePhone = userService.findOtherByUserId(getUserId(request), 1);
        OperationAppLog build = OperationAppLog.builder().appPrograme(getFrontClient(request)).opreateName(mobilePhone)
                .methodName(Constants.ORDER_MODUL_NAME).operateAction("删除自助下单-" + orderId).build();
        mqUtil.sendApp(build);
 
        return Result.success();
    }
 
 
    @ApiOperation(value = "根据日期查找回收员的订单")
    @PostMapping("/order/findOrderByTime")
    public Result<List<OrderInfo>> findByTime(HttpServletRequest request, @RequestBody FindOrderByTimeDto findOrderByTimeDto) {
        List<OrderInfo> list = orderMapper.findOrderByTime(findOrderByTimeDto);
        if (CollUtil.isNotEmpty(list)) {
            for (OrderInfo orderInfo : list) {
                if (StrUtil.isNotBlank(orderInfo.getCompleteTime())) {
                    //格式化hh:mm
                    orderInfo.setCompleteTime(DateUtil.parse(orderInfo.getCompleteTime(), DateUtils.DATE_FORMAT_YMDHMS).toString(DateUtils.DATE_FORMAT_HM));
                }
            }
        }
        return Result.success(list);
    }
 
 
    @ApiOperation(value = "订单状态变更")
    @PostMapping("/order/orderRevers")
    public Result orderRevers(HttpServletRequest request, @RequestBody OrderReversDto orderReversDto) {
        orderReversDto.setManageUserId(getUserId(request));
        orderReversDto.setIsSendMsg(true);
        orderService.orderRevers(orderReversDto);
 
        String mobilePhone = userService.findOtherByUserId(getUserId(request), 1);
        String collect = orderReversDto.getList().stream().map(x -> x.getOrderId()).collect(Collectors.joining(","));
        OperationAppLog build = OperationAppLog.builder().appPrograme(getFrontClient(request)).opreateName(mobilePhone)
                .methodName(Constants.ORDER_MODUL_NAME).operateAction("订单状态变更-" + collect).build();
        mqUtil.sendApp(build);
        return Result.success();
    }
 
 
    @ApiOperation(value = "订单标记")
    @PostMapping("/order/mark")
    public Result<String> mark(HttpServletRequest request, @RequestBody OrderMarkDTO orderMarkDTO) {
        OrderDetailInfo orderDetailInfo = new OrderDetailInfo();
        BeanUtil.copyProperties(orderMarkDTO, orderDetailInfo);
        //未读
        orderDetailInfo.setMarkRead("0");
        orderDetailService.update(orderDetailInfo);
 
        String mobilePhone = userService.findOtherByUserId(getUserId(request), 1);
        OperationAppLog build = OperationAppLog.builder().appPrograme(getFrontClient(request)).opreateName(mobilePhone)
                .methodName(Constants.ORDER_MODUL_NAME).operateAction("订单标记-" + orderMarkDTO.getOrderId()).build();
        mqUtil.sendApp(build);
        return Result.success();
    }
 
    @ApiOperation(value = "订单后台备注")
    @PostMapping("/admin/front/order/note")
    public Result<String> note(HttpServletRequest request, @RequestBody OrderMarkDTO orderMarkDTO) {
        OrderDetailInfo orderDetailInfo = new OrderDetailInfo();
        orderDetailInfo.setOrderId(orderMarkDTO.getOrderId());
        orderDetailInfo.setNote(orderMarkDTO.getMarkCode());
        orderDetailService.update(orderDetailInfo);
 
        String mobilePhone = userService.findOtherByUserId(getUserId(request), 1);
        OperationAppLog build = OperationAppLog.builder().appPrograme(getFrontClient(request)).opreateName(mobilePhone)
                .methodName(Constants.ORDER_MODUL_NAME).operateAction("订单后台备注-" + orderMarkDTO.getOrderId()).build();
        mqUtil.sendApp(build);
        return Result.success();
    }
 
    @ApiOperation(value = "到家服务支付")
    @PostMapping("/order/homePay")
    public Result<String> homePay(HttpServletRequest request, @RequestBody OrderHomePayDto orderHomePayDto) {
 
        String money = orderHomePayDto.getMoney();
        if (StrUtil.isBlank(money) || Convert.toBigDecimal(money).compareTo(BigDecimal.ZERO) <= 0) {
            throw new RestException("支付金额不正确");
        }
        Result<String> result = orderService.homePay(orderHomePayDto.getOrderId(), Convert.toBigDecimal(money));
        if (result.getCode() == 0) {
            OperationAppLog build = OperationAppLog.builder().appPrograme(getFrontClient(request)).opreateName(result.getData())
                    .methodName(Constants.ORDER_MODUL_NAME).operateAction("到家服务支付-" + orderHomePayDto.getOrderId()).build();
            mqUtil.sendApp(build);
        }
 
        return result;
 
    }
 
    /**
     * 查询用户订单
     *
     * @param orderModel
     * @return
     */
    @PostMapping("/admin/front/order/queryOrderDataList.do")
    @ApiOperation(value = "订单管理-用户订单", notes = "test: 仅0有正确返回")
    public JsonResult<Map<String, Object>> queryOrderDataList(@RequestBody OrderModel orderModel) {
        Map<String, Object> result = orderService.queryOrderApiList(orderModel);
        return JsonResult.success(result);
    }
 
    /**
     * 根据订单好查询订单详细
     *
     * @param orderModel
     * @return
     */
    @PostMapping("/admin/front/order/queryOrderDetailByNo.json")
    @ApiOperation(value = "订单管理-用户订单详情", notes = "test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "page", value = "页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "limit", value = "每页条数", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "orderId", value = "订单编号", required = true, dataType = "int")
    })
    public JsonResult<Map<String, Object>> queryOrderDetailByNo(@RequestBody OrderModel orderModel) {
        Map<String, Object> map = orderService.queryOrderByOrderno(orderModel);
        return JsonResult.success(map);
    }
 
    /**
     * 查询指派员或回收员
     *
     * @param orderModel
     * @return
     */
    @PostMapping("/admin/front/order/queryCuserApiByType.json")
    @ApiOperation(value = "订单管理-指派工作人员", notes = "test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "page", value = "页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "limit", value = "每页条数", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "orderId", value = "订单编号", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "name", value = "条件", required = true, dataType = "int")
    })
    public JsonResult<Map<String, Object>> queryCuserApiByType(@RequestBody OrderModel orderModel) {
        orderModel.setUserType("2");
        Map<String, Object> map = orderService.queryCuserApiByType(orderModel);
        map.put("orderId", orderModel.getOrderId());
        return JsonResult.success(map);
    }
 
    /**
     * 取消订单
     *
     * @param orderModel
     * @return
     */
    @PostMapping("/admin/front/order/updateOrderReserveTime.json")
    @ApiOperation(value = "订单管理-修改预约时间", notes = "test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "orderId", value = "订单编号", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "userId", value = "用户Id", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "reserveDate", value = "预约时间", required = true, dataType = "String")
    })
    public JsonResult<Map<String, Object>> updateOrderReserveTime(@RequestBody OrderModel orderModel, HttpServletRequest request) {
        Map<String, Object> map = orderService.updateOrderReserveTime(orderModel);
 
        OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))
                .methodName(Constants.ORDER_MODUL_NAME).operateAction("修改预约时间-" + orderModel.getOrderId()).build();
        mqUtil.sendApp(build);
        return JsonResult.success(map);
    }
 
    /**
     * 取消订单
     *
     * @param orderModel
     * @return
     */
    @PostMapping("/admin/front/order/cancelOrderData.json")
    @ApiOperation(value = "订单管理-确定弹窗", notes = "test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "orderId", value = "订单编号", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "userId", value = "用户Id", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "cancelReasonName", value = "订单取消原因", required = true, dataType = "String")
 
    })
    public JsonResult<Map<String, Object>> cancelOrderData(@RequestBody OrderModel orderModel, HttpServletRequest request) {
        Map<String, Object> map = orderService.cancelOrderData(orderModel);
 
        OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))
                .methodName(Constants.ORDER_MODUL_NAME).operateAction("取消订单-" + orderModel.getOrderId()).build();
        mqUtil.sendApp(build);
        return JsonResult.success(map);
    }
 
    /**
     * 重新指派
     *
     * @param orderModel
     * @return
     */
    @PostMapping("/admin/front/order/updateApirecByOrderId.json")
    @ApiOperation(value = "订单管理-重新指派", notes = "test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "orderId", value = "订单编号", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "userId", value = "用户Id", required = true, dataType = "int"),
    })
    public JsonResult<Map<String, Object>> updateApirecByOrderId(@RequestBody OrderModel orderModel, HttpServletRequest request) {
        Map<String, Object> map = orderService.updateApirecByOrderId(orderModel);
        if (Integer.parseInt(map.get("code").toString()) == 0) {
 
            OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))
                    .methodName(Constants.ORDER_MODUL_NAME).operateAction("重新指派-" + orderModel.getOrderId()).build();
            mqUtil.sendApp(build);
 
            return JsonResult.success(map);
 
        } else {
            return JsonResult.failMessage(map.get("msg").toString());
        }
    }
 
    /**
     * 入库订单
     *
     * @param orderModel
     * @return
     */
    @PostMapping("/admin/front/order/queryStorageApiList.do")
    @ApiOperation(value = "订单管理-(待)入库订单", notes = "test: 仅0有正确返回")
    public JsonResult<Map<String, Object>> queryStorageApiList(@RequestBody OrderModel orderModel) {
        Map<String, Object> map = orderService.queryStorageApiList(orderModel);
        return JsonResult.success(map);
    }
 
    /**
     * 入库订单明细
     *
     * @param orderModel
     * @return
     */
    @PostMapping("/admin/front/order/queryStorageDetailApiList.json")
    @ApiOperation(value = "订单管理-入库订单明细", notes = "test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "page", value = "页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "limit", value = "每页条数", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "orderType", value = "列表类型(0:订单列表 1:品类重量)", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "storageId", value = "入库单号", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "storageStatus", value = "入库类型(0:已入库,1:入库中)", required = true, dataType = "String")
    })
    public JsonResult<Map<String, Object>> queryStorageDetailApiList(@RequestBody OrderModel orderModel) {
        Map<String, Object> map = orderService.queryStorageDetailApiList(orderModel);
        return JsonResult.success(map);
    }
 
    @PostMapping("/admin/front/order/queryUserInfoByPhone.json")
    @ApiOperation(value = "订单管理-查询有电话下单的用户", notes = "test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "mobilePhone", value = "手机号", required = true, dataType = "String")
    })
    public JsonResult<List<OrderModel>> queryUserInfoByPhone(@RequestBody OrderModel orderModel) {
        List<OrderModel> result = new ArrayList<>();
        List<UserModel> userModelList = userService.queryUserByPhoneNormal(orderModel.getMobilePhone(), "3");
        if (null != userModelList && userModelList.size() > 0) {
            for (UserModel model : userModelList) {
                OrderModel orderModel1 = new OrderModel();
                orderModel1.setUserId(model.getUserId());
 
                if (!org.apache.commons.lang3.StringUtils.isEmpty(model.getNickName())) {
                    orderModel1.setNickName(StringUtils.decode(model.getNickName()));
                    UserAddressModel paramUserAddress = new UserAddressModel();
                    paramUserAddress.setUserId(model.getUserId());
                    paramUserAddress.setMobilePhone(model.getMobilePhone());
                    UserAddressModel addressModels = addressMapper.queryUserAddressInfo(model.getUserId(), model.getMobilePhone());
                    if (null != addressModels) {
                        orderModel1.setProvinceId(addressModels.getProvinceId());
                        orderModel1.setCityId(addressModels.getCityId());
                        orderModel1.setTownshipId(addressModels.getTownshipId());
                        orderModel1.setProvinceName(addressLevelService.queryAreaName("1", addressModels.getProvinceId()));
                        orderModel1.setCityName(addressLevelService.queryAreaName("2", addressModels.getCityId()));
                        orderModel1.setTownshipName(addressLevelService.queryAreaName("3", addressModels.getTownshipId()));
                        orderModel1.setAddressArea(addressModels.getAddressArea());
                        orderModel1.setDetailAddress(addressModels.getDetailAddress());
                        orderModel1.setLongitude(addressModels.getLongitude());
                        orderModel1.setLatitude(addressModels.getLatitude());
                        orderModel1.setMobilePhone(model.getMobilePhone());
                        orderModel1.setUserId(model.getUserId());
                    }
 
                }
                result.add(orderModel1);
            }
 
        }
        return JsonResult.success(result);
    }
 
 
    @PostMapping("/admin/front/order/addOrderByPhone.json")
    @ApiOperation(value = "订单管理-添加订单", notes = "test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "mobilePhone", value = "手机号", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "nickName", value = "用户昵称", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "type", value = "回收方式(0:上门回收 1:送货到店)", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "provinceId", value = "省", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "cityId", value = "市", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "townshipId", value = "区", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "addressArea", value = "区域名称", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "detailAddress", value = "详细地址", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "longitude", value = "经度", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "latitude", value = "纬度", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "reserveDay", value = "预约日期", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "reserveDate", value = "预约时间", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "itemIds", value = "物品类型id(多个用逗号隔开)", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "remark", value = "留言备注", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "storeId", value = "门店Id", required = true, dataType = "String")
    })
    public JsonResult<String> addOrderByPhone(@RequestBody OrderModel orderModel, HttpServletRequest request) {
        //1:电话下单必须为非注册用户 普通
        if (!DoubleUtil.isMobile(orderModel.getMobilePhone())) {
            return JsonResult.failMessage("用户手机号不正确!");
        }
        String isNomal = "0";
        orderModel.setAddressArea(orderModel.getProvinceId() + orderModel.getCityId() + orderModel.getTownshipId() + orderModel.getDetailAddress());
        String userType = "1";
        UserModel userModel = userMapper.queryUserByUsertype(orderModel.getMobilePhone(), userType, "0", null, null);
        if (userModel != null) {
            isNomal = "1";
        }
        List<OtherUserInfo> userModelOther = otherUserService.findByMobileForBidden(orderModel.getMobilePhone());
        if (null != userModelOther && userModelOther.size() > 0) {
            return JsonResult.failMessage("该用户存在平台身份,暂不支持下单操作");
        }
        List<OrderModel> orderModelList = orderMapper.queryOrderByPhone(orderModel.getMobilePhone());
        if (null != orderModelList && orderModelList.size() > 0) {
            return JsonResult.failMessage("该用户有未完成订单,不能重复下单");
        }
        //必须传入经纬度
        if (null != orderModel.getLongitude() && !"".equals(orderModel.getLongitude())) {
            log.debug("经纬度==" + orderModel.getLongitude());
        } else {
            return JsonResult.failMessage("地图指定异常!");
        }
        if (null != orderModel.getLatitude() && !"".equals(orderModel.getLatitude())) {
            log.debug("经纬度==" + orderModel.getLatitude());
        } else {
            return JsonResult.failMessage("地图指定异常!");
        }
        //下单是否超出范围
        //String townIds = service.queryConfigByTagCodeOne("ORDER_REGION");
        String partnerId = null;
        List<String> partnerIds = cityPartnerService.queryPartnerByCurrent();
        if (null != partnerIds && partnerIds.size() > 0) {
            partnerId = partnerIds.get(0);
        } else {
            return JsonResult.failMessage("只有合伙人才能电话下单!");
        }
        List<String> keys = partnerFenceMapper.queryElectricTownIds(partnerId);
        //预约时间是否大于当前时间
        String reTime = orderModel.getReserveDay() + " " + orderModel.getReserveDate() + ":00";
        log.info("传入的订单预约时间为 ====" + reTime);
        String now = cn.hutool.core.date.DateUtil.now();
 
        if (com.xzx.gc.util.DateUtil.checkBig(reTime, now) >= 2) {
            return JsonResult.failMessage("预约时间不能小于当前时间!");
        }
        orderModel.setPartnerId(partnerId);
        userModel = userService.insertUserInfo(orderModel, keys, isNomal);
        if (null != userModel) {
            OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))
                    .methodName(Constants.ORDER_MODUL_NAME).operateAction("添加订单-" + userModel.getOrderId()).build();
            mqUtil.sendApp(build);
 
            return JsonResult.success("下单成功!");
        } else {
            return JsonResult.failMessage("下单失败,订单超出范围!");
        }
 
    }
 
    @PostMapping("/admin/front/order/queryAdressArea.json")
    @ApiOperation(value = "订单管理-添加订单", notes = "test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "type", value = "查询类型(0:省份,1:对应的城市,2:城市对应的区)", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "level1Id", value = "省Id", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "level2Id", value = "市Id", required = true, dataType = "String")
    })
    public JsonResult<List<SysAddressLevelModel>> queryAdressArea(@RequestBody SysAddressLevelModel addressLevelModel) {
        if (null != addressLevelModel.getType() && !"".equals(addressLevelModel.getType())) {
            List<SysAddressLevelModel> list = orderService.queryAdressArea(addressLevelModel);
            return JsonResult.success(list);
        } else {
            return JsonResult.failMessage("请传入查询类型");
        }
    }
 
    @PostMapping("/admin/front/order/queryUserOrderApiList.do")
    @ApiOperation(value = "用户管理-普通用户的订单列表", notes = "test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "page", value = "页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "limit", value = "每页条数", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "userId", value = "用户id", required = true, dataType = "String")
    })
    public JsonResult<Map<String, Object>> queryUserOrderApiList(@RequestBody UserModel userModel) {
        Map<String, Object> map = orderService.queryUserOrderApiList(userModel);
        return JsonResult.success(map);
    }
 
    @ApiOperation(value = "订单导出", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    @PostMapping(value = "/admin/front/order/export")
    public void fileExport(@RequestBody FileExportDTO fileExportDTO, HttpServletRequest request, HttpServletResponse response) {
        List<List<String>> rows = new ArrayList<>();
        Map<String, Object> object = (Map<String, Object>) fileExportDTO.getObject();
        //标题
        List<String> header = CollUtil.newArrayList("订单号", "昵称", "手机号", "下单时间", "接单时间", "完成时间", "订单状态");
        rows.add(header);
 
        //组装数据
        OrderModel orderModel = BeanUtil.mapToBean(object, OrderModel.class, true);
        Map<String, Object> result = orderService.queryOrderApiList(orderModel);
        List<OrderModel> list = (List<OrderModel>) result.get("data");
        if (CollUtil.isNotEmpty(list)) {
            for (OrderModel model : list) {
                List<String> row = CollUtil.newArrayList(model.getOrderId(), StrUtil.isNotBlank(model.getName()) ? model.getName() : model.getNickName(), model.getMobilePhone(), model.getCreateTime(),
                        model.getReceiveTime(), model.getCompleteTime(), BusinessEnum.getOrderDescByCode(model.getOrderStatus()));
                rows.add(row);
            }
        }
 
        //导出
        export(rows, response);
 
        OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))
                .methodName(Constants.ORDER_MODUL_NAME).operateAction("订单导出").build();
        mqUtil.sendApp(build);
 
    }
 
    @PostMapping("/admin/front/order/queryOrderByHsy.json")
    @ApiOperation(value = "查询回收员所有订单", notes = "test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "userId", value = "用户Id", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "dayTime", value = "日期", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "startTime", value = "开始时间", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "endTime", value = "结束时间", required = true, dataType = "String")
    })
    public JsonResult<List<Map<String, String>>> queryOrderByHsy(@RequestBody XzxCityPartnerModel model) {
        List<Map<String, String>> list = cityPartnerService.queryOrderByHsy(model);
        return JsonResult.success(list);
    }
 
    @PostMapping("/admin/front/order/receiverStatsitic")
    @ApiOperation(value = "骑手订单统计")
    public JsonResult<List<ReceiverStatsiticResDTO>> receiverStatsitic(@RequestBody ReceiverStatsiticDTO receiverStatsiticDTO) {
//        int type = receiverStatsiticDTO.getType();
//        if(type==1||type==2||type==3){
//            receiverStatsiticDTO.setPageSize(0);
//        }
//        PageHelper.startPage(receiverStatsiticDTO.getPageNo(),receiverStatsiticDTO.getPageSize());
 
        if (StrUtil.isNotBlank(receiverStatsiticDTO.getMonth())) {
            receiverStatsiticDTO.setMonth(StringUtils.addZero(Convert.toInt(receiverStatsiticDTO.getMonth())));
        }
        return orderService.receiverStatsitic(receiverStatsiticDTO);
//        PageInfo<ReceiverStatsiticResDTO> pageInfo=new PageInfo<>(list);
    }
 
    @ApiOperation(value = "集货订单列表查询")
    @PostMapping("/order/gather/list")
    public Result<PageInfo<UserGatherOrderRes>> ordergatherList(HttpServletRequest request, @RequestBody UserGatherOrderParam userGatherOrderParam) {
 
        if (StrUtil.isNotBlank((userGatherOrderParam.getLatitude()))) {
            userGatherOrderParam.setLatitude(NumberUtil.roundStr(userGatherOrderParam.getLatitude(), 6, RoundingMode.DOWN));
        }
        if (StrUtil.isNotBlank(userGatherOrderParam.getLongitude())) {
            userGatherOrderParam.setLongitude(NumberUtil.roundStr(userGatherOrderParam.getLongitude(), 6, RoundingMode.DOWN));
        }
        PageHelper.startPage(userGatherOrderParam.getPageNo(), userGatherOrderParam.getPageSize());
        List<UserGatherOrderRes> list = orderService.ordergatherList(userGatherOrderParam);
        return Result.success(new PageInfo<>(list));
    }
 
    @ApiOperation(value = "集货确认收货")
    @PostMapping("/order/gather/sure")
    public Result ordergatherSure(HttpServletRequest request, @RequestBody UserGatherOrderSureParam userGatherOrderSureParam) {
        List<UserGatherOrderSureListParam> list = userGatherOrderSureParam.getList();
        if (CollUtil.isNotEmpty(list)) {
            String userId = userGatherOrderSureParam.getUserId();
            UserInfo byId = userService.findById(userId);
            String mobilePhone = byId.getMobilePhone();
            userGatherOrderSureParam.setUserInfo(byId);
            //确认
            orderService.ordergatherSure(userGatherOrderSureParam);
            OperationAppLog build = OperationAppLog.builder().appPrograme(getFrontClient(request)).opreateName(mobilePhone)
                    .methodName(Constants.ORDER_MODUL_NAME).operateAction("集货确认收货-" + list.stream().map(x -> x.getOrderId()).collect(Collectors.joining(","))).build();
            mqUtil.sendApp(build);
        }
        return Result.success();
    }
 
    @ApiOperation(value = "新版订单详情")
    @PostMapping("/order/new/detail")
    public Result<OrderNewDetailResDTO> orderNewDetail(HttpServletRequest request, @RequestBody OrderNewDetailParamDTO orderNewDetailParamDTO) {
        if (StrUtil.isBlank(orderNewDetailParamDTO.getOrderId())) {
            return Result.error("订单不存在");
        }
        OrderNewDetailResDTO resDTO = orderService.newDetail(orderNewDetailParamDTO);
        return Result.success(resDTO);
    }
 
 
    @ApiOperation(value = "更换骑手申请")
    @PostMapping("/order/changeReceiver")
    public Result<String> changeReceiver(HttpServletRequest request, @RequestBody OrderChangeReceiverDto orderChangeReceiverDto) {
        OrderDetailInfo orderDetailInfo = new OrderDetailInfo();
        BeanUtil.copyProperties(orderChangeReceiverDto, orderDetailInfo);
        orderDetailInfo.setChangeReceiverFlag(Convert.toShort(1));
        orderDetailService.update(orderDetailInfo);
        //推送给骑手
        jgPushUtil.pushOrder(orderDetailInfo.getOrderId(),orderDetailInfo.getReceiver());
 
        String mobilePhone = userService.findOtherByUserId(getUserId(request), 0);
        OperationAppLog build = OperationAppLog.builder().appPrograme(getFrontClient(request)).opreateName(mobilePhone)
                .methodName(Constants.ORDER_MODUL_NAME).operateAction("用户更换骑手申请-" + orderChangeReceiverDto.getOrderId()).build();
        mqUtil.sendApp(build);
        return Result.success();
    }
 
 
    @ApiOperation(value = "更换骑手审核")
    @PostMapping("/order/changeReceiverAudit")
    public Result<String> changeReceiverAudit(HttpServletRequest request, @RequestBody OrderChangeReceiverAuditDto orderChangeReceiverAuditDto) {
        orderService.changeReceiverAudit(orderChangeReceiverAuditDto);
 
        String mobilePhone = userService.findOtherByUserId(getUserId(request), 0);
        OperationAppLog build = OperationAppLog.builder().appPrograme(getFrontClient(request)).opreateName(mobilePhone)
                .methodName(Constants.ORDER_MODUL_NAME).operateAction("更换骑手审核-" + orderChangeReceiverAuditDto.getOrderId()).build();
        mqUtil.sendApp(build);
        return Result.success();
    }
 
    @ApiOperation("邀请好友下单明细")
    @ApiResponses(
            @ApiResponse(code = 200, message = "success", response = InviteUserOrderVo.class)
    )
    @PostMapping(value = Constants.ADMIN_VIEW_PREFIX + "/user/inviteUserQsOrderDetails.json")
    public JsonResult<Object> inviteUserQsOrderDetails(@RequestBody InviteUserOrderDetailsDto detailsDto, HttpServletRequest request) {
        String userId = getUserId(request);
        detailsDto.setUserId(userId);
        return JsonResult.success(orderService.inviteUserOrderDetail(detailsDto));
    }
}