using OASystem.Domain;
using OASystem.Domain.Entities.System;

namespace OASystem.Infrastructure.Repositories.System
{
    public class CompanyRepository : BaseRepository<Sys_Company, CompanyView>
    {
        public CompanyRepository(SqlSugarClient sqlSugar) : base(sqlSugar)
        {

        }

        /// <summary>
        /// 获取所有公司数据
        /// </summary>
        /// <param name="_CompanyRepository"></param>
        /// <returns></returns>
        public Result GetCompanyData()
        {
            Result result = new Result();

            string sql = "select * from Sys_Company where isdel = 0";
            var DBdata =  GetListBySqlWithNolock(sql);
            if (DBdata == null || DBdata.Count == 0)
            {
                result.Code = -1;
                result.Msg = "暂无数据！";
                return result;
            }

            result.Code = 0;
            result.Msg = "成功！";
            result.Data = DBdata;
            return result;
        }


        /// <summary>
        /// 获取公司名称数据
        /// </summary>
        /// <param name="_CompanyRepository"></param>
        /// <returns></returns>
        public async Task<Result> GetCompanyNameData()
        {
            Result result = new Result();

            string sql = "Select Id,CompanyName From Sys_Company Where IsDel = 0";

            var companyNameData = await _sqlSugar.SqlQueryable<CompanyNameView>(sql).ToListAsync();

            if (companyNameData == null || companyNameData.Count == 0)
            {
                result.Code = -1;
                result.Msg = "暂无数据！";
                return result;
            }

            result.Code = 0;
            result.Msg = "成功！";
            result.Data = companyNameData;
            return result;
        }

    }
}
