Add migration to rename index and create stored procedure for user weekly balances
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 9m55s
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 9m55s
- Added migration to rename index from IX_NetworkWeeklyBalances_PackageId to IX_NetworkWeeklyBalance_PackageId in the NetworkWeeklyBalances table. - Created stored procedure sp_GetUserWeeklyBalances to retrieve weekly balances with pagination and various filters.
This commit is contained in:
+4
@@ -56,5 +56,9 @@ public class NetworkWeeklyBalanceConfiguration : IEntityTypeConfiguration<Networ
|
||||
// Index برای IsExpired
|
||||
builder.HasIndex(e => e.IsExpired)
|
||||
.HasDatabaseName("IX_NetworkWeeklyBalance_IsExpired");
|
||||
|
||||
// Index برای PackageId — برای فیلتر در sp_GetUserWeeklyBalances
|
||||
builder.HasIndex(e => e.PackageId)
|
||||
.HasDatabaseName("IX_NetworkWeeklyBalance_PackageId");
|
||||
}
|
||||
}
|
||||
|
||||
+5204
File diff suppressed because it is too large
Load Diff
+30
@@ -0,0 +1,30 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CMSMicroservice.Infrastructure.Persistence.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddNetworkWeeklyBalance_PackageIdIndex : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_NetworkWeeklyBalances_PackageId",
|
||||
schema: "CMS",
|
||||
table: "NetworkWeeklyBalances",
|
||||
newName: "IX_NetworkWeeklyBalance_PackageId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_NetworkWeeklyBalance_PackageId",
|
||||
schema: "CMS",
|
||||
table: "NetworkWeeklyBalances",
|
||||
newName: "IX_NetworkWeeklyBalances_PackageId");
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -2478,7 +2478,8 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
|
||||
b.HasIndex("IsExpired")
|
||||
.HasDatabaseName("IX_NetworkWeeklyBalance_IsExpired");
|
||||
|
||||
b.HasIndex("PackageId");
|
||||
b.HasIndex("PackageId")
|
||||
.HasDatabaseName("IX_NetworkWeeklyBalance_PackageId");
|
||||
|
||||
b.HasIndex("WeekDefinitionId")
|
||||
.HasDatabaseName("IX_NetworkWeeklyBalance_WeekDefinitionId");
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
-- =============================================
|
||||
-- Stored Procedure: sp_GetUserWeeklyBalances
|
||||
-- Description: دریافت تعادلهای هفتگی با صفحهبندی و فیلترهای مختلف
|
||||
-- Author: System
|
||||
-- Created: 2026-05-04
|
||||
-- =============================================
|
||||
|
||||
CREATE OR ALTER PROCEDURE [CMS].[sp_GetUserWeeklyBalances]
|
||||
@UserId BIGINT = NULL,
|
||||
@WeekDefinitionId BIGINT = NULL,
|
||||
@PackageId BIGINT = NULL,
|
||||
@OnlyActive BIT = 0,
|
||||
@SortDescending BIT = 1, -- 1 = نزولی (جدیدترین اول)، 0 = صعودی
|
||||
@PageNumber INT = 1,
|
||||
@PageSize INT = 10
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
|
||||
DECLARE @Skip INT = @PageSize * (@PageNumber - 1);
|
||||
|
||||
SELECT
|
||||
n.Id,
|
||||
n.UserId,
|
||||
LTRIM(RTRIM(ISNULL(u.FirstName, '') + ' ' + ISNULL(u.LastName, ''))) AS UserFullName,
|
||||
n.WeekDefinitionId,
|
||||
ISNULL(wd.DisplayName, '') AS WeekDisplayName,
|
||||
n.LeftLegNewMembers,
|
||||
n.LeftLegCarryover,
|
||||
n.LeftLegTotal,
|
||||
n.RightLegNewMembers,
|
||||
n.RightLegCarryover,
|
||||
n.RightLegTotal,
|
||||
n.TotalBalances,
|
||||
n.WeeklyPoolContribution,
|
||||
n.CalculatedAt,
|
||||
n.IsExpired,
|
||||
n.Created,
|
||||
n.PackageId,
|
||||
ISNULL(p.Title, '') AS PackageTitle,
|
||||
COUNT(*) OVER() AS TotalCount
|
||||
FROM [CMS].[NetworkWeeklyBalances] n
|
||||
LEFT JOIN [CMS].[Users] u ON u.Id = n.UserId
|
||||
LEFT JOIN [CMS].[WeekDefinitions] wd ON wd.Id = n.WeekDefinitionId
|
||||
LEFT JOIN [CMS].[Packages] p ON p.Id = n.PackageId
|
||||
WHERE n.IsDeleted = 0
|
||||
AND (@UserId IS NULL OR n.UserId = @UserId)
|
||||
AND (@WeekDefinitionId IS NULL OR n.WeekDefinitionId = @WeekDefinitionId)
|
||||
AND (@PackageId IS NULL OR n.PackageId = @PackageId)
|
||||
AND (@OnlyActive = 0 OR n.IsExpired = 0)
|
||||
ORDER BY
|
||||
CASE WHEN @SortDescending = 1 THEN n.WeekDefinitionId END DESC,
|
||||
CASE WHEN @SortDescending = 0 THEN n.WeekDefinitionId END ASC
|
||||
OFFSET @Skip ROWS
|
||||
FETCH NEXT @PageSize ROWS ONLY;
|
||||
END;
|
||||
Reference in New Issue
Block a user