ComplianceServer/oldcode/Core.Web/Controllers/WxTranUserController.cs

120 lines
4.5 KiB
C#

using Core.Web.App_Start;
using Core.Web.WebHelper;
using CRM.Core.BLL.Wx;
using CRM.Core.Common;
using CRM.Core.Common.Layui;
using CRM.Core.Model.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Core.Web.Controllers
{
public class WxTranUserController : BaseController
{
private readonly Wx_Tran_User_BL _wxTranUser;
public WxTranUserController()
{
_wxTranUser = new Wx_Tran_User_BL();
}
[AuthorizeRedirect(RightsConfig.CONST_成交客户列表, ToolBarConfig.CONST_NotButton, true)]
public ActionResult Index()
{
return View();
}
public JsonResult GetList(WxTranUserQueryDto query)
{
var total = _wxTranUser.GetTotal(query);
var list = _wxTranUser.GetList(query);
// 获取所有员工信息
var employeeBL = new Employee_BL();
var employees = employeeBL.GetList()
.ToDictionary(e => e.employee_id.ToString(), e => new { e.employee_name, e.status });
// 处理每个用户的服务人员信息
foreach(var item in list)
{
if(!string.IsNullOrEmpty(item.Eids))
{
var eidList = item.Eids.Split(';');
var nameList = new List<string>();
foreach(var eid in eidList)
{
if(employees.ContainsKey(eid))
{
var emp = employees[eid];
nameList.Add($"{eid}-{emp.employee_name}({(emp.status == 1 ? "" : "")})");
}
else
{
nameList.Add(eid);
}
}
item.Eids = string.Join(",", nameList);
}
}
var data = new LayuiData<WxTranUserDto>()
{
msg = "数据加载成功!",
count = total,
code = 0,
data = list
};
return Json(data, JsonRequestBehavior.AllowGet);
}
public ActionResult ServiceUserList(string eids)
{
var list = new List<WeworkExternalUserLogDto>();
try
{
// 获取所有员工信息
var employeeBL = new Employee_BL();
var employees = employeeBL.GetList()
.ToDictionary(e => e.employee_id.ToString(), e => new { e.employee_name, e.status });
var weworkLog = new WeworkExternalUserLog_BL();
list = weworkLog.GetWeworkExternalUserList(eids)
.OrderByDescending(x => x.act_time)
.Select(x =>
{
// 解析 act_data
WeworkExternalUserActData actData = null;
try
{
if (!string.IsNullOrEmpty(x.act_data))
{
actData = Newtonsoft.Json.JsonConvert.DeserializeObject<WeworkExternalUserActData>(x.act_data);
// 如果找到对应的员工信息,更新员工姓名和状态
if (actData != null && !string.IsNullOrEmpty(actData.employee_id) && employees.ContainsKey(actData.employee_id))
{
var employee = employees[actData.employee_id];
actData.employee_name = employee.employee_name;
actData.status = employee.status;
}
}
}
catch (Exception ex)
{
LogHelper.Error(string.Format("解析act_data失败: {0}, 错误: {1}", x.act_data, ex.Message));
}
x.act_data = actData != null ? Newtonsoft.Json.JsonConvert.SerializeObject(actData) : x.act_data;
return x;
})
.ToList();
}
catch (Exception ex)
{
LogHelper.Error(ex);
}
return View(list);
}
}
}