Browse Source

加点数据展示

master
nili 6 months ago
parent
commit
0744adcfeb
  1. 8
      game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixAdvRecordMapper.java
  2. 6
      game-service/src/main/java/awesome/group/game/service/MatrixService.java
  3. 14
      game-service/src/main/java/awesome/group/game/service/bo/matrix/AdvTypeIncome.java
  4. 14
      game-service/src/main/java/awesome/group/game/service/matrix/AdminService.java
  5. 23
      game-service/src/main/java/awesome/group/game/service/matrix/AggregationService.java
  6. 48
      game-service/src/main/java/awesome/group/game/service/util/DateUtil.java
  7. 17
      game-web/src/main/java/awesome/group/game/web/rest/matrix/AdminController.java

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

@ -9,6 +9,11 @@ import org.apache.ibatis.annotations.Select;
import java.util.List;
public interface MatrixAdvRecordMapper extends BaseMapper<MatrixAdvRecord> {
@Select("select id from `matrix_adv_record` where `app_id` = #{appId} and `created_at` >= #{beginTime} order by id limit 1")
Integer getBeginId(Integer appId, String beginTime);
@Select("select adv_type, sum(ecpm) as ecpm from matrix_adv_record where `app_id` = #{appId} and id >= #{id}")
List<MatrixAdvRecord> groupByAdvType(Integer id, Integer appId);
@Select("select * from matrix_app where code = #{code}")
MatrixApp queryApp(String code);
@ -19,9 +24,6 @@ public interface MatrixAdvRecordMapper extends BaseMapper<MatrixAdvRecord> {
@Insert("insert ignore into matrix_white_device (device_id) values (#{deviceId})")
void insertWhiteList(String deviceId);
@Select("select device_id from matrix_white_device")
List<String> whiteList();
@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);
}

6
game-service/src/main/java/awesome/group/game/service/MatrixService.java

