KKSU
2023-12-11 b6ad0f29932c0a4f6053a765723aa4d80adcc706
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
package cc.mrbird.febs.mall.service.impl;
 
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.common.enumerates.DataDictionaryEnum;
import cc.mrbird.febs.common.enumerates.FlowTypeNewEnum;
import cc.mrbird.febs.common.enumerates.MoneyFlowTypeNewEnum;
import cc.mrbird.febs.common.enumerates.ProductEnum;
import cc.mrbird.febs.common.exception.FebsException;
import cc.mrbird.febs.common.utils.LoginUserUtil;
import cc.mrbird.febs.common.utils.MallUtils;
import cc.mrbird.febs.mall.dto.*;
import cc.mrbird.febs.mall.entity.*;
import cc.mrbird.febs.mall.mapper.*;
import cc.mrbird.febs.mall.service.IApiMallProductService;
import cc.mrbird.febs.mall.service.IMallMoneyFlowService;
import cc.mrbird.febs.mall.vo.*;
import cc.mrbird.febs.rabbit.producter.AgentProducer;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
 
@Slf4j
@Service
@RequiredArgsConstructor
public class ApiMallProductServiceImpl extends ServiceImpl<MallProductNftMapper, MallProductNft> implements IApiMallProductService {
 
    private final MallMemberMapper memberMapper;
    private final MallProductBuyMapper mallProductBuyMapper;
    private final MallMemberAmountMapper mallMemberAmountMapper;
    private final IMallMoneyFlowService iMallMoneyFlowService;
    private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
    private final AgentProducer agentProducer;
    private final MallProductSellMapper mallProductSellMapper;
    private final MallProductSellRecordMapper mallProductSellRecordMapper;
    private final MallProductBuyRecordMapper mallProductBuyRecordMapper;
    private final MallMemberSpeakMapper mallMemberSpeakMapper;
 
