using System;
using System.Collections.Generic;
using System.Text;
using MySql.Data.MySqlClient;
using Dapper;
using Bailun.DC.Models;
using Bailun.DC.Common;

namespace Bailun.DC.Services
{
    /// <summary>
    /// 用户权限
    /// </summary>
    public class UserAuthorityServices
    {
        /// <summary>
        /// 判断用户是否有导出权限
        /// </summary>
        /// <param name="code"></param>
        /// <param name="userid"></param>
        /// <returns></returns>
        public static bool checkUserExportAuthority(string code,int userid)
        {
            var sql = $"select * from dc_base_user_authoritys where has_export = 1 and code='{code}' and userid="+userid;

            using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
            {
                if (cn.State == System.Data.ConnectionState.Closed)
                {
                    cn.Open();
                }

                var obj = cn.QueryFirstOrDefault<dc_base_user_authoritys>(sql);

                return obj != null;
            }
        }

        public string Add(List<dc_base_user_authoritys> list)
        {
            using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
            {
                if (cn.State == System.Data.ConnectionState.Closed)
                {
                    cn.Open();
                }

                foreach (var item in list)
                {
                    cn.Insert<dc_base_user_authoritys>(item);
                }

            }

            return "";
        }

    }
}
