zj
2025-01-06 0e7b38c2b3af72ea2a7f8a2fcbaad4d78e2c1977
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
package com.gear.customer.swx.biz.impl;
 
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gear.common.constant.SwxConstons;
import com.gear.common.core.redis.RedisCache;
import com.gear.common.exception.CustomerException;
import com.gear.customer.swx.biz.SwxBizOrder;
import com.gear.customer.swx.config.DelayQueueRabbitConfig;
import com.gear.customer.swx.vo.request.SwxBuyOptionsVo;
import com.gear.customer.swx.vo.request.SwxBuySmartVo;
import com.gear.customer.swx.vo.response.SwxBuyOptionsInfo;
import com.gear.customer.swx.vo.response.SwxUserInfoVo;
import com.gear.swx.domain.*;
import com.gear.swx.service.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.concurrent.TimeUnit;
 
@Component
@Slf4j
public class SwxBizOrderImpl implements SwxBizOrder {
 
    private static final Logger lg = LoggerFactory.getLogger("orderFile");
    private static final Logger logger = LoggerFactory.getLogger(SwxBizOrderImpl.class);
 
    @Autowired
    private ISwxSmartOrderService swxSmartOrderService;
 
    @Autowired
    private ISwxUserService swxUserService;
 
    @Autowired
    private ISwxMarketService swxMarketService;
 
    @Autowired
    private ISwxMarketSmartService swxMarketSmartService;
 
    @Autowired
    private ISwxMoneyLogService swxMoneyLogService;
 
    @Autowired
    private ISwxOrderService swxOrderService;
 
    @Autowired
    private ISwxOptionsOrderService swxOptionsOrderService;
 
    @Autowired
    private ISwxMarketOptionsService swxMarketOptionsService;
 
    @Autowired
    private RedisCache redisCache;
 
    @Autowired
    private ISwxSettingsService swxSettingsService;
 
    @Autowired
    RabbitTemplate rabbitTemplate;
    @Autowired
    private ISwxUserLevelService swxUserLevelService;
    @Override
    public String buySmart(SwxBuySmartVo vo, String userId, String virtually) throws CustomerException {
 
        if (!SwxConstons.SWX_CUSTOMER_USER_ORDER_TYPE_TRUE.equals(virtually)){
            throw new CustomerException("10008");
        }
        //获取用户信息
        SwxUser swxUser = swxUserService.getById(userId);
        if (swxUser == null){
            throw new CustomerException("10009");
        }
        //获取产品
        SwxMarketSmart swxMarketSmart = swxMarketSmartService.getById(vo.getMarketId());
        if (swxMarketSmart == null || !Objects.equals(swxMarketSmart.getStatus(), SwxConstons.NOMARL_STATUS_YES)){
            throw new CustomerException("10010");
        }
        //当天是否存在相同订单
        if (swxSmartOrderService.checkRepeatOrder(userId, vo.getMarketId(), vo.getAllDay())) {
            //已购买相同产品,请勿重复购买
            throw new CustomerException("10024");
        }
        //获取用户是否有足够钱购买,用户余额为用户余额减保证金占用
        if((swxUser.getAmount().subtract(swxUser.getBondAmount())).compareTo(vo.getAmount()) < 0) {
            throw new CustomerException("10011");
        }
        String rateInfoStr = swxMarketSmart.getSmartInfo();
        BigDecimal rate = null;
        BigDecimal max = null;
        BigDecimal min = null;
        JSONArray jsonArray = JSONArray.parseArray(rateInfoStr);
        for(int i = 0; i < jsonArray.size(); i++){
            JSONObject object = jsonArray.getJSONObject(i);
            Integer days = object.getInteger("days");
            if (days.intValue() == vo.getAllDay().intValue()){
                rate = new BigDecimal(object.getString("rate"));
                max = new BigDecimal(object.getString("max"));
                min = new BigDecimal(object.getString("min"));
                break;
            }
        }
 
        if (rate == null || max == null || min == null){
            throw new CustomerException("10012");
        }
 
        if(vo.getAmount().compareTo(max) >0 || vo.getAmount().compareTo(min) < 0){
            throw new CustomerException("10013");
        }
        LocalDateTime localDateTime = LocalDateTime.now();
        LocalDateTime afterDays = localDateTime.plusDays(1);
        SwxSmartOrder swxSmartOrder = new SwxSmartOrder();
        BeanUtils.copyProperties(vo,swxSmartOrder);
        swxSmartOrder.setUserId(userId);
        swxSmartOrder.setMarketId(swxMarketSmart.getId());
        swxSmartOrder.setCurrentDay(0);
        swxSmartOrder.setBuyTime(new Date());
        swxSmartOrder.setRate(rate);
        swxSmartOrder.setNextProfitTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:00").format(Date.from(afterDays.atZone(ZoneId.systemDefault()).toInstant())));
        swxSmartOrder.setProfitType(swxMarketSmart.getProfitType());
        SwxMarket swxMarket = swxMarketService.getById(swxMarketSmart.getMId());
        swxSmartOrder.setMarketName(swxMarket.getAppName());
        swxSmartOrder.setMarketCode(swxMarket.getCode());
        swxSmartOrder.setAddRate(BigDecimal.ZERO);
        //获取加息
        if(!Strings.isEmpty(swxUser.getLevel())){
            SwxUserLevel userLevel = swxUserLevelService.getById(swxUser.getLevel());
            if (userLevel != null){
                swxSmartOrder.setAddRate(userLevel.getEquity1());
            }
        }
        lg.info("购买智能交易订单,产品id=‘{}’Rate=‘{}’", vo.getMarketId(), swxSmartOrder.getRate());
        //计算当期收益
        swxSmartOrder.setCurrentProfit(swxSmartOrder.getAmount().multiply(swxSmartOrder.getRate().add(swxSmartOrder.getAddRate())).divide(new BigDecimal(100)).multiply(BigDecimal.valueOf(swxSmartOrder.getAllDay())).setScale(2,BigDecimal.ROUND_HALF_UP));
        swxSmartOrderService.save(swxSmartOrder);
        //修改用户余额,插入资金日志
        SwxMoneyLog moneyLog = new SwxMoneyLog();
        moneyLog.setInfo("购买智能交易,产品为:"+swxMarketSmart.getMId()+",总额为:"+vo.getAmount()+"日利率为:"+vo.getRate());
        moneyLog.setStatus(SwxConstons.SWX_EXAMINE_STATUS_YES);
        moneyLog.setType(SwxConstons.SWX_MONEY_LOG_TYPE_BUY_SMART);
        moneyLog.setSymbol(SwxConstons.SWX_MONEY_TYPE_PAY);
        moneyLog.setTitle("购买智能交易");
        moneyLog.setOldAmount(swxUser.getAmount());
        swxUser.setAmount(swxUser.getAmount().subtract(vo.getAmount()));
        swxUserService.updateById(swxUser);
        moneyLog.setNowAmount(swxUser.getAmount());
        moneyLog.setUserId(swxUser.getId());
        moneyLog.setBusiId(vo.getId());
        moneyLog.setMoney(vo.getAmount());
        swxMoneyLogService.save(moneyLog);
 
        //插入订单总表
//        SwxOrder swxOrder = new SwxOrder();
//        swxOrder.setUserId(userId);
//        swxOrder.setType(SwxConstons.SWX_ORDER_TYPE_SMART);
//        swxOrder.setStatus(SwxConstons.SWX_ORDER_STATUS_SMART_WAIT);
//        swxOrder.setMId(swxMarketSmart.getMId());
//        swxOrder.setBuyType(SwxConstons.SWX_ORDER_BUY_TYPE_HY);
//        swxOrderService.save(swxOrder);
//        return "购买成功";
        return "20004";
    }
 
    @Override
    public IPage<SwxOrder> listOrder(String userId, String virtually,Integer pageNo,Integer pageSize) throws CustomerException {
        SwxUser swxUser = swxUserService.getById(userId);
        if (swxUser == null){
            throw new CustomerException("10009");
        }
        Page<SwxOrder> page = new Page<SwxOrder>(pageNo, pageSize);
        IPage<SwxOrder> pageList = swxOrderService.page(page, new QueryWrapper<SwxOrder>().lambda().eq(SwxOrder::getUserId,userId));
        return pageList;
    }
 
    @Override
    public IPage<SwxSmartOrder> listSmartOrder(String userId, String virtually, Integer pageNo, Integer pageSize) {
        SwxUser swxUser = swxUserService.getById(userId);
        if (swxUser == null){
            throw new CustomerException("10009");
        }
        Page<SwxSmartOrder> page = new Page<SwxSmartOrder>(pageNo, pageSize);
        QueryWrapper<SwxSmartOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SwxSmartOrder::getUserId,userId);
        queryWrapper.lambda().orderByDesc(SwxSmartOrder::getCreateTime);
        IPage<SwxSmartOrder> pageList = swxSmartOrderService.page(page, queryWrapper);
        return pageList;
    }
 
    @Override
    public String buyOptionsTrue(SwxBuyOptionsVo vo, String userId, String virtually) throws CustomerException {
        if (!SwxConstons.SWX_CUSTOMER_USER_ORDER_TYPE_TRUE.equals(virtually)){
            throw new CustomerException("10008");
        }
        //获取用户信息
        SwxUser swxUser = swxUserService.getById(userId);
        if (swxUser == null){
            throw new CustomerException("10009");
        }
        SwxUserInfoVo infoVo = new SwxUserInfoVo();
        BeanUtils.copyProperties(swxUser,infoVo);
        //获取订单
        SwxOptionsOrder order = getSwxOptionsOrderBuyInfo(vo,swxUser);
        order.setOrderType(1);
 
        BigDecimal yue = infoVo.getAmount().subtract(infoVo.getBondAmount()).subtract(order.getTradeFee());
 
        //判断资金是否足够
        if ((yue).compareTo(vo.getAmount()) < 0){
            throw new CustomerException("10011");
        }
 
        swxUser.setAmount(swxUser.getAmount().subtract(vo.getAmount()).subtract(order.getTradeFee()));
        swxUserService.updateById(swxUser);
        swxOptionsOrderService.save(order);
        String id = order.getId();
        //推送给消息队列
        Map<String,Object> messageMap = new HashMap<>();
        messageMap.put("id",id);
        messageMap.put("istrue",1);
        messageMap.put("userId",userId);
        Integer timeSeconds = vo.getLimitTime() * 1000;
        rabbitTemplate.convertAndSend(DelayQueueRabbitConfig.ORDER_EXCHANGE, DelayQueueRabbitConfig.ORDER_ROUTING_KEY, messageMap, message->{
            message.getMessageProperties().setExpiration(timeSeconds+"");
            return message;
        });
        return id;
    }
 
    private SwxOptionsOrder getSwxOptionsOrderBuyInfo(SwxBuyOptionsVo vo,SwxUser swxUser) throws CustomerException{
        //获取产品
        SwxMarketOptions swxMarketOptions = swxMarketOptionsService.getById(vo.getOptionsId());
        if (swxMarketOptions == null || swxMarketOptions.getStatus() != SwxConstons.NOMARL_STATUS_YES){
            throw new CustomerException("10014");
        }
 
        //获取产品
        SwxMarket swxMarket = swxMarketService.getById(swxMarketOptions.getMId());
        if (swxMarket == null){
            throw new CustomerException("10014");
        }
 
        //获取可交易时间
        if (!getCanTradeTime(swxMarketOptions.getCanTradeDateType(),swxMarketOptions.getCanTradeDate(),swxMarketOptions.getCanTradeTime())) {
            throw new CustomerException("10015");
        }
 
        if (vo.getAmount() == null || vo.getAmount().compareTo(BigDecimal.ZERO) <= 0){
            throw new CustomerException("10016");
        }
 
        //获取利润
        String rateInfoStr = swxMarketOptions.getOptionsInfo();
        BigDecimal rate = null;
        JSONArray jsonArray = JSONArray.parseArray(rateInfoStr);
        for(int i = 0; i < jsonArray.size(); i++){
            JSONObject object = jsonArray.getJSONObject(i);
            Integer days = object.getInteger("seconds");
            if (days.intValue() ==  vo.getLimitTime().intValue()){
                rate = new BigDecimal(object.getString("rate"));
                break;
            }
        }
        if (rate == null){
            throw new CustomerException("10017");
        }
 
        //获取概率
        SwxSettings percentSettins = swxSettingsService.getOne(new QueryWrapper<SwxSettings>().lambda().eq(SwxSettings::getParamKey,"options_win_percent"));
        if(percentSettins == null){
            throw new CustomerException("10018");
        }
 
        //获取手续费
        SwxSettings tradeFeeSettings = swxSettingsService.getOne(new QueryWrapper<SwxSettings>().lambda().eq(SwxSettings::getParamKey,"default_trade_fee"));
        if(percentSettins == null){
            throw new CustomerException("10018");
        }
        BigDecimal tradeFee = vo.getAmount().multiply(new BigDecimal(tradeFeeSettings.getParamValue())).divide(new BigDecimal(100));
 
        //创建订单
        SwxOptionsOrder swxOptionsOrder = new SwxOptionsOrder();
        BeanUtils.copyProperties(vo,swxOptionsOrder);
        swxOptionsOrder.setMarketName(swxMarket.getAppName());
        swxOptionsOrder.setMarketCode(swxMarket.getCode());
        swxOptionsOrder.setMarketType(swxMarket.getType());
        swxOptionsOrder.setRate(rate);
        //获取概率,存入是否会赢
        swxOptionsOrder.setOptionsId(swxMarketOptions.getId());
        swxOptionsOrder.setUserId(swxUser.getId());
        swxOptionsOrder.setMarketId(swxMarketOptions.getMId());
        swxOptionsOrder.setStatus(0);
        //判断用户是否设置包输包赢
        boolean isWin;
        if (swxUser.getBw() != 0){
            if (swxUser.getBw() == 1){
                isWin = true;
            }else{
                isWin = false;
            }
        }else{
            isWin = checkWin(Integer.parseInt(percentSettins.getParamValue()));
        }
        //判断是否赢,来设置显示平仓价
        BigDecimal endPrice = BigDecimal.ZERO;
        BigDecimal fd = (vo.getBuyPrice().multiply(getRandom(10)).divide(new BigDecimal(1000))).setScale(4, RoundingMode.HALF_UP);
        if (isWin){
            if(vo.getType() == 1){
                endPrice = vo.getBuyPrice().add(fd);
            }else{
                endPrice = vo.getBuyPrice().subtract(fd);
            }
        }else{
            if(vo.getType() == 1){
                endPrice = vo.getBuyPrice().subtract(fd);
            }else{
                endPrice = vo.getBuyPrice().add(fd);
            }
        }
        swxOptionsOrder.setResultType(isWin ? 1 : 2);
        swxOptionsOrder.setEndPrice(endPrice);
        swxOptionsOrder.setIncome(vo.getAmount().multiply(rate).divide(new BigDecimal(100)));
        swxOptionsOrder.setTradeFee(tradeFee);
        return swxOptionsOrder;
 
    }
    @Override
    public String buyOptionsVirtually(SwxBuyOptionsVo vo, String userId, String virtually) throws CustomerException {
        if (!SwxConstons.SWX_CUSTOMER_USER_ORDER_TYPE_VIRTRUAL.equals(virtually)){
            throw new CustomerException("10008");
        }
        //获取用户信息
        SwxUser swxUser = swxUserService.getById(userId);
        if (swxUser == null){
            throw new CustomerException("10009");
        }
        SwxUserInfoVo infoVo;
        if (redisCache.hasKey("SWX-CUSTOMER-VERTURAL-"+userId)){
            infoVo= redisCache.getCacheObject("SWX-CUSTOMER-VERTURAL-"+userId);
        }else{
            infoVo = new SwxUserInfoVo();
            BeanUtils.copyProperties(swxUser,infoVo);
            infoVo.setVirtuallyAmount(new BigDecimal(1000000));
            infoVo.setVirtuallyBondAmount(new BigDecimal(0));
            redisCache.setCacheObject("SWX-CUSTOMER-VERTURAL-"+swxUser.getId(),infoVo,604800L, TimeUnit.SECONDS);
        }
        //获取订单
        SwxOptionsOrder order = getSwxOptionsOrderBuyInfo(vo,swxUser);
        order.setOrderType(2);
        BigDecimal yue = infoVo.getVirtuallyAmount().subtract(infoVo.getVirtuallyBondAmount());
        //判断资金是否足够
        if ((yue.subtract(order.getTradeFee())).compareTo(vo.getAmount()) < 0){
            throw new CustomerException("10011");
        }
//        String id = UUID.randomUUID().toString();
        infoVo.setVirtuallyAmount(yue.subtract(vo.getAmount()).subtract(order.getTradeFee()));
//        //修改redis值
//        order.setId(id);
//        order.setCreateTime(new Date());
        Long exprise = redisCache.getExpire("SWX-CUSTOMER-VERTURAL-"+userId);
        if(exprise <= 0){
            exprise = 604800L;
        }
        redisCache.setCacheObject("SWX-CUSTOMER-VERTURAL-"+userId,infoVo,exprise,TimeUnit.SECONDS);
//        //将订单信息加入缓存中
//        Long orderExprise = redisCache.getExpire("SWX-CUSTOMER-VERTURAL-OPTIONS-"+userId);
//        List<SwxOptionsOrder> list = new ArrayList<>();
//        list.add(order);
//        redisCache.setCacheList("SWX-CUSTOMER-VERTURAL-OPTIONS-"+userId,list);
//        if (orderExprise <= 0){
//            orderExprise = 604800L;
//        }
//        redisCache.expire("SWX-CUSTOMER-VERTURAL-OPTIONS-"+userId,orderExprise,TimeUnit.SECONDS);
        swxOptionsOrderService.save(order);
        String id = order.getId();
        //推送给消息队列
        Map<String,Object> messageMap = new HashMap<>();
        messageMap.put("id",id);
        messageMap.put("istrue",2);
        messageMap.put("userId",userId);
        Integer timeSeconds = vo.getLimitTime() * 1000;
        rabbitTemplate.convertAndSend(DelayQueueRabbitConfig.ORDER_EXCHANGE, DelayQueueRabbitConfig.ORDER_ROUTING_KEY, messageMap, message->{
            message.getMessageProperties().setExpiration(timeSeconds+"");
            return message;
        });
        return id;
    }
 
 
 
    @Override
    public IPage<SwxBuyOptionsInfo> listOptionsOrder(String userId, String virtually, Integer pageNo, Integer pageSize) throws CustomerException {
        if (!SwxConstons.SWX_CUSTOMER_USER_ORDER_TYPE_TRUE.equals(virtually) && !SwxConstons.SWX_CUSTOMER_USER_ORDER_TYPE_VIRTRUAL.equals(virtually)){
            throw new CustomerException("10008");
        }
        //获取用户信息
        SwxUser swxUser = swxUserService.getById(userId);
        if (swxUser == null){
            throw new CustomerException("10009");
        }
        Page<SwxBuyOptionsInfo> result = new Page<>();
        Page<SwxOptionsOrder> page = new Page<>(pageNo,pageSize);
        QueryWrapper<SwxOptionsOrder> swxOptionsOrderQueryWrapper = new QueryWrapper<>();
        swxOptionsOrderQueryWrapper.lambda().eq(SwxOptionsOrder::getUserId,userId);
        swxOptionsOrderQueryWrapper.lambda().orderByDesc(SwxOptionsOrder::getCreateTime);
        if (SwxConstons.SWX_CUSTOMER_USER_ORDER_TYPE_VIRTRUAL.equals(virtually)){
            swxOptionsOrderQueryWrapper.lambda().eq(SwxOptionsOrder::getOrderType,2);
        }else {
            swxOptionsOrderQueryWrapper.lambda().eq(SwxOptionsOrder::getOrderType,1);
        }
        IPage<SwxOptionsOrder> pageList = swxOptionsOrderService.page(page,swxOptionsOrderQueryWrapper);
        result.setTotal(pageList.getTotal());
        List<SwxBuyOptionsInfo> records = new ArrayList<>();
        for (SwxOptionsOrder item : pageList.getRecords()){
            SwxBuyOptionsInfo info = new SwxBuyOptionsInfo();
            BeanUtils.copyProperties(item,info);
            if (item.getStatus() == 0){
                info.setEndPrice(BigDecimal.ZERO);
                info.setResultType(null);
            }
            records.add(info);
        }
        result.setRecords(records);
//        if (SwxConstons.SWX_CUSTOMER_USER_ORDER_TYPE_VIRTRUAL.equals(virtually)){
           //获取redis中缓存
//            Integer size = redisCache.getCacheListSize("SWX-CUSTOMER-VERTURAL-OPTIONS-"+userId).intValue();
//            result.setTotal(size);
//            if (size > 0){
//                Integer begin = (size - (pageNo * pageSize)) <= 0 ? 0 : (size - (pageNo * pageSize));
//                Integer end =size - ((pageNo-1) * pageSize) - 1;
//                List<SwxOptionsOrder> list = redisCache.getCacheList("SWX-CUSTOMER-VERTURAL-OPTIONS-"+userId,begin,end);
//                List<SwxBuyOptionsInfo> records = new ArrayList<>();
//                for (SwxOptionsOrder item : list){
//                    SwxBuyOptionsInfo info = new SwxBuyOptionsInfo();
//                    BeanUtils.copyProperties(item,info);
//                    if (item.getStatus() == 0){
//                        info.setEndPrice(BigDecimal.ZERO);
//                        info.setResultType(null);
//                    }
//                    records.add(info);
//                }
//                Collections.reverse(records);
//                result.setRecords(records);
//            }
//
//        }else{
//            Page<SwxOptionsOrder> page = new Page<>(pageNo,pageSize);
//            QueryWrapper<SwxOptionsOrder> swxOptionsOrderQueryWrapper = new QueryWrapper<>();
//            swxOptionsOrderQueryWrapper.lambda().eq(SwxOptionsOrder::getUserId,userId);
//            swxOptionsOrderQueryWrapper.lambda().orderByDesc(SwxOptionsOrder::getCreateTime);
//            IPage<SwxOptionsOrder> pageList = swxOptionsOrderService.page(page,swxOptionsOrderQueryWrapper);
//            result.setTotal(pageList.getTotal());
//            List<SwxBuyOptionsInfo> records = new ArrayList<>();
//            for (SwxOptionsOrder item : pageList.getRecords()){
//                SwxBuyOptionsInfo info = new SwxBuyOptionsInfo();
//                BeanUtils.copyProperties(item,info);
//                if (item.getStatus() == 0){
//                    info.setEndPrice(BigDecimal.ZERO);
//                    info.setResultType(null);
//                }
//                records.add(info);
//            }
//            result.setRecords(records);
//        }
        return result;
    }
 
    @Override
    public SwxBuyOptionsInfo getOptionsOrderById(String userId, String virtually, String id) {
        SwxOptionsOrder swxOptionsOrder = null;
        if (SwxConstons.SWX_CUSTOMER_USER_ORDER_TYPE_VIRTRUAL.equals(virtually)){
            List<SwxOptionsOrder> list = redisCache.getCacheList("SWX-CUSTOMER-VERTURAL-OPTIONS-"+userId);
            for (SwxOptionsOrder item : list){
                if (item.getId().equals(id)){
                    swxOptionsOrder = item ;
                    break;
                }
            }
        }else{
            swxOptionsOrder= swxOptionsOrderService.getById(id);
        }
        if (swxOptionsOrder != null){
            SwxBuyOptionsInfo info = new SwxBuyOptionsInfo();
            BeanUtils.copyProperties(swxOptionsOrder,info);
            if (info.getStatus() == 0){
                info.setEndPrice(BigDecimal.ZERO);
                info.setResultType(null);
            }
            return info;
        }
        return null;
    }
 
 
    private BigDecimal getRandom(Integer randomMax){
        Random random = new Random();
        Double randomFloat = random.nextDouble() * 10;
        return new BigDecimal(randomFloat).setScale(4, RoundingMode.HALF_UP);
    }
 
    private boolean checkWin(Integer persont){
        Random random = new Random();
        int randomNumber = random.nextInt(100);
        return persont >= randomNumber;
    }
 
    /**
     * 是否可交易时间
     * @param tradeDateType 可交易日期类型
     * @param tradeDate 可交易日期
     * @param tradeTime 可交易时间
     * @return
     */
    private boolean getCanTradeTime(Integer tradeDateType,String tradeDate,String tradeTime){
        logger.info("校验时间");
        logger.info("tradeDateType"+tradeDateType);
        logger.info("tradeDate"+tradeDate);
        logger.info("tradeTime"+tradeTime);
        Date date = new Date();
        boolean canTradeDayFlag = false;
        String[] cantrade = tradeDate.replace("[", "").replace("]", "").split(",");
        String currentDay = "";
        logger.info("data"+date);
        if (tradeDateType == 1){
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); // 定义日期格式
            currentDay = dateFormat.format(date).split("-")[2]; // 将日期转换为字
        }else if(tradeDateType == 2){
            // 周
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            currentDay = calendar.get(Calendar.DAY_OF_WEEK)+"";
        }else if(tradeDateType == 3){
           //余额
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); // 定义日期格式
            currentDay = dateFormat.format(date).split("-")[1]; // 将日期转换为字
        }
        logger.info("currentDay= "+currentDay);
        for (String item : cantrade){
            if (item.equals("\""+currentDay+"\"")){
                canTradeDayFlag = true;
                break;
            }
        }
        if (canTradeDayFlag){
            String[] canTradeTime = tradeTime.replace("[", "").replace("]", "").split(",");
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            int hour = calendar.get(Calendar.HOUR_OF_DAY);
            String hourStr =hour < 10 ? "\"0"+hour+"\"" : "\""+hour+"\"";
            logger.info("hourStr= "+hourStr);
            for (String item : canTradeTime){
                if (item.equals(hourStr)){
                    return true;
                }
            }
        }
        return false;
    }
 
 
}