Commit 5868fe0f by 284718418@qq.com

1.BUG修改

parent 673873a2
...@@ -90,7 +90,7 @@ public class DiskCatalogueController { ...@@ -90,7 +90,7 @@ public class DiskCatalogueController {
} }
diskCatalogue.setCreateUserId(userBean.getEmpNum()); diskCatalogue.setCreateUserId(userBean.getEmpNum());
diskCatalogue.setOrgId(userBean.getOrgCode()); diskCatalogue.setOrgId(userBean.getOrgCode());
diskCatalogue.setUserName(userBean.getUserInfo().getName()); diskCatalogue.setUserName(userBean.getQyzxEmpLogin().getUsername());
diskCatalogue.setUpdateUserId(userBean.getEmpNum()); diskCatalogue.setUpdateUserId(userBean.getEmpNum());
Boolean count = diskCatalogue.insertOrUpdate(); Boolean count = diskCatalogue.insertOrUpdate();
// 云盘修改 // 云盘修改
......
...@@ -9,14 +9,14 @@ import cn.timer.api.config.annotation.UserBean; ...@@ -9,14 +9,14 @@ import cn.timer.api.config.annotation.UserBean;
import cn.timer.api.config.enuminterface.JxglEnumInterface; import cn.timer.api.config.enuminterface.JxglEnumInterface;
import cn.timer.api.config.exception.CustomException; import cn.timer.api.config.exception.CustomException;
import cn.timer.api.config.sftp.SftpConfiguration; import cn.timer.api.config.sftp.SftpConfiguration;
import cn.timer.api.dto.disk.DiskCatalogueDto; import cn.timer.api.controller.disk.sevice.DiskFilesService;
import cn.timer.api.dto.disk.DiskFilesDto; import cn.timer.api.dto.disk.*;
import cn.timer.api.dto.disk.DiskFilesParam;
import cn.timer.api.dto.disk.FileInfoDto;
import cn.timer.api.service.FtpService; import cn.timer.api.service.FtpService;
import cn.timer.api.utils.FileUtils; import cn.timer.api.utils.FileUtils;
import cn.timer.api.utils.Result; import cn.timer.api.utils.Result;
import cn.timer.api.utils.ResultUtil; import cn.timer.api.utils.ResultUtil;
import cn.timer.api.utils.UserIp;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -24,15 +24,20 @@ import io.swagger.annotations.ApiParam; ...@@ -24,15 +24,20 @@ import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import java.io.*; import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
...@@ -50,6 +55,8 @@ public class DiskFilesController { ...@@ -50,6 +55,8 @@ public class DiskFilesController {
@Autowired @Autowired
private FtpService ftpService; private FtpService ftpService;
@Autowired
private DiskFilesService diskFilesService;
@Value("${sftp.client.root}") @Value("${sftp.client.root}")
private String root; private String root;
...@@ -68,7 +75,7 @@ public class DiskFilesController { ...@@ -68,7 +75,7 @@ public class DiskFilesController {
@PostMapping("/upload") @PostMapping("/upload")
@ApiOperation(value = "上传普通文件", httpMethod = "POST", notes = "接口发布说明") @ApiOperation(value = "上传普通文件", httpMethod = "POST", notes = "接口发布说明")
public Result<Object> upload(@CurrentUser UserBean userBean, @RequestParam(required = true) MultipartFile[] file, public Result<Object> upload(@CurrentUser UserBean userBean, @RequestParam(required = true) MultipartFile[] file,
@ApiParam("文件文件夹或共享空间ID") @RequestParam(required = true) Integer catalogueId) { @ApiParam("文件文件夹或共享空间ID") @RequestParam(required = true) Integer catalogueId,HttpServletRequest request) {
if(catalogueId<=0){ if(catalogueId<=0){
return ResultUtil.error("上传失败,请选择文件夹"); return ResultUtil.error("上传失败,请选择文件夹");
} }
...@@ -91,9 +98,10 @@ public class DiskFilesController { ...@@ -91,9 +98,10 @@ public class DiskFilesController {
diskFiles.setUrlPath(dto.getUrlPath()); diskFiles.setUrlPath(dto.getUrlPath());
diskFiles.setTitle(dto.getResourceFileName()); diskFiles.setTitle(dto.getResourceFileName());
diskFiles.setFileSize(dto.getFileSize()); diskFiles.setFileSize(dto.getFileSize());
// 显示大小:10KB,5M,2G 后续优化 // 显示大小:10KB,5M,2G
diskFiles.setShowSize(FileUtils.getSize(dto.getFileSize())); diskFiles.setShowSize(FileUtils.getSize(dto.getFileSize()));
diskFiles.setUserName(userBean.getUserInfo().getName()); diskFiles.setUserName(userBean.getQyzxEmpLogin().getUsername());
diskFiles.setUploadIp(UserIp.getIpAddr(request));
diskFiles.insert(); diskFiles.insert();
//新增中间关系 //新增中间关系
...@@ -108,7 +116,7 @@ public class DiskFilesController { ...@@ -108,7 +116,7 @@ public class DiskFilesController {
diskFilesLog.setTitle(dto.getResourceFileName()); diskFilesLog.setTitle(dto.getResourceFileName());
diskFilesLog.setType(JxglEnumInterface.DiskFilesLogType.CREATE_LOG.getType()); diskFilesLog.setType(JxglEnumInterface.DiskFilesLogType.CREATE_LOG.getType());
diskFilesLog.setUserId(userBean.getEmpNum()); diskFilesLog.setUserId(userBean.getEmpNum());
diskFilesLog.setUserName(userBean.getUserInfo().getName()); diskFilesLog.setUserName(userBean.getQyzxEmpLogin().getUsername());
diskFilesLog.insert(); diskFilesLog.insert();
} }
...@@ -118,7 +126,7 @@ public class DiskFilesController { ...@@ -118,7 +126,7 @@ public class DiskFilesController {
} }
return ResultUtil.error("上传文件失败"); return ResultUtil.error("上传文件失败");
} }
@ResponseBody /* @ResponseBody
@GetMapping("/download") @GetMapping("/download")
@ApiOperation(value = "下载普通文件", httpMethod = "POST", notes = "接口发布说明") @ApiOperation(value = "下载普通文件", httpMethod = "POST", notes = "接口发布说明")
public Result<Object> download(@CurrentUser UserBean userBean, public Result<Object> download(@CurrentUser UserBean userBean,
...@@ -142,7 +150,7 @@ public class DiskFilesController { ...@@ -142,7 +150,7 @@ public class DiskFilesController {
diskFilesLog.setTitle(diskFiles.getTitle()); diskFilesLog.setTitle(diskFiles.getTitle());
diskFilesLog.setType(JxglEnumInterface.DiskFilesLogType.DOWN_LOAD_LOG.getType()); diskFilesLog.setType(JxglEnumInterface.DiskFilesLogType.DOWN_LOAD_LOG.getType());
diskFilesLog.setUserId(userBean.getEmpNum()); diskFilesLog.setUserId(userBean.getEmpNum());
diskFilesLog.setUserName(userBean.getUserInfo().getName()); diskFilesLog.setUserName(userBean.getQyzxEmpLogin().getUsername());
diskFilesLog.insert(); diskFilesLog.insert();
return ResultUtil.success(); return ResultUtil.success();
} }
...@@ -151,7 +159,7 @@ public class DiskFilesController { ...@@ -151,7 +159,7 @@ public class DiskFilesController {
throw new CustomException("下载文件异常,请联系管理员"); throw new CustomException("下载文件异常,请联系管理员");
} }
return ResultUtil.error("下载文件失败"); return ResultUtil.error("下载文件失败");
} }*/
/** /**
* 云盘-文件重命名 * 云盘-文件重命名
* *
...@@ -166,7 +174,7 @@ public class DiskFilesController { ...@@ -166,7 +174,7 @@ public class DiskFilesController {
DiskFiles entity = new DiskFiles(); DiskFiles entity = new DiskFiles();
DiskFiles diskFiles = DiskFiles.builder().id(diskFilesParam.getId()).build().selectById(); DiskFiles diskFiles = DiskFiles.builder().id(diskFilesParam.getId()).build().selectById();
if (StringUtils.isEmpty(diskFiles) || !diskFiles.getCreateUserId().equals(userBean.getEmpNum())) { if (StringUtils.isEmpty(diskFiles) || !diskFiles.getCreateUserId().equals(userBean.getEmpNum())) {
return ResultUtil.error("操作失败!"); return ResultUtil.error("无权限,操作失败!");
} }
entity.setId(diskFiles.getId()); entity.setId(diskFiles.getId());
entity.setTitle(diskFilesParam.getName()); entity.setTitle(diskFilesParam.getName());
...@@ -185,7 +193,7 @@ public class DiskFilesController { ...@@ -185,7 +193,7 @@ public class DiskFilesController {
diskFilesLog.setFileSize(diskFiles.getFileSize() + "B"); diskFilesLog.setFileSize(diskFiles.getFileSize() + "B");
diskFilesLog.setTitle(diskFiles.getTitle()); diskFilesLog.setTitle(diskFiles.getTitle());
diskFilesLog.setUserId(userBean.getEmpNum()); diskFilesLog.setUserId(userBean.getEmpNum());
diskFilesLog.setUserName(userBean.getUserInfo().getName()); diskFilesLog.setUserName(userBean.getQyzxEmpLogin().getUsername());
diskFilesLog.insert(); diskFilesLog.insert();
return ResultUtil.data(StringUtils.isEmpty(diskFilesParam.getDeleteFlag())?"文件重命名成功":"删除文件成功"); return ResultUtil.data(StringUtils.isEmpty(diskFilesParam.getDeleteFlag())?"文件重命名成功":"删除文件成功");
} else { } else {
...@@ -197,4 +205,77 @@ public class DiskFilesController { ...@@ -197,4 +205,77 @@ public class DiskFilesController {
} }
} }
/**
* 云盘-我的文件空间大小
*
* @param userBean
* @return
*/
@GetMapping(value = "/mycatalogue")
@ApiOperation(value = "我的文件空间大小", httpMethod = "GET", notes = "我的文件空间大小")
public Result<Object> myCatalogue(@CurrentUser UserBean userBean) {
try {
DiskFileCatalogueDto diskFileCatalogueDto = diskFilesService.getFileCount(userBean.getEmpNum());
return ResultUtil.data(diskFileCatalogueDto);
}catch (Exception e){
e.printStackTrace();
throw new CustomException("获取我的文件空间大小异常");
}
}
@GetMapping(value = "/exportContract")
public void exportContract(@CurrentUser UserBean userBean, @ApiParam("文件ID") @RequestParam(required = true) Integer fileId, HttpServletResponse resp) {
if (fileId == null || fileId <= 0) {
throw new CustomException("下载失败,请选择文件下载");
}
DiskFiles diskFiles = DiskFiles.builder().id(fileId).build().selectById();
if(StringUtils.isEmpty(diskFiles)){
throw new CustomException("下载失败,文件不存在");
}
FileInputStream fis = null;
BufferedInputStream bis = null;
OutputStream os;
File filePath = null;
try {
String name = diskFiles.getTitle()+diskFiles.getFileType();
resp.setContentType("application/octet-stream");
resp.setHeader("content-disposition", "attachment; filename=" + new String(name.getBytes("UTF8"), "ISO-8859-1"));
resp.setCharacterEncoding("UTF-8");
filePath = new File(diskFiles.getDiskPath());
byte[] buffer = new byte[1024];
fis = new FileInputStream(filePath);
bis = new BufferedInputStream(fis);
os = resp.getOutputStream();
int i = bis.read(buffer);
while (i != -1) {
os.write(buffer, 0, i);
i = bis.read(buffer);
}
os.flush();
DiskFilesLog diskFilesLog = DiskFilesLog.builder().build();
//新增 文件浏览记录
diskFilesLog.setFilePath(diskFiles.getUrlPath());
diskFilesLog.setFilesId(diskFiles.getId());
diskFilesLog.setFileSize(diskFiles.getFileSize() + "B");
diskFilesLog.setTitle(diskFiles.getTitle());
diskFilesLog.setType(JxglEnumInterface.DiskFilesLogType.DOWN_LOAD_LOG.getType());
diskFilesLog.setUserId(userBean.getEmpNum());
diskFilesLog.setUserName(userBean.getQyzxEmpLogin().getUsername());
diskFilesLog.insert();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
} }
...@@ -3,6 +3,7 @@ package cn.timer.api.controller.disk.sevice; ...@@ -3,6 +3,7 @@ package cn.timer.api.controller.disk.sevice;
import cn.timer.api.bean.disk.DiskCatalogue; import cn.timer.api.bean.disk.DiskCatalogue;
import cn.timer.api.bean.disk.DiskFiles; import cn.timer.api.bean.disk.DiskFiles;
import cn.timer.api.dto.disk.DiskCatalogueParam; import cn.timer.api.dto.disk.DiskCatalogueParam;
import cn.timer.api.dto.disk.DiskFileCatalogueDto;
import java.util.List; import java.util.List;
...@@ -20,4 +21,11 @@ public interface DiskFilesService { ...@@ -20,4 +21,11 @@ public interface DiskFilesService {
* @return * @return
*/ */
List<DiskFiles> getDiskFiles(DiskCatalogueParam diskCatalogueParam); List<DiskFiles> getDiskFiles(DiskCatalogueParam diskCatalogueParam);
/**
* 获取用户文件空间大小
* @param userId
* @return
*/
DiskFileCatalogueDto getFileCount(Integer userId);
} }
package cn.timer.api.controller.disk.sevice; package cn.timer.api.controller.disk.sevice;
import cn.timer.api.bean.disk.DiskCatalogue;
import cn.timer.api.bean.disk.DiskCatalogueFiles;
import cn.timer.api.bean.disk.DiskFiles; import cn.timer.api.bean.disk.DiskFiles;
import cn.timer.api.dao.disk.DiskCatalogueMapper;
import cn.timer.api.dao.disk.DiskFilesMapper; import cn.timer.api.dao.disk.DiskFilesMapper;
import cn.timer.api.dto.disk.DiskCatalogueParam; import cn.timer.api.dto.disk.DiskCatalogueParam;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import cn.timer.api.dto.disk.DiskFileCatalogueDto;
import cn.timer.api.utils.FileUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/** /**
* @author wuqingjun * @author wuqingjun
...@@ -33,4 +27,17 @@ public class DiskFilesServiceImpl implements DiskFilesService { ...@@ -33,4 +27,17 @@ public class DiskFilesServiceImpl implements DiskFilesService {
public List<DiskFiles> getDiskFiles(DiskCatalogueParam diskCatalogueParam) { public List<DiskFiles> getDiskFiles(DiskCatalogueParam diskCatalogueParam) {
return diskFilesMapper.selectListByParam(diskCatalogueParam); return diskFilesMapper.selectListByParam(diskCatalogueParam);
} }
@Override
public DiskFileCatalogueDto getFileCount(Integer userId) {
DiskFileCatalogueDto dto = diskFilesMapper.selectFileCount(userId);
if(StringUtils.isEmpty(dto)){
dto = new DiskFileCatalogueDto();
}
dto.setShowCountSize(FileUtils.getSize(dto.getCountSize()));
dto.setSize(1*1024*1024*1024L);
//dto.setShowSize(FileUtils.getSize(dto.getSize()));
dto.setShowSize("1G");
return dto;
}
} }
...@@ -3,6 +3,7 @@ package cn.timer.api.dao.disk; ...@@ -3,6 +3,7 @@ package cn.timer.api.dao.disk;
import cn.timer.api.bean.disk.DiskFiles; import cn.timer.api.bean.disk.DiskFiles;
import cn.timer.api.dto.disk.DiskCatalogueParam; import cn.timer.api.dto.disk.DiskCatalogueParam;
import cn.timer.api.dto.disk.DiskFileCatalogueDto;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
...@@ -26,5 +27,12 @@ public interface DiskFilesMapper extends BaseMapper<DiskFiles> { ...@@ -26,5 +27,12 @@ public interface DiskFilesMapper extends BaseMapper<DiskFiles> {
* @return * @return
*/ */
List<DiskFiles> selectListByParam(@Param("param")DiskCatalogueParam diskCatalogueParam); List<DiskFiles> selectListByParam(@Param("param")DiskCatalogueParam diskCatalogueParam);
/**
* 获取用户文件空间大小
* @param userId
* @return
*/
DiskFileCatalogueDto selectFileCount(@Param("userId")Integer userId);
} }
package cn.timer.api.dto.disk;
import cn.timer.api.config.exception.ValidationMsg;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* @author wuqingjun
* @email 284718418@qq.com
* @date 2021-12-27 10:05:49
*/
@Data
public class DiskFileCatalogueDto implements Serializable{
private static final long serialVersionUID = -1230022223946170921L;
/**
* 所有文件总大小
*/
@ApiModelProperty(value = "文件总大小")
private Long countSize;
/**
* 所有文件总大小 显示值MB,KB
*/
@ApiModelProperty(value = "文件总大小 显示值 带单位MB,KB")
private String showCountSize;
/**
* 给定空间大小
*/
@ApiModelProperty(value = "给定空间大小 Byte")
private Long size;
/**
* 给定空间大小 显示值MB,KB
*/
@ApiModelProperty(value = "给定空间大小 显示值 带单位MB,KB")
private String showSize;
}
...@@ -11,7 +11,7 @@ public class FileUtils { ...@@ -11,7 +11,7 @@ public class FileUtils {
* 获取文件的大小(返回到达的最高单位) * 获取文件的大小(返回到达的最高单位)
* 比如:1024Byte就不再用Byte * 比如:1024Byte就不再用Byte
* 直接返回1KB * 直接返回1KB
* 返回值精确到小数点后3 * 返回值精确到小数点后2
* @param size 文件大小 * @param size 文件大小
* @return 文件的大小 若文件不存在或者不是文件就返回 “” * @return 文件的大小 若文件不存在或者不是文件就返回 “”
*/ */
...@@ -54,7 +54,7 @@ public class FileUtils { ...@@ -54,7 +54,7 @@ public class FileUtils {
default: default:
unit = "ER"; unit = "ER";
} }
String format = String.format("%.3f", s); String format = String.format("%.2f", s);
return format + unit; return format + unit;
} }
return ""; return "";
......
...@@ -32,4 +32,8 @@ ...@@ -32,4 +32,8 @@
ORDER BY f.create_time DESC ORDER BY f.create_time DESC
</select> </select>
<select id="selectFileCount" resultType="cn.timer.api.dto.disk.DiskFileCatalogueDto">
SELECT COALESCE(sum(file_size),0) as countSize FROM `disk_files` where create_user_id = #{userId} AND delete_flag=0
</select>
</mapper> </mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment