public async Task <List <NameByIdDto> > FindIdListByNameContains(IdByNameContainsParams request) { return(await Task.Run(() => { Channel channel = ClientFindCreateChannel.CreateChannel(_Mname, "FindIdListByNameContainsService").Result; var client = this._ProxyClient(channel); var serverRes = client.FindIdListByNameContains(request); channel.ShutdownAsync(); //关闭长连接 return serverRes; })); }
/// <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; })); }
private void AutoFindIdListByNameContains <QP>(out Task <List <NameByIdDto> > idQueryList, QP qParams, string wFields, string otherFields, string resSetField, Func <IdByNameContainsParams, Task <List <NameByIdDto> > > funcClient) { Task <List <NameByIdDto> > partyIdqueryList = null; Type qpType = qParams.GetType(); string[] fieldArray = wFields.Split(","); bool isWhere = false; for (int i = 0; i < fieldArray.Length; i++) { var fieldVal = qpType.GetProperty(fieldArray[i]).GetValue(qParams); if (fieldVal != null && fieldVal.ToString().Trim() != "") { isWhere = true; break; } } if (isWhere) { IdByNameContainsParams idByNameContainsParams = new IdByNameContainsParams(); Type inType = typeof(IdByNameContainsParams); Type qwType = typeof(IdByNameContainsParams.QueryWhereName); List <IdByNameContainsParams.QueryWhereName> queryList = new List <IdByNameContainsParams.QueryWhereName>(); for (int i = 0; i < fieldArray.Length; i++) { IdByNameContainsParams.QueryWhereName queryWhereName = new IdByNameContainsParams.QueryWhereName(); PropertyInfo likeProper = qpType.GetProperty("IS_LIKE_" + fieldArray[i]); if (likeProper == null) { queryWhereName.IsLike = false; } else { queryWhereName.IsLike = (bool)likeProper.GetValue(qParams); } queryWhereName.NameVal = Convert.ToString(qpType.GetProperty(fieldArray[i]).GetValue(qParams)); queryList.Add(queryWhereName); } idByNameContainsParams.queryWheres = queryList; if (!string.IsNullOrEmpty(otherFields)) { string[] oFieldArray = otherFields.Split(","); for (int i = 0; i < oFieldArray.Length; i++) { inType.GetProperty($"MappingDbField{ i + 1}").SetValue(idByNameContainsParams, oFieldArray[i]); } } partyIdqueryList = funcClient(idByNameContainsParams); if (!string.IsNullOrEmpty(resSetField)) { qpType.GetProperty(resSetField).SetValue(qParams, partyIdqueryList.Result.GetIDS()); } } idQueryList = partyIdqueryList; }