@ -42,7 +42,7 @@ public class MatrixService {
public void saveRecord(MatrixAdvRecordEditBo bo, String ip) {
Assert.isTrue(StringUtils.hasText(bo.appCode), "appCode不能为空");
MatrixApp app = mapper.queryApp(bo.appCode);
MatrixApp app = appMapper.queryByCode(bo.appCode);
if (app == null) {
return;//非法请求,直接忽略
}
@ -73,7 +73,7 @@ public class MatrixService {
if (!StringUtils.hasText(bo.appCode) || !StringUtils.hasText(bo.sign)) {
return;
}
MatrixApp app = mapper.queryApp(bo.appCode);
MatrixApp app = appMapper.queryByCode(bo.appCode);
if (app == null) {
return;
}
@ -87,7 +87,7 @@ public class MatrixService {
}
public List<MatrixAdvRecordSimple> getAdvList(String appCode, String deviceId) {
MatrixApp app = mapper.queryApp(appCode);
MatrixApp app = appMapper.queryByCode(appCode);
if (app == null) {
return null;
}

14
game-service/src/main/java/awesome/group/game/service/bo/matrix/AdvTypeIncome.java

@ -0,0 +1,14 @@
package awesome.group.game.service.bo.matrix;
public class AdvTypeIncome {
public int advType;
public long income;
public AdvTypeIncome() {
}
public AdvTypeIncome(int advType, long income) {
this.advType = advType;
this.income = income;
}
}

14
game-service/src/main/java/awesome/group/game/service/matrix/AdminService.java

@ -4,6 +4,7 @@ import awesome.group.game.dao.bean.*;
import awesome.group.game.dao.mapper.*;
import awesome.group.game.service.bo.*;
import awesome.group.game.service.bo.citrus.UserBo;
import awesome.group.game.service.bo.matrix.AdvTypeIncome;
import awesome.group.game.service.bo.matrix.MatrixAppBo;
import awesome.group.game.service.common.exception.PaganiException;
import awesome.group.game.service.common.exception.PaganiExceptionCode;
@ -379,6 +380,19 @@ public class AdminService {
mockScheduleMapper.insertBatch(list);
}
public List<AdvTypeIncome> advTypeIncomeToday(String code) {
MatrixApp app = appMapper.queryByCode(code);
Integer appId = app.getId();
String beginTime = DateUtil.getDayBegin();
Integer id = advRecordMapper.getBeginId(appId, beginTime);
if (id == null) {
return null;
}
List<MatrixAdvRecord> list = advRecordMapper.groupByAdvType(id, appId);
return list.stream().map(x -> new AdvTypeIncome(x.getAdvType(), x.getEcpm())).toList();
}
public OverviewBo incomeOverview(int adminId, String code) {
if (StringUtils.hasText(code)) {
MatrixApp app = appMapper.queryByCode(code);

23
game-service/src/main/java/awesome/group/game/service/matrix/AggregationService.java

@ -1,7 +1,10 @@
package awesome.group.game.service.matrix;
import awesome.group.game.dao.bean.MatrixAdvAggregation;
import awesome.group.game.dao.bean.MatrixApp;
import awesome.group.game.dao.mapper.MatrixAdvAggregationMapper;
import awesome.group.game.dao.mapper.MatrixAppMapper;
import awesome.group.game.service.bo.matrix.AdvTypeIncome;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jakarta.annotation.Resource;
@ -15,6 +18,9 @@ public class AggregationService {
@Resource
private MatrixAdvAggregationMapper aggregationMapper;
@Resource
private MatrixAppMapper appMapper;
public long getIncome(List<Integer> appIds, int startDate, int endDate) {
if (CollectionUtils.isEmpty(appIds)) {
return 0L;
@ -29,4 +35,21 @@ public class AggregationService {
}
return data.getIncome();
}
public List<AdvTypeIncome> advTypeIncomeHistory(String code, Integer beginDate, Integer endDate) {
MatrixApp app = appMapper.queryByCode(code);
Integer appId = app.getId();
LambdaQueryWrapper<MatrixAdvAggregation> query = new QueryWrapper<MatrixAdvAggregation>()
.select("adv_type, sum(income) as income").lambda();
query.eq(MatrixAdvAggregation::getAppId, appId);
if (beginDate != null) {
query.ge(MatrixAdvAggregation::getDate, beginDate);
}
if (endDate != null) {
query.le(MatrixAdvAggregation::getDate, endDate);
}
query.groupBy(MatrixAdvAggregation::getAdvType);
List<MatrixAdvAggregation> list = aggregationMapper.selectList(query);
return list.stream().map(x -> new AdvTypeIncome(x.getAdvType(), x.getIncome())).toList();
}
}

48
game-service/src/main/java/awesome/group/game/service/util/DateUtil.java

@ -36,6 +36,13 @@ public class DateUtil {
return x.getTimeInMillis();
}
public static String getDayBegin() {
LocalDateTime today0 = LocalDate.now().atStartOfDay();
// 格式化输出
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
return today0.format(formatter);
}
public static LocalDate long2Date(long timestamp) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp),
@ -73,52 +80,11 @@ public class DateUtil {
return Integer.parseInt(formatter.format(date));
}
public static Integer date2Number(Date date) {
SimpleDateFormat sdf = getSdf();
return Integer.parseInt(sdf.format(date));
}
public static Integer datePlus(Integer date, int plus) {
LocalDate localDate = number2Date(date);
return date2Number(localDate.plusDays(plus));
}
public static List<Integer> dateRange(Integer startDate, Integer endDate) {
LocalDate begin = number2Date(startDate);
LocalDate end = number2Date(endDate);
List<Integer> res = new ArrayList<>();
while (!begin.isAfter(end)) {
res.add(date2Number(begin));
begin = begin.plusDays(1);
}
return res;
}
public static List<Integer> latestDateRange(int minus, int plus) {
LocalDate todayDate = LocalDate.now();
List<Integer> res = new ArrayList<>();
for (int i = 0; i < minus; i++) {
LocalDate minusDate = todayDate.minusDays(minus - i);
res.add(date2Number(minusDate));
}
res.add(date2Number(todayDate));
for (int i = 1; i <= plus; i++) {
LocalDate plusDate = todayDate.plusDays(i);
res.add(date2Number(plusDate));
}
return res;
}
public static List<Integer> latestDate(int dayCnt) {
return latestDateRange(dayCnt, dayCnt);
}
public static int dayCntBetween(int date1, int date2) {
LocalDate localDate1 = number2Date(date1);
LocalDate localDate2 = number2Date(date2);
return (int) (localDate2.toEpochDay() - localDate1.toEpochDay());
}
public static long dayCntBetween(long timestamp1, long timestamp2) {
return 1 + (timestamp2 - timestamp1) / 86400_000;
}

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

@ -7,9 +7,11 @@ import awesome.group.game.dao.bean.MatrixWhiteDevice;
import awesome.group.game.service.MatrixService;
import awesome.group.game.service.bo.*;
import awesome.group.game.service.bo.citrus.UserBo;
import awesome.group.game.service.bo.matrix.AdvTypeIncome;
import awesome.group.game.service.bo.matrix.MatrixAppBo;
import awesome.group.game.service.common.response.R;
import awesome.group.game.service.matrix.AdminService;
import awesome.group.game.service.matrix.AggregationService;
import awesome.group.game.service.matrix.OSSService;
import awesome.group.game.service.util.JwtUtils;
import awesome.group.game.web.RequestContext;
@ -36,6 +38,9 @@ public class AdminController {
@Resource
private OSSService ossService;
@Resource
private AggregationService aggregationService;
@PostMapping("/login")
@RestApi
public R<Void> adminLogin(@RequestParam String name, @RequestParam String pwd) {
@ -119,6 +124,18 @@ public class AdminController {
return new R<>(R.CODE_SUCCESS, "ok", adminService.incomeDaily(query, RequestContext.getAdminID()));
}
@GetMapping("/advTypeIncomeHistory")
@RestApi
public R<List<AdvTypeIncome>> advTypeIncomeHistory(@RequestParam String code, @RequestParam(required = false) Integer beginDate, @RequestParam(required = false) Integer endDate) {
return new R<>(R.CODE_SUCCESS, "ok", aggregationService.advTypeIncomeHistory(code, beginDate, endDate));
}
@GetMapping("/advTypeIncomeToday")
@RestApi
public R<List<AdvTypeIncome>> advTypeIncomeToday(@RequestParam String code) {
return new R<>(R.CODE_SUCCESS, "ok", adminService.advTypeIncomeToday(code));
}
@PostMapping("/saveApp")
@RestApi
public R<Void> saveApp(@RequestBody MatrixApp matrixApp) {

Loading…
Cancel
Save