remove 移除海宁消费代码

This commit is contained in:
2024-10-18 11:50:17 +08:00
parent 5d97795cfe
commit 323b7c3f5d
3 changed files with 2 additions and 166 deletions

View File

@@ -23,12 +23,10 @@ namespace Dlhis.Canteen.Order.Controllers;
public class BalancesController : ControllerBase public class BalancesController : ControllerBase
{ {
private readonly IBalanceService _balanceService; private readonly IBalanceService _balanceService;
private readonly IHainingBalanceService _hainingBalanceService;
public BalancesController(IBalanceService balanceService, IHainingBalanceService hainingBalanceService) public BalancesController(IBalanceService balanceService)
{ {
_balanceService = balanceService; _balanceService = balanceService;
_hainingBalanceService = hainingBalanceService;
} }
/// <summary> /// <summary>
@@ -63,7 +61,7 @@ public class BalancesController : ControllerBase
[Transactional(IsolationLevel.ReadCommitted)] [Transactional(IsolationLevel.ReadCommitted)]
public async Task RefundAsync(BalanceRecordRefundRequest request) public async Task RefundAsync(BalanceRecordRefundRequest request)
{ {
await _balanceService.RefundAsync(request.No); await _balanceService.RefundAsync(request.No);
} }
@@ -157,30 +155,6 @@ public class BalancesController : ControllerBase
return await _balanceService.AverageDailyAsync(request); return await _balanceService.AverageDailyAsync(request);
} }
/// <summary>
/// 海宁餐补数据写入
/// </summary>
/// <param name="request"></param>
[Transactional]
[IgnoreTenant]
[HttpPost("haining/import")]
public async Task Import(BalanceHainingImportRequest request)
{
await _hainingBalanceService.HainingImportAsync(request);
}
/// <summary>
/// 根据工号海宁餐补数据获取
/// </summary>
/// <param name="userCode">工号</param>
/// <returns></returns>
[IgnoreTenant]
[HttpGet("haining/list")]
public async Task<List<BalanceHainingDownloadResponse>> HainingDownloadAsync([Required(ErrorMessage = "工号不能为空")] string userCode)
{
return await _hainingBalanceService.HainingDownloadAsync(userCode);
}
/// <summary> /// <summary>
/// 手动处理余额 /// 手动处理余额
/// </summary> /// </summary>

View File

@@ -1,11 +0,0 @@
using Dlhis.Canteen.Order.Request;
using Dlhis.Canteen.Order.Response;
namespace Dlhis.Canteen.Order.Services;
public interface IHainingBalanceService : IScopeDependency
{
Task HainingImportAsync(BalanceHainingImportRequest request);
Task<List<BalanceHainingDownloadResponse>> HainingDownloadAsync(string userCode);
}

View File

@@ -1,127 +0,0 @@
using Dlhis.Canteen.Order.Request;
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.Extensions;
using SqlSugar;
namespace Dlhis.Canteen.Order.Services.Implements;
public class HainingBalanceService : IHainingBalanceService
{
private readonly IDbContext _dbContext;
public HainingBalanceService(IDbContext dbContext)
{
_dbContext = dbContext;
}
public async Task HainingImportAsync(BalanceHainingImportRequest request)
{
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == request.UserCode).SingleAsync()
?? await _dbContext.Queryable<GainfoLeaveEntity>().Where(x => x.Code == request.UserCode).SingleAsync();
gainfo.ThrowIfNull($"工号{request.UserCode}不存在");
var gainfoMeal = await _dbContext.Queryable<GainfoMealEntity>().Where(x => x.UserCode == request.UserCode).SingleAsync();
if (gainfoMeal == null)
{
gainfoMeal = new GainfoMealEntity
{
UserCode = gainfo.Code,
Balance = 0,
BalanceOfRecharge = 0,
BalanceOfSubsidies = 0,
Version = 0
};
await _dbContext.InsertAsync(gainfoMeal);
}
var businessPlaceInfo = await _dbContext.Queryable<BusinessPlaceEntity>()
.LeftJoin<BusinessPlaceShiftRelationshipEntity>((a, b) => a.Code == b.PlaceCode)
.LeftJoin<BusinessShiftEntity>((a, b, c) => b.ShiftCode == c.Code)
.Where((a, b, c) => a.CustomCode == request.BusinessPlaceCode)
.Select((a, b, c) => new
{
a.Code,
ShiftCode = c.Code,
a.TenantId
})
.SingleAsync();
if (request.Type == BalanceRecordTypeEnumType.Out)
{
businessPlaceInfo.ThrowIfNull($"营业点{request.BusinessPlaceCode}不存在");
}
await _dbContext.InsertAsync(new BalanceRecordEntity
{
Amount = request.Amount,
ApplicationType = request.ApplicationType,
Type = request.Type,
BusinessPlaceCode = businessPlaceInfo?.Code,
BusinessShiftCode = businessPlaceInfo?.ShiftCode,
ShiftType = request.ShiftType,
CostDate = request.CostDate,
CostDateTime = request.CostDateTime,
UserNo = gainfo.No,
No = request.No,
UserCode = gainfo.Code,
Status = BalanceRecordStatusEnumType.Valid,
Source = request.Source,
Remark = request.Remark,
CostId = gainfo.CostId,
TenantId = businessPlaceInfo?.TenantId ?? request.Factory,
OriginTenantId = gainfo.Factory,
Werks = gainfo.Werks,
Name = gainfo.Name,
IsCostCrossTenant = false,
DepartmentNo = gainfo.DepartmentNo,
DeviceUniqueNo = request.DeviceUniqueNo,
IsDeleted = false,
});
var newBalance = gainfoMeal.Balance += request.Amount;
await _dbContext.Updateable<GainfoMealEntity>()
.SetColumns(x => x.Balance == newBalance)
.SetColumns(x => x.ModifiedBy == 1)
.SetColumns(x => x.ModifiedTime == DateTime.Now)
.SetColumns(x => x.Version == x.Version + 1)
.Where(x => x.UserCode == request.UserCode && x.Version == gainfoMeal.Version)
.ExecuteCommandThrowVersionAsync("写入失败,正在消费中");
}
public async Task<List<BalanceHainingDownloadResponse>> HainingDownloadAsync(string userCode)
{
return await _dbContext.Queryable<BalanceRecordEntity>()
.LeftJoin<GainfoEntity>((record, ga) => record.UserNo == ga.No)
.LeftJoin<DepartmentEntity>((record, ga, department) => ga.DepartmentNo == department.No)
.LeftJoin<BusinessPlaceEntity>((record, ga, department, bPlace) => record.BusinessPlaceCode == bPlace.Code)
.Where(record => record.Status == BalanceRecordStatusEnumType.Valid)
.Where((record, ga) => ga.Code == userCode)
.OrderBy(record => record.CreateTime, OrderByType.Desc)
.Select((record, ga, department, bPlace) => new BalanceHainingDownloadResponse
{
No = record.No,
Factory = record.TenantId,
OriginFactory = record.OriginTenantId,
Werks = record.Werks,
DepartmentNo = record.DepartmentNo,
DepartmentName = department.Name,
CostDate = record.CostDate,
CostDateTime = record.CostDateTime,
Remark = record.Remark,
Amount = SqlFunc.Abs(record.Amount),
Type = record.Type,
Source = record.Source,
BusinessPlaceCode = bPlace.CustomCode,
DeviceUniqueNo = record.DeviceUniqueNo
})
.ToListAsync();
}
}