😎增加一键同步所有租户数据库

This commit is contained in:
zuohuaijun 2024-06-26 00:36:08 +08:00
parent 51695c9e84
commit 95d156fe71
7 changed files with 223 additions and 108 deletions

View File

@ -381,6 +381,20 @@ public class SysTenantService : IDynamicApiController, ITransient
return password;
}
/// <summary>
/// 同步所有租户数据库 🔖
/// </summary>
/// <returns></returns>
[DisplayName("同步所有租户数据库")]
public async Task SyncTenantDb()
{
var tenantList = await _sysTenantRep.GetListAsync();
foreach (var tenant in tenantList)
{
await InitTenantDb(new TenantInput { Id = tenant.Id });
}
}
/// <summary>
/// 缓存所有租户
/// </summary>
@ -408,9 +422,8 @@ public class SysTenantService : IDynamicApiController, ITransient
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[ApiDescriptionSettings(Name = "CreateDb"), HttpPost]
[DisplayName("创建租户数据库")]
public async Task CreateDb(TenantInput input)
public async Task InitTenantDb(TenantInput input)
{
var tenant = await _sysTenantRep.GetSingleAsync(u => u.Id == input.Id);
if (tenant == null) return;

View File

@ -84,54 +84,6 @@ export const SysTenantApiAxiosParamCreator = function (configuration?: Configura
options: localVarRequestOptions,
};
},
/**
*
* @summary 🔖
* @param {TenantInput} [body]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
apiSysTenantCreateDbPost: async (body?: TenantInput, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
const localVarPath = `/api/sysTenant/createDb`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, 'https://example.com');
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}
const localVarRequestOptions :AxiosRequestConfig = { method: 'POST', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
// authentication Bearer required
// http bearer authentication required
if (configuration && configuration.accessToken) {
const accessToken = typeof configuration.accessToken === 'function'
? await configuration.accessToken()
: await configuration.accessToken;
localVarHeaderParameter["Authorization"] = "Bearer " + accessToken;
}
localVarHeaderParameter['Content-Type'] = 'application/json-patch+json';
const query = new URLSearchParams(localVarUrlObj.search);
for (const key in localVarQueryParameter) {
query.set(key, localVarQueryParameter[key]);
}
for (const key in options.params) {
query.set(key, options.params[key]);
}
localVarUrlObj.search = (new URLSearchParams(query)).toString();
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
const needsSerialization = (typeof body !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json';
localVarRequestOptions.data = needsSerialization ? JSON.stringify(body !== undefined ? body : {}) : (body || "");
return {
url: localVarUrlObj.pathname + localVarUrlObj.search + localVarUrlObj.hash,
options: localVarRequestOptions,
};
},
/**
*
* @summary 🔖
@ -228,6 +180,54 @@ export const SysTenantApiAxiosParamCreator = function (configuration?: Configura
options: localVarRequestOptions,
};
},
/**
*
* @summary 🔖
* @param {TenantInput} [body]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
apiSysTenantInitTenantDbPost: async (body?: TenantInput, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
const localVarPath = `/api/sysTenant/initTenantDb`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, 'https://example.com');
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}
const localVarRequestOptions :AxiosRequestConfig = { method: 'POST', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
// authentication Bearer required
// http bearer authentication required
if (configuration && configuration.accessToken) {
const accessToken = typeof configuration.accessToken === 'function'
? await configuration.accessToken()
: await configuration.accessToken;
localVarHeaderParameter["Authorization"] = "Bearer " + accessToken;
}
localVarHeaderParameter['Content-Type'] = 'application/json-patch+json';
const query = new URLSearchParams(localVarUrlObj.search);
for (const key in localVarQueryParameter) {
query.set(key, localVarQueryParameter[key]);
}
for (const key in options.params) {
query.set(key, options.params[key]);
}
localVarUrlObj.search = (new URLSearchParams(query)).toString();
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
const needsSerialization = (typeof body !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json';
localVarRequestOptions.data = needsSerialization ? JSON.stringify(body !== undefined ? body : {}) : (body || "");
return {
url: localVarUrlObj.pathname + localVarUrlObj.search + localVarUrlObj.hash,
options: localVarRequestOptions,
};
},
/**
*
* @summary Id集合 🔖
@ -420,6 +420,49 @@ export const SysTenantApiAxiosParamCreator = function (configuration?: Configura
options: localVarRequestOptions,
};
},
/**
*
* @summary 🔖
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
apiSysTenantSyncTenantDbPost: async (options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
const localVarPath = `/api/sysTenant/syncTenantDb`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, 'https://example.com');
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}
const localVarRequestOptions :AxiosRequestConfig = { method: 'POST', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
// authentication Bearer required
// http bearer authentication required
if (configuration && configuration.accessToken) {
const accessToken = typeof configuration.accessToken === 'function'
? await configuration.accessToken()
: await configuration.accessToken;
localVarHeaderParameter["Authorization"] = "Bearer " + accessToken;
}
const query = new URLSearchParams(localVarUrlObj.search);
for (const key in localVarQueryParameter) {
query.set(key, localVarQueryParameter[key]);
}
for (const key in options.params) {
query.set(key, options.params[key]);
}
localVarUrlObj.search = (new URLSearchParams(query)).toString();
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
return {
url: localVarUrlObj.pathname + localVarUrlObj.search + localVarUrlObj.hash,
options: localVarRequestOptions,
};
},
/**
*
* @summary 🔖
@ -539,20 +582,6 @@ export const SysTenantApiFp = function(configuration?: Configuration) {
return axios.request(axiosRequestArgs);
};
},
/**
*
* @summary 🔖
* @param {TenantInput} [body]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async apiSysTenantCreateDbPost(body?: TenantInput, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => Promise<AxiosResponse<void>>> {
const localVarAxiosArgs = await SysTenantApiAxiosParamCreator(configuration).apiSysTenantCreateDbPost(body, options);
return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
const axiosRequestArgs :AxiosRequestConfig = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url};
return axios.request(axiosRequestArgs);
};
},
/**
*
* @summary 🔖
@ -581,6 +610,20 @@ export const SysTenantApiFp = function(configuration?: Configuration) {
return axios.request(axiosRequestArgs);
};
},
/**
*
* @summary 🔖
* @param {TenantInput} [body]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async apiSysTenantInitTenantDbPost(body?: TenantInput, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => Promise<AxiosResponse<void>>> {
const localVarAxiosArgs = await SysTenantApiAxiosParamCreator(configuration).apiSysTenantInitTenantDbPost(body, options);
return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
const axiosRequestArgs :AxiosRequestConfig = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url};
return axios.request(axiosRequestArgs);
};
},
/**
*
* @summary Id集合 🔖
@ -637,6 +680,19 @@ export const SysTenantApiFp = function(configuration?: Configuration) {
return axios.request(axiosRequestArgs);
};
},
/**
*
* @summary 🔖
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async apiSysTenantSyncTenantDbPost(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => Promise<AxiosResponse<void>>> {
const localVarAxiosArgs = await SysTenantApiAxiosParamCreator(configuration).apiSysTenantSyncTenantDbPost(options);
return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
const axiosRequestArgs :AxiosRequestConfig = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url};
return axios.request(axiosRequestArgs);
};
},
/**
*
* @summary 🔖
@ -684,16 +740,6 @@ export const SysTenantApiFactory = function (configuration?: Configuration, base
async apiSysTenantAddPost(body?: AddTenantInput, options?: AxiosRequestConfig): Promise<AxiosResponse<void>> {
return SysTenantApiFp(configuration).apiSysTenantAddPost(body, options).then((request) => request(axios, basePath));
},
/**
*
* @summary 🔖
* @param {TenantInput} [body]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async apiSysTenantCreateDbPost(body?: TenantInput, options?: AxiosRequestConfig): Promise<AxiosResponse<void>> {
return SysTenantApiFp(configuration).apiSysTenantCreateDbPost(body, options).then((request) => request(axios, basePath));
},
/**
*
* @summary 🔖
@ -714,6 +760,16 @@ export const SysTenantApiFactory = function (configuration?: Configuration, base
async apiSysTenantGrantMenuPost(body?: RoleMenuInput, options?: AxiosRequestConfig): Promise<AxiosResponse<void>> {
return SysTenantApiFp(configuration).apiSysTenantGrantMenuPost(body, options).then((request) => request(axios, basePath));
},
/**
*
* @summary 🔖
* @param {TenantInput} [body]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async apiSysTenantInitTenantDbPost(body?: TenantInput, options?: AxiosRequestConfig): Promise<AxiosResponse<void>> {
return SysTenantApiFp(configuration).apiSysTenantInitTenantDbPost(body, options).then((request) => request(axios, basePath));
},
/**
*
* @summary Id集合 🔖
@ -754,6 +810,15 @@ export const SysTenantApiFactory = function (configuration?: Configuration, base
async apiSysTenantSetStatusPost(body?: TenantInput, options?: AxiosRequestConfig): Promise<AxiosResponse<AdminResultInt32>> {
return SysTenantApiFp(configuration).apiSysTenantSetStatusPost(body, options).then((request) => request(axios, basePath));
},
/**
*
* @summary 🔖
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async apiSysTenantSyncTenantDbPost(options?: AxiosRequestConfig): Promise<AxiosResponse<void>> {
return SysTenantApiFp(configuration).apiSysTenantSyncTenantDbPost(options).then((request) => request(axios, basePath));
},
/**
*
* @summary 🔖
@ -795,17 +860,6 @@ export class SysTenantApi extends BaseAPI {
public async apiSysTenantAddPost(body?: AddTenantInput, options?: AxiosRequestConfig) : Promise<AxiosResponse<void>> {
return SysTenantApiFp(this.configuration).apiSysTenantAddPost(body, options).then((request) => request(this.axios, this.basePath));
}
/**
*
* @summary 🔖
* @param {TenantInput} [body]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof SysTenantApi
*/
public async apiSysTenantCreateDbPost(body?: TenantInput, options?: AxiosRequestConfig) : Promise<AxiosResponse<void>> {
return SysTenantApiFp(this.configuration).apiSysTenantCreateDbPost(body, options).then((request) => request(this.axios, this.basePath));
}
/**
*
* @summary 🔖
@ -828,6 +882,17 @@ export class SysTenantApi extends BaseAPI {
public async apiSysTenantGrantMenuPost(body?: RoleMenuInput, options?: AxiosRequestConfig) : Promise<AxiosResponse<void>> {
return SysTenantApiFp(this.configuration).apiSysTenantGrantMenuPost(body, options).then((request) => request(this.axios, this.basePath));
}
/**
*
* @summary 🔖
* @param {TenantInput} [body]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof SysTenantApi
*/
public async apiSysTenantInitTenantDbPost(body?: TenantInput, options?: AxiosRequestConfig) : Promise<AxiosResponse<void>> {
return SysTenantApiFp(this.configuration).apiSysTenantInitTenantDbPost(body, options).then((request) => request(this.axios, this.basePath));
}
/**
*
* @summary Id集合 🔖
@ -872,6 +937,16 @@ export class SysTenantApi extends BaseAPI {
public async apiSysTenantSetStatusPost(body?: TenantInput, options?: AxiosRequestConfig) : Promise<AxiosResponse<AdminResultInt32>> {
return SysTenantApiFp(this.configuration).apiSysTenantSetStatusPost(body, options).then((request) => request(this.axios, this.basePath));
}
/**
*
* @summary 🔖
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof SysTenantApi
*/
public async apiSysTenantSyncTenantDbPost(options?: AxiosRequestConfig) : Promise<AxiosResponse<void>> {
return SysTenantApiFp(this.configuration).apiSysTenantSyncTenantDbPost(options).then((request) => request(this.axios, this.basePath));
}
/**
*
* @summary 🔖

View File

@ -118,14 +118,6 @@ export interface AddOrgInput {
*/
level?: number | null;
/**
* -
*
* @type {string}
* @memberof AddOrgInput
*/
type?: string | null;
/**
* Id
*
@ -179,4 +171,12 @@ export interface AddOrgInput {
* @memberof AddOrgInput
*/
name: string;
/**
*
*
* @type {string}
* @memberof AddOrgInput
*/
type?: string | null;
}

