refactor(项目管理): 文件管理相关的service从sdk中挪走

This commit is contained in:
song-tianyang 2023-10-18 18:03:44 +08:00 committed by 建国
parent 75de4ad7ce
commit 7f3c0d60ba
9 changed files with 20 additions and 63 deletions

View File

@ -1,9 +0,0 @@
package io.metersphere.sdk.mapper;
import org.apache.ibatis.annotations.Param;
public interface BaseModuleMapper {
long addResourceCount(@Param("tableName") String tableName, @Param("primaryKey") String primaryKey, @Param("count") int count);
long subResourceCount(@Param("tableName") String tableName, @Param("primaryKey") String primaryKey, @Param("count") int count);
}

View File

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.metersphere.sdk.mapper.BaseModuleMapper">
<update id="addResourceCount">
UPDATE #{tableName}
SET resource_count = resource_count + #{count}
WHERE id = #{primaryKey}
</update>
<update id="subResourceCount">
UPDATE #{tableName}
SET resource_count = resource_count - #{count}
WHERE id = #{primaryKey}
</update>
</mapper>

View File

@ -10,7 +10,6 @@ import io.metersphere.project.request.filemanagement.FileBatchProcessDTO;
import io.metersphere.sdk.constants.ModuleConstants;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.file.FileRequest;
import io.metersphere.sdk.service.FileService;
import io.metersphere.sdk.util.LogUtils;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;

View File

@ -15,7 +15,6 @@ import io.metersphere.sdk.constants.ModuleConstants;
import io.metersphere.sdk.constants.StorageType;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.file.FileRequest;
import io.metersphere.sdk.service.FileService;
import io.metersphere.sdk.util.*;
import io.metersphere.system.uid.UUID;
import jakarta.annotation.Resource;

View File

@ -11,7 +11,6 @@ import io.metersphere.sdk.dto.BaseModule;
import io.metersphere.sdk.dto.BaseTreeNode;
import io.metersphere.sdk.dto.request.NodeMoveRequest;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.service.ModuleTreeService;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.service.CleanupProjectResourceService;
import io.metersphere.system.uid.UUID;

View File

@ -1,4 +1,4 @@
package io.metersphere.sdk.service;
package io.metersphere.project.service;
import io.metersphere.sdk.file.FileCenter;
import io.metersphere.sdk.file.FileRequest;

View File

