Administrator
2025-07-04 d448834784e996a3c35c90097c4e7b110899bed2
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
package cc.mrbird.febs.mall.service.impl;
 
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.common.entity.QueryRequest;
import cc.mrbird.febs.common.enumerates.*;
import cc.mrbird.febs.common.properties.XcxProperties;
import cc.mrbird.febs.common.utils.SpringContextHolder;
import cc.mrbird.febs.common.utils.excl.ExcelSheetPO;
import cc.mrbird.febs.common.utils.excl.ExcelUtil;
import cc.mrbird.febs.common.utils.excl.ExcelVersion;
import cc.mrbird.febs.common.utils.excl.ResponseHeadUtil;
import cc.mrbird.febs.mall.dto.clothes.AdminClothesDeliverGoodsDto;
import cc.mrbird.febs.mall.dto.clothes.AdminClothesOrderListDto;
import cc.mrbird.febs.mall.dto.clothes.AdminClothesRefundOrderDto;
import cc.mrbird.febs.mall.dto.clothes.AdminClothesTypeInfoDto;
import cc.mrbird.febs.mall.entity.*;
import cc.mrbird.febs.mall.mapper.*;
import cc.mrbird.febs.mall.service.ClothesTypeService;
import cc.mrbird.febs.mall.service.IApiMallMemberWalletService;
import cc.mrbird.febs.mall.service.IMallMoneyFlowService;
import cc.mrbird.febs.mall.vo.AdminMallOrderInfoVo;
import cc.mrbird.febs.mall.vo.clothes.AdminClothesOrderListVo;
import cc.mrbird.febs.pay.util.WeixinServiceUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.*;
import java.util.stream.Collectors;
 
@Slf4j
@Service
@RequiredArgsConstructor
@Transactional
public class ClothesTypeServiceImpl extends ServiceImpl<ClothesTypeMapper, ClothesType> implements ClothesTypeService {
 
    private final ClothesTypeMapper clothesTypeMapper;
    private final ClothesSizeMapper clothesSizeMapper ;
    private final ClothesPatternMapper clothesPatternMapper;
    private final ClothesLocationMapper clothesLocationMapper;
    private final ClothesClothMapper clothesClothMapper;
    private final ClothesArtMapper clothesArtMapper;
    private final ClothesTypeArtMapper clothesTypeArtMapper;
    private final ClothesTypeSizeMapper clothesTypeSizeMapper;
    private final ClothesTypeClothMapper clothesTypeClothMapper;
    private final ClothesTypePatternMapper clothesTypePatternMapper;
    private final ClothesTypeLocationMapper clothesTypeLocationMapper;
    private final ClothesOrderMapper clothesOrderMapper;
    private final MallExpressInfoMapper mallExpressInfoMapper;
    private final IApiMallMemberWalletService memberWalletService;
    private final IMallMoneyFlowService mallMoneyFlowService;
    private final XcxProperties xcxProperties = SpringContextHolder.getBean(XcxProperties.class);
    @Autowired
    private WeixinServiceUtil weixinServiceUtil;
 
    @Override
    public IPage<ClothesType> adminTypeList(ClothesType dto, QueryRequest request) {
        Page<ClothesType> page = new Page<>(request.getPageNum(), request.getPageSize());
        LambdaQueryWrapper<ClothesType> clothesTypeLambdaQueryWrapper = Wrappers.lambdaQuery(ClothesType.class);
        Page<ClothesType> clothesTypePage = clothesTypeMapper.selectPage(page, clothesTypeLambdaQueryWrapper);
        return clothesTypePage;
    }
 
