Пример #1
0
        public ActionResult Search(bool OnlyKeyword, ConditionModal conditionModel, string keyword)
        {
            AjaxResult ar = new Globals.AjaxResult();

            if (conditionModel == null)
            {
                ar.state   = ResultType.error.ToString();
                ar.message = "提交的数据为空,查询数据失败";

                return(Json(ar, JsonRequestBehavior.AllowGet));
            }

            var currentUser = LoginManager.GetCurrentUser();
            List <CustomItem>       customItemList = new List <CustomItem>();
            List <InformationModel> modelList      = new List <InformationModel>();

            try
            {
                var state = OperatorState.error;

                List <Member> memberList = _underlingManager.GetUnderlingList();

                foreach (var member in memberList)
                {
                    state = _customItemBLL.GetCustomItems(member.Account, ref customItemList);
                    if (state == OperatorState.error)
                    {
                        ar.state   = ResultType.error.ToString();
                        ar.message = "获取自定义项失败,无法搜索到数据";

                        return(Json(ar, JsonRequestBehavior.AllowGet));
                    }

                    // 是否使用条件查询模式
                    if (OnlyKeyword)
                    {
                        state = _informationBLL.GetInformation(keyword, member.Account, conditionModel, customItemList, ref modelList);
                    }
                    else
                    {
                        state = _informationBLL.GetInformation(keyword, member.Account, null, customItemList, ref modelList);
                    }
                }

                // 查询自己
                state = _customItemBLL.GetCustomItems(currentUser.Account, ref customItemList);
                if (state == OperatorState.error)
                {
                    ar.state   = ResultType.error.ToString();
                    ar.message = "获取自定义项失败,无法搜索到数据";

                    return(Json(ar, JsonRequestBehavior.AllowGet));
                }

                // 是否使用条件查询模式
                if (OnlyKeyword)
                {
                    state = _informationBLL.GetInformation(keyword, currentUser.Account, conditionModel, customItemList, ref modelList);
                }
                else
                {
                    state = _informationBLL.GetInformation(keyword, currentUser.Account, null, customItemList, ref modelList);
                }

                if (state == OperatorState.empty)
                {
                    ar.state   = ResultType.error.ToString();
                    ar.message = "无法获取到当前用户,无法搜索到数据";
                }
                else if (state == OperatorState.success)
                {
                    if (modelList == null || modelList.Count <= 0)
                    {
                        ar.state   = ResultType.error.ToString();
                        ar.message = "无法搜索到有关数据";
                    }
                    else
                    {
                        ar.state = ResultType.success.ToString();
                        ar.data  = modelList.ToJson();

                        DataCacheManager.SetDataCache(CachaKey.Key, modelList);
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.writeLog_error(ex.Message);
                LogHelper.writeLog_error(ex.StackTrace);

                ar.state   = ResultType.error.ToString();
                ar.message = "系统错误,获取数据失败";
            }

            return(Json(ar, JsonRequestBehavior.AllowGet));
        }