BaseBll.cs 9.88 KB
using HHECS.Model;
using HHECS.Model.BLLModel;
using HHECS.Model.Entities;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace HHECS.Bll
{
    /// <summary>
    /// 基础数据和访问数据库相关的抽象类
    /// </summary>
    public abstract class BaseBll
    {
        public string ConnectStr { get; set; }

        public IDbConnection GetConnection()
        {
            return new MySqlConnection(ConnectStr);
        }

        #region 实例方法

        /// <summary>
        /// 检查按钮权限
        /// </summary>
        /// <param name="menuOperations"></param>
        /// <param name="controls"></param>
        public void CheckPermission(List<MenuOperation> menuOperations, UIElementCollection controls)
        {
            foreach (var item in controls)
            {
                if (item is Button)
                {
                    Button temp = item as Button;
                    if (temp.Tag is String)
                    {
                        string perms = (string)temp.Tag;
                        if (menuOperations.Count(t => t.Perms == perms) > 0)
                        {
                            temp.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            temp.Visibility = Visibility.Collapsed;
                        }
                    }
                    else
                    {
                        temp.Visibility = Visibility.Collapsed;
                    }
                }
            }
        }

        /// <summary>
        /// 检查按钮权限
        /// </summary>
        /// <param name="menuOperations"></param>
        /// <param name="controls"></param>
        public void CheckPermission(List<MenuOperation> menuOperations, List<UIElement> controls)
        {
            foreach (var item in controls)
            {
                if (item is Button)
                {
                    Button temp = item as Button;
                    if (temp.Tag is String)
                    {
                        string perms = (string)temp.Tag;
                        if (menuOperations.Count(t => t.Perms == perms) > 0)
                        {
                            temp.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            temp.Visibility = Visibility.Collapsed;
                        }
                    }
                    else
                    {
                        temp.Visibility = Visibility.Collapsed;
                    }
                }
            }
        }



        /// <summary>
        /// 组合一组权限和他的子权限
        /// </summary>
        /// <param name="menuOperations"></param>
        /// <param name="all"></param>
        public void Combine(List<MenuOperation> menuOperations, List<MenuOperation> all)
        {
            foreach (var item in menuOperations)
            {
                item.Children.AddRange(all.FindAll(t => t.ParentId == item.Id));
                if (item.Children.Count > 0)
                {
                    Combine(item.Children, all);
                }
            }
        }
        #endregion

        #region 基础数据

        public abstract BllResult<User> GetUserWithRoles(string userName, string password);
        public abstract BllResult<List<MenuOperation>> FindMenuOperation(List<Role> roles);
        public abstract BllResult<List<MenuOperation>> GetAllMenuOperation();
        public abstract BllResult<MenuOperation> SaveMenuOperation(MenuOperation currentMenuOperation);
        public abstract BllResult UpdateMenuOperation(MenuOperation currentMenuOperation);
        public abstract BllResult DeleteMenuOperationByIds(List<int> ids);
        public abstract BllResult<List<Role>> GetAllRole();
        public abstract BllResult<Role> GetRoleById(int value);
        public abstract void GetMenuOperationIds(List<MenuOperation> list, List<MenuOperation> menuOperations, List<int> ids);
        public abstract BllResult<List<Config>> GetAllConfig();
        public abstract BllResult<List<Material>> GetAllMaterial();
        public abstract BllResult<Role> InsertRoleAndMenuOperations(Role currentRole, List<MenuOperation> list);
        public abstract BllResult<Role> UpdateRoleAndMenuOperations(Role currentRole, List<MenuOperation> list);
        public abstract BllResult<List<User>> GetUserByCondition(string sql);
        public abstract BllResult SetUserDisable(List<int?> list, int enable);
        public abstract BllResult<User> SaveUserWithRoles(User currentUser, List<int> RoleIds);
        public abstract BllResult<User> UpdateUserWithRoles(User currentUser, List<int> RoleIds);
        public abstract BllResult<Dict> GetDictWithDetails(string v);
        public abstract BllResult DeleteConfigByIds(List<int> list);
        public abstract BllResult DeleteMaterialByIds(List<int> list);
        public abstract BllResult DeleteRoleByIds(List<int> list);
        public abstract BllResult DeleteDictByIds(List<int> list);
        public abstract BllResult DeleteEuipmentTypeByIds(List<int> list);
        public abstract BllResult DeleteEquipmentTypePropTemplateByIds(List<int> list);
        public abstract BllResult DeleteEuipmentByIds(List<int> ids);
        public abstract BllResult SyncEquipmentProp(int? id);
        public abstract BllResult CopyEquipment(EquipmentType equipment);


        #endregion

        #region Job

        /// <summary>
        /// 执行一次指定的job
        /// </summary>
        /// <param name="value"></param>
        /// <param name="client"></param>
        /// <returns></returns>
        public abstract Task<BllResult> ExcuteJobAsync(int value, HttpClient client);

        #endregion

        #region Data

        public abstract BllResult<List<T>> GetCommonModelByCondition<T>(string v);
        public abstract Task<BllResult<List<T>>> GetCommonModelByConditionAsync<T>(string v);
        public abstract BllResult<List<T>> GetCommonModelByCondition<T>(string v, IDbConnection connection, IDbTransaction tran);
        public abstract Task<BllResult<List<T>>> GetCommonModelByConditionAsync<T>(string v, IDbConnection connection, IDbTransaction tran);

        public abstract BllResult<int> GetCommonModelCount<T>(string sql);
        public abstract BllResult<int> GetCommonModelCount<T>(string sql, IDbConnection connection, IDbTransaction tran);

        public abstract BllResult<int?> SaveCommonModel<T>(T model);
        public abstract Task<BllResult<int?>> SaveCommonModelAsync<T>(T model);
        public abstract BllResult<int?> SaveCommonModel<T>(T model, IDbConnection connection, IDbTransaction tran);
        public abstract Task<BllResult<int?>> SaveCommonModelAsync<T>(T model, IDbConnection connection, IDbTransaction tran);

        public abstract BllResult UpdateCommonModel<T>(T model);
        public abstract Task<BllResult> UpdateCommonModelAsync<T>(T model);
        public abstract BllResult UpdateCommonModel<T>(T model, IDbConnection connection, IDbTransaction tran);
        public abstract Task<BllResult> UpdateCommonModelAsync<T>(T model, IDbConnection connection, IDbTransaction tran);

        public abstract BllResult DeleteCommonModelByIds<T>(List<int> list);
        public abstract Task<BllResult> DeleteCommonModelByIdsAsync<T>(List<int> list);
        public abstract BllResult DeleteCommonModelByIds<T>(List<int> list, IDbConnection connection, IDbTransaction tran);
        public abstract Task<BllResult> DeleteCommonModelByIdsAsync<T>(List<int> list, IDbConnection connection, IDbTransaction tran);

        public abstract BllResult<List<T>> GetCommonModeByPageCondition<T>(int pageNumber, int pageSize, string condition, string orderBy);
        public abstract Task<BllResult<List<T>>> GetCommonModeByPageConditionAsync<T>(int pageNumber, int pageSize, string condition, string orderBy);
        public abstract BllResult<List<T>> GetCommonModeByPageCondition<T>(IDbConnection connection, IDbTransaction tran, int pageNumber, int pageSize, string condition, string orderBy);
        public abstract Task<BllResult<List<T>>> GetCommonModeByPageConditionAsync<T>(IDbConnection connection, IDbTransaction tran, int pageNumber, int pageSize, string condition, string orderBy);


        public abstract BllResult<int> ExcuteCommonSqlForInsertOrUpdate(string sql);
        public abstract Task<BllResult<int>> ExcuteCommonSqlForInsertOrUpdateAsync(string sql);
        public abstract BllResult<int> ExcuteCommonSqlForInsertOrUpdate(string sql, IDbConnection connection, IDbTransaction tran);
        public abstract Task<BllResult<int>> ExcuteCommonSqlForInsertOrUpdateAsync(string sql, IDbConnection connection, IDbTransaction tran);

        public abstract BllResult<int> ExcuteCommonSqlForInsertOrUpdate(string sql, object param);
        public abstract Task<BllResult<int>> ExcuteCommonSqlForInsertOrUpdateAsync(string sql, object param);
        public abstract BllResult<int> ExcuteCommonSqlForInsertOrUpdate(string sql, object param, IDbConnection connection, IDbTransaction tran);
        public abstract Task<BllResult<int>> ExcuteCommonSqlForInsertOrUpdateAsync(string sql, object param, IDbConnection connection, IDbTransaction tran);

        public abstract BllResult<List<T>> GetCommonModelByConditionWithZero<T>(string v);
        public abstract Task<BllResult<List<T>>> GetCommonModelByConditionWithZeroAsync<T>(string v);
        public abstract BllResult<List<T>> GetCommonModelByConditionWithZero<T>(string v, IDbConnection connection, IDbTransaction tran);
        public abstract Task<BllResult<List<T>>> GetCommonModelByConditionWithZeroAsync<T>(string v, IDbConnection connection, IDbTransaction tran);

        #endregion

    }
}