TG.WXCRM.V4/WEB/Controllers/WeiXin/MessageController.cs

1172 lines
51 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Ninject;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web.Mvc;
using WX.CRM.BLL.Base;
using WX.CRM.Common;
using WX.CRM.IBLL.Base;
using WX.CRM.IBLL.Csvr;
using WX.CRM.IBLL.Util;
using WX.CRM.IBLL.Ww;
using WX.CRM.IBLL.Wx;
using WX.CRM.Model.Entity;
using WX.CRM.Model.MAP;
using WX.CRM.WebHelper;
namespace WX.CRM.WEB.Controllers.WeiXin
{
public class MessageController : BaseController
{
private ValidationErrors errors = new ValidationErrors();
[Inject]
public IWX_MESSAGE wx_Message_BL { get; set; }
[Inject]
public IWX_WORKACCOUNT wx_WorkAccount_BL { get; set; }
[Inject]
public IWX_RCONTACT wx_Rcontact_BL { get; set; }
[Inject]
public IBAS_INNERUSERGROUP_Q bas_InnerUserGroup_BL { get; set; }
[Inject]
public IBAS_INNERGROUP_Q bas_InnerGroup_BL { get; set; }
[Inject]
public IWX_MESSAGECOMPLIANCE wx_MessageCompliance_BL { get; set; }
[Inject]
public IBAS_PARAMETER bas_Parameter_BL { get; set; }
[Inject]
public IWw_huser ww_huser_bl { get; set; }
[Inject]
public IBAS_PARAMETER_Q bas_Parameter_Q_BL { get; set; }
[Inject]
public IBAS_COMTYPE_Q bas_ComType_Q_BL { get; set; }
[Inject]
public IBAS_SUBCOMTYPE_Q bas_SubComType_Q_BL { get; set; }
[Inject]
public ICACHE_Q cache_BL { get; set; }
[Inject]
public IBAS_PARAMETER_Q _BAS_PARAMETER_Q { get; set; }
[Inject]
public ICSVR_CALLRECORD_Q _CSVR_CALLRECORD_Q { get; set; }
[AuthorizeRedirect(Roles = InitRights.CONST_微信聊天合规管理)]
public ActionResult Index()
{
ToolBar tool = new ToolBar();
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights., userRightId);
tool.AllowButton(toolbtn);
tool.AddOtherButton("Other1", "标记违规信息", "icon-edit", "Update_Click", true);
tool.AddOtherButton("Other2", "合规关键字", "icon-edit", "Keyword_Click", true);
ViewBag.ToolBar = tool;
Pager pager = new Pager() { page = 1, rows = 30 };
string tableId = "tablist";
Table tab = new Table(tableId);
tab.AddHiddenHeadCol("msgsvrid", "");
tab.AddHiddenHeadCol("inneruserid", "");
tab.AddHiddenHeadCol("msgtype", "");
tab.AddHiddenHeadCol("username", "");
tab.AddHiddenHeadCol("msgurl", "");
tab.AddHiddenHeadCol("msgcontent", "");
tab.AddHeadCol("talker", "", "客户微信");
tab.AddHeadCol("issend", "", "");
tab.AddHeadCol("content", "50%", "消息内容");
tab.AddHeadCol("createtime", "", "消息时间");
tab.AddHeadCol("alias", "", "客服微信");
tab.AddHeadCol("eid", "", "客服");
tab.AddHeadCol("gname", "", "销售组");
tab.AddHeadCol("", "", "查看");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetHead() + Pagination.GetPage(pager, tableId, "20,30,50");
ViewBag.inneruserid = UserId;
ViewBag.userGroupId = userGroupId;
ViewBag.saleDeptId = saleDeptId;
ViewBag.roleCodes = DataCacheHelper.GetCache().Get_RoleCodes(userRoleId);
var model = bas_Parameter_Q_BL.GetModel_Patameter(WX.CRM.Model.Enum.Parameter.WeiXin_IllegalKewords.ToString());
ViewBag.keyword = model != null ? model.PARAVALUE.Trim(';') : "";
ViewBag.monthList = getMonthList();
return View();
}
[HttpPost]
[AuthorizeRedirect(Roles = InitRights.CONST_微信聊天合规管理)]
public JsonResult GetHtmlList(Pager pager, string month, string stime, string etime, string keyword, string customerUserName, string alias, string columns)
{
decimal saleDeptId = Request["saleDeptId"].GetDecimal(0);
decimal groupId = Request["groupId"].GetDecimal(0);
decimal userId = Request["userId"].GetDecimal(0);
var tableName = "";
if (string.IsNullOrWhiteSpace(month))
{
month = string.Format("{0:yyyyMM}", DateTime.Now);
}
tableName = "wx_message" + month;
var workAccountList = wx_WorkAccount_BL.GetList().ToList();
if (!string.IsNullOrWhiteSpace(alias))
{
var rcontact = wx_Rcontact_BL.Get(m => m.ALIAS == alias);
if (rcontact != null)
{
customerUserName = rcontact.USERNAME;
}
}
string unixStime = "";
string unixEtime = "";
if (!string.IsNullOrWhiteSpace(stime))
{
DateTime time1 = Convert.ToDateTime(stime);
unixStime = time1.ToShortDateString();
//unixStime = Utility.ConvertDateTimeToInt(time1).ToString();
}
if (!string.IsNullOrWhiteSpace(etime))
{
DateTime time2 = Convert.ToDateTime(etime).AddDays(1);
//unixEtime = Utility.ConvertDateTimeToInt(time2).ToString();
unixEtime = time2.ToShortDateString();
}
string userNames = "";
if (userId > 0)
{
var userNameList = workAccountList.Where(m => m.INNERUSERID == userId);
if (userNameList != null)
{
foreach (var item in userNameList)
{
userNames += item.USERNAME + ",";
}
userNames = userNames.Trim(',');
}
}
else if (groupId > 0)
{
var groupUserList = bas_InnerUserGroup_BL.GetList().Where(m => m.GID == groupId).ToList();
if (groupUserList != null)
{
var groupUserIdList = groupUserList.Select(m => m.INNERUSERID).ToList();
var userNameList = workAccountList.Where(m => groupUserIdList.Contains(m.INNERUSERID.Value));
if (userNameList != null)
{
foreach (var item in userNameList)
{
userNames += item.USERNAME + ",";
}
userNames = userNames.Trim(',');
}
}
}
else if (saleDeptId > 0)
{
var groupIdList = bas_InnerGroup_BL.GetList().Where(m => m.SALEDEPTID == saleDeptId).ToList().Select(mm => mm.GID).ToList(); ;
if (groupIdList != null)
{
var groupUserList = bas_InnerUserGroup_BL.GetList().Where(m => groupIdList.Contains(m.GID.Value)).ToList();
if (groupUserList != null)
{
var groupUserIdList = groupUserList.Select(m => m.INNERUSERID).ToList();
var userNameList = workAccountList.Where(m => groupUserIdList.Contains(m.INNERUSERID.Value));
if (userNameList != null)
{
foreach (var item in userNameList)
{
userNames += item.USERNAME + ",";
}
userNames = userNames.Trim(',');
}
}
}
}
var list = new List<WX_Message_Extend>();
if (!string.IsNullOrWhiteSpace(month) && !string.IsNullOrWhiteSpace(stime))
{
DateTime timer = Convert.ToDateTime(stime);
if (month == string.Format("{0:yyyyMM}", timer))
{
list = wx_Message_BL.GetMessageList(ref pager, keyword, tableName, userNames, unixStime, unixEtime, customerUserName);
}
}
string isShowMobileOfContent = cache_BL.GetValue_Parameter(Model.Enum.Parameter.Sys_IsShowMobileOfContent);
Table table = new Table(columns, true);
foreach (var model in list)
{
var workAccount = workAccountList.Where(m => m.USERNAME == model.username).OrderByDescending(m => m.CTIME).FirstOrDefault();
table.AddHiddenCol(model.msgsvrid);
table.AddHiddenCol(workAccount != null ? workAccount.INNERUSERID : 0);
table.AddHiddenCol(model.msgtype);
table.AddHiddenCol(model.username);
table.AddHiddenCol(model.msgurl);
table.AddHiddenCol(model.msgcontent);
table.AddCol(model.talker);
if (!string.IsNullOrEmpty(isShowMobileOfContent) && isShowMobileOfContent == "1")
{
table.AddCol(model.issend == 0 ? string.Format("<span style='color:#42b475'>{0}说:</span>", model.nickname) : string.Format("<span style='color:#006efe'>客服对{0}说:</span>", model.nickname));
}
else
{
table.AddCol(model.issend == 0 ? string.Format("<span style='color:#42b475'>{0}说:</span>", Utility.ReplaceMobile(model.nickname)) : string.Format("<span style='color:#006efe'>客服对{0}说:</span>", Utility.ReplaceMobile(model.nickname)));
}
table.AddCol(getMsgContent(model));
table.AddCol(Utility.ConvertStringToDateTime(model.createtime.ToString()));
table.AddCol(workAccount != null ? workAccount.ALIAS : "");
table.AddCol(workAccount != null ? InnerUserHelper.Instance.GetEidAndTrueName(workAccount.INNERUSERID) : "");
table.AddCol(workAccount != null ? InnerUserHelper.Instance.GetGroupName(InnerUserHelper.Instance.GetGroupId(workAccount.INNERUSERID)) : "");
table.AddCol(string.Format("<a href = \"javascript:void(0);\" onclick = \"ShowMesageDetial('{0}','{1}')\" > 查看消息 </a>", model.talker, model.username));
table.AddRow();
}
var json = new
{
totalPages = pager.totalPages,
totalRows = pager.totalRows,
rowsList = table.GetRows()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
[HttpPost]
[AuthorizeToolBar(InitRights.CONST_微信聊天合规管理, InitToolBar.CONST_Other1)]
public JsonResult UpdateIsillegal(string msgsvrid, string username, string msgcontent, string month, decimal? msgtype, string talker, string msgurl, DateTime createtime)
{
var tableName = "";
if (!string.IsNullOrWhiteSpace(month))
{
tableName = "wx_message" + month;
}
try
{
decimal? innerUserId = 0;
var workAccount = wx_WorkAccount_BL.Get(m => m.USERNAME == username);
if (workAccount != null)
{
innerUserId = workAccount.INNERUSERID;
}
WX_MESSAGECOMPLIANCE compliance = new WX_MESSAGECOMPLIANCE
{
PKID = new SEQUENCES_BL().Seq_base_get(),
JOBUSERNAME = username,
USERNAME = talker,
INNERUSERID = innerUserId,
MESSAGE = msgcontent,
MSGTYPE = msgtype,
CTIME = DateTime.Now,
OPERATORID = UserId,
MSGSOURCE = 1,
MSGSVRID = msgsvrid,
MSGURL = msgurl,
TYPE = 1,
ORIGINALTIME = createtime
};
wx_Message_BL.UpdateMessageIsIllegal(tableName, username, msgsvrid);
wx_MessageCompliance_BL.Add(compliance);
string rootPath = AppDomain.CurrentDomain.BaseDirectory + "Message"; //html文件生成的根目录
var dir = string.Format("{0}\\{1}", rootPath, username);
var path = string.Format("{0}_{1}.json", talker, month.Substring(0, 4) + month.Substring(4, 2).Replace("0", ""));
var str = Path.Combine(dir, path);
if (System.IO.File.Exists(Path.Combine(dir, path)))
{
string result = string.Format("[{0}]", FileUnit.Read(Path.Combine(dir, path)));
List<WX_MessageJson> messageJson = Utility.JSONToObject<List<WX_MessageJson>>(result);
if (messageJson != null && messageJson.Any(m => m.msgSvrId == msgsvrid))
{
Dictionary<string, WX_MessageJson> dic = messageJson.GroupBy(m => m.msgSvrId).ToDictionary(key => key.First().msgSvrId, value => value.First());
//Dictionary<string, WX_MessageJson> dic = new Dictionary<string, WX_MessageJson>();
//foreach(var m in messageJson)
//{
// dic.Add(m.msgSvrId, m);
//}
dic[msgsvrid].isillegal = 1;
FileUnit.Write(Path.Combine(dir, path), Utility.ConvertToJSON(dic.Values.ToList()).TrimStart('[').TrimEnd(']'));
}
}
return JsonHandler.ManageMessage("", true);
}
catch (Exception ex)
{
LogHelper.Error(ex);
return JsonHandler.ManageMessage(ex.Message, false);
}
}
[HttpGet]
[AuthorizeToolBar(InitRights.CONST_微信聊天合规管理, InitToolBar.CONST_Other1)]
public ActionResult MessageCompliance()
{
var model = new WX_MESSAGECOMPLIANCE();
var list = bas_ComType_Q_BL.GetList().Where(m => m.map_TYPECODE.Contains("MessageCompliance")).OrderBy(m => m.map_TYPECODE).ToList();
var bigTypeList = new List<SelectListItem>();
if (list != null)
{
foreach (var m in list)
{
bigTypeList.Add(new SelectListItem { Text = m.map_TYPENAME, Value = m.map_TYPECODE });
}
}
ViewBag.BigTypeList = bigTypeList;
return View(model);
}
[HttpPost]
[AuthorizeToolBar(InitRights.CONST_微信聊天合规管理, InitToolBar.CONST_Other1)]
public ActionResult MessageCompliance(WX_MESSAGECOMPLIANCE model, string msgsvrid, string username, string msgcontent, string month, decimal? msgtype, string talker, string msgurl, string bigType, string subType, DateTime createtime)
{
if (string.IsNullOrWhiteSpace(bigType))
{
errors.Add("请选择大类!");
return JsonHandler.UpdateMessage(errors, false);
}
if (string.IsNullOrWhiteSpace(subType))
{
errors.Add("请选择小类!");
return JsonHandler.UpdateMessage(errors, false);
}
if (string.IsNullOrWhiteSpace(model.REMARK))
{
errors.Add("请输入备注信息!");
return JsonHandler.UpdateMessage(errors, false);
}
var tableName = "";
if (!string.IsNullOrWhiteSpace(month))
{
tableName = "wx_message" + month;
}
try
{
decimal? innerUserId = 0;
var workAccount = wx_WorkAccount_BL.Get(m => m.USERNAME == username);
if (workAccount != null)
{
innerUserId = workAccount.INNERUSERID;
}
WX_MESSAGECOMPLIANCE compliance = new WX_MESSAGECOMPLIANCE
{
PKID = new SEQUENCES_BL().Seq_base_get(),
JOBUSERNAME = username,
USERNAME = talker,
INNERUSERID = innerUserId,
MESSAGE = msgcontent,
MSGTYPE = msgtype,
CTIME = DateTime.Now,
OPERATORID = UserId,
MSGSOURCE = 1,
MSGSVRID = msgsvrid,
MSGURL = msgurl,
BIGTYPE = bigType,
SUBTYPE = subType,
REMARK = model.REMARK,
TYPE = 1,
ORIGINALTIME = createtime,
RESULT = model.RESULT
};
var res = wx_MessageCompliance_BL.Get(m => m.MSGSVRID == msgsvrid);
if (res == null)
{
//进行合规扣款判断
/* 一类违规首次罚款500元二次再犯直接给予辞退或移交司法机关如该单已成交同时要扣除此单业绩
二类违规首次罚款300元二次再犯罚款500元第三次给予辞退如该单已成交同时要扣除此单业绩
三类违规首次罚款200元,二次或二次以上再犯罚款300元如该单已成交扣除此单业绩(超额订单直接退回用户)。
四类违规给予200元现金处罚
*/
if (compliance.BIGTYPE == "MessageComplianceA")
{
var complianceBlist = wx_MessageCompliance_BL.GetList(m => m.BIGTYPE == "MessageComplianceA" && m.INNERUSERID == innerUserId).ToList();
if (complianceBlist == null)
{
compliance.PENALTY = 500;
}
else
{
if (complianceBlist.Count == 0)
{
compliance.PENALTY = 500;
}
else
{
compliance.PENALTY = 0;
}
}
}
else if (compliance.BIGTYPE == "MessageComplianceB")
{
var complianceBlist = wx_MessageCompliance_BL.GetList(m => m.BIGTYPE == "MessageComplianceB" && m.INNERUSERID == innerUserId).ToList();
if (complianceBlist != null)
{
if (complianceBlist.Count >= 2)
{
compliance.PENALTY = 0;
}
else if (complianceBlist.Count == 1)
{
compliance.PENALTY = 500;
}
else if (complianceBlist.Count == 0)
{
compliance.PENALTY = 300;
}
}
else
{
compliance.PENALTY = 300;
}
}
else if (compliance.BIGTYPE == "MessageComplianceC")
{
var complianceBlist = wx_MessageCompliance_BL.GetList(m => m.BIGTYPE == "MessageComplianceC" && m.INNERUSERID == innerUserId).ToList();
if (complianceBlist == null)
{
compliance.PENALTY = 200;
}
else
{
if (complianceBlist.Count == 0)
{
compliance.PENALTY = 200;
}
else
{
compliance.PENALTY = 300;
}
}
}
else if (compliance.BIGTYPE == "MessageComplianceD")
{
compliance.PENALTY = 200;
}
else
{
compliance.PENALTY = 0;
}
wx_MessageCompliance_BL.Add(compliance);
}
wx_Message_BL.UpdateMessageIsIllegal(tableName, username, msgsvrid);
string rootPath = AppDomain.CurrentDomain.BaseDirectory + "Message"; //html文件生成的根目录
var dir = string.Format("{0}\\{1}", rootPath, username);
var path = string.Format("{0}_{1}.json", talker, month.Substring(0, 4) + month.Substring(4, 2).Replace("0", ""));
var str = Path.Combine(dir, path);
if (System.IO.File.Exists(Path.Combine(dir, path)))
{
string result = string.Format("[{0}]", FileUnit.Read(Path.Combine(dir, path)));
List<WX_MessageJson> messageJson = Utility.JSONToObject<List<WX_MessageJson>>(result);
if (messageJson != null && messageJson.Any(m => m.msgSvrId == msgsvrid))
{
Dictionary<string, WX_MessageJson> dic = messageJson.GroupBy(m => m.msgSvrId).ToDictionary(key => key.First().msgSvrId, value => value.First());
//Dictionary<string, WX_MessageJson> dic = new Dictionary<string, WX_MessageJson>();
//foreach(var m in messageJson)
//{
// dic.Add(m.msgSvrId, m);
//}
dic[msgsvrid].isillegal = 1;
FileUnit.Write(Path.Combine(dir, path), Utility.ConvertToJSON(dic.Values.ToList()).TrimStart('[').TrimEnd(']'));
}
}
return JsonHandler.ManageMessage("操作成功", true);
}
catch (Exception ex)
{
LogHelper.Error(ex);
return JsonHandler.ManageMessage(ex.Message, false);
}
}
public JsonResult GetSubTypeList(string bigType)
{
Pager pg = new Pager();
pg.page = 1;
pg.rows = int.MaxValue;
pg.order = "desc";
pg.sort = "paraKey";
var list = bas_SubComType_Q_BL.GetList_Subcomtype(ref pg, null, null, bigType, null, null);
var subTypeList = new List<SelectListItem>();
if (list != null)
{
foreach (var item in list)
{
subTypeList.Add(new SelectListItem { Text = item.Subtypename.map_SUBTYPENAME, Value = item.Subtypename.map_SUBTYPECODE });
}
}
return Json(subTypeList, JsonRequestBehavior.AllowGet);
}
[HttpGet]
[AuthorizeToolBar(InitRights.CONST_微信聊天合规管理, InitToolBar.CONST_Other2)]
public ActionResult Keyword()
{
var model = bas_Parameter_Q_BL.GetModel_Patameter(WX.CRM.Model.Enum.Parameter.WeiXin_IllegalKewords.ToString());
if (model == null)
{
model = new BAS_PARAMETER();
}
return View(model);
}
[HttpPost]
[AuthorizeToolBar(InitRights.CONST_微信聊天合规管理, InitToolBar.CONST_Other2)]
public JsonResult Keyword(BAS_PARAMETER model)
{
if (!string.IsNullOrEmpty(model.PARAKEY))
{
string keywords = model.PARAVALUE;
keywords = keywords.Replace("", ";").Replace("\n\r", "").Replace("\r", "").Replace("\n", "");
List<string> keylist2 = keywords.Split(';').ToList();
List<string> keylist = new List<string>();
foreach (var item in keylist2)
{
if (!string.IsNullOrEmpty(item))
keylist.Add(item);
}
string newkeyword = string.Join(";", keylist.ToArray());
model.PARAVALUE = keywords;
bas_Parameter_BL.Update_ParameterValueByKey(model.PARAKEY, model.PARAVALUE);
ww_huser_bl.SetKeyWords(keywords, ref errors);
return JsonHandler.UpdateMessage(errors, true);
}
else
{
errors.Add("不存在合规关键字记录,不能修改!");
return JsonHandler.UpdateMessage(errors, false);
}
}
#region
[AuthorizeRedirect(Roles = InitRights.CONST_微信聊天违规信息)]
public ActionResult ComplianceIndex()
{
ToolBar tool = new ToolBar();
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights., userRightId);
tool.AllowButton(toolbtn);
Pager pager = new Pager() { page = 1, rows = 20 };
string tableId = "tablist";
Table tab = new Table(tableId);
tab.AddHiddenHeadCol("PKID", "");
tab.AddHeadColRowSpan("RESID", 2, "来源");//合并行
tab.AddHeadCol("WXNAME", 4, "客服信息");
tab.AddHeadCol("CONTENT", 2, "违规信息");
tab.AddHeadCol("HGMSG", 6, "合规信息");
tab.AddHeadRow();
tab.AddHeadCol("JOBUSERNAME", "", "微信号/用户名");
tab.AddHeadCol("Alias", "", "企微/名称");
//tab.AddHeadCol("RESID", "", "客户ID");
tab.AddHeadCol("Eid", "", "客服");
tab.AddHeadCol("Gname", "", "销售组");
tab.AddHeadCol("USERNAME", "", "客户");
tab.AddHeadCol("MESSAGE", "25%", "消息");
tab.AddHeadCol("CTIME", "", "添加时间");
tab.AddHeadCol("OPERATORID", "", "操作人");
tab.AddHeadCol("SUBTYPE", "", "类别");
tab.AddHeadCol("REMARK", "", "违规细则");
tab.AddHeadCol("PENALTY", "", "违规金额");
tab.AddHeadCol("RESULT", "", "处理结果");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetHead() + Pagination.GetPage(pager, tableId, "20,30,50");
ViewBag.inneruserid = UserId;
ViewBag.userGroupId = userGroupId;
ViewBag.saleDeptId = saleDeptId;
ViewBag.ToolBar = tool;
ViewBag.roleCodes = DataCacheHelper.GetCache().Get_RoleCodes(userRoleId);
var model = new WX_MESSAGECOMPLIANCE();
var list = bas_ComType_Q_BL.GetList().Where(m => m.map_TYPECODE.Contains("MessageCompliance")).OrderBy(m => m.map_TYPECODE).ToList();
var bigTypeList = new List<SelectListItem>();
if (list != null)
{
foreach (var m in list)
{
bigTypeList.Add(new SelectListItem { Text = m.map_TYPENAME, Value = m.map_TYPECODE });
}
}
ViewBag.BigTypeList = bigTypeList;
return View();
}
[HttpPost]
[AuthorizeRedirect(Roles = InitRights.CONST_微信聊天违规信息)]
public JsonResult GetComplianceIndexHtmlList(Pager pager, string jobUserName, string stime, string etime, string nickName, string conRemark, string bigType, string subType, string columns)
{
decimal groupId = Request["groupId"].GetDecimal(0);
decimal userId = Request["userId"].GetDecimal(0);
string[] userArrs = null;
if (!string.IsNullOrWhiteSpace(nickName) || !string.IsNullOrWhiteSpace(conRemark))
{
Pager pager2 = new Pager();
pager2.rows = 1000;
pager2.page = 1;
var rcontackList = wx_Rcontact_BL.GetList(ref pager2, null, null, null, nickName, conRemark, null, null);
if (rcontackList != null && rcontackList.Count > 0)
{
userArrs = rcontackList.Select(m => m.USERNAME).ToArray();
}
}
var list = wx_MessageCompliance_BL.GetList(ref pager, groupId, userId, userArrs, jobUserName, bigType, subType, stime, etime);
Table table = new Table(columns, true);
foreach (var model in list)
{
WX_Message_Extend message = new WX_Message_Extend()
{
msgtype = (int?)model.wx_MessageCompliance.MSGTYPE,
msgsvrid = model.wx_MessageCompliance.MSGSVRID,
msgurl = model.wx_MessageCompliance.MSGURL,
msgcontent = model.wx_MessageCompliance.MESSAGE
};
table.AddHiddenCol(model.wx_MessageCompliance.PKID);
if (model.wx_MessageCompliance.TYPE == 1)
{
table.AddCol("<font color='#5FB878'>微信</font>");
}
else if (model.wx_MessageCompliance.TYPE == 2)
{
var linkUrl = string.Format("<a href=\"javascript:parent.ChildAddTab('{0}', '{1}', '')\">{2}</a>"
, "客户详细"
, "/Csvr/CustomerInfo/CustomerDetail?resid=" + model.wx_MessageCompliance.RESID
, model.wx_MessageCompliance.RESID);
table.AddCol(linkUrl);
}
else if (model.wx_MessageCompliance.TYPE == 3)
{
table.AddCol(string.Format("企微:<br/><font>{0}</font>", model.wx_MessageCompliance.CORPNAME));
}
if (!string.IsNullOrEmpty(model.wx_MessageCompliance.JOBUSERNAME))
{
table.AddCol(string.Format("{0}<br/>{1}", model.Alias, model.wx_MessageCompliance.JOBUSERNAME));
}
else
{
table.AddCol("");
}
if (!string.IsNullOrEmpty(model.wx_MessageCompliance.HHUSERID))
{
table.AddCol(string.Format("{0}/{1}", model.wx_MessageCompliance.HHUSERID, model.wx_MessageCompliance.HHUSERNAME));
}
else
{
table.AddCol("");
}
table.AddCol(InnerUserHelper.Instance.EidAndName(model.wx_MessageCompliance.INNERUSERID));
table.AddCol(InnerUserHelper.Instance.GetGroupName(InnerUserHelper.Instance.GetGroupId(model.wx_MessageCompliance.INNERUSERID)));
if (model.wx_MessageCompliance.TYPE == 3)
{
table.AddCol(model.wx_MessageCompliance.EXTNAME);
}
else
{
table.AddCol(model.wx_MessageCompliance.USERNAME);
}
if (model.wx_MessageCompliance.TYPE == 2)
{
string cti;
string playurl = _getCallRecordUrl(model.wx_MessageCompliance.SERVERID, model.wx_MessageCompliance.FILENAME, out cti);
var playcrl = string.Format("<input id=\"BtnPlayer\" type=\"button\" value=\" 播 放 \" onclick=\"PalyRecord('{0}','DivPlayer{1}','{2}')\" />",
playurl, model.wx_MessageCompliance.RECORDID, cti == null ? "" : cti);
playcrl += string.Format("<div id=\"DivPlayer{0}\"></div><input type=\"hidden\" id=\"hidRecordUrl\" value=\"{1}\" />", model.wx_MessageCompliance.RECORDID, playurl);
table.AddCol(playcrl);
}
else
{
table.AddCol(getMsgContent(message));
}
table.AddCol(model.wx_MessageCompliance.CTIME);
table.AddCol(InnerUserHelper.Instance.EidAndName(model.wx_MessageCompliance.OPERATORID));
table.AddCol(getSubType(model));
table.AddCol(model.wx_MessageCompliance.REMARK);
table.AddCol(model.wx_MessageCompliance.PENALTY);
table.AddCol(model.wx_MessageCompliance.RESULT);
table.AddRow();
}
var json = new
{
totalPages = pager.totalPages,
totalRows = pager.totalRows,
rowsList = table.GetRows()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
[AuthorizeToolBar(InitRights.CONST_微信聊天违规信息, InitToolBar.CONST_Delete)]
public JsonResult Delete(decimal? id)
{
if (!id.HasValue)
{
return JsonHandler.ManageMessage("id不能为空", false);
}
var model = wx_MessageCompliance_BL.Get(m => m.PKID == id);
if (model == null)
{
return JsonHandler.ManageMessage("删除的记录不存在", false);
}
bool result = false;
//删除微信聊天记录
if (model.TYPE == 1)
{
try
{
string month = string.Format("{0:yyyyMM}", model.ORIGINALTIME);
var tableName = "wx_message" + month;
var msgsvrid = model.MSGSVRID;
wx_MessageCompliance_BL.DeleteMessageIsIllegal(tableName, model.JOBUSERNAME, msgsvrid);
string rootPath = AppDomain.CurrentDomain.BaseDirectory + "Message"; //html文件生成的根目录
var dir = string.Format("{0}\\{1}", rootPath, model.JOBUSERNAME);
var path = string.Format("{0}_{1}.json", model.USERNAME, month.Substring(0, 4) + month.Substring(4, 2).Replace("0", ""));
var str = Path.Combine(dir, path);
if (System.IO.File.Exists(Path.Combine(dir, path)))
{
string res = string.Format("[{0}]", FileUnit.Read(Path.Combine(dir, path)));
List<WX_MessageJson> messageJson = Utility.JSONToObject<List<WX_MessageJson>>(res);
if (messageJson != null && messageJson.Any(m => m.msgSvrId == msgsvrid))
{
Dictionary<string, WX_MessageJson> dic = messageJson.GroupBy(m => m.msgSvrId).ToDictionary(key => key.First().msgSvrId, value => value.First());
//Dictionary<string, WX_MessageJson> dic = new Dictionary<string, WX_MessageJson>();
//foreach(var m in messageJson)
//{
// dic.Add(m.msgSvrId, m);
//}
dic[msgsvrid].isillegal = 0;
FileUnit.Write(Path.Combine(dir, path), Utility.ConvertToJSON(dic.Values.ToList()).TrimStart('[').TrimEnd(']'));
}
}
result = wx_MessageCompliance_BL.DeleteMessage(ref errors, id.Value);
return JsonHandler.DeleteMessage(errors, result);
}
catch (Exception ex)
{
LogHelper.Error(ex);
errors.Add(ex.ToString());
return JsonHandler.DeleteMessage(errors, false);
}
}
else //删除录音记录
{
result = wx_MessageCompliance_BL.DeleteMessage(ref errors, id.Value);
return JsonHandler.DeleteMessage(errors, result);
}
}
#endregion
[AuthorizeRedirect(Roles = InitRights.CONST_合规信息统计)]
public ActionResult CountCompliance(DateTime? stime, DateTime? etime)
{
ToolBar tool = new ToolBar();
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights., userRightId);
tool.AllowButton(toolbtn);
ViewBag.ToolBar = tool;
if (!stime.HasValue)
stime = DateTime.Now;
if (!etime.HasValue)
etime = DateTime.Now;
var list = bas_ComType_Q_BL.GetList().Where(m => m.map_TYPECODE.Contains("MessageCompliance")).OrderBy(m => m.map_TYPECODE).ToList();
//string tableId = "tablist";
//Table tab = new Table(tableId);
//tab.AddHeadCol("Eid", "", "客服");
//tab.AddHeadCol("Gname", "", "销售组");
//if(list != null)
//{
// foreach(var bigType in list)
// {
// tab.AddHeadCol(bigType.map_TYPECODE, "", bigType.map_TYPENAME);
// }
//}
//ViewBag.gridTable = tab.GetHead();
if (list == null)
{
list = new List<BAS_COMTYPE>();
}
ViewBag.BigTypeList = list;
ViewBag.stime = stime;
ViewBag.etime = etime;
return View();
}
[AuthorizeRedirect(Roles = InitRights.CONST_合规信息统计)]
public JsonResult GetCountComplianceHtml(string stime, string etime)
{
DataSet ds = wx_MessageCompliance_BL.CountMessageCompliance(stime, etime);
List<CountComplianceByUser> countComplianceByUserList = null;
List<CountComplianceBySubType> countComplianceBySubTypeList = null;
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
countComplianceByUserList = ds.Tables[0].ToList<CountComplianceByUser>();
}
if (ds != null && ds.Tables[1].Rows.Count > 0)
{
countComplianceBySubTypeList = ds.Tables[1].ToList<CountComplianceBySubType>();
}
var bigTypelist = bas_ComType_Q_BL.GetList().Where(m => m.map_TYPECODE.Contains("MessageCompliance")).OrderBy(m => m.map_TYPECODE).ToList();
List<BAS_SUBCOMTYPE> subTypeList = new List<BAS_SUBCOMTYPE>();
if (bigTypelist != null)
{
List<BAS_SUBCOMTYPE> subList = null;
foreach (var item in bigTypelist)
{
subList = cache_BL.GetList_SubComType(item.map_TYPECODE);
if (subList != null)
{
subTypeList.AddRange(subList);
}
}
}
Table tab = new Table("tablist");
if (countComplianceByUserList != null)
{
List<decimal> innerUserIdList = countComplianceByUserList.GroupBy(m => m.InnerUserId).Select(g => g.Key).ToList();
if (innerUserIdList != null)
{
foreach (var userId in innerUserIdList)
{
tab.AddCol(InnerUserHelper.Instance.GetEidAndTrueName(userId));
tab.AddCol(InnerUserHelper.Instance.GetGroupName(InnerUserHelper.Instance.GetGroupId(userId)));
if (bigTypelist != null)
{
foreach (var item in bigTypelist)
{
var model = countComplianceByUserList.Where(m => m.InnerUserId == userId && m.BigType == item.map_TYPECODE).SingleOrDefault();
tab.AddCol(model != null ? model.CountNum : 0);
}
}
tab.AddRow();
}
}
}
string tableId = "tablist2";
Table tab2 = new Table(tableId);
tab2.AddHeadCol("SubType", "", "合规分类");
tab2.AddHeadCol("CountNum", "", "数量");
tab2.AddHeadCol("NumRate", "", "占比(%)");
tab2.AddHeadRow();
if (countComplianceBySubTypeList != null)
{
foreach (var item in countComplianceBySubTypeList)
{
var subType = subTypeList.Where(m => m.map_SUBTYPECODE == item.SubType).SingleOrDefault();
tab2.AddCol(subType != null ? subType.map_SUBTYPENAME : "");
string url = string.Format("<a href=\"javascript:window.parent.ChildAddTab('微信聊天违规信息', '/WeiXin/Message/ComplianceIndex?subType={0}&stime={1}&etime={2}', '');\">{3}</a>", item.SubType, stime, etime, item.CountNum);
tab2.AddCol(url);
tab2.AddCol(item.NumRate);
tab2.AddRow();
}
}
//ViewBag.gridTable = tab.GetTable();
var json = new
{
data = tab.GetRows(),
rowList = tab2.GetTable()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
[AuthorizeRedirect(Roles = InitRights.CONST_合规信息统计)]
public ActionResult CountComplianceList()
{
//ToolBar
ToolBar tool = new ToolBar();
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights., userRightId);
tool.AllowButton(toolbtn);
ViewBag.ToolBar = tool;
//table
string tableId = "tablist";
Table tab = new Table(tableId);
tab.AddHeadCol("Eid", "", "客服");
tab.AddHeadCol("GName", "", "销售组");
tab.AddHeadCol("SubTypeName", "", "类别");
tab.AddHeadCol("ARRIVALPAY", "", "数量");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetHead();
return View();
}
[HttpPost]
[AuthorizeRedirect(Roles = InitRights.CONST_合规信息统计)]
public JsonResult GetCountComplianceHtmlList(string columns)
{
var typeCode = Request["typeCode"];
var stime = Request["stime"];
var etime = Request["etime"];
DataSet ds = wx_MessageCompliance_BL.CountMessageComplianceList(typeCode, stime, etime);
var subList = cache_BL.GetList_SubComType(typeCode);
Table table = new Table(columns, true);
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
DataTable dt = ds.Tables[0];
foreach (DataRow dr in dt.Rows)
{
table.AddCol(InnerUserHelper.Instance.GetEidAndTrueName(Convert.ToDecimal(dr["inneruserid"])));
table.AddCol(InnerUserHelper.Instance.GetGroupName(InnerUserHelper.Instance.GetGroupId(Convert.ToDecimal(dr["inneruserid"]))));
if (subList != null)
{
var subType = subList.Where(m => m.map_SUBTYPECODE == dr["subtype"].ToString()).SingleOrDefault();
table.AddCol(subType != null ? subType.SUBTYPENAME : "");
}
else
{
table.AddCol("");
}
table.AddCol(dr["countnum"]);
table.AddRow();
}
}
var json = new
{
rowsList = table.GetRows()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
private string getSubType(WX_MESSAGECOMPLIANCE_Extend model)
{
if (model.wx_MessageCompliance.BIGTYPE == Model.Enum.ComType.MessageComplianceA.ToString())
{
var subList = cache_BL.GetList_SubComType(Model.Enum.ComType.MessageComplianceA);
if (subList != null)
{
var subType = subList.Where(m => m.map_SUBTYPECODE == model.wx_MessageCompliance.SUBTYPE).FirstOrDefault();
if (subType != null)
{
return subType.map_SUBTYPENAME;
}
}
}
else if (model.wx_MessageCompliance.BIGTYPE == Model.Enum.ComType.MessageComplianceB.ToString())
{
var subList = cache_BL.GetList_SubComType(Model.Enum.ComType.MessageComplianceB);
if (subList != null)
{
var subType = subList.Where(m => m.map_SUBTYPECODE == model.wx_MessageCompliance.SUBTYPE).FirstOrDefault();
if (subType != null)
{
return subType.map_SUBTYPENAME;
}
}
}
else if (model.wx_MessageCompliance.BIGTYPE == Model.Enum.ComType.MessageComplianceC.ToString())
{
var subList = cache_BL.GetList_SubComType(Model.Enum.ComType.MessageComplianceC);
if (subList != null)
{
var subType = subList.Where(m => m.map_SUBTYPECODE == model.wx_MessageCompliance.SUBTYPE).FirstOrDefault();
if (subType != null)
{
return subType.map_SUBTYPENAME;
}
}
}
else if (model.wx_MessageCompliance.BIGTYPE == Model.Enum.ComType.MessageComplianceD.ToString())
{
var subList = cache_BL.GetList_SubComType(Model.Enum.ComType.MessageComplianceD);
if (subList != null)
{
var subType = subList.Where(m => m.map_SUBTYPECODE == model.wx_MessageCompliance.SUBTYPE).FirstOrDefault();
if (subType != null)
{
return subType.map_SUBTYPENAME;
}
}
}
return "";
}
private string getMsgContent(WX_Message_Extend model)
{
if (model.msgtype == 3)
{
return string.Format("[图片]<img style='max-width:300px' id='file_{0}' src=''><script>GetImage('{0}','{1}');</script>", model.msgsvrid, model.msgtype);
}
else if (model.msgtype == 47)
{
if (!string.IsNullOrWhiteSpace(model.msgurl))
{
return string.Format("<img style='max-width:100px' id='file_{0}' src='{2}'><script>GetImage('{0}','{1}');</script>", model.msgsvrid, model.msgtype, model.msgurl);
}
else
{
return string.Format("<img style='max-width:100px' id='file_{0}' src=''><script>GetImage('{0}','{1}');</script>", model.msgsvrid, model.msgtype);
}
}
else if (model.msgtype == 34)
{
return string.Format("<a id='file_{0}' >[语音]<a><script>GetImage('{0}','{1}');</script>", model.msgsvrid, model.msgtype);
}
else if (model.msgtype == 43)
{
return string.Format("<a id='file_{0}' >[视频]<a><script>GetImage('{0}','{1}');</script>", model.msgsvrid, model.msgtype);
}
else if (model.msgtype == 49)
{
return string.Format("<a id='file_{0}' >[文件]<a><script>GetImage('{0}','{1}');</script>", model.msgsvrid, model.msgtype);
}
else
{
return string.Format("<div id='txt_{0}'>{1}</div><script>keyHighLight('{0}');</script>", model.msgsvrid, model.msgcontent);
//return model.msgcontent;
}
}
private List<SelectListItem> getMonthList()
{
List<SelectListItem> list = new List<SelectListItem>();
var currentText = string.Format("{0:yyyy}年{0:MM}月", DateTime.Now);
var currentValue = string.Format("{0:yyyyMM}", DateTime.Now);
var endText = "2016年12月";
var endValue = "201612";
list.Add(new SelectListItem { Text = currentText, Value = currentValue });
int i = 1;
while (true)
{
var text = string.Format("{0:yyyy}年{0:MM}月", DateTime.Now.AddMonths(-i));
var value = string.Format("{0:yyyyMM}", DateTime.Now.AddMonths(-i));
if (value == endValue)
{
break;
}
list.Add(new SelectListItem { Text = text, Value = value });
i++;
}
list.Add(new SelectListItem { Text = endText, Value = endValue });
return list;
}
private class CountComplianceByUser
{
public decimal InnerUserId { get; set; }
public string BigType { get; set; }
public decimal CountNum { get; set; }
}
private class CountComplianceBySubType
{
public string SubType { get; set; }
public decimal CountNum { get; set; }
public decimal NumRate { get; set; }
}
//获取录音地址
private string _getCallRecordUrl(string _ServerID, string _FileName, out string cti)
{
var playurl = "";
cti = "";
var _IAD_localhostCallRecord = _BAS_PARAMETER_Q.GetModel_Patameter("ICSR_IAD_localhostCallRecord");
if (null != _IAD_localhostCallRecord)
{
var FuturesRecordServerUrl = _IAD_localhostCallRecord.PARAVALUE;
playurl = FuturesRecordServerUrl + "?serverID=" + _ServerID + "&file=" + _FileName.Replace("\\", "/");
cti = _CSVR_CALLRECORD_Q.Sys_Environment_CTI_VER();
if (cti != null && cti == ((int)WX.CRM.Model.Enum.CTI_VER.).ToString())
{
playurl = FuturesRecordServerUrl + "?file=" + _FileName.Replace("\\", "/");
}
if (cti != null && cti == ((int)WX.CRM.Model.Enum.CTI_VER.).ToString())
{
var shjctiinterface = Utility.GetSettingByKey("shj");
playurl = shjctiinterface + "?action=record_download&filename=/var/spool/asterisk/monitor/" + _FileName.Replace("\\", "/");
}
if (cti != null && cti == ((int)WX.CRM.Model.Enum.CTI_VER.).ToString())
{
playurl = FuturesRecordServerUrl + "?file=" + _FileName;
}
if (cti != null && cti == ((int)WX.CRM.Model.Enum.CTI_VER.).ToString())
{
playurl = FuturesRecordServerUrl + _FileName;
}
if (cti != null && cti == ((int)WX.CRM.Model.Enum.CTI_VER.new).ToString())
{
_IAD_localhostCallRecord = _BAS_PARAMETER_Q.GetModel_Patameter("ICSR_IAD_localhostCallRecord_AX");
var filename = _FileName;
if (null != _IAD_localhostCallRecord)
{
playurl = _IAD_localhostCallRecord.PARAVALUE + (filename.StartsWith("UP") ? "/home/" + filename : filename);
playurl = playurl.Replace("\\", "/");
}
}
}
return playurl;
}
}
}