Compare commits
2 Commits
e685dbff5b
...
38fcdcb859
| Author | SHA1 | Date |
|---|---|---|
|
|
38fcdcb859 | |
|
|
cbec04ba89 |
|
|
@ -7,6 +7,7 @@ import com.electromagnetic.industry.software.common.enums.UserOperationModuleEnu
|
|||
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||
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.models.EdFileRelation;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.CheckNameUniqueRequest;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.UpdateRelationDTO;
|
||||
|
|
@ -32,12 +33,7 @@ public class EdFileRelationController {
|
|||
@RequestMapping(value = "/create", method = RequestMethod.POST)
|
||||
@UserOperation(value="创建了文件关系", modelName = UserOperationModuleEnum.DATABASE)
|
||||
public ElectromagneticResult<?> createRelation(@RequestBody EdFileRelation relation) {
|
||||
try {
|
||||
Boolean res = edFileRelationService.createRelation(relation);
|
||||
return ElectromagneticResultUtil.success(res);
|
||||
} catch (BizException e) {
|
||||
return ElectromagneticResultUtil.fail("500", e.getMessage());
|
||||
}
|
||||
return ElectromagneticResultUtil.success(edFileRelationService.createRelation(relation));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -51,7 +47,11 @@ public class EdFileRelationController {
|
|||
public ElectromagneticResult<?> updateRelation(@RequestBody UpdateRelationDTO updateRelation) {
|
||||
LambdaUpdateWrapper<EdFileRelation> wrapper = new LambdaUpdateWrapper<>();
|
||||
wrapper.eq(EdFileRelation::getId, updateRelation.getRelationId()).set(EdFileRelation::getRelationship, updateRelation.getRelationship());
|
||||
return ElectromagneticResultUtil.success(edFileRelationService.update(wrapper));
|
||||
boolean isUpdated = edFileRelationService.update(wrapper);
|
||||
if (isUpdated) {
|
||||
UserThreadLocal.setSuccessInfo("", updateRelation.getRelationId(), "更新了文件关系");
|
||||
}
|
||||
return ElectromagneticResultUtil.success(isUpdated);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4,13 +4,11 @@ import com.electromagnetic.industry.software.common.annotations.RequiredRole;
|
|||
import com.electromagnetic.industry.software.common.annotations.UserOperation;
|
||||
import com.electromagnetic.industry.software.common.enums.AdminTypeEnum;
|
||||
import com.electromagnetic.industry.software.common.enums.UserOperationModuleEnum;
|
||||
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.RoleDTO;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.RolePageDTO;
|
||||
import com.electromagnetic.industry.software.manage.service.RoleService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
|
@ -26,24 +24,14 @@ public class RoleController {
|
|||
@UserOperation(value="新建了角色", modelName = UserOperationModuleEnum.PERMISSION)
|
||||
@RequestMapping(value = "/createRole", method = RequestMethod.POST)
|
||||
public ElectromagneticResult<?> createRole(@RequestBody RoleDTO roleDTO) {
|
||||
try {
|
||||
Boolean res = roleService.createRole(roleDTO);
|
||||
return ElectromagneticResultUtil.success(res);
|
||||
} catch (BizException e) {
|
||||
return ElectromagneticResultUtil.fail("400", e.getMessage());
|
||||
}
|
||||
return ElectromagneticResultUtil.success(roleService.createRole(roleDTO));
|
||||
}
|
||||
|
||||
@RequiredRole(AdminTypeEnum.SECURITY)
|
||||
@UserOperation(value="更新了角色", modelName = UserOperationModuleEnum.PERMISSION)
|
||||
@RequestMapping(value = "/updateRole", method = RequestMethod.POST)
|
||||
public ElectromagneticResult<?> updateRole(@RequestBody RoleDTO roleDTO) {
|
||||
try {
|
||||
Boolean res = roleService.updateRole(roleDTO);
|
||||
return ElectromagneticResultUtil.success(res);
|
||||
} catch (BizException e) {
|
||||
return ElectromagneticResultUtil.fail("400", e.getMessage());
|
||||
}
|
||||
return ElectromagneticResultUtil.success(roleService.updateRole(roleDTO));
|
||||
}
|
||||
|
||||
@RequiredRole(AdminTypeEnum.SECURITY)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
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;
|
||||
|
|
@ -7,6 +8,7 @@ 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.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;
|
||||
|
|
@ -26,6 +28,7 @@ public class EdFileFavoriteServiceImpl extends ServiceImpl<EdFileFavoriteMapper,
|
|||
|
||||
@Override
|
||||
public boolean addFavorite(String userId, String fileId) {
|
||||
|
||||
// 查询是否已存在
|
||||
LambdaQueryWrapper<EdFileFavorite> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(EdFileFavorite::getUserId, userId)
|
||||
|
|
@ -38,7 +41,11 @@ public class EdFileFavoriteServiceImpl extends ServiceImpl<EdFileFavoriteMapper,
|
|||
EdFileFavorite favorite = new EdFileFavorite();
|
||||
favorite.setUserId(userId);
|
||||
favorite.setFileId(fileId);
|
||||
return this.save(favorite);
|
||||
boolean isSaved = this.save(favorite);
|
||||
if (isSaved) {
|
||||
UserThreadLocal.setSuccessInfo("", fileId, StrFormatter.format("收藏了文件"));
|
||||
}
|
||||
return isSaved;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -46,7 +53,11 @@ public class EdFileFavoriteServiceImpl extends ServiceImpl<EdFileFavoriteMapper,
|
|||
LambdaQueryWrapper<EdFileFavorite> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(EdFileFavorite::getUserId, userId)
|
||||
.eq(EdFileFavorite::getFileId, fileId);
|
||||
return this.remove(queryWrapper);
|
||||
boolean isRemoved = this.remove(queryWrapper);
|
||||
if (isRemoved) {
|
||||
UserThreadLocal.setSuccessInfo("", fileId, StrFormatter.format("取消了收藏"));
|
||||
}
|
||||
return isRemoved;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -66,10 +77,9 @@ public class EdFileFavoriteServiceImpl extends ServiceImpl<EdFileFavoriteMapper,
|
|||
|
||||
// 创建分页对象
|
||||
Page<FileInfoVO> page = new Page<>(fileInfoQueryDTO.getPageNum(), fileInfoQueryDTO.getPageSize());
|
||||
|
||||
IPage<FileInfoVO> fileInfoVOIPage = fileInfoService.queryFileList(page, fileIds, fileInfoQueryDTO, EleDataSaveStatusEnum.SUCCESS.code, EffectFlagEnum.EFFECT.code);
|
||||
|
||||
fileInfoService.resetFileSize(fileInfoVOIPage.getRecords());
|
||||
UserThreadLocal.setSuccessInfo("", "", "查询了收藏列表");
|
||||
return fileInfoVOIPage;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
|||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.text.StrFormatter;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
|
|
@ -44,10 +45,6 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
|||
EdFileInfoServiceImpl edFileInfoService;
|
||||
@Resource
|
||||
private CommonService commonService;
|
||||
@Resource
|
||||
private FileSystemService fileSystemService;
|
||||
@Autowired
|
||||
private EdFileInfoServiceImpl edFileInfoServiceImpl;
|
||||
|
||||
/**
|
||||
* 创建文件关系
|
||||
|
|
@ -71,7 +68,11 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
|||
|
||||
edFileRelation.setId(IdWorker.getSnowFlakeIdString());
|
||||
edFileRelation.setCreatedBy(UserThreadLocal.getUserId());
|
||||
return this.save(edFileRelation);
|
||||
boolean isSaved = this.save(edFileRelation);
|
||||
if (isSaved) {
|
||||
UserThreadLocal.setSuccessInfo("", edFileRelation.getId(), StrFormatter.format("关联了文件"));
|
||||
}
|
||||
return isSaved;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -82,7 +83,12 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
|||
*/
|
||||
@Override
|
||||
public Boolean cancelRelation(String id) {
|
||||
return this.removeById(id);
|
||||
|
||||
boolean isRemoved = this.removeById(id);
|
||||
if (isRemoved) {
|
||||
UserThreadLocal.setSuccessInfo("", id, StrFormatter.format("取消了文件关联"));
|
||||
}
|
||||
return isRemoved;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -131,6 +137,7 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
|||
nodes.add(fileSimpleInfoVO);
|
||||
}
|
||||
fileRelationViewVO.setNodes(nodes);
|
||||
UserThreadLocal.setSuccessInfo("", startId, StrFormatter.format("查询了文件{}的关联关系",startId));
|
||||
return fileRelationViewVO;
|
||||
}
|
||||
|
||||
|
|
@ -263,6 +270,7 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
|||
log.error(info, e);
|
||||
throw new BizException(info);
|
||||
}
|
||||
UserThreadLocal.setSuccessInfo("", "", "上传了文件并建立了文件关系");
|
||||
return ElectromagneticResultUtil.success(true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,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.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
|
|
@ -8,6 +10,7 @@ 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.util.IdWorker;
|
||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||
import com.electromagnetic.industry.software.manage.mapper.EdTagLibraryMapper;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.EdTagLibrary;
|
||||
import com.electromagnetic.industry.software.manage.pojo.resp.TagListVO;
|
||||
|
|
@ -46,7 +49,11 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
|||
tagGroup.setOrderBy(maxOrder+1); // 排在最后
|
||||
tagGroup.setIsPublished(PublishEnum.UNPUBLISHED.getCode());
|
||||
tagGroup.setCreatedBy(createdBy);
|
||||
return this.save(tagGroup);
|
||||
boolean isSuccess = this.save(tagGroup);
|
||||
if (isSuccess) {
|
||||
UserThreadLocal.setSuccessInfo("", tagGroup.getTagId(), StrFormatter.format("新建了标签组{}", tagName));
|
||||
}
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -73,7 +80,11 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
|||
tag.setOrderBy(maxOrder+1); // 默认排序
|
||||
tag.setIsPublished(PublishEnum.UNPUBLISHED.getCode()); // 默认未发布
|
||||
tag.setCreatedBy(createdBy);
|
||||
return this.save(tag);
|
||||
boolean isSuccess =this.save(tag);
|
||||
if (isSuccess) {
|
||||
UserThreadLocal.setSuccessInfo("", tag.getTagId(), StrFormatter.format("新建了标签{}", tagName));
|
||||
}
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -85,6 +96,7 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
|||
@Transactional
|
||||
public Boolean updateTagOrder(String tagId, String newParentId, Integer newOrderBy, String updatedBy) {
|
||||
|
||||
|
||||
if (StringUtils.isEmpty(newParentId) || newOrderBy == null) {
|
||||
throw new IllegalArgumentException("缺少参数");
|
||||
}
|
||||
|
|
@ -93,9 +105,7 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
|||
EdTagLibrary tag = this.getOne(new LambdaQueryWrapper<EdTagLibrary>()
|
||||
.eq(EdTagLibrary::getTagId, tagId));
|
||||
|
||||
if (tag == null) {
|
||||
throw new IllegalArgumentException("标签不存在");
|
||||
}
|
||||
Assert.notNull(tag,"标签不存在");
|
||||
|
||||
String oldParentId = tag.getParentId();
|
||||
Integer oldOrderBy = tag.getOrderBy();
|
||||
|
|
@ -116,11 +126,15 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
|||
}
|
||||
|
||||
// 更新当前标签的新排序值
|
||||
return this.update(new LambdaUpdateWrapper<EdTagLibrary>()
|
||||
boolean isUpdated = this.update(new LambdaUpdateWrapper<EdTagLibrary>()
|
||||
.eq(EdTagLibrary::getTagId, tagId)
|
||||
.set(EdTagLibrary::getParentId, newParentId)
|
||||
.set(EdTagLibrary::getOrderBy, newOrderBy)
|
||||
.set(EdTagLibrary::getUpdatedBy, updatedBy));
|
||||
if (isUpdated) {
|
||||
UserThreadLocal.setSuccessInfo("", tagId, StrFormatter.format("更新了标签{}的排序", tag.getTagName()));
|
||||
}
|
||||
return isUpdated;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -131,10 +145,7 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
|||
@Transactional
|
||||
public Boolean batchPublishTagGroups(List<String> tagGroupIds) {
|
||||
|
||||
if (tagGroupIds == null || tagGroupIds.isEmpty()) {
|
||||
throw new IllegalArgumentException("参数 tagGroupIds 不能为空");
|
||||
}
|
||||
|
||||
Assert.notEmpty(tagGroupIds, "参数 tagGroupIds 不能为空");
|
||||
boolean groupUpdated = this.update(new LambdaUpdateWrapper<EdTagLibrary>()
|
||||
.in(EdTagLibrary::getTagId, tagGroupIds)
|
||||
.eq(EdTagLibrary::getType, TagTypeEnum.GROUP.getCode()) // 只更新标签组
|
||||
|
|
@ -153,6 +164,7 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
|||
throw new RuntimeException("发布标签失败");
|
||||
}
|
||||
|
||||
UserThreadLocal.setSuccessInfo("", "", "发布了标签");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -165,18 +177,17 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
|||
@Transactional
|
||||
public Boolean deleteTagOrGroup(String tagId) {
|
||||
EdTagLibrary tag = this.getById(tagId);
|
||||
|
||||
if (tag == null) {
|
||||
throw new BizException("此标签已被删除");
|
||||
}
|
||||
|
||||
Assert.notNull(tag, "标签不存在");
|
||||
// 如果是标签组,级联删除其下的所有标签
|
||||
if (tag.getType() == 0) {
|
||||
this.remove(new LambdaQueryWrapper<EdTagLibrary>().eq(EdTagLibrary::getParentId, tagId));
|
||||
}
|
||||
|
||||
// 删除本身
|
||||
return this.removeById(tagId);
|
||||
boolean isDeleted = this.removeById(tagId);
|
||||
if (isDeleted) {
|
||||
UserThreadLocal.setSuccessInfo("", tagId, StrFormatter.format("删除了标签{}", tag.getTagName()));
|
||||
}
|
||||
return isDeleted;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -207,6 +218,7 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
|||
vo.setChildList(tagsGrouped.getOrDefault(group.getTagId(), new ArrayList<>()));
|
||||
result.add(vo);
|
||||
}
|
||||
UserThreadLocal.setSuccessInfo("", "", "获取了标签数据");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -223,7 +235,11 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
|||
updateWrapper.eq(EdTagLibrary::getTagId, tagId)
|
||||
.set(EdTagLibrary::getTagName, tagName)
|
||||
.set(EdTagLibrary::getUpdatedBy, updatedBy);
|
||||
return this.update(updateWrapper);
|
||||
boolean isUpdated = this.update(updateWrapper);
|
||||
if (isUpdated) {
|
||||
UserThreadLocal.setSuccessInfo("", tagId, StrFormatter.format("更新了标签{}信息", tagName));
|
||||
}
|
||||
return isUpdated;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
||||
|
||||
import cn.hutool.core.text.StrFormatter;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.electromagnetic.industry.software.common.enums.*;
|
||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,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.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
|
|
@ -9,7 +11,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.electromagnetic.industry.software.common.enums.*;
|
||||
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||
import com.electromagnetic.industry.software.common.util.EleLog;
|
||||
import com.electromagnetic.industry.software.common.util.IdWorker;
|
||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||
|
|
@ -40,15 +41,16 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||
|
||||
@Resource
|
||||
private RolePermissionService rolePermissionService;
|
||||
|
||||
@Resource
|
||||
private UserRoleService userRoleService;
|
||||
|
||||
@Resource
|
||||
private PermissionService permissionService;
|
||||
|
||||
private EleLog log = new EleLog(RoleServiceImpl.class);
|
||||
@Resource
|
||||
private RoleMapper roleMapper;
|
||||
|
||||
@Resource
|
||||
private EdFileInfoMapper edFileInfoMapper;
|
||||
|
||||
|
|
@ -62,11 +64,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||
@Override
|
||||
public Boolean createRole(RoleDTO roleDTO) {
|
||||
|
||||
if (!checkRoleNameUnique(roleDTO)) {
|
||||
String info = "当前角色名称已存在:" + roleDTO.getRoleName();
|
||||
log.error(info);
|
||||
throw new BizException(info);
|
||||
}
|
||||
Assert.isTrue(checkRoleNameUnique(roleDTO),StrFormatter.format("角色名称 {} 已存在" , roleDTO.getRoleName()));
|
||||
|
||||
// 创建角色
|
||||
Role role = new Role();
|
||||
|
|
@ -84,6 +82,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||
List<RolePermissionDTO> data = roleDTO.getData();
|
||||
List<RolePermission> list = flattenTree(data, roleId);
|
||||
rolePermissionService.saveBatch(list);
|
||||
UserThreadLocal.setSuccessInfo("", roleId, "创建了角色");
|
||||
return true;
|
||||
|
||||
}
|
||||
|
|
@ -98,11 +97,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||
@Override
|
||||
public Boolean updateRole(RoleDTO roleDTO) {
|
||||
|
||||
if (!checkRoleNameUnique(roleDTO)) {
|
||||
String info = "当前角色名称已存在:" + roleDTO.getRoleName();
|
||||
log.error(info);
|
||||
throw new BizException(info);
|
||||
}
|
||||
Assert.isTrue(checkRoleNameUnique(roleDTO),StrFormatter.format("角色名称 {} 已存在" , roleDTO.getRoleName()));
|
||||
|
||||
// 更新角色信息
|
||||
LambdaUpdateWrapper<Role> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
|
|
@ -123,6 +118,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||
List<RolePermission> list = flattenTree(data, roleDTO.getRoleId());
|
||||
rolePermissionService.saveBatch(list);
|
||||
|
||||
UserThreadLocal.setSuccessInfo("", roleDTO.getRoleId(), "更新了角色");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -149,6 +145,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||
// 删除角色
|
||||
LambdaQueryWrapper<Role> queryWrapper2 = new LambdaQueryWrapper<>();
|
||||
queryWrapper2.eq(Role::getRoleId, roleId);
|
||||
UserThreadLocal.setSuccessInfo("", roleId, "删除了角色");
|
||||
return this.remove(queryWrapper2);
|
||||
}
|
||||
|
||||
|
|
@ -193,7 +190,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||
}
|
||||
|
||||
roleDTO.setData(buildTree(nodes));
|
||||
|
||||
UserThreadLocal.setSuccessInfo("",roleId,"查询了角色详情");
|
||||
return roleDTO;
|
||||
}
|
||||
|
||||
|
|
@ -209,6 +206,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||
LambdaQueryWrapper<Role> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(Role::getRoleName, roleName);
|
||||
Role role = this.getOne(queryWrapper);
|
||||
UserThreadLocal.setSuccessInfo("", role.getRoleId(), "查询了角色详情");
|
||||
return getRole(role.getRoleId());
|
||||
}
|
||||
|
||||
|
|
@ -239,6 +237,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||
roleDTO.setAllowedActions(chineseString);
|
||||
}
|
||||
}
|
||||
UserThreadLocal.setSuccessInfo("","", "查询了角色列表");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -290,9 +289,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||
rolePermissionDTO.setPermission(permissionService.transToMap(permissionCodes,false));
|
||||
nodes.add(rolePermissionDTO);
|
||||
}
|
||||
|
||||
roleDTO.setData(buildTree(nodes));
|
||||
|
||||
return roleDTO;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
|||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.SystemClock;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.text.StrFormatter;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
|
|
@ -70,6 +72,7 @@ public class UserServiceImpl implements UserService {
|
|||
UserLoginResponse userLoginResponse = new UserLoginResponse();
|
||||
userLoginResponse.setToken(tokenStr);
|
||||
userLoginResponse.setUserId(user.getUserId());
|
||||
UserThreadLocal.setSuccessInfo("", user.getUserId(), StrFormatter.format("用户{}登陆", user.getUserName()));
|
||||
return ElectromagneticResultUtil.success(userLoginResponse);
|
||||
}
|
||||
return ElectromagneticResultUtil.fail("500", "用户不存在/密码错误");
|
||||
|
|
@ -134,6 +137,7 @@ public class UserServiceImpl implements UserService {
|
|||
|
||||
user.setCreator(UserThreadLocal.getUserId());
|
||||
user.setCreatorName(UserThreadLocal.getUsername());
|
||||
UserThreadLocal.setSuccessInfo("", user.getUserId(), StrFormatter.format("新增了用户{}", user.getUserName()));
|
||||
return ElectromagneticResultUtil.success(userMapper.insert(user) > 0);
|
||||
}
|
||||
|
||||
|
|
@ -148,6 +152,7 @@ public class UserServiceImpl implements UserService {
|
|||
User user = UserMappers.INSTANCE.getUserModiRequestToModel(userModiRequest);
|
||||
user.setModifier(UserThreadLocal.getUserId());
|
||||
user.setModifierName(UserThreadLocal.getUsername());
|
||||
UserThreadLocal.setSuccessInfo("", userModiRequest.getUserId(), StrFormatter.format("更新了用户{}", user.getUserName()));
|
||||
return ElectromagneticResultUtil.success(userMapper.modify(user) > 0);
|
||||
}
|
||||
|
||||
|
|
@ -162,6 +167,7 @@ public class UserServiceImpl implements UserService {
|
|||
PublishParam model = UserMappers.INSTANCE.getUserPublishRequestToModel(userPublishRequest);
|
||||
model.setModifier(UserThreadLocal.getUserId());
|
||||
model.setModifierName(UserThreadLocal.getUsername());
|
||||
UserThreadLocal.setSuccessInfo("","",StrFormatter.format("批量发布了用户"));
|
||||
return ElectromagneticResultUtil.success(userMapper.publish(model) > 0);
|
||||
}
|
||||
|
||||
|
|
@ -206,6 +212,7 @@ public class UserServiceImpl implements UserService {
|
|||
public ElectromagneticResult<?> getSingleUser(GetSingleUserRequest getSingleUserRequest) {
|
||||
User user = userMapper.getSingleUser(getSingleUserRequest.getUserId());
|
||||
SingleUserResponse singleUserResponse = UserMappers.INSTANCE.getSingleUserToResponse(user);
|
||||
UserThreadLocal.setSuccessInfo("", getSingleUserRequest.getUserId(), StrFormatter.format("查询了用户{}详情信息", singleUserResponse.getUserName()));
|
||||
return ElectromagneticResultUtil.success(singleUserResponse);
|
||||
}
|
||||
|
||||
|
|
@ -238,11 +245,13 @@ public class UserServiceImpl implements UserService {
|
|||
UserSearchResponse userSearchResponse = new UserSearchResponse();
|
||||
userSearchResponse.setUserList(list);
|
||||
userSearchResponse.setTotalCount(totalCount);
|
||||
UserThreadLocal.setSuccessInfo("", "", StrFormatter.format("查询了用户列表"));
|
||||
return ElectromagneticResultUtil.success(userSearchResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectromagneticResult<?> deleteUser(UserDeleteRequest userDeleteRequest) {
|
||||
|
||||
// 将请求对象转换为模型对象
|
||||
UserDeleteKeyWords userDeleteKeyWords = UserMappers.INSTANCE.getUserDeleteRequestToModel(userDeleteRequest);
|
||||
userDeleteKeyWords.setModifier(UserThreadLocal.getUserId());
|
||||
|
|
@ -250,23 +259,17 @@ public class UserServiceImpl implements UserService {
|
|||
|
||||
// 检查用户是否已经被逻辑删除
|
||||
User existingUser = userMapper.getSingleUser(userDeleteKeyWords.getUserId());
|
||||
Assert.notNull(existingUser, StrFormatter.format("用户ID {} 无效", userDeleteRequest.getUserId()));
|
||||
Assert.isTrue(EffectFlagEnum.EFFECT.code.equals(existingUser.getEffectFlag()), StrFormatter.format("用户{}已经被逻辑删除", existingUser.getUserName()));
|
||||
|
||||
if (existingUser != null && existingUser.getEffectFlag() == 0) {
|
||||
// 如果用户已经被逻辑删除(在这个假设中,0 表示已删除),则不进行任何操作或返回错误
|
||||
return ElectromagneticResultUtil.fail(ElectromagneticErrorEnum.FINE_DELETE_USER_ERROR);
|
||||
}
|
||||
if (existingUser != null && existingUser.getEffectFlag() == 1) {// 在这个假设中,1 表示未删除
|
||||
return ElectromagneticResultUtil.success(userMapper.deleteUser(userDeleteKeyWords));
|
||||
} else {
|
||||
// 如果用户不存在(理论上不应该发生,除非数据库状态不一致),则返回错误
|
||||
return ElectromagneticResultUtil.fail(ElectromagneticErrorEnum.FINE_DELETE_USER_ERROR);
|
||||
|
||||
}
|
||||
UserThreadLocal.setSuccessInfo("", "", StrFormatter.format("删除了用户{}", existingUser.getUserName()));
|
||||
return ElectromagneticResultUtil.success(userMapper.deleteUser(userDeleteKeyWords));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectromagneticResult<?> logout(String token) {
|
||||
token = token.substring(7);
|
||||
UserThreadLocal.setSuccessInfo("", "", StrFormatter.format("用户{}登出", UserThreadLocal.getUsername()));
|
||||
return ElectromagneticResultUtil.success(tokenMapper.deleteToken(token));
|
||||
}
|
||||
|
||||
|
|
@ -282,6 +285,7 @@ public class UserServiceImpl implements UserService {
|
|||
activeRole(dto);
|
||||
bindRole(dto);
|
||||
}
|
||||
UserThreadLocal.setSuccessInfo("", "", StrFormatter.format("绑定了人员和角色"));
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -295,14 +299,12 @@ public class UserServiceImpl implements UserService {
|
|||
@Override
|
||||
public ElectromagneticResult<?> changePassword(String userId, String newPassword) {
|
||||
User user = userMapper.getSingleUser(userId);
|
||||
if (user == null) {
|
||||
return ElectromagneticResultUtil.fail("53106", "USER_NOT_FOUND");
|
||||
}
|
||||
|
||||
Assert.notNull(user, StrFormatter.format("用户ID {} 无效", userId));
|
||||
String decodeNewPwd = AESUtils.decrypt(newPassword, UserConstants.SECRET_KEY);
|
||||
user.setUserPwd(SignUtils.MD5(decodeNewPwd + user.getSalt()));
|
||||
user.setModifier(UserThreadLocal.getUserId());
|
||||
user.setModifierName(UserThreadLocal.getUsername());
|
||||
UserThreadLocal.setSuccessInfo("", UserThreadLocal.getUserId(), StrFormatter.format("修改了用户密码"));
|
||||
return ElectromagneticResultUtil.success(userMapper.modify(user) > 0);
|
||||
}
|
||||
|
||||
|
|
@ -315,8 +317,13 @@ public class UserServiceImpl implements UserService {
|
|||
@Transactional
|
||||
public Boolean resetPassword(String userId) {
|
||||
User user = userMapper.getSingleUser(userId);
|
||||
Assert.notNull(user, StrFormatter.format("用户ID {} 无效", userId));
|
||||
user.setUserPwd(SignUtils.MD5(UserConstants.DEFAULT_PASSWORD + user.getSalt()));
|
||||
return userMapper.modify(user) > 0;
|
||||
boolean isModified = userMapper.modify(user) > 0;
|
||||
if (isModified) {
|
||||
UserThreadLocal.setSuccessInfo("", userId, StrFormatter.format("重置了用户{}的密码", user.getUserName()));
|
||||
}
|
||||
return isModified;
|
||||
}
|
||||
|
||||
private void activeRole(UserBindRoleDTO dto) {
|
||||
|
|
@ -353,19 +360,18 @@ public class UserServiceImpl implements UserService {
|
|||
// 在 UserServiceImpl.java 类中实现以下方法
|
||||
@Override
|
||||
public ElectromagneticResult<?> validateOldPassword(String userId, String oldInputPassword) {
|
||||
User user = userMapper.getSingleUser(userId);
|
||||
if (user == null) {
|
||||
return ElectromagneticResultUtil.fail("53106", "USER_NOT_FOUND");
|
||||
}
|
||||
String decodeOldPwd = AESUtils.decrypt(oldInputPassword, UserConstants.SECRET_KEY);
|
||||
|
||||
// To lzh: UserId可以从UserThreadLocal中获取
|
||||
// To lzh:代码可以尽量简洁,避免过多的嵌套和逻辑判断,注释也不用写太多,简单的逻辑简单处理
|
||||
|
||||
User user = userMapper.getSingleUser(userId);
|
||||
Assert.notNull(user, StrFormatter.format("用户不存在,ID为 {}", userId));
|
||||
String decodeOldPwd = AESUtils.decrypt(oldInputPassword, UserConstants.SECRET_KEY);
|
||||
|
||||
// if (!user.getUserPwd().equals(SignUtils.MD5(decodeOldPwd + user.getSalt()))) {
|
||||
// return ElectromagneticResultUtil.fail("53107", "OLD_PASSWORD_INCORRECT");
|
||||
// }
|
||||
if (!matchPassword(user,decodeOldPwd)) {
|
||||
return ElectromagneticResultUtil.fail("53107", "OLD_PASSWORD_INCORRECT");
|
||||
}
|
||||
Assert.isTrue(matchPassword(user,decodeOldPwd), StrFormatter.format("旧密码错误,ID为 {}", userId));
|
||||
return ElectromagneticResultUtil.success(true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue