Exemplo n.º 1
0
        private string HandlerSearchRequest()
        {
            System.Text.StringBuilder sbResult = new System.Text.StringBuilder();
            System.Text.StringBuilder sbContent = new System.Text.StringBuilder();

            try
            {
                CY.CSTS.Core.Business.AiSearchJson json = new CY.CSTS.Core.Business.AiSearchJson();

                string strPageSize = string.Empty;
                string strPageNum = string.Empty;
                string strSearchJson = string.Empty;

                int pageSize = default(int);
                int pageNum = default(int);

                #region - Validatetion and Get Data-

                if (CY.Utility.Common.RequestUtility.IsGet)
                {
                    strPageSize = CY.Utility.Common.RequestUtility.GetQueryString("pageSize");
                    strPageNum = CY.Utility.Common.RequestUtility.GetQueryString("pageNum");
                    strSearchJson = CY.Utility.Common.RequestUtility.GetQueryString("searchCondition");

                }
                else if (CY.Utility.Common.RequestUtility.IsPost)
                {
                    strPageSize = CY.Utility.Common.RequestUtility.GetFormString("pageSize");
                    strPageNum = CY.Utility.Common.RequestUtility.GetFormString("pageNum");
                    strSearchJson = CY.Utility.Common.RequestUtility.GetFormString("searchCondition");
                }
                if (
                !CY.Utility.Common.ParseUtility.TryParseInt32(strPageSize, out pageSize) ||
                !CY.Utility.Common.ParseUtility.TryParseInt32(strPageNum, out pageNum))
                {
                    return sbResult.Append("{success:false,status:'none',msg:'pagesize,pagenum 参数错误!'}").ToString();
                }

                //strSearchJson = CY.Utility.Common.StringUtility.RemoveIllegalCharacters(strSearchJson);

                json = Newtonsoft.Json.JavaScriptConvert.DeserializeObject(strSearchJson, typeof(CY.CSTS.Core.Business.AiSearchJson)) as CY.CSTS.Core.Business.AiSearchJson;

                if (json == null)
                {
                    return sbResult.Append("{success:false,status:'none',msg:'condition error,搜索参数错误!'}").ToString();
                }

                System.Collections.Generic.List<CY.CSTS.Core.Business.AIChat> chats = CY.CSTS.Core.Business.AIChat.SelectAichatBySearchConditionPageInfo(json, new CY.CSTS.Core.Business.PagingInfo() { CurrentPage = pageNum, PageSize = pageSize }) as List<CY.CSTS.Core.Business.AIChat>;
                if (chats != null)
                {
                    int count = 0;
                    sbContent.Append("[");
                    foreach (CY.CSTS.Core.Business.AIChat chat in chats)
                    {
                        sbContent.Append("{");

                        sbContent.Append(string.Format("id:'{0}'", chat.Id.ToString()));
                        sbContent.Append(string.Format(",keyword:'{0}'", chat.KeyWords));
                        sbContent.Append(string.Format(",answer:'{0}'", chat.Answer));
                        sbContent.Append(string.Format(",unit:'{0}'", chat.UintID.ToString()));
                        sbContent.Append(string.Format(",unitname:'{0}'", chat.Unit.ToString()));
                        sbContent.Append(string.Format(",addtime:'{0}'", chat.AddTime.ToString("yyyy年MM月dd")));
                        sbContent.Append(string.Format(",addperson:'{0}'", chat.AddPerson.ToString()));
                        sbContent.Append("},");

                    }
                    if (chats.Count > 0)
                    {
                        sbContent.Remove(sbContent.Length - 1, 1);
                    }
                    sbContent.Append("]");
                }

                // return action status msg
                sbResult.Append("{");
                sbResult.Append("success:true");
                sbResult.Append(",action:'update'");
                sbResult.Append(",status:'update'");
                sbResult.Append(",msg:'success '");
                // sbResult.Append(string.Format(",pageinfo:{0}",sbPageInfo.ToString()));
                sbResult.Append(string.Format(",results:{0}", sbContent.ToString()));
                sbResult.Append("}");

                #endregion
            }
            catch (Exception ex)
            {
                // Do Nothing
                return sbResult.Append("{success:'false',action:'none',status:'none',msg:'搜索参数错误!'}").ToString();
            }
            finally
            {

            }
            return sbResult.ToString();
        }
