Merge remote-tracking branch 'ztcloud/test' into dev
This commit is contained in:
@@ -53,6 +53,10 @@ public class FileController {
|
|||||||
if (fileDO == null) {
|
if (fileDO == null) {
|
||||||
return CommonResult.error(HttpStatus.NOT_FOUND.value(), "文件不存在");
|
return CommonResult.error(HttpStatus.NOT_FOUND.value(), "文件不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 统计下载次数
|
||||||
|
fileService.incDownloadCount(fileId);
|
||||||
|
|
||||||
// FileDO 转换为 FileRespVO
|
// FileDO 转换为 FileRespVO
|
||||||
FileRespVO fileRespVO = BeanUtils.toBean(fileDO, FileRespVO.class);
|
FileRespVO fileRespVO = BeanUtils.toBean(fileDO, FileRespVO.class);
|
||||||
return success(fileRespVO);
|
return success(fileRespVO);
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.apache.ibatis.annotations.Update;
|
import org.apache.ibatis.annotations.Update;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件操作 Mapper
|
* 文件操作 Mapper
|
||||||
*
|
*
|
||||||
@@ -34,7 +36,16 @@ public interface FileMapper extends BaseMapperX<FileDO> {
|
|||||||
return selectFirstOne(FileDO::getHash, hash);
|
return selectFirstOne(FileDO::getHash, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据configId和path查找文件信息
|
||||||
|
* @param configId
|
||||||
|
* @param path
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
default List<FileDO> selectByConfigIdAndPath(Long configId, String path){
|
||||||
|
return selectList(FileDO::getConfigId, configId, FileDO::getPath, path);
|
||||||
|
};
|
||||||
|
|
||||||
@Update("UPDATE INFRA_FILE SET DOWNLOAD_COUNT = DOWNLOAD_COUNT + 1 WHERE CONFIG_ID = #{configId} AND PATH = #{path}")
|
@Update("UPDATE INFRA_FILE SET DOWNLOAD_COUNT = DOWNLOAD_COUNT + 1 WHERE ID = #{fileId}")
|
||||||
int incDownloadCount(@Param("configId") Long configId, @Param("path") String path);
|
int incDownloadCount(@Param("fileId") Long fileId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,4 +119,10 @@ public interface FileService {
|
|||||||
* @param path
|
* @param path
|
||||||
*/
|
*/
|
||||||
void incDownloadCount(Long configId, String path);
|
void incDownloadCount(Long configId, String path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新文件下载次数
|
||||||
|
* @param fileId
|
||||||
|
*/
|
||||||
|
void incDownloadCount(Long fileId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import cn.hutool.core.io.FileUtil;
|
|||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.crypto.digest.DigestUtil;
|
import cn.hutool.crypto.digest.DigestUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.zt.plat.framework.common.pojo.PageResult;
|
import com.zt.plat.framework.common.pojo.PageResult;
|
||||||
import com.zt.plat.framework.common.util.object.BeanUtils;
|
import com.zt.plat.framework.common.util.object.BeanUtils;
|
||||||
@@ -32,6 +33,8 @@ import javax.crypto.spec.IvParameterSpec;
|
|||||||
import javax.crypto.spec.SecretKeySpec;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static cn.hutool.core.date.DatePattern.PURE_DATE_PATTERN;
|
import static cn.hutool.core.date.DatePattern.PURE_DATE_PATTERN;
|
||||||
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
@@ -336,7 +339,14 @@ public class FileServiceImpl implements FileService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void incDownloadCount(Long configId, String path) {
|
public void incDownloadCount(Long configId, String path) {
|
||||||
fileMapper.incDownloadCount(configId, path);
|
List<FileDO> fileList = fileMapper.selectByConfigIdAndPath(configId, path);
|
||||||
|
if(fileList != null && !fileList.isEmpty())
|
||||||
|
incDownloadCount(fileList.get(0).getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void incDownloadCount(Long fileId) {
|
||||||
|
fileMapper.incDownloadCount(fileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user