基于mall4j产品的二开项目后端
lee
2024-12-18 efdb99f8cecc4afb592afad79c761081d5d5cf22
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
package com.yami.shop.api.controller.cdn;
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yami.shop.bean.model.Area;
import com.yami.shop.bean.model.Device;
import com.yami.shop.bean.param.CdnIncomeBangParam;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.service.AreaService;
import com.yami.shop.service.CdnFlowService;
import com.yami.shop.service.DeviceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import java.math.BigDecimal;
import java.util.*;
 
@RestController
@RequestMapping("/cdn/income")
@Tag(name = "cdn收益")
public class CdnIncomeBangController {
    @Autowired
    private CdnFlowService cdnFlowService;
 
    @Autowired
    private DeviceService deviceService;
 
    @Autowired
    private AreaService areaService;
 
    @GetMapping("/getIncomeByUserId")
    @Operation(summary = "通过用户id和日期获取收益asd",description = "通过用户id和日期获取收益")
    private ServerResponseEntity<Double> getIncomeByUserId(@RequestParam String userId, @RequestParam(required = false) String date) {
        date = !Objects.equals(date, "") ? date : "";
        return ServerResponseEntity.success(cdnFlowService.getIncomeByUserId(userId,date));
    }
 
 //   @GetMapping("/getIncomeBangPage")
    @Operation(summary = "获取收益排行榜",description = "获取收益排行榜")
    private ServerResponseEntity<List<CdnIncomeBangParam>> getIncomeBangByUserId(@RequestParam Long type) {
        Page<Device> list = deviceService.page(new Page(1, 10), Wrappers.lambdaQuery(Device.class).eq(Device::getType, type));
        List<CdnIncomeBangParam> cdnIncomeBangParams = new ArrayList<>();
        list.getRecords().forEach(device -> {
            CdnIncomeBangParam cdnIncomeBangParam = new CdnIncomeBangParam();
            cdnIncomeBangParam.setSn(device.getDeviceCode());
            double randomNum = 3 + (Math.random() * (5 - 3)) * 0.95;
            randomNum = Math.min(randomNum, 5);
            randomNum = Math.floor(randomNum * 100) / 100;
            cdnIncomeBangParam.setIncome(BigDecimal.valueOf(randomNum));
            cdnIncomeBangParam.setType(device.getType());
            cdnIncomeBangParams.add(cdnIncomeBangParam);
        });
        cdnIncomeBangParams.sort((o1, o2) -> o2.getIncome().compareTo(o1.getIncome()));
        return ServerResponseEntity.success(cdnIncomeBangParams);
    }
 
    @GetMapping("/getIncomeBangPage")
    @Operation(summary = "获取收益集结榜",description = "获取收益集结榜")
    private ServerResponseEntity<List<CdnIncomeBangParam>> getIncomeBang(@RequestParam Long type) {
        List<CdnIncomeBangParam> cdnIncomeBangParams = new ArrayList<>();
        List<Area> areas = areaService.list(Wrappers.lambdaQuery(Area.class).eq(Area::getLevel,2));
        for (int i = 0; i < 333; i++) {
            CdnIncomeBangParam cdnIncomeBangParam = new CdnIncomeBangParam();
            Random random = new Random();
            int randomNumber = random.nextInt(900000000) + 100000000;
            String dateString = String.valueOf(randomNumber);
            cdnIncomeBangParam.setSn("P" + dateString);
            double randomNum = 1 + (Math.random() * (5 - 1)) * 0.95;
            randomNum = Math.min(randomNum, 5);
            randomNum = Math.floor(randomNum * 100) / 100;
            cdnIncomeBangParam.setIncome(BigDecimal.valueOf(randomNum));
            int randomArea = (int) (Math.random() * areas.size());
            Area area = areas.get(randomArea);
            Area area1 = areaService.getById(area.getParentId());
            cdnIncomeBangParam.setProvinceCity(area1.getAreaName() + area.getAreaName());
            cdnIncomeBangParam.setType(0L);
            cdnIncomeBangParams.add(cdnIncomeBangParam);
        }
        for (int i = 0; i < 333; i++) {
            CdnIncomeBangParam cdnIncomeBangParam = new CdnIncomeBangParam();
            Random random = new Random();
            int randomNumber = random.nextInt(900000000) + 100000000;
            String dateString = String.valueOf(randomNumber);
            cdnIncomeBangParam.setSn("X" + dateString);
            double randomDouble = 40 + Math.random() * (80 - 40);
            randomDouble = Math.round(randomDouble * 100) / 100.0;
            cdnIncomeBangParam.setIncome(BigDecimal.valueOf(randomDouble));
            int randomArea = (int) (Math.random() * areas.size());
            Area area = areas.get(randomArea);
            Area area1 = areaService.getById(area.getParentId());
            cdnIncomeBangParam.setProvinceCity(area1.getAreaName() + area.getAreaName());
            cdnIncomeBangParam.setType(0L);
            cdnIncomeBangParams.add(cdnIncomeBangParam);
        }
        for (int i = 0; i < 333; i++) {
            CdnIncomeBangParam cdnIncomeBangParam = new CdnIncomeBangParam();
            Random random = new Random();
            int randomNumber = random.nextInt(900000000) + 100000000;
            String dateString = String.valueOf(randomNumber);
            cdnIncomeBangParam.setSn("L" + dateString);
            double randomDouble = 0.9 + Math.random() * (5 - 0.9);
            randomDouble = Math.round(randomDouble * 100) / 100.0;
            cdnIncomeBangParam.setIncome(BigDecimal.valueOf(randomDouble));
            int randomArea = (int) (Math.random() * areas.size());
            Area area = areas.get(randomArea);
            Area area1 = areaService.getById(area.getParentId());
            cdnIncomeBangParam.setProvinceCity(area1.getAreaName() + area.getAreaName());
            cdnIncomeBangParam.setType(0L);
            cdnIncomeBangParams.add(cdnIncomeBangParam);
        }
        Collections.shuffle(cdnIncomeBangParams);
        return ServerResponseEntity.success(cdnIncomeBangParams);
    }
}