194 lines
8.0 KiB
C#
194 lines
8.0 KiB
C#
using CRM.Core.BLL.Base;
|
|
using CRM.Core.Model.Entity;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using WX.CRM.Common;
|
|
|
|
namespace CRM.Core.BLL.Csvr
|
|
{
|
|
public class Csvr_Message_BL : DbContextRepository<Csvr_Message>
|
|
{
|
|
//public Csvr_Message_Type GetTypeModel(string msgcode)
|
|
//{
|
|
// using (var db = new CRM.Core.Model.Entity.zxdContext())
|
|
// {
|
|
// return db.Csvr_Message_Type.FirstOrDefault(m => m.msgcode == msgcode);
|
|
// }
|
|
//}
|
|
|
|
/// <summary>
|
|
/// 推送 消息给指定的消息类型
|
|
/// </summary>
|
|
/// <param name="msgcode">消息编码</param>
|
|
/// <param name="title">标题</param>
|
|
/// <param name="fromer">发送人</param>
|
|
/// <param name="param">其他参数</param>
|
|
/// <returns></returns>
|
|
public bool PushMsg(string msgcode, string title, string fromer, string param)
|
|
{
|
|
try
|
|
{
|
|
Csvr_Message_Type_BL _msgtype = new Csvr_Message_Type_BL();
|
|
var typemodel = _msgtype.Get(m => m.msgcode == msgcode);
|
|
if (typemodel == null)
|
|
{
|
|
LogHelper.Error($"编码:{msgcode}错误!");
|
|
return false;
|
|
}
|
|
LogHelper.Info("获取的数据:" + typemodel.ToJson());
|
|
List<int> sendeidlist = new List<int>();//需要发送的eid
|
|
if (typemodel.sendtype == "all")
|
|
{
|
|
BAS_INNERUSER_BL _user = new BAS_INNERUSER_BL();
|
|
sendeidlist = _user.GetList(m => m.ISDISMISS == 0).Select(m => m.EID).ToList();
|
|
}
|
|
else if (typemodel.sendtype == "eid")
|
|
{
|
|
BAS_INNERUSER_BL _user = new BAS_INNERUSER_BL();
|
|
List<int> eids = new List<int>();//需要发送的eid
|
|
string[] models = typemodel.sendConfig.Split(',');
|
|
foreach (var item in models)
|
|
{
|
|
if (string.IsNullOrEmpty(item))
|
|
continue;
|
|
int meid = 0;
|
|
if (int.TryParse(item, out meid))
|
|
{
|
|
eids.Add(meid);
|
|
}
|
|
}
|
|
sendeidlist = _user.GetList(m => m.ISDISMISS == 0 && eids.Contains(m.EID)).Select(m => m.EID).ToList();
|
|
}
|
|
else if (typemodel.sendtype == "role")
|
|
{
|
|
string[] models = typemodel.sendConfig.Split(',');
|
|
using (var db = new zxdContext())
|
|
{
|
|
sendeidlist = (from a in db.BAS_INNERUSER
|
|
join b in db.BAS_INNERUSERROLE on a.PKID equals b.INNERUSERID
|
|
join c in db.BAS_ROLE on b.ROLEID equals c.ROLEID
|
|
where models.Contains(c.CODE)
|
|
where a.ISDISMISS == 0
|
|
select a.EID
|
|
).ToList()
|
|
;
|
|
}
|
|
}
|
|
LogHelper.Info("获取的数据:" + sendeidlist.ToJson());
|
|
if (sendeidlist != null && sendeidlist.Count > 0)
|
|
{
|
|
foreach (var item in sendeidlist)
|
|
{
|
|
Add(new Csvr_Message()
|
|
{
|
|
ctime = DateTime.Now,
|
|
eid = item,
|
|
fromer = fromer,
|
|
islook = 0,
|
|
message = title,
|
|
msgcode = msgcode,
|
|
param = param
|
|
});
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogHelper.Error(e.ToString());
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 推送 文案审核消息类型推送(比较特殊,需要从配置的角色中找到匹配部门才行)
|
|
/// </summary>
|
|
/// <param name="msgcode">消息编码</param>
|
|
/// <param name="title">标题</param>
|
|
/// <param name="fromer">发送人</param>
|
|
/// <param name="param">其他参数</param>
|
|
/// <returns></returns>
|
|
public bool PushNewsMsg(string msgcode, string title, string fromer, string param, string companycode)
|
|
{
|
|
try
|
|
{
|
|
Csvr_Message_Type_BL _msgtype = new Csvr_Message_Type_BL();
|
|
var typemodel = _msgtype.Get(m => m.msgcode == msgcode);
|
|
if (typemodel == null)
|
|
{
|
|
LogHelper.Error($"编码:{msgcode}错误!");
|
|
return false;
|
|
}
|
|
LogHelper.Info("获取的数据:" + typemodel.ToJson());
|
|
List<int> sendeidlist = new List<int>();//需要发送的eid
|
|
if (typemodel.sendtype == "all")
|
|
{
|
|
BAS_INNERUSER_BL _user = new BAS_INNERUSER_BL();
|
|
sendeidlist = _user.GetList(m => m.ISDISMISS == 0 && m.ISHIDE == 0).Select(m => m.EID).ToList();
|
|
}
|
|
else if (typemodel.sendtype == "eid")
|
|
{
|
|
BAS_INNERUSER_BL _user = new BAS_INNERUSER_BL();
|
|
List<int> eids = new List<int>();//需要发送的eid
|
|
string[] models = typemodel.sendConfig.Split(',');
|
|
foreach (var item in models)
|
|
{
|
|
if (string.IsNullOrEmpty(item))
|
|
continue;
|
|
int meid = 0;
|
|
if (int.TryParse(item, out meid))
|
|
{
|
|
eids.Add(meid);
|
|
}
|
|
}
|
|
sendeidlist = _user.GetList(m => m.ISDISMISS == 0 && m.ISHIDE == 0 && eids.Contains(m.EID)).Select(m => m.EID).ToList();
|
|
}
|
|
else if (typemodel.sendtype == "role")
|
|
{
|
|
string[] models = typemodel.sendConfig.Split(',');
|
|
|
|
using (var db = new zxdContext())
|
|
{
|
|
sendeidlist = (from a in db.BAS_INNERUSER
|
|
join b in db.BAS_INNERUSERROLE on a.PKID equals b.INNERUSERID
|
|
join c in db.BAS_ROLE on b.ROLEID equals c.ROLEID
|
|
join d in db.Bas_Role_Com on c.ROLEID equals d.roleid
|
|
where models.Contains(c.CODE)
|
|
where a.ISDISMISS == 0
|
|
where a.ISHIDE == 0
|
|
where d.companycode.Contains(companycode)
|
|
select a.EID
|
|
).ToList()
|
|
;
|
|
}
|
|
}
|
|
LogHelper.Info("获取的数据:" + sendeidlist.ToJson());
|
|
if (sendeidlist != null && sendeidlist.Count > 0)
|
|
{
|
|
foreach (var item in sendeidlist)
|
|
{
|
|
Add(new Csvr_Message()
|
|
{
|
|
ctime = DateTime.Now,
|
|
eid = item,
|
|
fromer = fromer,
|
|
islook = 0,
|
|
message = title,
|
|
msgcode = msgcode,
|
|
param = param
|
|
});
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogHelper.Error(e.ToString());
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
}
|
|
}
|