feat 手动余额导入重算功能
This commit is contained in:
@@ -137,7 +137,7 @@ public class BalancesController : ControllerBase
|
||||
{
|
||||
return await _balanceService.GetConsumeDeviceAsync(request);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 海宁餐补数据写入
|
||||
/// </summary>
|
||||
@@ -161,4 +161,17 @@ public class BalancesController : ControllerBase
|
||||
{
|
||||
return await _balanceService.HainingDownloadAsync(userCode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 手动处理余额
|
||||
/// </summary>
|
||||
/// <param name="requests"></param>
|
||||
[Authorize(Roles = "admin")]
|
||||
[HttpPost("manuallyRecalc")]
|
||||
[IgnoreTenant]
|
||||
[Transactional]
|
||||
public async Task ManuallyImportBalanceAndReCalcAsync(List<BalanceManuallyImportRequest> requests)
|
||||
{
|
||||
await _balanceService.ManuallyImportBalanceAndReCalcAsync(requests);
|
||||
}
|
||||
}
|
||||
11
Src/Dlhis.Canteen/Order/Request/BalanceManuallyImport.cs
Normal file
11
Src/Dlhis.Canteen/Order/Request/BalanceManuallyImport.cs
Normal file
@@ -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; }
|
||||
}
|
||||
@@ -34,4 +34,6 @@ public interface IBalanceService : IScopeDependency
|
||||
Task HainingImportAsync(BalanceHainingImportRequest request);
|
||||
|
||||
Task<List<BalanceHainingDownloadResponse>> HainingDownloadAsync(string userCode);
|
||||
|
||||
Task ManuallyImportBalanceAndReCalcAsync(List<BalanceManuallyImportRequest> requests);
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task ManuallyImportBalanceAndReCalcAsync(List<BalanceManuallyImportRequest> requests)
|
||||
{
|
||||
foreach (var request in requests)
|
||||
{
|
||||
var gainfo = await _dbContext.Queryable<GainfoEntity>().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<GainfoMealEntity>().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<BalanceRecordEntity>()
|
||||
.Where(x => x.UserCode == gainfo.Code)
|
||||
.Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
|
||||
.SumAsync(x => x.Amount);
|
||||
|
||||
await _dbContext.Updateable<GainfoMealEntity>()
|
||||
.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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取离线设备
|
||||
|
||||
@@ -28,8 +28,16 @@ public enum CanteenApplicationTypeEnumType
|
||||
/// </summary>
|
||||
[Description("餐补发放")]
|
||||
MealSupplement = 400,
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 余额转入
|
||||
/// </summary>
|
||||
[Description("余额转入")]
|
||||
BalanceMigration
|
||||
}
|
||||
BalanceMigration = 500,
|
||||
|
||||
/// <summary>
|
||||
/// 手动写入
|
||||
/// </summary>
|
||||
[Description("手动写入")]
|
||||
Manually = 600,
|
||||
}
|
||||
Reference in New Issue
Block a user