Browse Source

白名单和刷数据后台

master
nili 9 months ago
parent
commit
fa7f54ce5d
  1. 21
      game-dao/src/main/java/awesome/group/game/dao/bean/MatrixMockSchedule.java
  2. 16
      game-dao/src/main/java/awesome/group/game/dao/bean/MatrixWhiteDevice.java
  3. 13
      game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixMockScheduleMapper.java
  4. 23
      game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixWhiteDeviceMapper.java
  5. 91
      game-service/src/main/java/awesome/group/game/service/AdminService.java
  6. 8
      game-service/src/main/java/awesome/group/game/service/bo/AddMockScheduleReq.java
  7. 43
      game-web/src/main/java/awesome/group/game/web/rest/matrix/AdminController.java

21
game-dao/src/main/java/awesome/group/game/dao/bean/MatrixMockSchedule.java

@ -0,0 +1,21 @@
package awesome.group.game.dao.bean;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import java.sql.Timestamp;
@Data
public class MatrixMockSchedule {
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
private Integer appId;
private String channel;
private Integer incomeYuan;
private Long mockIncome;//ecpm累计,分
private Integer status;
private Timestamp scheduleTime;
private Timestamp createdAt;
private Timestamp updatedAt;
}

16
game-dao/src/main/java/awesome/group/game/dao/bean/MatrixWhiteDevice.java

@ -0,0 +1,16 @@
package awesome.group.game.dao.bean;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import java.sql.Timestamp;
@Data
public class MatrixWhiteDevice {
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
private String deviceId;
private String channel;
private Timestamp createdAt;
}

13
game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixMockScheduleMapper.java

@ -0,0 +1,13 @@
package awesome.group.game.dao.mapper;
import awesome.group.game.dao.bean.MatrixMockSchedule;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Update;
public interface MatrixMockScheduleMapper extends BaseMapper<MatrixMockSchedule> {
@Update("update matrix_mock_schedule set status=#{status} where id = #{id}")
int updateStatus(int status, int id);
@Update("update matrix_mock_schedule set mock_income = mock_income + #{incrMockIncome} where id = #{id}")
int updateMockIncome(long incrMockIncome, int id);
}

23
game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixWhiteDeviceMapper.java

@ -0,0 +1,23 @@
package awesome.group.game.dao.mapper;
import awesome.group.game.dao.bean.MatrixWhiteDevice;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import java.util.List;
public interface MatrixWhiteDeviceMapper extends BaseMapper<MatrixWhiteDevice> {
@Insert("insert ignore into matrix_white_device (device_id, channel) values (#{deviceId}, #{channel})")
void insertWhiteList(String deviceId, String channel);
@Select("select device_id from matrix_white_device")
List<String> whiteList();
@Select("select count(*) from matrix_white_device where device_id = #{deviceId}")
Integer queryWhitelist(String deviceId);
@Delete("delete from matrix_white_device where device_id = #{deviceId}")
int deleteByDeviceId(String deviceId);
}

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

