ComplianceServer/oldcode/WEB/Controllers/WeiXin/WXRcontactController.cs

913 lines
41 KiB
C#

using CRM.Core.DTO;
using Ninject;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using WX.CRM.Common;
using WX.CRM.IBLL.Base;
using WX.CRM.IBLL.Wx;
using WX.CRM.Model.Entity;
using WX.CRM.Model.MAP;
using WX.CRM.WEB.Handler;
using WX.CRM.WebHelper;
namespace WX.CRM.WEB.Controllers.WeiXin
{
public class WXRcontactController : BaseController
{
ValidationErrors errors = new ValidationErrors();
private IWX_RCONTACT rcontactBL;
private readonly IWX_FRIENDSRELATION _friendsrelation;
[Inject]
public IWX_WORKACCOUNT wx_Workaccount_BL { get; set; }
[Inject]
public IBAS_PARAMETER_Q bas_Parameter_BL { get; set; }
[Inject]
public WX.CRM.IBLL.Util.ICACHE_Q cache_q { get; set; }
public WXRcontactController(IWX_RCONTACT _rcontactBL, IWX_FRIENDSRELATION friendsrelation)
{
this.rcontactBL = _rcontactBL;
_friendsrelation = friendsrelation;
}
#region
[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-export", "Export_Click1", true);
ViewBag.ToolBar = tool;
Pager pager = new Pager() { page = 1, rows = 10 };
string tableId = "tablist";
Table tab = new Table(tableId);
tab.AddHiddenHeadCol("PKID", "编号");
tab.AddHeadCol("groupName", "", "组别");
tab.AddHeadCol("inneruserEid", "", "员工");
tab.AddHeadCol("JOBWXUSERNAME", "15%", "工作微信用户名");
tab.AddHeadCol("USERNAME", "15%", "客户微信用户名");
tab.AddHeadCol("NICKNAME", "", "昵称");
tab.AddHeadCol("CONREMARK", "", "备注和标签");
tab.AddHeadCol("CTIME", "15%", "创建时间");
tab.AddHeadCol("", "6%", "");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetTable() + Pagination.GetPage(pager, tableId, "5,8,10,15");
ViewBag.inneruserid = UserId;
ViewBag.userGroupId = userGroupId;
ViewBag.saleDeptId = saleDeptId;
ViewBag.roleCodes = DataCacheHelper.GetCache().Get_RoleCodes(userRoleId);
return View();
}
/// <summary>
/// 按照条件获取数据
/// </summary>
/// <param name="pager"></param>
/// <param name="queryStr"></param>
/// <returns></returns>
[HttpPost]
[AuthorizeRedirect(Roles = InitRights.CONST_工作微信好友关系)]
public JsonResult GetHtmlList(Pager pager, string jobUsername, string Username, string userId, string groupId, string columns)
{
string Stime = Request.Form["Stime"];
string Etime = Request.Form["Etime"];
string Eid = Request.Form["Eid"];
string path = System.Web.HttpContext.Current.Request.Url.Authority.ToString();//得到的结果:localhost:port
decimal saleid = 0;
try
{
if (!string.IsNullOrWhiteSpace(Eid))
saleid = InnerUserHelper.Instance.GetUserIdByEid(Convert.ToDecimal(Eid.Trim()));
List<WX_RCONTACT_Extend> list = new List<WX_RCONTACT_Extend>();// rcontactBL.GetList(ref pager, Username, jobUsername, userId, groupId, saleid, Stime, Etime);
Table table = new Table(columns, true);
table.gridPager = pager;
string isShowMobileOfContent = cache_q.GetValue_Parameter(Model.Enum.Parameter.Sys_IsShowMobileOfContent);
foreach (WX_RCONTACT_Extend model in list)
{
table.AddHiddenCol(model.wx_rcontact.PKID);
table.AddCol(model.groupName);
table.AddCol(model.inneruserEid.ToString() + " - " + model.inneruserName);
table.AddCol(model.wx_rcontact.JOBWXUSERNAME);
table.AddCol(model.wx_rcontact.USERNAME);
if (!string.IsNullOrEmpty(isShowMobileOfContent) && isShowMobileOfContent == "1")
{
table.AddCol(model.wx_rcontact.NICKNAME);
table.AddCol(model.wx_rcontact.CONREMARK);
}
else
{
table.AddCol(Utility.ReplaceMobile(model.wx_rcontact.NICKNAME));
table.AddCol(Utility.ReplaceMobile(model.wx_rcontact.CONREMARK));
}
table.AddCol(model.wx_rcontact.CTIME);
var linkUrl = string.Format("<a href=\"javascript:messageRecord('http://" + path + "/WeiXinmm/k/{0}/n001.html')\">消息记录</a>", model.wx_rcontact.USERNAME);
table.AddCol(linkUrl);
table.AddRow();
}
var json = new
{
totalPages = pager.totalPages,
totalRows = pager.totalRows,
rowsList = table.GetRows()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
LogHelper.Error("WXRcontactController:" + ex.Message + ex.StackTrace);
return JsonHandler.ManageMessage(ex.Message, false);
}
}
#endregion
#region
[AuthorizeRedirect(Roles = InitRights.CONST_微信资源列表)]
public ActionResult List()
{
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.AddHeadCol("USERNAME", "", "客户微信用户名(时间段重复数)");
tab.AddHeadCol("NICKNAME", "", "昵称");
tab.AddHeadCol("CONREMARK", "", "备注和标签");
tab.AddHeadCol("JOBWXUSERNAME", "", "工作微信");
tab.AddHeadCol("WorkAlias", "", "工作微信号");
tab.AddHeadCol("inneruserId", "", "客服");
tab.AddHeadCol("RESID", "", "绑定资源");
tab.AddHeadCol("CTIME", "", "添加时间");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetTable() + Pagination.GetPage(pager, tableId, "10,20,30");
//ViewBag.inneruserid = UserId;
//ViewBag.userGroupId = userGroupId;
//ViewBag.saleDeptId = saleDeptId;
//ViewBag.roleCodes = DataCacheHelper.GetCache().Get_RoleCodes(userRoleId);
return View();
}
[HttpPost]
[AuthorizeRedirect(Roles = InitRights.CONST_微信资源列表)]
public JsonResult GetListHtml(Pager pager, string workAlias, string userName, string alias, string resID, string nickName, string conRemark, string stime, string etime, string columns)
{
try
{
var jobUserName = "";
if (!string.IsNullOrEmpty(workAlias))
{
var workAccount = wx_Workaccount_BL.Get(m => m.ALIAS == workAlias);
if (workAccount != null)
{
jobUserName = workAccount.USERNAME;
}
}
List<WX_RCONTACT_Extend> list = rcontactBL.GetListAndWorkAccount(ref pager, jobUserName, userName, alias, nickName, conRemark, stime, etime, resID);
Table table = new Table(columns, true);
table.gridPager = pager;
List<string> usernameList = list.Select(m => m.wx_rcontact.USERNAME).ToList();
var countList = rcontactBL.GetRcontactUserNameCount(stime, etime, usernameList);
string isShowMobileOfContent = cache_q.GetValue_Parameter(Model.Enum.Parameter.Sys_IsShowMobileOfContent);
foreach (WX_RCONTACT_Extend model in list)
{
table.AddHiddenCol(model.wx_rcontact.PKID);
decimal num = 1;
var numModel = countList.Where(m => m.UserName == model.wx_rcontact.USERNAME).FirstOrDefault();
if (numModel != null)
{
num = numModel.Num;
}
table.AddCol(string.Format("{0} ({1})", model.wx_rcontact.USERNAME, num));
if (!string.IsNullOrEmpty(isShowMobileOfContent) && isShowMobileOfContent == "1")
{
table.AddCol(model.wx_rcontact.NICKNAME);
table.AddCol(model.wx_rcontact.CONREMARK);
}
else
{
table.AddCol(Utility.ReplaceMobile(model.wx_rcontact.NICKNAME));
table.AddCol(Utility.ReplaceMobile(model.wx_rcontact.CONREMARK));
}
table.AddCol(model.wx_rcontact.JOBWXUSERNAME);
table.AddCol(model.WorkAlias);
table.AddCol(InnerUserHelper.Instance.GetEidAndTrueName(model.inneruserId));
var linkUrl = string.Format("<a href=\"javascript:parent.ChildAddTab('{0}', '{1}', '')\">{2}</a>"
, "客户详细"
, "/Csvr/CustomerInfo/CustomerDetail?resid=" + model.wx_rcontact.RESID
, model.wx_rcontact.RESID);
table.AddCol(linkUrl);
table.AddCol(model.wx_rcontact.CTIME);
table.AddRow();
}
var json = new
{
totalPages = pager.totalPages,
totalRows = pager.totalRows,
rowsList = table.GetRows()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
LogHelper.Error("WXRcontactController:" + ex.Message + ex.StackTrace);
return JsonHandler.ManageMessage(ex.Message, false);
}
}
#endregion
#region
[AuthorizeToolBar(InitRights.CONST_工作微信好友关系, InitToolBar.CONST_Other1)]
public FileResult ListExport()
{
string jobUsername = Request.QueryString["jobUsername"];
string Username = Request.QueryString["Username"];
string Eid = Request.QueryString["Eid"];
string groupId = Request.QueryString["groupId"];
string userId = Request.QueryString["userId"];
string stime = Request.QueryString["Stime"];
string etime = Request.QueryString["Etime"];
decimal saleid = 0;
if (!string.IsNullOrWhiteSpace(Eid))
saleid = InnerUserHelper.Instance.GetUserIdByEid(Convert.ToDecimal(Eid.Trim()));
Pager pager = new Pager() { rows = int.MaxValue, page = 1 };
string checkedFilds = PageRequest.GetQueryString("checkedFilds");
string checkedTitle = PageRequest.GetQueryString("checkedTitles");
List<WX_RCONTACT_Extend> list = new List<WX_RCONTACT_Extend>();//rcontactBL.GetList(ref pager, Username, jobUsername, userId, groupId, saleid, stime, etime);
return File(ExcelHelper.ExportListModelToExcel<WX_RCONTACT_Extend>(list, "工作微信好友关系", 60000, checkedFilds, checkedTitle, null), "application/ms-excel", PageRequest.GetDlownLoadName("工作微信好友关系.xls"));
}
#endregion
#region
[HttpGet]
[AuthorizeRedirect(InitRights.CONST_微信资源日报表)]
public ActionResult DayReport()
{
ControlResource.JudgeSYQ();
string tableId = "tablist";
Table tab = new Table(tableId);
BAS_PARAMETER p = bas_Parameter_BL.GetModel_Patameter("WeiXin_RPort_IsShowAddCount");//资源日报表显示主动加资源数
BAS_PARAMETER p2 = bas_Parameter_BL.GetModel_Patameter("WeiXin_WebChatAssistant"); //微信助手参数
//Pager pager = new Pager() { page = 1, rows = int.MaxValue };
tab.AddHeadCol("dayTime", "", "日期");
tab.AddHeadCol("resourceCount", "", "资源数");
tab.AddHeadCol("distinctResourceCount", "", "去重资源数");
tab.AddHeadCol("rconcateCount", "", "好友资源数");
if (p != null && p.PARAVALUE == "1")
{
tab.AddHeadCol("addResourceCount", "", "主加资源数");
}
if (p2 != null && p2.PARAVALUE == "show")
{
tab.AddHeadCol("webChatResourceCount", "", "微信助手资源数");
}
tab.AddHeadRow();
ViewBag.gridTable = tab.GetTable();
return View();
}
[HttpGet]
[AuthorizeRedirect(InitRights.CONST_微信资源日报表_三部)]
public ActionResult DayReport3()
{
ControlResource.JudgeSYQ();
string tableId = "tablist";
Table tab = new Table(tableId);
BAS_PARAMETER p = bas_Parameter_BL.GetModel_Patameter("WeiXin_RPort_IsShowAddCount");//资源日报表显示主动加资源数
BAS_PARAMETER p2 = bas_Parameter_BL.GetModel_Patameter("WeiXin_WebChatAssistant"); //微信助手参数
//Pager pager = new Pager() { page = 1, rows = int.MaxValue };
tab.AddHeadCol("dayTime", "", "日期");
tab.AddHeadCol("resourceCount", "", "资源数");
tab.AddHeadCol("distinctResourceCount", "", "去重资源数");
tab.AddHeadCol("rconcateCount", "", "好友资源数");
if (p != null && p.PARAVALUE == "1")
{
tab.AddHeadCol("addResourceCount", "", "主加资源数");
}
if (p2 != null && p2.PARAVALUE == "show")
{
tab.AddHeadCol("webChatResourceCount", "", "微信助手资源数");
}
tab.AddHeadRow();
ViewBag.gridTable = tab.GetTable();
return View();
}
[HttpPost]
//[AuthorizeRedirect(InitRights.CONST_微信资源日报表)]
public JsonResult DayReportHtml(string columns, string sdCTime, string edCTime, decimal? type)
{
ControlResource.JudgeSYQ();
try
{
if (string.IsNullOrEmpty(sdCTime) || string.IsNullOrEmpty(edCTime))
{
return JsonHandler.ManageMessage("参数有误,请确认!", false);
}
DateTime? sTime = null;
DateTime? eTime = null;
DateTime stTime;
DateTime etTime;
DateTime.TryParse(sdCTime, out stTime);
sTime = stTime;
DateTime.TryParse(edCTime, out etTime);
eTime = etTime.AddDays(1);
Table table = new Table(columns, true);
var dt = rcontactBL.RcontactByDayReport(sTime, eTime, type);
var list = new List<decimal>();
BAS_PARAMETER p = bas_Parameter_BL.GetModel_Patameter("WeiXin_RPort_IsShowAddCount");//资源日报表显示主动加资源数
BAS_PARAMETER p2 = bas_Parameter_BL.GetModel_Patameter("WeiXin_WebChatAssistant"); //微信助手参数
BAS_PARAMETER p3 = bas_Parameter_BL.GetModel_Patameter("Sys_SaleDeptId_Three"); //业务三部id
decimal threeSaleDeptid = 0;
if (p3 != null && !string.IsNullOrEmpty(p3.PARAVALUE))
{
threeSaleDeptid = Convert.ToDecimal(p3.PARAVALUE);
}
foreach (DataRow model in dt.Rows)
{
if (string.IsNullOrEmpty(model["dayTime"].ToString()))
{
table.AddCol("合计:");
table.AddCol(model["resourceCount"].ToString());
table.AddCol(list.Sum());
table.AddCol(model["rconcateCount"].ToString());
if (p != null && p.PARAVALUE == "1")
{
table.AddCol(model["addResourceCount"].ToString());
}
if (p2 != null && p2.PARAVALUE == "show")
{
table.AddCol(model["webChatResourceCount"].ToString());
}
}
else
{
var i = getDistinctWeiXinFriendCountFromCache(model["dayTime"].ToString(), type, threeSaleDeptid);
list.Add(i);
var linkUrl = string.Format("<a href=\"javascript:parent.ChildAddTab('{0}', '{1}', '')\">{2}</a>", "微信员工日资源汇总", "/WeiXin/WXRcontact/UserDayReport?datetime=" + model["dayTime"] + "&type=" + type, model["resourceCount"]);
table.AddCol(model["dayTime"].ToString());
table.AddCol(linkUrl);
table.AddCol(i);
table.AddCol(model["rconcateCount"].ToString());
if (p != null && p.PARAVALUE == "1")
{
table.AddCol(model["addResourceCount"].ToString());
}
if (p2 != null && p2.PARAVALUE == "show")
{
var linkUrl2 = string.Format("<a href=\"javascript:parent.ChildAddTab('{0}', '{1}', '')\">{2}</a>", "微信助手日资源汇总", "/WeiXin/WXRcontact/WebChatDayReport?datetime=" + model["dayTime"] + "&type=" + type, model["webChatResourceCount"]);
table.AddCol(linkUrl2);
}
}
table.AddRow();
}
var json = new { rowsList = table.GetRows() };
return Json(json, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
LogHelper.Error("WXRcontactController:" + ex.Message + ex.StackTrace);
return JsonHandler.ManageMessage(ex.Message, false);
}
}
private decimal getDistinctWeiXinFriendCountFromCache(string day, decimal? type, decimal? saleDeptId)
{
if (string.IsNullOrWhiteSpace(day))
{
return 0;
}
if (!type.HasValue)
{
type = 0;
}
string nday = cache_q.GetValue_Parameter("WeiXin_DayReportShowDay");//位置资源日报表缓存天数
int days = 1;//默认是一天前
if (!string.IsNullOrWhiteSpace(nday))
{
days = Convert.ToInt32(nday);
}
if (DateTime.Now.Date > Convert.ToDateTime(day).AddDays(days - 1))
{
var cacheKey = "cache_GetDistinctWeiXinFriendCount_" + day + "_" + type.Value;
if (CacheHelper.Exists(cacheKey))
{
return CacheHelper.Get<decimal>(cacheKey);
}
else
{
var val = rcontactBL.GetDistinctWeiXinFriendCount(day, type, saleDeptId);
CacheHelper.Set<decimal>(cacheKey, val, DateTime.Now.AddDays(1));
return val;
}
}
else
{
return rcontactBL.GetDistinctWeiXinFriendCount(day, type, saleDeptId);
}
}
#endregion
#region
[HttpGet]
[AuthorizeRedirect(InitRights.CONST_员工明显日报表)]
public ViewResult UserDayReport(DateTime datetime, decimal? type)
{
ControlResource.JudgeSYQ();
string isShowAlias = cache_q.GetValue_Parameter("WeiXin_IsShowAliasDownLoadButton");//是否显示微信号
string tableId = "tablist";
Table tab = new Table(tableId);
//Pager pager = new Pager() { page = 1, rows = int.MaxValue };
tab.AddHeadCol("", "", "");
tab.AddHeadCol("", "", "");
tab.AddHeadCol("dayTime", "", "员工");
tab.AddHeadCol("alias", "", "工作微信号");
if (Common.Utility.GetSettingByKey("TagFrom") != null && Common.Utility.GetSettingByKey("TagFrom") == "true")
{
tab.AddHeadCol("resourceCount", "", "资源数");
tab.AddHeadCol("distCount", "", "去重资源数");
tab.AddHeadCol("resourceCount", "", "好友资源数");
}
else
{
tab.AddHeadCol("resourceCount", "", "推广资源数");
tab.AddHeadCol("resourceCount2", "", "非推广资源数");
tab.AddHeadCol("rconcateCount", "", "好友资源数");
}
tab.AddHeadRow();
ViewBag.gridTable = tab.GetTable();
ViewBag.IsShowAlias = !string.IsNullOrEmpty(isShowAlias) ? isShowAlias : "0";//等于空就不显示
return View();
}
public JsonResult UserDayReportHtml(string columns, DateTime datetime, decimal? type)
{
ControlResource.JudgeSYQ();
Table table = new Table(columns, true);
try
{
DateTime eTime = datetime.AddDays(1);
if (Common.Utility.GetSettingByKey("TagFrom") != null && Common.Utility.GetSettingByKey("TagFrom") == "true")
{
string style1 = "text-align:left;padding-left:10px;";
string style2 = "text-align:left;padding-left:30px;";
string style3 = "text-align:left;padding-left:10px;color:red;font-weight:bold";
var dt = rcontactBL.RcontactByTag(datetime, eTime);
var list = dt.ToList<TagFrom>();
var tagList =
from q in list
group q by new { q.Tag, q.TagName } into g
select new { g.Key.Tag, g.Key.TagName, ResourceCount = g.Sum(p => p.ResourceCount), RcontactCount = g.Sum(p => p.RconcateCount), DistCount = g.Sum(p => p.DistCount) };
foreach (var tag in tagList)
{
table.AddCol(style1, "", "<span class='expand-activity txt-expand' title='" + tag.TagName + "'> </span>");
table.AddCol(style1, "", tag.TagName);
table.AddCol("");
table.AddCol("");
table.AddCol(style1, "", tag.ResourceCount);
table.AddCol(style1, "", rcontactBL.ResourceByTagDistinctCount(datetime, tag.Tag == "未知" ? "" : tag.Tag));
table.AddCol(style1, "", tag.RcontactCount);
table.AddRow();
var groupList =
from q in list
where q.Tag == tag.Tag
group q by new { q.Name, q.Groupid } into g
select new { GroupName = g.Key.Name, GroupId = g.Key.Groupid, ResourceCount = g.Sum(p => p.ResourceCount), RcontactCount = g.Sum(p => p.RconcateCount), DistCount = g.Sum(p => p.DistCount) };
foreach (var item in groupList)
{
table.AddCol(style2, "", "<span class='expand-activity txt-expand' title='" + tag.Tag + item.GroupName + "'> </span>");
table.AddCol(style2, "", item.GroupName);
table.AddCol("");
table.AddCol("");
table.AddCol(style2, "", item.ResourceCount);
table.AddCol(style2, "", rcontactBL.ResourceByNameDistinctCount(datetime, tag.Tag, item.GroupId));
table.AddCol(style2, "", item.RcontactCount);
table.AddRow("style='display:none' typeName='" + tag.TagName + "'");
var userList =
from q in list
where q.Tag == tag.Tag && q.Name == item.GroupName
group q by new { q.InneruserId, q.Alias, q.JobUserName } into g
select new { g.Key.InneruserId, g.Key.Alias, g.Key.JobUserName, ResourceCount = g.Sum(p => p.ResourceCount), RcontactCount = g.Sum(p => p.RconcateCount), DistCount = g.Sum(p => p.DistCount) };
foreach (var user in userList)
{
var linkUrl = string.Format("<a href=\"javascript:parent.ChildAddTab('{0}', '{1}', '')\">{2}</a>", "微信员工日资源详细", "/WeiXin/WXRcontact/BeiJiaResource?jobusername=" + user.JobUserName + "&day=" + datetime.ToString("yyyy-MM-dd"), user.ResourceCount);
table.AddCol("");
table.AddCol("");
table.AddCol(style2, "", InnerUserHelper.Instance.GetEidAndTrueName(user.InneruserId));
table.AddCol(style2, "", user.Alias);
table.AddCol(style2, "", linkUrl);
table.AddCol(style2, "", user.DistCount);
table.AddCol(style2, "", user.RcontactCount);
table.AddRow("style='display:none' typeName='" + tag.Tag + item.GroupName + "'");
}
}
}
}
else
{
var dt = rcontactBL.RcontactByUserAndDay(datetime, eTime, type);
foreach (DataRow item in dt.Rows)
{
decimal inneruserId = Convert.ToDecimal(item["inneruserid"].ToString());
var linkUrl = string.Format("<a href=\"javascript:parent.ChildAddTab('{0}', '{1}', '')\">{2}</a>", "微信员工日资源详细", "/WeiXin/WXRcontact/BeiJiaResource?jobusername=" + item["jobusername"] + "&day=" + datetime.ToString("yyyy-MM-dd") + "&istuiguang=1", item["resourceCount"]);
var linkUrl2 = string.Format("<a href=\"javascript:parent.ChildAddTab('{0}', '{1}', '')\">{2}</a>", "微信员工日资源详细", "/WeiXin/WXRcontact/BeiJiaResource?jobusername=" + item["jobusername"] + "&day=" + datetime.ToString("yyyy-MM-dd") + "&istuiguang=0", item["resourceCount2"]);
table.AddCol("");
table.AddCol("");
table.AddCol(InnerUserHelper.Instance.GetEidAndTrueName(inneruserId));
table.AddCol(item["alias"]);
table.AddCol(linkUrl);
table.AddCol(linkUrl2);
table.AddCol(item["rconcateCount"]);
table.AddRow();
}
}
}
catch (Exception ex)
{
LogHelper.Error("WXRcontactController:" + ex.Message + ex.StackTrace);
return JsonHandler.ManageMessage(ex.Message, false);
}
var json = new { rowsList = table.GetRows() };
return Json(json, JsonRequestBehavior.AllowGet);
}
#endregion
#region
[HttpGet]
[AuthorizeRedirect(InitRights.CONST_员工明显日报表)]
public ViewResult WebChatDayReport(DateTime datetime)
{
string tableId = "tablist";
Table tab = new Table(tableId);
//Pager pager = new Pager() { page = 1, rows = int.MaxValue };
tab.AddHeadCol("eid", "", "员工");
tab.AddHeadCol("alias", "", "工作微信号");
tab.AddHeadCol("resourceCount", "", "资源数");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetTable();
return View();
}
public JsonResult WebChatDayReportHtml(string columns, DateTime datetime, decimal? type)
{
ControlResource.JudgeSYQ();
Table table = new Table(columns, true);
try
{
DateTime eTime = datetime.AddDays(1);
var ds = rcontactBL.GetWebChatResourceList(datetime, eTime, type);
if (ds != null && ds.Tables[0] != null)
{
var dt = ds.Tables[0];
foreach (DataRow item in dt.Rows)
{
decimal inneruserId = Convert.ToDecimal(item["inneruserid"].ToString());
table.AddCol(InnerUserHelper.Instance.GetEidAndTrueName(inneruserId));
table.AddCol(item["alias"]);
var linkUrl = string.Format("<a href=\"javascript:parent.ChildAddTab('{0}', '{1}', '')\">{2}</a>", "微信助手日资源详细", "/WeiXin/WXRcontact/WebChatResource?jobusername=" + item["jobusername"] + "&day=" + datetime.ToString("yyyy-MM-dd"), item["num"]);
table.AddCol(linkUrl);
table.AddRow();
}
}
}
catch (Exception ex)
{
LogHelper.Error("WXRcontactController:" + ex.Message + ex.StackTrace);
return JsonHandler.ManageMessage(ex.Message, false);
}
var json = new { rowsList = table.GetRows() };
return Json(json, JsonRequestBehavior.AllowGet);
}
[HttpGet]
[AuthorizeRedirect(InitRights.CONST_员工明显日报表)]
public ActionResult WebChatResource(string day, string jobusername)
{
string tableId = "tablist";
Table tab = new Table(tableId);
tab.AddHeadCol("alias", "", "工作微信");
tab.AddHeadCol("username", "", "微信用户名");
tab.AddHeadCol("nickname", "", "昵称");
tab.AddHeadCol("validatemsg", "", "打招呼用语");
tab.AddHeadCol("createtime", "", "添加时间");
//tab.AddHeadCol("type", "", "类型");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetTable();
ViewBag.day = day;
ViewBag.jobusername = jobusername;
return View();
}
[HttpPost]
[AuthorizeRedirect(InitRights.CONST_员工明显日报表)]
public JsonResult WebChatResourceHtml(string columns)
{
try
{
var day = Request["day"];
var jobusername = Request["jobusername"];
DateTime? time = null;
if (!string.IsNullOrEmpty(day))
{
DateTime t;
DateTime.TryParse(day, out t);
time = t;
}
Table table = new Table(columns, true);
if (time == null)
{
return JsonHandler.ManageMessage("日期不能为空", false);
}
DataSet ds = rcontactBL.GetWebChatResourceDetail(time, time.Value.AddDays(1), jobusername);
string isShowMobileOfContent = cache_q.GetValue_Parameter(Model.Enum.Parameter.Sys_IsShowMobileOfContent);
if (ds != null && ds.Tables[0] != null)
{
var dt = ds.Tables[0];
foreach (DataRow item in dt.Rows)
{
table.AddCol(item["alias"]);
table.AddCol(item["username"]);
if (!string.IsNullOrEmpty(isShowMobileOfContent) && isShowMobileOfContent == "1")
{
table.AddCol(item["nickname"]);
}
else
{
table.AddCol(Utility.ReplaceMobile(item["nickname"]));
}
table.AddCol(item["validatemsg"]);
table.AddCol(item["createtime"]);
table.AddRow();
}
}
var json = new { rowsList = table.GetRows() };
return Json(json, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
LogHelper.Error("BeiJiaResourceHtml:" + ex.Message + ex.StackTrace);
return JsonHandler.ManageMessage(ex.Message, false);
}
}
#endregion
#region
[HttpGet]
[AuthorizeRedirect(InitRights.CONST_员工明显日报表)]
public ActionResult BeiJiaResource(string day, string jobusername, string istuiguang)
{
ControlResource.JudgeSYQ();
string isShowAlias = cache_q.GetValue_Parameter("WeiXin_IsShowAlias");//是否显示微信号
string tableId = "tablist";
Table tab = new Table(tableId);
tab.AddHeadCol("JobUserName", "", "工作微信");
tab.AddHeadCol("username", "", "微信用户名");
if (!string.IsNullOrEmpty(isShowAlias) && isShowAlias == "1")
{
tab.AddHeadCol("ALIAS", "", "微信号");
}
tab.AddHeadCol("nickname", "", "昵称");
tab.AddHeadCol("conremark", "", "备注");
tab.AddHeadCol("createtime", "", "添加时间");
//tab.AddHeadCol("type", "", "类型");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetTable();
ViewBag.day = day;
ViewBag.jobusername = jobusername;
ViewBag.istuiguang = istuiguang;
return View();
}
public FileResult ResourceExport(int type, DateTime beginTime, DateTime endTime, decimal? inneruserid)
{
ControlResource.JudgeSYQ();
string name = "";
if (type == 0)
{
name = "被加资源";
}
else if (type == 1)
{
name = "主加资源";
}
else if (type == 2)
{
name = "好友资源";
}
string contentType = "application/ms-excel";
string downloadName = PageRequest.GetDlownLoadName(name + beginTime.ToString("yyyy-MM-dd") + ".xls");
//List<Model.QueryMap.ActivitySourceExport> list = activityBiz_Q.GetListExport_Activity(ResTypeId, ActivityId, DateTime.Parse(stime), DateTime.Parse(etime)) as List<Model.QueryMap.ActivitySourceExport>;
DataSet daset = rcontactBL.ExportWeiXinResource(beginTime, endTime, inneruserid);
System.IO.Stream strem = ExcelHelper.ExportDataTableToExcel(daset.Tables[type], "资源列表");
return File(strem, contentType, downloadName);
}
[HttpPost]
[AuthorizeRedirect(InitRights.CONST_员工明显日报表)]
public JsonResult BeiJiaResourceHtml(string columns)
{
ControlResource.JudgeSYQ();
try
{
string isShowAlias = cache_q.GetValue_Parameter("WeiXin_IsShowAlias");//是否显示微信号
var day = Request["day"];
var jobusername = Request["jobusername"];
var istuiguang = Request["istuiguang"];
DateTime? time = null;
if (!string.IsNullOrEmpty(day))
{
DateTime t;
DateTime.TryParse(day, out t);
time = t;
}
Table table = new Table(columns, true);
//LogHelper.Info(time.ToString());
var workAccount = wx_Workaccount_BL.Get(m => m.USERNAME == jobusername);
string[] jobWorks = new string[] { jobusername };
var workList = new List<WX_WORKACCOUNT>();
if (workAccount != null)
{
workList = wx_Workaccount_BL.GetList(m => m.INNERUSERID == workAccount.INNERUSERID).ToList();
if (workList != null)
{
jobWorks = workList.Select(m => m.USERNAME).ToArray();
}
}
decimal? isTuiGuang = null;
if (!string.IsNullOrEmpty(istuiguang))
{
decimal tg = 0;
decimal.TryParse(istuiguang, out tg);
isTuiGuang = tg;
}
string isShowMobileOfContent = cache_q.GetValue_Parameter(Model.Enum.Parameter.Sys_IsShowMobileOfContent);
var list = _friendsrelation.GetBeiJiaResources(time, jobWorks, isTuiGuang);
foreach (var wxBeiJiaResource in list)
{
WX_WORKACCOUNT model = null;
if (workList != null)
{
model = workList.Where(m => m.USERNAME == wxBeiJiaResource.JobUserName).FirstOrDefault();
}
table.AddCol(model != null ? model.ALIAS : "");
table.AddCol(wxBeiJiaResource.UserName);
if (!string.IsNullOrEmpty(isShowAlias) && isShowAlias == "1")
{
table.AddCol(wxBeiJiaResource.Alias);
}
if (!string.IsNullOrEmpty(isShowMobileOfContent) && isShowMobileOfContent == "1")
{
table.AddCol(wxBeiJiaResource.NickName);
table.AddCol(wxBeiJiaResource.ConRemark);
}
else
{
table.AddCol(Utility.ReplaceMobile(wxBeiJiaResource.NickName));
table.AddCol(Utility.ReplaceMobile(wxBeiJiaResource.ConRemark));
}
table.AddCol(wxBeiJiaResource.CreateTime);
//if (wxBeiJiaResource.Type == 1)
// table.AddCol("被加没验证");
//else if (wxBeiJiaResource.Type == 2)
// table.AddCol("被加有验证");
table.AddRow();
}
var json = new { rowsList = table.GetRows() };
return Json(json, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
LogHelper.Error("BeiJiaResourceHtml:" + ex.Message + ex.StackTrace);
return JsonHandler.ManageMessage(ex.Message, false);
}
}
#endregion
/// <summary>
/// 添加资源数的resid
/// </summary>
/// <returns></returns>
public JsonResult AddRcontactResId(string username, string resid)
{
try
{
if (string.IsNullOrEmpty(username))
{
return JsonHandler.ManageMessage("请选择微信!", false);
}
if (string.IsNullOrEmpty(resid))
{
return JsonHandler.ManageMessage("参数错误!", false);
}
bool isSucced = rcontactBL.UpdateRcontactResId(ref errors, username, resid, UserId);
if (isSucced)
{
var host = Utility.GetSettingOrNullByKey("DataSyncApiUrl");
var url = host + "/api/DataSync";
var data = new { resid = resid, username = username, deptcode = companyCode };
var para = new SYNC_PUSH_DTO()
{
bidatatype = "Server_WxUserResid",
deptcode = companyCode,
jsontext = data.ToJson()
};
var rep = Utility.PostAjaxData(url, para.ToJson(), Encoding.UTF8);
var ret2 = Utility.JSONToObject<retMsg>(rep);
if (!ret2.result)
{
LogHelper.Info("同步到中心点异常:" + para.ToJson());
}
}
return JsonHandler.ManageMessage(errors, isSucced);
}
catch (Exception ex)
{
LogHelper.Error("BeiJiaResourceHtml:" + ex.ToString());
return JsonHandler.ManageMessage(ex.Message, false);
}
}
public class TagFrom
{
public decimal InneruserId { get; set; }
public string JobUserName { get; set; }
public string Alias { get; set; }
public string Tag { get; set; }
public string TagName { get; set; }
public decimal? ResourceCount { get; set; }
public decimal? RconcateCount { get; set; }
public string Name { get; set; }
public decimal? DistCount { get; set; }
public string nTag { get; set; }
public decimal? Groupid { get; set; }
}
}
}