Exemplo n.º 2
0
        private string HandlerRebuildRequest()
        {
            System.Text.StringBuilder sbResult = new System.Text.StringBuilder();

            System.Text.StringBuilder sbPageInfo = new System.Text.StringBuilder();

            System.Text.StringBuilder sbContent = new System.Text.StringBuilder();

            CY.CSTS.Core.Business.PagingInfo pagingInfo = new CY.CSTS.Core.Business.PagingInfo();
            CY.CSTS.Core.Business.AiSearchJson json = new CY.CSTS.Core.Business.AiSearchJson();

            try
            {
                #region --Init variable--

                string strJson = string.Empty;

                string strpageSize = string.Empty;

                string strpageNum = string.Empty;

                long totalCount = default(long);

                #endregion

                #region --init viriable and Validation --

                if (CY.Utility.Common.RequestUtility.IsGet)
                {
                    strJson = CY.Utility.Common.RequestUtility.GetQueryString("condition");
                    strpageSize = CY.Utility.Common.RequestUtility.GetQueryString("pagesize");
                    strpageNum = CY.Utility.Common.RequestUtility.GetQueryString("pagenum");
                }
                else if (CY.Utility.Common.RequestUtility.IsPost)
                {
                    strJson = CY.Utility.Common.RequestUtility.GetFormString("condition");
                    strpageSize = CY.Utility.Common.RequestUtility.GetFormString("pagesize");
                    strpageNum = CY.Utility.Common.RequestUtility.GetFormString("pagenum");
                }

                if (string.IsNullOrEmpty(strJson) || (json = Newtonsoft.Json.JavaScriptConvert.DeserializeObject(strJson, typeof(CY.CSTS.Core.Business.AiSearchJson)) as CY.CSTS.Core.Business.AiSearchJson) == null)
                {
                    return sbResult.Append("{success:false,action:'none',status:'error','参数错误!'}").ToString();
                }

                if (string.IsNullOrEmpty(strpageSize) || CY.Utility.Common.ConvertUtility.ConvertToInt(strpageSize, default(int)) <= 0 || string.IsNullOrEmpty(strpageNum) || CY.Utility.Common.ConvertUtility.ConvertToInt(strpageNum, default(int)) <= 0)
                {
                    return sbResult.Append("{success:false,action:'none',status:'error','参数错误!'}").ToString();
                }

                totalCount = CY.CSTS.Core.Business.AIChat.GetAiChatCount(json);

                pagingInfo.PageSize = CY.Utility.Common.ConvertUtility.ConvertToInt(strpageSize, default(int));
                pagingInfo.CurrentPage = CY.Utility.Common.ConvertUtility.ConvertToInt(strpageNum, default(int));

                List<CY.CSTS.Core.Business.AIChat> chats = CY.CSTS.Core.Business.AIChat.SelectAichatBySearchConditionPageInfo(json, pagingInfo) as List<CY.CSTS.Core.Business.AIChat>;
                if (chats != null)
                {
                    sbContent.Append("results:[");
                    foreach (CY.CSTS.Core.Business.AIChat chat in chats)
                    {
                        sbContent.Append("{");
                        sbContent.Append(string.Format("id:'{0}'", chat.Id.ToString()));
                        sbContent.Append(string.Format(",keyword:'{0}'", chat.KeyWords));
                        sbContent.Append(string.Format(",answer:'{0}'", chat.Answer));
                        sbContent.Append(string.Format(",unit:'{0}'", chat.UintID.ToString()));
                        sbContent.Append(string.Format(",unitname:'{0}'", chat.Unit.ToString()));
                        sbContent.Append(string.Format(",addtime:'{0}'", chat.AddTime.ToString("yyyy年MM月dd")));
                        sbContent.Append(string.Format(",addperson:'{0}'", chat.AddPerson.ToString()));
                        sbContent.Append("},");
                    }
                    if (chats.Count > 0)
                    {
                        sbContent.Remove(sbContent.Length - 1, 1);
                    }
                    sbContent.Append("]");
                }

                //pageinfo---分页信息--可以修改
                sbPageInfo.Append("pageinfo:");
                sbPageInfo.Append("{");
                sbPageInfo.Append(string.Format("pagesize:'{0}'", pagingInfo.PageSize));
                sbPageInfo.Append(string.Format(",pagenum:'{0}'", pagingInfo.CurrentPage));
                sbPageInfo.Append(string.Format(",totalcount:'{0}'", totalCount.ToString()));
                sbPageInfo.Append("}");

                sbResult.Append("{");
                sbResult.Append("success:true,action:'update',status:'success',msg:'success'");
                sbResult.Append(",");
                sbResult.Append(sbPageInfo.ToString());
                sbResult.Append(",");
                sbResult.Append(sbContent.ToString());
                sbResult.Append("}");

                #endregion

            }
            catch (Exception ex)
            {
                throw ex;
                return sbResult.Append("{success:false,action:'none',status:'error',msg:'查询出错,请稍候再试!'}").ToString();
            }
            finally
            {

            }
            return sbResult.ToString();
        }