|
|
@ -1,30 +1,23 @@ |
|
|
package com.bnyer.img.service.impl; |
|
|
package com.bnyer.img.service.impl; |
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
import com.bnyer.common.core.utils.StringUtils; |
|
|
import com.bnyer.common.core.utils.StringUtils; |
|
|
import com.bnyer.common.redis.service.RedisService; |
|
|
import com.bnyer.common.redis.service.RedisService; |
|
|
import com.bnyer.img.constants.RedisKeyConstant; |
|
|
|
|
|
import com.bnyer.img.domain.CreatorProfit; |
|
|
import com.bnyer.img.domain.CreatorProfit; |
|
|
import com.bnyer.img.dto.CreatorProfitAdInsertDto; |
|
|
|
|
|
import com.bnyer.img.dto.CreatorProfitInviteInsertDto; |
|
|
|
|
|
import com.bnyer.img.dto.CreatorProfitPageDto; |
|
|
import com.bnyer.img.dto.CreatorProfitPageDto; |
|
|
import com.bnyer.img.mapper.CreatorProfitMapper; |
|
|
import com.bnyer.img.mapper.CreatorProfitMapper; |
|
|
import com.bnyer.img.service.CreatorProfitService; |
|
|
import com.bnyer.img.service.CreatorProfitService; |
|
|
import com.bnyer.img.service.TiktokImgService; |
|
|
import com.bnyer.img.service.TiktokImgService; |
|
|
import com.bnyer.img.vo.*; |
|
|
import com.bnyer.img.vo.ProfitVo; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.Date; |
|
|
import java.util.Date; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
@Service |
|
|
@Slf4j |
|
|
@Slf4j |
|
|
@ -40,80 +33,37 @@ public class CreatorProfitServiceImpl implements CreatorProfitService { |
|
|
private TiktokImgService tiktokImgService; |
|
|
private TiktokImgService tiktokImgService; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public boolean insertPreAdProfit(CreatorProfitAdInsertDto params) { |
|
|
public boolean checkCreatorProfitExist(Long creatorId, Long imgId,String appType,String platform, String date) { |
|
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
LambdaQueryWrapper<CreatorProfit> wrapper = new LambdaQueryWrapper<>(); |
|
|
String date = df.format(new Date()); |
|
|
wrapper.eq(CreatorProfit::getCreatorId, creatorId); |
|
|
String redisKey = RedisKeyConstant.WECHAT_CREATOR_DOWNLOAD_KEY + date; |
|
|
wrapper.eq(CreatorProfit::getImgId, imgId); |
|
|
String hashKey = params.getCreatorId()+":"+params.getImgId()+":"+params.getAppType()+":"+params.getPlatform(); |
|
|
wrapper.eq(CreatorProfit::getAppType, appType); |
|
|
try{ |
|
|
wrapper.eq(CreatorProfit::getPlatform,platform); |
|
|
if(!redisService.hasHashKey(redisKey,hashKey)){ |
|
|
wrapper.eq(CreatorProfit::getCreateTime, date); |
|
|
//写入入账缓存
|
|
|
CreatorProfit creatorProfit = creatorProfitMapper.selectOne(wrapper); |
|
|
params.setCreateTime(new Date()); |
|
|
if(creatorProfit != null){ |
|
|
redisService.setCacheMapValue(redisKey,hashKey, JSON.toJSON(params)); |
|
|
|
|
|
log.info("艺术家id【{}】图片【{}】应用【{}】平台【{}】被下载了,写入即将入账广告缓存成功!", |
|
|
|
|
|
params.getCreatorId(),params.getImgId(),params.getAppType(),params.getPlatform()); |
|
|
|
|
|
} |
|
|
|
|
|
//写入图片下载量缓存
|
|
|
|
|
|
tiktokImgService.writeDownloadNum(params.getCreatorId(),params.getAppType(),params.getImgId(),params.getPlatform()); |
|
|
|
|
|
//写入应用平台下载数量缓存
|
|
|
|
|
|
tiktokImgService.writeDownloadTotalNum(params.getAppType(),params.getPlatform()); |
|
|
|
|
|
return true; |
|
|
|
|
|
}catch (Exception e){ |
|
|
|
|
|
log.error("写入即将入账广告缓存失败!失败原因为:",e); |
|
|
|
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
}else{ |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public boolean insertPreInviteProfit(CreatorProfitInviteInsertDto params) { |
|
|
|
|
|
String redisKey = RedisKeyConstant.WECHAT_CREATOR_INVITE_KEY + params.getCreatorId(); |
|
|
|
|
|
//被邀请人搜索码
|
|
|
|
|
|
String hashKey = params.getScanCode(); |
|
|
|
|
|
try{ |
|
|
|
|
|
if(!redisService.hasHashKey(redisKey,hashKey)){ |
|
|
|
|
|
//写入入账缓存
|
|
|
|
|
|
params.setCreateTime(new Date()); |
|
|
|
|
|
redisService.setCacheMapValue(redisKey,hashKey, JSON.toJSON(params)); |
|
|
|
|
|
log.info("艺术家id【{}】邀请了搜索码【{}】成为艺术家,写入即将入账邀请缓存成功!", |
|
|
|
|
|
params.getCreatorId(),params.getScanCode()); |
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
return true; |
|
|
}catch (Exception e){ |
|
|
|
|
|
log.error("写入即将入账邀请缓存失败!失败原因为:",e); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
public int insertAd(Long creatorId) { |
|
|
public int insertCreatorProfit(CreatorProfit creatorProfit) { |
|
|
//TODO 确认收益后讲缓存中信息批量写入数据库,删除对应缓存
|
|
|
|
|
|
List<CreatorPreAdProfitVo> creatorPreProfitVos = this.queryFrontPreAdProfitList(creatorId); |
|
|
|
|
|
CreatorProfit creatorProfit = new CreatorProfit(); |
|
|
|
|
|
creatorProfit.setCreateTime(new Date()); |
|
|
creatorProfit.setCreateTime(new Date()); |
|
|
creatorProfit.setUpdateTime(new Date()); |
|
|
creatorProfit.setUpdateTime(new Date()); |
|
|
creatorProfit.setIncomeTime(new Date()); |
|
|
creatorProfit.setStatus("0"); |
|
|
creatorProfit.setStatus("1"); |
|
|
|
|
|
creatorProfit.setConfirmStatus("0"); |
|
|
|
|
|
creatorProfit.setIsShow("1"); |
|
|
creatorProfit.setIsShow("1"); |
|
|
creatorProfit.setSort(0); |
|
|
creatorProfit.setSort(0); |
|
|
|
|
|
creatorProfit.setDownloadNum(1); |
|
|
return creatorProfitMapper.insert(creatorProfit); |
|
|
return creatorProfitMapper.insert(creatorProfit); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
public int insertInvite(Long creatorId) { |
|
|
public int updateCreatorProfitDownloadNum(Long creatorId, Long imgId, String appType, String platform, String date) { |
|
|
//TODO 确认收益后讲缓存中信息批量写入数据库,删除对应缓存
|
|
|
return creatorProfitMapper.updateDownloadNum(creatorId,imgId,appType,platform,date); |
|
|
List<CreatorPreInviteProfitVo> creatorPreProfitVos = this.queryFrontPreInviteProfitList(creatorId); |
|
|
|
|
|
CreatorProfit creatorProfit = new CreatorProfit(); |
|
|
|
|
|
creatorProfit.setCreateTime(new Date()); |
|
|
|
|
|
creatorProfit.setUpdateTime(new Date()); |
|
|
|
|
|
creatorProfit.setIncomeTime(new Date()); |
|
|
|
|
|
creatorProfit.setStatus("1"); |
|
|
|
|
|
creatorProfit.setConfirmStatus("0"); |
|
|
|
|
|
creatorProfit.setIsShow("1"); |
|
|
|
|
|
creatorProfit.setSort(0); |
|
|
|
|
|
return creatorProfitMapper.insert(creatorProfit); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
@ -210,85 +160,6 @@ public class CreatorProfitServiceImpl implements CreatorProfitService { |
|
|
log.info("==============批量更新艺术家收益状态完成,耗时【{}】毫秒!===============",System.currentTimeMillis() - startTime); |
|
|
log.info("==============批量更新艺术家收益状态完成,耗时【{}】毫秒!===============",System.currentTimeMillis() - startTime); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public List<CreatorPreAdProfitVo> queryFrontPreAdProfitList(Long creatorId) { |
|
|
|
|
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
|
|
String date = df.format(new Date()); |
|
|
|
|
|
String redisKey = RedisKeyConstant.WECHAT_CREATOR_DOWNLOAD_KEY + date; |
|
|
|
|
|
String imgKey = RedisKeyConstant.TIKTOK_IMG_DOWNLOAD_NUM_KEY + date; |
|
|
|
|
|
//获取基础图片信息
|
|
|
|
|
|
List<CreatorPreAdProfitVo> list = new ArrayList<>(); |
|
|
|
|
|
try{ |
|
|
|
|
|
if(redisService.hasKey(redisKey)){ |
|
|
|
|
|
CreatorPreAdProfitVo profitVo = null; |
|
|
|
|
|
Map<String, Object> cacheMap = redisService.getCacheMap(redisKey); |
|
|
|
|
|
for (Map.Entry<String, Object> stringObjectEntry : cacheMap.entrySet()) { |
|
|
|
|
|
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(stringObjectEntry.getValue())); |
|
|
|
|
|
profitVo = new CreatorPreAdProfitVo(); |
|
|
|
|
|
profitVo.setCreatorId(creatorId); |
|
|
|
|
|
profitVo.setImgId(Long.valueOf(jsonObject.getString("imgId"))); |
|
|
|
|
|
profitVo.setImgUrl(jsonObject.getString("imgUrl")); |
|
|
|
|
|
profitVo.setAppType(jsonObject.getString("appType")); |
|
|
|
|
|
profitVo.setType(jsonObject.getString("type")); |
|
|
|
|
|
profitVo.setPlatform(jsonObject.getString("platform")); |
|
|
|
|
|
profitVo.setScanCode(jsonObject.getString("scanCode")); |
|
|
|
|
|
profitVo.setStatus(jsonObject.getString("status")); |
|
|
|
|
|
profitVo.setCreateTime(new Date(Long.parseLong(jsonObject.getString("createTime")))); |
|
|
|
|
|
//获取图片下载量
|
|
|
|
|
|
if(redisService.hasHashKey(imgKey,stringObjectEntry.getKey())){ |
|
|
|
|
|
Integer downloadNum = (Integer) redisService.getCacheMapValue(imgKey, stringObjectEntry.getKey()); |
|
|
|
|
|
profitVo.setDownloadNum(downloadNum); |
|
|
|
|
|
} |
|
|
|
|
|
list.add(profitVo); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}catch (Exception e){ |
|
|
|
|
|
log.error("艺术家查询即将入账广告收益失败,错误为:",e); |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return list; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public List<CreatorPreInviteProfitVo> queryFrontPreInviteProfitList(Long creatorId) { |
|
|
|
|
|
String redisKey = RedisKeyConstant.WECHAT_CREATOR_DOWNLOAD_KEY + creatorId; |
|
|
|
|
|
//获取邀请列表信息
|
|
|
|
|
|
List<CreatorPreInviteProfitVo> list = new ArrayList<>(); |
|
|
|
|
|
try{ |
|
|
|
|
|
if(redisService.hasKey(redisKey)){ |
|
|
|
|
|
CreatorPreInviteProfitVo profitVo = null; |
|
|
|
|
|
Map<String, Object> cacheMap = redisService.getCacheMap(redisKey); |
|
|
|
|
|
for (Map.Entry<String, Object> stringObjectEntry : cacheMap.entrySet()) { |
|
|
|
|
|
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(stringObjectEntry.getValue())); |
|
|
|
|
|
profitVo = new CreatorPreInviteProfitVo(); |
|
|
|
|
|
profitVo.setCreatorId(creatorId); |
|
|
|
|
|
profitVo.setHeadUrl(jsonObject.getString("headUrl")); |
|
|
|
|
|
profitVo.setAppType(jsonObject.getString("appType")); |
|
|
|
|
|
profitVo.setType(jsonObject.getString("type")); |
|
|
|
|
|
profitVo.setScanCode(jsonObject.getString("scanCode")); |
|
|
|
|
|
profitVo.setStatus(jsonObject.getString("status")); |
|
|
|
|
|
profitVo.setCreateTime(new Date(Long.parseLong(jsonObject.getString("createTime")))); |
|
|
|
|
|
list.add(profitVo); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}catch (Exception e){ |
|
|
|
|
|
log.error("艺术家查询即将入账邀请收益失败,错误为:",e); |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
return list; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public CreatorIncomeProfitVo queryFrontIncomeProfit(Long creatorId) { |
|
|
|
|
|
return creatorProfitMapper.queryFrontIncomeProfit(creatorId); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public CreatorTransIntoProfitVo queryFrontTransIntoProfit(Long creatorId) { |
|
|
|
|
|
return creatorProfitMapper.queryFrontTransIntoProfit(creatorId); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public ProfitVo queryFrontProfitInfo(Long creatorId) { |
|
|
public ProfitVo queryFrontProfitInfo(Long creatorId) { |
|
|
//TODO 计算收益
|
|
|
//TODO 计算收益
|
|
|
|