代码优化
This commit is contained in:
parent
fe656f9beb
commit
43001fca86
|
|
@ -38,4 +38,11 @@ public interface EdFileRelationService extends IService<EdFileRelation> {
|
||||||
*/
|
*/
|
||||||
Boolean checkNameExist(CheckNameUniqueRequest checkNameUniqueRequest);
|
Boolean checkNameExist(CheckNameUniqueRequest checkNameUniqueRequest);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 逻辑删除文件关系
|
||||||
|
* @param fileId 文件主键id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
boolean logicRemove (String fileId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,4 +34,13 @@ public interface FileTagRelationService extends IService<FileTagRelation> {
|
||||||
*/
|
*/
|
||||||
List<String> getFileIdsByTagIds(List<String> tagIds);
|
List<String> getFileIdsByTagIds(List<String> tagIds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 逻辑删除文件标签关系
|
||||||
|
*
|
||||||
|
* @param fileId
|
||||||
|
* @param tagId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
boolean logicRemove(String fileId, String tagId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
package com.electromagnetic.industry.software.manage.service;
|
package com.electromagnetic.industry.software.manage.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
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.EdFileInfo;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.RolePermission;
|
import com.electromagnetic.industry.software.manage.pojo.models.RolePermission;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.req.PublishedFileDTO;
|
import com.electromagnetic.industry.software.manage.pojo.req.PublishedFileDTO;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -41,4 +44,14 @@ public interface RolePermissionService extends IService<RolePermission> {
|
||||||
* @param prjId
|
* @param prjId
|
||||||
*/
|
*/
|
||||||
void syncPermissionsAfterTreeUpdate(List<EdFileInfo> files, String prjId);
|
void syncPermissionsAfterTreeUpdate(List<EdFileInfo> files, String prjId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 逻辑删除
|
||||||
|
*
|
||||||
|
* @param roleId
|
||||||
|
* @param fileId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
boolean logicRemove (String roleId, String fileId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,17 @@ package com.electromagnetic.industry.software.manage.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.UserRole;
|
import com.electromagnetic.industry.software.manage.pojo.models.UserRole;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
public interface UserRoleService extends IService<UserRole> {
|
public interface UserRoleService extends IService<UserRole> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 逻辑删除用户-角色关联关系
|
||||||
|
* @param userId 用户ID(可选)
|
||||||
|
* @param roleId 角色ID(可选)
|
||||||
|
* @return 操作是否成功
|
||||||
|
* @throws IllegalArgumentException 参数校验失败时抛出
|
||||||
|
*/
|
||||||
|
boolean logicRemove (String userId, String roleId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,14 @@ public class EdFileFavoriteServiceImpl extends ServiceImpl<EdFileFavoriteMapper,
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public boolean logicRemove(String userId, String fileId) {
|
public boolean logicRemove(String userId, String fileId) {
|
||||||
|
if (userId == null && fileId == null) {
|
||||||
|
throw new IllegalArgumentException("必须提供至少一个参数");
|
||||||
|
}
|
||||||
LambdaUpdateWrapper<EdFileFavorite> updateWrapper = Wrappers.lambdaUpdate(EdFileFavorite.class)
|
LambdaUpdateWrapper<EdFileFavorite> updateWrapper = Wrappers.lambdaUpdate(EdFileFavorite.class)
|
||||||
.eq(EdFileFavorite::getUserId, userId)
|
.set(EdFileFavorite::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
|
||||||
.eq(EdFileFavorite::getFileId, fileId)
|
.eq(userId != null, EdFileFavorite::getUserId, userId)
|
||||||
.set(EdFileFavorite::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code);
|
.eq(fileId != null, EdFileFavorite::getFileId, fileId)
|
||||||
|
.eq(EdFileFavorite::getEffectFlag, EffectFlagEnum.EFFECT.code);
|
||||||
return update(updateWrapper);
|
return update(updateWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ import com.electromagnetic.industry.software.manage.pojo.resp.UploadRecordVO;
|
||||||
import com.electromagnetic.industry.software.manage.service.*;
|
import com.electromagnetic.industry.software.manage.service.*;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.core.io.FileSystemResource;
|
import org.springframework.core.io.FileSystemResource;
|
||||||
import org.springframework.core.io.InputStreamResource;
|
import org.springframework.core.io.InputStreamResource;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
|
|
@ -83,6 +84,8 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
||||||
private UserAccessLogService userAccessLogService;
|
private UserAccessLogService userAccessLogService;
|
||||||
@Resource
|
@Resource
|
||||||
private EdFileRelationService edFileRelationService;
|
private EdFileRelationService edFileRelationService;
|
||||||
|
@Resource
|
||||||
|
private RolePermissionService rolePermissionService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询文件列表
|
* 查询文件列表
|
||||||
|
|
@ -256,6 +259,8 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
||||||
.set(EdFileInfo::getEffectFlag, false)
|
.set(EdFileInfo::getEffectFlag, false)
|
||||||
.set(EdFileInfo::getAllDeleted, true)
|
.set(EdFileInfo::getAllDeleted, true)
|
||||||
.eq(EdFileInfo::getFileId, fileInfo.getFileId()));
|
.eq(EdFileInfo::getFileId, fileInfo.getFileId()));
|
||||||
|
// 统一处理文件相关关系
|
||||||
|
cleanRelatedData(fileInfo.getFileId());
|
||||||
UserThreadLocal.setSuccessInfo(fileInfo.getParentId(), id, "作废文件 {}.{} 成功,路径为 {}", fileInfo.getFileName(), fileInfo.getFileType(), dbPath);
|
UserThreadLocal.setSuccessInfo(fileInfo.getParentId(), id, "作废文件 {}.{} 成功,路径为 {}", fileInfo.getFileName(), fileInfo.getFileType(), dbPath);
|
||||||
return ElectromagneticResultUtil.success(true);
|
return ElectromagneticResultUtil.success(true);
|
||||||
}
|
}
|
||||||
|
|
@ -1498,4 +1503,27 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
||||||
UserThreadLocal.setSuccessInfo("", id, StrFormatter.format("建立了文件 {} 与文件 {} 的关系", id, relatedFileId));
|
UserThreadLocal.setSuccessInfo("", id, StrFormatter.format("建立了文件 {} 与文件 {} 的关系", id, relatedFileId));
|
||||||
return ElectromagneticResultUtil.success(true);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@ package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
||||||
|
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.core.text.StrFormatter;
|
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.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.electromagnetic.industry.software.common.enums.EffectFlagEnum;
|
import com.electromagnetic.industry.software.common.enums.EffectFlagEnum;
|
||||||
|
|
@ -177,6 +179,23 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
||||||
return count > 0;
|
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) {
|
private List<Edge> getEdges(String id) {
|
||||||
|
|
||||||
LambdaQueryWrapper<EdFileRelation> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<EdFileRelation> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,8 @@ import java.util.stream.Collectors;
|
||||||
public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdTagLibrary> implements EdTagLibraryService {
|
public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdTagLibrary> implements EdTagLibraryService {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
FileTagRelationMapper fileTagRelationMapper;
|
FileTagRelationService fileTagRelationService;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新建标签组
|
* 新建标签组
|
||||||
|
|
@ -208,11 +209,9 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
||||||
.eq(EdTagLibrary::getParentId, tagId));
|
.eq(EdTagLibrary::getParentId, tagId));
|
||||||
// 逻辑删除子标签的关联关系
|
// 逻辑删除子标签的关联关系
|
||||||
if (!tags.isEmpty()) {
|
if (!tags.isEmpty()) {
|
||||||
fileTagRelationMapper.update(
|
for (EdTagLibrary childTag : tags) {
|
||||||
Wrappers.lambdaUpdate(FileTagRelation.class)
|
fileTagRelationService.logicRemove(null, childTag.getTagId());
|
||||||
.set(FileTagRelation::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
|
}
|
||||||
.in(FileTagRelation::getTagId, tags.stream().map(EdTagLibrary::getTagId).collect(Collectors.toList()))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -223,11 +222,8 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
||||||
.eq(EdTagLibrary::getTagId, tagId)
|
.eq(EdTagLibrary::getTagId, tagId)
|
||||||
);
|
);
|
||||||
// 逻辑删除本身的关联关系
|
// 逻辑删除本身的关联关系
|
||||||
fileTagRelationMapper.update(
|
fileTagRelationService.logicRemove(null, tagId);
|
||||||
Wrappers.lambdaUpdate(FileTagRelation.class)
|
|
||||||
.set(FileTagRelation::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
|
|
||||||
.eq(FileTagRelation::getTagId, tagId)
|
|
||||||
);
|
|
||||||
if (mainDeleted) {
|
if (mainDeleted) {
|
||||||
UserThreadLocal.setSuccessInfo("", tagId, StrFormatter.format("删除了标签 {} ", tag.getTagName()));
|
UserThreadLocal.setSuccessInfo("", tagId, StrFormatter.format("删除了标签 {} ", tag.getTagName()));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -142,4 +142,24 @@ public class FileTagRelationServiceImpl extends ServiceImpl<FileTagRelationMappe
|
||||||
.toList();
|
.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)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -9,6 +9,7 @@ import com.electromagnetic.industry.software.common.enums.EffectFlagEnum;
|
||||||
import com.electromagnetic.industry.software.manage.mapper.RolePermissionMapper;
|
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.EdFileInfo;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.RolePermission;
|
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.pojo.req.PublishedFileDTO;
|
||||||
import com.electromagnetic.industry.software.manage.service.RolePermissionService;
|
import com.electromagnetic.industry.software.manage.service.RolePermissionService;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
|
@ -156,4 +157,29 @@ public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper,
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
return !parentIdSet.contains(id);
|
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)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,10 +100,8 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
||||||
.set(Role::getRoleName, roleDTO.getRoleName())
|
.set(Role::getRoleName, roleDTO.getRoleName())
|
||||||
.set(Role::getRoleDesc, roleDTO.getRoleDesc());
|
.set(Role::getRoleDesc, roleDTO.getRoleDesc());
|
||||||
this.update(updateWrapper);
|
this.update(updateWrapper);
|
||||||
|
|
||||||
// 失效角色关联的旧权限
|
// 失效角色关联的旧权限
|
||||||
disableRolePermission(roleDTO.getRoleId());
|
rolePermissionService.logicRemove(roleDTO.getRoleId(), null);
|
||||||
|
|
||||||
// 插入/激活新权限信息
|
// 插入/激活新权限信息
|
||||||
List<RolePermissionDTO> data = roleDTO.getData();
|
List<RolePermissionDTO> data = roleDTO.getData();
|
||||||
List<RolePermission> list = flattenTree(data, roleDTO.getRoleId());
|
List<RolePermission> list = flattenTree(data, roleDTO.getRoleId());
|
||||||
|
|
@ -123,17 +121,18 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
||||||
@Override
|
@Override
|
||||||
public Boolean deleteRole(String roleId) {
|
public Boolean deleteRole(String roleId) {
|
||||||
|
|
||||||
// 失效角色权限关联表
|
|
||||||
disableRolePermission(roleId);
|
|
||||||
|
|
||||||
// 失效用户角色关联表
|
|
||||||
disableUserRole(roleId);
|
|
||||||
|
|
||||||
// 失效角色
|
// 失效角色
|
||||||
LambdaUpdateWrapper<Role> updateWrapper = new LambdaUpdateWrapper<>();
|
LambdaUpdateWrapper<Role> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
updateWrapper.eq(Role::getId, roleId)
|
updateWrapper.eq(Role::getId, roleId)
|
||||||
.set(Role::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code);
|
.set(Role::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code);
|
||||||
this.update(updateWrapper);
|
boolean isUpdated =this.update(updateWrapper);
|
||||||
|
|
||||||
|
if (isUpdated) {
|
||||||
|
// 失效角色权限关联表
|
||||||
|
rolePermissionService.logicRemove(roleId, null);
|
||||||
|
// 失效用户角色关联表
|
||||||
|
userRoleService.logicRemove(null, roleId);
|
||||||
|
}
|
||||||
|
|
||||||
UserThreadLocal.setSuccessInfo("", roleId, "删除了角色");
|
UserThreadLocal.setSuccessInfo("", roleId, "删除了角色");
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -393,25 +392,5 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
||||||
return infos;
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,40 @@
|
||||||
package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
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.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.mapper.UserRoleMapper;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.UserRole;
|
import com.electromagnetic.industry.software.manage.pojo.models.UserRole;
|
||||||
import com.electromagnetic.industry.software.manage.service.UserRoleService;
|
import com.electromagnetic.industry.software.manage.service.UserRoleService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {
|
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)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ import com.electromagnetic.industry.software.manage.pojo.other.SingleUserRespons
|
||||||
import com.electromagnetic.industry.software.manage.pojo.req.*;
|
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.UserLoginResponse;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.resp.UserSearchResponse;
|
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.UserRoleService;
|
||||||
import com.electromagnetic.industry.software.manage.service.UserService;
|
import com.electromagnetic.industry.software.manage.service.UserService;
|
||||||
import io.jsonwebtoken.Jwts;
|
import io.jsonwebtoken.Jwts;
|
||||||
|
|
@ -58,6 +59,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||||
private UserRoleService userRoleService;
|
private UserRoleService userRoleService;
|
||||||
@Resource
|
@Resource
|
||||||
private RoleMapper roleMapper;
|
private RoleMapper roleMapper;
|
||||||
|
@Resource
|
||||||
|
private EdFileFavoriteService edFileFavoriteService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户登录
|
* 用户登录
|
||||||
|
|
@ -272,11 +275,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||||
.eq(User::getId, userId)
|
.eq(User::getId, userId)
|
||||||
.set(User::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code));
|
.set(User::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code));
|
||||||
|
|
||||||
// 2. 级联失效用户角色关系
|
|
||||||
if (success) {
|
if (success) {
|
||||||
userRoleService.update(new LambdaUpdateWrapper<UserRole>()
|
// 级联失效用户角色关系
|
||||||
.eq(UserRole::getUserId, userId)
|
userRoleService.logicRemove(userId, null);
|
||||||
.set(UserRole::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code));
|
// 级联失效用户文件收藏关系
|
||||||
|
edFileFavoriteService.logicRemove(userId, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
UserThreadLocal.setSuccessInfo("", "", StrFormatter.format("删除了用户 {} ", user.getUserName()));
|
UserThreadLocal.setSuccessInfo("", "", StrFormatter.format("删除了用户 {} ", user.getUserName()));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue