namespace Tiobon.Core.Services;

/// <summary>
/// 系统用户 (服务)
/// </summary>
public class Ghrs_UserServices : BaseServices<Ghrs_User, Ghrs_UserDto, InsertGhrs_UserInput, EditGhrs_UserInput>, IGhrs_UserServices
{
    private readonly IBaseRepository<Ghrs_User> _dal;
    public Ghrs_UserServices(IBaseRepository<Ghrs_User> dal)
    {
        this._dal = dal;
        base.BaseDal = dal;
    }

    public override async Task<Ghrs_UserDto> QuerySingleDto(Expression<Func<Ghrs_User, bool>> whereExpression)
    {

        var entity = await base.QuerySingleDto(whereExpression);

        if (entity != null)
        {
            var staff = await Db.Queryable<Ghra_Staff>().Where(x => x.StaffID == entity.UserStaffID).FirstAsync();
            if (staff != null)
            {
                entity.StaffNo = staff.StaffNo;
                entity.StaffName = staff.StaffName;
            }
        }

        return entity;
    }
}