提交 dbe4ab72 authored 作者: zhangshuang's avatar zhangshuang

文件下载次数

上级 2167e619
......@@ -28,4 +28,12 @@ public class DownLoadCountController {
public List<DownLoadCount> findCount(@RequestBody DownLoadRequest downLoadRequest){
return downLoadService.findCount(downLoadRequest);
}
@PutMapping("/add")
@ApiImplicitParams({
@ApiImplicitParam(name = "DownLoadCount",value = "看下面model",paramType = "query",required = true)
})
public ServerResponse add(@RequestBody DownLoadCount downLoadCount){
return downLoadService.downloadCount(downLoadCount);
}
}
package com.zjty.efs.ftp.controller;
import com.zjty.efs.ftp.base.response.ServerResponse;
import com.zjty.efs.ftp.entity.DownLoadCount;
import com.zjty.efs.ftp.service.FileDownLoadService;
import com.zjty.efs.misc.config.AutoDocument;
......@@ -21,15 +22,15 @@ public class FileDownLoadController {
@Autowired
private FileDownLoadService fileDownLoadService;
@PutMapping("/download/{fileName}")
@GetMapping("/download/{fileName}")
@ApiOperation(value = "文件下载",notes = "通过文件名称下载文件")
@ApiImplicitParams({
@ApiImplicitParam(name = "fileName",value = "文件名称",paramType = "query",example = "1.zip",required = true),
@ApiImplicitParam(name = "response",value = "响应对象",paramType = "query",required = true),
@ApiImplicitParam(name = "request",value = "请求对象",paramType = "query",required = true),
@ApiImplicitParam(name = "downLoadCount",value = "下载次数对象",paramType = "query",required = true)
})
public void fileDownLoad(@PathVariable("fileName") String fileName, @RequestBody DownLoadCount downLoadCount, HttpServletResponse response, HttpServletRequest request){
fileDownLoadService.fileDownLoad(fileName,downLoadCount,response,request);
public void fileDownLoad(@PathVariable("fileName") String fileName, HttpServletResponse response, HttpServletRequest request){
fileDownLoadService.fileDownLoad(fileName,response,request);
}
}
......@@ -14,4 +14,6 @@ public interface DownLoadService {
* @return
*/
List<DownLoadCount> findCount(DownLoadRequest downLoadRequest);
ServerResponse downloadCount(DownLoadCount downLoadCount);
}
......@@ -13,6 +13,6 @@ public interface FileDownLoadService {
* @param response
* @param httpServletRequest
*/
void fileDownLoad(String fileName, DownLoadCount downLoadCount,HttpServletResponse response, HttpServletRequest httpServletRequest);
void fileDownLoad(String fileName,HttpServletResponse response, HttpServletRequest httpServletRequest);
}
......@@ -42,4 +42,16 @@ public class DownLoadServiceImpl implements DownLoadService {
return loadCounts;
}
@Override
public ServerResponse downloadCount(DownLoadCount downLoadCount) {
//统计下载次数
int count = 1;
if(downLoadCount.getCount() != null){
count = downLoadCount.getCount() + 1;
}
downLoadCount.setCount(count);
downLoadCountDao.save(downLoadCount);
return ServerResponse.success();
}
}
......@@ -36,7 +36,7 @@ public class FileDownLoadServiceImpl implements FileDownLoadService {
* @param fileName
* 文件名称
*/
public void fileDownLoad(String fileName, DownLoadCount downLoadCount, HttpServletResponse response, HttpServletRequest httpServletRequest) {
public void fileDownLoad(String fileName, HttpServletResponse response, HttpServletRequest httpServletRequest) {
if(fileName != null){
response.setHeader("content-type", "application/octet-stream");
response.setContentType("application/octet-stream");
......@@ -66,13 +66,7 @@ public class FileDownLoadServiceImpl implements FileDownLoadService {
i = bs.read(buffer);
}
os.flush();
//统计下载次数
int count = 1;
if(downLoadCount.getCount() != null){
count = downLoadCount.getCount() + 1;
}
downLoadCount.setCount(count);
countDao.save(downLoadCount);
} catch (FileNotFoundException e) {
log.error(file.getAbsolutePath() + "文件不存在");
e.printStackTrace();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论