@ -1,13 +1,7 @@
package awesome.group.game.service; package awesome.group.game.service;
import awesome.group.game.dao.bean.MatrixAdmin; import awesome.group.game.dao.bean.*;
import awesome.group.game.dao.bean.MatrixAdvAggregation; import awesome.group.game.dao.mapper.*;
import awesome.group.game.dao.bean.MatrixAdvRecord;
import awesome.group.game.dao.bean.MatrixApp;
import awesome.group.game.dao.mapper.MatrixAdminMapper;
import awesome.group.game.dao.mapper.MatrixAdvAggregationMapper;
import awesome.group.game.dao.mapper.MatrixAdvRecordMapper;
import awesome.group.game.dao.mapper.MatrixAppMapper;
import awesome.group.game.service.bo.*; import awesome.group.game.service.bo.*;
import awesome.group.game.service.common.exception.PaganiException; import awesome.group.game.service.common.exception.PaganiException;
import awesome.group.game.service.common.exception.PaganiExceptionCode; import awesome.group.game.service.common.exception.PaganiExceptionCode;
@ -23,6 +17,7 @@ import com.google.common.base.Joiner;
import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.lang.RandomStringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
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.Async;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -56,6 +51,16 @@ public class AdminService {
@Autowired @Autowired
private AggregationService aggregationService; private AggregationService aggregationService;
@Autowired
private MatrixWhiteDeviceMapper whiteDeviceMapper;
@Autowired
private MatrixMockScheduleMapper mockScheduleMapper;
@Lazy
@Autowired
private AdminService adminService;
public static final int SUPER_ADMIN = 1;//超级管理员 public static final int SUPER_ADMIN = 1;//超级管理员
public static final int NORMAL_ADMIN = 2;//普通管理员 public static final int NORMAL_ADMIN = 2;//普通管理员
public static final int OTHER = 3;//普通账号 public static final int OTHER = 3;//普通账号
@ -226,6 +231,76 @@ public class AdminService {
} }
} }
@Async
public void mockData(MatrixMockSchedule schedule) {
mockScheduleMapper.updateStatus(1, schedule.getId());
String channel = schedule.getChannel();
int yuan = schedule.getIncomeYuan();
List<MatrixAdvRecord> mockDevice = advRecordMapper.getWhiteDevice(channel);
if (CollectionUtils.isEmpty(mockDevice)) {
return;
}
long income = 0;
long target = yuan * 100L * 1000;
while (income < target) {
try {
Thread.sleep(ThreadLocalRandom.current().nextInt(10_000, 20_000));
} catch (Exception e) {
L.trace("mockData", "error:" + e.getMessage(), e);
}
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(schedule.getAppId());
record.setPlatform(2);
record.setAdvType(3);
income += ecpm;
advRecordMapper.insert(record);
mockScheduleMapper.updateMockIncome(ecpm, schedule.getId());
}
mockScheduleMapper.updateStatus(2, schedule.getId());
}
@Scheduled(cron = "0 * * * * ?")
public void mockSchedule() {
LambdaQueryWrapper<MatrixMockSchedule> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.le(MatrixMockSchedule::getScheduleTime, new Timestamp(System.currentTimeMillis()));
queryWrapper.eq(MatrixMockSchedule::getStatus, 0);
List<MatrixMockSchedule> res = mockScheduleMapper.selectList(queryWrapper);
res.forEach(adminService::mockData);
}
public void addWhiteList(String deviceId, String channel) {
if (whiteDeviceMapper.queryWhitelist(deviceId) > 0) {
return;
}
whiteDeviceMapper.insertWhiteList(deviceId, channel);
}
public void deleteWhiteList(String deviceId) {
whiteDeviceMapper.deleteByDeviceId(deviceId);
}
public List<MatrixWhiteDevice> whiteDeviceList() {
return whiteDeviceMapper.selectList(null);
}
public List<MatrixMockSchedule> mockScheduleList() {
return mockScheduleMapper.selectList(null);
}
public void addMockSchedule(AddMockScheduleReq bo) {
MatrixMockSchedule schedule = new MatrixMockSchedule();
schedule.setAppId(bo.appId);
schedule.setScheduleTime(new Timestamp(bo.scheduleTime));
schedule.setChannel(bo.channel);
schedule.setIncomeYuan(bo.incomeYuan);
mockScheduleMapper.insert(schedule);
}
public OverviewBo incomeOverview(int adminId, String code) { public OverviewBo incomeOverview(int adminId, String code) {
if (StringUtils.hasText(code)) { if (StringUtils.hasText(code)) {
MatrixApp app = appMapper.queryByCode(code); MatrixApp app = appMapper.queryByCode(code);

8
game-service/src/main/java/awesome/group/game/service/bo/AddMockScheduleReq.java

@ -0,0 +1,8 @@
package awesome.group.game.service.bo;
public class AddMockScheduleReq {
public Integer appId;
public String channel;
public Integer incomeYuan;
public long scheduleTime;//毫秒
}

43
game-web/src/main/java/awesome/group/game/web/rest/matrix/AdminController.java

@ -1,13 +1,16 @@
package awesome.group.game.web.rest.matrix; package awesome.group.game.web.rest.matrix;
import awesome.group.game.web.RequestContext;
import awesome.group.game.web.aop.RestApi;
import awesome.group.game.dao.bean.MatrixAdmin; import awesome.group.game.dao.bean.MatrixAdmin;
import awesome.group.game.dao.bean.MatrixApp; import awesome.group.game.dao.bean.MatrixApp;
import awesome.group.game.dao.bean.MatrixMockSchedule;
import awesome.group.game.dao.bean.MatrixWhiteDevice;
import awesome.group.game.service.AdminService; import awesome.group.game.service.AdminService;
import awesome.group.game.service.MatrixService;
import awesome.group.game.service.bo.*; import awesome.group.game.service.bo.*;
import awesome.group.game.service.common.response.R; import awesome.group.game.service.common.response.R;
import awesome.group.game.service.util.JwtUtils; import awesome.group.game.service.util.JwtUtils;
import awesome.group.game.web.RequestContext;
import awesome.group.game.web.aop.RestApi;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.servlet.http.Cookie; import jakarta.servlet.http.Cookie;
@ -23,6 +26,9 @@ public class AdminController {
@Resource @Resource
private AdminService adminService; private AdminService adminService;
@Resource
private MatrixService matrixService;
@PostMapping("/login") @PostMapping("/login")
@RestApi @RestApi
public R<Void> adminLogin(@RequestParam String name, @RequestParam String pwd) { public R<Void> adminLogin(@RequestParam String name, @RequestParam String pwd) {
@ -99,4 +105,37 @@ public class AdminController {
adminService.mockData(appCode, incomeYuan, channel); adminService.mockData(appCode, incomeYuan, channel);
return new R<>(R.CODE_SUCCESS, "ok", null); return new R<>(R.CODE_SUCCESS, "ok", null);
} }
@PostMapping("/addWhiteList")
@RestApi
public R<Void> addWhiteList(@RequestParam String deviceId, @RequestParam String channel){
adminService.addWhiteList(deviceId, channel);
return new R<>(R.CODE_SUCCESS, "ok", null);
}
@PostMapping("/deleteWhiteList")
@RestApi
public R<Void> deleteWhiteList(@RequestParam String deviceId) {
adminService.deleteWhiteList(deviceId);
return new R<>(R.CODE_SUCCESS, "ok", null);
}
@GetMapping("/whiteList")
@RestApi
public R<List<MatrixWhiteDevice>> whiteList() {
return new R<>(R.CODE_SUCCESS, "ok", adminService.whiteDeviceList());
}
@GetMapping("/scheduleList")
@RestApi
public R<List<MatrixMockSchedule>> scheduleList() {
return new R<>(R.CODE_SUCCESS, "ok", adminService.mockScheduleList());
}
@PostMapping("/addSchedule")
@RestApi
public R<Void> addSchedule(@RequestBody AddMockScheduleReq bo) {
adminService.addMockSchedule(bo);
return new R<>(R.CODE_SUCCESS, "ok", null);
}
} }

Loading…
Cancel
Save