1.修复 平台web-ui,默认项目可以删除

2.删除项目时,删除所有包含项目ID,数据库表中的数据
This commit is contained in:
Wang Chen Chen
2023-11-22 14:04:51 +08:00
parent 148462f30b
commit 8e93295468
4 changed files with 40 additions and 5 deletions

View File

@@ -73,8 +73,12 @@
</span>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item :icon="Link" command="ResetPassword">重置密码</el-dropdown-item>
<el-dropdown-item :icon="Delete" command="Delete">删除</el-dropdown-item>
<div v-has="['cms_project:reset:password']">
<el-dropdown-item :icon="Link" command="ResetPassword">重置密码</el-dropdown-item>
</div>
<div v-if="scope.row.projectId !== 10001" v-has="['cms_project:delete']">
<el-dropdown-item :icon="Delete" command="Delete">删除</el-dropdown-item>
</div>
</el-dropdown-menu>
</template>
</el-dropdown>

View File

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xaaef.molly.corems.entity.CmsProject;
import com.xaaef.molly.corems.entity.TenantAndProject;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.Set;
@@ -28,8 +29,17 @@ public interface CmsProjectMapper extends BaseMapper<CmsProject> {
Set<String> selectListTableNamesByNotIncludeColumn(String column);
// 查询 所有的包含 project_id 的表
@InterceptorIgnore(tenantLine = "true")
Set<String> selectListTableNamesByIncludeColumn(String column);
// 删除项目
@InterceptorIgnore(tenantLine = "true")
int deleteByProjectId(@Param("tableName") Set<String> tableName, @Param("projectId") Long projectId);
// 根据 租户的数据名称 查询 项目列表。如: molly_master 、molly_google
Set<TenantAndProject> selectListByTenantDbName(Collection<String> tenantDbNameList);
}

View File

@@ -22,10 +22,12 @@ import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import static com.xaaef.molly.auth.jwt.JwtSecurityUtils.*;
import static com.xaaef.molly.common.consts.ConfigName.PROJECT_DEFAULT_PASSWORD;
import static com.xaaef.molly.common.consts.MbpConst.PROJECT_ID;
/**
@@ -171,11 +173,18 @@ public class CmsProjectServiceImpl extends BaseServiceImpl<CmsProjectMapper, Cms
if (dbProject == null) {
throw new RuntimeException(StrUtil.format("项目Id {} 不存在!", entity.getProjectId()));
}
var flag = matchesPassword(entity.getPassword(), dbProject.getPassword());
if (!flag) {
var flag1 = matchesPassword(entity.getPassword(), dbProject.getPassword());
if (!flag1) {
throw new RuntimeException(StrUtil.format("项目 {} 密码输入错误!", dbProject.getProjectName()));
}
var flag2 = super.removeById(dbProject.getProjectId());
// 查询 所有的 包含 project_id 的表
Set<String> tableNames = baseMapper.selectListTableNamesByIncludeColumn(PROJECT_ID);
// 删除 此项目 在所有表中的数据
if (!tableNames.isEmpty()) {
baseMapper.deleteByProjectId(tableNames, dbProject.getProjectId());
}
// 租户 删除 此项目
tenantService.tenantDelProjectId(TenantUtils.getTenantId(), dbProject.getProjectId());
return flag2;
}

View File

@@ -16,6 +16,18 @@
</select>
<select id="selectListTableNamesByIncludeColumn" resultType="java.lang.String">
SELECT DISTINCT TABLE_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = (SELECT DATABASE()) AND COLUMN_NAME = #{column}
</select>
<delete id="deleteByProjectId">
<foreach collection='tableName' item='item' index='index'>
DELETE FROM ${item} WHERE `project_id` = #{projectId};
</foreach>
</delete>
<resultMap id="tenantAndProjectMap" type="com.xaaef.molly.corems.entity.TenantAndProject">
<id property="projectId" column="project_id"/>
<result property="tenantId" column="tenant_id"/>