diff --git a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs index f405b28c..c9c66116 100644 --- a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs +++ b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs @@ -137,7 +137,7 @@ public class BalancesController : ControllerBase { return await _balanceService.GetConsumeDeviceAsync(request); } - + /// /// 海宁餐补数据写入 /// @@ -161,4 +161,17 @@ public class BalancesController : ControllerBase { return await _balanceService.HainingDownloadAsync(userCode); } + + /// + /// 手动处理余额 + /// + /// + [Authorize(Roles = "admin")] + [HttpPost("manuallyRecalc")] + [IgnoreTenant] + [Transactional] + public async Task ManuallyImportBalanceAndReCalcAsync(List requests) + { + await _balanceService.ManuallyImportBalanceAndReCalcAsync(requests); + } } \ No newline at end of file diff --git a/Src/Dlhis.Canteen/Order/Request/BalanceManuallyImport.cs b/Src/Dlhis.Canteen/Order/Request/BalanceManuallyImport.cs new file mode 100644 index 00000000..24786ef7 --- /dev/null +++ b/Src/Dlhis.Canteen/Order/Request/BalanceManuallyImport.cs @@ -0,0 +1,11 @@ +using System.ComponentModel.DataAnnotations; + +namespace Dlhis.Canteen.Order.Request; + +public class BalanceManuallyImportRequest +{ + [Required] + public string UserCode { get; set; } + + public decimal Balance { get; set; } +} \ No newline at end of file diff --git a/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs b/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs index 33fb3a07..f7466ac5 100644 --- a/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs @@ -34,4 +34,6 @@ public interface IBalanceService : IScopeDependency Task HainingImportAsync(BalanceHainingImportRequest request); Task> HainingDownloadAsync(string userCode); + + Task ManuallyImportBalanceAndReCalcAsync(List requests); } \ No newline at end of file diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index 51db85c6..16e4002a 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -1,7 +1,6 @@ using Dlhis.Basic.Api; using Dlhis.Canteen.Order.Request; using Dlhis.Canteen.Order.Response; -using Dlhis.Canteen.Setting.Services; using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Canteen.Entities; using Dlhis.Entity.Canteen.Enums; @@ -25,19 +24,16 @@ public class BalanceService : IBalanceService private readonly IDbContext _dbContext; private readonly ICurrentUser _currentUser; private readonly ITenantApi _tenantApi; - private readonly ICanteenSettingService _canteenSettingService; private readonly IBusinessPlacePermissionsApi _businessPlacePermissionsApi; public BalanceService(IDbContext dbContext, ICurrentUser currentUser, ITenantApi tenantApi, - ICanteenSettingService canteenSettingService, IBusinessPlacePermissionsApi businessPlacePermissionsApi) { _dbContext = dbContext; _currentUser = currentUser; _tenantApi = tenantApi; - _canteenSettingService = canteenSettingService; _businessPlacePermissionsApi = businessPlacePermissionsApi; } @@ -613,6 +609,76 @@ public class BalanceService : IBalanceService .ToListAsync(); } + /// + public async Task ManuallyImportBalanceAndReCalcAsync(List requests) + { + foreach (var request in requests) + { + var gainfo = await _dbContext.Queryable().Where(x => x.Code == request.UserCode).SingleAsync(); + + await _dbContext.InsertAsync(new BalanceRecordEntity + { + No = "M" + SnowFlakeHelper.Instance.NextId(), + UserNo = gainfo.No, + Name = gainfo.Name, + UserCode = gainfo.Code, + DepartmentNo = gainfo.DepartmentNo, + Source = BalanceRecordSourceEnumType.OtherTenantSubsidies, + Type = BalanceRecordTypeEnumType.In, + Amount = request.Balance, + BusinessPlaceCode = null, + BusinessShiftCode = null, + ShiftType = null, + CostDate = DateTime.Now.Date, + DeviceUniqueNo = null, + SubsidiesFromMonth = DateTime.Now.ToString("yyyyMM"), + IP = null, + CostId = gainfo.CostId, + OriginTenantId = gainfo.Factory, + IsCostCrossTenant = false, + Status = BalanceRecordStatusEnumType.Valid, + CostDateTime = DateTime.Now, + Remark = "手动写入余额", + ApplicationType = CanteenApplicationTypeEnumType.Manually, + TenantId = gainfo.Factory, + Werks = gainfo.Werks, + IsDeleted = false + }); + + await CommonHelper.RetryAsync(async () => + { + var gainfoMeal = await _dbContext.Queryable().Where(x => x.UserCode == gainfo.Code).FirstAsync(); + if (gainfoMeal == null) + { + gainfoMeal = new GainfoMealEntity + { + UserNo = gainfo.No, + UserCode = gainfo.Code, + Balance = 0, + BalanceOfRecharge = 0, + BalanceOfSubsidies = 0, + Version = 0 + }; + + await _dbContext.InsertAsync(gainfoMeal); + } + + //重新核算 + var balance = await _dbContext.Queryable() + .Where(x => x.UserCode == gainfo.Code) + .Where(x => x.Status == BalanceRecordStatusEnumType.Valid) + .SumAsync(x => x.Amount); + + await _dbContext.Updateable() + .SetColumns(x => x.Version == x.Version + 1) + .SetColumns(x => x.Balance == balance) + .SetColumns(x => x.ModifiedTime == DateTime.Now) + .Where(x => x.UserCode == gainfoMeal.UserCode && x.Version == gainfoMeal.Version) + .ExecuteCommandThrowVersionAsync(); + }, 5); + } + } + /// /// 获取离线设备 diff --git a/Src/Dlhis.Entity/Canteen/Enums/CanteenApplicationTypeEnumType.cs b/Src/Dlhis.Entity/Canteen/Enums/CanteenApplicationTypeEnumType.cs index 77bdf515..a1871cf5 100644 --- a/Src/Dlhis.Entity/Canteen/Enums/CanteenApplicationTypeEnumType.cs +++ b/Src/Dlhis.Entity/Canteen/Enums/CanteenApplicationTypeEnumType.cs @@ -28,8 +28,16 @@ public enum CanteenApplicationTypeEnumType /// [Description("餐补发放")] MealSupplement = 400, - - + + /// + /// 余额转入 + /// [Description("余额转入")] - BalanceMigration -} + BalanceMigration = 500, + + /// + /// 手动写入 + /// + [Description("手动写入")] + Manually = 600, +} \ No newline at end of file