文件上传和排序接口整合
Showing
3 changed files
with
34 additions
and
2 deletions
| ... | @@ -4,10 +4,12 @@ import java.util.Date; | ... | @@ -4,10 +4,12 @@ import java.util.Date; |
| 4 | import java.io.Serializable; | 4 | import java.io.Serializable; |
| 5 | 5 | ||
| 6 | import com.baomidou.mybatisplus.annotation.TableField; | 6 | import com.baomidou.mybatisplus.annotation.TableField; |
| 7 | import com.fasterxml.jackson.annotation.JsonFormat; | ||
| 7 | import io.swagger.annotations.ApiModel; | 8 | import io.swagger.annotations.ApiModel; |
| 8 | import io.swagger.annotations.ApiModelProperty; | 9 | import io.swagger.annotations.ApiModelProperty; |
| 9 | import lombok.Data; | 10 | import lombok.Data; |
| 10 | import lombok.EqualsAndHashCode; | 11 | import lombok.EqualsAndHashCode; |
| 12 | import org.springframework.format.annotation.DateTimeFormat; | ||
| 11 | 13 | ||
| 12 | /** | 14 | /** |
| 13 | * <p> | 15 | * <p> |
| ... | @@ -41,6 +43,8 @@ public class AddDgFileRequest implements Serializable { | ... | @@ -41,6 +43,8 @@ public class AddDgFileRequest implements Serializable { |
| 41 | * 上传日期 | 43 | * 上传日期 |
| 42 | */ | 44 | */ |
| 43 | @ApiModelProperty(name = "scrq", value = "上传日期") | 45 | @ApiModelProperty(name = "scrq", value = "上传日期") |
| 46 | @DateTimeFormat(pattern = "yyyy-MM-dd") | ||
| 47 | @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") | ||
| 44 | private Date scrq; | 48 | private Date scrq; |
| 45 | 49 | ||
| 46 | /** | 50 | /** | ... | ... |
| ... | @@ -74,4 +74,10 @@ public class DgFileListVO implements Serializable { | ... | @@ -74,4 +74,10 @@ public class DgFileListVO implements Serializable { |
| 74 | */ | 74 | */ |
| 75 | @ApiModelProperty(name = "xh", value = "序号") | 75 | @ApiModelProperty(name = "xh", value = "序号") |
| 76 | private Integer xh; | 76 | private Integer xh; |
| 77 | |||
| 78 | /** | ||
| 79 | * 存储url | ||
| 80 | */ | ||
| 81 | @ApiModelProperty(name = "saveUrl", value = "存储url") | ||
| 82 | private String saveUrl; | ||
| 77 | } | 83 | } | ... | ... |
| 1 | package com.pashanhoo.file.service.impl; | 1 | package com.pashanhoo.file.service.impl; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.date.DateTime; | ||
| 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 4 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| 4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 5 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| 5 | import com.pashanhoo.common.util.fileupload.MinioConfig; | 6 | import com.pashanhoo.common.util.fileupload.MinioConfig; |
| ... | @@ -11,6 +12,7 @@ import com.pashanhoo.file.mapper.DgFileMapper; | ... | @@ -11,6 +12,7 @@ import com.pashanhoo.file.mapper.DgFileMapper; |
| 11 | import com.pashanhoo.file.service.DgFileService; | 12 | import com.pashanhoo.file.service.DgFileService; |
| 12 | import org.springframework.beans.factory.annotation.Autowired; | 13 | import org.springframework.beans.factory.annotation.Autowired; |
| 13 | import org.springframework.stereotype.Service; | 14 | import org.springframework.stereotype.Service; |
| 15 | import org.springframework.transaction.annotation.Transactional; | ||
| 14 | import org.springframework.web.multipart.MultipartFile; | 16 | import org.springframework.web.multipart.MultipartFile; |
| 15 | 17 | ||
| 16 | 18 | ||
| ... | @@ -84,6 +86,7 @@ public class DgFileServiceImpl extends ServiceImpl<DgFileMapper, DgFileDO> imple | ... | @@ -84,6 +86,7 @@ public class DgFileServiceImpl extends ServiceImpl<DgFileMapper, DgFileDO> imple |
| 84 | @Override | 86 | @Override |
| 85 | public List<DgCatalogWithFileVO> getFileList(String bsmArchive) { | 87 | public List<DgCatalogWithFileVO> getFileList(String bsmArchive) { |
| 86 | List<DgCatalogWithFileVO> fileList = dgfileMapper.getFileList(bsmArchive); | 88 | List<DgCatalogWithFileVO> fileList = dgfileMapper.getFileList(bsmArchive); |
| 89 | fileList.forEach(item->item.getFileLists().forEach(file->file.setSaveUrl(file.getFjurl()))); | ||
| 87 | fileList.forEach(catalogWithFiles->catalogWithFiles.getFileLists().forEach(file->file.setFjurl(minioUtil.getPreviewUrl(file.getFjurl())))); | 90 | fileList.forEach(catalogWithFiles->catalogWithFiles.getFileLists().forEach(file->file.setFjurl(minioUtil.getPreviewUrl(file.getFjurl())))); |
| 88 | return fileList; | 91 | return fileList; |
| 89 | } | 92 | } |
| ... | @@ -126,12 +129,31 @@ public class DgFileServiceImpl extends ServiceImpl<DgFileMapper, DgFileDO> imple | ... | @@ -126,12 +129,31 @@ public class DgFileServiceImpl extends ServiceImpl<DgFileMapper, DgFileDO> imple |
| 126 | * @return | 129 | * @return |
| 127 | */ | 130 | */ |
| 128 | @Override | 131 | @Override |
| 132 | @Transactional(rollbackFor = Exception.class) | ||
| 129 | public boolean upload(MultipartFile file, AddDgFileRequest fileRequest) throws IOException { | 133 | public boolean upload(MultipartFile file, AddDgFileRequest fileRequest) throws IOException { |
| 130 | //文件上传 | 134 | //文件上传 |
| 131 | FileAttribute fileAttribute = minioUtil.upload(file); | 135 | FileAttribute fileAttribute = minioUtil.upload(file); |
| 132 | 136 | ||
| 133 | //文件 | 137 | Integer firstXh = fileRequest.getXh(); |
| 134 | return true; | 138 | String firstBsmCatalog = fileRequest.getBsmCatalog(); |
| 139 | |||
| 140 | //文件信息入库 | ||
| 141 | QueryWrapper<DgFileDO> fileWrapper = new QueryWrapper<>(); | ||
| 142 | DgFileDO fileDO = new DgFileDO(); | ||
| 143 | fileDO.setBsmCatalog(fileRequest.getBsmCatalog()); | ||
| 144 | fileDO.setFjurl(fileAttribute.getSaveUrl()); | ||
| 145 | fileDO.setFjsize(fileAttribute.getFileSize()); | ||
| 146 | fileDO.setKzm(fileAttribute.getExpandName()); | ||
| 147 | fileDO.setScrq(DateTime.now()); | ||
| 148 | fileDO.setScr(null); | ||
| 149 | fileDO.setXh(firstXh + 1); | ||
| 150 | this.save(fileDO); | ||
| 151 | |||
| 152 | //重新排序 | ||
| 153 | fileWrapper.lambda().eq(DgFileDO::getBsmCatalog, firstBsmCatalog).ge(DgFileDO::getXh, firstXh + 1); | ||
| 154 | List<DgFileDO> list = this.list(fileWrapper); | ||
| 155 | list.forEach(item -> item.setXh(item.getXh() + 1)); | ||
| 156 | return this.saveBatch(list); | ||
| 135 | } | 157 | } |
| 136 | 158 | ||
| 137 | 159 | ... | ... |
-
Please register or sign in to post a comment