347 lines
15 KiB
C#
347 lines
15 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Data;
|
|
using CommonLib;
|
|
using Lskj.PubJPush;
|
|
using Lskj.PubJPush.Push.Mode;
|
|
using Lskj.PubJPush.Push;
|
|
using System.Windows.Forms;
|
|
using System.Threading;
|
|
|
|
namespace Lskj.Common
|
|
{
|
|
/// <summary>
|
|
/// 消息推送类
|
|
/// </summary>
|
|
public 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 推送单据审核确认消息
|
|
/// </summary>
|
|
public void push_bill_comfirm_message()
|
|
{
|
|
|
|
}
|
|
/// <summary>
|
|
/// 推送单据审核消息
|
|
/// </summary>
|
|
public void push_bill_oper_message()
|
|
{
|
|
try
|
|
{
|
|
pushMessages.Clear();
|
|
|
|
// 极光推送key
|
|
DataTable dtSystemTab = SqlHelper.ExecuteDataSet("select * from p_systemtab").Tables[0];
|
|
string appKey = dtSystemTab.Rows[0]["JPushAppKey"] + "";
|
|
string master_secret = dtSystemTab.Rows[0]["JPushMaster_Secret"] + "";
|
|
string clict_code = dtSystemTab.Rows[0]["ClientCode"] + "";
|
|
|
|
if (string.IsNullOrEmpty(appKey))
|
|
return;
|
|
|
|
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.ExecuteDataSet(sqlValue).Tables[0];
|
|
|
|
|
|
|
|
// 清空上一步人员消息
|
|
if (!string.IsNullOrEmpty(beforeusers) && !string.IsNullOrEmpty(beforemenuname) && beforeid > 0)
|
|
{
|
|
DataTable dtUsers = SqlHelper.ExecuteDataSet(string.Format("select employeeid userid,employeename username from P_employeeTab where employeename in ({0})",
|
|
"'" + beforeusers.Replace(",", "','") + "'")).Tables[0];
|
|
|
|
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);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// 单据提交处理
|
|
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 dtUsers = SqlHelper.ExecuteDataSet(sqlValue).Tables[0];
|
|
|
|
if (dtUsers.Rows.Count > 0)
|
|
{
|
|
beforeusers = dtUsers.Rows[0]["operators"] + "";
|
|
beforemenuname = dtUsers.Rows[0]["menuname"] + "";
|
|
beforeid = Convert.ToInt32(dtUsers.Rows[0]["id"] + "");
|
|
}
|
|
}
|
|
|
|
// 推送本次人员消息
|
|
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.ExecuteDataSet(string.Format("select employeeid userid,employeename username from P_employeeTab where employeename in ({0})",
|
|
"'" + operators.Replace(",", "','") + "'")).Tables[0];
|
|
|
|
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"] + "");
|
|
|
|
addPushSource(appKey, master_secret, clict_code, beforeid, total, beforemenuname, menuid, uid);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// 重新计算人员消息
|
|
if (!string.IsNullOrEmpty(beforeusers) && !string.IsNullOrEmpty(beforemenuname) && beforeid > 0)
|
|
{
|
|
DataTable dtUsers = SqlHelper.ExecuteDataSet(string.Format("select employeeid userid,employeename username from P_employeeTab where employeename in ({0})",
|
|
"'" + beforeusers.Replace(",", "','") + "'")).Tables[0];
|
|
|
|
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"] + "");
|
|
|
|
addPushSource(appKey, master_secret, clict_code, beforeid, total, beforemenuname, menuid, uid);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
}
|
|
|
|
new Thread(new ThreadStart(push_all_message)).Start();
|
|
}
|
|
/// <summary>
|
|
/// 推送基础档案审核确认消息
|
|
/// </summary>
|
|
public void push_base_comfirm_message()
|
|
{
|
|
|
|
}
|
|
/// <summary>
|
|
/// 推送基础档案审核消息
|
|
/// </summary>
|
|
public void push_base_oper_message()
|
|
{
|
|
try
|
|
{
|
|
pushMessages.Clear();
|
|
|
|
// 极光推送key
|
|
DataTable dtSystemTab = SqlHelper.ExecuteDataSet("select * from p_systemtab").Tables[0];
|
|
string appKey = dtSystemTab.Rows[0]["JPushAppKey"] + "";
|
|
string master_secret = dtSystemTab.Rows[0]["JPushMaster_Secret"] + "";
|
|
string clict_code = dtSystemTab.Rows[0]["ClientCode"] + "";
|
|
if (string.IsNullOrEmpty(appKey))
|
|
return;
|
|
|
|
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.ExecuteDataSet(sqlValue).Tables[0];
|
|
|
|
|
|
|
|
// 清空上一步人员消息
|
|
if (!string.IsNullOrEmpty(beforeusers) && !string.IsNullOrEmpty(beforemenuname) && beforeid > 0)
|
|
{
|
|
DataTable dtUsers = SqlHelper.ExecuteDataSet(string.Format("select employeeid userid,employeename username from P_employeeTab where employeename in ({0})",
|
|
"'" + beforeusers.Replace(",", "','") + "'")).Tables[0];
|
|
|
|
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);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// 单据提交处理
|
|
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 a.stepover=0", billid);
|
|
DataTable dtUsers = SqlHelper.ExecuteDataSet(sqlValue).Tables[0];
|
|
|
|
if (dtUsers.Rows.Count > 0)
|
|
{
|
|
beforeusers = dtUsers.Rows[0]["operators"] + "";
|
|
beforemenuname = dtUsers.Rows[0]["menuname"] + "";
|
|
beforeid = Convert.ToInt32(dtUsers.Rows[0]["id"] + "");
|
|
}
|
|
}
|
|
|
|
// 推送本次人员消息
|
|
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.ExecuteDataSet(string.Format("select employeeid userid,employeename username from P_employeeTab where employeename in ({0})",
|
|
"'" + operators.Replace(",", "','") + "'")).Tables[0];
|
|
|
|
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"] + "");
|
|
|
|
addPushSource(appKey, master_secret, clict_code, beforeid, total, beforemenuname, menuid, uid);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// 终审重新计算人员
|
|
if (!string.IsNullOrEmpty(beforeusers) && !string.IsNullOrEmpty(beforemenuname) && beforeid > 0)
|
|
{
|
|
DataTable dtUsers = SqlHelper.ExecuteDataSet(string.Format("select employeeid userid,employeename username from P_employeeTab where employeename in ({0})",
|
|
"'" + beforeusers.Replace(",", "','") + "'")).Tables[0];
|
|
|
|
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"] + "");
|
|
|
|
addPushSource(appKey, master_secret, clict_code, beforeid, total, beforemenuname, menuid, uid);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
}
|
|
|
|
new Thread(new ThreadStart(push_all_message)).Start();
|
|
}
|
|
/// <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>
|
|
/// <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 push_all_message()
|
|
{
|
|
foreach (PushMessage item in pushMessages.Values)
|
|
{
|
|
// 推送android、ios消息
|
|
JPushClient jPushClient = new JPushClient(item.appkey, item.appsecret);
|
|
|
|
Dictionary<string, object> dicExtras = new Dictionary<string, object>();
|
|
|
|
dicExtras.Add("id", item.id); // 1.基础档案审批通知,2.单据审核通知
|
|
dicExtras.Add("title", item.menuname);
|
|
dicExtras.Add("total", item.total);
|
|
dicExtras.Add("desc", string.Format("您有{0}条数据需要审批.", item.total));
|
|
dicExtras.Add("menuid", menuid);
|
|
|
|
// 发送android消息
|
|
try
|
|
{
|
|
PushPayload android = JPushApi.PushObject_Android_Message("1002", item.appclict + "_" + item.uid + "", dicExtras);
|
|
MessageResult androidResult = jPushClient.SendPush(android);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
|
|
try
|
|
{
|
|
// 发送ios消息
|
|
PushPayload ios = JPushApi.PushObject_Ios_Message("1002", item.appclict + "_" + item.uid + "", dicExtras);
|
|
MessageResult iosResult = jPushClient.SendPush(ios);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
} |