|
|
|
@ -5,8 +5,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
|
import com.bnyer.common.redis.service.RedisService; |
|
|
|
import com.bnyer.common.redis.service.RedissonService; |
|
|
|
import com.bnyer.img.constants.RedisKeyConstant; |
|
|
|
import com.bnyer.img.domain.CreatorProfit; |
|
|
|
import com.bnyer.img.domain.InviteLog; |
|
|
|
import com.bnyer.img.dto.CreatorProfitAdInsertDto; |
|
|
|
import com.bnyer.img.dto.CreatorProfitPageDto; |
|
|
|
import com.bnyer.img.dto.ProfitInOrEndDto; |
|
|
|
import com.bnyer.img.mapper.CreatorProfitMapper; |
|
|
|
@ -54,16 +56,33 @@ public class CreatorProfitServiceImpl implements CreatorProfitService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 写入下载次数 |
|
|
|
* @param appType 应用 |
|
|
|
* @param platform 平台 |
|
|
|
* @param userId 用户id |
|
|
|
*/ |
|
|
|
private void writePlatformUserDownloadNum(String appType,String platform,Long userId){ |
|
|
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
String date = df.format(new Date()); |
|
|
|
String hashKey = appType+":"+platform+":"+userId; |
|
|
|
log.info("日期【{}】应用【{}】平台【{}】用户【{}】下载数+1",date,appType,platform,userId); |
|
|
|
String redisKey = RedisKeyConstant.PLATFORM_USER_DOWNLOAD_KEY + date; |
|
|
|
redisService.hashIncr(redisKey, hashKey, 1); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public int insertCreatorProfit(CreatorProfit creatorProfit) { |
|
|
|
public int insertCreatorProfit(CreatorProfitAdInsertDto params) { |
|
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
long times = System.currentTimeMillis(); |
|
|
|
String date = format.format(times); |
|
|
|
String mark = creatorProfit.getCreatorId().toString() + creatorProfit.getImgId().toString() + creatorProfit.getAppType() + creatorProfit.getPlatform() + |
|
|
|
String mark = params.getCreatorId().toString() + params.getImgId().toString() + params.getAppType() + params.getPlatform() + |
|
|
|
"0" + date.replace("-", ""); |
|
|
|
//缓存中下载总数+1
|
|
|
|
tiktokImgService.writeDownloadTotalNum(creatorProfit.getAppType(), creatorProfit.getPlatform()); |
|
|
|
tiktokImgService.writeDownloadTotalNum(params.getAppType(), params.getPlatform()); |
|
|
|
//redis累计平台用户当天下载次数,12.00后过期
|
|
|
|
writePlatformUserDownloadNum(params.getAppType(), params.getPlatform(), params.getUserId()); |
|
|
|
//检查收益表是否存在广告记录,存在则更新次数
|
|
|
|
boolean b = this.checkCreatorProfitExist(mark); |
|
|
|
if (b) { |
|
|
|
@ -72,6 +91,12 @@ public class CreatorProfitServiceImpl implements CreatorProfitService { |
|
|
|
return update; |
|
|
|
} |
|
|
|
//不存在则新增广告记录
|
|
|
|
CreatorProfit creatorProfit = new CreatorProfit(); |
|
|
|
creatorProfit.setCreatorId(params.getCreatorId()); |
|
|
|
creatorProfit.setScanCode(params.getScanCode()); |
|
|
|
creatorProfit.setImgId(params.getImgId()); |
|
|
|
creatorProfit.setPlatform(params.getPlatform()); |
|
|
|
creatorProfit.setAppType(params.getAppType()); |
|
|
|
creatorProfit.setCreateTime(new Date()); |
|
|
|
creatorProfit.setUpdateTime(new Date()); |
|
|
|
creatorProfit.setType("0"); |
|
|
|
@ -81,7 +106,7 @@ public class CreatorProfitServiceImpl implements CreatorProfitService { |
|
|
|
creatorProfit.setDownloadNum(1); |
|
|
|
creatorProfit.setMark(mark); |
|
|
|
//根据平台生成订单号
|
|
|
|
switch (creatorProfit.getPlatform()) { |
|
|
|
switch (params.getPlatform()) { |
|
|
|
case "0": |
|
|
|
creatorProfit.setOrderNo("DY" + IdUtil.getSnowflakeNextIdStr()); |
|
|
|
break; |
|
|
|
@ -231,6 +256,21 @@ public class CreatorProfitServiceImpl implements CreatorProfitService { |
|
|
|
log.info("==============批量更新艺术家收益状态完成,耗时【{}】毫秒!===============", System.currentTimeMillis() - startTime); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void batchDeleteUserDownloadNum() { |
|
|
|
log.info("==============批量删除昨日用户下载次数开始!==============="); |
|
|
|
long startTime = System.currentTimeMillis(); |
|
|
|
//获取昨日日期
|
|
|
|
Date yesterday = new Date(startTime - 1000 * 60 * 60 * 24); |
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
String date = simpleDateFormat.format(yesterday); |
|
|
|
String redisKey = RedisKeyConstant.PLATFORM_USER_DOWNLOAD_KEY + date; |
|
|
|
if(redisService.hasKey(redisKey)){ |
|
|
|
redisService.deleteObject(redisKey); |
|
|
|
} |
|
|
|
log.info("==============批量删除昨日用户下载次数完成,耗时【{}】毫秒!===============", System.currentTimeMillis() - startTime); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ProfitVo queryFrontProfitInfo(Long creatorId) { |
|
|
|
//累计收益
|
|
|
|
@ -319,4 +359,24 @@ public class CreatorProfitServiceImpl implements CreatorProfitService { |
|
|
|
public int batchUpdate(List<Long> list) { |
|
|
|
return creatorProfitMapper.batchUpdateTransInfo(list); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean checkUserCanDownload(Long userId, String platform, String appType) { |
|
|
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
String date = df.format(new Date()); |
|
|
|
String hashKey = appType+":"+platform+":"+userId; |
|
|
|
String redisKey = RedisKeyConstant.PLATFORM_USER_DOWNLOAD_KEY + date; |
|
|
|
if(redisService.hasHashKey(redisKey,hashKey)){ |
|
|
|
//存在键,判断次数,次数达标则不可下载
|
|
|
|
Integer downloadNum = redisService.getCacheMapValue(redisKey, hashKey); |
|
|
|
if(downloadNum >= 5){ |
|
|
|
return true; |
|
|
|
}else{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
}else{ |
|
|
|
//不存在键则可下载
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|