feat: 修改文件数据接口的返回结果,增添收藏标识,个人文件标识和标签列表
This commit is contained in:
parent
3d908e23b6
commit
a750c3cb62
|
|
@ -175,7 +175,7 @@ public class EdFileInfoController {
|
|||
@UserOperation(value="收藏了文件", modelName = UserOperationModuleEnum.DATABASE)
|
||||
public ElectromagneticResult<?> addFavorite(@RequestParam String id) {
|
||||
String userId = UserThreadLocal.getUserId();
|
||||
return ElectromagneticResultUtil.success(edFileFavoriteService.addFavorite(userId, id));
|
||||
return ElectromagneticResultUtil.success(edFileInfoService.addFavorite(userId, id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -187,7 +187,7 @@ public class EdFileInfoController {
|
|||
@UserOperation(value="从收藏夹移除了文件", modelName = UserOperationModuleEnum.DATABASE)
|
||||
public ElectromagneticResult<?> removeFavorite(@RequestParam String id) {
|
||||
String userId = UserThreadLocal.getUserId();
|
||||
return ElectromagneticResultUtil.success(edFileFavoriteService.removeFavorite(userId, id));
|
||||
return ElectromagneticResultUtil.success(edFileInfoService.removeFavorite(userId, id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -198,6 +198,6 @@ public class EdFileInfoController {
|
|||
@UserOperation(value="查看了收藏夹", modelName = UserOperationModuleEnum.DATABASE)
|
||||
public ElectromagneticResult<?> listFavorite(@RequestBody FileInfoQueryDTO fileInfoQueryDTO) {
|
||||
String userId = UserThreadLocal.getUserId();
|
||||
return ElectromagneticResultUtil.success(edFileFavoriteService.findFavorite(userId, fileInfoQueryDTO));
|
||||
return ElectromagneticResultUtil.success(edFileInfoService.findFavorite(userId, fileInfoQueryDTO));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.electromagnetic.industry.software.common.enums.UserOperationModuleEnu
|
|||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.TagCreateDTO;
|
||||
import com.electromagnetic.industry.software.manage.service.EdTagLibraryService;
|
||||
import com.electromagnetic.industry.software.manage.service.FileTagRelationService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
|
@ -91,8 +92,8 @@ public class EdTagLibraryController {
|
|||
// 批量添加标签到文件
|
||||
@PostMapping("/addTagsToFile")
|
||||
@UserOperation(value="批量添加了标签到文件", modelName = UserOperationModuleEnum.TAG)
|
||||
public ElectromagneticResult<?> addTagsToFile(@RequestParam String fileId, @RequestParam List<String> tagIds) {
|
||||
public ElectromagneticResult<?> addTagsToFile(@RequestBody TagCreateDTO dto) {
|
||||
String createdBy = UserThreadLocal.getUserId();
|
||||
return ElectromagneticResultUtil.success(fileTagRelationService.addTagsToFile(fileId, tagIds, createdBy));
|
||||
return ElectromagneticResultUtil.success(fileTagRelationService.addTagsToFile(dto.getFileId(), dto.getTagIds(), createdBy));
|
||||
}
|
||||
}
|
||||
|
|
@ -161,7 +161,7 @@ public class UserEdFileInfoController {
|
|||
@UserOperation(value="收藏文件", modelName = UserOperationModuleEnum.USER_PRJ)
|
||||
public ElectromagneticResult<?> addFavorite(@RequestParam String id) {
|
||||
String userId = UserThreadLocal.getUserId();
|
||||
return ElectromagneticResultUtil.success(edFileFavoriteService.addFavorite(userId, id));
|
||||
return ElectromagneticResultUtil.success(edFileInfoService.addFavorite(userId, id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -173,19 +173,7 @@ public class UserEdFileInfoController {
|
|||
@UserOperation(value="从收藏夹移除文件", modelName = UserOperationModuleEnum.USER_PRJ)
|
||||
public ElectromagneticResult<?> removeFavorite(@RequestParam String id) {
|
||||
String userId = UserThreadLocal.getUserId();
|
||||
return ElectromagneticResultUtil.success(edFileFavoriteService.removeFavorite(userId, id));
|
||||
return ElectromagneticResultUtil.success(edFileInfoService.removeFavorite(userId, id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 展示当前用户收藏夹文件
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/listCollection")
|
||||
@UserOperation(value="查看收藏夹", modelName = UserOperationModuleEnum.USER_PRJ)
|
||||
public ElectromagneticResult<?> listFavorite(@RequestBody FileInfoQueryDTO fileInfoQueryDTO) {
|
||||
String userId = UserThreadLocal.getUserId();
|
||||
return ElectromagneticResultUtil.success(edFileFavoriteService.findFavorite(userId, fileInfoQueryDTO));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import lombok.Data;
|
|||
@TableName("ed_file_favorite")
|
||||
public class EdFileFavorite {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
@TableId(type = IdType.ASSIGN_UUID)
|
||||
private String id;
|
||||
|
||||
@TableField("user_id")
|
||||
private String userId;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import java.util.Date;
|
|||
@TableName("ed_tag_library")
|
||||
public class EdTagLibrary {
|
||||
|
||||
@TableId
|
||||
private String tagId; // 主键 ID
|
||||
private String parentId; // 父 ID,"" 代表是标签组
|
||||
private Integer type; // 0: 标签组, 1: 标签
|
||||
|
|
|
|||
|
|
@ -48,4 +48,9 @@ public class FileInfoVO {
|
|||
|
||||
private List<FileTagInfo> labels;
|
||||
|
||||
// 是否是收藏数据,1是,0否
|
||||
private Integer isFavorite;
|
||||
|
||||
// 是否是个人数据,1是,0否
|
||||
private Integer isPersonal;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
package com.electromagnetic.industry.software.manage.pojo.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class TagCreateDTO {
|
||||
|
||||
private String fileId;
|
||||
|
||||
private List<String> tagIds;
|
||||
}
|
||||
|
|
@ -1,42 +1,7 @@
|
|||
package com.electromagnetic.industry.software.manage.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.EdFileFavorite;
|
||||
import com.electromagnetic.industry.software.manage.pojo.other.FileInfoVO;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.FileInfoQueryDTO;
|
||||
|
||||
public interface EdFileFavoriteService extends IService<EdFileFavorite> {
|
||||
|
||||
/**
|
||||
* 添加收藏
|
||||
* @param userId
|
||||
* @param fileId
|
||||
* @return
|
||||
*/
|
||||
boolean addFavorite(String userId, String fileId);
|
||||
|
||||
/**
|
||||
* 移除收藏
|
||||
* @param userId
|
||||
* @param fileId
|
||||
* @return
|
||||
*/
|
||||
boolean removeFavorite(String userId, String fileId);
|
||||
|
||||
/**
|
||||
* 判断是否已收藏
|
||||
* @param userId
|
||||
* @param fileId
|
||||
* @return
|
||||
*/
|
||||
boolean isFavorite(String userId, String fileId);
|
||||
|
||||
/**
|
||||
* 查询当前用户收藏文件信息
|
||||
* @param userId 用户id
|
||||
* @param fileInfoQueryDTO 分页信息
|
||||
* @return
|
||||
*/
|
||||
IPage<FileInfoVO> findFavorite(String userId, FileInfoQueryDTO fileInfoQueryDTO);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -199,4 +199,36 @@ public interface EdFileInfoService {
|
|||
* @return
|
||||
*/
|
||||
public boolean isFolder(String id);
|
||||
|
||||
/**
|
||||
* 添加收藏
|
||||
* @param userId
|
||||
* @param fileId
|
||||
* @return
|
||||
*/
|
||||
boolean addFavorite(String userId, String fileId);
|
||||
|
||||
/**
|
||||
* 判断是否已收藏
|
||||
* @param userId
|
||||
* @param fileId
|
||||
* @return
|
||||
*/
|
||||
boolean isFavorite(String userId, String fileId);
|
||||
|
||||
/**
|
||||
* 移除收藏
|
||||
* @param userId
|
||||
* @param fileId
|
||||
* @return
|
||||
*/
|
||||
boolean removeFavorite(String userId, String fileId);
|
||||
|
||||
/**
|
||||
* 查询当前用户收藏文件信息
|
||||
* @param userId 用户id
|
||||
* @param fileInfoQueryDTO 分页信息
|
||||
* @return
|
||||
*/
|
||||
IPage<FileInfoVO> findFavorite(String userId, FileInfoQueryDTO fileInfoQueryDTO);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,26 @@ package com.electromagnetic.industry.software.manage.service;
|
|||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.FileTagRelation;
|
||||
import com.electromagnetic.industry.software.manage.pojo.resp.FileTagInfo;
|
||||
import com.electromagnetic.industry.software.manage.pojo.resp.TagListVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface FileTagRelationService extends IService<FileTagRelation> {
|
||||
boolean addTagToFile(String fileId, String tagId, String createdBy);
|
||||
|
||||
/**
|
||||
* 批量添加标签到文件
|
||||
* @param fileId
|
||||
* @param tagIds
|
||||
* @param createdBy
|
||||
* @return
|
||||
*/
|
||||
boolean addTagsToFile(String fileId, List<String> tagIds, String createdBy);
|
||||
|
||||
/**
|
||||
* 获取文件标签
|
||||
* @param fileId
|
||||
* @return
|
||||
*/
|
||||
List<FileTagInfo> getFileTags (String fileId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,86 +1,11 @@
|
|||
package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
||||
|
||||
import cn.hutool.core.text.StrFormatter;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.electromagnetic.industry.software.common.enums.EffectFlagEnum;
|
||||
import com.electromagnetic.industry.software.common.enums.EleDataSaveStatusEnum;
|
||||
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||
import com.electromagnetic.industry.software.common.util.EleCommonUtil;
|
||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||
import com.electromagnetic.industry.software.manage.mapper.EdFileFavoriteMapper;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.EdFileFavorite;
|
||||
import com.electromagnetic.industry.software.manage.pojo.other.FileInfoVO;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.FileInfoQueryDTO;
|
||||
import com.electromagnetic.industry.software.manage.service.EdFileFavoriteService;
|
||||
import com.electromagnetic.industry.software.manage.service.EdFileInfoService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class EdFileFavoriteServiceImpl extends ServiceImpl<EdFileFavoriteMapper, EdFileFavorite> implements EdFileFavoriteService {
|
||||
|
||||
@Resource
|
||||
private EdFileInfoService fileInfoService;
|
||||
|
||||
@Override
|
||||
public boolean addFavorite(String userId, String fileId) {
|
||||
|
||||
// 查询是否已存在
|
||||
LambdaQueryWrapper<EdFileFavorite> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(EdFileFavorite::getUserId, userId)
|
||||
.eq(EdFileFavorite::getFileId, fileId);
|
||||
if (this.getOne(queryWrapper) != null) {
|
||||
throw new BizException("文件已收藏,无法重复收藏!");
|
||||
}
|
||||
|
||||
// 插入收藏记录
|
||||
EdFileFavorite favorite = new EdFileFavorite();
|
||||
favorite.setUserId(userId);
|
||||
favorite.setFileId(fileId);
|
||||
boolean isSaved = this.save(favorite);
|
||||
if (isSaved) {
|
||||
UserThreadLocal.setSuccessInfo("", fileId, StrFormatter.format("收藏了文件"));
|
||||
}
|
||||
return isSaved;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFavorite(String userId, String fileId) {
|
||||
LambdaQueryWrapper<EdFileFavorite> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(EdFileFavorite::getUserId, userId)
|
||||
.eq(EdFileFavorite::getFileId, fileId);
|
||||
boolean isRemoved = this.remove(queryWrapper);
|
||||
if (isRemoved) {
|
||||
UserThreadLocal.setSuccessInfo("", fileId, StrFormatter.format("取消了收藏"));
|
||||
}
|
||||
return isRemoved;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFavorite(String userId, String fileId) {
|
||||
LambdaQueryWrapper<EdFileFavorite> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(EdFileFavorite::getUserId, userId)
|
||||
.eq(EdFileFavorite::getFileId, fileId);
|
||||
return this.getOne(queryWrapper) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<FileInfoVO> findFavorite(String userId, FileInfoQueryDTO fileInfoQueryDTO) {
|
||||
// 查询该用户收藏的文件id
|
||||
LambdaQueryWrapper<EdFileFavorite> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.select(EdFileFavorite::getFileId).eq(EdFileFavorite::getUserId, userId);
|
||||
List<String> fileIds = this.listObjs(queryWrapper, Object::toString);
|
||||
|
||||
// 创建分页对象
|
||||
Page<FileInfoVO> page = new Page<>(fileInfoQueryDTO.getPageNum(), fileInfoQueryDTO.getPageSize());
|
||||
IPage<FileInfoVO> fileInfoVOIPage = fileInfoService.queryFileList(page, fileIds, fileInfoQueryDTO, EleDataSaveStatusEnum.SUCCESS.code, EffectFlagEnum.EFFECT.code);
|
||||
fileInfoVOIPage.getRecords().forEach(e -> e.setFileSizeShow(EleCommonUtil.convertFileSize(e.getFileSize())));
|
||||
UserThreadLocal.setSuccessInfo("", "", "查询了收藏列表");
|
||||
return fileInfoVOIPage;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,16 +27,14 @@ import com.electromagnetic.industry.software.common.util.*;
|
|||
import com.electromagnetic.industry.software.manage.config.ElePropertyConfig;
|
||||
import com.electromagnetic.industry.software.manage.mapper.EdFileInfoMapper;
|
||||
import com.electromagnetic.industry.software.manage.mapper.UserMapper;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.EdFileFavorite;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.EdFileInfo;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.User;
|
||||
import com.electromagnetic.industry.software.manage.pojo.other.FileInfoVO;
|
||||
import com.electromagnetic.industry.software.manage.pojo.other.UploadRecordDTO;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.*;
|
||||
import com.electromagnetic.industry.software.manage.pojo.resp.*;
|
||||
import com.electromagnetic.industry.software.manage.service.EdFileInfoService;
|
||||
import com.electromagnetic.industry.software.manage.service.EdTagLibraryService;
|
||||
import com.electromagnetic.industry.software.manage.service.FileSystemService;
|
||||
import com.electromagnetic.industry.software.manage.service.PermissionService;
|
||||
import com.electromagnetic.industry.software.manage.service.*;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
|
@ -79,7 +77,10 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
private ElePropertyConfig elePropertyConfig;
|
||||
|
||||
@Resource
|
||||
private EdTagLibraryService edTagLibraryService;
|
||||
private EdFileFavoriteService fileFavoriteService;
|
||||
|
||||
@Resource
|
||||
private FileTagRelationService fileTagRelationService;
|
||||
|
||||
/**
|
||||
* 查询文件列表
|
||||
|
|
@ -144,7 +145,12 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
Page<EdFileInfo> edFileInfoPage = this.baseMapper.selectPage(new Page<>(pars.getPageNum(), pars.getPageSize()), queryWrapper);
|
||||
long total = edFileInfoPage.getTotal();
|
||||
List<FileInfoVO> records = BeanUtil.copyToList(edFileInfoPage.getRecords(), FileInfoVO.class);
|
||||
records.forEach(e -> e.setFileSizeShow(EleCommonUtil.convertFileSize(e.getFileSize())));
|
||||
records.forEach(e -> {
|
||||
e.setFileSizeShow(EleCommonUtil.convertFileSize(e.getFileSize()));
|
||||
e.setIsFavorite(isFavorite(UserThreadLocal.getUserId(), e.getId()) ? 1 : 0);
|
||||
e.setIsPersonal(dataOwnCode == DataOwnEnum.USER_FILE.code ? 1 : 0);
|
||||
e.setLabels(fileTagRelationService.getFileTags(e.getId()));
|
||||
});
|
||||
UserThreadLocal.setSuccessInfo("", "", "查询文件成功");
|
||||
return ElectromagneticResultUtil.success(new RespPageVO<>(total, records));
|
||||
}
|
||||
|
|
@ -1323,4 +1329,89 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
return fileInfo.getDataType().equals(EleDataTypeEnum.FOLDER.code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加收藏
|
||||
* @param userId
|
||||
* @param fileId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean addFavorite(String userId, String fileId) {
|
||||
|
||||
// 查询是否已存在
|
||||
LambdaQueryWrapper<EdFileFavorite> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(EdFileFavorite::getUserId, userId)
|
||||
.eq(EdFileFavorite::getFileId, fileId);
|
||||
if (fileFavoriteService.getOne(queryWrapper) != null) {
|
||||
throw new BizException("文件已收藏,无法重复收藏!");
|
||||
}
|
||||
|
||||
// 插入收藏记录
|
||||
EdFileFavorite favorite = new EdFileFavorite();
|
||||
favorite.setUserId(userId);
|
||||
favorite.setFileId(fileId);
|
||||
boolean isSaved = fileFavoriteService.save(favorite);
|
||||
if (isSaved) {
|
||||
UserThreadLocal.setSuccessInfo("", fileId, StrFormatter.format("收藏了文件"));
|
||||
}
|
||||
return isSaved;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否已收藏
|
||||
* @param userId
|
||||
* @param fileId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean isFavorite(String userId, String fileId) {
|
||||
LambdaQueryWrapper<EdFileFavorite> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(EdFileFavorite::getUserId, userId)
|
||||
.eq(EdFileFavorite::getFileId, fileId);
|
||||
return fileFavoriteService.getOne(queryWrapper) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除收藏
|
||||
* @param userId
|
||||
* @param fileId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean removeFavorite(String userId, String fileId) {
|
||||
LambdaQueryWrapper<EdFileFavorite> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(EdFileFavorite::getUserId, userId)
|
||||
.eq(EdFileFavorite::getFileId, fileId);
|
||||
boolean isRemoved = fileFavoriteService.remove(queryWrapper);
|
||||
if (isRemoved) {
|
||||
UserThreadLocal.setSuccessInfo("", fileId, StrFormatter.format("取消了收藏"));
|
||||
}
|
||||
return isRemoved;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前用户收藏文件信息
|
||||
* @param userId 用户id
|
||||
* @param fileInfoQueryDTO 分页信息
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public IPage<FileInfoVO> findFavorite(String userId, FileInfoQueryDTO fileInfoQueryDTO) {
|
||||
// 查询该用户收藏的文件id
|
||||
LambdaQueryWrapper<EdFileFavorite> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.select(EdFileFavorite::getFileId).eq(EdFileFavorite::getUserId, userId);
|
||||
List<String> fileIds = fileFavoriteService.listObjs(queryWrapper, Object::toString);
|
||||
|
||||
// 创建分页对象
|
||||
Page<FileInfoVO> page = new Page<>(fileInfoQueryDTO.getPageNum(), fileInfoQueryDTO.getPageSize());
|
||||
IPage<FileInfoVO> fileInfoVOIPage = queryFileList(page, fileIds, fileInfoQueryDTO, EleDataSaveStatusEnum.SUCCESS.code, EffectFlagEnum.EFFECT.code);
|
||||
fileInfoVOIPage.getRecords().forEach(e -> {
|
||||
e.setFileSizeShow(EleCommonUtil.convertFileSize(e.getFileSize()));
|
||||
e.setIsFavorite(isFavorite(UserThreadLocal.getUserId(), e.getId()) ? 1 : 0);
|
||||
e.setIsPersonal(e.getCreatedBy() == UserThreadLocal.getUserId() ? 1 : 0);
|
||||
});
|
||||
UserThreadLocal.setSuccessInfo("", "", "查询了收藏列表");
|
||||
return fileInfoVOIPage;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,20 +9,23 @@ import com.electromagnetic.industry.software.manage.mapper.EdTagLibraryMapper;
|
|||
import com.electromagnetic.industry.software.manage.mapper.FileTagRelationMapper;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.EdTagLibrary;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.FileTagRelation;
|
||||
import com.electromagnetic.industry.software.manage.pojo.resp.FileTagInfo;
|
||||
import com.electromagnetic.industry.software.manage.pojo.resp.TagListVO;
|
||||
import com.electromagnetic.industry.software.manage.service.FileTagRelationService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class FileTagRelationServiceImpl extends ServiceImpl<FileTagRelationMapper, FileTagRelation> implements FileTagRelationService {
|
||||
@Autowired
|
||||
private EdTagLibraryMapper edTagLibraryMapper;
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean addTagToFile(String fileId, String tagId, String createdBy) {
|
||||
private boolean addTagToFile(String fileId, String tagId, String createdBy) {
|
||||
// 检查标签是否存在并且已发布
|
||||
EdTagLibrary tag = edTagLibraryMapper.selectOne(new LambdaQueryWrapper<EdTagLibrary>()
|
||||
.eq(EdTagLibrary::getTagId, tagId)
|
||||
|
|
@ -36,13 +39,19 @@ public class FileTagRelationServiceImpl extends ServiceImpl<FileTagRelationMappe
|
|||
relation.setTagId(tagId);
|
||||
relation.setCreatedBy(createdBy);
|
||||
|
||||
boolean isSuccess = this.save(relation);
|
||||
if (isSuccess) {
|
||||
UserThreadLocal.setSuccessInfo("", relation.getId(), "添加了标签到文件");
|
||||
}
|
||||
return isSuccess;
|
||||
return this.saveOrUpdate(relation, new LambdaQueryWrapper<FileTagRelation>()
|
||||
.eq(FileTagRelation::getFileId, fileId)
|
||||
.eq(FileTagRelation::getTagId, tagId));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量添加标签到文件
|
||||
* @param fileId
|
||||
* @param tagIds
|
||||
* @param createdBy
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean addTagsToFile(String fileId, List<String> tagIds, String createdBy) {
|
||||
|
|
@ -50,6 +59,29 @@ public class FileTagRelationServiceImpl extends ServiceImpl<FileTagRelationMappe
|
|||
for (String tagId : tagIds) {
|
||||
isSuccess &= addTagToFile(fileId, tagId, createdBy);
|
||||
}
|
||||
if (isSuccess) {
|
||||
UserThreadLocal.setSuccessInfo("", "", "添加了标签到文件");
|
||||
}
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件标签
|
||||
* @param fileId
|
||||
* @return
|
||||
*/
|
||||
public List<FileTagInfo> getFileTags (String fileId) {
|
||||
LambdaQueryWrapper<FileTagRelation> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(FileTagRelation::getFileId, fileId);
|
||||
List<FileTagRelation> relations = this.list(queryWrapper);
|
||||
List<FileTagInfo> result = new ArrayList<>();
|
||||
for (FileTagRelation relation : relations) {
|
||||
EdTagLibrary tagInfo = edTagLibraryMapper.selectById(relation.getTagId());
|
||||
FileTagInfo vo = new FileTagInfo();
|
||||
BeanUtils.copyProperties(tagInfo, vo);
|
||||
result.add(vo);
|
||||
}
|
||||
UserThreadLocal.setSuccessInfo("", "", "获取了标签数据");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue