113 lines
4.7 KiB
C#
113 lines
4.7 KiB
C#
using NetCore.BLL;
|
||
using NetCore.BLL.qw;
|
||
using NetCore.Common;
|
||
using NetCore.Model.enums;
|
||
using NetCore.Model.qw;
|
||
using System;
|
||
using System.Threading;
|
||
|
||
namespace NetCore.Service.QW
|
||
{
|
||
/// <summary>
|
||
/// 微信电话
|
||
/// </summary>
|
||
public class RecordThread
|
||
{
|
||
public string threadKey { get; set; }
|
||
public string keyName { get; set; }
|
||
public DateTime checkdate { get; set; }
|
||
public string matchstr { get; set; }
|
||
private bool needSleep { get; set; }
|
||
public int hgclearcount { get; set; }
|
||
public string name { get; set; }
|
||
public hg_excute_log log { get; set; }
|
||
public string comcode { get; set; }
|
||
|
||
public void execute()
|
||
{
|
||
try
|
||
{
|
||
bas_config_bll _config_bll = new bas_config_bll(comcode);
|
||
hg_man_config_bll _manconfigbll = new hg_man_config_bll(comcode);
|
||
hg_record_bll recordbll = new hg_record_bll(comcode);
|
||
|
||
while (true)
|
||
{
|
||
needSleep = false;//默认不需要 睡眠
|
||
int sleepTime = _config_bll.GetIntConfig(BasConfigEnum.ManThreadSleepTime);
|
||
try
|
||
{
|
||
log = new hg_excute_log();
|
||
bas_config config = _config_bll.GetConfig(BasConfigEnum.HgClearCount);
|
||
hgclearcount = config != null ? Convert.ToInt32(config.value) : 1000;//重配置中获取最新的数量配置
|
||
|
||
|
||
//int SeqMax = msgPKID;
|
||
|
||
hg_record_bll _hgmsgbll = new hg_record_bll(comcode);
|
||
hg_man_config manconfig = _manconfigbll.GetNowManConfig("ReCordConfig");//获取企业微信的当前配置
|
||
|
||
#region 初始化属性
|
||
DateTime now = DateTime.Now;//如果没有配置,那就从今天开始运算
|
||
var todaytime = new DateTime(now.Year, now.Month, now.Day);
|
||
|
||
if (manconfig == null)//找不到配置,进行插入操作
|
||
{
|
||
_manconfigbll.Add(new hg_man_config()
|
||
{
|
||
tablename = "ww_record",
|
||
checkdate = todaytime,
|
||
seq = 0,
|
||
corpid = "ReCordConfig",
|
||
name = "企业微信电话",
|
||
status = 0
|
||
});
|
||
manconfig = _manconfigbll.GetNowManConfig("ReCordConfig");//获取企业微信的当前配置
|
||
}
|
||
|
||
//msgPKID = manconfig.pkid;
|
||
checkdate = manconfig.checkdate;
|
||
bool result = recordbll.ExeRecordToVoice(checkdate);
|
||
if (result)
|
||
{
|
||
if (checkdate == todaytime)
|
||
{
|
||
needSleep = true;//已经最新到当天了,所以需要休眠
|
||
}
|
||
_manconfigbll.updateRecord(new hg_man_config() { corpid = "ReCordConfig", name = "企业微信电话", seq = 0, tablename = "ww_record", checkdate = (checkdate < todaytime ? checkdate.AddDays(1) : checkdate), status = 0 });//这天进行完成
|
||
}
|
||
|
||
#endregion
|
||
}
|
||
|
||
catch (Exception e)
|
||
{
|
||
Console.WriteLine(string.Format("企微电话入库线程错误:matchstr:{0},erro:{1}", matchstr, e.ToString()));
|
||
log.status = 500;
|
||
log.message = "system erro:" + e.ToString();
|
||
|
||
LogHelper.Error(e.ToString());
|
||
}
|
||
finally
|
||
{
|
||
Console.WriteLine(string.Format("企微电话入库线程结束,matchstr:{0},信息:{1},checkdate:{2}", matchstr, log.message, checkdate.ToString("yyyy-MM-dd")));
|
||
}
|
||
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());
|
||
}
|
||
}
|
||
|
||
}
|
||
} |