Browse Source

下载次数限制

feature-1.0-img-prototype
qyhdd 4 years ago
parent
commit
000d7a3a79
  1. 104
      bnyer-services/bnyer-file/src/main/java/com/bnyer/file/constants/RedisKeyConstant.java
  2. 6
      bnyer-services/bnyer-file/src/main/java/com/bnyer/file/service/IFileService.java
  3. 19
      bnyer-services/bnyer-file/src/main/java/com/bnyer/file/service/impl/FileServiceImpl.java
  4. 4
      bnyer-services/bnyer-img/src/main/java/com/bnyer/img/constants/RedisKeyConstant.java
  5. 6
      bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/CreatorMiniController.java
  6. 27
      bnyer-services/bnyer-img/src/main/java/com/bnyer/img/dto/CreatorDownloadDto.java
  7. 7
      bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/CreatorProfitService.java
  8. 30
      bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/CreatorProfitServiceImpl.java
  9. 7
      bnyer-services/bnyer-img/src/main/java/com/bnyer/img/task/UserDownloadSyncTask.java

104
bnyer-services/bnyer-file/src/main/java/com/bnyer/file/constants/RedisKeyConstant.java

@ -0,0 +1,104 @@
package com.bnyer.file.constants;
public class RedisKeyConstant {
/**
* 抖音小程序用户收藏图片键
*/
public static final String TIKTOK_USER_COLLECT_KEY = "bnyer.img.tiktok.collect:";
/**
* 抖音小程序图片收藏数量键
*/
public static final String TIKTOK_IMG_COLLECT_NUM_KEY = "bnyer.img.tiktok.collectNum";
/**
* 快手小程序图片收藏数量键
*/
public static final String FAST_HAND_IMG_COLLECT_NUM_KEY = "bnyer.img.fh.collectNum";
/**
* 微信小程序图片收藏数量键
*/
public static final String WECHAT_IMG_COLLECT_NUM_KEY = "bnyer.img.wx.collectNum";
/**
* 抖音小程序用户点赞图片键
*/
public static final String TIKTOK_USER_LIKE_KEY = "bnyer.img.tiktok.like";
/**
* 快手小程序用户点赞图片键
*/
public static final String FAST_HAND_USER_LIKE_KEY = "bnyer.img.fh.like";
/**
* 微信小程序用户点赞图片键
*/
public static final String WECHAT_USER_LIKE_KEY = "bnyer.img.wx.like";
/**
* 抖音小程序图片点赞数量键
*/
public static final String TIKTOK_IMG_LIKE_NUM_KEY = "bnyer.img.tiktok.likeNum";
/**
* 快手小程序图片点赞数量键
*/
public static final String FAST_HAND_IMG_LIKE_NUM_KEY = "bnyer.img.fh.likeNum";
/**
* 微信小程序图片点赞数量键
*/
public static final String WECHAT_IMG_LIKE_NUM_KEY = "bnyer.img.wx.likeNum";
/**
* 抖音小程序图片下载数量键
*/
public static final String TIKTOK_IMG_DOWNLOAD_NUM_KEY = "bnyer.img.creator.downloadNum:";
/**
* 抖音小程序图片下载总数量键
*/
public static final String TIKTOK_IMG_TOTAL_DOWNLOAD_NUM_KEY = "bnyer.img.date.downloadTotalNum:";
/**
* 抖音小程序用户登录键
*/
public static final String TIKTOK_USER_LOGIN_KEY = "bnyer.img.tiktok.user:";
/**
* 快手小程序用户登录键
*/
public static final String FH_USER_LOGIN_KEY = "bnyer.img.fh.user:";
/**
* 微信小程序用户登录键
*/
public static final String WECHAT_USER_LOGIN_KEY = "bnyer.img.wx.user:";
/**
* 微信小程序艺术家登录键
*/
public static final String WECHAT_CREATOR_LOGIN_KEY = "bnyer.img.wechat.creator:";
/**
* 微信小程序艺术家邀请键
*/
public static final String WECHAT_CREATOR_INVITE_KEY = "bnyer.img.invite.creator:";
/**
* 审核收益锁键
*/
public static final String VERIFY_PROFIT_LOCK_KEY = "bnyer.img.profit.lock:";
/**
* 平台用户下载键
*/
public static final String PLATFORM_USER_DOWNLOAD_KEY = "bnyer.img.user.download:";
/**
* 艺术家上传键
*/
public static final String CREATOR_DOWNLOAD_KEY="bnyer.img.createor.download";
}

