huangxiaoqiang
2025-06-12 a407d85032a312cd93513d24e1bd34219e3aa3c9
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Core/BaseServices/ServiceBase.cs
@@ -60,6 +60,73 @@
        }
        //protected string ValidatePageOptions(PageDataOptions options)
        //{
        //    options = options ?? new PageDataOptions();
        //    string where = "";
        //    List<SearchParameters> searchParametersList = new List<SearchParameters>();
        //    if (options.Filter != null && options.Filter.Count > 0)
        //    {
        //        searchParametersList.AddRange(options.Filter);
        //    }
        //    else if (!string.IsNullOrEmpty(options.Wheres))
        //    {
        //        try
        //        {
        //            searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
        //            options.Filter = searchParametersList;
        //        }
        //        catch { }
        //    }
        //    QueryRelativeList?.Invoke(searchParametersList);
        //    for (int i = 0; i < searchParametersList.Count; i++)
        //    {
        //        if (string.IsNullOrEmpty(searchParametersList[i].Value))
        //        {
        //            continue;
        //        }
        //        PropertyInfo property = TProperties.Where(c => c.Name.ToUpper() == searchParametersList[i].Name.ToUpper()).FirstOrDefault();
        //        if (property == null) continue;
        //        List<(bool, string, object)> results = property.ValidationValueForDbType(searchParametersList[i].Value.Split(',')).ToList();
        //        if (results == null || results.Count() == 0)
        //        {
        //            continue;
        //        }
        //        for (int j = 0; j < results.Count(); j++)
        //        {
        //            if (j == 0)
        //            {
        //                where += "(";
        //            }
        //            LinqExpressionType expressionType = searchParametersList[i].DisplayType.GetLinqCondition();
        //            if (expressionType == LinqExpressionType.Equal)
        //            {
        //                where += $"{searchParametersList[i].Name} like '%{results[j].Item3}%'";
        //            }
        //            else
        //            {
        //                where += $"{searchParametersList[i].Name} {searchParametersList[i].DisplayType} '{results[j].Item3}'";
        //            }
        //            if (j == results.Count() - 1)
        //            {
        //                where += ")";
        //            }
        //            else
        //            {
        //                where += " or ";
        //            }
        //        }
        //        if (i < searchParametersList.Count - 1)
        //            where += " and ";
        //    }
        //    return where;
        //}
        protected string ValidatePageOptions(PageDataOptions options)
        {
            options = options ?? new PageDataOptions();
@@ -91,38 +158,48 @@
                if (property == null) continue;
                List<(bool, string, object)> results = property.ValidationValueForDbType(searchParametersList[i].Value.Split(',')).ToList();
                if (results == null || results.Count() == 0)
                (bool, string, object) result = property.ValidationVal(searchParametersList[i].Value);
                if (!result.Item1)
                {
                    continue;
                }
                for (int j = 0; j < results.Count(); j++)
                {
                    if (j == 0)
                    {
                        where += "(";
                    }
                    LinqExpressionType expressionType = searchParametersList[i].DisplayType.GetLinqCondition();
                    if (expressionType == LinqExpressionType.Equal)
                    {
                        where += $"{searchParametersList[i].Name} like '%{results[j].Item3}%'";
                    }
                    else
                    {
                        where += $"{searchParametersList[i].Name} {searchParametersList[i].DisplayType} '{results[j].Item3}'";
                    }
                    if (j == results.Count() - 1)
                LinqExpressionType expressionType = searchParametersList[i].DisplayType.GetLinqCondition();
                if (expressionType == LinqExpressionType.Equal)
                {
                    if (string.IsNullOrEmpty(where))
                    {
                        where += ")";
                        // 针对字符串类型的字段使用模糊查询
                        //where += $"{searchParametersList[i].Name} like '%{searchParametersList[i].Value}%'";
                        if (searchParametersList[i].Value.ToLower() == "true" || searchParametersList[i].Value.ToLower() == "false")
                        {
                            where += $" {searchParametersList[i].Name} = '{searchParametersList[i].Value.ToLower()}'";
                        }
                        else
                        {
                            where += $"{searchParametersList[i].Name} like '%{searchParametersList[i].Value}%'";
                        }
                    }
                    else
                    {
                        where += " or ";
                        // 针对布尔类型字段进行精确查询
                        if (searchParametersList[i].Value.ToLower() == "true" || searchParametersList[i].Value.ToLower() == "false")
                        {
                            where += $" and {searchParametersList[i].Name} = '{searchParametersList[i].Value.ToLower()}'";
                        }
                        else
                        {
                            where += $" and {searchParametersList[i].Name} like '%{searchParametersList[i].Value}%'";
                        }
                    }
                }
                if (i < searchParametersList.Count - 1)
                    where += " and ";
                else
                {
                    if (string.IsNullOrEmpty(where))
                        where += $"{searchParametersList[i].Name} {searchParametersList[i].DisplayType} '{searchParametersList[i].Value}'";
                    else
                        where += $" and {searchParametersList[i].Name} {searchParametersList[i].DisplayType} '{searchParametersList[i].Value}'";
                }
            }
            return where;
        }
