feat 提供跳板机数据上传接口
This commit is contained in:
32
Src/Dlhis.Canteen/Order/Controllers/MiddleController.cs
Normal file
32
Src/Dlhis.Canteen/Order/Controllers/MiddleController.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Dlhis.Canteen.Order.Response;
|
||||
using Dlhis.Canteen.Order.Services;
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Dlhis.Canteen.Order.Controllers;
|
||||
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class MiddleController : ControllerBase
|
||||
{
|
||||
private readonly IMiddleService _middleService;
|
||||
|
||||
public MiddleController(IMiddleService middleService)
|
||||
{
|
||||
_middleService = middleService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 跳板机离线数据上传
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[IgnoreTenant]
|
||||
[HttpPost("upload")]
|
||||
public async Task<OrderResultResponse> MiddleUpload(BalanceRecordEntity entity)
|
||||
{
|
||||
return await _middleService.MiddleUploadAsync(entity);
|
||||
}
|
||||
}
|
||||
9
Src/Dlhis.Canteen/Order/Services/IMiddleService.cs
Normal file
9
Src/Dlhis.Canteen/Order/Services/IMiddleService.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using Dlhis.Canteen.Order.Response;
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
|
||||
namespace Dlhis.Canteen.Order.Services;
|
||||
|
||||
public interface IMiddleService : IScopeDependency
|
||||
{
|
||||
Task<OrderResultResponse> MiddleUploadAsync(BalanceRecordEntity entity);
|
||||
}
|
||||
73
Src/Dlhis.Canteen/Order/Services/Implements/MiddleService.cs
Normal file
73
Src/Dlhis.Canteen/Order/Services/Implements/MiddleService.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using Dlhis.Canteen.Order.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils;
|
||||
|
||||
namespace Dlhis.Canteen.Order.Services.Implements;
|
||||
|
||||
public class MiddleService : IMiddleService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
|
||||
public MiddleService(IDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<OrderResultResponse> MiddleUploadAsync(BalanceRecordEntity entity)
|
||||
{
|
||||
entity.Id = 0;
|
||||
await _dbContext.InsertAsync(entity);
|
||||
|
||||
await CommonHelper.RetryAsync(async () =>
|
||||
{
|
||||
var mealUser = await _dbContext.Queryable<GainfoMealEntity>().Where(x => x.UserCode == entity.UserCode).FirstAsync();
|
||||
if (mealUser == null)
|
||||
{
|
||||
mealUser = new GainfoMealEntity
|
||||
{
|
||||
UserNo = entity.No,
|
||||
UserCode = entity.UserCode,
|
||||
Balance = 0,
|
||||
BalanceOfRecharge = 0,
|
||||
BalanceOfSubsidies = 0,
|
||||
Version = 0
|
||||
};
|
||||
|
||||
await _dbContext.InsertAsync(mealUser);
|
||||
}
|
||||
|
||||
//重新核算
|
||||
var balance = await _dbContext.Queryable<BalanceRecordEntity>()
|
||||
.Where(x => x.UserCode == entity.UserCode)
|
||||
.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 == mealUser.UserCode && x.Version == mealUser.Version)
|
||||
.ExecuteCommandThrowVersionAsync();
|
||||
}, 5);
|
||||
|
||||
//获取人员余额
|
||||
return await _dbContext.Queryable<GainfoMealEntity>()
|
||||
.LeftJoin<GainfoEntity>((x, ga) => x.UserNo == ga.No)
|
||||
.LeftJoin<DepartmentEntity>((x, ga, department) => ga.DepartmentNo == department.No)
|
||||
.Where(x => x.UserNo == entity.No)
|
||||
.Select((x, ga, department) => new OrderResultResponse
|
||||
{
|
||||
UserCode = ga.Code,
|
||||
UserName = ga.Name,
|
||||
DepartmentNo = ga.DepartmentNo,
|
||||
DepartmentName = department.Name,
|
||||
CurrentBalance = x.Balance
|
||||
})
|
||||
.SingleAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user