@ -1,12 +1,10 @@
package io.metersphere.sdk.service;
package io.metersphere.project.service;
import io.metersphere.sdk.constants.ModuleConstants;
import io.metersphere.sdk.dto.BaseModule;
import io.metersphere.sdk.dto.BaseTreeNode;
import io.metersphere.sdk.dto.request.NodeMoveRequest;
import io.metersphere.sdk.mapper.BaseModuleMapper;
import io.metersphere.sdk.util.Translator;
import org.apache.commons.lang3.StringUtils;
public abstract class ModuleTreeService {
@ -17,31 +15,18 @@ public abstract class ModuleTreeService {
return new BaseTreeNode(ModuleConstants.DEFAULT_NODE_ID, Translator.get("default.module"), ModuleConstants.NODE_TYPE_DEFAULT);
}
public long changeResourceCount(String tableName, String primaryKey, int count, boolean isAdd, BaseModuleMapper baseModuleMapper) {
if (isAdd) {
return baseModuleMapper.addResourceCount(tableName, primaryKey, count);
} else {
return baseModuleMapper.subResourceCount(tableName, primaryKey, count);
}
}
/**
* 模块树排序
*/
public void sort(NodeMoveRequest nodeMoveRequest) {
if (StringUtils.isAllBlank(nodeMoveRequest.getPreviousNodeId(), nodeMoveRequest.getNextNodeId())) {
// 获取相邻节点
BaseModule previousNode = getNode(nodeMoveRequest.getPreviousNodeId());
BaseModule nextNode = getNode(nodeMoveRequest.getNextNodeId());
if (previousNode == null && nextNode == null) {
// 没有相邻节点pos为0
updatePos(nodeMoveRequest.getNodeId(), 0);
} else {
BaseModule previousNode = null;
BaseModule nextNode = null;
// 获取相邻节点
if (StringUtils.isNotBlank(nodeMoveRequest.getPreviousNodeId())) {
previousNode = getNode(nodeMoveRequest.getPreviousNodeId());
}
if (StringUtils.isNotBlank(nodeMoveRequest.getNextNodeId())) {
nextNode = getNode(nodeMoveRequest.getNextNodeId());
}
boolean refreshPos = false;
int pos;
if (nextNode == null) {

View File

@ -7,16 +7,15 @@ import io.metersphere.project.domain.Project;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.constants.UserSource;
import io.metersphere.sdk.dto.*;
import io.metersphere.system.log.annotation.Log;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.sdk.util.PageUtils;
import io.metersphere.sdk.util.Pager;
import io.metersphere.system.utils.SessionUtils;
import io.metersphere.system.domain.Organization;
import io.metersphere.system.dto.UserBatchCreateDTO;
import io.metersphere.system.dto.request.UserInviteRequest;
import io.metersphere.system.dto.request.UserRegisterRequest;
import io.metersphere.system.dto.response.UserInviteResponse;
import io.metersphere.system.log.annotation.Log;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.request.OrganizationMemberBatchRequest;
import io.metersphere.system.request.ProjectAddMemberBatchRequest;
import io.metersphere.system.request.user.UserChangeEnableRequest;
@ -26,6 +25,7 @@ import io.metersphere.system.response.user.UserImportResponse;
import io.metersphere.system.response.user.UserSelectOption;
import io.metersphere.system.response.user.UserTableResponse;
import io.metersphere.system.service.*;
import io.metersphere.system.utils.SessionUtils;
import io.metersphere.system.utils.TreeNodeParseUtils;
import io.metersphere.validation.groups.Created;
import io.metersphere.validation.groups.Updated;
@ -112,7 +112,7 @@ public class UserController {
@Log(type = OperationLogType.DELETE, expression = "#msClass.deleteLog(#request)", msClass = UserLogService.class)
@RequiresPermissions(PermissionConstants.SYSTEM_USER_DELETE)
public TableBatchProcessResponse deleteUser(@Validated @RequestBody TableBatchProcessDTO request) {
return userService.deleteUser(request, SessionUtils.getUserId());
return userService.deleteUser(request, SessionUtils.getUserId(), SessionUtils.getUser().getName());
}
@PostMapping("/reset/password")

View File

@ -6,10 +6,6 @@ import io.metersphere.sdk.constants.UserSource;
import io.metersphere.sdk.dto.UserExtend;
import io.metersphere.sdk.dto.*;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.system.log.service.OperationLogService;
import io.metersphere.system.mapper.BaseUserMapper;
import io.metersphere.system.notice.sender.impl.MailNoticeSender;
import io.metersphere.system.uid.UUID;
import io.metersphere.sdk.util.*;
import io.metersphere.system.domain.*;
import io.metersphere.system.dto.UserBatchCreateDTO;
@ -19,13 +15,17 @@ import io.metersphere.system.dto.excel.UserExcelRowDTO;
import io.metersphere.system.dto.request.UserInviteRequest;
import io.metersphere.system.dto.request.UserRegisterRequest;
import io.metersphere.system.dto.response.UserInviteResponse;
import io.metersphere.system.log.service.OperationLogService;
import io.metersphere.system.mapper.BaseUserMapper;
import io.metersphere.system.mapper.ExtUserMapper;
import io.metersphere.system.mapper.SystemParameterMapper;
import io.metersphere.system.mapper.UserMapper;
import io.metersphere.system.notice.sender.impl.MailNoticeSender;
import io.metersphere.system.request.user.UserChangeEnableRequest;
import io.metersphere.system.request.user.UserEditRequest;
import io.metersphere.system.response.user.UserImportResponse;
import io.metersphere.system.response.user.UserTableResponse;
import io.metersphere.system.uid.UUID;
import io.metersphere.system.utils.UserImportEventListener;
import jakarta.annotation.Resource;
import jakarta.mail.internet.InternetAddress;
@ -266,26 +266,26 @@ public class UserService {
}
public TableBatchProcessResponse deleteUser(@Valid TableBatchProcessDTO request, String operator) {
public TableBatchProcessResponse deleteUser(@Valid TableBatchProcessDTO request, String operatorId, String operatorName) {
List<String> userIdList = userToolService.getBatchUserIds(request);
this.checkUserInDb(userIdList);
//检查是否含有Admin
this.checkAdminAndThrowException(userIdList);
this.checkCannotDeleteUserAndThrowException(userIdList, operatorId, operatorName);
UserExample userExample = new UserExample();
userExample.createCriteria().andIdIn(userIdList);
//更新删除标志位
TableBatchProcessResponse response = new TableBatchProcessResponse();
response.setTotalCount(userIdList.size());
response.setSuccessCount(this.deleteUserByList(userIdList, operator));
response.setSuccessCount(this.deleteUserByList(userIdList, operatorId));
//删除用户角色关系
userRoleRelationService.deleteByUserIdList(userIdList);
return response;
}
private void checkAdminAndThrowException(List<String> userIdList) {
private void checkCannotDeleteUserAndThrowException(List<String> userIdList, String operatorId, String operatorName) {
for (String userId : userIdList) {
if (userId.equals("admin")) {
throw new MSException(Translator.get("user.not.delete"));
if (StringUtils.equalsAny(userId, "admin", operatorId)) {
throw new MSException(Translator.get("user.not.delete") + ":" + operatorName);
}
}
}