Compare commits

..

No commits in common. "42ff11815749cb5c2fd3d8115a281ef994be7202" and "80c36386317174da0694d902c6619cd85bb496ed" have entirely different histories.

16 changed files with 95 additions and 338 deletions

View File

@ -9,6 +9,6 @@ import org.apache.ibatis.annotations.Select;
@Mapper
public interface EdTagLibraryMapper extends BaseMapper<EdTagLibrary> {
// @Select("SELECT MAX(order_by) FROM ed_tag_library WHERE type = #{type} and parent_id = #{parentId}")
// Integer selectMaxOrder(@Param("type") int type, @Param("parentId") String parentId);
@Select("SELECT MAX(order_by) FROM ed_tag_library WHERE type = #{type} and parent_id = #{parentId}")
Integer selectMaxOrder(@Param("type") int type, @Param("parentId") String parentId);
}

View File

@ -1,23 +1,16 @@
package com.electromagnetic.industry.software.manage.pojo.models;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.electromagnetic.industry.software.common.cons.UserConstants;
import com.electromagnetic.industry.software.common.enums.EffectFlagEnum;
import com.electromagnetic.industry.software.common.enums.PublishEnum;
import com.electromagnetic.industry.software.common.util.IdWorker;
import com.electromagnetic.industry.software.common.util.SignUtils;
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
import lombok.Data;
import java.util.Date;
@Data
@TableName("ed_tag_library")
public class EdTagLibrary extends BaseModel{
public class EdTagLibrary {
@TableId
private String tagId; // 主键 ID
@ -26,18 +19,14 @@ public class EdTagLibrary extends BaseModel{
private String tagName; // 标签库或标签名称
private Integer orderBy; // 排序字段
private Integer isPublished; // 是否已发布0: 未发布, 1: 已发布
private String createdBy; // 创建人
public void newInit() {
String id = IdWorker.getSnowFlakeIdString();
String userId = UserThreadLocal.getUserId();
this.setTagId(id);
Date now = new Date();
this.setCreatedTime(now);
this.setUpdatedTime(now);
this.setCreatedBy(userId);
this.setUpdatedBy(userId);
this.setEffectFlag(EffectFlagEnum.EFFECT.code);
this.setIsPublished(PublishEnum.UNPUBLISHED.getCode()); //默认未发布
}
@TableField(fill = FieldFill.INSERT)
private Date createdTime; // 创建时间
private String updatedBy; // 更新人
@TableField(fill = FieldFill.UPDATE)
private Date updatedTime; // 更新时间
}

View File

@ -3,32 +3,15 @@ package com.electromagnetic.industry.software.manage.pojo.models;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.electromagnetic.industry.software.common.enums.EffectFlagEnum;
import com.electromagnetic.industry.software.common.util.IdWorker;
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("file_tag_relations")
public class FileTagRelation extends BaseModel {
@TableId(type = IdType.ASSIGN_UUID)
private String id;
private String fileId;
private String tagId;
public void newInit() {
String newId = IdWorker.getSnowFlakeIdString();
Date now = new Date();
String userId = UserThreadLocal.getUserId();
this.setId(newId);
this.setCreatedTime(now);
this.setCreatedBy(userId);
this.setUpdatedTime(now);
this.setUpdatedBy(userId);
this.setEffectFlag(EffectFlagEnum.EFFECT.code);
}
}

View File

@ -38,11 +38,4 @@ public interface EdFileRelationService extends IService<EdFileRelation> {
*/
Boolean checkNameExist(CheckNameUniqueRequest checkNameUniqueRequest);
/**
* 逻辑删除文件关系
* @param fileId 文件主键id
* @return
*/
boolean logicRemove (String fileId);
}

View File

@ -33,14 +33,4 @@ public interface FileTagRelationService extends IService<FileTagRelation> {
* @return
*/
List<String> getFileIdsByTagIds(List<String> tagIds);
/**
* 逻辑删除文件标签关系
*
* @param fileId
* @param tagId
* @return
*/
boolean logicRemove(String fileId, String tagId);
}

View File

@ -1,12 +1,9 @@
package com.electromagnetic.industry.software.manage.service;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.electromagnetic.industry.software.common.enums.EffectFlagEnum;
import com.electromagnetic.industry.software.manage.pojo.models.EdFileInfo;
import com.electromagnetic.industry.software.manage.pojo.models.RolePermission;
import com.electromagnetic.industry.software.manage.pojo.req.PublishedFileDTO;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@ -44,14 +41,4 @@ public interface RolePermissionService extends IService<RolePermission> {
* @param prjId
*/
void syncPermissionsAfterTreeUpdate(List<EdFileInfo> files, String prjId);
/**
* 逻辑删除
*
* @param roleId
* @param fileId
* @return
*/
boolean logicRemove (String roleId, String fileId);
}

View File

@ -2,17 +2,6 @@ package com.electromagnetic.industry.software.manage.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.electromagnetic.industry.software.manage.pojo.models.UserRole;
import org.springframework.transaction.annotation.Transactional;
public interface UserRoleService extends IService<UserRole> {
/**
* 逻辑删除用户-角色关联关系
* @param userId 用户ID可选
* @param roleId 角色ID可选
* @return 操作是否成功
* @throws IllegalArgumentException 参数校验失败时抛出
*/
boolean logicRemove (String userId, String roleId);
}

View File

@ -20,14 +20,10 @@ public class EdFileFavoriteServiceImpl extends ServiceImpl<EdFileFavoriteMapper,
* @return
*/
public boolean logicRemove(String userId, String fileId) {
if (userId == null && fileId == null) {
throw new IllegalArgumentException("必须提供至少一个参数");
}
LambdaUpdateWrapper<EdFileFavorite> updateWrapper = Wrappers.lambdaUpdate(EdFileFavorite.class)
.set(EdFileFavorite::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
.eq(userId != null, EdFileFavorite::getUserId, userId)
.eq(fileId != null, EdFileFavorite::getFileId, fileId)
.eq(EdFileFavorite::getEffectFlag, EffectFlagEnum.EFFECT.code);
.eq(EdFileFavorite::getUserId, userId)
.eq(EdFileFavorite::getFileId, fileId)
.set(EdFileFavorite::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code);
return update(updateWrapper);
}

View File

@ -40,7 +40,6 @@ import com.electromagnetic.industry.software.manage.pojo.resp.UploadRecordVO;
import com.electromagnetic.industry.software.manage.service.*;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpHeaders;
@ -84,8 +83,6 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
private UserAccessLogService userAccessLogService;
@Resource
private EdFileRelationService edFileRelationService;
@Resource
private RolePermissionService rolePermissionService;
/**
* 查询文件列表
@ -259,8 +256,6 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
.set(EdFileInfo::getEffectFlag, false)
.set(EdFileInfo::getAllDeleted, true)
.eq(EdFileInfo::getFileId, fileInfo.getFileId()));
// 统一处理文件相关关系
cleanRelatedData(fileInfo.getFileId());
UserThreadLocal.setSuccessInfo(fileInfo.getParentId(), id, "作废文件 {}.{} 成功,路径为 {}", fileInfo.getFileName(), fileInfo.getFileType(), dbPath);
return ElectromagneticResultUtil.success(true);
}
@ -1366,33 +1361,20 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
LambdaQueryWrapper<EdFileFavorite> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(EdFileFavorite::getUserId, userId)
.eq(EdFileFavorite::getFileId, fileId);
EdFileFavorite existingFavorite = fileFavoriteService.getOne(queryWrapper);
boolean result;
if (existingFavorite != null) {
// 如果收藏记录已存在且有效
if (Objects.equals(existingFavorite.getEffectFlag(), EffectFlagEnum.EFFECT.code)) {
throw new BizException("文件已收藏,无法重复收藏!");
}
// 恢复失效的收藏记录
existingFavorite.setEffectFlag(EffectFlagEnum.EFFECT.code);
existingFavorite.newInit(); // 重置更新时间等信息
result = fileFavoriteService.updateById(existingFavorite);
} else {
// 插入收藏记录
EdFileFavorite favorite = new EdFileFavorite();
favorite.newInit();
favorite.setUserId(userId);
favorite.setFileId(fileId);
result = fileFavoriteService.save(favorite);
if (fileFavoriteService.getOne(queryWrapper) != null) {
throw new BizException("文件已收藏,无法重复收藏!");
}
if (result) {
// 插入收藏记录
EdFileFavorite favorite = new EdFileFavorite();
favorite.setUserId(userId);
favorite.setFileId(fileId);
boolean isSaved = fileFavoriteService.save(favorite);
if (isSaved) {
EdFileInfo fileInfo = this.baseMapper.selectById(fileId);
UserThreadLocal.setSuccessInfo(Optional.ofNullable(fileInfo).map(EdFileInfo::getParentId).orElse(""), fileId, StrFormatter.format("收藏了文件"));
}
return result;
return isSaved;
}
/**
@ -1505,27 +1487,4 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
UserThreadLocal.setSuccessInfo("", id, StrFormatter.format("建立了文件 {} 与文件 {} 的关系", id, relatedFileId));
return ElectromagneticResultUtil.success(true);
}
/**
* 统一废除文件相关数据
* @param fileId **文件编号非id
*/
public void cleanRelatedData (String fileId) {
// 查询
LambdaQueryWrapper<EdFileInfo> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(EdFileInfo::getFileId, fileId);
List<EdFileInfo> fileInfos =this.list(queryWrapper);
for (EdFileInfo file : fileInfos) {
String id = file.getId();
// 逻辑删除 文件收藏关系
fileFavoriteService.logicRemove(null, id);
// 逻辑删除 文件权限关系
rolePermissionService.logicRemove(null, id);
// 逻辑删除 文件关联关系
edFileRelationService.logicRemove(id);
}
// 逻辑删除 文件标签关系
fileTagRelationService.logicRemove(fileId, null);
}
}

View File

@ -2,9 +2,7 @@ package com.electromagnetic.industry.software.manage.service.serviceimpl;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.text.StrFormatter;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.electromagnetic.industry.software.common.enums.EffectFlagEnum;
@ -179,23 +177,6 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
return count > 0;
}
/**
* 逻辑删除文件关系
* @param fileId 文件主键id
* @return
*/
@Override
public boolean logicRemove (String fileId) {
Assert.notNull(fileId, "参数不能为空");
return this.update( new LambdaUpdateWrapper<EdFileRelation>()
.set(EdFileRelation::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
.and(wrapper -> wrapper
.eq(EdFileRelation::getId1, fileId)
.or()
.eq(EdFileRelation::getId2, fileId))
.eq(EdFileRelation::getEffectFlag, EffectFlagEnum.EFFECT.code));
}
private List<Edge> getEdges(String id) {
LambdaQueryWrapper<EdFileRelation> queryWrapper = new LambdaQueryWrapper<>();

View File

@ -5,13 +5,12 @@ import cn.hutool.core.text.StrFormatter;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.electromagnetic.industry.software.common.enums.EffectFlagEnum;
import com.electromagnetic.industry.software.common.enums.PublishEnum;
import com.electromagnetic.industry.software.common.enums.TagTypeEnum;
import com.electromagnetic.industry.software.common.exception.BizException;
import com.electromagnetic.industry.software.common.pojo.TreeNode;
import com.electromagnetic.industry.software.common.util.IdWorker;
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
import com.electromagnetic.industry.software.manage.mapper.EdTagLibraryMapper;
import com.electromagnetic.industry.software.manage.mapper.FileTagRelationMapper;
@ -20,7 +19,6 @@ 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.EdTagLibraryService;
import com.electromagnetic.industry.software.manage.service.FileTagRelationService;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
@ -33,8 +31,7 @@ import java.util.stream.Collectors;
public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdTagLibrary> implements EdTagLibraryService {
@Resource
FileTagRelationService fileTagRelationService;
FileTagRelationMapper fileTagRelationMapper;
/**
* 新建标签组
@ -48,13 +45,15 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
Assert.isTrue(!checkNameExist(tagName), StrFormatter.format("该标签组 {} 已存在", tagName));
// 查询当前最大排序值
int maxOrder = selectMaxOrder(TagTypeEnum.GROUP.getCode(), "0");
Integer maxOrder = selectMaxOrder(TagTypeEnum.GROUP.getCode(), "0");
EdTagLibrary tagGroup = new EdTagLibrary();
tagGroup.newInit();
tagGroup.setTagId(IdWorker.getSnowFlakeIdString());
tagGroup.setParentId("0"); // 标签组父节点为"0"
tagGroup.setType(TagTypeEnum.GROUP.getCode());
tagGroup.setTagName(tagName);
tagGroup.setOrderBy(maxOrder + 1); // 排在最后
tagGroup.setIsPublished(PublishEnum.UNPUBLISHED.getCode());
tagGroup.setCreatedBy(createdBy);
boolean isSuccess = this.save(tagGroup);
if (isSuccess) {
UserThreadLocal.setSuccessInfo("", tagGroup.getTagId(), StrFormatter.format("新建了标签组{}", tagName));
@ -73,9 +72,9 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
public Boolean createTag(String parentId, String tagName, String createdBy) {
Assert.isTrue(!checkNameExist(tagName), StrFormatter.format("该标签名 {} 已存在", tagName));
// 查询当前组内最大排序值
int maxOrder = selectMaxOrder(TagTypeEnum.TAG.getCode(), parentId);
Integer maxOrder = selectMaxOrder(TagTypeEnum.TAG.getCode(), parentId);
EdTagLibrary tag = new EdTagLibrary();
tag.newInit();
tag.setTagId(IdWorker.getSnowFlakeIdString());
tag.setParentId(parentId);
tag.setType(TagTypeEnum.TAG.getCode()); // 标签
tag.setTagName(tagName);
@ -88,7 +87,7 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
tag.setCreatedBy(createdBy);
boolean isSuccess = this.save(tag);
if (isSuccess) {
UserThreadLocal.setSuccessInfo("", tag.getTagId(), StrFormatter.format("新建了标签 {} ", tagName));
UserThreadLocal.setSuccessInfo("", tag.getTagId(), StrFormatter.format("新建了标签{}", tagName));
}
return isSuccess;
}
@ -188,46 +187,27 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
@Override
@Transactional
public Boolean deleteTagOrGroup(String tagId) {
EdTagLibrary tag = this.getOne(
Wrappers.lambdaQuery(EdTagLibrary.class)
.eq(EdTagLibrary::getTagId, tagId)
.eq(EdTagLibrary::getEffectFlag, EffectFlagEnum.EFFECT.code)
);
EdTagLibrary tag = this.getById(tagId);
Assert.notNull(tag, "标签不存在");
// 如果是标签组级联删除其下的所有标签
if (Objects.equals(tag.getType(), TagTypeEnum.GROUP.getCode())) {
// 逻辑删除子标签
this.update(
Wrappers.lambdaUpdate(EdTagLibrary.class)
.set(EdTagLibrary::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
.eq(EdTagLibrary::getParentId, tagId)
);
if (tag.getType() == 0) {
// 查询所有子标签
List<EdTagLibrary> tags = this.list(new LambdaQueryWrapper<EdTagLibrary>()
.eq(EdTagLibrary::getParentId, tagId));
// 逻辑删除子标签的关联关系
if (!tags.isEmpty()) {
for (EdTagLibrary childTag : tags) {
fileTagRelationService.logicRemove(null, childTag.getTagId());
}
}
// 删除所有子标签的关联关系
fileTagRelationMapper.delete(new LambdaQueryWrapper<FileTagRelation>().in(FileTagRelation::getTagId, tags.stream().map(EdTagLibrary::getTagId).collect(Collectors.toList())));
// 删除所有子标签
this.remove(new LambdaQueryWrapper<EdTagLibrary>().eq(EdTagLibrary::getParentId, tagId));
}
// 逻辑删除当前标签/
boolean mainDeleted = this.update(
Wrappers.lambdaUpdate(EdTagLibrary.class)
.set(EdTagLibrary::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
.eq(EdTagLibrary::getTagId, tagId)
);
// 逻辑删除本身的关联关系
fileTagRelationService.logicRemove(null, tagId);
if (mainDeleted) {
// 删除本身
boolean isDeleted = this.removeById(tagId);
// 删除本身的关联关系
fileTagRelationMapper.delete(new LambdaQueryWrapper<FileTagRelation>().eq(FileTagRelation::getTagId, tagId));
if (isDeleted) {
UserThreadLocal.setSuccessInfo("", tagId, StrFormatter.format("删除了标签 {} ", tag.getTagName()));
}
return mainDeleted;
return isDeleted;
}
/**
@ -241,13 +221,11 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
// 查询所有标签组
List<EdTagLibrary> groups = this.list(new LambdaQueryWrapper<EdTagLibrary>()
.eq(EdTagLibrary::getType, TagTypeEnum.GROUP.getCode())
.eq(EdTagLibrary::getEffectFlag, EffectFlagEnum.EFFECT.code)
.orderByAsc(EdTagLibrary::getOrderBy));
// 查询所有标签
List<EdTagLibrary> tags = this.list(new LambdaQueryWrapper<EdTagLibrary>()
.eq(EdTagLibrary::getType, TagTypeEnum.TAG.getCode())
.eq(EdTagLibrary::getEffectFlag, EffectFlagEnum.EFFECT.code)
.orderByAsc(EdTagLibrary::getOrderBy));
// 构造分组数据
@ -318,8 +296,7 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
public List<TreeNode> listTagTree() {
LambdaQueryWrapper<EdTagLibrary> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(EdTagLibrary::getIsPublished, PublishEnum.PUBLISHED.getCode())
.eq(EdTagLibrary::getEffectFlag, EffectFlagEnum.EFFECT.code);
queryWrapper.eq(EdTagLibrary::getIsPublished, PublishEnum.PUBLISHED.getCode());
List<EdTagLibrary> tags = this.list(queryWrapper);
Map<String, TreeNode> map = new HashMap<>();
List<TreeNode> list = new ArrayList<>();
@ -366,8 +343,7 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
public List<FileTagInfo> listAllTags() {
LambdaQueryWrapper<EdTagLibrary> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(EdTagLibrary::getIsPublished, PublishEnum.PUBLISHED.getCode())
.eq(EdTagLibrary::getType, TagTypeEnum.TAG.getCode())
.eq(EdTagLibrary::getEffectFlag, EffectFlagEnum.EFFECT.code);
.eq(EdTagLibrary::getType, TagTypeEnum.TAG.getCode());
return this.list(queryWrapper).stream()
.map(tag -> {
FileTagInfo info = new FileTagInfo();
@ -384,7 +360,7 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
*/
private boolean checkNameExist(String tagName) {
LambdaQueryWrapper<EdTagLibrary> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(EdTagLibrary::getTagName, tagName).eq(EdTagLibrary::getEffectFlag, EffectFlagEnum.EFFECT.code);
queryWrapper.eq(EdTagLibrary::getTagName, tagName);
return this.count(queryWrapper) > 0;
}
@ -395,19 +371,8 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
*/
private int selectMaxOrder(int typeCode, String parentId) {
// 查询当前最大排序值
// int maxOrder = Optional.ofNullable(this.getBaseMapper().selectMaxOrder(typeCode, parentId)).orElse(0);
return this.baseMapper.selectObjs(
Wrappers.lambdaQuery(EdTagLibrary.class)
.select(EdTagLibrary::getOrderBy)
.eq(EdTagLibrary::getType, typeCode)
.eq(EdTagLibrary::getParentId, parentId)
.eq(EdTagLibrary::getEffectFlag, EffectFlagEnum.EFFECT.code)
.orderByDesc(EdTagLibrary::getOrderBy)
.last("LIMIT 1") // 取最大值
).stream()
.findFirst()
.map(obj -> (Integer) obj)
.orElse(0); // 处理空值
int maxOrder = Optional.ofNullable(this.getBaseMapper().selectMaxOrder(typeCode, parentId)).orElse(0);
return maxOrder;
}
}

View File

@ -2,10 +2,7 @@ package com.electromagnetic.industry.software.manage.service.serviceimpl;
import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.electromagnetic.industry.software.common.enums.EffectFlagEnum;
import com.electromagnetic.industry.software.common.enums.PublishEnum;
import com.electromagnetic.industry.software.common.util.IdWorker;
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
@ -42,29 +39,20 @@ public class FileTagRelationServiceImpl extends ServiceImpl<FileTagRelationMappe
// 检查标签是否存在并且已发布
EdTagLibrary tag = edTagLibraryMapper.selectOne(new LambdaQueryWrapper<EdTagLibrary>()
.eq(EdTagLibrary::getTagId, tagId)
.eq(EdTagLibrary::getIsPublished, PublishEnum.PUBLISHED.getCode())
.eq(EdTagLibrary::getEffectFlag, EffectFlagEnum.EFFECT.code));
.eq(EdTagLibrary::getIsPublished, PublishEnum.PUBLISHED.getCode()));
Assert.notNull(tag, "标签不存在或未发布");
// 查询或创建关联关系
FileTagRelation relation = this.getOne(new LambdaQueryWrapper<FileTagRelation>()
// 创建文件与标签关系
FileTagRelation relation = new FileTagRelation();
relation.setId(IdWorker.getSnowFlakeIdString());
relation.setFileId(fileId);
relation.setTagId(tagId);
relation.setCreatedBy(createdBy);
return this.saveOrUpdate(relation, new LambdaQueryWrapper<FileTagRelation>()
.eq(FileTagRelation::getFileId, fileId)
.eq(FileTagRelation::getTagId, tagId));
boolean result;
if (relation == null) {
relation = new FileTagRelation();
relation.newInit();
relation.setFileId(fileId);
relation.setTagId(tagId);
result = this.save(relation);
} else {
// 恢复已删除的关联
relation.setEffectFlag(EffectFlagEnum.EFFECT.code);
relation.setUpdatedBy(createdBy);
result = this.updateById(relation);
}
return result;
}
/**
@ -78,8 +66,6 @@ public class FileTagRelationServiceImpl extends ServiceImpl<FileTagRelationMappe
@Override
@Transactional
public boolean addTagsToFile(String fileId, List<String> tagIds, String createdBy) {
Assert.notEmpty(tagIds, "标签列表不能为空");
boolean isSuccess = true;
for (String tagId : tagIds) {
isSuccess &= addTagToFile(fileId, tagId, createdBy);
@ -89,7 +75,6 @@ public class FileTagRelationServiceImpl extends ServiceImpl<FileTagRelationMappe
String tags = edTagLibraryMapper.selectList(new LambdaQueryWrapper<EdTagLibrary>()
.in(EdTagLibrary::getTagId, tagIds)
.select(EdTagLibrary::getTagName)
.eq(EdTagLibrary::getEffectFlag, EffectFlagEnum.EFFECT.code)
.eq(EdTagLibrary::getIsPublished, PublishEnum.PUBLISHED.getCode())).stream().map(EdTagLibrary::getTagName).collect(Collectors.joining(","));
EdFileInfo fileInfo = edFileInfoMapper.selectById(fileId);
@ -108,8 +93,7 @@ public class FileTagRelationServiceImpl extends ServiceImpl<FileTagRelationMappe
@Override
public List<FileTagInfo> getFileTags(String fileId) {
LambdaQueryWrapper<FileTagRelation> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(FileTagRelation::getFileId, fileId)
.eq(FileTagRelation::getEffectFlag, EffectFlagEnum.EFFECT.code);
queryWrapper.eq(FileTagRelation::getFileId, fileId);
List<FileTagRelation> relations = this.list(queryWrapper);
List<FileTagInfo> result = new ArrayList<>();
for (FileTagRelation relation : relations) {
@ -133,33 +117,11 @@ public class FileTagRelationServiceImpl extends ServiceImpl<FileTagRelationMappe
@Override
public List<String> getFileIdsByTagIds(List<String> tagIds) {
LambdaQueryWrapper<FileTagRelation> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(FileTagRelation::getTagId, tagIds)
.eq(FileTagRelation::getEffectFlag, EffectFlagEnum.EFFECT.code);
queryWrapper.in(FileTagRelation::getTagId, tagIds);
List<FileTagRelation> relations = this.list(queryWrapper);
return relations.stream()
.map(FileTagRelation::getFileId)
.distinct()
.toList();
}
/**
* 逻辑删除文件标签关系
*
* @param fileId
* @param tagId
* @return
*/
@Override
public boolean logicRemove(String fileId, String tagId) {
if (fileId == null && tagId == null) {
throw new IllegalArgumentException("必须提供至少一个参数");
}
return this.update(
new LambdaUpdateWrapper<FileTagRelation>()
.set(FileTagRelation::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
.eq(fileId != null, FileTagRelation::getFileId, fileId)
.eq(tagId != null, FileTagRelation::getTagId, tagId)
.eq(FileTagRelation::getEffectFlag, EffectFlagEnum.EFFECT.code)
);
}
}

View File

@ -9,7 +9,6 @@ import com.electromagnetic.industry.software.common.enums.EffectFlagEnum;
import com.electromagnetic.industry.software.manage.mapper.RolePermissionMapper;
import com.electromagnetic.industry.software.manage.pojo.models.EdFileInfo;
import com.electromagnetic.industry.software.manage.pojo.models.RolePermission;
import com.electromagnetic.industry.software.manage.pojo.models.UserRole;
import com.electromagnetic.industry.software.manage.pojo.req.PublishedFileDTO;
import com.electromagnetic.industry.software.manage.service.RolePermissionService;
import jakarta.annotation.Resource;
@ -157,29 +156,4 @@ public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper,
.collect(Collectors.toSet());
return !parentIdSet.contains(id);
}
/**
* 逻辑删除
*
* @param roleId
* @param fileId
* @return
*/
@Transactional
@Override
public boolean logicRemove (String roleId, String fileId) {
// 参数校验
if (roleId == null && fileId == null) {
throw new IllegalArgumentException("必须提供至少一个参数");
}
// 执行逻辑删除
return this.update(
new LambdaUpdateWrapper<RolePermission>()
.set(RolePermission::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
.eq(fileId != null, RolePermission::getFileId, fileId)
.eq(roleId != null, RolePermission::getRoleId, roleId)
.eq(RolePermission::getEffectFlag, EffectFlagEnum.EFFECT.code)
);
}
}

View File

@ -100,8 +100,10 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
.set(Role::getRoleName, roleDTO.getRoleName())
.set(Role::getRoleDesc, roleDTO.getRoleDesc());
this.update(updateWrapper);
// 失效角色关联的旧权限
rolePermissionService.logicRemove(roleDTO.getRoleId(), null);
disableRolePermission(roleDTO.getRoleId());
// 插入/激活新权限信息
List<RolePermissionDTO> data = roleDTO.getData();
List<RolePermission> list = flattenTree(data, roleDTO.getRoleId());
@ -121,18 +123,17 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
@Override
public Boolean deleteRole(String roleId) {
// 失效角色权限关联表
disableRolePermission(roleId);
// 失效用户角色关联表
disableUserRole(roleId);
// 失效角色
LambdaUpdateWrapper<Role> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(Role::getId, roleId)
.set(Role::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code);
boolean isUpdated =this.update(updateWrapper);
if (isUpdated) {
// 失效角色权限关联表
rolePermissionService.logicRemove(roleId, null);
// 失效用户角色关联表
userRoleService.logicRemove(null, roleId);
}
this.update(updateWrapper);
UserThreadLocal.setSuccessInfo("", roleId, "删除了角色");
return true;
@ -392,5 +393,25 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
return infos;
}
/**
* 失效角色权限关系
*/
private void disableRolePermission(String roleId) {
// 失效旧权限信息
LambdaQueryWrapper<RolePermission> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(RolePermission::getRoleId, roleId);
List<RolePermission> oldPermissions = rolePermissionService.list(queryWrapper);
rolePermissionService.disableOldPermissions(oldPermissions);
}
/**
* 失效角色用户关系
*/
private void disableUserRole(String roleId) {
LambdaUpdateWrapper<UserRole> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(UserRole::getRoleId, roleId)
.set(UserRole::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code);
userRoleService.update(updateWrapper);
}
}

