Commit 20bba76f by 284718418@qq.com

1.云盘-我的文件业务代码

parent 3f6d958f
......@@ -87,6 +87,11 @@ public class DiskCatalogue extends Model<DiskCatalogue> {
@ApiModelProperty(value = "创建者")
private Integer createUserId;
/**
* 用户姓名
*/
@ApiModelProperty(value = "用户姓名")
private String userName;
/**
* 更新者
*/
@ApiModelProperty(value = "更新者")
......
......@@ -90,6 +90,11 @@ public class DiskFiles extends Model<DiskFiles> {
@ApiModelProperty(value = "")
private Integer createUserId;
/**
* 用户姓名
*/
@ApiModelProperty(value = "用户姓名")
private String userName;
/**
* 更新者
*/
@ApiModelProperty(value = "")
......
......@@ -268,11 +268,12 @@ public interface JxglEnumInterface {
}
/**
* 云盘-文件浏览记录类型: 0查看,1下载,2创建
* 云盘-文件浏览记录类型: 0查看,1下载,2创建,3收藏,4编辑
*/
@Getter
enum DiskFilesLogType implements JxglEnumInterface {
LOOK_LOG(0, "查看"), DOWN_LOAD_LOG(1, "下载"), CREATE_LOG(1, "下载");
LOOK_LOG(0, "查看"), DOWN_LOAD_LOG(1, "下载"), CREATE_LOG(2, "创建")
, COLLECT_LOG(3, "收藏"), UPDATE_LOG(4, "修改"), DELETE_LOG(5, "逻辑删除");
private Integer type;
......
package cn.timer.api.controller.disk;
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.config.annotation.CurrentUser;
import cn.timer.api.config.annotation.UserBean;
import cn.timer.api.config.exception.CustomException;
import cn.timer.api.controller.disk.sevice.DiskCatalogueService;
import cn.timer.api.controller.disk.sevice.DiskFilesService;
import cn.timer.api.dto.disk.DiskCatalogueDto;
import cn.timer.api.dto.disk.DiskCatalogueParam;
import cn.timer.api.utils.Result;
......@@ -40,6 +43,9 @@ public class DiskCatalogueController {
@Autowired
private DiskCatalogueService diskCatalogueService;
@Autowired
private DiskFilesService diskFilesService;
/**
* 云盘-新建文件夹
*
......@@ -65,6 +71,7 @@ public class DiskCatalogueController {
}
diskCatalogue.setCreateUserId(empNum);
diskCatalogue.setOrgId(orgCode);
diskCatalogue.setUpdateUserId(empNum);
Boolean count = diskCatalogue.insertOrUpdate();
if (count) {
return ResultUtil.data(diskCatalogue, "新建文件夹成功!");
......@@ -109,14 +116,16 @@ public class DiskCatalogueController {
try {
Integer empNum = userBean.getEmpNum();
Integer orgCode = userBean.getOrgCode();
diskCatalogueParam.setUserId(empNum);
// 获取文件夹
List<DiskCatalogue> diskFileDataList = DiskCatalogue.builder().build().selectList(new QueryWrapper<DiskCatalogue>()
List<DiskCatalogue> diskCatalogueList = DiskCatalogue.builder().build().selectList(new QueryWrapper<DiskCatalogue>()
.lambda().eq(DiskCatalogue::getOrgId, orgCode)
.eq(DiskCatalogue::getCreateUserId, empNum)
.eq(DiskCatalogue::getParentId, diskCatalogueParam.getParentId())
.eq(DiskCatalogue::getType, diskCatalogueParam.getType())
.eq(DiskCatalogue::getDeleteFlag, 0)
);
List<DiskFiles> filesList = diskFilesService.getDiskFiles(diskCatalogueParam);
// 获取面包屑
List<DiskCatalogue> breadcrumbDataList = null;
......@@ -139,7 +148,8 @@ public class DiskCatalogueController {
);
}
Map<String,Object> map = new HashMap<>(2);
map.put("diskFileData",diskFileDataList);
map.put("diskCatalogueData",diskCatalogueList);
map.put("diskFileData",filesList);
map.put("breadcrumbData",breadcrumbDataList);
return ResultUtil.data(map);
}catch (Exception e){
......
package cn.timer.api.controller.disk;
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.DiskFilesLog;
import cn.timer.api.config.annotation.CurrentUser;
import cn.timer.api.config.annotation.UserBean;
import cn.timer.api.config.enuminterface.JxglEnumInterface;
import cn.timer.api.config.exception.CustomException;
import cn.timer.api.config.sftp.SftpConfiguration;
import cn.timer.api.dto.disk.DiskCatalogueDto;
import cn.timer.api.dto.disk.DiskFilesDto;
import cn.timer.api.dto.disk.DiskFilesParam;
import cn.timer.api.dto.disk.FileInfoDto;
import cn.timer.api.service.FtpService;
import cn.timer.api.utils.Result;
import cn.timer.api.utils.ResultUtil;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import javax.transaction.Transactional;
import java.io.*;
import java.util.List;
......@@ -55,9 +63,9 @@ public class DiskFilesController {
private String serverUrl;
@ApiOperation(value = "上传普通文件", httpMethod = "POST", notes = "接口发布说明")
@ResponseBody
@PostMapping("/upload")
@ApiOperation(value = "上传普通文件", httpMethod = "POST", notes = "接口发布说明")
public Result<Object> upload(@CurrentUser UserBean userBean, @RequestParam(required = true) MultipartFile[] file,
@ApiParam("文件文件夹或共享空间ID") @RequestParam(required = true) Integer catalogueId) {
if (file == null || file.length == 0) {
......@@ -107,5 +115,86 @@ public class DiskFilesController {
}
return ResultUtil.error("上传文件失败");
}
@ResponseBody
@GetMapping("/download")
@ApiOperation(value = "下载普通文件", httpMethod = "POST", notes = "接口发布说明")
public Result<Object> download(@CurrentUser UserBean userBean,
@ApiParam("文件ID") @RequestParam(required = true) Integer fileId,
@ApiParam("本地保存目录") @RequestParam(required = true) String localPath) {
if (fileId == null || fileId <= 0) {
return ResultUtil.error("下载失败,请选择文件下载");
}
Integer empNum = userBean.getEmpNum();
Integer orgCode = userBean.getOrgCode();
DiskFiles diskFiles = DiskFiles.builder().id(fileId).build().selectById();
if(StringUtils.isEmpty(diskFiles)){
return ResultUtil.error("下载失败,文件不存在");
}
try {
boolean count = ftpService.downloadFile(diskFiles.getDiskPath(),localPath,diskFiles.getTitle()+diskFiles.getFileType());
if(count){
DiskFilesLog diskFilesLog = new DiskFilesLog();
//新增 文件浏览记录
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(empNum);
diskFilesLog.setUserName(userBean.getUserInfo().getName());
diskFilesLog.insert();
return ResultUtil.success();
}
} catch (Exception e) {
e.printStackTrace();
throw new CustomException("下载文件异常,请联系管理员");
}
return ResultUtil.error("下载文件失败");
}
/**
* 云盘-文件重命名
*
* @param userBean
* @return
*/
@ResponseBody
@PostMapping(value = "/file_name")
@ApiOperation(value = "文件重命名", httpMethod = "POST", notes = "文件重命名")
public Result<Object> updateFileName(@CurrentUser UserBean userBean, @Validated @RequestBody DiskFilesParam diskFilesParam) {
try{
Integer empNum = userBean.getEmpNum();
DiskFiles entity = new DiskFiles();
DiskFiles diskFiles = DiskFiles.builder().id(diskFilesParam.getId()).build().selectById();
if (StringUtils.isEmpty(diskFiles) || !diskFiles.getCreateUserId().equals(empNum)) {
return ResultUtil.error("操作失败!");
}
entity.setId(diskFiles.getId());
entity.setTitle(diskFilesParam.getName());
entity.setUpdateUserId(empNum);
DiskFilesLog diskFilesLog = new DiskFilesLog();
diskFilesLog.setType(JxglEnumInterface.DiskFilesLogType.UPDATE_LOG.getType());
if(!StringUtils.isEmpty(diskFilesParam.getDeleteFlag())){
entity.setDeleteFlag(1);
diskFilesLog.setType(JxglEnumInterface.DiskFilesLogType.DELETE_LOG.getType());
}
Boolean count = entity.updateById();
if (count) {
//新增 文件浏览记录
diskFilesLog.setFilePath(diskFiles.getUrlPath());
diskFilesLog.setFilesId(diskFiles.getId());
diskFilesLog.setFileSize(diskFiles.getFileSize() + "B");
diskFilesLog.setTitle(diskFiles.getTitle());
diskFilesLog.setUserId(empNum);
diskFilesLog.setUserName(userBean.getUserInfo().getName());
diskFilesLog.insert();
return ResultUtil.data(StringUtils.isEmpty(diskFilesParam.getDeleteFlag())?"文件重命名成功":"删除文件成功");
} else {
return ResultUtil.error(StringUtils.isEmpty(diskFilesParam.getDeleteFlag())?"文件重命名失败":"删除文件失败");
}
}catch (Exception e){
e.printStackTrace();
throw new CustomException(StringUtils.isEmpty(diskFilesParam.getDeleteFlag())?"文件重命名异常":"删除文件异常");
}
}
}
package cn.timer.api.controller.disk.sevice;
import cn.timer.api.bean.disk.DiskCatalogue;
import cn.timer.api.bean.disk.DiskFiles;
import cn.timer.api.dto.disk.DiskCatalogueParam;
import java.util.List;
/**
* @author wuqingjun
* @email 284718418@qq.com
* @date 2022/1/4
*/
public interface DiskFilesService {
/**
* 我的文件夹
* @param diskCatalogueParam
* @return
*/
List<DiskFiles> getDiskFiles(DiskCatalogueParam diskCatalogueParam);
}
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.dao.disk.DiskCatalogueMapper;
import cn.timer.api.dao.disk.DiskFilesMapper;
import cn.timer.api.dto.disk.DiskCatalogueParam;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author wuqingjun
* @email 284718418@qq.com
* @date 2021/12/29
*/
@Service
public class DiskFilesServiceImpl implements DiskFilesService {
@Resource
private DiskFilesMapper diskFilesMapper;
@Override
public List<DiskFiles> getDiskFiles(DiskCatalogueParam diskCatalogueParam) {
return diskFilesMapper.selectListByParam(diskCatalogueParam);
}
}
......@@ -2,9 +2,13 @@ package cn.timer.api.dao.disk;
import cn.timer.api.bean.disk.DiskFiles;
import cn.timer.api.dto.disk.DiskCatalogueParam;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* 云盘-资源上传文件表
*
......@@ -14,5 +18,13 @@ import org.springframework.stereotype.Repository;
*/
@Repository
public interface DiskFilesMapper extends BaseMapper<DiskFiles> {
/**
* 我的文件夹
* @param diskCatalogueParam
* @return
*/
List<DiskFiles> selectListByParam(@Param("param")DiskCatalogueParam diskCatalogueParam);
}
......@@ -42,4 +42,10 @@ public class DiskCatalogueParam implements Serializable {
@NotNull(message = ValidationMsg.NOTNULL)
@ApiModelProperty(value = "0云盘,1文件夹")
private Integer type;
/**
* 用户ID
*/
@ApiModelProperty(value = "用户ID", example = "0")
private Integer userId;
}
package cn.timer.api.dto.disk;
import cn.timer.api.config.exception.ValidationMsg;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* @author wuqingjun
* @email 284718418@qq.com
* @date 2021/12/31
*/
@Data
public class DiskFilesParam implements Serializable {
private static final long serialVersionUID = -1230023773946170911L;
/**
* 资源上传文件ID
*/
@NotNull(message = ValidationMsg.NOTNULL)
@ApiModelProperty(value = "资源上传文件ID", example = "0")
private Integer id;
@NotBlank(message = ValidationMsg.NOTBLANK)
@ApiModelProperty(value = "文件标题")
private String name;
@ApiModelProperty(value = "逻辑删除标记0.未删除 1.删除")
private Integer deleteFlag;
/**
* 用户ID
*/
@ApiModelProperty(value = "用户ID", example = "0")
private Integer userId;
}
......@@ -4,6 +4,8 @@ import cn.timer.api.dto.disk.FileInfoDto;
import com.jcraft.jsch.ChannelSftp;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.OutputStream;
import java.util.List;
/**
......@@ -21,6 +23,15 @@ public interface FtpService {
* @return
*/
List<FileInfoDto> uploadFile(String targetPath, MultipartFile[] files, boolean reservedName);
/**
* 下载单个文件
*
* @param remotePath:远程目录
* @param localPath:本地保存目录
* @param localFileName:保存文件名
* @return
*/
boolean downloadFile(String remotePath, String localPath, String localFileName);
/**
* 删除服务器文件
......
......@@ -12,6 +12,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
......@@ -58,6 +59,7 @@ public class FtpServiceImpl implements FtpService {
}
return false;
}
@Override
public List<FileInfoDto> uploadFile(String targetPath, MultipartFile[] files, boolean reservedName) {
ChannelSftp sftp = config.getSftpSocket();
......@@ -77,12 +79,12 @@ public class FtpServiceImpl implements FtpService {
String name = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf("."));
String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
if (reservedName) {
fileName = Md5.md5(name+UUID.randomUUID().toString()) + suffix;
fileName = Md5.md5(name + UUID.randomUUID().toString()) + suffix;
} else {
fileName = UUID.randomUUID().toString()+suffix;
fileName = UUID.randomUUID().toString() + suffix;
}
sftp.put(file.getInputStream(), fileName);
dto.setUrlPath(config.getServerUrl() + "/" +fileName);
dto.setUrlPath(config.getServerUrl() + "/" + fileName);
dto.setResourceFileName(name);
dto.setFileName(fileName);
......@@ -104,8 +106,50 @@ public class FtpServiceImpl implements FtpService {
config.returnSftpSocket(sftp);
}
}
/**
* 下载单个文件
*
* @param remotePath:远程下载目录
* @param localPath:本地保存目录(以路径符号结束)
* @param localFileName:保存文件名
* @return
*/
@Override
public boolean downloadFile(String remotePath, String localPath, String localFileName) {
FileOutputStream fieloutput = null;
ChannelSftp sftp = config.getSftpSocket();
try {
// sftp.cd(remotePath);
File file = new File(localPath + localFileName);
// mkdirs(localPath + localFileName);
fieloutput = new FileOutputStream(file);
sftp.get(remotePath, fieloutput);
if (log.isInfoEnabled()) {
log.info("===DownloadFile:" + remotePath + " success from sftp.");
}
return true;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (SftpException e) {
e.printStackTrace();
} finally {
if (null != fieloutput) {
try {
fieloutput.close();
} catch (IOException e) {
e.printStackTrace();
}
}
config.returnSftpSocket(sftp);
}
return false;
}
@Override
public boolean deleteFile(List<String> targetPath){
public boolean deleteFile(List<String> targetPath) {
ChannelSftp sftp = null;
try {
sftp = config.getSftpSocket();
......
......@@ -15,6 +15,7 @@
<result property="usedSize" column="used_size"/>
<result property="sort" column="sort"/>
<result property="createUserId" column="create_user_id"/>
<result property="userName" column="user_name"/>
<result property="updateUserId" column="update_user_id"/>
<result property="remark" column="remark"/>
<result property="deleteFlag" column="delete_flag"/>
......
......@@ -3,7 +3,7 @@
<mapper namespace="cn.timer.api.dao.disk.DiskFilesMapper">
<!-- 可根据自己的需求,是否要使用 -->
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="cn.timer.api.bean.disk.DiskFiles" id="BaseResultMap">
<id property="id" column="id"/>
<result property="title" column="title"/>
......@@ -15,9 +15,18 @@
<result property="uploadIp" column="upload_ip"/>
<result property="deleteFlag" column="delete_flag"/>
<result property="createUserId" column="create_user_id"/>
<result property="userName" column="user_name"/>
<result property="updateUserId" column="update_user_id"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
</resultMap>
<select id="selectListByParam" resultMap="BaseResultMap">
SELECT f.* FROM `disk_files` f
LEFT JOIN disk_catalogue_files cf ON f.id=cf.files_id AND cf.id > 0
WHERE f.delete_flag=0 AND cf.delete_flag = 0
AND f.create_user_id = #{param.userId} AND cf.catalogue_id=#{param.parentId}
ORDER BY f.create_time DESC
</select>
</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