TG.WXCRM.V4/NetCore.Service/MainThread.cs

302 lines
16 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.Model.enums;
using NetCore.Model.qw;
using System;
using System.Collections.Generic;
using System.Threading;
namespace NetCore.Service
{
public class MainThread
{
public string comcode { get; set; }
public string funcconfig { get; set; }
public void Execte()
{
bas_config_bll _config_bll = new bas_config_bll(comcode);
while (true)
{
int sleepTime = 3;
try
{
Console.WriteLine($"{comcode}企业开始执行合规数据:" + funcconfig);
sleepTime = _config_bll.GetIntConfig(BasConfigEnum.MainSleepTime);
ww_corp_bll _corp_bll = new ww_corp_bll(comcode);
if (funcconfig.Contains("[QW]"))
{
Console.WriteLine("企业微信合规数据库初始化");
//new qw_orderuser_bll(comcode).InitHgOrderUser();//从oracle中读取订单客户到mysql中(已兼容)
//new qw_orderuser_bll(comcode).InitHgJobUser();//从oracle中读取工作企业微信到mysql中已兼容
}
if (funcconfig.Contains("[RECORD]"))
{
Console.WriteLine("坐席录音合规数据库初始化");
//new crm_orderuser_bll(comcode).InitHgOrderResid();//从oracle中读取订单客户到oracle中
}
if (funcconfig.Contains("[WX]"))
{
Console.WriteLine("微信合规数据库初始化");
//new wx_orderuser_bll(comcode).InitHgOrderUserName();//从oracle中读取订单username到sqlserver已兼容
//new wx_orderuser_bll(comcode).InitJobUserName();//初始化工作微信到sqlserver已兼容
}
Console.WriteLine("order customer read completed!");
List<ww_corp> corplist = _corp_bll.GetList();
Console.WriteLine("企业号主线程检测:");
bas_config config2 = _config_bll.GetConfig(BasConfigEnum.CusMsgNeedHG);//客户发得消息是否需要合规
int CusMsgNeedHG = config2 != null ? Convert.ToInt32(config2.value) : 0;
#region
//if (funcconfig.Contains("[QW]"))
//{
// foreach (ww_corp item in corplist)
// {
// if (item.corpid != "ww89347c2378b6e050")
// continue;
// if (!Program.corpThread.ContainsKey($"{comcode}_{item.corpid}"))//如果有新的corp就新开一个线程
// {
// Console.WriteLine("+++++++主线程:" + item.corpid);
// MainCorpThread thmodel = new MainCorpThread()
// {
// corpid = item.corpid,
// name = item.corpname,
// matchstr = Program.GenerateRandomLetter(5),
// seq = 0,
// tablename = "",
// cusmsgdeedhg = CusMsgNeedHG,
// keyName = item.corpid,
// comcode = comcode,
// threadKey = $"{comcode}_{item.corpid}"
// //checkdate = item.checkdate
// };
// Thread thread = new Thread(new ThreadStart(thmodel.execute));
// thread.Start();
// Program.corpThread.Add($"{comcode}_{item.corpid}", item.corpname);
// Thread.Sleep(1000);
// break;
// }
// }
// if (!Program.corpThread.ContainsKey($"{comcode}_qwReCord"))//企业微信电话入库
// {
// Console.WriteLine("+++++++主线程:qwReCord");
// RecordThread thmodel = new RecordThread()
// {
// matchstr = Program.GenerateRandomLetter(5),
// keyName = "企微电话",
// comcode = comcode,
// threadKey = $"{comcode}_qwReCord"
// };
// Thread thread = new Thread(new ThreadStart(thmodel.execute));
// thread.Start();
// Program.corpThread.Add($"{comcode}_qwReCord", "企微电话");
// Thread.Sleep(1000);
// }
// if (!Program.corpThread.ContainsKey($"{comcode}_qwFiles"))//
// {
// Console.WriteLine("+++++++主线程:qwFiles");
// FilesThread thmodel = new FilesThread()
// {
// matchstr = Program.GenerateRandomLetter(5),
// tablename = "",
// keyName = "企微文件翻译",
// comcode = comcode,
// threadKey = $"{comcode}_qwFiles"
// };
// Thread thread = new Thread(new ThreadStart(thmodel.execute));
// thread.Start();
// Program.corpThread.Add($"{comcode}_qwFiles", "企微文件翻译");
// Thread.Sleep(1000);
// }
// if (!Program.corpThread.ContainsKey($"{comcode}_qwHGFiles"))//如果有新的corp就新开一个线程
// {
// Console.WriteLine("+++++++主线程:qwHGFiles");
// FilesHGThread thmodel = new FilesHGThread()
// {
// matchstr = Program.GenerateRandomLetter(5),
// tablename = "",
// keyName = "企微语音文本合规",
// comcode = comcode,
// threadKey = $"{comcode}_qwHGFiles"
// };
// Thread thread = new Thread(new ThreadStart(thmodel.execute));
// thread.Start();
// Program.corpThread.Add($"{comcode}_qwHGFiles", "企微语音文本合规");
// Thread.Sleep(1000);
// }
//}
#endregion
#region
//if (funcconfig.Contains("[RECORD]"))
//{
// if (!Program.corpThread.ContainsKey($"{comcode}_ReCord"))//语音翻译
// {
// Console.WriteLine("+++++++主线程:ReCord");
// ReCoredThread thmodel = new ReCoredThread()
// {
// matchstr = Program.GenerateRandomLetter(5),
// keyName = "订单电话语音入库",
// threadKey = $"{comcode}_ReCord"
// };
// Thread thread = new Thread(new ThreadStart(thmodel.execute));
// thread.Start();
// Program.corpThread.Add($"{comcode}_ReCord", "订单电话语音入库");
// Thread.Sleep(1000);
// }
// if (!Program.corpThread.ContainsKey($"{comcode}_ReCordTrans"))//语音翻译
// {
// Console.WriteLine("+++++++主线程:ReCordTrans");
// ReCoredTransThread thmodel = new ReCoredTransThread()
// {
// matchstr = Program.GenerateRandomLetter(5),
// keyName = "电话语音翻译",
// comcode = comcode,
// threadKey = $"{comcode}_ReCordTrans"
// };
// Thread thread = new Thread(new ThreadStart(thmodel.execute));
// thread.Start();
// Program.corpThread.Add($"{comcode}_ReCordTrans", "电话语音翻译");
// Thread.Sleep(1000);
// }
// if (!Program.corpThread.ContainsKey($"{comcode}_ReCordHG"))//语音翻译
// {
// Console.WriteLine("+++++++主线程:ReCordHG");
// ReCordHGThread thmodel = new ReCordHGThread()
// {
// matchstr = Program.GenerateRandomLetter(5),
// keyName = "电话录音文本合规",
// threadKey = $"{comcode}_ReCordHG"
// };
// Thread thread = new Thread(new ThreadStart(thmodel.execute));
// thread.Start();
// Program.corpThread.Add($"{comcode}_ReCordHG", "电话录音文本合规");
// Thread.Sleep(1000);
// }
//}
#endregion
#region
//if (funcconfig.Contains("[WX]"))
//{
// if (!Program.corpThread.ContainsKey($"{comcode}_wxMsgHG"))//语音翻译
// {
// Console.WriteLine("+++++++主线程:wxMsgHG");
// MainMsgTread thmodel = new MainMsgTread()
// {
// matchstr = Program.GenerateRandomLetter(5),
// keyName = "微信文本合规",
// comcode = comcode,
// threadKey = $"{comcode}_wxMsgHG"
// };
// Thread thread = new Thread(new ThreadStart(thmodel.execute));
// thread.Start();
// Program.corpThread.Add($"{comcode}_wxMsgHG", "微信文本合规");
// Thread.Sleep(1000);
// }
// if (!Program.corpThread.ContainsKey($"{comcode}_wxFiles"))//语音翻译
// {
// Console.WriteLine("+++++++主线程:wxFiles");
// wxFilesThread thmodel = new wxFilesThread()
// {
// matchstr = Program.GenerateRandomLetter(5),
// keyName = "微信语音翻译",
// comcode = comcode,
// threadKey = $"{comcode}_wxFiles"
// };
// Thread thread = new Thread(new ThreadStart(thmodel.execute));
// thread.Start();
// Program.corpThread.Add($"{comcode}_wxFiles", "微信语音合规");
// Thread.Sleep(1000);
// }
// if (!Program.corpThread.ContainsKey($"{comcode}_wxTransTxt"))//语音文本合规
// {
// Console.WriteLine("+++++++主线程:wxTransTxt");
// wxVideoContentHgThread thmodel = new wxVideoContentHgThread()
// {
// matchstr = Program.GenerateRandomLetter(5),
// keyName = "微信语音文本合规",
// comcode = comcode,
// threadKey = $"{comcode}_wxTransTxt"
// };
// Thread thread = new Thread(new ThreadStart(thmodel.execute));
// thread.Start();
// Program.corpThread.Add($"{comcode}_wxTransTxt", "微信语音文本合规");
// Thread.Sleep(1000);
// }
//}
#endregion
#region
if (!Program.corpThread.ContainsKey($"{comcode}_PushMsg"))//语音翻译
{
Console.WriteLine("+++++++主线程:PushMsg");
PushThread thmodel = new PushThread()
{
matchstr = Program.GenerateRandomLetter(5),
keyName = "推送数据",
comcode = comcode,
threadKey = $"{comcode}_PushMsg"
};
Thread thread = new Thread(new ThreadStart(thmodel.execute));
thread.Start();
Program.corpThread.Add($"{comcode}_PushMsg", "推送数据");
Thread.Sleep(1000);
}
#endregion
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
Thread.Sleep((sleepTime == 0 ? 20 : sleepTime) * 60 * 1000);//默认20分钟执行一次从数据库获取
}
}
}
}
#region
//List<hg_make_up> makeuplist = _make_up.GetList();//获取补充字段得列表
//if (makeuplist.Any())
//{
// var group = makeuplist.GroupBy(m => new { m.corpid, m.pici });//通过seq相同分配到同一个线程进行处理
// foreach (var gp in group)
// {
// string key = string.Format("{0}_{1}", gp.Key.corpid, gp.Key.pici);
// if (!makeThread.ContainsKey(key))//无此批次就新增
// {
// Console.WriteLine("+++++++补充关键词线程:" + key);
// List<hg_make_up> mlist = makeuplist.Where(m => m.corpid == gp.Key.corpid && m.pici == gp.Key.pici).ToList();
// int maxseq = mlist.Max(m => m.maxseq);///取最大得seq
// List<hg_keyword> mywordlist = mlist.Select(m => new hg_keyword() { keyword = m.keyword }).ToList();//合并到一起关键词
// MakeUpThread thmodel = new MakeUpThread()
// {
// corpid = gp.Key.corpid,
// //name = item.name,
// matchstr = GenerateRandomLetter(5),
// seq = mlist.FirstOrDefault().seq,
// maxseq = maxseq,
// tablename = mlist.FirstOrDefault().tablename,
// words = mywordlist,
// cusmsgdeedhg = CusMsgNeedHG,
// makeuplist = mlist,
// keyName = key
// };
// Thread thread = new Thread(new ThreadStart(thmodel.execute));
// thread.Start();
// makeThread.Add(key, key);
// Thread.Sleep(1000);
// }
// }
//}
#endregion