erp-platform/api/src/Erp.Platform.Application.Contracts/LookUpQueryValues.cs
2025-11-12 12:44:47 +03:00

172 lines
6.8 KiB
C#

using System.Text.Json;
using Erp.Platform.Enums;
using Erp.Platform.ListForms;
using static Erp.Platform.PlatformConsts;
namespace Erp.Platform;
public static class LookupQueryValues
{
private const string defaultDomain = "Erp";
public static string TenantValues =
$"SELECT * FROM (" +
$"SELECT NULL AS \"Key\", 'Host' AS \"Name\" " +
$"UNION ALL " +
$"SELECT " +
$"\"AbpTenants\".\"Id\" AS \"Key\", " +
$"\"AbpTenants\".\"Name\" AS \"Name\" " +
$"FROM \"AbpTenants\"" +
$") AS \"List\" " +
$"ORDER BY \"Name\"";
public static string LanguageKeyValues =
$"SELECT " +
$"\"{FullNameTable(TableNameEnum.LanguageKey)}\".\"Key\", " +
$"CONCAT(" +
$"\"{FullNameTable(TableNameEnum.LanguageKey)}\".\"Key\", " +
$"' (', " +
$"\"{FullNameTable(TableNameEnum.LanguageText)}\".\"Value\", " +
$"')'" +
$") AS \"Name\" " +
$"FROM \"{FullNameTable(TableNameEnum.LanguageKey)}\" " +
$"LEFT OUTER JOIN \"{FullNameTable(TableNameEnum.LanguageText)}\" " +
$"ON \"{FullNameTable(TableNameEnum.LanguageKey)}\".\"Key\" = \"{FullNameTable(TableNameEnum.LanguageText)}\".\"Key\" " +
$"AND \"{FullNameTable(TableNameEnum.LanguageKey)}\".\"ResourceName\" = \"{FullNameTable(TableNameEnum.LanguageText)}\".\"ResourceName\" " +
$"WHERE " +
$"\"{FullNameTable(TableNameEnum.LanguageKey)}\".\"IsDeleted\" = 'false' " +
$"AND \"{FullNameTable(TableNameEnum.LanguageText)}\".\"IsDeleted\" = 'false' " +
$"AND \"{FullNameTable(TableNameEnum.LanguageText)}\".\"CultureName\" = 'tr' " +
$"ORDER BY \"{FullNameTable(TableNameEnum.LanguageKey)}\".\"Key\";";
public static string CountryValues =
$"SELECT " +
$"\"Code\" AS \"Key\", " +
$"\"Name\" AS \"Name\" " +
$"FROM \"{FullNameTable(TableNameEnum.Country)}\" " +
$"WHERE \"IsDeleted\" = 'false' " +
$"ORDER BY \"Name\";";
public static string DefaultLookupQueryJson(
string TableName,
string ValueExpr,
string DisplayExpr,
bool isTable = true,
bool isDeleted = false) => JsonSerializer.Serialize(new LookupDto
{
DataSourceType = UiLookupDataSourceTypeEnum.Query,
ValueExpr = "Key",
DisplayExpr = "Name",
LookupQuery = $"SELECT " +
$"\"{ValueExpr}\" AS \"Key\", " +
$"\"{DisplayExpr}\" AS \"Name\" " +
$"FROM \"{(isTable ? TableNameResolver.GetFullTableName($"{TableName}") : TableNameResolver.GetFullViewName($"{TableName}"))}\" " +
(!isDeleted ? "" : $"WHERE \"IsDeleted\" = 'false'") +
$"ORDER BY \"{DisplayExpr}\";"
});
public static string CityValues =
$"SELECT " +
$"\"Code\" AS \"Key\", " +
$"\"Name\" AS \"Name\" " +
$"FROM \"{FullNameTable(TableNameEnum.City)}\" " +
$"WHERE " +
$"(\"Country\" = @param0 OR @param0 IS NULL) " +
$"AND \"IsDeleted\" = 'false' " +
$"ORDER BY \"Name\";";
public static string DistrictValues =
$"SELECT " +
$"\"Name\" AS \"Key\", " +
$"\"Name\" AS \"Name\" " +
$"FROM \"{FullNameTable(TableNameEnum.District)}\" " +
$"WHERE " +
$"(\"Country\" = @param0 OR @param0 IS NULL) " +
$"AND (\"City\" = @param1 OR @param1 IS NULL) " +
$"AND \"IsDeleted\" = 'false' " +
$"GROUP BY \"Name\" " +
$"ORDER BY \"Name\";";
public static string StreetValues =
$"SELECT " +
$"\"Street\" AS \"Key\", " +
$"\"Street\" AS \"Name\" " +
$"FROM \"{FullNameTable(TableNameEnum.District)}\" " +
$"WHERE " +
$"(\"Country\" = @param0 OR @param0 IS NULL) " +
$"AND (\"City\" = @param1 OR @param1 IS NULL) " +
$"AND (\"Name\" = @param2 OR @param2 IS NULL) " +
$"AND \"IsDeleted\" = 'false' " +
$"GROUP BY \"Street\" " +
$"ORDER BY \"Street\";";
public static string RoleValues =
$"SELECT " +
$"\"Id\" AS \"Key\", " +
$"\"Name\" AS \"Name\" " +
$"FROM \"AbpRoles\"" +
$"ORDER BY \"Name\"";
public static string UserValues =
$"SELECT " +
$"\"Id\" AS \"Key\", " +
$"\"UserName\" AS \"Name\" " +
$"FROM \"AbpUsers\"" +
$"ORDER BY \"Name\"";
public static string BranchValues =
$"SELECT \"Id\" AS \"Key\", " +
$"\"Name\" AS \"Name\" " +
$"FROM \"{defaultDomain}\".\"dbo\".\"{FullNameTable(TableNameEnum.Branch)}\" " +
$"WHERE " +
$"\"TenantId\" = '@TENANTID' " + // 🔹 Bu form doğru — Replace hedefi bu.
$"AND \"IsDeleted\" = 'false' " +
$"AND \"Id\" IN ( " +
$"SELECT \"BranchId\" " +
$"FROM \"{FullNameTable(TableNameEnum.BranchUsers)}\" " +
$"WHERE \"UserId\" = '@USERID' " + // 🔹 Bu da doğru.
$") " +
$"ORDER BY \"Name\";";
public static string RegistrationTypeValues =
$"SELECT " +
$"\"Id\" AS \"Key\", " +
$"\"Name\" AS \"Name\" " +
$"FROM \"{FullNameTable(TableNameEnum.RegistrationType)}\" " +
$"WHERE " +
$"(\"BranchId\" = @param0 OR @param0 IS NULL) " +
$"AND \"IsDeleted\" = 'false' " +
$"ORDER BY \"Name\";";
public static string ClassTypeValues =
$"SELECT " +
$"\"Id\" AS \"Key\", " +
$"\"Name\" AS \"Name\" " +
$"FROM \"{FullNameTable(TableNameEnum.ClassType)}\" " +
$"WHERE " +
$"(\"BranchId\" = @param0 OR @param0 IS NULL) " +
$"AND \"IsDeleted\" = 'false' " +
$"ORDER BY \"Name\";";
public static string PermissionNameValues =
$"SELECT \"Name\" AS \"Key\", " +
$"CONCAT(\"Name\", ' (', \"DisplayName\", ')') AS \"Name\" " +
$"FROM \"AbpPermissions\" " +
$"WHERE \"IsEnabled\" = 'true' " +
$"ORDER BY \"Name\";";
public static string PermissionGroupValues =
$"SELECT \"Name\" AS \"Key\", " +
$"\"DisplayName\" AS \"Name\" " +
$"FROM \"AbpPermissionGroups\" " +
$"ORDER BY \"Name\";";
public static string MenuCodeValues =
$"SELECT " +
$"\"Code\" AS \"Key\", " +
$"\"DisplayName\" AS \"Name\" " +
$"FROM \"{TableNameResolver.GetFullTableName(nameof(TableNameEnum.Menu))}\" " +
$"WHERE \"IsDeleted\" = 'false' " +
"AND \"IsDisabled\" = 'false' " +
$"ORDER BY \"ParentCode\", \"Order\";";
}