diff --git a/game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixAdvRecordMapper.java b/game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixAdvRecordMapper.java index 457987c..d2390c7 100644 --- a/game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixAdvRecordMapper.java +++ b/game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixAdvRecordMapper.java @@ -26,4 +26,7 @@ public interface MatrixAdvRecordMapper extends BaseMapper { @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 getWhiteDevice(String channel); + + @Select("select * from matrix_adv_record where user_id = #{userId} order by id desc limit 1") + MatrixAdvRecord queryByUid(Integer userId); } diff --git a/game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixInnerUserMapper.java b/game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixInnerUserMapper.java index ea93f2b..b97e84d 100644 --- a/game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixInnerUserMapper.java +++ b/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 org.apache.ibatis.annotations.Select; +import java.util.List; + public interface MatrixInnerUserMapper extends BaseMapper { @Select("select * from matrix_inner_user where user_id = #{userId}") MatrixInnerUser queryByUserId(Integer userId); + + @Select("Select user_id from matrix_inner_user where app_id = #{appId}") + List queryByAppId(Integer appId); } diff --git a/game-service/src/main/java/awesome/group/game/service/bo/matrix/AppNormalConfig.java b/game-service/src/main/java/awesome/group/game/service/bo/matrix/AppNormalConfig.java index 66894db..6a6ceca 100644 --- a/game-service/src/main/java/awesome/group/game/service/bo/matrix/AppNormalConfig.java +++ b/game-service/src/main/java/awesome/group/game/service/bo/matrix/AppNormalConfig.java @@ -55,4 +55,15 @@ public class AppNormalConfig { } 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; + } } diff --git a/game-service/src/main/java/awesome/group/game/service/matrix/SuperAdminService.java b/game-service/src/main/java/awesome/group/game/service/matrix/SuperAdminService.java index 2f90d23..980710b 100644 --- a/game-service/src/main/java/awesome/group/game/service/matrix/SuperAdminService.java +++ b/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.mapper.*; 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.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.toolkit.Wrappers; import com.google.common.collect.Lists; 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.util.Assert; import org.springframework.util.CollectionUtils; import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.concurrent.ThreadLocalRandom; import java.util.stream.Collectors; import static awesome.group.game.service.util.Constants.SUPER_ADMIN; @@ -44,6 +50,13 @@ public class SuperAdminService { @Autowired private MatrixMockScheduleV2Mapper mockScheduleV2Mapper; + @Autowired + private MatrixAdvRecordMapper advRecordMapper; + + @Lazy + @Autowired + private SuperAdminService superAdminService; + public List evilAppList() { List app = evilAppMapper.selectList(null); Collections.reverse(app); @@ -144,5 +157,62 @@ public class SuperAdminService { mockScheduleV2Mapper.insertBatch(list); } + @Scheduled(cron = "0 * * * * ?") + public void mockSchedule() { + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); + queryWrapper.le(MatrixMockScheduleV2::getScheduleTime, new Timestamp(System.currentTimeMillis())); + queryWrapper.lt(MatrixMockScheduleV2::getStatus, 2); + List 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 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()); + } + }