Browse Source

刷数据任务fx

master
nili 8 months ago
parent
commit
8d4ee6588a
  1. 55
      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

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

@ -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;
return; if (target <= schedule.getMockIncome()) {
} mockScheduleMapper.updateStatus(2, schedule.getId());
List<MatrixAdvRecord> mockDevice = advRecordMapper.getWhiteDevice(channel);
if (CollectionUtils.isEmpty(mockDevice)) {
return; return;
} }
long income = 0; if (schedule.getStatus() == 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()); 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;
while (income < target) {
try { try {
Thread.sleep(ThreadLocalRandom.current().nextInt(10_000, 20_000)); Thread.sleep(10_000 + random.nextInt(40_000));
} catch (Exception e) { } catch (Exception e) {
L.trace("mockData", "error:" + e.getMessage(), e); L.trace("mockData", "error:" + e.getMessage(), e);
} }
MatrixAdvRecord record = mockDevice.get(ThreadLocalRandom.current().nextInt(0, mockDevice.size())); MatrixAdvRecord record = mockDevice.get(ThreadLocalRandom.current().nextInt(0, mockDevice.size()));
long ecpm = ThreadLocalRandom.current().nextInt(500_00, 1500_00); long ecpm = 500_00 + random.nextInt(1000_00);
record.setId(null); record.setId(null);
record.setEcpm(ecpm); record.setEcpm(ecpm);
record.setAppId(schedule.getAppId()); record.setAppId(schedule.getAppId());
record.setPlatform(2); record.setPlatform(2);
record.setAdvType(3); record.setAdvType(3);
income += ecpm;
advRecordMapper.insert(record); advRecordMapper.insert(record);
mockScheduleMapper.updateMockIncome(ecpm, schedule.getId()); 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