TG.WXCRM.V4/NetCore.Service/RC/ReCoredThread.cs

209 lines
8.8 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using NetCore.BLL;
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.RC
{
/// <summary>
/// 录音翻译线程
/// </summary>
public class ReCoredThread
{
/// <summary>
/// 生成的ID
/// </summary>
public decimal seq { get; set; }
public string threadKey { get; set; }
/// <summary>
/// 随机数
/// </summary>
public string matchstr { get; set; }
/// <summary>
/// 合规清洗取得数据量
/// </summary>
public int hgclearcount { get; set; }
/// <summary>
/// 客户发得消息是否需要合规默认0不需要 1需要
/// </summary>
public int cusmsgdeedhg { get; set; }
public hg_excete_log_crm log { get; set; }
public string keyName { get; set; }
public DateTime checkdate { get; set; }
/// <summary>
/// 是否需要sleep
/// </summary>
private bool needSleep { get; set; }
public string comcode { get; set; }
public void execute()
{
bas_config_bll _config_bll = new bas_config_bll(comcode);
crm_hg_record_config_bll _manconfigbll = new crm_hg_record_config_bll(comcode);
//hg_message_word_bll _hgmsgwordbll = new hg_message_word_bll();
try
{
while (true)
{
needSleep = false;//默认不需要 睡眠
int sleepTime = _config_bll.GetIntConfig(BasConfigEnum.ManThreadSleepTime);
string recordUrl = ConfigHelper.GetSectionValue($"{comcode}_Config:fileConfig:recordUrl");
//将数据入库
try
{
//Console.WriteLine(string.Format("---关键词数量:{0}", words.Count));
bas_config config = _config_bll.GetConfig(BasConfigEnum.PhoneRecordTransCount);
hgclearcount = config != null ? Convert.ToInt32(config.value) : 1000;//重配置中获取最新的数量配置
decimal SeqMax = seq;
crm_callrecord_bll _msgbll = new crm_callrecord_bll(comcode);
//hg_message_bll _hgmsgbll = new hg_message_bll();
//hg_ordervoice_bll _ordervoice = new hg_ordervoice_bll();
hg_record_config manconfig = _manconfigbll.GetNowManConfig();//获取企业微信的当前配置
#region
DateTime now = DateTime.Now;//如果没有配置,那就从今天开始运算
var todaytime = new DateTime(now.Year, now.Month, now.Day);
if (manconfig == null)//找不到配置,进行插入操作
{
_manconfigbll.Add(new hg_record_config()
{
checkdate = todaytime,
ctime = DateTime.Now,
pkid = 0,
status = 0
});
manconfig = _manconfigbll.GetNowManConfig();//获取企业微信的当前配置
}
seq = manconfig.pkid;
checkdate = manconfig.checkdate;
#endregion
log = new hg_excete_log_crm()
{
starttime = DateTime.Now,
type = "tran"
};
Console.WriteLine(string.Format("电话录音入库线程开始:matchstr:{0}", matchstr));
List<crm_callrecord> hgmsgList = _msgbll.GetList(hgclearcount, seq, checkdate);///获取消息数据量
if (hgmsgList.Any())
{
foreach (crm_callrecord item in hgmsgList)
{
SeqMax = item.pkid > SeqMax ? item.pkid : SeqMax;
var voiceUrl = recordUrl + item.filename;
_msgbll.Add(new hg_order_record()
{
checkdate = checkdate,
filename = item.filename,
voiceurl = voiceUrl,
resid = item.resid,
pkid = item.pkid,
saleseid = item.saleseid,
timelength = item.timelength
});
}
_msgbll.StartInsert();
//_ordervoice.StartInsert();
}
else
{
if (todaytime != checkdate)//比如过度到了第二天
{
//corptable nexttable = nowtable.Where(m => String.Compare(m.table_name, tablename) == 1).OrderBy(m => m.table_name).FirstOrDefault();//取大于当前tablename得数据
//if (nexttable != null)
//{
// tablename = nexttable.table_name;//跳到下一个表
//}
_manconfigbll.update(new hg_record_config() { checkdate = checkdate, status = 1, pkid = SeqMax, id = manconfig.id });//这天进行完成
_manconfigbll.Add(new hg_record_config()
{
pkid = seq,
status = 0,
ctime = DateTime.Now,
checkdate = checkdate.AddDays(1)//下一天
});
checkdate = checkdate.AddDays(1);
}
else
{
needSleep = true;
}
}
seq = SeqMax;//修改最大值,下次继续
_manconfigbll.update(new hg_record_config() { checkdate = checkdate, status = 0, pkid = SeqMax, id = manconfig.id, utime = DateTime.Now });
log.status = 200;
log.message = string.Format("seq {0}~{1},rows count {2} ,checkdate:{3}", seq, SeqMax, hgmsgList.Count, checkdate.ToString("yyyy-MM-dd"));
GoLog();
_msgbll.Clear();
}
catch (Exception e)
{
Console.WriteLine(string.Format("电话录音入库线程错误:pkid:{0},matchstr:{1}erro:", seq, matchstr, e.ToString()));
log.status = 500;
log.message = "system erro:" + e.ToString();
GoLog();
LogHelper.Error(e.ToString());
}
finally
{
Console.WriteLine(string.Format("电话录音入库线程结束:pkid:{0},matchstr:{1},信息:{2},checkdate:{3}", seq, matchstr, log.message, checkdate.ToString("yyyy-MM-dd")));
}
//将数据进行翻译
try
{
}
catch (Exception e)
{
}
if (needSleep)
{
Console.WriteLine(string.Format("电话录音入库线程没数据了休息{0}分钟", 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());
}
}
/// <summary>
/// 执行日志记录
/// </summary>
public void GoLog()
{
log.endtime = DateTime.Now;
log.exscend = (int)(log.endtime.Value - log.starttime.Value).TotalSeconds;
hg_excute_log_bll bll = new hg_excute_log_bll(comcode);
bll.LogCrm(log);
}
}
}