using CallCenterApi.Common;
using CallCenterApi.Interface.Controllers.Base;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace CallCenterApi.Interface.Controllers.tel
{
    public class SeatMonitoringController : BaseController
    {
        /// <summary>
        /// 获取坐席列表
        /// </summary>
        /// <returns></returns>
        public ActionResult GetList(string username, string deptid = "")
        {
            ActionResult res = NoToken("未知错误，请重新登录");
            if (Request.IsAuthenticated)
            {
                DataTable dt = new DataTable();
                int deptId = CurrentUser.UserData.F_DeptId;
                int roleid = CurrentUser.UserData.F_RoleId;
                var deptCode = CurrentUser.UserData.F_UserCode;
                BLL.T_Sys_UserAccount bll = new BLL.T_Sys_UserAccount();
                string sql = "";
                if (username != null && username.Trim() != "")
                {
                    sql += " and F_UserName like '%" + username.Trim() + "%'";
                }

                //17=系统管理员,36=客服,37=组长,38=组员,39=业主,40=话务员,41=客服主管,43=分公司市场部主任,45=业务稽核,46=集团客户部,
                //47 =网络部,48=市场部经理,50=业务支撑中心,51=市场部,52=客户服务中心,53=总经理,54=副总经理,55=业务负责人,56=投诉处理员,57=基础业务主管,

                if (roleid != 0)
                {
                    if (roleid != 17)
                    {
                        //各分公司
                        if (deptCode.Replace("|0|1|", "").Length > 0)
                        {
                            sql += " and F_DeptId=" + deptId;
                        }
                    }
                }



                if (!string.IsNullOrWhiteSpace(deptid) && Convert.ToInt32(deptid) > 0)
                {
                    sql += " and F_DeptId=" + deptid;
                }

                dt = bll.GetList(" f_seatflag=1 and F_DeleteFlag=0 " + sql + " order by f_userid desc ").Tables[0];

                res = Success("坐席列表加载成功", dt);
            }
            return res;
        }
    }
}