    @Override
    public List<ApiMallProductNftVo> productNFTList() {
 
        DateTime nowTime = DateUtil.parseTime(DateUtil.formatTime(DateUtil.date()));
        DataDictionaryCustom startTimeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.YU_YUE_START_TIME.getType(),
                DataDictionaryEnum.YU_YUE_START_TIME.getCode()
        );
        DateTime startTime = DateUtil.parseTime(startTimeDic.getValue());
        DataDictionaryCustom endTimeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.YU_YUE_END_TIME.getType(),
                DataDictionaryEnum.YU_YUE_END_TIME.getCode()
        );
        DateTime endTime = DateUtil.parseTime(endTimeDic.getValue());
        List<ApiMallProductNftVo> list = this.baseMapper.selectByState(ProductEnum.PRODUCT_NFT_OPEN.getValue());
        if(CollUtil.isNotEmpty(list)){
            for(ApiMallProductNftVo apiMallProductNftVo : list){
                if(nowTime.compareTo(startTime) < 0){
                    apiMallProductNftVo.setYuYueState(1);
                }
                if(nowTime.compareTo(startTime) >= 0 && nowTime.compareTo(endTime) <= 0){
                    apiMallProductNftVo.setYuYueState(2);
                }
                if(nowTime.compareTo(endTime) > 0){
                    apiMallProductNftVo.setYuYueState(3);
                }
            }
        }
        return list;
    }
 
    @Override
    @Transactional
    public FebsResponse createNFT(ApiCreateNFTDto createNFTDto) {
        Long memberId = LoginUserUtil.getLoginUser().getId();
        MallMember mallMember = memberMapper.selectById(memberId);
        Long productNFTId = createNFTDto.getId();
        String tradePassword = SecureUtil.md5(createNFTDto.getTradePassword());
        /**
         * 预约,验证交易密码、预约产品是否开启状态、该产品是否已经预约、token是否足够
         * 冻结对应的令牌数量、生成预约记录、生成流水记录
         */
        Boolean aBoolean = operationPermissionMemberFrozen(memberId);
        if(aBoolean){
            throw new FebsException("用户已冻结");
        }
 
        DateTime nowTime = DateUtil.parseTime(DateUtil.formatTime(DateUtil.date()));
        DataDictionaryCustom startTimeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.YU_YUE_START_TIME.getType(),
                DataDictionaryEnum.YU_YUE_START_TIME.getCode()
        );
        DateTime startTime = DateUtil.parseTime(startTimeDic.getValue());
        DataDictionaryCustom endTimeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.YU_YUE_END_TIME.getType(),
                DataDictionaryEnum.YU_YUE_END_TIME.getCode()
        );
        DateTime endTime = DateUtil.parseTime(endTimeDic.getValue());
        if(!(nowTime.compareTo(startTime) >= 0 && nowTime.compareTo(endTime) <= 0)){
            throw new FebsException("预约未开始");
        }
        if(!tradePassword.equals(mallMember.getTradePassword())){
            throw new FebsException("请输入正确的交易密码");
        }
        MallProductNft mallProductNft = this.baseMapper.selectById(productNFTId);
        if(ObjectUtil.isEmpty(mallProductNft)){
            throw new FebsException("网络异常");
        }
        if(ProductEnum.PRODUCT_NFT_OPEN.getValue() != mallProductNft.getState()){
            throw new FebsException("预约超时");
        }
        MallProductBuy mallProductBuy = mallProductBuyMapper.selectMemberIdAndNFTIdAndStateAndMateState(
                memberId,productNFTId,ProductEnum.PRODUCT_BUY_ON_GOING.getValue(),ProductEnum.PRODUCT_BUY_MATE_STATE_FAIL.getValue());
        if(ObjectUtil.isNotEmpty(mallProductBuy)){
            throw new FebsException("不可重复预约");
        }
 
        BigDecimal priceToken = mallProductNft.getPriceToken();
        MallMemberAmount mallMemberAmount = mallMemberAmountMapper.selectByMemberId(memberId);
        if(BigDecimal.ZERO.compareTo(mallMemberAmount.getTokenAva()) >= 0
         || priceToken.compareTo(mallMemberAmount.getTokenAva()) > 0){
            throw new FebsException("余额不足");
        }
 
        String orderNo = MallUtils.getOrderNum("YY");
        mallProductBuy = new MallProductBuy();
        mallProductBuy.setMemberId(memberId);
        mallProductBuy.setOrderNo(orderNo);
        mallProductBuy.setProductNftId(mallProductNft.getId());
        mallProductBuy.setState(ProductEnum.PRODUCT_BUY_ON_GOING.getValue());
        mallProductBuy.setMateState(ProductEnum.PRODUCT_BUY_MATE_STATE_FAIL.getValue());
        mallProductBuy.setNftTotal(mallProductNft.getPriceNft());
        mallProductBuy.setNftAva(mallProductNft.getPriceNft());
