Browse Source

刷数据任务fx

master
nili 8 months ago
parent
commit
8d4ee6588a
  1. 83
      game-service/src/main/java/awesome/group/game/service/AdminService.java
  2. 7
      game-web/src/main/java/awesome/group/game/web/rest/matrix/AdminController.java

83
game-service/src/main/java/awesome/group/game/service/AdminService.java

@ -120,7 +120,7 @@ public class AdminService {
int page = param.current; int page = param.current;
int pageSize = param.pageSize; int pageSize = param.pageSize;
PageResult<MatrixAdvRecordBo> res = new PageResult<>(); PageResult<MatrixAdvRecordBo> res = new PageResult<>();
if(page == 1 && StringUtils.hasText(param.deviceId)) { if (page == 1 && StringUtils.hasText(param.deviceId)) {
QueryWrapper<MatrixAdvRecord> sumQuery = wrapper.clone(); QueryWrapper<MatrixAdvRecord> sumQuery = wrapper.clone();
sumQuery.select("sum(ecpm) as ecpm"); sumQuery.select("sum(ecpm) as ecpm");
MatrixAdvRecord sum = advRecordMapper.selectOne(sumQuery); MatrixAdvRecord sum = advRecordMapper.selectOne(sumQuery);
@ -206,77 +206,46 @@ public class AdminService {
} }
@Async @Async
public void mockData(String appCode, long yuan, String channel) { public void mockData(Integer scheduleId) {
MatrixApp app = appMapper.queryByCode(appCode); MatrixMockSchedule schedule = mockScheduleMapper.selectById(scheduleId);
if (app == null) { long target = schedule.getIncomeYuan() * 100L * 1000;
if (target <= schedule.getMockIncome()) {
mockScheduleMapper.updateStatus(2, schedule.getId());
return; return;
} }
if (schedule.getStatus() == 0) {
List<MatrixAdvRecord> mockDevice = advRecordMapper.getWhiteDevice(channel); mockScheduleMapper.updateStatus(1, schedule.getId());
if (CollectionUtils.isEmpty(mockDevice)) {
return;
}
long income = 0;
long target = yuan * 100 * 1000;
while (income < target) {
MatrixAdvRecord record = mockDevice.get(ThreadLocalRandom.current().nextInt(0, mockDevice.size()));
long ecpm = ThreadLocalRandom.current().nextInt(500_00, 1500_00);
record.setId(null);
record.setEcpm(ecpm);
record.setAppId(app.getId());
record.setPlatform(2);
record.setAdvType(3);
income += ecpm;
advRecordMapper.insert(record);
try {
Thread.sleep(ThreadLocalRandom.current().nextInt(10_000, 20_000));
} catch (Exception e) {
L.trace("mockData", "error:" + e.getMessage(), e);
}
} }
}
@Async
public void mockData(MatrixMockSchedule schedule) {
mockScheduleMapper.updateStatus(1, schedule.getId());
String channel = schedule.getChannel(); String channel = schedule.getChannel();
int yuan = schedule.getIncomeYuan();
List<MatrixAdvRecord> mockDevice = advRecordMapper.getWhiteDevice(channel); List<MatrixAdvRecord> mockDevice = advRecordMapper.getWhiteDevice(channel);
if (CollectionUtils.isEmpty(mockDevice)) { if (CollectionUtils.isEmpty(mockDevice)) {
return; return;
} }
long income = 0; Random random = new Random();
long target = yuan * 100L * 1000; try {
while (income < target) { Thread.sleep(10_000 + random.nextInt(40_000));
try { } catch (Exception e) {
Thread.sleep(ThreadLocalRandom.current().nextInt(10_000, 20_000)); L.trace("mockData", "error:" + e.getMessage(), e);
} catch (Exception e) { }
L.trace("mockData", "error:" + e.getMessage(), e); MatrixAdvRecord record = mockDevice.get(ThreadLocalRandom.current().nextInt(0, mockDevice.size()));
} long ecpm = 500_00 + random.nextInt(1000_00);
MatrixAdvRecord record = mockDevice.get(ThreadLocalRandom.current().nextInt(0, mockDevice.size())); record.setId(null);
long ecpm = ThreadLocalRandom.current().nextInt(500_00, 1500_00); record.setEcpm(ecpm);
record.setId(null); record.setAppId(schedule.getAppId());
record.setEcpm(ecpm); record.setPlatform(2);
record.setAppId(schedule.getAppId()); record.setAdvType(3);
record.setPlatform(2);
record.setAdvType(3); advRecordMapper.insert(record);
mockScheduleMapper.updateMockIncome(ecpm, schedule.getId());
income += ecpm;
advRecordMapper.insert(record);
mockScheduleMapper.updateMockIncome(ecpm, schedule.getId());
}
mockScheduleMapper.updateStatus(2, schedule.getId());
} }
@Scheduled(cron = "0 * * * * ?") @Scheduled(cron = "0 * * * * ?")
public void mockSchedule() { public void mockSchedule() {
LambdaQueryWrapper<MatrixMockSchedule> queryWrapper = Wrappers.lambdaQuery(); LambdaQueryWrapper<MatrixMockSchedule> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.le(MatrixMockSchedule::getScheduleTime, new Timestamp(System.currentTimeMillis())); queryWrapper.le(MatrixMockSchedule::getScheduleTime, new Timestamp(System.currentTimeMillis()));
queryWrapper.eq(MatrixMockSchedule::getStatus, 0); queryWrapper.lt(MatrixMockSchedule::getStatus, 2);
List<MatrixMockSchedule> res = mockScheduleMapper.selectList(queryWrapper); List<MatrixMockSchedule> res = mockScheduleMapper.selectList(queryWrapper);
res.forEach(adminService::mockData); res.forEach(x -> adminService.mockData(x.getId()));
} }

7
game-web/src/main/java/awesome/group/game/web/rest/matrix/AdminController.java

@ -99,13 +99,6 @@ public class AdminController {
return new R<>(R.CODE_SUCCESS, "ok", null); return new R<>(R.CODE_SUCCESS, "ok", null);
} }
@GetMapping("/mockData")
@RestApi
public R<Void> mockData(@RequestParam String appCode, @RequestParam long incomeYuan, @RequestParam String channel) {
adminService.mockData(appCode, incomeYuan, channel);
return new R<>(R.CODE_SUCCESS, "ok", null);
}
@PostMapping("/addWhiteList") @PostMapping("/addWhiteList")
@RestApi @RestApi
public R<Void> addWhiteList(@RequestParam String deviceId, @RequestParam String channel){ public R<Void> addWhiteList(@RequestParam String deviceId, @RequestParam String channel){

Loading…
Cancel
Save