public static IEnumerable <WarningClearDetail> GetWarningClears(int wId, DateTime startTime, DateTime endTime, int setId,
                                                                        WarningType warningType, WarningDataType dataType, IEnumerable <int> deviceIds)
        {
            var clears = new List <WarningClearDetail>();
            var param  = new List <string> {
                "DealTime >= @startTime", "DealTime <= @endTime"
            };

            if (wId != 0)
            {
                param.Add("WorkshopId = @wId");
            }
            if (warningType != WarningType.默认)
            {
                param.Add("b.WarningType = @warningType");
            }
            if (dataType != WarningDataType.默认)
            {
                param.Add("b.DataType = @dataType");
            }
            if (setId != 0)
            {
                param.Add("SetId = @setId");
            }
            if (deviceIds != null && deviceIds.Any())
            {
                var t = new List <WarningClearDetail>();
                param.Add("FIND_IN_SET(@deviceId, a.DeviceIds)");
                foreach (var deviceId in deviceIds)
                {
                    t.AddRange(ServerConfig.ApiDb.Query <WarningClearDetail>(
                                   $"SELECT a.* FROM `warning_clear` a " +
                                   $"JOIN `warning_set` b ON a.SetId = b.Id {(param.Any() ? $" WHERE {param.Join(" AND ")}" : "")} ORDER BY DealTime DESC;",
                                   new { startTime, endTime, setId, deviceId }));
                }
                clears.AddRange(t.GroupBy(x => x.SetId).Select(x => x.First()));
            }
            else
            {
                clears.AddRange(ServerConfig.ApiDb.Query <WarningClearDetail>(
                                    $"SELECT a.* FROM `warning_clear` a " +
                                    $"JOIN `warning_set` b ON a.SetId = b.Id {(param.Any() ? $" WHERE {param.Join(" AND ")}" : "")} ORDER BY DealTime DESC;",
                                    new { startTime, endTime, setId, warningType, dataType }));
            }

            if (clears.Any())
            {
                var sets          = WarningSetHelper.GetMenus(wId, clears.Select(x => x.SetId).Distinct()).ToDictionary(x => x.Id);
                var devices       = DeviceHelper.GetMenus(wId, clears.SelectMany(x => x.DeviceIdList).Distinct()).ToDictionary(x => x.Id);
                var createUserIds = AccountInfoHelper.GetAccountInfoByAccounts(clears.Select(x => x.CreateUserId).Distinct()).ToDictionary(x => x.Account);
                foreach (var d in clears)
                {
                    d.Name    = createUserIds.ContainsKey(d.CreateUserId) ? createUserIds[d.CreateUserId].Name : "";
                    d.SetName = sets.ContainsKey(d.SetId) ? sets[d.SetId].Name : "";
                    d.DeviceList.AddRange(d.DeviceIdList.Select(x => devices.ContainsKey(x) ? devices[x].Code : x.ToString()));
                }
            }

            return(clears);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="workshopId"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="setId"></param>
        /// <param name="itemId"></param>
        /// <param name="warningType"></param>
        /// <param name="dataType"></param>
        /// <param name="deviceIds"></param>
        /// <param name="itemTypes"></param>
        /// <param name="isWarning">-1all 0  1 </param>
        /// <param name="setIds"></param>
        /// <param name="itemIds"></param>
        /// <returns></returns>
        public static IEnumerable <WarningLog> GetWarningLogs(int workshopId, DateTime startTime, DateTime endTime, int setId, int itemId,
                                                              WarningType warningType, WarningDataType dataType, IEnumerable <int> deviceIds, IEnumerable <WarningItemType> itemTypes, IEnumerable <int> setIds, IEnumerable <int> itemIds, int isWarning = -1)
        {
            var param = new List <string> {
                "a.WorkshopId = @workshopId"
            };

            if (startTime != default(DateTime))
            {
                param.Add("a.WarningTime >= @startTime");
            }
            if (endTime != default(DateTime))
            {
                param.Add("a.WarningTime <= @endTime");
            }
            if (setId != 0)
            {
                param.Add("a.SetId = @setId");
            }
            if (setIds != null && setIds.Any())
            {
                param.Add("a.SetId IN @setIds");
            }
            if (itemId != 0)
            {
                param.Add("a.ItemId = @itemId");
            }
            if (warningType != WarningType.默认)
            {
                param.Add("a.WarningType = @warningType");
            }
            if (dataType != WarningDataType.默认)
            {
                param.Add("a.DataType = @dataType");
            }
            if (deviceIds != null && deviceIds.Any())
            {
                param.Add("a.DeviceId IN @deviceIds");
            }
            if (isWarning != -1)
            {
                param.Add("a.IsWarning = @isWarning");
            }

            if (itemTypes != null && itemTypes.Any())
            {
                param.Add("b.ItemType IN @itemTypes");
                //var args = new List<Tuple<string, string, dynamic>>
                //{
                //    new Tuple<string, string, dynamic>("ItemType", "IN", itemTypes)
                //};
                //if (setId != 0)
                //{
                //    args.Add(new Tuple<string, string, dynamic>("SetId", "=", setId));
                //}
                //var tItemIds = WarningSetItemHelper.Instance.CommonGet<WarningSetItem>(args).Select(x => x.Id);
                //if (!tItemIds.Any())
                //{
                //    return new List<WarningLog>();
                //}
                //param.Add("a.ItemId IN @itemIds");
                //if (itemIds.Any())
                //{
                //    itemIds = tItemIds.Intersect(itemIds);
                //}
            }
            if (itemIds != null && itemIds.Any())
            {
                param.Add("a.ItemId IN @itemIds");
            }
            var r = ServerConfig.ApiDb.Query <WarningLog>(
                $"SELECT a.*, b.ItemType FROM `warning_log` a " +
                $"JOIN warning_set_item_final b ON a.ItemId = b.Id " +
                $"{(param.Any() ? $" WHERE {param.Join(" AND ")}" : "")} ORDER BY a.WarningTime DESC;",
                new { workshopId, startTime, endTime, setId, itemId, warningType, dataType, deviceIds, setIds, itemIds, itemTypes, isWarning });

            if (r != null && r.Any())
            {
                var sets       = WarningSetHelper.GetMenus(workshopId, r.Select(x => x.SetId).Distinct()).ToDictionary(x => x.Id);
                var devices    = DeviceHelper.GetMenus(workshopId, r.Select(x => x.DeviceId).Distinct()).ToDictionary(x => x.Id);
                var categories = DeviceCategoryHelper.GetMenus(workshopId, r.Select(x => x.CategoryId).Distinct()).ToDictionary(x => x.Id);
                foreach (var d in r)
                {
                    //var d = ClassExtension.ParentCopyToChild<WarningCurrent, WarningLog>(current);
                    d.SetName = sets.ContainsKey(d.SetId) ? sets[d.SetId].Name : "";
                    d.Code    = devices.ContainsKey(d.DeviceId) ? devices[d.DeviceId].Code : "";
                    //d.Class = classes.FirstOrDefault(x => x.Id == d.ClassId)?.Class ?? "";
                    d.CategoryName = categories.ContainsKey(d.CategoryId) ? categories[d.CategoryId].Name : "";
                }
            }

            return(r);
        }