//        mallProductBuy.setNftAva(BigDecimal.ZERO);
        mallProductBuyMapper.insert(mallProductBuy);
        //令牌 可用减少,冻结增加
        mallMemberAmount.setTokenAva(mallMemberAmount.getTokenAva().subtract(priceToken));
        mallMemberAmount.setTokenFrozen(mallMemberAmount.getTokenFrozen().add(priceToken));
        mallMemberAmountMapper.updateTokenAvaAndTokenFrozenById(mallMemberAmount);
        iMallMoneyFlowService.addMoneyFlow(
                memberId,
                priceToken.negate(),
                MoneyFlowTypeNewEnum.TOKEN_BUY_FROZEN.getValue(),
                orderNo,
                null,
                FlowTypeNewEnum.TOKEN.getValue(),
                MoneyFlowTypeNewEnum.TOKEN_BUY_FROZEN.getDescrition());
        return new FebsResponse().success();
    }
 
    @Override
    @Transactional
    public FebsResponse outFcm(ApiOutFcmDto outFcmDto) {
        Long memberId = LoginUserUtil.getLoginUser().getId();
        MallMember mallMember = memberMapper.selectById(memberId);
        String tradePassword = SecureUtil.md5(outFcmDto.getTradePassword());
        /**
         * 实时兑换FCM-to-NFT
         * 验证账户交易密码,fcm余额
         * 计算手续费、减少用户的fcm余额
         * 增加流水
         */
 
        Boolean aBoolean = operationPermissionMemberFrozen(memberId);
        if(aBoolean){
            throw new FebsException("用户已冻结");
        }
        if(!tradePassword.equals(mallMember.getTradePassword())){
            throw new FebsException("请输入正确的交易密码");
        }
        BigDecimal fcmCnt = outFcmDto.getFcmCnt();
        DataDictionaryCustom outFcmMinDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.OUT_FCM_MIN.getType(),
                DataDictionaryEnum.OUT_FCM_MIN.getCode());
        BigDecimal outFcmMin = ObjectUtil.isEmpty(outFcmMinDic) ? new BigDecimal(100) : new BigDecimal(outFcmMinDic.getValue());
        if(outFcmMin.compareTo(fcmCnt) > 0){
            throw new FebsException("最少"+outFcmMin);
        }
        MallMemberAmount mallMemberAmount = mallMemberAmountMapper.selectByMemberId(memberId);
        if(BigDecimal.ZERO.compareTo(mallMemberAmount.getFcmCntAva()) >= 0
                || fcmCnt.compareTo(mallMemberAmount.getTokenAva()) > 0){
            throw new FebsException("余额不足");
        }
        DataDictionaryCustom fcmPriceDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.FCM_PRICE.getType(),
                DataDictionaryEnum.FCM_PRICE.getCode());
        BigDecimal fcmPrice = ObjectUtil.isEmpty(fcmPriceDic) ? new BigDecimal(2) : new BigDecimal(fcmPriceDic.getValue());
        //手续费
        DataDictionaryCustom outFcmFeeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.OUT_FCM_FEE.getType(),
                DataDictionaryEnum.OUT_FCM_FEE.getCode());
        BigDecimal outFcmFeePercent = ObjectUtil.isEmpty(outFcmFeeDic) ? new BigDecimal(20) : new BigDecimal(outFcmFeeDic.getValue());
        outFcmFeePercent = outFcmFeePercent.divide(new BigDecimal(100),4,BigDecimal.ROUND_DOWN);
        BigDecimal outFcmFee = fcmCnt.multiply(outFcmFeePercent);
        //实际到账数量
        BigDecimal fcmCntReal = fcmCnt.subtract(outFcmFee).setScale(2, BigDecimal.ROUND_DOWN);
 
        BigDecimal nftCnt = fcmCntReal.multiply(fcmPrice);
 
        mallMemberAmount.setFcmCntAva(mallMemberAmount.getFcmCntAva().subtract(fcmCnt));
        mallMemberAmountMapper.updateFcmCntAvaById(mallMemberAmount);
        String orderNo = MallUtils.getOrderNum("DB");
        iMallMoneyFlowService.addMoneyFlow(
                memberId,
                fcmCnt.negate(),
                MoneyFlowTypeNewEnum.FCM_OUT.getValue(),
                orderNo,
                mallMember.getId(),
                FlowTypeNewEnum.FCM_COIN.getValue(),
                MoneyFlowTypeNewEnum.FCM_OUT.getDescrition());
        iMallMoneyFlowService.addMoneyFlow(
                memberId,
                outFcmFee.negate(),
                MoneyFlowTypeNewEnum.FCM_OUT_FEE.getValue(),
                orderNo,
                mallMember.getId(),
                FlowTypeNewEnum.FCM_COIN.getValue(),
                MoneyFlowTypeNewEnum.FCM_OUT_FEE.getDescrition());
 
        MallMemberAmount mallMemberAmountNft = mallMemberAmountMapper.selectByMemberId(memberId);
        mallMemberAmountNft.setTrendsNft(mallMemberAmountNft.getTrendsNft().add(nftCnt));
        mallMemberAmountMapper.updateTrendsNftById(mallMemberAmountNft);
        String orderNoNFT = MallUtils.getOrderNum("NFT");
        iMallMoneyFlowService.addMoneyFlow(
                memberId,
                nftCnt,
                MoneyFlowTypeNewEnum.NFT_IN.getValue(),
                orderNoNFT,
                mallMember.getId(),
                FlowTypeNewEnum.NFT.getValue(),
                MoneyFlowTypeNewEnum.NFT_IN.getDescrition());
 
        agentProducer.sendFcmNFTExchangeMsg(outFcmFee.toString());
        return new FebsResponse().success();
    }
 
    @Override
    @Transactional
    public FebsResponse outNFT(ApiOutNFTDto outNFTDto) {
        Long memberId = LoginUserUtil.getLoginUser().getId();
        MallMember mallMember = memberMapper.selectById(memberId);
        String tradePassword = SecureUtil.md5(outNFTDto.getTradePassword());
        /**
         * 验证数量、交易密码、NFT余额
         * 计算手续费、减少动态NFT、增加冻结NFT
         * 增加流水
         */
 
        Boolean aBoolean = operationPermissionMemberFrozen(memberId);
        if(aBoolean){
            throw new FebsException("用户已冻结");
        }
        if(!tradePassword.equals(mallMember.getTradePassword())){
            throw new FebsException("请输入正确的交易密码");
        }
        BigDecimal nftCnt = outNFTDto.getNftCnt();
        DataDictionaryCustom nftMinDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.NFT_MIN.getType(),
                DataDictionaryEnum.NFT_MIN.getCode());
        BigDecimal nftMin = ObjectUtil.isEmpty(nftMinDic) ? new BigDecimal(100) : new BigDecimal(nftMinDic.getValue());
        if(nftMin.compareTo(nftCnt) > 0){
            throw new FebsException("最少"+nftMin);
        }
        MallMemberAmount mallMemberAmount = mallMemberAmountMapper.selectByMemberId(memberId);
        if(BigDecimal.ZERO.compareTo(mallMemberAmount.getTrendsNft()) >= 0
                || nftCnt.compareTo(mallMemberAmount.getTrendsNft()) > 0){
            throw new FebsException("余额不足");
        }
        DataDictionaryCustom nftFeeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.NFT_FEE.getType(),
                DataDictionaryEnum.NFT_FEE.getCode());
        BigDecimal nftFeePercent = ObjectUtil.isEmpty(nftFeeDic) ? new BigDecimal(20) : new BigDecimal(nftFeeDic.getValue());
        nftFeePercent = nftFeePercent.divide(new BigDecimal(100),4,BigDecimal.ROUND_DOWN);
        BigDecimal nftFee = nftCnt.multiply(nftFeePercent);
        DataDictionaryCustom fcmPriceDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.FCM_PRICE.getType(),
                DataDictionaryEnum.FCM_PRICE.getCode());
        BigDecimal fcmPrice = ObjectUtil.isEmpty(fcmPriceDic) ? new BigDecimal(2) : new BigDecimal(fcmPriceDic.getValue());
        BigDecimal fcmFeeCnt = nftFee.divide(fcmPrice, 2, BigDecimal.ROUND_DOWN);
        if(BigDecimal.ZERO.compareTo(mallMemberAmount.getTrendsNft()) >= 0
            || fcmFeeCnt.compareTo(mallMemberAmount.getFcmCntAva()) > 0){
            throw new FebsException("手续费不足");
        }
 
        String orderNo = MallUtils.getOrderNum("NFT");
        MallProductSell mallProductSell = new MallProductSell();
        mallProductSell.setMemberId(memberId);
        mallProductSell.setOrderNo(orderNo);
        mallProductSell.setNftTotal(nftCnt);
        mallProductSell.setNftCnt(nftCnt);
        mallProductSell.setNftCntAva(nftCnt);
        mallProductSell.setNftFee(nftFee);
        mallProductSell.setFcmFee(fcmFeeCnt);
        mallProductSell.setState(ProductEnum.PRODUCT_SELL_ON_GOING.getValue());
        mallProductSellMapper.insert(mallProductSell);
 
        mallMemberAmount.setTrendsNft(mallMemberAmount.getTrendsNft().subtract(nftCnt));
        mallMemberAmountMapper.updateTrendsNftById(mallMemberAmount);
 
        MallMemberAmount mallMemberAmountFcm = mallMemberAmountMapper.selectByMemberId(memberId);
        mallMemberAmountFcm.setFcmCntAva(mallMemberAmountFcm.getFcmCntAva().subtract(fcmFeeCnt));
        mallMemberAmountMapper.updateFcmCntAvaById(mallMemberAmountFcm);
 
        MallMemberAmount mallMemberAmountFrozenNFT = mallMemberAmountMapper.selectByMemberId(memberId);
        mallMemberAmountFrozenNFT.setFrozenNft(mallMemberAmountFrozenNFT.getFrozenNft().add(nftCnt));
        mallMemberAmountMapper.updateFrozenNftById(mallMemberAmountFrozenNFT);
        iMallMoneyFlowService.addMoneyFlow(
                memberId,
                nftCnt.negate(),
                MoneyFlowTypeNewEnum.NFT_OUT.getValue(),
                orderNo,
                mallMember.getId(),
                FlowTypeNewEnum.NFT.getValue(),
                MoneyFlowTypeNewEnum.NFT_OUT.getDescrition());
        iMallMoneyFlowService.addMoneyFlow(
                memberId,
                fcmFeeCnt.negate(),
                MoneyFlowTypeNewEnum.NFT_OUT_FEE_FCM.getValue(),
                orderNo,
                mallMember.getId(),
                FlowTypeNewEnum.FCM_COIN.getValue(),
                MoneyFlowTypeNewEnum.NFT_OUT_FEE_FCM.getDescrition());
        agentProducer.sendFcmNFTExchangeMsg(fcmFeeCnt.toString());
        return new FebsResponse().success();
    }
 
    public static void main(String[] args) {
        DateTime dateTime = DateUtil.parseTime("15:00:00");
        DateTime dateTime2 = DateUtil.parseTime("19:00:00");
        DateTime dateTime1 = DateUtil.parseTime(DateUtil.formatTime(DateUtil.date()));
        System.out.println(dateTime);
        System.out.println(dateTime1);
        System.out.println(dateTime1.compareTo(dateTime));
        System.out.println(dateTime1.compareTo(dateTime2));
        System.out.println(dateTime1.compareTo(dateTime) >= 0 && dateTime1.compareTo(dateTime2) <= 0);
    }
 
    @Override
    public FebsResponse orderList(ApiOrderListDto apiOrderListDto) {
        Long memberId = LoginUserUtil.getLoginUser().getId();
        List<ApiOrderListVo> objects = new ArrayList<>();
        Integer orderType = apiOrderListDto.getOrderType();
        apiOrderListDto.setMemberId(memberId);
        DateTime nowTime = DateUtil.parseTime(DateUtil.formatTime(DateUtil.date()));
        DataDictionaryCustom startTimeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.YU_YUE_START_TIME.getType(),
                DataDictionaryEnum.YU_YUE_START_TIME.getCode()
        );
        DateTime startTime = DateUtil.parseTime(startTimeDic.getValue());
        DataDictionaryCustom endTimeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.YU_YUE_END_TIME.getType(),
                DataDictionaryEnum.YU_YUE_END_TIME.getCode()
        );
        DateTime endTime = DateUtil.parseTime(endTimeDic.getValue());
        if(nowTime.compareTo(startTime) >= 0 && nowTime.compareTo(endTime) <= 0){
            //买单
            if(2 == orderType){
                IPage<ApiOrderListVo> page = new Page<>(apiOrderListDto.getPageNum(), apiOrderListDto.getPageSize());
                IPage<ApiOrderListVo> apiOrderListVoIPageBuy = mallProductBuyMapper.selectListInPage(page, apiOrderListDto);
                if(CollUtil.isNotEmpty(apiOrderListVoIPageBuy.getRecords())){
                    for(ApiOrderListVo apiOrderListVo : apiOrderListVoIPageBuy.getRecords()){
                        objects.add(apiOrderListVo);
                    }
                }
            }
            //卖单
            if(1 == orderType){
                IPage<ApiOrderListVo> page = new Page<>(apiOrderListDto.getPageNum(), apiOrderListDto.getPageSize());
                IPage<ApiOrderListVo> apiOrderListVoIPageSell = mallProductSellMapper.selectListInPage(page, apiOrderListDto);
                if(CollUtil.isNotEmpty(apiOrderListVoIPageSell.getRecords())){
                    for(ApiOrderListVo apiOrderListVo : apiOrderListVoIPageSell.getRecords()){
                        objects.add(apiOrderListVo);
                    }
                }
            }
        }
 
        return new FebsResponse().success().data(objects);
    }
 
    @Override
    public FebsResponse orderSell(ApiOrderSellInfoDto apiOrderSellInfoDto) {
        Long productSellId = apiOrderSellInfoDto.getId();
        Long memberId = LoginUserUtil.getLoginUser().getId();
        ApiOrderSellInfoVo apiOrderSellInfoVo = mallProductSellMapper.selectSellInfoById(productSellId);
        if(ObjectUtil.isEmpty(apiOrderSellInfoVo)){
            throw new FebsException("记录不存在");
        }
        List<ApiOrderSellRecordInfoVo> apiOrderSellRecordInfoVos = mallProductSellRecordMapper.selectBySellId(productSellId);
        if(CollUtil.isNotEmpty(apiOrderSellRecordInfoVos)){
            apiOrderSellInfoVo.setApiOrderSellRecordInfoVos(apiOrderSellRecordInfoVos);
        }
        return new FebsResponse().success().data(apiOrderSellInfoVo);
    }
 
    @Override
    public FebsResponse orderBuy(ApiOrderBuyInfoDto apiOrderBuyInfoDto) {
        Long productBuyId = apiOrderBuyInfoDto.getId();
        Long memberId = LoginUserUtil.getLoginUser().getId();
        ApiOrderBuyInfoVo apiOrderBuyInfoVo = mallProductBuyMapper.selectBuyById(productBuyId);
        if(ObjectUtil.isEmpty(apiOrderBuyInfoVo)){
            throw new FebsException("记录不存在");
        }
        List<ApiOrderBuyRecordInfoVo> apiOrderBuyRecordInfoVos = mallProductBuyRecordMapper.selectByBuyId(productBuyId);
        if(CollUtil.isNotEmpty(apiOrderBuyRecordInfoVos)){
            apiOrderBuyInfoVo.setApiOrderBuyRecordInfoVos(apiOrderBuyRecordInfoVos);
        }
        return new FebsResponse().success().data(apiOrderBuyInfoVo);
    }
 
    @Override
    public FebsResponse orderBuyInsure(ApiOrderBuyInsureDto apiOrderBuyInsureDto) {
        Long memberId = LoginUserUtil.getLoginUser().getId();
        MallMember mallMember = memberMapper.selectById(memberId);
        Long buyRecordId = apiOrderBuyInsureDto.getBuyRecordId();
        String nftImg = apiOrderBuyInsureDto.getNftImg();
        Integer type = apiOrderBuyInsureDto.getType();
        String tradePassword = SecureUtil.md5(apiOrderBuyInsureDto.getTradePassword());
        /**
         * 验证订单是否存在
         * 更新买单状态
         * 更新卖单状态
         * 生成流水信息
         */
 
        Boolean aBoolean = operationPermissionMemberFrozen(memberId);
        if(aBoolean){
            throw new FebsException("用户已冻结");
        }
        if(!tradePassword.equals(mallMember.getTradePassword())){
            throw new FebsException("请输入正确的交易密码");
        }
        MallProductBuyRecord mallProductBuyRecord = mallProductBuyRecordMapper.selectById(buyRecordId);
        if(ObjectUtil.isEmpty(mallProductBuyRecord)){
            throw new FebsException("记录不存在");
        }
        Integer state = mallProductBuyRecord.getState();
        if(ProductEnum.PRODUCT_MATE_STATE_WAIT_PAY.getValue() != state){
            throw new FebsException("记录不是待支付状态");
        }
 
        MallProductSellRecord mallProductSellRecord = mallProductSellRecordMapper.selectById(mallProductBuyRecord.getSellRecordId());
        if(ObjectUtil.isEmpty(mallProductSellRecord)){
            throw new FebsException("记录不存在");
        }
        Integer stateSell = mallProductSellRecord.getState();
        if(ProductEnum.PRODUCT_MATE_STATE_WAIT_PAY.getValue() != stateSell){
            throw new FebsException("记录不是待支付状态");
        }
 
        DateTime payTime = DateUtil.date();
        mallProductBuyRecord.setState(ProductEnum.PRODUCT_MATE_STATE_PAY.getValue());
        mallProductBuyRecord.setPayTime(payTime);
        mallProductBuyRecord.setNftImg(nftImg);
        mallProductBuyRecord.setType(type);
        mallProductBuyRecordMapper.updateById(mallProductBuyRecord);
 
        mallProductSellRecord.setState(ProductEnum.PRODUCT_MATE_STATE_PAY.getValue());
        mallProductSellRecord.setPayTime(payTime);
        mallProductSellRecord.setNftImg(nftImg);
        mallProductSellRecord.setType(type);
        mallProductSellRecordMapper.updateById(mallProductSellRecord);
 
        String orderNo = MallUtils.getOrderNum("ZF");
        iMallMoneyFlowService.addMoneyFlow(
                memberId,
                mallProductBuyRecord.getPickNftCnt(),
                MoneyFlowTypeNewEnum.PAY.getValue(),
                orderNo,
                mallMember.getId(),
                FlowTypeNewEnum.NFT.getValue(),
                MoneyFlowTypeNewEnum.PAY.getDescrition());
        return new FebsResponse().success();
    }
 
    @Override
    public FebsResponse orderSellInsure(ApiOrderSellInsureDto apiOrderSellInsureDto) {
        Long memberId = LoginUserUtil.getLoginUser().getId();
        MallMember mallMember = memberMapper.selectById(memberId);
        String tradePassword = SecureUtil.md5(apiOrderSellInsureDto.getTradePassword());
        Long sellRecordId = apiOrderSellInsureDto.getSellRecordId();
        /**
         * 验证订单是否存在
         * 更新买单状态
         * 更新卖单状态
         * 生成流水信息
         */
 
        Boolean aBoolean = operationPermissionMemberFrozen(memberId);
        if(aBoolean){
            throw new FebsException("用户已冻结");
        }
        if(!tradePassword.equals(mallMember.getTradePassword())){
            throw new FebsException("请输入正确的交易密码");
        }
        MallProductSellRecord mallProductSellRecord = mallProductSellRecordMapper.selectById(sellRecordId);
        if(ObjectUtil.isEmpty(mallProductSellRecord)){
            throw new FebsException("记录不存在");
        }
        Integer stateSell = mallProductSellRecord.getState();
        if(ProductEnum.PRODUCT_MATE_STATE_PAY.getValue() != stateSell){
            throw new FebsException("记录不是已支付状态");
        }
 
        MallProductBuyRecord mallProductBuyRecord = mallProductBuyRecordMapper.selectById(mallProductSellRecord.getBuyRecordId());
        if(ObjectUtil.isEmpty(mallProductBuyRecord)){
            throw new FebsException("记录不存在");
        }
        Integer state = mallProductBuyRecord.getState();
        if(ProductEnum.PRODUCT_MATE_STATE_PAY.getValue() != state){
            throw new FebsException("记录不是已支付状态");
        }
 
        mallProductBuyRecord.setState(ProductEnum.PRODUCT_MATE_STATE_CONFIRM.getValue());
        mallProductBuyRecordMapper.updateById(mallProductBuyRecord);
 
        mallProductSellRecord.setState(ProductEnum.PRODUCT_MATE_STATE_CONFIRM.getValue());
        mallProductSellRecordMapper.updateById(mallProductSellRecord);
 
        agentProducer.sendFcmOrderSellInsureMsg(sellRecordId);
        return new FebsResponse().success();
    }
 
    @Override
    public FebsResponse orderBuyList(ApiOrderBuyDto apiOrderBuyDto) {
        Long memberId = LoginUserUtil.getLoginUser().getId();
        IPage<ApiOrderBuyVo> page = new Page<>(apiOrderBuyDto.getPageNum(), apiOrderBuyDto.getPageSize());
        apiOrderBuyDto.setMemberId(memberId);
        IPage<ApiOrderBuyVo> apiOrderBuyVoIPage = mallProductBuyMapper.selectBuyListInPage(page, apiOrderBuyDto);
        return new FebsResponse().success().data(apiOrderBuyVoIPage);
    }
 
    @Override
    public Boolean operationPermissionMemberFrozen(Long memberId) {
        MallMember mallMember = memberMapper.selectById(memberId);
        if(ProductEnum.MEMBER_FROZEN.getValue() == mallMember.getIsFrozen()){
            return true;
        }
        return false;
    }
 
    @Override
    public FebsResponse orderSellComplain(ApiOrderSellComplainDto apiOrderSellComplainDto) {
        Long memberId = LoginUserUtil.getLoginUser().getId();
        Long sellRecordId = apiOrderSellComplainDto.getSellRecordId();
        MallProductSellRecord mallProductSellRecord = mallProductSellRecordMapper.selectById(sellRecordId);
        if(ObjectUtil.isEmpty(mallProductSellRecord)){
            throw new FebsException("记录不存在");
        }
 
        MallProductBuyRecord mallProductBuyRecord = mallProductBuyRecordMapper.selectById(mallProductSellRecord.getBuyRecordId());
        if(ObjectUtil.isEmpty(mallProductBuyRecord)){
            throw new FebsException("记录不存在");
        }
 
        mallProductBuyRecord.setState(ProductEnum.PRODUCT_MATE_STATE_COMPLAIN.getValue());
        mallProductBuyRecordMapper.updateById(mallProductBuyRecord);
 
        mallProductSellRecord.setState(ProductEnum.PRODUCT_MATE_STATE_COMPLAIN.getValue());
        mallProductSellRecordMapper.updateById(mallProductSellRecord);
 
        MallMemberSpeak mallMemberSpeak = new MallMemberSpeak();
        mallMemberSpeak.setMemberId(memberId);
        mallMemberSpeak.setState(ProductEnum.SPEAK_NO_DEAL.getValue());
        String description = apiOrderSellComplainDto.getDescription();
        String buyOrderNo = mallProductBuyRecord.getBuyOrderNo();
        mallMemberSpeak.setDescription("编号:"+buyOrderNo+","+description);
        mallMemberSpeakMapper.insert(mallMemberSpeak);
        return new FebsResponse().success();
    }
}