Exemple #1
0
        public ActionResult Create()
        {
            bool result = false;

            AspectF.Define
            .Log(log, "RecordController-Create[post]开始", "RecordController-Create[post]结束")
            .HowLong(log)
            .Retry(log)
            .Do(() =>
            {
                var reader          = new StreamReader(Request.InputStream).ReadToEnd();
                var model           = JsonConvert.DeserializeObject <ViewRecord>(reader);
                BizRecord bizRecord = new BizRecord();
                ViewToDBForModel(bizRecord, model);
                result = recordService.Add(bizRecord);
            });
            if (result)
            {
                return(Json(new { status = "y" }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { status = "n" }, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #2
0
        public ActionResult GetAnswer(BizRule bizRule, string text)
        {
            RuleResult     ruleResult   = new RuleResult();
            TuLingResult   tuLingResult = new TuLingResult();
            BizRecord      bizRecord    = new BizRecord();
            List <BizRule> bizRules     = new List <BizRule>();

            AspectF.Define
            .Log(log, "RuleController-QueryRule[post]开始", "RuleController-QueryRule[post]结束")
            .HowLong(log)
            .Retry(log)
            .Do(() =>
            {
                text     = RegularRemoveSign(text);
                bizRules = ruleService.List(bizRule).ToList();
                Dictionary <string, string> keyValues = new Dictionary <string, string>();
                foreach (var item in bizRules)
                {
                    //关键字一为Null
                    if (item.KeyWordOne == null)
                    {
                        if (text.Contains(item.KeyWordTwo))
                        {
                            text = text.Substring(0, text.IndexOf(item.KeyWordTwo) + item.KeyWordTwo.Length);
                            string keyWordTwo = item.KeyWordTwo;
                            text    = text.Replace(keyWordTwo, "");
                            bizRule = ruleService.SingleTwo(keyWordTwo);
                        }
                    }
                    //关键字二为Null
                    else if (item.KeyWordTwo == null)
                    {
                        if (text.Contains(item.KeyWordOne))
                        {
                            text    = text.Substring(text.IndexOf(item.KeyWordOne));
                            text    = text.Replace(item.KeyWordOne, "");
                            bizRule = ruleService.SingleOne(item.KeyWordOne);
                        }
                    }
                    //关键字均不为空
                    else if (text.Contains(item.KeyWordOne))
                    {
                        if (text.Contains(item.KeyWordTwo))
                        {
                            text = text.Substring(text.IndexOf(item.KeyWordOne));
                            text = text.Substring(0, text.IndexOf(item.KeyWordTwo) + item.KeyWordTwo.Length);
                            text = text.Replace(item.KeyWordOne, "");
                            text = text.Replace(item.KeyWordTwo, "");
                            keyValues.Add(item.KeyWordOne, item.KeyWordTwo);
                            bizRule = ruleService.Single(keyValues.Keys.SingleOrDefault(), keyValues.Values.SingleOrDefault());
                        }
                    }
                }
            });
            if (bizRule.RuleID == null)
            {
                //图灵机器人回复
                ruleResult.text           = ConnectTu(text).text;
                bizRecord.QuestionContent = text;
                recordService.Add(bizRecord);
            }
            else
            {
                ruleResult.text    = bizRule.Answer;
                ruleResult.url     = bizRule.Website;
                ruleResult.type    = bizRule.AnswerTypes;
                ruleResult.keyword = text;
            }
            return(new JsonResultPro(ruleResult, JsonRequestBehavior.AllowGet, "yyyy-MM-dd"));
        }