153 lines
7.1 KiB
C#
153 lines
7.1 KiB
C#
using NetCore.BLL;
|
||
using NetCore.Common;
|
||
using NetCore.Model;
|
||
using NetCore.Model.crm;
|
||
using NetCore.Model.enums;
|
||
using NetCore.Model.qw;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading;
|
||
using System.Web;
|
||
|
||
namespace NetCore.Service.RC
|
||
{
|
||
public class ReCoredTransThread
|
||
{
|
||
|
||
/// <summary>
|
||
/// 表名称
|
||
/// </summary>
|
||
public string tablename { get; set; }
|
||
public string threadKey { get; set; }
|
||
|
||
|
||
/// <summary>
|
||
/// 随机数
|
||
/// </summary>
|
||
public string matchstr { get; set; }
|
||
|
||
/// <summary>
|
||
/// 合规清洗取得数据量
|
||
/// </summary>
|
||
public int hgclearcount { get; set; }
|
||
|
||
//public List<hg_keyword> words { get; set; }
|
||
public string keyName { get; set; }
|
||
/// <summary>
|
||
/// 是否需要sleep
|
||
/// </summary>
|
||
private bool needSleep { 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_man_config_bll _manconfigbll = new hg_man_config_bll();
|
||
//ww_message_bll _msgbll = new ww_message_bll();
|
||
//hg_message_word_bll _hgmsgwordbll = new hg_message_word_bll();
|
||
crm_callrecord_bll _ordervoice = new crm_callrecord_bll(comcode);
|
||
try
|
||
{
|
||
string coreVoiceUrl = ConfigHelper.GetSectionValue($"{comcode}_Config:fileConfig:coreVoiceUrl");
|
||
string transBackUrl = ConfigHelper.GetSectionValue($"{comcode}_Config:fileConfig:transBackUrl");
|
||
string recordUrl = ConfigHelper.GetSectionValue($"{comcode}_Config:fileConfig:recordUrl");
|
||
|
||
while (true)
|
||
{
|
||
needSleep = false;//默认不需要 睡眠
|
||
int sleepTime = _config_bll.GetIntConfig(BasConfigEnum.ManThreadSleepTime);
|
||
try
|
||
{
|
||
//words = _keyword.GetWordListByParameter();//查询重新查询出所有的关键词
|
||
//if (words.Any())//有关键词才开始行动
|
||
//{
|
||
//Console.WriteLine(string.Format("---关键词数量:{0}", words.Count));
|
||
bas_config config = _config_bll.GetConfig(BasConfigEnum.PhoneRecordTransCount);
|
||
hgclearcount = config != null ? Convert.ToInt32(config.value) : 1000;//重配置中获取最新的数量配置
|
||
|
||
List<hg_order_record> ordvoiceList = _ordervoice.GetNeedTransList(hgclearcount);
|
||
|
||
DateTime now = DateTime.Now;//如果没有配置,那就从今天开始运算
|
||
var todaytime = new DateTime(now.Year, now.Month, now.Day);
|
||
Console.WriteLine(string.Format("电话录音翻译线程:matchstr:{0},数据量{1}", matchstr, ordvoiceList.Count));
|
||
if (ordvoiceList.Any())
|
||
{
|
||
foreach (hg_order_record item in ordvoiceList)//循环调用中心点进行数据翻译
|
||
{
|
||
try
|
||
{
|
||
if (!item.voiceurl.Contains("http:"))
|
||
item.voiceurl = $"{recordUrl}{item.voiceurl}";
|
||
string st = HttpHelper.GetData(coreVoiceUrl, $"voiceUrl={HttpUtility.UrlEncode(item.voiceurl)}&returnUrl={HttpUtility.UrlEncode(transBackUrl + "?type=crm&voiceid=" + item.id + "&comcode=" + comcode)}", Encoding.UTF8);
|
||
Console.WriteLine($"地址:{item.voiceurl}\n 返回结果 {st}");
|
||
ApiResult result = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResult>(st);
|
||
if (result.result)
|
||
{
|
||
if (result.retcode == 10001)//已经翻译过,直接入库修改数据
|
||
{
|
||
_ordervoice.ToTrans(item.id, 3);//已经开始翻译了
|
||
int transstatus = 0;
|
||
dynamic info = result.retData;
|
||
if (info.StatusText == "SUCCESS")
|
||
{
|
||
transstatus = 1;
|
||
}
|
||
else
|
||
{
|
||
transstatus = 2;
|
||
}
|
||
_ordervoice.TransBack((string)info.voicetext, item.id, transstatus);
|
||
}
|
||
else
|
||
{
|
||
_ordervoice.ToTrans(item.id, 3);//已经开始翻译了
|
||
//这个时候需要根据语音的长度进行休眠,因为语音比较大,花费的时间比较长
|
||
Thread.Sleep(item.timelength * 10 * 2);//需要休息的长度
|
||
}
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
LogHelper.Error(e.ToString());
|
||
}
|
||
//Thread.Sleep(2000);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
needSleep = true;//没有数据,进行休眠
|
||
}
|
||
|
||
}
|
||
|
||
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());
|
||
}
|
||
}
|
||
}
|
||
} |