Browse Source

刷数据v2,定时任务

master
nili 5 months ago
parent
commit
e6691ee44f
  1. 3
      game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixAdvRecordMapper.java
  2. 5
      game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixInnerUserMapper.java
  3. 11
      game-service/src/main/java/awesome/group/game/service/bo/matrix/AppNormalConfig.java
  4. 78
      game-service/src/main/java/awesome/group/game/service/matrix/SuperAdminService.java

3
game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixAdvRecordMapper.java

@ -26,4 +26,7 @@ public interface MatrixAdvRecordMapper extends BaseMapper<MatrixAdvRecord> {
@Select("select device_id, device_brand, device_name, ip from matrix_adv_record where device_id in (select device_id from matrix_white_device where channel = #{channel}) limit 200") @Select("select device_id, device_brand, device_name, ip from matrix_adv_record where device_id in (select device_id from matrix_white_device where channel = #{channel}) limit 200")
List<MatrixAdvRecord> getWhiteDevice(String channel); List<MatrixAdvRecord> getWhiteDevice(String channel);
@Select("select * from matrix_adv_record where user_id = #{userId} order by id desc limit 1")
MatrixAdvRecord queryByUid(Integer userId);
} }

5
game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixInnerUserMapper.java

@ -4,7 +4,12 @@ import awesome.group.game.dao.bean.MatrixInnerUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import java.util.List;
public interface MatrixInnerUserMapper extends BaseMapper<MatrixInnerUser> { public interface MatrixInnerUserMapper extends BaseMapper<MatrixInnerUser> {
@Select("select * from matrix_inner_user where user_id = #{userId}") @Select("select * from matrix_inner_user where user_id = #{userId}")
MatrixInnerUser queryByUserId(Integer userId); MatrixInnerUser queryByUserId(Integer userId);
@Select("Select user_id from matrix_inner_user where app_id = #{appId}")
List<Integer> queryByAppId(Integer appId);
} }

11
game-service/src/main/java/awesome/group/game/service/bo/matrix/AppNormalConfig.java

@ -55,4 +55,15 @@ public class AppNormalConfig {
} }
return defaultRate; return defaultRate;
} }
public long getEcpmReal(long ecpm, MatrixUser u) {
Integer rate = getRate(u);
long ecpmReal = ecpm * rate / 100;
ecpmReal = Math.min(maxIncomeEachVideo * 1000L, ecpmReal);
if (u.getUpUid() != null) {
long contribute = ecpmReal / 10;
ecpmReal = ecpmReal - contribute;
}
return ecpmReal;
}
} }

78
game-service/src/main/java/awesome/group/game/service/matrix/SuperAdminService.java

@ -3,19 +3,25 @@ package awesome.group.game.service.matrix;
import awesome.group.game.dao.bean.*; import awesome.group.game.dao.bean.*;
import awesome.group.game.dao.mapper.*; import awesome.group.game.dao.mapper.*;
import awesome.group.game.service.bo.AddMockScheduleReq; import awesome.group.game.service.bo.AddMockScheduleReq;
import awesome.group.game.service.bo.matrix.AppNormalConfig;
import awesome.group.game.service.bo.matrix.WhiteUserBo; import awesome.group.game.service.bo.matrix.WhiteUserBo;
import awesome.group.game.service.common.log.L;
import awesome.group.game.service.util.Constants;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.*;
import java.util.Collections; import java.util.concurrent.ThreadLocalRandom;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static awesome.group.game.service.util.Constants.SUPER_ADMIN; import static awesome.group.game.service.util.Constants.SUPER_ADMIN;
@ -44,6 +50,13 @@ public class SuperAdminService {
@Autowired @Autowired
private MatrixMockScheduleV2Mapper mockScheduleV2Mapper; private MatrixMockScheduleV2Mapper mockScheduleV2Mapper;
@Autowired
private MatrixAdvRecordMapper advRecordMapper;
@Lazy
@Autowired
private SuperAdminService superAdminService;
public List<MatrixEvilApp> evilAppList() { public List<MatrixEvilApp> evilAppList() {
List<MatrixEvilApp> app = evilAppMapper.selectList(null); List<MatrixEvilApp> app = evilAppMapper.selectList(null);
Collections.reverse(app); Collections.reverse(app);
@ -144,5 +157,62 @@ public class SuperAdminService {
mockScheduleV2Mapper.insertBatch(list); mockScheduleV2Mapper.insertBatch(list);
} }
@Scheduled(cron = "0 * * * * ?")
public void mockSchedule() {
LambdaQueryWrapper<MatrixMockScheduleV2> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.le(MatrixMockScheduleV2::getScheduleTime, new Timestamp(System.currentTimeMillis()));
queryWrapper.lt(MatrixMockScheduleV2::getStatus, 2);
List<MatrixMockScheduleV2> res = mockScheduleV2Mapper.selectList(queryWrapper);
res.forEach(x -> superAdminService.mockData(x.getId()));
}
@Async
public void mockData(Integer scheduleId) {
MatrixMockScheduleV2 schedule = mockScheduleV2Mapper.selectById(scheduleId);
long target = schedule.getIncomeYuan() * 100L * 1000;
if (target <= schedule.getMockIncome()) {
mockScheduleV2Mapper.updateStatus(2, schedule.getId());
return;
}
if (schedule.getStatus() == 0) {
mockScheduleV2Mapper.updateStatus(1, schedule.getId());
}
List<Integer> userIds = innerUserMapper.queryByAppId(schedule.getAppId());
if (CollectionUtils.isEmpty(userIds)) {
return;
}
Random random = new Random();
Integer uid = userIds.get(random.nextInt(userIds.size()));
try {
Thread.sleep(10_000 + random.nextInt(40_000));
} catch (Exception e) {
L.trace("mockData", "error:" + e.getMessage(), e);
}
MatrixAdvRecord record = advRecordMapper.queryByUid(uid);
long ecpm = 3000_00 + random.nextInt(2000_00);
MatrixApp app = appMapper.selectById(schedule.getAppId());
MatrixUser u = userMapper.selectById(uid);
AppNormalConfig config = AppNormalConfig.getConfig(app);
long ecpmReal = config.getEcpmReal(ecpm, u);
MatrixAdvRecord newRecord = new MatrixAdvRecord();
newRecord.setDeviceId(record.getDeviceId());
newRecord.setAppId(schedule.getAppId());
newRecord.setAdvId(null);
newRecord.setPlatform(2);
newRecord.setAdvType(Constants.VIDEO);
newRecord.setEcpm(ecpm);
newRecord.setEcpmReal(ecpmReal);
newRecord.setEcpmAdmin(0L);
newRecord.setUserId(uid);
newRecord.setDeviceName(record.getDeviceName());
newRecord.setDeviceBrand(record.getDeviceBrand());
newRecord.setIp(record.getIp());
newRecord.setAdminId(null);
advRecordMapper.insert(newRecord);
mockScheduleV2Mapper.updateMockIncome(ecpm, schedule.getId());
}
} }

Loading…
Cancel
Save