diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs index 6e9b3ada..4481a860 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs @@ -137,7 +137,7 @@ public class DevicePermissionService : IDevicePermissionService public async Task> GetAssignmentsAsync(DeviceGetAssignmentsRequest request) { return await _dbContext.Queryable() - .WhereIF(request.TenantId.IsPresent(), x => x.TenantId == request.TenantId) + .WhereIF(request.TenantId.IsPresent() && request.AssignType == AssignTypeEnumType.Department, x => x.TenantId == request.TenantId) .Where(x => x.AssignType == request.AssignType) .Where(x => x.AssignValue == request.AssignValue) .Where(x => x.UniqueType == request.UniqueType) diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfoMealController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfoMealController.cs index b599aa87..24b50fc6 100644 --- a/Src/Dlhis.Basic/Organization/Controllers/GainfoMealController.cs +++ b/Src/Dlhis.Basic/Organization/Controllers/GainfoMealController.cs @@ -38,9 +38,7 @@ public class GainfoMealController : ControllerBase /// 迁移 /// /// - [Authorize(Roles = "admin")] [Transactional] - [Authorize(Roles = "admin,tenant-admin")] [HttpPost("migration")] public async Task MigrationAsync(GainfoBalanceMigrationRequest request) { diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoMealService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoMealService.cs index 0b816dc9..0e62de89 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoMealService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoMealService.cs @@ -68,7 +68,6 @@ public class GainfoMealService : IGainfoMealService return page; } - /// public async Task MigrationAsync(GainfoBalanceMigrationRequest request) { //只能针对离职人员 @@ -81,20 +80,53 @@ public class GainfoMealService : IGainfoMealService return; } - //清空余额 + var now = DateTime.Now; + + await _dbContext.InsertAsync(new BalanceRecordEntity + { + No = SnowFlakeHelper.Instance.NextId().ToString(), + UserNo = gainfoLeave.No, + Name = gainfoLeave.Name, + UserCode = gainfoLeave.Code, + DepartmentNo = gainfoLeave.DepartmentNo, + Source = BalanceRecordSourceEnumType.BalanceMigration, + Type = BalanceRecordTypeEnumType.In, + Amount = -Math.Abs(beforeBalance), + BusinessPlaceCode = null, + BusinessShiftCode = null, + ShiftType = null, + CostDate = now.Date, + DeviceUniqueNo = null, + SubsidiesFromMonth = now.ToString("yyyyMM"), + IP = null, + CostId = gainfoLeave.CostId, + OriginTenantId = gainfoLeave.Factory, + IsCostCrossTenant = false, + Status = BalanceRecordStatusEnumType.Valid, + CostDateTime = DateTime.Now, + Remark = $"{gainfoLeave.Code}:余额转出", + ApplicationType = CanteenApplicationTypeEnumType.BalanceMigration, + TenantId = gainfoLeave.Factory, + Werks = gainfoLeave.Werks, + IsDeleted = false, + }); + + var beforeBalanceAmount = await _dbContext.Queryable() + .Where(x => x.UserCode == gainfoLeave.Code) + .Where(x => x.Status == BalanceRecordStatusEnumType.Valid) + .SumAsync(x => x.Amount); + await _dbContext.Updateable() - .SetColumns(x => x.Balance == 0) + .SetColumns(x => x.Balance == beforeBalanceAmount) .SetColumns(x => x.ModifiedTime == DateTime.Now) .SetColumns(x => x.Version == x.Version + 1) .Where(x => x.UserCode == request.BeforeCode) //不需要判断version .ExecuteCommandAsync(); - + //转移到现有人员 var gainfo = await _dbContext.Queryable().Where(x => x.Code == request.NowCode).SingleAsync(); gainfo.ThrowIfNull("目标人员不存在"); - var now = DateTime.Now; - await _dbContext.InsertAsync(new BalanceRecordEntity { No = SnowFlakeHelper.Instance.NextId().ToString(), @@ -126,6 +158,7 @@ public class GainfoMealService : IGainfoMealService var nowGainfoMeal = await _dbContext.Queryable().Where(x => x.UserCode == request.NowCode).SingleAsync(); var nowBalance = nowGainfoMeal.Balance + beforeBalance; + await _dbContext.Updateable() .SetColumns(x => x.Balance == nowBalance) .SetColumns(x => x.ModifiedTime == DateTime.Now) diff --git a/Src/Dlhis.Entity/Canteen/Enums/CanteenApplicationTypeEnumType.cs b/Src/Dlhis.Entity/Canteen/Enums/CanteenApplicationTypeEnumType.cs index a1871cf5..54cc684e 100644 --- a/Src/Dlhis.Entity/Canteen/Enums/CanteenApplicationTypeEnumType.cs +++ b/Src/Dlhis.Entity/Canteen/Enums/CanteenApplicationTypeEnumType.cs @@ -32,7 +32,7 @@ public enum CanteenApplicationTypeEnumType /// /// 余额转入 /// - [Description("余额转入")] + [Description("余额迁移")] BalanceMigration = 500, ///