View File

@ -154,4 +154,12 @@ export interface LoginUserOutput {
* @memberof LoginUserOutput
*/
roleIds?: Array<number> | null;
/**
*
*
* @type {string}
* @memberof LoginUserOutput
*/
watermarkText?: string | null;
}

View File

@ -30,6 +30,12 @@ export interface MemberInfo {
*/
memberType?: MemberTypes;
/**
* @type {string}
* @memberof MemberInfo
*/
name?: string | null;
/**
* @type {Type}
* @memberof MemberInfo
@ -42,12 +48,6 @@ export interface MemberInfo {
*/
reflectedType?: Type;
/**
* @type {string}
* @memberof MemberInfo
*/
name?: string | null;
/**
* @type {Module}
* @memberof MemberInfo

View File

@ -118,14 +118,6 @@ export interface UpdateOrgInput {
*/
level?: number | null;
/**
* -
*
* @type {string}
* @memberof UpdateOrgInput
*/
type?: string | null;
/**
* Id
*
@ -179,4 +171,12 @@ export interface UpdateOrgInput {
* @memberof UpdateOrgInput
*/
name: string;
/**
*
*
* @type {string}
* @memberof UpdateOrgInput
*/
type?: string | null;
}

View File

@ -17,6 +17,9 @@
<el-form-item>
<el-button type="primary" icon="ele-Plus" @click="openAddTenant" v-auth="'sysTenant:add'"> 新增 </el-button>
</el-form-item>
<el-form-item>
<el-button type="danger" icon="ele-Refresh" @click="syncTenantDb" plain> 同步所有租户数据库 </el-button>
</el-form-item>
</el-form>
</el-card>
@ -239,7 +242,7 @@ const createTenant = (row: any) => {
type: 'warning',
})
.then(async () => {
await getAPI(SysTenantApi).apiSysTenantCreateDbPost({ id: row.id });
await getAPI(SysTenantApi).apiSysTenantInitTenantDbPost({ id: row.id });
ElMessage.success('创建/更新租户数据库成功');
})
.catch(() => {});
@ -256,4 +259,20 @@ const changeStatus = (row: any) => {
row.status = row.status == 1 ? 2 : 1;
});
};
//
const syncTenantDb = (row: any) => {
ElMessageBox.confirm(`确定同步所有租户数据库?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(async () => {
state.loading = true;
await getAPI(SysTenantApi).apiSysTenantSyncTenantDbPost();
ElMessage.success('同步成功');
state.loading = false;
})
.catch(() => {});
};
</script>