|
|
@@ -7,14 +7,9 @@ import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
-import com.ytpm.advertise.enums.AdSourceTypeEnum;
|
|
|
-import com.ytpm.agent.enums.UserStatusEnum;
|
|
|
import com.ytpm.agent.param.AdRecordListParam;
|
|
|
import com.ytpm.agent.param.AuditCheckParam;
|
|
|
-import com.ytpm.agent.param.AuditUserParam;
|
|
|
-import com.ytpm.agent.view.AgentAuditCheckVO;
|
|
|
import com.ytpm.app.model.YtDyzAdRecord;
|
|
|
-import com.ytpm.app.model.YtDyzLoginRecord;
|
|
|
import com.ytpm.app.model.YtNovelUser;
|
|
|
import com.ytpm.app.model.YtUser;
|
|
|
import com.ytpm.app.param.AppQueryUserTodayTimeParam;
|
|
|
@@ -23,7 +18,6 @@ import com.ytpm.app.param.AppUserQueryParam;
|
|
|
import com.ytpm.app.param.AppUserTodayBannedParam;
|
|
|
import com.ytpm.app.param.YtAppUserListParam;
|
|
|
import com.ytpm.app.view.HourCountView;
|
|
|
-import com.ytpm.app.view.WxDefaultConfig;
|
|
|
import com.ytpm.app.view.YtAppUserListView;
|
|
|
import com.ytpm.general.RepMessage;
|
|
|
import com.ytpm.general.Result;
|
|
|
@@ -31,16 +25,10 @@ import com.ytpm.general.ResultTable;
|
|
|
import com.ytpm.novel.dao.AdRecordMapper;
|
|
|
import com.ytpm.novel.dao.AppUserMapper;
|
|
|
import com.ytpm.novel.dao.LoginRecordMapper;
|
|
|
-import com.ytpm.novel.dao.NovelAdRecordMapper;
|
|
|
import com.ytpm.novel.model.dto.UserStaticParam;
|
|
|
-import com.ytpm.novel.redis.RedisService;
|
|
|
-import com.ytpm.risk.enums.BannedTypeEnum;
|
|
|
-import com.ytpm.risk.view.RiskConfigView;
|
|
|
-import com.ytpm.risk.view.RiskTemplateView;
|
|
|
-import com.ytpm.util.NumberUtils;
|
|
|
+import com.ytpm.novel.service.UserService;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
@@ -51,7 +39,6 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.math.RoundingMode;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
@@ -59,9 +46,7 @@ import java.util.ArrayList;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author lih
|
|
|
@@ -79,12 +64,7 @@ public class UserController {
|
|
|
@Resource
|
|
|
private AdRecordMapper adRecordMapper;
|
|
|
@Resource
|
|
|
- private NovelAdRecordMapper novelAdRecordMapper;
|
|
|
- @Resource
|
|
|
- private RedisService redisService;
|
|
|
-
|
|
|
- @Value("${yt.revenue.scale:3}")
|
|
|
- private Integer revenueScale;
|
|
|
+ private UserService userService;
|
|
|
|
|
|
|
|
|
@ApiOperation("根据应用ID查询当月注册用户")
|
|
|
@@ -99,48 +79,11 @@ public class UserController {
|
|
|
*/
|
|
|
@PostMapping("/queryAll")
|
|
|
public ResultTable<YtAppUserListView> queryAll(@RequestBody YtAppUserListParam param) {
|
|
|
- //查询主应用
|
|
|
- PageHelper.startPage(param.getPage(), param.getLimit());
|
|
|
- List<YtAppUserListView> result = appUserMapper.queryAll(param);
|
|
|
- String collect = result.stream().map(YtAppUserListView::getUserId).collect(Collectors.joining(","));
|
|
|
- List<YtDyzAdRecord> adRecords = adRecordMapper.getByUserIds(collect);
|
|
|
- List<YtDyzLoginRecord> dyzLogins = loginRecordMapper.getLoginRecordByIds(collect);
|
|
|
- Map<String, List<YtDyzAdRecord>> userAdMap = adRecords.stream().collect(
|
|
|
- Collectors.groupingBy(YtDyzAdRecord::getUserId));
|
|
|
- Map<String, List<YtDyzLoginRecord>> loginMap = dyzLogins.stream().collect(
|
|
|
- Collectors.groupingBy(YtDyzLoginRecord::getUserId));
|
|
|
- setUserExtInfo(result, userAdMap, loginMap);
|
|
|
+ List<YtAppUserListView> result = userService.queryAll(param);
|
|
|
return ResultTable.resultTableOk(new PageInfo<>(result));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 设置视频记录和登录信息
|
|
|
- */
|
|
|
- private void setUserExtInfo(List<YtAppUserListView> result, Map<String, List<YtDyzAdRecord>> userAdMap,
|
|
|
- Map<String, List<YtDyzLoginRecord>> loginMap) {
|
|
|
- for (YtAppUserListView user : result) {
|
|
|
- if (loginMap.containsKey(user.getUserId())) {
|
|
|
- user.setLoginRecordList(loginMap.get(user.getUserId()));
|
|
|
- }
|
|
|
- //获取今日收益 | 今日视频播放数
|
|
|
- if (userAdMap.containsKey(user.getUserId())) {
|
|
|
- List<YtDyzAdRecord> ytDyzAdRecords = userAdMap.get(user.getUserId());
|
|
|
- List<YtDyzAdRecord> collect = ytDyzAdRecords.stream().filter(
|
|
|
- s -> DateUtil.isSameDay(DateUtil.date(), DateUtil.parseDate(s.getFinishTime()))).collect(Collectors.toList());
|
|
|
- BigDecimal todayIncome = collect.stream().map(YtDyzAdRecord::getRevenue).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- user.setTodayVideo((int) collect.stream().filter(
|
|
|
- s -> s.getAdSourceType() == AdSourceTypeEnum.rewarded_video.getAdSourceType()).count());
|
|
|
- user.setTodayIncome(todayIncome);
|
|
|
- // 统计4天-今日收益=前三日收益
|
|
|
- if (user.getNearlyIncome() != null && user.getNearlyIncome().compareTo(todayIncome) >= 0) {
|
|
|
- user.setNearlyIncome(user.getNearlyIncome().subtract(todayIncome));
|
|
|
- }
|
|
|
- } else {
|
|
|
- user.setTodayIncome(BigDecimal.ZERO);
|
|
|
- user.setTodayVideo(0);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
@ApiOperation("根据时间统计收益")
|
|
|
@PostMapping("/getRevenueByTime")
|
|
|
@@ -158,29 +101,7 @@ public class UserController {
|
|
|
*/
|
|
|
@GetMapping("/getUserInfo")
|
|
|
public Result<YtNovelUser> getUserInfo(@RequestParam("userId") String userId) {
|
|
|
- YtNovelUser user = appUserMapper.selectPrimaryKey(userId);
|
|
|
- if (user != null) {
|
|
|
- user.setLoginRecordList(loginRecordMapper.getLoginRecords(userId));
|
|
|
- user.setNovelAdRecordList(novelAdRecordMapper.selectToDayNovelRecode(userId));
|
|
|
- // 分层系数
|
|
|
- WxDefaultConfig defaultConfig = appUserMapper.getDefaultConfigByAppId(user.getAppId());
|
|
|
- String revenueDisplayRate = defaultConfig == null ? "" : defaultConfig.getRevenueDisplayRate();
|
|
|
- BigDecimal todayRevenue = adRecordMapper.getToTalRevenue(userId, 1);
|
|
|
- BigDecimal totalRevenue = user.getTotalIncome() == null ? adRecordMapper.getToTalRevenue(userId, 2) : user.getTotalIncome();
|
|
|
- if (StrUtil.isNotEmpty(revenueDisplayRate)) {
|
|
|
- BigDecimal rate = NumberUtils.rateToBigDecimal(revenueDisplayRate);
|
|
|
- todayRevenue = todayRevenue.multiply(rate).setScale(revenueScale, RoundingMode.HALF_UP);
|
|
|
- totalRevenue = totalRevenue.multiply(rate).setScale(revenueScale, RoundingMode.HALF_UP);
|
|
|
- }
|
|
|
- // 今日收益
|
|
|
- user.setTodayIncome(todayRevenue);
|
|
|
- // 历史收益
|
|
|
- user.setTotalIncome(totalRevenue);
|
|
|
- // 前三日总收益
|
|
|
- if (user.getNearlyIncome() != null) {
|
|
|
- user.setNearlyIncome(user.getNearlyIncome().setScale(revenueScale, RoundingMode.HALF_UP));
|
|
|
- }
|
|
|
- }
|
|
|
+ YtNovelUser user = userService.getUserInfo(userId);
|
|
|
return Result.resultObjOk(user);
|
|
|
}
|
|
|
|
|
|
@@ -304,24 +225,12 @@ public class UserController {
|
|
|
|
|
|
@PostMapping("/unLockUser")
|
|
|
public void unLockUser(@RequestParam("userIds") String userIds) {
|
|
|
- List<YtNovelUser> users = appUserMapper.queryByUserIds(userIds);
|
|
|
- if (CollUtil.isNotEmpty(users)) {
|
|
|
- appUserMapper.unlockUser(userIds);
|
|
|
- }
|
|
|
+ userService.unLockUser(userIds);
|
|
|
}
|
|
|
|
|
|
@GetMapping("/lockUser")
|
|
|
public YtNovelUser lockUser(@RequestParam("userId") String userId, @RequestParam("userStatus") Integer userStatus) {
|
|
|
- YtNovelUser dyzUser = appUserMapper.selectPrimaryKey(userId);
|
|
|
- YtNovelUser newUser = new YtNovelUser();
|
|
|
- newUser.setUserId(userId);
|
|
|
- newUser.setUserStatus(userStatus);
|
|
|
- newUser.setRiskReason(BannedTypeEnum.CHANNEL.getDesc() + "禁止登录");
|
|
|
- if (Objects.nonNull(dyzUser)) {
|
|
|
- appUserMapper.updateUser(newUser);
|
|
|
- return dyzUser;
|
|
|
- }
|
|
|
- return null;
|
|
|
+ return userService.lockUser(userId, userStatus);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -330,91 +239,7 @@ public class UserController {
|
|
|
*/
|
|
|
@PostMapping("/batchAudit")
|
|
|
public void batchAudit(@RequestBody AuditCheckParam checkParam) {
|
|
|
- AuditUserParam auditParam = checkParam.getAuditParam();
|
|
|
- RiskTemplateView ecpmLimit = checkParam.getEcpmLimit();
|
|
|
- RiskTemplateView revenueLimit = checkParam.getRevenueLimit();
|
|
|
- //查询用户,指定应用激励视频的广告记录
|
|
|
- List<AgentAuditCheckVO> auditList = new ArrayList<>();
|
|
|
- List<AgentAuditCheckVO> auditCheckList = appUserMapper.queryTodayUserAd(auditParam);
|
|
|
- if (CollUtil.isNotEmpty(auditCheckList)) {
|
|
|
- auditList.addAll(auditCheckList);
|
|
|
- }
|
|
|
- Map<String, List<YtDyzAdRecord>> adRecordMap = auditList.stream().collect(
|
|
|
- Collectors.toMap(AgentAuditCheckVO::getUserId, AgentAuditCheckVO::getAdRecordList));
|
|
|
- checkRisk742(ecpmLimit, adRecordMap, auditParam);
|
|
|
- checkRisk746(revenueLimit, adRecordMap, auditParam);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 校验默认风控规则742
|
|
|
- */
|
|
|
- private void checkRisk742(RiskTemplateView ecpmLimit, Map<String, List<YtDyzAdRecord>> adRecordMap, AuditUserParam auditParam) {
|
|
|
- if (ecpmLimit.getEnabled() != 1) return;
|
|
|
- Map<String, String> limitMap = ecpmLimit.getConfigList().stream().collect(
|
|
|
- Collectors.toMap(RiskConfigView::getFieldName, RiskConfigView::getConfigVal));
|
|
|
- int adCount = 0;
|
|
|
- for (Map.Entry<String, List<YtDyzAdRecord>> entry : adRecordMap.entrySet()) {
|
|
|
- adCount = CollUtil.isEmpty(entry.getValue()) ? adCount : entry.getValue().size();
|
|
|
- ++adCount;
|
|
|
- //判断当日观看视频数已经达到风控条件预设的视频数
|
|
|
- int firstAdCount = Integer.parseInt(limitMap.get("firstAdCount"));
|
|
|
- if (adCount >= firstAdCount) {
|
|
|
- //过滤出ecpm值小于预设值的视频数
|
|
|
- int ecpm = Integer.parseInt(limitMap.get("ecpm"));
|
|
|
- long count = entry.getValue().stream().filter(
|
|
|
- s -> Objects.nonNull(s.getEcpm()) && (s.getEcpm().compareTo(BigDecimal.valueOf(ecpm))) < 0).count();
|
|
|
- int exact = Math.toIntExact(count);
|
|
|
- //判断小于预设值的视频数超出预设次数
|
|
|
- int haveCount = Integer.parseInt(limitMap.get("haveCount"));
|
|
|
- if (exact > haveCount) {//把风控不满足的用户记录redis 进行封禁
|
|
|
- checkLock(entry, auditParam);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 用户锁定操作
|
|
|
- */
|
|
|
- private void checkLock(Map.Entry<String, List<YtDyzAdRecord>> entry, AuditUserParam auditParam) {
|
|
|
- log.error("执行对低价值用户{}的定时风控操作", entry.getKey());
|
|
|
- if (auditParam.getEffectTime() == 0) { //立即锁定
|
|
|
- lockUser(entry.getKey(), UserStatusEnum.RISK.getCode());
|
|
|
- redisService.setTimeOutHoursStr("unlock_" + entry.getKey(), auditParam.getAppId(), auditParam.getBannedLimit() * 24L);
|
|
|
- } else {//延迟锁定
|
|
|
- redisService.setTimeOutHoursStr("lock_" + entry.getKey(), auditParam.getAppId(), auditParam.getEffectTime());
|
|
|
- redisService.setTimeOutHoursStr("unlock_" + entry.getKey(), auditParam.getAppId(),
|
|
|
- auditParam.getBannedLimit() * 24L + auditParam.getEffectTime());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 校验默认风控规则746
|
|
|
- */
|
|
|
- private void checkRisk746(RiskTemplateView revenueLimit, Map<String, List<YtDyzAdRecord>> adRecordMap,
|
|
|
- AuditUserParam auditParam) {
|
|
|
- if (revenueLimit.getEnabled() != 1) return;
|
|
|
- Map<String, String> revenueMap = revenueLimit.getConfigList().stream().collect(
|
|
|
- Collectors.toMap(RiskConfigView::getFieldName, RiskConfigView::getConfigVal));
|
|
|
- for (Map.Entry<String, List<YtDyzAdRecord>> entry : adRecordMap.entrySet()) {
|
|
|
- List<YtDyzAdRecord> revenues = entry.getValue().stream().filter(
|
|
|
- s -> Objects.nonNull(s.getRevenue()) && (s.getRevenue().compareTo(BigDecimal.ZERO)) > 0)
|
|
|
- .collect(Collectors.toList());
|
|
|
- int incomeCount = 0;
|
|
|
- incomeCount = CollUtil.isEmpty(revenues) ? incomeCount : entry.getValue().size();
|
|
|
- //判断当日获得收益的广告达到预设数值,触发风控规则
|
|
|
- int rewardCount = Integer.parseInt(revenueMap.get("rewardCount"));
|
|
|
- if (incomeCount >= rewardCount) {
|
|
|
- BigDecimal income = new BigDecimal(revenueMap.get("income"));
|
|
|
- //获取最先的两条
|
|
|
- BigDecimal reduce = revenues.stream().map(YtDyzAdRecord::getRevenue).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- if (reduce.compareTo(income) < 0) {
|
|
|
- checkLock(entry, auditParam);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ userService.batchAudit(checkParam);
|
|
|
}
|
|
|
|
|
|
}
|