6
bnyer-services/bnyer-file/src/main/java/com/bnyer/file/service/IFileService.java

@ -16,4 +16,10 @@ public interface IFileService {
ArrayList<ChekFileVo> checkImg(ArrayList<MultipartFile> multipartFiles);
//图片检测+图片上传+图片保存
void checkUploadSave(FileUploadDto fileUploadDto) throws IOException;
/**
* 写入艺术家上传次数
* @param creator 艺术家id
*/
void writeDownloadTotalNum(Long creator);
}

19
bnyer-services/bnyer-file/src/main/java/com/bnyer/file/service/impl/FileServiceImpl.java

@ -1,5 +1,7 @@
package com.bnyer.file.service.impl;
import com.bnyer.common.redis.service.RedisService;
import com.bnyer.file.constants.RedisKeyConstant;
import com.bnyer.file.dto.FileDto;
import com.bnyer.file.dto.FileUploadDto;
import com.bnyer.file.service.IFileService;
@ -11,6 +13,7 @@ import com.bnyer.file.vo.TiktokImgVo;
import com.bnyer.img.api.RemoteImgService;
import com.bnyer.img.api.dto.TiktokImgMiniDto;
import com.bnyer.system.api.RemoteFileService;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.entity.ContentType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockMultipartFile;
@ -22,7 +25,9 @@ import javax.annotation.Resource;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.UUID;
/**
@ -31,6 +36,7 @@ import java.util.UUID;
* @Description:
*/
@Service("file")
@Slf4j
public class FileServiceImpl implements IFileService {
@Autowired
private IQiniuService qiniuService;
@ -38,6 +44,8 @@ public class FileServiceImpl implements IFileService {
private ITikTokImage tikTokImage;
@Autowired
private RemoteImgService remoteImgService;
@Autowired
private RedisService redisService;
@Override
public ArrayList<ChekFileVo> checkImg(ArrayList<MultipartFile> multipartFiles) {
ArrayList<ChekFileVo> chekFileVos = new ArrayList<>();
@ -81,6 +89,8 @@ public class FileServiceImpl implements IFileService {
@Override
@Async("mySimpleAsync")
public void checkUploadSave(FileUploadDto fileUploadDto) throws IOException {
//redis累计平台用户当天下载次数,12.00后过期
writeDownloadTotalNum(fileUploadDto.getCreatorId());
ArrayList<MultipartFile> multipartFiles = new ArrayList<>();
for (FileDto fileDto : fileUploadDto.getFiles()) {
InputStream inputStream = new ByteArrayInputStream(fileDto.getBytes());
@ -102,4 +112,13 @@ public class FileServiceImpl implements IFileService {
}
}
@Override
public void writeDownloadTotalNum(Long creator) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String date = df.format(new Date());
log.info("日期【{}】艺术家【{}】下载数+1",date,creator);
String redisKey = RedisKeyConstant.CREATOR_DOWNLOAD_KEY + date;
redisService.hashIncr(redisKey, creator.toString(), 1);
}
}

4
bnyer-services/bnyer-img/src/main/java/com/bnyer/img/constants/RedisKeyConstant.java

@ -97,4 +97,8 @@ public class RedisKeyConstant {
* 平台用户下载键
*/
public static final String PLATFORM_USER_DOWNLOAD_KEY = "bnyer.img.user.download:";
/**
* 艺术家上传键
*/
public static final String CREATOR_DOWNLOAD_KEY="bnyer.img.createor.download";
}

6
bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/CreatorMiniController.java

@ -340,4 +340,10 @@ public class CreatorMiniController extends BaseController {
}
return AjaxResult.error();
}
@ApiOperation(value="检查某艺术家当日下载次数是否超标")
@PostMapping(value = "/checkCreatorCanDownload")
public AjaxResult checkCreatorCanDownload(@Validated @RequestBody @ApiParam("检查超标对象") CreatorDownloadDto dto){
log.debug("【微信图文小程序】检查艺术家当日上传次数是否超标参数为:{}", JSON.toJSONString(dto));
return AjaxResult.success(creatorProfitService.checkCreatorCanDownload(dto.getCreatorId()));
}
}

27
bnyer-services/bnyer-img/src/main/java/com/bnyer/img/dto/CreatorDownloadDto.java

@ -0,0 +1,27 @@
package com.bnyer.img.dto;
import com.bnyer.common.core.annotation.Desensitized;
import com.bnyer.common.core.enums.SensitiveTypeEnum;
import com.bnyer.common.core.utils.Sm4Util;
import com.bnyer.common.core.utils.StringUtils;
import com.bnyer.img.domain.CreatorAccount;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
@Getter
@Setter
@ApiModel("艺术家下载次数接收类")
public class CreatorDownloadDto implements Serializable {
@ApiModelProperty(value="艺术家id")
@NotBlank
private Long creatorId;
}

7
bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/CreatorProfitService.java

@ -194,4 +194,11 @@ public interface CreatorProfitService {
* @return -
*/
CreatorProfitEndAmtVo queryFrontEndAmtDetails(Long id);
boolean checkCreatorCanDownload(Long creatorId);
/**
* 批量删除昨日艺术家上传次数
*/
void batchDeleteCreatorDownloadNum();
}

30
bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/CreatorProfitServiceImpl.java

@ -384,4 +384,34 @@ public class CreatorProfitServiceImpl implements CreatorProfitService {
public CreatorProfitEndAmtVo queryFrontEndAmtDetails(Long id) {
return creatorProfitMapper.queryFrontEndAmtDetails(id);
}
@Override
public boolean checkCreatorCanDownload(Long creatorId) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String date = df.format(new Date());
String redisKey = RedisKeyConstant.CREATOR_DOWNLOAD_KEY + date;
if(redisService.hasHashKey(redisKey,creatorId.toString())){
//存在键,判断次数,次数达标则不可下载
Integer downloadNum = redisService.getCacheMapValue(redisKey, creatorId.toString());
return downloadNum >= 40;
}else{
//不存在键则可下载
return false;
}
}
@Override
public void batchDeleteCreatorDownloadNum() {
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.CREATOR_DOWNLOAD_KEY + date;
if(redisService.hasKey(redisKey)){
redisService.deleteObject(redisKey);
}
log.info("==============批量删除昨日艺术家上传次数完成,耗时【{}】毫秒!===============", System.currentTimeMillis() - startTime);
}
}

7
bnyer-services/bnyer-img/src/main/java/com/bnyer/img/task/UserDownloadSyncTask.java

@ -26,4 +26,11 @@ public class UserDownloadSyncTask {
XxlJobLogger.log("{} 我执行了批量删除昨日用户下载次数任务", System.currentTimeMillis());
return ReturnT.SUCCESS;
}
@XxlJob("creatorDownloadSyncTask")
public ReturnT<String> syncCreatorDownload(String param) throws Exception {
creatorProfitService.batchDeleteCreatorDownloadNum();
XxlJobLogger.log("{} 我执行了批量删除昨日用户下载次数任务", System.currentTimeMillis());
return ReturnT.SUCCESS;
}
}

Loading…
Cancel
Save