fix 调整生日券退款.增加数据上传
This commit is contained in:
@@ -7,6 +7,7 @@ using Dlhis.Constants;
|
|||||||
using Dlhis.Entity.Basic.Entity;
|
using Dlhis.Entity.Basic.Entity;
|
||||||
using Dlhis.Entity.Canteen.Entities;
|
using Dlhis.Entity.Canteen.Entities;
|
||||||
using Dlhis.Entity.Canteen.Entities.EMealVoucher;
|
using Dlhis.Entity.Canteen.Entities.EMealVoucher;
|
||||||
|
using Dlhis.Entity.Canteen.Entities.Voucher;
|
||||||
using Dlhis.Entity.Canteen.Enums;
|
using Dlhis.Entity.Canteen.Enums;
|
||||||
using Dlhis.Entity.Device;
|
using Dlhis.Entity.Device;
|
||||||
using Dlhis.Entity.Device.Entities;
|
using Dlhis.Entity.Device.Entities;
|
||||||
@@ -203,6 +204,25 @@ public class BalanceService : IBalanceService
|
|||||||
.ExecuteCommandThrowVersionAsync();
|
.ExecuteCommandThrowVersionAsync();
|
||||||
}, 5);
|
}, 5);
|
||||||
}
|
}
|
||||||
|
else if (balanceRecord.Source == BalanceRecordSourceEnumType.Birthday)
|
||||||
|
{
|
||||||
|
//生日券消费退款
|
||||||
|
throw new UserFriendlyException("不支持生日券消费退款");
|
||||||
|
//var voucherNo = balanceRecord.Remark.Replace("(生日券消费)", "");
|
||||||
|
|
||||||
|
//await CommonHelper.RetryAsync(async () =>
|
||||||
|
//{
|
||||||
|
// var voucher = await _dbContext.Queryable<VoucherEntity>().Where(x => x.No == voucherNo).SingleAsync();
|
||||||
|
// var amount = Math.Abs(balanceRecord.Amount);
|
||||||
|
// await _dbContext.Updateable<VoucherEntity>()
|
||||||
|
// .SetColumns(x => x.Version == x.Version + 1)
|
||||||
|
// .SetColumns(x => x.Balance == x.Balance + amount)
|
||||||
|
// .SetColumns(x => x.ModifiedTime == DateTime.Now)
|
||||||
|
// .Where(x => x.No == voucherNo && x.Version == voucher.Version)
|
||||||
|
// .ExecuteCommandThrowVersionAsync();
|
||||||
|
|
||||||
|
//},5);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await _balanceRepository.CalculateBalanceAsync(balanceRecord.UserCode);
|
await _balanceRepository.CalculateBalanceAsync(balanceRecord.UserCode);
|
||||||
@@ -413,6 +433,7 @@ public class BalanceService : IBalanceService
|
|||||||
{
|
{
|
||||||
var balanceInfo = await _dbContext.Queryable<BalanceRecordEntity>().Where(x => x.No == request.No).SingleAsync();
|
var balanceInfo = await _dbContext.Queryable<BalanceRecordEntity>().Where(x => x.No == request.No).SingleAsync();
|
||||||
balanceInfo.ThrowIfNull("明细数据不存在");
|
balanceInfo.ThrowIfNull("明细数据不存在");
|
||||||
|
BalanceRecordSourceConstants.IgnoreSources.Contains(balanceInfo.Source).ThrowIfTrue("类型不支持");
|
||||||
(balanceInfo.Status != BalanceRecordStatusEnumType.Valid || balanceInfo.Type != BalanceRecordTypeEnumType.Out).ThrowIfTrue("消费明细状态有误");
|
(balanceInfo.Status != BalanceRecordStatusEnumType.Valid || balanceInfo.Type != BalanceRecordTypeEnumType.Out).ThrowIfTrue("消费明细状态有误");
|
||||||
|
|
||||||
balanceInfo.Status = BalanceRecordStatusEnumType.Obsolute;
|
balanceInfo.Status = BalanceRecordStatusEnumType.Obsolute;
|
||||||
|
|||||||
98
Src/Dlhis.ScheduledTask/Jobs/BirthdayCostUploadJob.cs
Normal file
98
Src/Dlhis.ScheduledTask/Jobs/BirthdayCostUploadJob.cs
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
using Dlhis.Entity.Canteen.Entities;
|
||||||
|
using Dlhis.Entity.Canteen.Entities.Voucher;
|
||||||
|
using Dlhis.Entity.Canteen.Enums;
|
||||||
|
using Dlhis.Jip.Api;
|
||||||
|
using Dlhis.Jip.Api.Requests;
|
||||||
|
using Dlhis.ScheduledTask.Attributes;
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
|
namespace Dlhis.ScheduledTask.Jobs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生日券发放消费上传
|
||||||
|
/// </summary>
|
||||||
|
[RecurringJob(nameof(BirthdayCostUploadJob), "0 0 0 10 * ? ", Name = "生日券发放消费上传")]
|
||||||
|
public class BirthdayCostUploadJob : BaseJob
|
||||||
|
{
|
||||||
|
|
||||||
|
public BirthdayCostUploadJob(IServiceProvider serviceProvider) : base(serviceProvider)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task RunAsync(IServiceProvider serviceProvider)
|
||||||
|
{
|
||||||
|
var jipApi = serviceProvider.GetService<IJinkoJipApi>();
|
||||||
|
|
||||||
|
var now = DateTime.Now;
|
||||||
|
|
||||||
|
var year = now.Month == 1 ? now.Year - 1 : now.Year;
|
||||||
|
var month = now.Month == 1 ? 12 : now.Month - 1;
|
||||||
|
|
||||||
|
var s = new DateTime(year, month, 1);
|
||||||
|
var e = s.AddMonths(1);
|
||||||
|
var endDayOfMonth = e.AddDays(-1);
|
||||||
|
|
||||||
|
var userCodeAll = await DbContext.Queryable<UserBalanceEntity>()
|
||||||
|
.Select(x => x.UserCode)
|
||||||
|
.Distinct()
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
//获取所有人员的生日券发放和消费数据,逐人上传
|
||||||
|
foreach (var userCode in userCodeAll)
|
||||||
|
{
|
||||||
|
var request = new UploadCostRequest
|
||||||
|
{
|
||||||
|
Data = new List<UploadCostItemRequest>(2)
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//查询生日券发放数据
|
||||||
|
var voucher = await DbContext.Queryable<VoucherEntity>()
|
||||||
|
.LeftJoin<VoucherUserInfoEntity>((x, xu) => x.No == xu.VoucherNo)
|
||||||
|
.Where((x, xu) => xu.UserCode == userCode)// 指定用户
|
||||||
|
.Where(x => x.Type == VoucherEnumType.Birthday)
|
||||||
|
.Where(x => x.ClaimDateTime >= s && x.ClaimDateTime < e)
|
||||||
|
.Select((x, xu) => new
|
||||||
|
{
|
||||||
|
x.OriginalBalance
|
||||||
|
})
|
||||||
|
.SingleAsync();
|
||||||
|
|
||||||
|
if (voucher != null)
|
||||||
|
{
|
||||||
|
request.Data.Add(new UploadCostItemRequest
|
||||||
|
{
|
||||||
|
WorkCode = userCode,
|
||||||
|
Code = "2088",
|
||||||
|
BeginDate = endDayOfMonth.ToString("yyyy-MM-dd"),
|
||||||
|
Charge = voucher.OriginalBalance
|
||||||
|
});
|
||||||
|
}
|
||||||
|
//生日券消费数据
|
||||||
|
var cost = await DbContext.Queryable<BalanceRecordEntity>()
|
||||||
|
.Where(record => record.UserCode == userCode)// 指定用户
|
||||||
|
.Where(record => record.CostDate >= s && record.CostDate < e)
|
||||||
|
.Where(record => record.Source == BalanceRecordSourceEnumType.Birthday)
|
||||||
|
.Where(record => record.Type == BalanceRecordTypeEnumType.Out && record.Status == BalanceRecordStatusEnumType.Valid)
|
||||||
|
.SumAsync(record => SqlFunc.Abs(SqlFunc.IsNull(record.Amount, 0)));
|
||||||
|
|
||||||
|
request.Data.Add(new UploadCostItemRequest
|
||||||
|
{
|
||||||
|
WorkCode = userCode,
|
||||||
|
Code = "2089",
|
||||||
|
BeginDate = endDayOfMonth.ToString("yyyy-MM-dd"),
|
||||||
|
Charge = cost
|
||||||
|
});
|
||||||
|
|
||||||
|
var response = await jipApi.UploadCostAsync(request);
|
||||||
|
var handleData = response.Data.Where(x => x.Success == "S").ToList();
|
||||||
|
Logger.LogInformation("BirthdayCostUploadJob生日券发放消费上传成功{userCode}", userCode);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.LogError(ex, "BirthdayCostUploadJob生日券发放消费上传失败-{userCode}:{error}", userCode, ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user