From 16075b5a3f241c1c864252b373c4c48ff02fcacc Mon Sep 17 00:00:00 2001 From: nili Date: Tue, 9 Apr 2024 21:14:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E4=B8=AA=E6=8E=A5=E5=8F=A3=E5=88=B7?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dao/mapper/MatrixAdvRecordMapper.java | 5 + .../group/game/service/AdminService.java | 150 ++++++++++++++++++ .../java/awesome/group/game/Application.java | 2 + .../game/web/rest/matrix/AdminController.java | 7 + 4 files changed, 164 insertions(+) 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 a4ce44a..ddf105b 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 @@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Select; +import java.util.List; + public interface MatrixAdvRecordMapper extends BaseMapper { @Select("select * from matrix_app where code = #{code}") @@ -16,4 +18,7 @@ public interface MatrixAdvRecordMapper extends BaseMapper { @Insert("insert ignore into matrix_white_device (device_id) values (#{deviceId})") void insertWhiteList(String deviceId); + + @Select("select device_id from matrix_white_device") + List whiteList(); } diff --git a/game-service/src/main/java/awesome/group/game/service/AdminService.java b/game-service/src/main/java/awesome/group/game/service/AdminService.java index b7a28b9..7b10f9f 100644 --- a/game-service/src/main/java/awesome/group/game/service/AdminService.java +++ b/game-service/src/main/java/awesome/group/game/service/AdminService.java @@ -11,6 +11,7 @@ import awesome.group.game.dao.mapper.MatrixAppMapper; import awesome.group.game.service.bo.*; import awesome.group.game.service.common.exception.PaganiException; import awesome.group.game.service.common.exception.PaganiExceptionCode; +import awesome.group.game.service.common.log.L; import awesome.group.game.service.util.DateUtil; import awesome.group.game.service.util.EncryptUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -18,9 +19,12 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import org.apache.commons.lang.RandomStringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; @@ -31,6 +35,7 @@ import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; +import java.util.concurrent.ThreadLocalRandom; import java.util.stream.Collectors; @Service @@ -185,6 +190,151 @@ public class AdminService { } } + @Async + public void mockData(String appCode, long yuan) { + MatrixApp app = appMapper.queryByCode(appCode); + if (app == null) { + return; + } + String str = "[\n" + + " {\n" + + " \"deviceId\": \"08F662623A20E39D47230CCA3C7CD01B589D9FDC\",\n" + + " \"deviceBrand\": \"HUAWEI\",\n" + + " \"deviceName\": \"NCO-AL00\",\n" + + " \"ip\": \"223.160.189.157\"\n" + + " },\n" + + " {\n" + + " \"deviceId\": \"0AA84A49BE88FB0B3222333E62A7948A4614AF10\",\n" + + " \"deviceBrand\": \"HUAWEI\",\n" + + " \"deviceName\": \"NCO-AL00\",\n" + + " \"ip\": \"223.160.184.124\"\n" + + " },\n" + + " {\n" + + " \"deviceId\": \"25554364946807212ACA4634BB56DCC485A5B3D4\",\n" + + " \"deviceBrand\": \"OPPO\",\n" + + " \"deviceName\": \"PDKM00\",\n" + + " \"ip\": \"116.169.4.143\"\n" + + " },\n" + + " {\n" + + " \"deviceId\": \"30816052DC1079EA74996D14FEB8089AFBD3A86C\",\n" + + " \"deviceBrand\": \"HONOR\",\n" + + " \"deviceName\": \"ADT-AN00\",\n" + + " \"ip\": \"110.191.217.16\"\n" + + " },\n" + + " {\n" + + " \"deviceId\": \"338EC09FC55B68CBDF2FF288C7E240CA3518E40B\",\n" + + " \"deviceBrand\": \"OPPO\",\n" + + " \"deviceName\": \"PEMM00\",\n" + + " \"ip\": \"171.219.187.59\"\n" + + " },\n" + + " {\n" + + " \"deviceId\": \"360467864371C8FFC32C2FD3CBF19ED866AEFE45\",\n" + + " \"deviceBrand\": \"HUAWEI\",\n" + + " \"deviceName\": \"RTE-AL00\",\n" + + " \"ip\": \"116.169.6.151\"\n" + + " },\n" + + " {\n" + + " \"deviceId\": \"39147CCDB0F7B87C082B414B56AE108F79FC71EA\",\n" + + " \"deviceBrand\": \"HUAWEI\",\n" + + " \"deviceName\": \"ELE-AL00\",\n" + + " \"ip\": \"110.191.217.43\"\n" + + " },\n" + + " {\n" + + " \"deviceId\": \"3EAA7334E94764EB2B44829587116DE7CD3359A4\",\n" + + " \"deviceBrand\": \"HUAWEI\",\n" + + " \"deviceName\": \"RTE-AL00\",\n" + + " \"ip\": \"223.160.191.45\"\n" + + " },\n" + + " {\n" + + " \"deviceId\": \"78B8DF1B8D897476BB60BF0BE93393A27602CF51\",\n" + + " \"deviceBrand\": \"HUAWEI\",\n" + + " \"deviceName\": \"HMA-AL00\",\n" + + " \"ip\": \"171.212.241.181\"\n" + + " },\n" + + " {\n" + + " \"deviceId\": \"7CDF3CC5345149A978B9E66E50524A9DC9C7DEEE\",\n" + + " \"deviceBrand\": \"HUAWEI\",\n" + + " \"deviceName\": \"RTE-AL00\",\n" + + " \"ip\": \"116.169.80.96\"\n" + + " },\n" + + " {\n" + + " \"deviceId\": \"92549D031D5C97EBFA3674B280D692A896DC3F17\",\n" + + " \"deviceBrand\": \"HUAWEI\",\n" + + " \"deviceName\": \"ELE-AL00\",\n" + + " \"ip\": \"171.212.241.181\"\n" + + " },\n" + + " {\n" + + " \"deviceId\": \"A4D5BE85EB867507C2A712F9611198A331C5E0B1\",\n" + + " \"deviceBrand\": \"HUAWEI\",\n" + + " \"deviceName\": \"RTE-AL00\",\n" + + " \"ip\": \"116.169.80.199\"\n" + + " },\n" + + " {\n" + + " \"deviceId\": \"B381503F2EF5786E97111189FD60506D511FEC76\",\n" + + " \"deviceBrand\": \"HUAWEI\",\n" + + " \"deviceName\": \"RTE-AL00\",\n" + + " \"ip\": \"171.212.241.99\"\n" + + " },\n" + + " {\n" + + " \"deviceId\": \"BA8415B1260D17BED453412A8BDEB92B9EBC4591\",\n" + + " \"deviceBrand\": \"HUAWEI\",\n" + + " \"deviceName\": \"NCO-AL00\",\n" + + " \"ip\": \"171.216.234.101\"\n" + + " },\n" + + " {\n" + + " \"deviceId\": \"C3A4C960E65D29E442B58D1E6B1F264546B2FA8B\",\n" + + " \"deviceBrand\": \"HUAWEI\",\n" + + " \"deviceName\": \"NCO-AL00\",\n" + + " \"ip\": \"171.93.181.121\"\n" + + " },\n" + + " {\n" + + " \"deviceId\": \"C5B5B00BEA8A36CD946B4F5D6FE2EAE648BC6895\",\n" + + " \"deviceBrand\": \"OPPO\",\n" + + " \"deviceName\": \"PEMM00\",\n" + + " \"ip\": \"118.114.61.62\"\n" + + " },\n" + + " {\n" + + " \"deviceId\": \"DA8FE2D143218A095C04C864A8F3C8E40B53FA3B\",\n" + + " \"deviceBrand\": \"HUAWEI\",\n" + + " \"deviceName\": \"RTE-AL00\",\n" + + " \"ip\": \"116.169.10.217\"\n" + + " },\n" + + " {\n" + + " \"deviceId\": \"DC867C2DB33A8C7276F5F27558C783A21E398BE3\",\n" + + " \"deviceBrand\": \"HUAWEI\",\n" + + " \"deviceName\": \"ELE-AL00\",\n" + + " \"ip\": \"110.191.217.43\"\n" + + " },\n" + + " {\n" + + " \"deviceId\": \"E63144AB8D6702335C5440CE94B89FC3FF766C0D\",\n" + + " \"deviceBrand\": \"HUAWEI\",\n" + + " \"deviceName\": \"ELE-AL00\",\n" + + " \"ip\": \"171.212.241.181\"\n" + + " }\n" + + "]"; + Gson gson = new Gson(); + List mockDevice = gson.fromJson(str, new TypeToken>(){}.getType()); + 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.setEcpm(ecpm); + record.setAppId(app.getId()); + record.setPlatform(2); + record.setAdvType(3); + + income += ecpm; + advRecordMapper.insert(record); + + try{ + Thread.sleep(ThreadLocalRandom.current().nextInt(10000, 20000)); + } catch (Exception e) { + L.trace("mockData", "error:" + e.getMessage(), e); + } + } + } + public OverviewBo incomeOverview(int adminId, String code) { if (StringUtils.hasText(code)) { MatrixApp app = appMapper.queryByCode(code); diff --git a/game-web/src/main/java/awesome/group/game/Application.java b/game-web/src/main/java/awesome/group/game/Application.java index 2b0711b..5feb8d5 100644 --- a/game-web/src/main/java/awesome/group/game/Application.java +++ b/game-web/src/main/java/awesome/group/game/Application.java @@ -5,11 +5,13 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.ApplicationPidFileWriter; import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication @ServletComponentScan @EnableScheduling +@EnableAsync @EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true) public class Application { public static void main(String[] args) { diff --git a/game-web/src/main/java/awesome/group/game/web/rest/matrix/AdminController.java b/game-web/src/main/java/awesome/group/game/web/rest/matrix/AdminController.java index 6fec072..b92a689 100644 --- a/game-web/src/main/java/awesome/group/game/web/rest/matrix/AdminController.java +++ b/game-web/src/main/java/awesome/group/game/web/rest/matrix/AdminController.java @@ -92,4 +92,11 @@ public class AdminController { adminService.saveApp(matrixApp); return new R<>(R.CODE_SUCCESS, "ok", null); } + + @GetMapping("/mockData") + @RestApi + public R mockData(@RequestParam String appCode, @RequestParam long incomeYuan) { + adminService.mockData(appCode, incomeYuan); + return new R<>(R.CODE_SUCCESS, "ok", null); + } }