@@ -225,7 +302,10 @@
                {
                    return WebResponseContent.Instance.Error("传参错误,参数不能为空");
                }
                string validResult = typeof(TEntity).ValidateDicInEntity(saveModel.MainData, true, TProperties);
                var x = saveModel.MainData;
                string validResult = typeof(TEntity).ValidateDicInEntity(x, true, TProperties);
                if (!string.IsNullOrEmpty(validResult))
                {
@@ -286,7 +366,7 @@
                List<TDetail> list = detailDics.DicToIEnumerable<TDetail>();
                ((SqlSugarClient)BaseDal.Db).BeginTran();
                ((SqlSugarScope)BaseDal.Db).BeginTran();
                int id = BaseDal.Db.Insertable(entity).ExecuteReturnIdentity();
@@ -298,13 +378,13 @@
                BaseDal.Db.Insertable(list).ExecuteCommand();
                ((SqlSugarClient)BaseDal.Db).CommitTran();
                ((SqlSugarScope)BaseDal.Db).CommitTran();
                content = WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                ((SqlSugarClient)BaseDal.Db).RollbackTran();
                ((SqlSugarScope)BaseDal.Db).RollbackTran();
                content = WebResponseContent.Instance.Error(ex.Message);
            }
            return content;
@@ -457,7 +537,7 @@
                object mainId = typeof(TEntity).GetPropertyValue(entity, typeof(TEntity).GetKeyName());
                if (mainId != null)
                {
                    ((SqlSugarClient)BaseDal.Db).BeginTran();
                    ((SqlSugarScope)BaseDal.Db).BeginTran();
                    if (dynamicDelKeys.Count > 0)
                        BaseDal.Db.Deleteable<object>().AS(detailType.Name).Where($"{detailType.GetKeyName()} in (@id)", new { id = dynamicDelKeys.ToArray() }).ExecuteCommandHasChange();
@@ -474,7 +554,7 @@
                    BaseDal.Db.Insertable(addRows).ExecuteCommand();
                    ((SqlSugarClient)BaseDal.Db).CommitTran();
                    ((SqlSugarScope)BaseDal.Db).CommitTran();
                    content = WebResponseContent.Instance.OK();
                }
@@ -486,7 +566,7 @@
            }
            catch (Exception ex)
            {
                ((SqlSugarClient)BaseDal.Db).RollbackTran();
                ((SqlSugarScope)BaseDal.Db).RollbackTran();
                content = WebResponseContent.Instance.Error(ex.Message);
            }
            return content;
@@ -532,14 +612,14 @@
                        {
                            dynamicDelKeys.Add(keys[i]);
                        }
                        ((SqlSugarClient)BaseDal.Db).BeginTran();
                        ((SqlSugarScope)BaseDal.Db).BeginTran();
                        if (dynamicDelKeys.Count > 0)
                            BaseDal.Db.Deleteable<object>().AS(detailType.Name).Where($"{name} in (@id)", new { id = dynamicDelKeys.ToArray() }).ExecuteCommandHasChange();
                        BaseDal.DeleteDataByIds(keys);
                        ((SqlSugarClient)BaseDal.Db).CommitTran();
                        ((SqlSugarScope)BaseDal.Db).CommitTran();
                        return WebResponseContent.Instance.OK();
                    }
@@ -551,7 +631,7 @@
            }
            catch (Exception ex)
            {
                ((SqlSugarClient)BaseDal.Db).RollbackTran();
                ((SqlSugarScope)BaseDal.Db).RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }