148 lines
5.8 KiB
C#
148 lines
5.8 KiB
C#
using CRM.Core.DTO;
|
||
using Newtonsoft.Json;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using WX.CRM.BLL.Base;
|
||
using WX.CRM.BLL.Csvr;
|
||
using WX.CRM.Common;
|
||
using WX.CRM.Model.Entity;
|
||
using System.Threading;
|
||
using WX.CRM.BLL.Util;
|
||
using WX.CRM.BLL.Res;
|
||
|
||
namespace WX.CRM.CRMServices.WeiXin
|
||
{
|
||
public static class UCRDingDingPush
|
||
{
|
||
private static BAS_PARAMETER_BL _BAS_PARAMETER_Q = new BAS_PARAMETER_BL();
|
||
private static CSVR_CALLRECORD_BL _CSVR_CALLRECORD_BL = new CSVR_CALLRECORD_BL();
|
||
private static RES_CUSTOMER_BL _RES_CUSTOMER_BL = new RES_CUSTOMER_BL();
|
||
/// <summary>
|
||
/// 推送
|
||
/// </summary>
|
||
public static void Push() {
|
||
var dingTalkRemindTimeStr = _BAS_PARAMETER_Q.GetModel_Patameter("DingTalkRemindTime");
|
||
if (dingTalkRemindTimeStr == null)
|
||
return;
|
||
|
||
var dingTalk = Utility.JSONToObject<DingTalkRemindTime>(dingTalkRemindTimeStr.PARAVALUE);
|
||
|
||
var now = DateTime.Now;
|
||
|
||
var everyHour = 0;
|
||
//判断工作时间,休息时间
|
||
var isWorkDay = false;
|
||
var webApi = _BAS_PARAMETER_Q.GetModel_Patameter("Hg_Core_WebApi");
|
||
var url = $"{webApi.PARAVALUE}/api/OutComplaint/WorkDay";
|
||
var para = $"dateTime={now.ToString("yyyy-MM-dd")}";
|
||
var dataStr = Utility.GetData(url, para, Encoding.UTF8);
|
||
var data = JsonConvert.DeserializeObject<MSG_API_Result<bool>>(dataStr);
|
||
if (data.code == 0)
|
||
isWorkDay = data.data;
|
||
|
||
//if (now.DayOfWeek != DayOfWeek.Saturday && now.DayOfWeek != DayOfWeek.Sunday)
|
||
// isWorkDay = true;
|
||
|
||
if (isWorkDay)
|
||
{
|
||
if (now.Hour >= 9 && now.Hour < 24)
|
||
everyHour = dingTalk.WorkDayHour;
|
||
else
|
||
{
|
||
everyHour = dingTalk.ResDayHour;
|
||
isWorkDay = false;
|
||
}
|
||
}
|
||
else
|
||
everyHour = dingTalk.ResDayHour;
|
||
|
||
|
||
//var CallRecordunList = _CSVR_CALLRECORD_BL.GetUNCallBackList(Convert.ToInt32(ddTimeout),10);//获取所有
|
||
|
||
//获取所有未回访通话
|
||
var CallRecordunList = _CSVR_CALLRECORD_BL.GetUNCallRemindList(dingTalk.StartTime,dingTalk.DaysAgo);
|
||
LogHelper.Info("回访数量:" + CallRecordunList.Count());
|
||
if (!CallRecordunList.Any()) return;
|
||
|
||
foreach (var unc in CallRecordunList)
|
||
{
|
||
try
|
||
{
|
||
//非工作时间如果提醒过了就不再提醒
|
||
if (!isWorkDay && unc.PUSHED == 1)
|
||
continue;
|
||
|
||
if (!unc.REMINDTIME.HasValue || (unc.REMINDTIME.HasValue && unc.REMINDTIME.Value.AddHours(everyHour) < now))
|
||
{
|
||
var count = _CSVR_CALLRECORD_BL.GetNotHFCount(unc.RESID, dingTalk.StartTime, dingTalk.DaysAgo);
|
||
|
||
PushOne(unc, count);
|
||
Thread.Sleep(100);
|
||
unc.REMINDTIME = now;
|
||
|
||
if(!isWorkDay)
|
||
unc.PUSHED = 1;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error("【" + unc.PKID + "】未接电话通知钉钉失败:" + ex.Message);
|
||
}
|
||
}
|
||
_CSVR_CALLRECORD_BL.BathUpdateReCallRecordUn(CallRecordunList);
|
||
}
|
||
private static void PushOne(CSVR_CALLRECORDUN unModel,int count) {
|
||
//var url = "http://192.168.11.81:8086/api/CsvrMessageComtroller/Push";
|
||
Dictionary<string, object> msgParam = new Dictionary<string, object>();
|
||
var _msg_url_encypt = _BAS_PARAMETER_Q.GetModel_Patameter("Hg_Core_WebApi");
|
||
if (_msg_url_encypt != null)
|
||
{
|
||
//获取umid
|
||
var customer = _RES_CUSTOMER_BL.getResCustomerByResId(unModel.RESID);
|
||
|
||
var url = _msg_url_encypt.PARAVALUE + "/api/CsvrMessageComtroller/Push";
|
||
string msg = "【未接电话】回访通知";
|
||
//msg += "\r\n客户ID:" + unModel.RESID;
|
||
msg += "\r\n客户ID:" + customer?.UMID;
|
||
msg += "\r\n事业部:" + unModel.DEPTNAME;
|
||
msg += "\r\n呼入时间:" + unModel.TIMESTART.Value.ToString("yyyy-MM-dd HH:mm:ss");
|
||
msg += "\r\n分配回访人:" + unModel.ENAME;
|
||
msg += "\r\n回访状态:未回访";
|
||
msg += "\r\n呼入次数:" + count;
|
||
|
||
msgParam.Add("msgcode", "WJDH");
|
||
msgParam.Add("title", "未接电话通知!");
|
||
msgParam.Add("fromer", "");
|
||
msgParam.Add("eid", unModel.EID.ToString());
|
||
msgParam.Add("param", "");
|
||
msgParam.Add("companycode", "");
|
||
msgParam.Add("sendDingDing", true);
|
||
msgParam.Add("dingDingContent", msg);
|
||
var str = Utility.PostAjaxData(url, JsonConvert.SerializeObject(msgParam), Encoding.UTF8);//请求线索接口 获取事业部信息
|
||
var qtr = JsonConvert.DeserializeObject<MSG_API_Result<bool>>(str);
|
||
if (qtr.code != 0)
|
||
{
|
||
LogHelper.Error("【" + unModel.PKID + "】未接电话通知钉钉失败:" + qtr.message);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
public class MSG_API_Result<T>
|
||
{
|
||
public T data { get; set; }
|
||
public string message { get; set; }
|
||
public int code { get; set; }
|
||
}
|
||
|
||
public class DingTalkRemindTime
|
||
{
|
||
public DateTime StartTime { get; set; }
|
||
public int DaysAgo { get; set; }
|
||
public int WorkDayHour { get; set; }
|
||
public int ResDayHour { get; set; }
|
||
}
|
||
}
|