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);
|
}
|
}
|