From 9ca748a432a6c3cac6e7d7a1abf0180827522cef Mon Sep 17 00:00:00 2001 From: liguoyang Date: Mon, 8 Apr 2024 18:25:18 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E6=9F=A5=E8=AF=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MealSupplementsRecordController.cs | 2 +- .../MealSupplementRecordMyResponse.cs | 15 ++- .../Services/IMealSupplementRecordService.cs | 2 +- .../Implements/MealSupplementRecordService.cs | 22 ++- .../Order/Controllers/BalancesController.cs | 2 +- .../Request/BalanceRecordUserPageRequest.cs | 127 ++++++++++-------- ...se.cs => BalanceRecordUserPageResponse.cs} | 44 ++++-- .../Order/Services/IBalanceService.cs | 2 +- .../Services/Implements/BalanceService.cs | 38 +++--- 9 files changed, 156 insertions(+), 98 deletions(-) rename Src/Dlhis.Canteen/Order/Response/{BalanceRecordUserResponse.cs => BalanceRecordUserPageResponse.cs} (56%) diff --git a/Src/Dlhis.Canteen/MealSupplementRecord/Controller/MealSupplementsRecordController.cs b/Src/Dlhis.Canteen/MealSupplementRecord/Controller/MealSupplementsRecordController.cs index 15daaf72..2644e477 100644 --- a/Src/Dlhis.Canteen/MealSupplementRecord/Controller/MealSupplementsRecordController.cs +++ b/Src/Dlhis.Canteen/MealSupplementRecord/Controller/MealSupplementsRecordController.cs @@ -39,7 +39,7 @@ public class MealSupplementsRecordController /// /// [HttpGet("my")] - public async Task> GetMyMealSupplementRecords([FromQuery] MealSupplementRecordMyRequest request) + public async Task GetMyMealSupplementRecords([FromQuery] MealSupplementRecordMyRequest request) { return await _mealSupplementRecordService.GetMyMealSupplementRecords(request); } diff --git a/Src/Dlhis.Canteen/MealSupplementRecord/Response/MealSupplementRecordMyResponse.cs b/Src/Dlhis.Canteen/MealSupplementRecord/Response/MealSupplementRecordMyResponse.cs index 1d2f37f1..b3de406c 100644 --- a/Src/Dlhis.Canteen/MealSupplementRecord/Response/MealSupplementRecordMyResponse.cs +++ b/Src/Dlhis.Canteen/MealSupplementRecord/Response/MealSupplementRecordMyResponse.cs @@ -2,7 +2,7 @@ namespace Dlhis.Canteen.MealSupplementRecord.Response; -public class MealSupplementRecordMyResponse +public class MealSupplementRecordItemResponse { /// /// 餐补日期 @@ -22,3 +22,16 @@ public class MealSupplementRecordMyResponse /// public string Remark { get; set; } } + +public class MealSupplementRecordMyResponse +{ + [JsonIgnore] + public decimal CurrentMonthSum { get; set; } + + /// + /// 当前月份总和 + /// + public string MonthSum => CurrentMonthSum.ToString("f2"); + + public List Items { get; set; } +} diff --git a/Src/Dlhis.Canteen/MealSupplementRecord/Services/IMealSupplementRecordService.cs b/Src/Dlhis.Canteen/MealSupplementRecord/Services/IMealSupplementRecordService.cs index e02ab60e..a14785b9 100644 --- a/Src/Dlhis.Canteen/MealSupplementRecord/Services/IMealSupplementRecordService.cs +++ b/Src/Dlhis.Canteen/MealSupplementRecord/Services/IMealSupplementRecordService.cs @@ -8,5 +8,5 @@ public interface IMealSupplementRecordService : IScopeDependency { Task> GetPageAsync(MealSupplementRecordRequest request); - Task> GetMyMealSupplementRecords(MealSupplementRecordMyRequest request); + Task GetMyMealSupplementRecords(MealSupplementRecordMyRequest request); } diff --git a/Src/Dlhis.Canteen/MealSupplementRecord/Services/Implements/MealSupplementRecordService.cs b/Src/Dlhis.Canteen/MealSupplementRecord/Services/Implements/MealSupplementRecordService.cs index 6f58e722..7e9e287a 100644 --- a/Src/Dlhis.Canteen/MealSupplementRecord/Services/Implements/MealSupplementRecordService.cs +++ b/Src/Dlhis.Canteen/MealSupplementRecord/Services/Implements/MealSupplementRecordService.cs @@ -50,21 +50,37 @@ public class MealSupplementRecordService : IMealSupplementRecordService return page; } - public async Task> GetMyMealSupplementRecords(MealSupplementRecordMyRequest request) + public async Task GetMyMealSupplementRecords(MealSupplementRecordMyRequest request) { var code = _currentUser.GetUserClaim("jinko-code") ?? string.Empty; - return await _dbContext.Queryable() + var data = await _dbContext.Queryable() .Where(x => x.Date >= request.SearchDateTimePeriod.Start && x.Date <= request.SearchDateTimePeriod.End) .Where(x => x.Status == MealSupplementStatusEnumtype.Success) .Where(x => x.Code == code) .OrderBy(x => x.Date, OrderByType.Desc) - .Select(x => new MealSupplementRecordMyResponse + .Select(x => new MealSupplementRecordItemResponse { CurrentAmount = x.Amount, Date = x.Date, Remark = x.Remark }) .ToListAsync(); + + var now = DateTime.Now; + var monthStart = new DateTime(now.Year, now.Month, 1); + var monthEnd = monthStart.AddMonths(1).AddSeconds(-1); + + var monthSum = await _dbContext.Queryable() + .Where(x => x.Date >= monthStart && x.Date <= monthEnd) + .Where(x => x.Status == MealSupplementStatusEnumtype.Success) + .Where(x => x.Code == code) + .SumAsync(x => SqlFunc.Abs(x.Amount)); + + return new MealSupplementRecordMyResponse + { + CurrentMonthSum = monthSum, + Items = data, + }; } } diff --git a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs index df67ab1d..abb8d969 100644 --- a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs +++ b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs @@ -80,7 +80,7 @@ public class BalancesController : ControllerBase /// [HttpGet("user/page")] [IgnoreTenant] - public async Task> GetPageByUserAsync([FromQuery] BalanceRecordUserPageRequest request) + public async Task GetPageByUserAsync([FromQuery] BalanceRecordUserPageRequest request) { return await _balanceService.GetPageByUserAsync(request); } diff --git a/Src/Dlhis.Canteen/Order/Request/BalanceRecordUserPageRequest.cs b/Src/Dlhis.Canteen/Order/Request/BalanceRecordUserPageRequest.cs index 8e544b15..99e8cd66 100644 --- a/Src/Dlhis.Canteen/Order/Request/BalanceRecordUserPageRequest.cs +++ b/Src/Dlhis.Canteen/Order/Request/BalanceRecordUserPageRequest.cs @@ -3,71 +3,80 @@ using Kurisu.Core.CustomClass; using System.ComponentModel.DataAnnotations; using Kurisu.Core.DataAccess.Dto; -namespace Dlhis.Canteen.Order.Request +namespace Dlhis.Canteen.Order.Request; + +public class BalanceRecordUserPageRequest : PageDto, IValidatableObject { - public class BalanceRecordUserPageRequest : PageDto, IValidatableObject + /// + /// 查询日期范围类型 DateTimeSearchEnumType + /// + [EnumDataType(typeof(DateTimeSearchEnumType))] + public DateTimeSearchEnumType? SearchDateTimeDimension { get; set; } + + /// + /// 消费应用类型 + /// + public CanteenApplicaitonTypeEnumType? ApplicationType { get; set; } + + /// + /// 日期范围查询 + /// + public DateTimePeriod SearchDateTimePeriod { get; set; } + + + public IEnumerable Validate(ValidationContext validationContext) { - /// - /// 查询日期范围类型 DateTimeSearchEnumType - /// - [EnumDataType(typeof(DateTimeSearchEnumType))] - public DateTimeSearchEnumType? SearchDateTimeDimension { get; set; } - - /// - /// 消费应用类型 - /// - public CanteenApplicaitonTypeEnumType? ApplicationType { get; set; } - - /// - /// 日期范围查询 - /// - public DateTimePeriod SearchDateTimePeriod { get; set; } - - - public IEnumerable Validate(ValidationContext validationContext) + var now = DateTime.Now; + if (SearchDateTimeDimension.HasValue) { - var now = DateTime.Now; - if (SearchDateTimeDimension.HasValue) + //重新赋值 + SearchDateTimePeriod = new DateTimePeriod(); + + if (SearchDateTimeDimension == DateTimeSearchEnumType.Day) { - //重新赋值 - SearchDateTimePeriod = new DateTimePeriod(); - - if (SearchDateTimeDimension == DateTimeSearchEnumType.Day) - { - SearchDateTimePeriod.Start = DateTime.Today; - SearchDateTimePeriod.End = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59); - } - else if (SearchDateTimeDimension == DateTimeSearchEnumType.Week) - { - SearchDateTimePeriod.Start = now.AddDays(1 - (int)now.DayOfWeek); - SearchDateTimePeriod.End = SearchDateTimePeriod.Start.Value.AddDays(6); - } - else if (SearchDateTimeDimension == DateTimeSearchEnumType.Month) - { - SearchDateTimePeriod.Start = new DateTime(now.Year, now.Month, 1); - SearchDateTimePeriod.End = SearchDateTimePeriod.Start.Value.AddMonths(1).AddDays(-1); - } - else if (SearchDateTimeDimension == DateTimeSearchEnumType.Season) - { - SearchDateTimePeriod.Start = now.AddMonths(0 - (now.Month - 1) % 3); - SearchDateTimePeriod.End = now.AddMonths(3 - (now.Month - 1) % 3).AddMonths(1).AddDays(-1); - } - else if (SearchDateTimeDimension == DateTimeSearchEnumType.HalfOfYear) - { - SearchDateTimePeriod.Start = now.AddDays(-180); - SearchDateTimePeriod.End = now; - } - else if (SearchDateTimeDimension == DateTimeSearchEnumType.Year) - { - SearchDateTimePeriod.Start = new DateTime(now.Year, 1, 1); - SearchDateTimePeriod.End = SearchDateTimePeriod.Start.Value.AddYears(1).AddDays(-1); - } - - SearchDateTimePeriod.Start = SearchDateTimePeriod.Start.Value.Date; - SearchDateTimePeriod.End = SearchDateTimePeriod.End.Value.Date; + SearchDateTimePeriod.Start = DateTime.Today; + SearchDateTimePeriod.End = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59); + } + else if (SearchDateTimeDimension == DateTimeSearchEnumType.Week) + { + SearchDateTimePeriod.Start = now.AddDays(1 - (int)now.DayOfWeek); + SearchDateTimePeriod.End = SearchDateTimePeriod.Start.Value.AddDays(6); + } + else if (SearchDateTimeDimension == DateTimeSearchEnumType.Month) + { + SearchDateTimePeriod.Start = new DateTime(now.Year, now.Month, 1); + SearchDateTimePeriod.End = SearchDateTimePeriod.Start.Value.AddMonths(1).AddDays(-1); + } + else if (SearchDateTimeDimension == DateTimeSearchEnumType.Season) + { + SearchDateTimePeriod.Start = now.AddMonths(0 - (now.Month - 1) % 3); + SearchDateTimePeriod.End = now.AddMonths(3 - (now.Month - 1) % 3).AddMonths(1).AddDays(-1); + } + else if (SearchDateTimeDimension == DateTimeSearchEnumType.HalfOfYear) + { + SearchDateTimePeriod.Start = now.AddDays(-180); + SearchDateTimePeriod.End = now; + } + else if (SearchDateTimeDimension == DateTimeSearchEnumType.Year) + { + SearchDateTimePeriod.Start = new DateTime(now.Year, 1, 1); + SearchDateTimePeriod.End = SearchDateTimePeriod.Start.Value.AddYears(1).AddDays(-1); } - yield break; + SearchDateTimePeriod.Start = SearchDateTimePeriod.Start.Value.Date; + SearchDateTimePeriod.End = SearchDateTimePeriod.End.Value.Date; } + else + { + if (SearchDateTimePeriod != null) + { + if (SearchDateTimePeriod.End != null) + { + SearchDateTimePeriod.End = SearchDateTimePeriod.End.Value.AddDays(1).AddSeconds(-1); + } + } + } + + yield break; } } diff --git a/Src/Dlhis.Canteen/Order/Response/BalanceRecordUserResponse.cs b/Src/Dlhis.Canteen/Order/Response/BalanceRecordUserPageResponse.cs similarity index 56% rename from Src/Dlhis.Canteen/Order/Response/BalanceRecordUserResponse.cs rename to Src/Dlhis.Canteen/Order/Response/BalanceRecordUserPageResponse.cs index 9ad32164..b1a09866 100644 --- a/Src/Dlhis.Canteen/Order/Response/BalanceRecordUserResponse.cs +++ b/Src/Dlhis.Canteen/Order/Response/BalanceRecordUserPageResponse.cs @@ -1,9 +1,11 @@ using Dlhis.Entity.Canteen.Enums; using Kurisu.AspNetCore.Utils.Extensions; +using Kurisu.Core.DataAccess.Dto; +using Newtonsoft.Json; namespace Dlhis.Canteen.Order.Response; -public class BalanceRecordUserResponse +public class BalanceRecordUserPageResponse { public long Id { get; set; } @@ -20,37 +22,36 @@ public class BalanceRecordUserResponse public string SourceDesc => Source.GetDescription(); /// - /// 收入/支出 + /// 金额 /// - public BalanceRecordTypeEnumType Type { get; set; } - - public string TypeDesc => Type.GetDescription(); + [JsonIgnore] + public decimal CurrentAmount { get; set; } /// /// 金额 /// - public decimal Amount { get; set; } + public string Amount => CurrentAmount.ToString("f2"); + /// + /// 营业点 + /// public string BusinessPlaceName { get; set; } - public string BusinessShiftName { get; set; } - /// - /// 数据状态 + /// 餐次 /// - public BalanceRecordStatusEnumType Status { get; set; } + public ShiftEnumType? ShiftType { get; set; } /// - /// 数据状态描述 + /// 餐次 /// - public string StatusDesc => Status.GetDescription(); + public string ShiftTypeDesc => ShiftType?.GetDescription(); /// - /// 记录产生日期 + /// 消费时间 /// public DateTime CostDateTime { get; set; } - /// /// 消费应用类型 /// @@ -61,3 +62,18 @@ public class BalanceRecordUserResponse /// public string ApplicationTypeDesc => ApplicationType.GetDescription(); } + + +public class BalanceRecordUserResultResponse +{ + [JsonIgnore] + public decimal CurrentMonthSum { get; set; } + + /// + /// 当前月份总和 + /// + public string MonthSum => CurrentMonthSum.ToString("f2"); + + + public Pagination Items { get; set; } +} diff --git a/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs b/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs index 8b4b8c07..ea6a26cc 100644 --- a/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs @@ -11,7 +11,7 @@ public interface IBalanceService : IScopeDependency Task> GetPageByDeviceUniqueNoAsync(BalanceRecordPageByDeviceUniqueNoRequest request); - Task> GetPageByUserAsync(BalanceRecordUserPageRequest request); + Task GetPageByUserAsync(BalanceRecordUserPageRequest request); Task ObsoluteAsync(BalanceRecordObsoluteRequest request); diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index d0213415..f07ad2b4 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -515,44 +515,48 @@ public class BalanceService : IBalanceService return page; } - public async Task> GetPageByUserAsync(BalanceRecordUserPageRequest request) + public async Task GetPageByUserAsync(BalanceRecordUserPageRequest request) { - //当前用户 - var subjectId = _currentUser.GetIntSubjectId(); - var gainfo = await _dbContext.Queryable().Where(x => x.IdentityUserId == subjectId).FirstAsync(); var jinkoCode = _currentUser.GetUserClaim("jinko-code") ?? string.Empty; - if (jinkoCode.IsPresent()) - { - gainfo = await _dbContext.Queryable().Where(x => x.Code == jinkoCode).FirstAsync(); - } var page = await _dbContext.Queryable() .LeftJoin((record, ga) => record.UserNo == ga.No) .LeftJoin((record, ga, department) => ga.DepartmentNo == department.No) .LeftJoin((record, ga, department, bplace) => record.BusinessPlaceCode == bplace.Code) - .LeftJoin((record, ga, department, bplace, bshiftR) => bplace.Code == bshiftR.PlaceCode) - .LeftJoin((record, ga, department, bplace, bshiftR, shift) => shift.Code == bshiftR.ShiftCode) + .Where(record => record.Type == BalanceRecordTypeEnumType.Out) .WhereIF(request.SearchDateTimePeriod?.Start.HasValue == true, record => record.CostDate >= request.SearchDateTimePeriod.Start) .WhereIF(request.SearchDateTimePeriod?.End.HasValue == true, record => record.CostDate <= request.SearchDateTimePeriod.End) .WhereIF(request.ApplicationType.HasValue, record => record.ApplicationType == request.ApplicationType) - .Where((record, ga) => ga.Code == gainfo.Code) + .Where((record, ga) => ga.Code == jinkoCode) .OrderBy(record => record.CreateTime, OrderByType.Desc) - .Select((record, ga, department, bplace, bshiftR, shift) => new BalanceRecordUserResponse + .Select((record, ga, department, bplace) => new BalanceRecordUserPageResponse { Id = record.Id, - Amount = record.Amount, - Type = record.Type, - Status = record.Status, + CurrentAmount = record.Amount, Source = record.Source, No = record.No, BusinessPlaceName = bplace.Name, - BusinessShiftName = shift.Name, + ShiftType = record.ShiftType, CostDateTime = record.CostDateTime, ApplicationType = record.ApplicationType, }) .ToPageListAsync(request); - return page; + var now = DateTime.Now; + var monthStart = new DateTime(now.Year, now.Month, 1); + var monthEnd = monthStart.AddMonths(1).AddSeconds(-1); + + var monthSum = await _dbContext.Queryable() + .Where(x => x.CostDateTime >= monthStart && x.CostDateTime <= monthEnd) + .Where(x => x.Type == BalanceRecordTypeEnumType.Out) + .Where(x => x.UserCode == jinkoCode) + .SumAsync(x => SqlFunc.Abs(x.Amount)); + + return new BalanceRecordUserResultResponse + { + CurrentMonthSum = monthSum, + Items = page + }; } public async Task ObsoluteAsync(BalanceRecordObsoluteRequest request)