using PoJun.Dapper;
using ASHermed.SinoInterface.Api.IRepository.Test;
using ASHermed.SinoInterface.Entity.Test;
using ASHermed.SinoInterface.Repository.MySql;
using ASHermed.SinoInterface.Tools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ASHermed.SinoInterface.Api.ContractModel.App;
using ASHermed.SinoInterface.Api.IRepository;
using ASHermed.SinoInterface.Api.ContractModel;

namespace ASHermed.SinoInterface.Api.MySqlRepository
{

    public class PubBannerRepository : BaseRepositoryToASHermed_SinoInterface<Pub_Banner>, IPubBannerRepository
    {


        public List<Pub_Banner> GetBanner(int language, int showWhere)
        {
            var selectSql = new StringBuilder();
            if (language == 1)
            {
                selectSql.Append(@" select ImgUrl,HtmlUrl,JumpUrl");
            }
            else
            {
                selectSql.Append(@" select ImgEnUrl as ImgUrl,HtmlEnUrl as HtmlUrl,JumpEnUrl as JumpUrl");
            }
            selectSql.Append(@",Sort,IsHasHead,BannerTitle,JumpAppId from pub_banner where IsDeleted = false and ShowWhere = @ShowWhere");
            var parms = new Dictionary<string, object>();
            parms.Add("@ShowWhere", showWhere);
            var result = Query<Pub_Banner>(selectSql.ToString(), parms);
            return result?.ToList();
        }

        public async Task<List<AppletBtn>> GetFunction(int showWhere, int language)
        {
            var selectSql = new StringBuilder();
            if (language == 1)
            {
                selectSql.Append(@"select id,BtnTextCn as BtnText,");
            }
            else
            {
                selectSql.Append(@"select id,BtnTextEn as BtnText,");
            }
            selectSql.Append(@"GoUrl,BtnIcon,GoType,JumpAppId,IsHot from  pub_appletbtn where `status`=1 and ShowWhere =@showWhere ");
            if (showWhere == 1)
            {
                selectSql.Append(@" order by sort LIMIT 4");
            }
            var result = QueryAsync<AppletBtn>(selectSql.ToString(), new { showWhere = showWhere });
            return result.Result.ToList();
        }

        public List<City> GetSinoCity(int language)
        {
            var selectSql = new StringBuilder();
            //if (language == 1)
            //{
            //    selectSql.Append(@"select id,cn_name as CityName ");
            //}
            //else
            //{
            //    selectSql.Append(@"select id,en_name as CityName ");
            //}
            selectSql.Append(@"select id,cn_name as CityName,En_name as CityNameEn  from  dic_city where `is_deleted`=0");
            var result = Query<City>(selectSql.ToString(), null);
            return result.ToList();
        }
    }
}
