using NetCore.BLL; using NetCore.BLL.crm; using NetCore.Common; using NetCore.Model.crm; using NetCore.Model.enums; using NetCore.Model.qw; using System; using System.Collections.Generic; using System.Linq; using System.Threading; namespace NetCore.Service.QW { /// /// 翻译成文本后的合规 /// public class ReCordHGThread { /// /// 随机数 /// public string matchstr { get; set; } public string threadKey { get; set; } /// /// 合规清洗取得数据量 /// public int hgclearcount { get; set; } public string keyName { get; set; } /// /// 是否需要sleep /// private bool needSleep { get; set; } public List words { get; set; } public string comcode { get; set; } public void execute() { hg_keyword_bll _keyword = new hg_keyword_bll(comcode); bas_config_bll _config_bll = new bas_config_bll(comcode); hg_message_word_bll _hgmsgwordbll = new hg_message_word_bll(comcode); crm_callrecord_bll _crmcall = new crm_callrecord_bll(comcode); hg_record_word_bll _wordbll = new hg_record_word_bll(comcode); try { string coreVoiceUrl = ConfigHelper.GetSectionValue("fileConfig:coreVoiceUrl"); string qwUrl = ConfigHelper.GetSectionValue("fileConfig:qwUrl"); string transBackUrl = ConfigHelper.GetSectionValue("fileConfig:transBackUrl"); while (true) { words = _keyword.GetWordListByParameter();//查询重新查询出所有的关键词 if (words.Any())//有关键词才开始行动 { needSleep = false;//默认不需要 睡眠 int sleepTime = _config_bll.GetIntConfig(BasConfigEnum.ManThreadSleepTime); try { hg_record_message_bll _hgmsgbll = new hg_record_message_bll(comcode); //words = _keyword.GetWordListByParameter();//查询重新查询出所有的关键词 //if (words.Any())//有关键词才开始行动 //{ //Console.WriteLine(string.Format("---关键词数量:{0}", words.Count)); bas_config config = _config_bll.GetConfig(BasConfigEnum.HgClearCount); hgclearcount = 100;// config != null ? Convert.ToInt32(config.value) : 1000;//重配置中获取最新的数量配置 List hgorderrecordList = _crmcall.GetNeedHegList(hgclearcount); DateTime now = DateTime.Now;//如果没有配置,那就从今天开始运算 var todaytime = new DateTime(now.Year, now.Month, now.Day); Console.WriteLine(string.Format("电话录音文本合规:matchstr:{0},数据量", matchstr, hgorderrecordList.Count)); int hegRows = 0; if (hgorderrecordList.Any()) { foreach (hg_order_record item in hgorderrecordList)//循环调用中心点进行数据翻译 { try { bool weiguile = false;//违规了 List wordlist = new List(); foreach (hg_keyword word in words) { if (KeyWordHelper.IsViolation(item.transcontent, word.keyword))//发现违规关键字 { wordlist.Add(new hg_record_word() { keyword = word.keyword, pkid = item.pkid }); weiguile = true; } } if (weiguile) { hegRows++; _wordbll.AddList(wordlist.ToArray());//新增消息违规关键字表 string word = string.Join("|", wordlist.Select(m => m.keyword));//关键词 hg_record_message msg = new hg_record_message() { hgstatus = 90, checkdate = item.checkdate, filename = item.filename, pkid = item.pkid, resid = item.resid, saleseid = item.saleseid, transcontent = item.transcontent, transtime = item.transtime, voiceurl = item.voiceurl, word = word }; _hgmsgbll.Add(msg); } } catch (Exception e) { LogHelper.Error(e.ToString()); } Thread.Sleep(500); } _crmcall.UpdateHgStatus(hgorderrecordList.Select(m => m.id).ToList());//修改合规状态 _hgmsgbll.StartInsert(); } else { needSleep = true;//没有数据,进行休眠 } //} //else //{ // Console.WriteLine("无关键词"); //} } catch (Exception e) { Console.WriteLine(string.Format("电话录音文本合规线程错误matchstr:{0},erro:{1}", matchstr, e.ToString())); LogHelper.Error(e.ToString()); } finally { Console.WriteLine(string.Format("电话录音文本合规线程结束 matchstr:{0}", matchstr)); } if (needSleep) { Console.WriteLine(string.Format("{0}没数据了休息{1}分钟", "电话录音文本合规", sleepTime)); Thread.Sleep((sleepTime == 0 ? 3 : sleepTime) * 60 * 1000);//默认3分钟执行一次,从数据库获取 } else Thread.Sleep(5000);//如果有数据就只休息5秒钟 } } } catch (Exception aa) { Program.ToFinishMan(threadKey); LogHelper.Error(aa.ToString()); } } } }