using OpenAuth.App.BaseApp.Base;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenAuth.App.Interface;
using SqlSugar;

namespace OpenAuth.App.ServiceApp.TaxManage
{
    public class TaxManagementApp : SqlSugarBaseApp<TaxTuceng, SugarDbContext>
    {
        private ISqlSugarClient client;

        #region 构造函数
        public TaxManagementApp(
            ISugarUnitOfWork<SugarDbContext> unitWork,
            ISimpleClient<TaxTuceng> repository,
            IAuth auth,
            ISqlSugarClient sqlSugarClient
            ) : base(unitWork, repository, auth)
        {
            this.client = sqlSugarClient;
        }
        #endregion

        #region 图层查询
        public async Task<List<TaxTuceng>> GetTucengInfo()
        {
            var list = await client.Queryable<TaxTuceng>().ToTreeAsync(it => it.Child, it => it.PId, 0);
            return list;
        }
        #endregion

        #region  用地、房屋图层相关企业查询
        public async Task<List<dynamic>> GetTaxBuildingInfo(string req)
        {
            string sql = "select * from view_building";
            if (!string.IsNullOrEmpty(req))
            {
                sql += "  where syrmc like '%" + req + "%' or zdbm='" + req + "'";
            }
            var list = await client.SqlQueryable<dynamic>(sql).ToListAsync();
            return list;
        }

        public async Task<List<dynamic>> GetTaxZongdiInfo(string req)
        {
            string sql = "select * from view_zongdi";
            if (!string.IsNullOrEmpty(req))
            {
                sql += "  where syrmc like '%" + req + "%' or zdbm='" + req + "'";
            }
            var list = await client.SqlQueryable<dynamic>(sql).ToListAsync();
            return list;
        }
        #endregion

    }
}
