108 lines
2.5 KiB
C#
108 lines
2.5 KiB
C#
|
|
using System;
|
||
|
|
using Erp.SqlQueryManager.Domain.Shared;
|
||
|
|
using Volo.Abp.Domain.Entities.Auditing;
|
||
|
|
using Volo.Abp.MultiTenancy;
|
||
|
|
|
||
|
|
namespace Erp.SqlQueryManager.Domain.Entities;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// SQL View entity for creating and managing database views
|
||
|
|
/// </summary>
|
||
|
|
public class SqlView : FullAuditedEntity<Guid>, IMultiTenant
|
||
|
|
{
|
||
|
|
public Guid? TenantId { get; set; }
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// View name in database
|
||
|
|
/// </summary>
|
||
|
|
public string ViewName { get; set; }
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Schema name (default: dbo)
|
||
|
|
/// </summary>
|
||
|
|
public string SchemaName { get; set; }
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Display name
|
||
|
|
/// </summary>
|
||
|
|
public string DisplayName { get; set; }
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Description
|
||
|
|
/// </summary>
|
||
|
|
public string Description { get; set; }
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// View definition (SELECT statement)
|
||
|
|
/// </summary>
|
||
|
|
public string ViewDefinition { get; set; }
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// DataSource code
|
||
|
|
/// </summary>
|
||
|
|
public string DataSourceCode { get; set; }
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Status
|
||
|
|
/// </summary>
|
||
|
|
public SqlQueryStatus Status { get; set; }
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Category
|
||
|
|
/// </summary>
|
||
|
|
public string Category { get; set; }
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Whether view exists in database
|
||
|
|
/// </summary>
|
||
|
|
public bool IsDeployed { get; set; }
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Last deployment time
|
||
|
|
/// </summary>
|
||
|
|
public DateTime? LastDeployedAt { get; set; }
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Whether to use WITH SCHEMABINDING
|
||
|
|
/// </summary>
|
||
|
|
public bool WithSchemaBinding { get; set; }
|
||
|
|
|
||
|
|
protected SqlView()
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
public SqlView(
|
||
|
|
Guid id,
|
||
|
|
string viewName,
|
||
|
|
string schemaName,
|
||
|
|
string displayName,
|
||
|
|
string viewDefinition,
|
||
|
|
string dataSourceCode,
|
||
|
|
Guid? tenantId = null) : base(id)
|
||
|
|
{
|
||
|
|
ViewName = viewName;
|
||
|
|
SchemaName = schemaName ?? "dbo";
|
||
|
|
DisplayName = displayName;
|
||
|
|
ViewDefinition = viewDefinition;
|
||
|
|
DataSourceCode = dataSourceCode;
|
||
|
|
TenantId = tenantId;
|
||
|
|
Status = SqlQueryStatus.Draft;
|
||
|
|
IsDeployed = false;
|
||
|
|
WithSchemaBinding = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void UpdateDefinition(string definition)
|
||
|
|
{
|
||
|
|
ViewDefinition = definition;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void MarkAsDeployed()
|
||
|
|
{
|
||
|
|
IsDeployed = true;
|
||
|
|
LastDeployedAt = DateTime.UtcNow;
|
||
|
|
Status = SqlQueryStatus.Active;
|
||
|
|
}
|
||
|
|
|
||
|
|
public string GetFullName() => $"{SchemaName}.{ViewName}";
|
||
|
|
}
|