View File

@ -1,40 +1,11 @@
package com.electromagnetic.industry.software.manage.service.serviceimpl;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.electromagnetic.industry.software.common.enums.EffectFlagEnum;
import com.electromagnetic.industry.software.manage.mapper.UserRoleMapper;
import com.electromagnetic.industry.software.manage.pojo.models.UserRole;
import com.electromagnetic.industry.software.manage.service.UserRoleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {
/**
* 逻辑删除用户-角色关联关系
* @param userId 用户ID可选
* @param roleId 角色ID可选
* @return 操作是否成功
* @throws IllegalArgumentException 参数校验失败时抛出
*/
@Transactional
@Override
public boolean logicRemove (String userId, String roleId) {
// 参数校验
if (userId == null && roleId == null) {
throw new IllegalArgumentException("必须提供至少一个参数");
}
// 执行逻辑删除
return this.update(
new LambdaUpdateWrapper<UserRole>()
.set(UserRole::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
.eq(userId != null, UserRole::getUserId, userId)
.eq(roleId != null, UserRole::getRoleId, roleId)
.eq(UserRole::getEffectFlag, EffectFlagEnum.EFFECT.code)
);
}
}

View File

@ -33,7 +33,6 @@ import com.electromagnetic.industry.software.manage.pojo.other.SingleUserRespons
import com.electromagnetic.industry.software.manage.pojo.req.*;
import com.electromagnetic.industry.software.manage.pojo.resp.UserLoginResponse;
import com.electromagnetic.industry.software.manage.pojo.resp.UserSearchResponse;
import com.electromagnetic.industry.software.manage.service.EdFileFavoriteService;
import com.electromagnetic.industry.software.manage.service.UserRoleService;
import com.electromagnetic.industry.software.manage.service.UserService;
import io.jsonwebtoken.Jwts;
@ -59,8 +58,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
private UserRoleService userRoleService;
@Resource
private RoleMapper roleMapper;
@Resource
private EdFileFavoriteService edFileFavoriteService;
/**
* 用户登录
@ -275,11 +272,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
.eq(User::getId, userId)
.set(User::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code));
// 2. 级联失效用户角色关系
if (success) {
// 级联失效用户角色关系
userRoleService.logicRemove(userId, null);
// 级联失效用户文件收藏关系
edFileFavoriteService.logicRemove(userId, null);
userRoleService.update(new LambdaUpdateWrapper<UserRole>()
.eq(UserRole::getUserId, userId)
.set(UserRole::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code));
}
UserThreadLocal.setSuccessInfo("", "", StrFormatter.format("删除了用户 {} ", user.getUserName()));