feat 餐补余额导入
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using Dlhis.Canteen.MealSupplementRecord.Request;
|
using Dlhis.Canteen.MealSupplementRecord.Request;
|
||||||
using Dlhis.Canteen.MealSupplementRecord.Response;
|
using Dlhis.Canteen.MealSupplementRecord.Response;
|
||||||
using Dlhis.Canteen.MealSupplementRecord.Services;
|
using Dlhis.Canteen.MealSupplementRecord.Services;
|
||||||
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
|
||||||
using Kurisu.Core.DataAccess.Dto;
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@@ -44,4 +45,14 @@ public class MealSupplementsRecordController
|
|||||||
{
|
{
|
||||||
return await _mealSupplementRecordService.GetMyMealSupplementRecords(request);
|
return await _mealSupplementRecordService.GetMyMealSupplementRecords(request);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/// <summary>
|
||||||
|
/// 期初餐补余额导入
|
||||||
|
/// </summary>
|
||||||
|
[HttpPost("init/import")]
|
||||||
|
[Transactional]
|
||||||
|
public async Task InitImportAsync(List<MealSupplementInitImportRequest> requests)
|
||||||
|
{
|
||||||
|
await _mealSupplementRecordService.InitImportAsync(requests);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace Dlhis.Canteen.MealSupplementRecord.Request;
|
||||||
|
|
||||||
|
public class MealSupplementInitImportRequest
|
||||||
|
{
|
||||||
|
[Required(ErrorMessage = "工号不能为空")]
|
||||||
|
public string Code { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 余额
|
||||||
|
/// </summary>
|
||||||
|
[Range(1, int.MaxValue, ErrorMessage = "余额有误")]
|
||||||
|
public decimal Balance { get; set; }
|
||||||
|
}
|
||||||
@@ -9,8 +9,11 @@ public class MealSupplementRecordMyRequest : IValidatableObject
|
|||||||
|
|
||||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||||
{
|
{
|
||||||
SearchDateTimePeriod.End = SearchDateTimePeriod.End.Value.AddDays(1).AddSeconds(-1);
|
if (SearchDateTimePeriod.End.HasValue)
|
||||||
|
{
|
||||||
|
SearchDateTimePeriod.End = SearchDateTimePeriod.End.Value.AddDays(1).AddSeconds(-1);
|
||||||
|
}
|
||||||
|
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,4 +9,6 @@ public interface IMealSupplementRecordService : IScopeDependency
|
|||||||
Task<Pagination<MealSupplementRecordResponse>> GetPageAsync(MealSupplementRecordRequest request);
|
Task<Pagination<MealSupplementRecordResponse>> GetPageAsync(MealSupplementRecordRequest request);
|
||||||
|
|
||||||
Task<MealSupplementRecordMyResponse> GetMyMealSupplementRecords(MealSupplementRecordMyRequest request);
|
Task<MealSupplementRecordMyResponse> GetMyMealSupplementRecords(MealSupplementRecordMyRequest request);
|
||||||
|
|
||||||
|
Task InitImportAsync(List<MealSupplementInitImportRequest> requests);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ using Dlhis.Canteen.MealSupplementRecord.Response;
|
|||||||
using Dlhis.Entity.Basic.Entity;
|
using Dlhis.Entity.Basic.Entity;
|
||||||
using Dlhis.Entity.Basic.Enums;
|
using Dlhis.Entity.Basic.Enums;
|
||||||
using Dlhis.Entity.Canteen.Entities;
|
using Dlhis.Entity.Canteen.Entities;
|
||||||
|
using Dlhis.Entity.Canteen.Enums;
|
||||||
using Dlhis.Sys.Api;
|
using Dlhis.Sys.Api;
|
||||||
|
using Kurisu.AspNetCore.Utils;
|
||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
using Kurisu.Core.DataAccess.Dto;
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
using Kurisu.Core.User.Abstractions;
|
using Kurisu.Core.User.Abstractions;
|
||||||
@@ -15,7 +17,6 @@ namespace Dlhis.Canteen.MealSupplementRecord.Services.Implements;
|
|||||||
|
|
||||||
public class MealSupplementRecordService : IMealSupplementRecordService
|
public class MealSupplementRecordService : IMealSupplementRecordService
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly IDbContext _dbContext;
|
private readonly IDbContext _dbContext;
|
||||||
private readonly ICurrentUser _currentUser;
|
private readonly ICurrentUser _currentUser;
|
||||||
private readonly ITenantApi _tenantApi;
|
private readonly ITenantApi _tenantApi;
|
||||||
@@ -36,8 +37,8 @@ public class MealSupplementRecordService : IMealSupplementRecordService
|
|||||||
.WhereIF(request.Workplace.IsPresent(), x => x.Workplace == request.Workplace)
|
.WhereIF(request.Workplace.IsPresent(), x => x.Workplace == request.Workplace)
|
||||||
.WhereIF(request.Factory.IsPresent(), x => x.Factory == request.Factory)
|
.WhereIF(request.Factory.IsPresent(), x => x.Factory == request.Factory)
|
||||||
.WhereIF(request.DateTimePeriod?.Start.HasValue == true
|
.WhereIF(request.DateTimePeriod?.Start.HasValue == true
|
||||||
&& request.DateTimePeriod?.End.HasValue == true,
|
&& request.DateTimePeriod?.End.HasValue == true,
|
||||||
x => x.Date >= request.DateTimePeriod.Start && x.Date <= request.DateTimePeriod.End)
|
x => x.Date >= request.DateTimePeriod.Start && x.Date <= request.DateTimePeriod.End)
|
||||||
.WhereIF(request.Search.IsPresent(), (x, ga) => x.Code == request.Search || ga.Name == request.Search)
|
.WhereIF(request.Search.IsPresent(), (x, ga) => x.Code == request.Search || ga.Name == request.Search)
|
||||||
.Select((x, ga) => new MealSupplementRecordResponse
|
.Select((x, ga) => new MealSupplementRecordResponse
|
||||||
{
|
{
|
||||||
@@ -70,7 +71,6 @@ public class MealSupplementRecordService : IMealSupplementRecordService
|
|||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -110,4 +110,77 @@ public class MealSupplementRecordService : IMealSupplementRecordService
|
|||||||
Items = data,
|
Items = data,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public async Task InitImportAsync(List<MealSupplementInitImportRequest> requests)
|
||||||
|
{
|
||||||
|
var today = DateTime.Now.Date;
|
||||||
|
foreach (var request in requests)
|
||||||
|
{
|
||||||
|
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == request.Code).FirstAsync();
|
||||||
|
if (gainfo == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
await CommonHelper.RetryAsync(async () =>
|
||||||
|
{
|
||||||
|
var mealUser = await _dbContext.Queryable<GainfoMealEntity>().Where(x => x.UserCode == request.Code).FirstAsync();
|
||||||
|
if (mealUser == null)
|
||||||
|
{
|
||||||
|
mealUser = new GainfoMealEntity
|
||||||
|
{
|
||||||
|
UserNo = gainfo.No,
|
||||||
|
UserCode = gainfo.Code,
|
||||||
|
Balance = 0,
|
||||||
|
BalanceOfRecharge = 0,
|
||||||
|
BalanceOfSubsidies = 0,
|
||||||
|
Version = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
await _dbContext.InsertAsync(mealUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
var b = mealUser.Balance += request.Balance;
|
||||||
|
|
||||||
|
await _dbContext.Updateable<GainfoMealEntity>()
|
||||||
|
.SetColumns(x => x.Version == x.Version + 1)
|
||||||
|
.SetColumns(x => x.Balance == b)
|
||||||
|
.SetColumns(x => x.ModifiedTime == DateTime.Now)
|
||||||
|
.Where(x => x.UserCode == mealUser.UserCode && x.Version == mealUser.Version)
|
||||||
|
.ExecuteCommandThrowVersionAsync();
|
||||||
|
}, 5);
|
||||||
|
|
||||||
|
await _dbContext.InsertAsync(new BalanceRecordEntity
|
||||||
|
{
|
||||||
|
Amount = request.Balance,
|
||||||
|
ApplicationType = CanteenApplicaitonTypeEnumType.MealSupplement,
|
||||||
|
Type = BalanceRecordTypeEnumType.In,
|
||||||
|
BusinessPlaceCode = null,
|
||||||
|
BusinessShiftCode = null,
|
||||||
|
ShiftType = null,
|
||||||
|
CostDate = today,
|
||||||
|
CostDateTime = DateTime.Now,
|
||||||
|
UserNo = gainfo.No,
|
||||||
|
No = SnowFlakeHelper.Instance.NextId().ToString(),
|
||||||
|
UserCode = gainfo.Code,
|
||||||
|
TenantId = gainfo.Factory,
|
||||||
|
Status = BalanceRecordStatusEnumType.Valid,
|
||||||
|
Source = BalanceRecordSourceEnumType.LocalTenantSubsidies,
|
||||||
|
Remark = "期初导入",
|
||||||
|
CostId = gainfo.CostId,
|
||||||
|
SubsidiesFromMonth = today.ToString("yyyyMM"),
|
||||||
|
OriginTenantId = gainfo.Factory,
|
||||||
|
Werks = gainfo.Werks,
|
||||||
|
Name = gainfo.Name,
|
||||||
|
IsCostCrossTenant = false,
|
||||||
|
DepartmentNo = gainfo.DepartmentNo,
|
||||||
|
DeviceUniqueNo = null,
|
||||||
|
|
||||||
|
CreatedBy = 1,
|
||||||
|
CreateTime = DateTime.Now,
|
||||||
|
ModifiedBy = 1,
|
||||||
|
ModifiedTime = DateTime.Now,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user