Files
lserp_cs_6.0/插件库/Lskj.Business/Impl/PushHelper.cs
T
cyf ab56a9bcf7 基线 SVN r240
SVN-Revision: r240
2025-02-06 06:46:06 +00:00

310 lines
14 KiB
C#

/******************************
* 说明:消息推送
* 创建人:龚宇超
* 创建日期:2018-03-19
* 修改人:
* 修改日期:
* 修改备注:
* 版本:1.0.0.0
******************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lskj.Push;
using Lskj.Push.Push.Mode;
using Lskj.Push.Push;
using System.Threading;
using System.Data;
using Lskj.Business.Impl;
using Lskj.Core;
using Lskj.Util;
namespace Lskj.Business
{
/// <summary>
/// 消息推送类
/// </summary>
public sealed class PushHelper
{
private string _billId;
private string _stepCode;
private string _menuId;
private string _beforeUsers;
private string _beforeMenuName;
private int _beforeId;
private Dictionary<string, PushMessage> _pushMessages = new Dictionary<string, PushMessage>();
public PushHelper(string billid, string stepcode, string menuid, string beforeusers, string beforemenuname, int beforeid)
{
this._billId = billid;
this._menuId = menuid;
this._stepCode = stepcode;
this._beforeUsers = beforeusers;
this._beforeMenuName = beforemenuname;
this._beforeId = beforeid;
}
#region 消息推送
/// <summary>
/// 推送单据审核确认消息
/// </summary>
public void Push_Bill_Confirm_Message()
{
}
/// <summary>
/// 推送单据审核消息
/// </summary>
public void Push_Bill_Oper_Message()
{
if (SystemInfo.Instance.AuroraPushData)
{
try
{
string sqlValue = string.Format("select operators,typeName menuname,'2'+CAST(b.id as varchar(10)) id from wms_billflowOper a,p_systembilltype b where a.modid=b.typeCode and keyvalue='{0}' and a.stepover=0", _billId);
DataTable dtTable = SqlHelper.ExecuteDataTable(sqlValue);
// 极光推送key
DataTable dtSystemTab = SqlHelper.ExecuteDataTable("select * from p_systemtab");
string appKey = dtSystemTab.Rows[0]["JPushAppKey"] + "";
string master_secret = dtSystemTab.Rows[0]["JPushMaster_Secret"] + "";
string clict_code = dtSystemTab.Rows[0]["ClientCode"] + "";
// 清空上一步人员消息
if (!string.IsNullOrEmpty(_beforeUsers) && !string.IsNullOrEmpty(_beforeMenuName) && _beforeId > 0)
{
DataTable dtUsers = SqlHelper.ExecuteDataTable(string.Format("select employeeid userid,employeename username from P_employeeTab where employeename in ({0})",
"'" + _beforeUsers.Replace(",", "','") + "'"));
foreach (DataRow item in dtUsers.Rows)
{
string uid = item["userid"] + "";
string username = item["username"] + "";
AddPushSource(appKey, master_secret, clict_code, _beforeId, 0, _beforeMenuName, _menuId, uid);
}
}
// 推送本次人员消息
if (dtTable != null && dtTable.Rows.Count > 0)
{
string operators = dtTable.Rows[0]["operators"] + "";
string menuname = dtTable.Rows[0]["menuname"] + "";
int id = Convert.ToInt32(dtTable.Rows[0]["id"] + "");
dtTable = SqlHelper.ExecuteDataTable(string.Format("select employeeid userid,employeename username from P_employeeTab where employeename in ({0})",
"'" + operators.Replace(",", "','") + "'"));
foreach (DataRow item in dtTable.Rows)
{
string uid = item["userid"] + "";
string username = item["username"] + "";
sqlValue = string.Format(string.Format("select COUNT(1) total from wms_BillflowOper where stepOver=0 and modid='{0}' and CHARINDEX(',{1},',','+operators+',')>0", _menuId, username));
int total = Convert.ToInt32(SqlHelper.ExecuteDataSet(sqlValue).Tables[0].Rows[0]["total"] + "");
if (total > 0)
Push_ALL_Message(appKey, master_secret, clict_code, id, total, menuname, _menuId, uid);
}
}
else
{
// 重新计算人员消息
if (!string.IsNullOrEmpty(_beforeUsers) && !string.IsNullOrEmpty(_beforeMenuName) && _beforeId > 0)
{
DataTable dtUsers = SqlHelper.ExecuteDataTable(string.Format("select employeeid userid,employeename username from P_employeeTab where employeename in ({0})",
"'" + _beforeUsers.Replace(",", "','") + "'"));
foreach (DataRow item in dtUsers.Rows)
{
string uid = item["userid"] + "";
string username = item["username"] + "";
sqlValue = string.Format(string.Format("select COUNT(1) total from wms_BillflowOper where stepOver=0 and modid='{0}' and CHARINDEX(',{1},',','+operators+',')>0", _menuId, username));
int total = Convert.ToInt32(SqlHelper.ExecuteDataSet(sqlValue).Tables[0].Rows[0]["total"] + "");
if (total > 0)
Push_ALL_Message(appKey, master_secret, clict_code, _beforeId, total, _beforeMenuName, _menuId, uid);
}
}
}
}
catch (Exception)
{
}
}
}
/// <summary>
/// 去除重复消息通知
/// </summary>
/// <param name="appkey"></param>
/// <param name="appsecret"></param>
/// <param name="appclict"></param>
/// <param name="id"></param>
/// <param name="total"></param>
/// <param name="menuname"></param>
/// <param name="menuid"></param>
/// <param name="uid"></param>
private void AddPushSource(string appkey, string appsecret, string appclict, int id, int total, string menuname, string menuid, string uid)
{
if (_pushMessages.ContainsKey(uid))
{
PushMessage push = _pushMessages[uid];
if (push.total == 0)
{
push.total = total;
}
}
else
{
_pushMessages.Add(uid, new PushMessage()
{
appkey = appkey,
appsecret = appsecret,
appclict = appclict,
id = _beforeId,
total = total,
menuname = _beforeMenuName,
menuid = menuid,
uid = uid
});
}
}
/// <summary>
/// 推送基础档案审核确认消息
/// </summary>
private void Push_Base_Confirm_Message()
{
}
/// <summary>
/// 推送基础档案审核消息
/// </summary>
public void Push_Base_Oper_Message()
{
if (SystemInfo.Instance.AuroraPushData)
{
try
{
string sqlValue = string.Format("select operators,ToolsName menuname,'1'+CAST(b.dllid as varchar(10)) id from P_baseflowOper a,P_systemdlltab b where a.modid=b.DllCoid and keyvalue='{0}' and stepcode='{1}' and a.stepover=0", _billId, _stepCode);
DataTable dtTable = SqlHelper.ExecuteDataTable(sqlValue);
// 极光推送key
DataTable dtSystemTab = SqlHelper.ExecuteDataTable("select * from p_systemtab");
string appKey = dtSystemTab.Rows[0]["JPushAppKey"] + "";
string master_secret = dtSystemTab.Rows[0]["JPushMaster_Secret"] + "";
string clict_code = dtSystemTab.Rows[0]["ClientCode"] + "";
// 清空上一步人员消息
if (!string.IsNullOrEmpty(_beforeUsers) && !string.IsNullOrEmpty(_beforeMenuName) && _beforeId > 0)
{
DataTable dtUsers = SqlHelper.ExecuteDataTable(string.Format("select employeeid userid,employeename username from P_employeeTab where employeename in ({0})",
"'" + _beforeUsers.Replace(",", "','") + "'"));
foreach (DataRow item in dtUsers.Rows)
{
string uid = item["userid"] + "";
string username = item["username"] + "";
AddPushSource(appKey, master_secret, clict_code, _beforeId, 0, _beforeMenuName, _menuId, uid);
}
}
// 推送本次人员消息
if (dtTable != null && dtTable.Rows.Count > 0)
{
string operators = dtTable.Rows[0]["operators"] + "";
string menuname = dtTable.Rows[0]["menuname"] + "";
int id = Convert.ToInt32(dtTable.Rows[0]["id"] + "");
dtTable = SqlHelper.ExecuteDataTable(string.Format("select employeeid userid,employeename username from P_employeeTab where employeename in ({0})",
"'" + operators.Replace(",", "','") + "'"));
foreach (DataRow item in dtTable.Rows)
{
string uid = item["userid"] + "";
string username = item["username"] + "";
sqlValue = string.Format(string.Format("select COUNT(1) total from P_baseflowOper where stepOver=0 and modid='{0}' and CHARINDEX(',{1},',','+operators+',')>0", _menuId, username));
int total = Convert.ToInt32(SqlHelper.ExecuteDataSet(sqlValue).Tables[0].Rows[0]["total"] + "");
Push_ALL_Message(appKey, master_secret, clict_code, id, total, menuname, _menuId, uid);
}
}
else
{
// 终审重新计算人员
if (!string.IsNullOrEmpty(_beforeUsers) && !string.IsNullOrEmpty(_beforeMenuName) && _beforeId > 0)
{
DataTable dtUsers = SqlHelper.ExecuteDataTable(string.Format("select employeeid userid,employeename username from P_employeeTab where employeename in ({0})",
"'" + _beforeUsers.Replace(",", "','") + "'"));
foreach (DataRow item in dtUsers.Rows)
{
string uid = item["userid"] + "";
string username = item["username"] + "";
sqlValue = string.Format(string.Format("select COUNT(1) total from P_baseflowOper where stepOver=0 and modid='{0}' and CHARINDEX(',{1},',','+operators+',')>0", _menuId, username));
int total = Convert.ToInt32(SqlHelper.ExecuteDataSet(sqlValue).Tables[0].Rows[0]["total"] + "");
Push_ALL_Message(appKey, master_secret, clict_code, _beforeId, total, _beforeMenuName, _menuId, uid);
}
}
}
}
catch (Exception)
{
}
}
}
private void Push_ALL_Message(string appkey, string appsecret, string appclict, int id, int total, string menuname, string menuid, string uid)
{
// 推送android、ios消息
JPushClient jPushClient = new JPushClient(appkey, appsecret);
Dictionary<string, object> dicExtras = new Dictionary<string, object>();
dicExtras.Add("id", id); // 1.基础档案审批通知,2.单据审核通知
dicExtras.Add("title", menuname);
dicExtras.Add("total", total);
dicExtras.Add("desc", string.Format("您有{0}条数据需要审批.", total));
dicExtras.Add("menuid", menuid);
// 发送android消息
try
{
PushPayload android = JPushApi.PushObject_Android_Message("1002", appclict + "_" + uid + "", dicExtras);
MessageResult androidResult = jPushClient.SendPush(android);
}
catch (Exception)
{
}
try
{
// 发送ios消息
//PushPayload ios = JPushApi.PushObject_Ios_Message("1002", appclict + "_" + uid + "", dicExtras);
PushPayload ios = JPushApi.PushObject_Ios_Alias_TitleWithContent(menuname, string.Format("您有{0}条数据需要审批.", total), appclict + "_" + uid + "", dicExtras);
MessageResult iosResult = jPushClient.SendPush(ios);
}
catch (Exception)
{
}
}
#endregion
}
public class PushMessage
{
public string appkey;
public string appsecret;
public string appclict;
public int id;
public int total;
public string menuname;
public string menuid;
public string uid;
}
}