256 lines
11 KiB
C#
256 lines
11 KiB
C#
using NetCore.BLL;
|
||
using NetCore.Common;
|
||
using NetCore.Model;
|
||
using NetCore.Model.enums;
|
||
using NetCore.Model.qw;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading;
|
||
|
||
namespace NetCore.Service.QW
|
||
{
|
||
/// <summary>
|
||
/// 补充关键字
|
||
/// </summary>
|
||
public class MakeUpThread
|
||
{
|
||
|
||
public string corpid { get; set; }
|
||
/// <summary>
|
||
/// 生成的ID
|
||
/// </summary>
|
||
public int seq { get; set; }
|
||
/// <summary>
|
||
/// 最大得补充序号
|
||
/// </summary>
|
||
public int maxseq { get; set; }
|
||
/// <summary>
|
||
/// 表名称
|
||
/// </summary>
|
||
public string tablename { get; set; }
|
||
/// <summary>
|
||
/// 企业名称
|
||
/// </summary>
|
||
public string name { 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; }
|
||
/// <summary>
|
||
/// 执行得makeupid
|
||
/// </summary>
|
||
public int makeupid { get; set; }
|
||
|
||
public hg_excute_log log { get; set; }
|
||
public List<hg_keyword> words { get; set; }
|
||
public string keyName { get; set; }
|
||
/// <summary>
|
||
/// 需要补充得集合
|
||
/// </summary>
|
||
public List<hg_make_up> makeuplist { 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);
|
||
bool isFinish = false;
|
||
while (isFinish == false)
|
||
{
|
||
needSleep = false;
|
||
int sleepTime = _config_bll.GetIntConfig(BasConfigEnum.MakeUpSleepTime);
|
||
try
|
||
{
|
||
bas_config config = _config_bll.GetConfig(BasConfigEnum.HgClearCount);
|
||
hgclearcount = config != null ? Convert.ToInt32(config.value) : 1000;//重配置中获取最新的数量配置
|
||
|
||
int SeqMax = seq;
|
||
hg_make_up_bll _makeupbll = new hg_make_up_bll(comcode);
|
||
bas_config_bll _configbll = new bas_config_bll(comcode);
|
||
ww_message_bll _msgbll = new ww_message_bll(comcode);
|
||
hg_message_bll _hgmsgbll = new hg_message_bll(comcode);
|
||
hg_message_word_bll _hgmsgwordbll = new hg_message_word_bll(comcode);
|
||
log = new hg_excute_log()
|
||
{
|
||
corpid = corpid,
|
||
starttime = DateTime.Now,
|
||
name = name,
|
||
seq = seq,
|
||
tablename = tablename
|
||
};
|
||
|
||
Console.WriteLine(string.Format("补充线程开始:corpid:{0},name:{1},seq:{2},talename:{3},matchstr:{4}", corpid, name, seq, tablename, matchstr));
|
||
List<corptable> nowtable = _configbll.GetCorpTable(corpid);//本月及本月之前的表
|
||
if (!nowtable.Any())
|
||
{
|
||
Console.WriteLine(string.Format("没有消息表,corpid:{0},name:{1},seq:{2},talename:{3},matchstr:{4}", corpid, name, seq, tablename, matchstr));
|
||
log.status = 500;
|
||
log.message = "can't find message tables!";
|
||
GoLog();
|
||
return;
|
||
}
|
||
string nowtablename = string.Format("ww_message_{0}", DateTime.Now.ToString("yyyyMM"));//当前时间应该的名称
|
||
if (string.IsNullOrEmpty(tablename))
|
||
{
|
||
tablename = nowtable.OrderBy(m => m.table_name).FirstOrDefault().table_name;
|
||
}
|
||
List<ww_message> hgmsgList = _msgbll.GetList(tablename, corpid, hgclearcount, seq,0,DateTime.Now);///获取消息数据量
|
||
int hegRows = 0;
|
||
if (hgmsgList.Any())
|
||
{
|
||
foreach (ww_message item in hgmsgList)
|
||
{
|
||
SeqMax = item.seq > SeqMax ? item.seq : SeqMax;
|
||
if (cusmsgdeedhg == 0 && item.fromer.Length == 32)//客户发得消息,不做合规
|
||
continue;
|
||
bool weiguile = false;//违规了
|
||
List<hg_message_word> wordlist = new List<hg_message_word>();
|
||
foreach (hg_keyword word in words)
|
||
{
|
||
if (KeyWordHelper.IsViolation(item.content, word.keyword))//发现违规关键字
|
||
{
|
||
wordlist.Add(new hg_message_word() { keyword = word.keyword, msgid = item.msgid });
|
||
weiguile = true;
|
||
}
|
||
}
|
||
if (weiguile)
|
||
{
|
||
hegRows++;
|
||
_hgmsgwordbll.AddList(wordlist.ToArray());//新增消息违规关键字表
|
||
hg_message msg = new hg_message()
|
||
{
|
||
action = item.action,
|
||
//fromer = item.fromer,
|
||
//tolist = item.tolist,
|
||
content = item.content,
|
||
corpid = corpid,
|
||
cusname = "",
|
||
ext = item.ext,
|
||
hgstatus = 90,
|
||
//issend = 1,
|
||
kehuname = "",
|
||
msgid = item.msgid,
|
||
msgtype = item.msgtype,
|
||
nfile = item.nfile,
|
||
roomid = item.roomid,
|
||
seq = item.seq,
|
||
msgtime = item.msgtime,
|
||
};
|
||
if (string.IsNullOrEmpty(item.roomid))//非群得合规表
|
||
{
|
||
if (item.fromer.Length == 32)//客户发得消息
|
||
{
|
||
msg.issend = 0;
|
||
msg.fromer = item.tolist;
|
||
msg.tolist = item.fromer;
|
||
}
|
||
else
|
||
{
|
||
msg.issend = 1;
|
||
msg.fromer = item.fromer;
|
||
msg.tolist = item.tolist;
|
||
}
|
||
_hgmsgbll.Add(msg);
|
||
}
|
||
else
|
||
{
|
||
_hgmsgbll.AddGroupMsg(msg);
|
||
}
|
||
}
|
||
}
|
||
_hgmsgbll.StartInsert();
|
||
}
|
||
else
|
||
{
|
||
if (nowtablename != tablename)//找不到数据,将表修改到下一个表
|
||
{
|
||
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;//跳到下一个表
|
||
}
|
||
}
|
||
else
|
||
{
|
||
needSleep = true;//需要sleep
|
||
}
|
||
}
|
||
_makeupbll.update(makeuplist, SeqMax, tablename);//修改执行状态
|
||
log.status = 200;
|
||
log.message = string.Format("succed {2} rows:seq {0}~{1} ,and hg {3} rows", seq, SeqMax, hgmsgList.Count, hegRows);
|
||
|
||
GoLog();
|
||
seq = SeqMax;
|
||
|
||
if (seq >= maxseq)
|
||
{
|
||
isFinish = true;
|
||
Program.ToFinishMakeUp(keyName);//修改完成状态
|
||
}
|
||
_hgmsgbll.Clear();
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
Console.WriteLine(string.Format("补充线程错误:corpid:{0},name:{1},seq:{2},talename:{3},matchstr:{4},erro:", corpid, name, seq, tablename, matchstr, e.ToString()));
|
||
log.status = 500;
|
||
log.message = "system erro:" + e.ToString();
|
||
GoLog();
|
||
LogHelper.Error(e.ToString());
|
||
Program.ToFinishMakeUp(keyName);//完犊子了,修改状态
|
||
}
|
||
finally
|
||
{
|
||
Console.WriteLine(string.Format("补充线程结束:corpid:{0},name:{1},seq:{2},talename:{3},matchstr:{4},信息:{5}", corpid, name, seq, tablename, matchstr, log.message));
|
||
}
|
||
if (isFinish == false)
|
||
{
|
||
if (needSleep)
|
||
{
|
||
|
||
Thread.Sleep((sleepTime == 0 ? 5 : sleepTime) * 60 * 1000);//默认5分钟执行一次,从数据库获取
|
||
}
|
||
else
|
||
{
|
||
Thread.Sleep(5000);//如果有数据就只休息5秒钟
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
/// <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);
|
||
var picilist = makeuplist.GroupBy(m => new { m.pici });
|
||
foreach (var item in picilist)
|
||
{
|
||
log.pici = item.Key.pici;//执行入库
|
||
bll.Log(log);
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
}
|
||
|