Ejemplo n.º 1
0
        public virtual Task <PageResult <PD> > GetListByPage <PD, PP>(PP request, Func <IQueryable <M>, PP, IQueryable <M> > ExtendQueryListByPage, bool IsAutoSelector = true, Expression <Func <M, M> > _ListByPageSelector = null)
        {
            return(Task.Run <PageResult <PD> >(() =>
            {
                try
                {
                    var QueryParams = request.GetType().GetProperty("QueryParams").GetValue(request);
                    var PageInfo = (PageFilter)request.GetType().GetProperty("PageInfo").GetValue(request);


                    PageResult <PD> pageResult;
                    if (_ListByPageSelector == null && IsAutoSelector)
                    {
                        var _ListByPageAutoSelector = LambdaSelectBuilder.BuildSelect <M, PD>();
                        var awaitRes = this.baseService().PageQuery(q => ExtendQueryListByPage(EntityAutoMapper.QueryWhereJoinBuild(q, QueryParams), request), PageInfo, _ListByPageAutoSelector);

                        pageResult = awaitRes.Result.GetJsonConvetPageData(PageInfo);
                    }
                    else
                    {
                        var awaitRes = this.baseService().PageQuery(q => ExtendQueryListByPage(EntityAutoMapper.QueryWhereJoinBuild(q, QueryParams), request), PageInfo, _ListByPageSelector);
                        pageResult = EntityAutoMapper.ConvertMappingList <PD, M>(awaitRes.Result).GetJsonConvetPageData(PageInfo);
                    }

                    return pageResult;
                }
                catch (Exception ex)
                {
                    logger.Error(ex: ex);
                    return new PageResult <PD> {
                        Total = -1
                    };
                }
            }));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据传入的list id集合 查询对应的名称集合
        /// </summary>
        /// <param name="request"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public virtual Task <List <NameByIdDto> > FindNameListByIdList(NameByIdParams request, ServerCallContext context)
        {
            return(Task.Run(() =>
            {
                Dictionary <string, string> dictionaryMapping = new Dictionary <string, string>();


                var mList = baseService().FindAll <NameByIdDto>(
                    LambdaSelectBuilder.BuildSelect <M, NameByIdDto>(new Dictionary <string, string> {
                    { "NAME1", request.MappingDbField1 },
                    { "NAME2", request.MappingDbField2 },
                    { "NAME3", request.MappingDbField3 },
                    { "NAME4", request.MappingDbField4 },
                    { "NAME5", request.MappingDbField5 },
                    { "NAME6", request.MappingDbField6 },
                    { "NAME7", request.MappingDbField7 }
                })
                    , p => request.IdList.Contains(p.ID)
                    );
                return mList.Result;
            }));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 根据传入的名称模糊查询满足模糊的所有ID进行返回
        /// </summary>
        /// <param name="request"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public virtual Task <List <NameByIdDto> > FindIdListByNameContains(IdByNameContainsParams request, ServerCallContext context)
        {
            return(Task.Run(() =>
            {
                FilterCollection _filterCollection = new FilterCollection();
                Type type = typeof(IdByNameContainsParams);
                Type tType = typeof(M);
                PropertyInfo propertyInfo;

                for (int i = 0; i < request.queryWheres.Count; i++)
                {
                    var fieldName = type.GetProperty($"MappingDbField{i + 1}").GetValue(request);
                    if (fieldName != null)
                    {
                        if (!string.IsNullOrEmpty(request.queryWheres[i].NameVal))
                        {
                            propertyInfo = tType.GetProperty(fieldName.ToString());
                            List <Filter> filter = new List <Filter>
                            {
                                new Filter
                                {
                                    PropertyName = fieldName.ToString(),
                                    Value = request.queryWheres[i].NameVal.ChangeTypeExtend(propertyInfo)
                                }
                            };

                            if (request.queryWheres[i].IsLike)
                            {
                                filter[0].Operation = AttributeModel.ExpressionOptions.Contains;
                            }
                            else
                            {
                                filter[0].Operation = AttributeModel.ExpressionOptions.Equals;
                            }

                            _filterCollection.Add(filter);
                        }
                        else if (request.queryWheres[i].NameValIntList != null)
                        {
                            List <Filter> filter = new List <Filter>
                            {
                                new Filter
                                {
                                    PropertyName = fieldName.ToString(),
                                    Value = request.queryWheres[i].NameValIntList,
                                    Operation = AttributeModel.ExpressionOptions.ContainsList
                                }
                            };
                            _filterCollection.Add(filter);
                        }
                    }
                }


                List <NameByIdDto> mList = baseService().FindAll(
                    LambdaSelectBuilder.BuildSelect <M, NameByIdDto>(new Dictionary <string, string> {
                    { "NAME1", request.MappingDbField1 },
                    { "NAME2", request.MappingDbField2 },
                    { "NAME3", request.MappingDbField3 },
                    { "NAME4", request.MappingDbField4 },
                    { "NAME5", request.MappingDbField5 },
                    { "NAME6", request.MappingDbField6 },
                    { "NAME7", request.MappingDbField7 }
                })
                    , LambdaExpressionBuilder.GetExpression <M>(_filterCollection)).Result;

                return mList;
            }));
        }