KKSU
2024-04-18 3cd3b259d39993fd5c1e216675e8881be5bc1a56
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
package cc.mrbird.febs.dapp.service.impl;
 
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.common.entity.QueryRequest;
import cc.mrbird.febs.common.enumerates.DataDicEnum;
import cc.mrbird.febs.common.exception.FebsException;
import cc.mrbird.febs.dapp.entity.DappCoinPrice;
import cc.mrbird.febs.dapp.entity.DappHdRecord;
import cc.mrbird.febs.dapp.entity.DataDictionaryCustom;
import cc.mrbird.febs.dapp.entity.PlatformBanner;
import cc.mrbird.febs.dapp.mapper.DappCoinPriceMapper;
import cc.mrbird.febs.dapp.mapper.DappHdRecordMapper;
import cc.mrbird.febs.dapp.mapper.DataDictionaryCustomMapper;
import cc.mrbird.febs.dapp.mapper.PlatformBannerMapper;
import cc.mrbird.febs.dapp.service.AsyncCjService;
import cc.mrbird.febs.dapp.service.IAdminBannerService;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
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 javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
 
@Slf4j
@Service
@RequiredArgsConstructor
@Transactional
public class AdminBannerServiceImpl extends ServiceImpl<PlatformBannerMapper, PlatformBanner> implements IAdminBannerService {
 
    private final PlatformBannerMapper platformBannerMapper;
    private final DappCoinPriceMapper dappCoinPriceMapper;
    private final DappHdRecordMapper dappHdRecordMapper;
    private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
    private final AsyncCjService asyncCjService;
 
    @Override
    public IPage<PlatformBanner> findPlatformBannerInPage(PlatformBanner platformBannerEntity,
                                                          QueryRequest request) {
        Page<PlatformBanner> page = new Page<>(request.getPageNum(), request.getPageSize());
        IPage<PlatformBanner> platformBannerEntitys = platformBannerMapper.findPlatformBannerInPage(page, platformBannerEntity);
        return platformBannerEntitys;
    }
 
    @Override
    public PlatformBanner selectPlatformBannerById(long id) {
        PlatformBanner platformBannerEntity = platformBannerMapper.selectById(id);
        return platformBannerEntity;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public FebsResponse platformBannerConfirm(@Valid PlatformBanner platformBannerEntity) {
        platformBannerMapper.updateById(platformBannerEntity);
        return new FebsResponse().success();
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public FebsResponse platformBannerDelete(@NotNull(message = "{required}") Long id) {
        platformBannerMapper.deleteById(id);
        return new FebsResponse().success();
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void platformBannerAdd(@Valid PlatformBanner platformBannerEntity) {
        PlatformBanner platformBannerEntityAdd = new PlatformBanner();
        platformBannerEntityAdd.setImageUrl(platformBannerEntity.getImageUrl());
        platformBannerEntityAdd.setIsInside(platformBannerEntity.getIsInside());
        platformBannerEntityAdd.setIsJump(platformBannerEntity.getIsJump());
        platformBannerEntityAdd.setIsTop(platformBannerEntity.getIsTop());
        platformBannerEntityAdd.setJumpUrl(platformBannerEntity.getJumpUrl());
        platformBannerEntityAdd.setName(platformBannerEntity.getName());
        platformBannerEntityAdd.setShowPort(platformBannerEntity.getShowPort());
        platformBannerEntityAdd.setSort(platformBannerEntity.getSort());
        platformBannerMapper.insert(platformBannerEntityAdd);
 
    }
 
    @Override
    public IPage<DappCoinPrice> findCoinPriceInPage(DappCoinPrice dappCoinPrice, QueryRequest request) {
        Page<DappCoinPrice> page = new Page<>(request.getPageNum(), request.getPageSize());
        IPage<DappCoinPrice> platformBannerEntitys = dappHdRecordMapper.findCoinPriceInPage(page, dappCoinPrice);
        return platformBannerEntitys;
    }
 
    @Override
    public FebsResponse coinPriceAdd(String price) {
        BigDecimal bigDecimal = new BigDecimal(price).setScale(8, BigDecimal.ROUND_DOWN);
        DappCoinPrice dappCoinPrice = new DappCoinPrice();
        dappCoinPrice.setPrice(bigDecimal);
        dappCoinPriceMapper.insert(dappCoinPrice);
        DataDictionaryCustom dataDictionaryCustom = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDicEnum.GFA_PRICE.getValue(),
                DataDicEnum.GFA_PRICE.getValue()
        );
 
        dataDictionaryCustom.setValue(bigDecimal.toString());
        dataDictionaryCustomMapper.updateById(dataDictionaryCustom);
 
        asyncCjService.redisCacheUpdate(DataDicEnum.GFA_PRICE.getValue(),bigDecimal.toString(),0);
        return new FebsResponse().success();
    }
 
    @Override
    public IPage<DappHdRecord> findHdRecordInPage(DappHdRecord dappHdRecord, QueryRequest request) {
        String startTime = dappHdRecord.getStartTime();
        String endTime = dappHdRecord.getEndTime();
        if(StrUtil.isNotBlank(startTime) && StrUtil.isNotBlank(endTime)){
            DateTime dateStartTime= DateUtil.parseDate(startTime);
            DateTime dateEndTime = DateUtil.parseDate(endTime);
            int compare = DateUtil.compare(dateStartTime, dateEndTime);
            if(compare >= 0){
                throw new FebsException("请输入正确的开始时间和结束时间");
            }
        }
        Page<DappHdRecord> page = new Page<>(request.getPageNum(), request.getPageSize());
        IPage<DappHdRecord> dappHdRecordIPage = dappHdRecordMapper.findHdRecordInPage(page, dappHdRecord);
        return dappHdRecordIPage;
    }
}