65 lines
2.0 KiB
C#
65 lines
2.0 KiB
C#
using Dlhis.Basic.MealUser.Request;
|
|
using Dlhis.Basic.MealUser.Response;
|
|
using Dlhis.Basic.Organization.Services;
|
|
using Dlhis.Entity.Basic.Entity;
|
|
using Dlhis.Entity.Basic.Enums;
|
|
using Kurisu.AspNetCore.Utils.Extensions;
|
|
using Kurisu.Core.DataAccess.Dto;
|
|
using Kurisu.SqlSugar.Extensions;
|
|
using Kurisu.SqlSugar.Services;
|
|
|
|
namespace Dlhis.Basic.MealUser.Services.Implements;
|
|
|
|
public class MealUserService : IMealUserService
|
|
{
|
|
private readonly IDbContext _dbContext;
|
|
private readonly IGainfoStore _gainfoStore;
|
|
|
|
public MealUserService(IDbContext dbContext, IGainfoStore gainfoStore)
|
|
{
|
|
_dbContext = dbContext;
|
|
_gainfoStore = gainfoStore;
|
|
}
|
|
|
|
public async Task<Pagination<MealUserResponse>> GetPageAsync(MealUserPageRequest request)
|
|
{
|
|
var page = await _dbContext.Queryable<CanteenUserEntity>()
|
|
.Select<MealUserResponse>()
|
|
.ToPageListAsync(request);
|
|
|
|
return page;
|
|
}
|
|
|
|
public async Task AddAsync(MealUserAddRequest request)
|
|
{
|
|
//todo 获取档案信息
|
|
|
|
var gainfoEntity = await _gainfoStore.Queryable(GainfoStatusEnumType.Working)
|
|
.Where(x => x.Guestno == request.UserId)
|
|
.FirstAsync();
|
|
var b = gainfoEntity == null ? true : false;
|
|
b.ThrowIfTrue($"档案[{request.UserId}]不存在");
|
|
|
|
var entity = new CanteenUserEntity
|
|
{
|
|
UserId = request.UserId,
|
|
UserType = request.UserType,
|
|
UserCode = gainfoEntity.Ename,
|
|
CarNo = gainfoEntity.CarNo,
|
|
Balance = 0,
|
|
BalanceOfRecharge = 0,
|
|
BalanceOfSubsidies = 0,
|
|
Version = 0,
|
|
};
|
|
await _dbContext.InsertAsync(entity);
|
|
}
|
|
|
|
public async Task<MealUserResponse> GetMealUserAsync(string userId)
|
|
{
|
|
return await _dbContext.Queryable<CanteenUserEntity>()
|
|
.Where(x => x.UserId == userId)
|
|
.Select<MealUserResponse>()
|
|
.FirstAsync();
|
|
}
|
|
}
|