提交 48979a78 authored 作者: zhangshuang's avatar zhangshuang

文件下载次数修改

上级 a671bad6
...@@ -20,7 +20,7 @@ import javax.persistence.Id; ...@@ -20,7 +20,7 @@ import javax.persistence.Id;
@ApiModel(value = "FileSave",description = "将文件信息存储在数据库中") @ApiModel(value = "FileSave",description = "将文件信息存储在数据库中")
public class FileSave { public class FileSave {
@Id @Id
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.IDENTITY)
@ApiModelProperty(name = "id",value = "文件id",notes = "文件id",example = "1") @ApiModelProperty(name = "id",value = "文件id",notes = "文件id",example = "1")
private Integer id;//文件id private Integer id;//文件id
@ApiModelProperty(name = "realName",value = "文件真正存储名称",notes = "文件真正存储名称",example = "1(1).zip") @ApiModelProperty(name = "realName",value = "文件真正存储名称",notes = "文件真正存储名称",example = "1(1).zip")
......
...@@ -18,23 +18,27 @@ public class DownLoadServiceImpl implements DownLoadService { ...@@ -18,23 +18,27 @@ public class DownLoadServiceImpl implements DownLoadService {
@Override @Override
public List<DownLoadCount> findCount(DownLoadRequest downLoadRequest) { public List<DownLoadCount> findCount(DownLoadRequest downLoadRequest) {
List<Integer> fileIdList = downLoadRequest.getFileIds();//请求的id集合
List<DownLoadCount> loadCounts = new ArrayList<>(); List<DownLoadCount> loadCounts = new ArrayList<>();
if(fileIdList != null && fileIdList.size() != 0){ if(!downLoadRequest.getUserId().isEmpty()){
loadCounts = downLoadCountDao.findCount(downLoadRequest.getUserId(),fileIdList); List<Integer> fileIdList = downLoadRequest.getFileIds();//请求的id集合
if(loadCounts.size() != fileIdList.size()){ if(fileIdList != null && fileIdList.size() != 0){
//没有文件id loadCounts = downLoadCountDao.findCount(downLoadRequest.getUserId(),fileIdList);
List<Integer> idList = new ArrayList<>();//数据库id集合 //如果传入的文件id不存在,视为没有下载过的查询,下载过的次数为0
for(DownLoadCount downLoadCount:loadCounts){ if(loadCounts.size() != fileIdList.size()){
idList.add(downLoadCount.getFileId()); //没有文件id
} List<Integer> idList = new ArrayList<>();//数据库id集合
for(Integer i:fileIdList){ for(DownLoadCount downLoadCount:loadCounts){
if(!idList.contains(i)){ idList.add(downLoadCount.getFileId());
DownLoadCount downLoadCount = new DownLoadCount(); }
downLoadCount.setUserId(downLoadRequest.getUserId()); //将不存在的文件下载次数设置为0
downLoadCount.setFileId(i); for(Integer i:fileIdList){
downLoadCount.setCount(0); if(!idList.contains(i)){
loadCounts.add(downLoadCount); DownLoadCount downLoadCount = new DownLoadCount();
downLoadCount.setUserId(downLoadRequest.getUserId());
downLoadCount.setFileId(i);
downLoadCount.setCount(0);
loadCounts.add(downLoadCount);
}
} }
} }
} }
......
...@@ -71,7 +71,8 @@ public class FileDownLoadServiceImpl implements FileDownLoadService { ...@@ -71,7 +71,8 @@ public class FileDownLoadServiceImpl implements FileDownLoadService {
log.error(file.getAbsolutePath() + "文件不存在"); log.error(file.getAbsolutePath() + "文件不存在");
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) { } catch (IOException e) {
log.error(file.getAbsolutePath() + "文件读取异常"); //log.error(file.getAbsolutePath() + "文件读取异常");
log.error(file.getAbsolutePath() + "文件用户终止下载");
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
try { try {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论