    @Override
    public FebsResponse typeAdd(ClothesType dto) {
        ClothesType clothesType = new ClothesType();
        clothesType.setName(dto.getName());
        clothesType.setOrderNum(dto.getOrderNum());
        clothesType.setImage(dto.getImage());
        clothesType.setImageFront(dto.getImageFront());
        clothesType.setImageBack(dto.getImageBack());
        clothesType.setContent(dto.getContent());
        clothesTypeMapper.insert(clothesType);
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public FebsResponse typeUpdate(ClothesType dto) {
        Long id = dto.getId();
        ClothesType clothesType = clothesTypeMapper.selectById(id);
        if (ObjectUtil.isNotNull(clothesType)) {
            clothesTypeMapper.update(null,
                    Wrappers.lambdaUpdate(ClothesType.class)
                            .eq(ClothesType::getId, id)
                            .set(ClothesType::getName, dto.getName())
                            .set(ClothesType::getOrderNum, dto.getOrderNum())
                            .set(ClothesType::getImage, dto.getImage())
                            .set(ClothesType::getImageFront, dto.getImageFront())
                            .set(ClothesType::getImageBack, dto.getImageBack())
                            .set(ClothesType::getContent, dto.getContent())
                    );
        }
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public FebsResponse changeState(Long id, Integer type, Integer state) {
        ClothesType clothesType = clothesTypeMapper.selectById(id);
        if(ObjectUtil.isNotEmpty(clothesType)){
            switch (type) {
                case 1:
                    clothesType.setState( state);
                    break;
                case 2:
                    clothesType.setClothState(state);
                    break;
                case 3:
                    clothesType.setArtState(state);
                    break;
                case 4:
                    clothesType.setPatternState(state);
                    break;
                case 5:
                    clothesType.setLocationState(state);
                    break;
                case 6:
                    clothesType.setSizeState(state);
                    break;
                default:
                    break;
            }
            clothesTypeMapper.updateById(clothesType);
        }
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public IPage<ClothesSize> adminSizeList(ClothesSize dto, QueryRequest request) {
        Page<ClothesSize> page = new Page<>(request.getPageNum(), request.getPageSize());
        LambdaQueryWrapper<ClothesSize> clothesSizeLambdaQueryWrapper = Wrappers.lambdaQuery(ClothesSize.class);
        Page<ClothesSize> clothesSizePage = clothesSizeMapper.selectPage(page, clothesSizeLambdaQueryWrapper);
        return clothesSizePage;
    }
 
    @Override
    public FebsResponse sizeAdd(ClothesSize dto) {
        ClothesSize clothesSize = new ClothesSize();
        clothesSize.setName(dto.getName());
        clothesSize.setOrderNum(dto.getOrderNum());
        clothesSize.setPrice(dto.getPrice());
        clothesSize.setType(dto.getType());
        clothesSize.setImage(dto.getImage());
        clothesSize.setContent(dto.getContent());
        clothesSizeMapper.insert(clothesSize);
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public FebsResponse sizeUpdate(ClothesSize dto) {
        Long id = dto.getId();
        ClothesSize clothesSize = clothesSizeMapper.selectById(id);
        if (ObjectUtil.isNotNull(clothesSize)) {
            clothesSizeMapper.update(null,
                    Wrappers.lambdaUpdate(ClothesSize.class)
                        .eq(ClothesSize::getId, id)
                        .set(ClothesSize::getName, dto.getName())
                        .set(ClothesSize::getCode, dto.getCode())
                        .set(ClothesSize::getOrderNum, dto.getOrderNum())
                        .set(ClothesSize::getPrice, dto.getPrice())
                        .set(ClothesSize::getType, dto.getType())
                        .set(ClothesSize::getImage, dto.getImage())
                        .set(ClothesSize::getContent, dto.getContent())
            );
        }
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public IPage<ClothesPattern> adminPatternList(ClothesPattern dto, QueryRequest request) {
        Page<ClothesPattern> page = new Page<>(request.getPageNum(), request.getPageSize());
        LambdaQueryWrapper<ClothesPattern> clothesPatternLambdaQueryWrapper = Wrappers.lambdaQuery(ClothesPattern.class);
        Page<ClothesPattern> clothesPatternPage = clothesPatternMapper.selectPage(page, clothesPatternLambdaQueryWrapper);
        return clothesPatternPage;
    }
 
    @Override
    public FebsResponse patternAdd(ClothesPattern dto) {
        ClothesPattern clothesPattern = new ClothesPattern();
        clothesPattern.setName(dto.getName());
        clothesPattern.setCode(dto.getCode());
        clothesPattern.setType(dto.getType());
        clothesPattern.setPrice(dto.getPrice());
        clothesPattern.setOrderNum(dto.getOrderNum());
        clothesPattern.setImage(dto.getImage());
        clothesPattern.setContent(dto.getContent());
        clothesPatternMapper.insert(clothesPattern);
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public FebsResponse patternUpdate(ClothesPattern dto) {
        Long id = dto.getId();
        ClothesPattern clothesPattern = clothesPatternMapper.selectById(id);
        if (ObjectUtil.isNotNull(clothesPattern)) {
            clothesPatternMapper.update(null,
                    Wrappers.lambdaUpdate(ClothesPattern.class)
                            .eq(ClothesPattern::getId, id)
                            .set(ClothesPattern::getName, dto.getName())
                            .set(ClothesPattern::getCode, dto.getCode())
                            .set(ClothesPattern::getImage, dto.getImage())
                            .set(ClothesPattern::getContent, dto.getContent())
                            .set(ClothesPattern::getOrderNum, dto.getOrderNum())
                            .set(ClothesPattern::getPrice, dto.getPrice())
                            .set(ClothesPattern::getType, dto.getType())
            );
        }
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public IPage<ClothesLocation> adminLocationList(ClothesLocation dto, QueryRequest request) {
        Page<ClothesLocation> page = new Page<>(request.getPageNum(), request.getPageSize());
        LambdaQueryWrapper<ClothesLocation> queryWrapper = Wrappers.lambdaQuery(ClothesLocation.class);
        Page<ClothesLocation> pages = clothesLocationMapper.selectPage(page, queryWrapper);
        return pages;
    }
 
    @Override
    public FebsResponse locationAdd(ClothesLocation dto) {
        ClothesLocation clothesLocation = new ClothesLocation();
        clothesLocation.setName(dto.getName());
        clothesLocation.setCode(dto.getCode());
        clothesLocation.setImage(dto.getImage());
        clothesLocation.setContent(dto.getContent());
        clothesLocation.setPrice(dto.getPrice());
        clothesLocation.setOrderNum(dto.getOrderNum());
        clothesLocationMapper.insert(clothesLocation);
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public FebsResponse locationUpdate(ClothesLocation dto) {
        Long id = dto.getId();
        ClothesLocation clothesLocation = clothesLocationMapper.selectById(id);
        if (ObjectUtil.isNotNull(clothesLocation)) {
            clothesLocationMapper.update(null,
                    Wrappers.lambdaUpdate(ClothesLocation.class)
                            .eq(ClothesLocation::getId, id)
                            .set(ClothesLocation::getName, dto.getName())
                            .set(ClothesLocation::getCode, dto.getCode())
                            .set(ClothesLocation::getOrderNum, dto.getOrderNum())
                            .set(ClothesLocation::getPrice, dto.getPrice())
                            .set(ClothesLocation::getImage, dto.getImage())
                            .set(ClothesLocation::getContent, dto.getContent())
            );
        }
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public IPage<ClothesCloth> adminClothList(ClothesCloth dto, QueryRequest request) {
        Page<ClothesCloth> page = new Page<>(request.getPageNum(), request.getPageSize());
        LambdaQueryWrapper<ClothesCloth> queryWrapper = Wrappers.lambdaQuery(ClothesCloth.class);
        Page<ClothesCloth> pages = clothesClothMapper.selectPage(page, queryWrapper);
        return pages;
    }
 
    @Override
    public FebsResponse clothAdd(ClothesCloth dto) {
        ClothesCloth clothesCloth = new ClothesCloth();
        clothesCloth.setName(dto.getName());
        clothesCloth.setCode(dto.getCode());
        clothesCloth.setImage(dto.getImage());
        clothesCloth.setContent(dto.getContent());
        clothesCloth.setPrice(dto.getPrice());
        clothesCloth.setOrderNum(dto.getOrderNum());
        clothesClothMapper.insert(clothesCloth);
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public FebsResponse clothUpdate(ClothesCloth dto) {
        Long id = dto.getId();
        ClothesCloth clothesCloth = clothesClothMapper.selectById(id);
        if (ObjectUtil.isNotNull(clothesCloth)) {
            clothesClothMapper.update(null,
                    Wrappers.lambdaUpdate(ClothesCloth.class)
                            .eq(ClothesCloth::getId, id)
                            .set(ClothesCloth::getName, dto.getName())
                            .set(ClothesCloth::getCode, dto.getCode())
                            .set(ClothesCloth::getOrderNum, dto.getOrderNum())
                            .set(ClothesCloth::getPrice, dto.getPrice())
                            .set(ClothesCloth::getImage, dto.getImage())
                            .set(ClothesCloth::getContent, dto.getContent())
            );
        }
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public IPage<ClothesArt> adminArtList(ClothesArt dto, QueryRequest request) {
        Page<ClothesArt> page = new Page<>(request.getPageNum(), request.getPageSize());
        LambdaQueryWrapper<ClothesArt> queryWrapper = Wrappers.lambdaQuery(ClothesArt.class);
        Page<ClothesArt> pages = clothesArtMapper.selectPage(page, queryWrapper);
        return pages;
    }
 
    @Override
    public FebsResponse artAdd(ClothesArt dto) {
        ClothesArt clothesArt = new ClothesArt();
        clothesArt.setName(dto.getName());
        clothesArt.setCode(dto.getCode());
        clothesArt.setImage(dto.getImage());
        clothesArt.setContent(dto.getContent());
        clothesArt.setPrice(dto.getPrice());
        clothesArt.setOrderNum(dto.getOrderNum());
        clothesArtMapper.insert(clothesArt);
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public FebsResponse artUpdate(ClothesArt dto) {
        Long id = dto.getId();
        ClothesArt clothesArt = clothesArtMapper.selectById(id);
        if (ObjectUtil.isNotNull(clothesArt)) {
            clothesArtMapper.update(null,
                    Wrappers.lambdaUpdate(ClothesArt.class)
                            .eq(ClothesArt::getId, id)
                            .set(ClothesArt::getName, dto.getName())
                            .set(ClothesArt::getCode, dto.getCode())
                            .set(ClothesArt::getOrderNum, dto.getOrderNum())
                            .set(ClothesArt::getPrice, dto.getPrice())
                            .set(ClothesArt::getImage, dto.getImage())
                            .set(ClothesArt::getContent, dto.getContent())
            );
        }
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public FebsResponse artSet(AdminClothesTypeInfoDto dto) {
        Long typeId = dto.getTypeId();
        List<Long> chooseIds = dto.getChooseIds();
        ClothesType clothesType = clothesTypeMapper.selectById(typeId);
        if (ObjectUtil.isNotEmpty(clothesType)) {
            LambdaQueryWrapper<ClothesTypeArt> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(ClothesTypeArt::getTypeId,typeId);
            clothesTypeArtMapper.delete(queryWrapper);
            if(CollUtil.isNotEmpty(chooseIds)){
                for (Long chooseId : chooseIds){
                    ClothesTypeArt entity = new ClothesTypeArt();
                    entity.setTypeId(typeId);
                    entity.setArtId(chooseId);
                    clothesTypeArtMapper.insert(entity);
                }
            }
        }
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public FebsResponse sizeSet(AdminClothesTypeInfoDto dto) {
        Long typeId = dto.getTypeId();
        List<Long> chooseIds = dto.getChooseIds();
        ClothesType clothesType = clothesTypeMapper.selectById(typeId);
        if (ObjectUtil.isNotEmpty(clothesType)) {
            LambdaQueryWrapper<ClothesTypeSize> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(ClothesTypeSize::getTypeId,typeId);
            clothesTypeSizeMapper.delete(queryWrapper);
            if(CollUtil.isNotEmpty(chooseIds)){
                for (Long chooseId : chooseIds){
                    ClothesTypeSize entity = new ClothesTypeSize();
                    entity.setTypeId(typeId);
                    entity.setSizeId(chooseId);
                    clothesTypeSizeMapper.insert(entity);
                }
            }
        }
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public FebsResponse clothSet(AdminClothesTypeInfoDto dto) {
        Long typeId = dto.getTypeId();
        List<Long> chooseIds = dto.getChooseIds();
        ClothesType clothesType = clothesTypeMapper.selectById(typeId);
        if (ObjectUtil.isNotEmpty(clothesType)) {
            LambdaQueryWrapper<ClothesTypeCloth> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(ClothesTypeCloth::getTypeId,typeId);
            clothesTypeClothMapper.delete(queryWrapper);
            if(CollUtil.isNotEmpty(chooseIds)){
                for (Long chooseId : chooseIds){
                    ClothesTypeCloth entity = new ClothesTypeCloth();
                    entity.setTypeId(typeId);
                    entity.setClothId(chooseId);
                    clothesTypeClothMapper.insert(entity);
                }
            }
        }
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public FebsResponse patternSet(AdminClothesTypeInfoDto dto) {
        Long typeId = dto.getTypeId();
        List<Long> chooseIds = dto.getChooseIds();
        ClothesType clothesType = clothesTypeMapper.selectById(typeId);
        if (ObjectUtil.isNotEmpty(clothesType)) {
            LambdaQueryWrapper<ClothesTypePattern> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(ClothesTypePattern::getTypeId,typeId);
            clothesTypePatternMapper.delete(queryWrapper);
            if(CollUtil.isNotEmpty(chooseIds)){
                for (Long chooseId : chooseIds){
                    ClothesTypePattern entity = new ClothesTypePattern();
                    entity.setTypeId(typeId);
                    entity.setPatternId(chooseId);
                    clothesTypePatternMapper.insert(entity);
                }
            }
        }
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public FebsResponse locationSet(AdminClothesTypeInfoDto dto) {
        Long typeId = dto.getTypeId();
        List<Long> chooseIds = dto.getChooseIds();
        ClothesType clothesType = clothesTypeMapper.selectById(typeId);
        if (ObjectUtil.isNotEmpty(clothesType)) {
            LambdaQueryWrapper<ClothesTypeLocation> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(ClothesTypeLocation::getTypeId,typeId);
            clothesTypeLocationMapper.delete(queryWrapper);
            if(CollUtil.isNotEmpty(chooseIds)){
                for (Long chooseId : chooseIds){
                    ClothesTypeLocation entity = new ClothesTypeLocation();
                    entity.setTypeId(typeId);
                    entity.setLocationId(chooseId);
                    clothesTypeLocationMapper.insert(entity);
                }
            }
        }
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public IPage<AdminClothesOrderListVo> getOrderListInPage(AdminClothesOrderListDto dto, QueryRequest request) {
        Page<AdminClothesOrderListVo> page = new Page<>(request.getPageNum(), request.getPageSize());
        IPage<AdminClothesOrderListVo> vos = clothesOrderMapper.selectOrderListInPage(page, dto);
        return vos;
    }
 
    @Override
    public FebsResponse deliverGoods(AdminClothesDeliverGoodsDto dto) {
        ClothesOrder clothesOrder = clothesOrderMapper.selectById(dto.getId());
 
        if(ObjectUtil.isNull(clothesOrder)){
            return new FebsResponse().fail().message("订单不存在,刷新后重试");
        }
        Integer status = clothesOrder.getStatus();
        if(ClothesOrderStatusEnum.WAIT_SHIPPING.getValue() != status){
            return new FebsResponse().fail().message("订单不是待发货状态");
        }
        String expressNo = dto.getExpressNo();
        if(StrUtil.isEmpty(expressNo)){
            return new FebsResponse().fail().message("请输入物流单号");
        }
        String expressCom = dto.getExpressCom();
        if(StrUtil.isEmpty(expressCom)){
            return new FebsResponse().fail().message("请输入物流公司");
        }
        MallExpressInfo mallExpressInfo = new MallExpressInfo();
        mallExpressInfo.setMemberId(clothesOrder.getMemberId());
        mallExpressInfo.setOrderId(clothesOrder.getId());
        mallExpressInfo.setOrderNo(clothesOrder.getOrderNo());
        mallExpressInfo.setExpressNo(expressNo);
        mallExpressInfo.setExpressCom(expressCom);
        mallExpressInfoMapper.insert(mallExpressInfo);
 
        clothesOrderMapper.update(
                null,
                Wrappers.lambdaUpdate(ClothesOrder.class)
                .set(ClothesOrder::getStatus, ClothesOrderStatusEnum.WAIT_FINISH.getValue())
                .set(ClothesOrder::getUpdatedTime, new Date())
                .set(ClothesOrder::getDeliveryState, OrderDeliveryStateEnum.DELIVERY_FINISH.getValue())
                        .eq(ClothesOrder::getId, clothesOrder.getId())
        );
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public FebsResponse deliverGoodsUpdate(AdminClothesDeliverGoodsDto dto) {
        ClothesOrder clothesOrder = clothesOrderMapper.selectById(dto.getId());
 
        if(ObjectUtil.isNull(clothesOrder)){
            return new FebsResponse().fail().message("订单不存在,刷新后重试");
        }
        Integer status = clothesOrder.getStatus();
        if(ClothesOrderStatusEnum.WAIT_FINISH.getValue() != status){
            return new FebsResponse().fail().message("订单不是待发货状态");
        }
        String expressNo = dto.getExpressNo();
        if(StrUtil.isEmpty(expressNo)){
            return new FebsResponse().fail().message("请输入物流单号");
        }
        String expressCom = dto.getExpressCom();
        if(StrUtil.isEmpty(expressCom)){
            return new FebsResponse().fail().message("请输入物流公司");
        }
        MallExpressInfo mallExpressInfo = mallExpressInfoMapper.selectOne(
                Wrappers.lambdaQuery(MallExpressInfo.class)
                        .eq(MallExpressInfo::getOrderId, clothesOrder.getId())
                        .eq(MallExpressInfo::getOrderNo, clothesOrder.getOrderNo())
                        .last("limit 1")
        );
        if(ObjectUtil.isNull(mallExpressInfo)){
            return new FebsResponse().fail().message("请先发货");
        }
        mallExpressInfoMapper.update(
                null,
                Wrappers.lambdaUpdate(MallExpressInfo.class)
                        .set(MallExpressInfo::getExpressNo, expressNo)
                        .set(MallExpressInfo::getExpressCom, expressCom)
                        .set(MallExpressInfo::getUpdatedTime, new Date())
                        .eq(MallExpressInfo::getId, mallExpressInfo.getId())
        );
        return new FebsResponse().success().message("操作成功");
    }
 
 
    private void clothesUpdateStatusAndUpdateTimeById(Long id, Date date, int value) {
        clothesOrderMapper.update(
                null,
                Wrappers.lambdaUpdate(ClothesOrder.class)
                        .set(ClothesOrder::getStatus, ClothesOrderStatusEnum.CANCEL.getValue())
                        .set(ClothesOrder::getUpdatedTime, new Date())
                        .eq(ClothesOrder::getId, id)
        );
    }
 
    private Boolean weChatRefundOrderEvent(int refundMoney, BigDecimal orderAmount, String orderNo, String refundNo) {
        Boolean flag;
        Boolean debug = xcxProperties.getDebug();
        if (debug) {
            if(orderAmount.compareTo(BigDecimal.ZERO) > 0){
                boolean b = weixinServiceUtil.comRefund(orderNo, refundNo, 1, 1, null);
                flag = b;
            }else{
                flag = true;
            }
        } else {
            if(orderAmount.compareTo(BigDecimal.ZERO) > 0){
                log.info("开始调用退款接口。。。退款编号为{}", refundNo);
                boolean b = weixinServiceUtil.comRefund(orderNo, refundNo, refundMoney, refundMoney, null);
                flag = b;
            }else{
                flag = true;
            }
        }
        return flag;
    }
    @Override
    public FebsResponse refundOrder(AdminClothesRefundOrderDto dto) {
        ClothesOrder clothesOrder = clothesOrderMapper.selectById(dto.getId());
        if(ObjectUtil.isNull(clothesOrder)){
            return new FebsResponse().fail().message("订单不存在,刷新后重试");
        }
        Integer status = clothesOrder.getStatus();
        if(ClothesOrderStatusEnum.WAIT_SHIPPING.getValue() != status){
            return new FebsResponse().fail().message("订单不是待发货状态");
        }
 
        //退款订单编号
        String orderNo = clothesOrder.getOrderNo();
        //退款退款编号
        String refundNo = clothesOrder.getOrderNo()+"_REFUND_"+clothesOrder.getId();
        //退款订单金额
        BigDecimal orderAmount = clothesOrder.getRealAmount();
 
        //余额支付退款
        if(ClothesOrderPayTypeEnum.BALANCE.getName().equals(clothesOrder.getPayMethod())){
            log.info("余额支付退款");
            if(orderAmount.compareTo(BigDecimal.ZERO) > 0){
                //更新订单详情
                clothesUpdateStatusAndUpdateTimeById(clothesOrder.getId(),new Date(),ClothesOrderStatusEnum.CANCEL.getValue());
 
                memberWalletService.add(orderAmount, clothesOrder.getMemberId(), "balance");
                mallMoneyFlowService.addMoneyFlow(
                        clothesOrder.getMemberId(),
                        orderAmount,
                        ScoreFlowTypeEnum.REFUND.getValue(),
                        clothesOrder.getOrderNo(),
                        FlowTypeEnum.BALANCE.getValue(),
                        StrUtil.format(ScoreFlowTypeEnum.REFUND.getDesc(),orderAmount),
                        2
                );
            }
            return new FebsResponse().success().message("退款成功");
        }else if(ClothesOrderPayTypeEnum.WECHAT.getName().equals(clothesOrder.getPayMethod())){
 
            int refundMoney = orderAmount.multiply(new BigDecimal(100)).intValue();
            Boolean flag = weChatRefundOrderEvent(refundMoney, orderAmount, orderNo, refundNo);
            if(flag){
                if(orderAmount.compareTo(BigDecimal.ZERO) > 0){
                    //更新订单详情
                    clothesUpdateStatusAndUpdateTimeById(clothesOrder.getId(),new Date(),ClothesOrderStatusEnum.CANCEL.getValue());
 
                    mallMoneyFlowService.addMoneyFlow(
                            clothesOrder.getMemberId(),
                            orderAmount,
                            ScoreFlowTypeEnum.WECHAT_REFUND.getValue(),
                            clothesOrder.getOrderNo(),
                            FlowTypeEnum.BALANCE.getValue(),
                            StrUtil.format(ScoreFlowTypeEnum.WECHAT_REFUND.getDesc(),orderAmount),
                            2
                    );
                }
            }else{
                return new FebsResponse().fail().message("退款失败,请联系客服人员");
            }
        }else{
            return new FebsResponse().fail().message("退款失败,请联系客服人员");
        }
 
        return new FebsResponse().success().message("退款成功");
    }
 
    @Override
    public void confirmOrder(long orderId) {
        ClothesOrder clothesOrder = clothesOrderMapper.selectById(orderId);
        if(ObjectUtil.isNotNull(clothesOrder) && ClothesOrderStatusEnum.WAIT_FINISH.getValue() == clothesOrder.getStatus()){
            clothesUpdateStatusAndUpdateTimeById(clothesOrder.getId(),new Date(),ClothesOrderStatusEnum.FINISH.getValue());
        }
    }
 
    @Override
    public void exportOrderList(List<Long> orderIds, HttpServletResponse response) throws IOException {
        List<ExcelSheetPO> res = new ArrayList<>();
 
        ExcelSheetPO orderSheet = new ExcelSheetPO();
        String title = "订单列表";
        orderSheet.setSheetName(title);
        orderSheet.setTitle(title);
        String[] header = {"订单ID", "订单编号", "收货姓名", "收货电话", "收货地址", "商品详情", "备注", "物流单号", "物流公司", "物流公司码"};
        orderSheet.setHeaders(header);
 
        QueryRequest request = new QueryRequest();
        request.setPageNum(1);
        request.setPageSize(9999);
        List<ClothesOrder> dataList = clothesOrderMapper.selectList(
                Wrappers.lambdaQuery(ClothesOrder.class)
                        .in(ClothesOrder::getId, orderIds)
                        .eq(ClothesOrder::getDelFlag, 0)
                        .eq(ClothesOrder::getStatus, ClothesOrderStatusEnum.WAIT_SHIPPING.getValue()));
        Map<Long, ClothesType> longClothesTypeHashMap = new HashMap<>();
        if(CollUtil.isNotEmpty(dataList)){
            Set<Long> typeIds = dataList.stream().map(ClothesOrder::getTypeId).collect(Collectors.toSet());
            List<ClothesType> clothesTypes = clothesTypeMapper.selectList(
                    Wrappers.lambdaQuery(ClothesType.class)
                            .in(ClothesType::getId, typeIds)
            );
            if(CollUtil.isNotEmpty(clothesTypes)){
                //stream操作clothesTypes,返回一个HashMap<Long, ClothesType>, key为clothesType.id, value为clothesType
                longClothesTypeHashMap = clothesTypes.stream().collect(Collectors.toMap(ClothesType::getId, clothesType -> clothesType));
            }
        }
 
        List<List<Object>> list = new ArrayList<>();
 
        if (dataList.size() > 0) {
            for (ClothesOrder item : dataList) {
                List<Object> temp = new ArrayList<>();
                temp.add(item.getId());
                temp.add(item.getOrderNo());
                temp.add(item.getName());
                temp.add(item.getPhone());
                temp.add(item.getAddress());
                temp.add(longClothesTypeHashMap.get(item.getTypeId()).getName());
                temp.add(item.getRemark());
                list.add(temp);
            }
        }
        orderSheet.setDataList(list);
        res.add(orderSheet);
        response = ResponseHeadUtil.setExcelHead(response);
        response.setHeader("Content-Disposition",
                "attachment;filename=" + URLEncoder.encode(title + DateUtil.format(new Date(), "yyyyMMDDHHmmss") + ".xlsx".trim(), "UTF-8"));
        OutputStream os = response.getOutputStream();
        ExcelUtil.createWorkbookAtOutStream(ExcelVersion.V2007, res, os, true);
    }
 
    @Override
    public void deliverGoodsImport(AdminClothesDeliverGoodsDto dto) {
        ClothesOrder clothesOrder = clothesOrderMapper.selectById(dto.getId());
 
        if(ObjectUtil.isNull(clothesOrder)){
            return;
        }
        Integer status = clothesOrder.getStatus();
        if(ClothesOrderStatusEnum.WAIT_SHIPPING.getValue() != status){
            return;
        }
        String expressNo = dto.getExpressNo();
        if(StrUtil.isEmpty(expressNo)){
            return;
        }
        String expressCom = dto.getExpressCom();
        if(StrUtil.isEmpty(expressCom)){
            return;
        }
        mallExpressInfoMapper.update(
                null,
                Wrappers.lambdaUpdate(MallExpressInfo.class)
                        .set(MallExpressInfo::getExpressNo, expressNo)
                        .set(MallExpressInfo::getExpressCom, expressCom)
                        .eq(MallExpressInfo::getOrderId, clothesOrder.getId())
                        .eq(MallExpressInfo::getOrderNo, clothesOrder.getOrderNo())
        );
 
        clothesOrderMapper.update(
                null,
                Wrappers.lambdaUpdate(ClothesOrder.class)
                        .set(ClothesOrder::getStatus, ClothesOrderStatusEnum.WAIT_FINISH.getValue())
                        .set(ClothesOrder::getUpdatedTime, new Date())
                        .set(ClothesOrder::getDeliveryState, OrderDeliveryStateEnum.DELIVERY_ING.getValue())
                        .eq(ClothesOrder::getId, clothesOrder.getId())
        );
    }
}