@ -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 < MatrixEvilApp > evilAppList ( ) {
List < MatrixEvilApp > app = evilAppMapper . selectList ( null ) ;
Collections . reverse ( app ) ;
@ -144,5 +157,62 @@ public class SuperAdminService {
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 ( ) ) ;
}
}