| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546 |
- using CallCenter.Utility;
- using CallCenterApi.Common;
- using CallCenterApi.DB;
- using CallCenterApi.Interface.Controllers.Base;
- using CallCenterApi.Interface.Models.Filter;
- using CallCenterApi.Interface.Models.Input;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- namespace CallCenterApi.Interface.Controllers
- {
- public class UserAccountController : BaseController
- {
- private BLL.T_Sys_UserAccount sysUserAccountBll = new BLL.T_Sys_UserAccount();
- private BLL.T_Sys_Department departmentBLL = new BLL.T_Sys_Department();
- private BLL.T_Sys_DictionaryValue dicValueBLL = new BLL.T_Sys_DictionaryValue();
- //[Authority]
- //用户列表
- public ActionResult GetList(FilterUserAccount filter)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- DataTable dt = new DataTable();
- string sql = " ";
- if (filter.dptid > 0)
- {
- Model.T_Sys_Department deptModel = departmentBLL.GetModel(filter.dptid);
- if (deptModel != null)
- {
- sql += " and F_DeptId in ( select F_DeptId from T_Sys_Department where F_DeptCode like '" + deptModel.F_DeptCode + "%') ";
- }
- }
- if (!string.IsNullOrWhiteSpace(filter.Key))
- {
- sql = "";
- string str = string.Format(" and (F_UserCode like '%{0}%' or F_UserName like '%{1}%')", filter.Key, filter.Key);
- sql += str;
- }
- if (!string.IsNullOrWhiteSpace(filter.sgid))
- {
- sql += " and F_SeartGroupID in (" + filter.sgid + ")";
- }
- int recordCount = 0;
- dt = BLL.PagerBLL.GetListPager(
- "T_Sys_UserAccount",
- "F_UserId",
- "*",
- sql,
- "ORDER BY F_UserId desc",
- filter.PageSize,
- filter.PageIndex,
- true,
- out recordCount);
- List<Model.UserAccount> modelList = new BLL.UserAccount().DataTableToList(dt);
- var obj = new
- {
- rows = modelList.Select(x => new
- {
- F_UserId = x.F_UserId,
- F_UserCode = x.F_UserCode,
- F_ExtensionNumber = x.F_ExtensionNumber,
- F_UserName = x.F_UserName,
- F_GroupName = x.F_GroupName,
- F_DeptId = x.F_DeptId,
- F_RoleId = x.F_RoleId,
- F_GroupId = x.F_GroupId,
- F_SeatFlag = x.F_SeatFlag,
- F_SeatRight = x.F_SeatRight,
- F_SeatLevel = x.F_SeatLevel,
- F_SexFlag = x.F_SexFlag,
- F_RemindFlag = x.F_RemindFlag,
- F_Remark = x.F_Remark,
- F_Telephone = x.F_Telephone,
- F_Mobile = x.F_Mobile,
- F_HomePhone = x.F_HomePhone,
- F_Birthday = x.F_Birthday,
- F_CreateOn = x.F_CreateOn,
- F_CancelOn = x.F_CancelOn,
- F_DeleteFlag = x.F_DeleteFlag,
- F_APPOnFlag = x.F_APPOnFlag,
- F_LastActiveTime = x.F_LastActiveTime,
- F_See = x.F_See,
- F_HJType = x.F_HJType,
- F_PId = x.F_PId,
- F_TmId = x.F_TmId,
- F_RoleName = x.F_RoleName,
- F_DeptName = x.F_DeptName,
- F_WorkNumber = x.F_WorkNumber,
- //F_WXNo=x.F_WXNo,
- F_SeatGroup = x.F_SeartGroup
- }),
- total = recordCount
- };
- res = Content(obj.ToJson());
- dt.Clear();
- dt.Dispose();
- }
- return res;
- }
- //[Authority]
- //获取用户信息
- public ActionResult GetUser(int userId = 0, string userCode = "")
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- string sql = "";
- if (userId > 0)
- {
- sql += " and F_UserId=" + userId;
- }
- if (!string.IsNullOrWhiteSpace(userCode))
- {
- sql += " and F_UserCode=" + userCode;
- }
- if (string.IsNullOrWhiteSpace(sql))
- return Error("获取失败");
- Model.T_Sys_UserAccount userModel = sysUserAccountBll.GetModelList(" 1=1 " + sql).FirstOrDefault();
- if (userModel == null) return Error("获取失败");
- var depModel = departmentBLL.GetModel(userModel.F_DeptId);
- var zxzModel = dicValueBLL.GetModel(userModel.F_GroupId ?? 0);
- res = Success("获取成功", new
- {
- F_UserId = userModel.F_UserId,
- F_UserCode = userModel.F_UserCode,
- F_ExtensionNumber = userModel.F_ExtensionNumber,
- F_UserName = userModel.F_UserName,
- F_DeptId = userModel.F_DeptId,
- F_RoleId = userModel.F_RoleId,
- F_GroupId = userModel.F_GroupId,
- F_SeatFlag = userModel.F_SeatFlag,
- F_SeatRight = userModel.F_SeatRight,
- F_SeatLevel = userModel.F_SeatLevel,
- F_SexFlag = userModel.F_SexFlag,
- F_RemindFlag = userModel.F_RemindFlag,
- F_Remark = userModel.F_Remark,
- F_Telephone = userModel.F_Telephone,
- F_Mobile = userModel.F_Mobile,
- F_HomePhone = userModel.F_HomePhone,
- F_Birthday = (userModel.F_Birthday!=null? userModel.F_Birthday.Value.ToString("yyyy-MM-dd"):""),
- F_CreateOn = userModel.F_CreateOn,
- F_CancelOn = userModel.F_CancelOn,
- F_DeleteFlag = userModel.F_DeleteFlag,
- F_APPOnFlag = userModel.F_APPOnFlag,
- F_LastActiveTime = userModel.F_LastActiveTime,
- F_See = userModel.F_See,
- F_HJType = userModel.F_HJType ?? 0,
- F_PId = userModel.F_PId,
- F_TmId = userModel.F_TmId,
- F_WorkNumber = userModel.F_WorkNumber,
- //F_WXNo = userModel.F_WXNo,
- F_SeatGroup=userModel.F_SeartGroup,
- zxzname = zxzModel?.F_Name ?? "",
- depname = depModel?.F_DeptName ?? ""
- });
- }
- return res;
- }
- //[Authority]
- //添加用户信息
- public ActionResult AddUsers(UserAccountInput input)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- Model.T_Sys_UserAccount userAccountModel = new Model.T_Sys_UserAccount();
- if (input.Usercode != null)
- {
- userAccountModel.F_UserCode = input.Usercode.Trim();
- userAccountModel.F_WorkNumber = input.Usercode.Trim();
- }
- if (input.Username != null)
- userAccountModel.F_UserName = input.Username.Trim();
- if (input.Password != null)
- userAccountModel.F_Password = input.Password.Trim();
- if (input.Extno != null)
- userAccountModel.F_ExtensionNumber = input.Extno.Trim();
- if (input.DeptId != 0)
- userAccountModel.F_DeptId = input.DeptId;
- if (input.RoleId != 0)
- userAccountModel.F_RoleId = input.RoleId;
- //if (input.GroupId != 0)
- // userAccountModel.F_GroupId = input.GroupId;
-
- userAccountModel.F_SeatFlag = input.IsSeat;
- if (input.SearRight != null)
- userAccountModel.F_SeatRight = input.SearRight;
- if (input.Sex != null)
- userAccountModel.F_SexFlag = input.Sex;
- if (input.Remark != null)
- userAccountModel.F_Remark = input.Remark;
- if (input.Mobile != null)
- userAccountModel.F_Mobile = input.Mobile;
- if (input.Telphone != null)
- userAccountModel.F_Telephone = input.Telphone;
- if (input.Birth != null)
- userAccountModel.F_Birthday = input.Birth;
- userAccountModel.F_CreateOn = DateTime.Now;
- userAccountModel.F_DeleteFlag = 0;
- if (input.HjType != null)
- userAccountModel.F_HJType = input.HjType;
- //if (input.IsSeat)
- //{
- // userAccountModel.F_WXNo = input.WXNo.Trim();
- //}
- //if (input.SeartGroupID != 0)
- if (input.GroupId != 0)
- {
- userAccountModel.F_SeartGroupID = input.GroupId;
- Model.T_Sys_SeatGroup sm = new BLL.T_Sys_SeatGroup().GetModel(input.GroupId);
- if (sm != null)
- {
- userAccountModel.F_SeartGroup = sm.F_ZXZName;
- }
- }
- if (input.IsSeat)
- {
- SysConfigController sys = new SysConfigController();
- //话务人员限制权限判断
- if (sys.IsValidSeatPermission())
- {
- var model = sysUserAccountBll.GetModel(int.Parse(input.Usercode));
- if (model != null)
- return Error("当前员工工号存在,请更换!");
- if (sysUserAccountBll.Add(userAccountModel) > 0)
- res = Success("新增成功!");
- else
- res = Error("新增失败!");
- }
- else
- {
- res = Error("话务人员数量已超!");
- }
- }
- else {
- if (sysUserAccountBll.Add(userAccountModel) > 0)
- res = Success("新增成功!");
- else
- res = Error("新增失败!");
- }
- }
- return res;
- }
- // [Authority]
- //修改用户信息
- public ActionResult EditUsers(UserAccountInput input)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- Model.T_Sys_UserAccount userAccountModel = sysUserAccountBll.GetModelList(" F_UserId = " + input.UserId).FirstOrDefault();
- if (userAccountModel == null)
- return Error("获取用户失败");
- if (input.Usercode != null)
- {
- userAccountModel.F_UserCode = input.Usercode.Trim();
- userAccountModel.F_WorkNumber = input.Usercode;
- }
- if (input.Username != null)
- userAccountModel.F_UserName = input.Username.Trim();
- if(input.Password!=null)
- userAccountModel.F_Password = input.Password.Trim();
- if (input.Extno != null)
- userAccountModel.F_ExtensionNumber = input.Extno.Trim();
- //if (input.WXNo != null)
- // userAccountModel.F_WXNo = input.WXNo.Trim();
- if (input.DeptId != 0)
- userAccountModel.F_DeptId = input.DeptId;
- if (input.RoleId != 0)
- userAccountModel.F_RoleId = input.RoleId;
- //if (input.GroupId != 0)
- // userAccountModel.F_GroupId = input.GroupId;
- userAccountModel.F_SeatFlag = input.IsSeat;
- if (input.SearRight != null)
- userAccountModel.F_SeatRight = input.SearRight;
- if (input.Sex != null)
- userAccountModel.F_SexFlag = input.Sex;
- if (input.Remark != null)
- userAccountModel.F_Remark = input.Remark;
- if (input.Mobile != null)
- userAccountModel.F_Mobile = input.Mobile;
- if (input.Telphone != null)
- userAccountModel.F_Telephone = input.Telphone;
- if (input.Birth != null)
- userAccountModel.F_Birthday = input.Birth;
- //userAccountModel.F_CreateOn = DateTime.Now;
- //if (input.SeartGroupID != 0)
- if (input.GroupId != 0)
- {
- userAccountModel.F_SeartGroupID = input.GroupId;
- Model.T_Sys_SeatGroup sm = new BLL.T_Sys_SeatGroup().GetModel(input.GroupId);
- if (sm != null)
- {
- userAccountModel.F_SeartGroup = sm.F_ZXZName;
- }
- }
- userAccountModel.F_DeleteFlag = 0;
- if (input.HjType != null)
- userAccountModel.F_HJType = input.HjType;
- if (input.IsSeat)
- {
- SysConfigController sys = new SysConfigController();
- //话务人员限制权限判断
- if (sys.IsValidSeatPermission())
- {
- if (sysUserAccountBll.Update(userAccountModel))
- res = Success("编辑成功!");
- else
- res = Error("编辑失败!");
- }
- else
- {
- res = Error("话务人员数量已超!");
- }
- }
- else
- {
- if (sysUserAccountBll.Update(userAccountModel))
- res = Success("编辑成功!");
- else
- res = Error("编辑失败!");
- }
- }
- return res;
- }
- //[Authority]
- //删除/禁用/启用 用户
- [Authority]
- public ActionResult DelUsers(string[] ids, int state = 0)
- {
- //ActionResult res = NoToken("未知错误,请重新登录");
- //if (Request.IsAuthenticated)
- //{
- if (ids == null || ids.Length <= 0)
- return Error("请选择用户");
- var idStr = string.Join(",", ids);
- if (string.IsNullOrEmpty(idStr))
- return Error("请选择用户");
- SysConfigController sys = new SysConfigController();
- if (state == 0)
- {
- //话务人员限制权限判断
- if (sys.IsValidSeatPermission())
- {
- if (sysUserAccountBll.DeleteList(idStr, state))
- return Success("设置成功");
- else
- return Error("设置失败");
- }
- return Error("话务人员数量已超!");
- }
- if (sysUserAccountBll.DeleteList(idStr, state))
- return Success("设置成功");
- else
- return Error("设置失败");
- //}
- //return res;
- }
- //[Authority]
- //删除用户
- public ActionResult DeleteUsers(string[] ids)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- if (ids == null || ids.Length <= 0)
- return Error("请选择用户");
- var idStr = string.Join(",", ids);
- if (string.IsNullOrEmpty(idStr))
- return Error("请选择用户");
- if (sysUserAccountBll.DeleteList(idStr))
- res = Success("删除成功");
- else
- res = Error("删除失败");
- }
- return res;
- }
- //获取坐席列表
- public ActionResult GetSeatList()
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- string sql = " f_seatflag=1 ";
- int roleid = CurrentUser.UserData.F_RoleId;
- int deptid = CurrentUser.UserData.F_DeptId;
- if (roleid != 0)
- {
- if (roleid != 17)
- {
- if (deptid != 0)
- sql += " and F_DeptId=" + deptid;
- }
- }
- List<Model.T_Sys_UserAccount> userSeartList = sysUserAccountBll.GetModelList(sql + " order by f_userid desc ");
- if (userSeartList.Count > 0)
- res = Success("列表加载成功", userSeartList);
- else
- res = Error("列表加载失败");
- }
- return res;
- }
- //根据部门获取用户
- public ActionResult GetDeptUserList(int deptid = 0)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- List<Model.T_Sys_UserAccount> DeptUserList = sysUserAccountBll.GetModelList("F_DeptId='" + deptid + "' order by f_userid desc ");
- res = Success("列表加载成功", DeptUserList);
- }
- return res;
- }
- //获取当前用户信息
- public ActionResult GetNowUser()
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- Model.T_Sys_UserAccount userModel = sysUserAccountBll.GetModel(CurrentUser.UserData.F_UserId);
- if (userModel == null)
- return Error("获取失败");
- Model.T_Sys_RoleInfo roleModel = new BLL.T_Sys_RoleInfo().GetModel(userModel.F_RoleId);
- var obj = new
- {
- user = userModel,
- role = roleModel
- };
- res = Success("获取成功", obj);
- }
- return res;
- }
- // [Authority]
- /// <summary>
- /// 重置密码
- /// </summary>
- /// <param name="usercode"></param>
- /// <param name="pwd"></param>
- /// <returns></returns>
- public ActionResult ResetPwd(string usercode = "", string pwd = "")
- {
- var res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- if (string.IsNullOrWhiteSpace(pwd))
- return Error("请输入密码");
- var model = sysUserAccountBll.GetModel(usercode);
- if (model == null) return Error("此用户不存在");
- model.F_Password = pwd;
- if (sysUserAccountBll.Update(model))
- res = Success("重置密码成功");
- else
- res = Error("重置密码失败");
- }
- return res;
- }
- public ActionResult UpdatePwd(string usercode = "", string pwd = "", string oldPwd = "", string mobile = "")
- {
- var res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- if (string.IsNullOrWhiteSpace(pwd))
- return Error("请输入密码");
- if (string.IsNullOrWhiteSpace(usercode))
- return Error("账号错误");
- var model = sysUserAccountBll.GetModel(int.Parse(usercode));
- if (model == null) return Error("此用户不存在");
- if (!model.F_Password.Equals(oldPwd)) return Error("原密码不正确");
- model.F_Password = pwd;
- if (!string.IsNullOrWhiteSpace(mobile))
- model.F_Mobile = mobile;
- if (sysUserAccountBll.Update(model))
- res = Success("重置密码成功");
- else
- res = Error("重置密码失败");
- }
- return res;
- }
- /// <summary>
- /// 批量修改坐席的坐席组ID
- /// </summary>
- /// <param name="userids"></param>
- /// <param name="sgid"></param>
- /// <returns></returns>
- public ActionResult UpdateSeatGroup(string[] userids, string sgid)
- {
- if (userids == null || userids.Length <= 0)
- return Error("请选择要修改的坐席");
- var idStr = string.Join(",", userids);
- if (string.IsNullOrEmpty(idStr.Trim()))
- return Error("请选择要修改的坐席");
- Model.T_Sys_SeatGroup sgModel = new BLL.T_Sys_SeatGroup().GetModel(int.Parse(sgid));
- string sgname = sgModel != null ? sgModel.F_ZXZName : "";
- var res=sysUserAccountBll.UpdateSeatGroup(idStr, sgid, sgname);
- if(res)
- {
- return Success("修改坐席组成功");
- }
- return Error("修改坐席组失败!");
- }
- //根据工号获取坐席组号
- //public ActionResult GetSeatGroup(string worknum)
- //{
- // ActionResult res = NoToken("未知错误,请重新登录");
- // if (Request.IsAuthenticated)
- // {
- // string strwhere = "";
- // if (worknum != "")
- // {
- // strwhere = " F_WorkNumber='" + worknum + "'";
- // }
- // string setgroup = sysUserAccountBll.GetGroup(strwhere);
- // res = Success("坐席组号获取成功", setgroup);
- // }
- // return res;
- //}
- }
- }
|