| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 |
- using CallCenter.Utility;
- using CallCenterApi.DB;
- using CallCenterApi.Interface.Controllers.Base;
- 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
- {
- //[Authority]
- public class DepartmentController : BaseController
- {
- private BLL.T_Sys_Department departmentBLL = new BLL.T_Sys_Department();
- /// <summary>
- /// 获取部门列表 - Pc和微信(不用身份验证)
- /// </summary>
- /// <returns></returns>
- public ActionResult GetAllList()
- {
- //if (Request.IsAuthenticated)
- //{
- DataTable dt = new DataTable();
- dt = new BLL.T_Sys_Department().GetList(" F_State=1 ").Tables[0];
- return Success("加载成功", dt);
- //}
- //return NoToken("未知错误,请重新登录");
- }
- /// <summary>
- /// 获取大区分公司
- /// </summary>
- /// <returns></returns>
- public ActionResult GetLinkList(int F_Layer)
- {
- DataTable dt = new DataTable();
- dt = new BLL.T_Sys_Department().GetList(" F_State=1 and F_Layer=+" + F_Layer).Tables[0];
- List<Model.TreeModel> modelList = BindTree(dt, "0");
- if (modelList != null)
- {
- if (modelList.Count > 0)
- return Success("加载成功", modelList);
- }
- return Error("加载失败");
- }
- /// <summary>
- /// 获取大区分公司
- /// </summary>
- /// <returns></returns>
- public ActionResult GetList(int F_Layer, string F_DeptName="" )
- {
- DataTable dt = new DataTable();
- if (F_DeptName!="")
- {
- Model.T_Sys_Department dModel = departmentBLL.GetModel(F_DeptName);
- if (dModel!=null )
- {
- dt = new BLL.T_Sys_Department().GetList(" F_State=1 and F_Layer=" + F_Layer+ " and F_ParentId=" + dModel.F_DeptId ).Tables[0];
- }
- else
- {
- return Error("加载失败");
- }
-
- }
- else
- {
- dt = new BLL.T_Sys_Department().GetList(" F_State=1 and F_Layer=" + F_Layer ).Tables[0];
- }
- if (dt != null)
- {
- if (dt.Rows .Count > 0)
- return Success("加载成功", dt);
- }
- return Error("加载失败");
- }
- /// <summary>
- /// 获取部门
- /// </summary>
- /// <param name="deptId"></param>
- /// <returns></returns>
- public ActionResult GetDept(int deptId = 0)
- {
- if (Request.IsAuthenticated)
- {
- BLL.T_Sys_Department dBLL = new BLL.T_Sys_Department();
- Model.T_Sys_Department dModel = dBLL.GetModel(deptId);
- if (dModel != null)
- return Success("获取部门信息成功", new
- {
- deptid = dModel.F_DeptId,
- depname = dModel.F_DeptName,
- sort = dModel.F_Sort,
- parentid = dModel.F_ParentId,
- parentname = dModel.F_ParentName,
- remark = dModel.F_Remark,
- layerType=dModel .F_Layer,
- //部门类型0不区分1大区2分公司
- // headerid = dModel.F_Header, //部门权限范围:9全部,1区域,2项目,3期
- // TypeId = dModel.F_Type, //部门操作权限:1接待部,2办理人员,3区域客服,4监管
- });
- return Error("获取部门信息失败");
- }
- return NoToken("未知错误,请重新登录");
- }
- /// <summary>
- /// 添加部门
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult AddDept(DepartmentInput input)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- string pcode = "";
- Model.T_Sys_Department dModel = new Model.T_Sys_Department();
- dModel.F_ParentId = input.PId;
- if (input.PId != 0)
- {
- Model.T_Sys_Department pdModel = departmentBLL.GetModel(input.PId);
- if (pdModel != null)
- {
- pcode = dModel.F_ParentCode = pdModel.F_DeptCode;
- }
- }
- dModel.F_Sort = input.Sort;
- dModel.F_DeptName = input.DeptName;
- if (!string.IsNullOrEmpty(input.Remark))
- dModel.F_Remark = input.Remark;
- dModel.F_State = 1;
- dModel.F_Layer = input.F_Layer;//部门类型0不区分1大区2分公司
- // dModel.F_Header = input.Headerid; //部门权限范围:9全部,1区域,2项目,3期
- // dModel.F_Type = input.TypeId; //部门操作权限:1接待部,2办理人员,3区域客服,4监管
- int id = departmentBLL.Add(dModel);
- if (id > 0)
- {
- departmentBLL.UpdateDeptCode(pcode + id.ToString() + "|", id);
- res = Success("添加成功");
- }
- else
- res = Success("添加失败");
- }
- return res;
- }
- /// <summary>
- /// 编辑部门
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult EditDept(DepartmentInput input)
- {
- if (Request.IsAuthenticated)
- {
- if (input.DeptId <= 0)
- return Error("请选择要编辑的部门");
- BLL.T_Sys_Department dBLL = new BLL.T_Sys_Department();
- Model.T_Sys_Department dModel = dBLL.GetModel(input.DeptId);
- if (dModel == null)
- return Error("获取信息失败");
- dModel.F_ParentId = input.PId;
- if (input.PId != 0)
- {
- Model.T_Sys_Department pdModel = departmentBLL.GetModel(input.PId);
- if (pdModel != null)
- {
- dModel.F_ParentCode = pdModel.F_DeptCode;
- dModel.F_DeptCode = pdModel.F_DeptCode + input.DeptId.ToString() + "|";
- }
- }
- dModel.F_Sort = input.Sort;
- dModel.F_DeptName = input.DeptName;
- if (!string.IsNullOrEmpty(input.Remark))
- dModel.F_Remark = input.Remark;
- dModel.F_Layer = input.F_Layer;//部门类型0不区分1大区2分公司
- // dModel.F_Header = input.Headerid; //部门权限范围:9全部,1区域,2项目,3期
- // dModel.F_Type = input.TypeId; //部门操作权限:1接待部,2办理人员,3区域客服,4监管
- if (dBLL.Update(dModel))
- return Success("编辑成功");
- return Error("编辑失败");
- }
- return NoToken("未知错误,请重新登录");
- }
- /// <summary>
- /// 删除部门
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- public ActionResult DelDept(string[] ids)
- {
- if (Request.IsAuthenticated)
- {
- if (ids == null || ids.Length <= 0)
- return Error("请选择要删除的部门");
- var idStr = string.Join(",", ids);
- if (string.IsNullOrEmpty(idStr.Trim()))
- return Error("请选择要删除的部门");
- if (departmentBLL.DeleteList(idStr))
- return Success("删除成功");
- return Error("删除失败");
- }
- return NoToken("未知错误,请重新登录");
- }
- /// <summary>
- /// 获取部门列表
- /// </summary>
- /// <returns></returns>
- public ActionResult GetDeptList(int pId = 0)
- {
- //if (Request.IsAuthenticated)
- //{
- DataTable dt = new DataTable();
- dt = new BLL.T_Sys_Department().GetList(" F_State=1 and F_ParentId=" + pId).Tables[0];
- List<Model.TreeModel> modelList = BindTree(dt, "0");
- if (modelList != null)
- {
- if (modelList.Count > 0)
- return Success("加载成功", modelList);
- }
- return Error("加载失败");
- //}
- //return NoToken("未知错误,请重新登录");
- }
- /// <summary>
- /// 获取部门列表 by 处理人员
- /// </summary>
- /// <returns></returns>
- public ActionResult GetDeptListbyReceive(int pId = 0)
- {
- DataTable dt = new DataTable();
- string sqlstr = "SELECT F_ParentId FROM dbo.T_Sys_Department WHERE F_Type = 2"; //一级
- //string sqlstr2 = "SELECT F_DeptId FROM dbo.T_Sys_Department WHERE F_Type = 2"; //二级
- string sqlstr3 = "SELECT F_ParentId FROM dbo.T_Sys_Department WHERE F_Type = 3"; //一级 区域客服(分类显示成其他)
- //string sqlstr4 = "SELECT TOP 1 F_DeptId FROM dbo.T_Sys_Department WHERE F_Type = 3 ORDER BY F_Sort ASC"; //二级 区域客服(分类显示成其他)
- //dt = new BLL.T_Sys_Department().GetList($" F_State=1 and (F_ParentId=0 OR F_DeptId IN({sqlstr}) OR F_DeptId IN({sqlstr2}) OR F_DeptId IN({sqlstr3}) OR F_DeptId IN({sqlstr4}) )").Tables[0];
- dt = new BLL.T_Sys_Department().GetList($" F_State=1 and (F_ParentId=0 OR F_DeptId IN({sqlstr}) OR F_DeptId IN({sqlstr3}) )").Tables[0];
- List<DepartmentTreeList> list = new List<DepartmentTreeList>();
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- var model = new DepartmentTreeList();
- model.id = Convert.ToInt32(dt.Rows[i]["F_DeptId"]); //当前功能ID
- model.ParentId = Convert.ToInt32(dt.Rows[i]["F_ParentId"]);
- model.text = dt.Rows[i]["F_DeptName"].ToString();
- model.sort = Convert.ToInt32(dt.Rows[i]["F_Sort"].ToString());
- list.Add(model);
- }
- return Success("加载成功", list);
- }
- /// <summary>
- /// tree 树形部门
- /// </summary>
- /// <param name="tab"></param>
- /// <param name="parentid"></param>
- /// <returns></returns>
- private List<Model.TreeModel> BindTree(DataTable tab, string parentid)
- {
- DataTable tab2 = new DataTable();
- if (tab != null && tab.Rows.Count > 0)
- {
- List<Model.T_Sys_Department> categorylist = new BLL.T_Sys_Department().DataTableToList(tab);
- List<Model.TreeModel> modelList = new List<Model.TreeModel>(categorylist.Count);
- for (int i = 0; i < categorylist.Count; i++)
- {
- Model.TreeModel model = new Model.TreeModel();
- string currentID = categorylist[i].F_DeptId.ToString();//当前功能ID
- model.id = currentID;
- model.code = categorylist[i].F_DeptCode;
- model.IconCls = "";//图标
- model.text = categorylist[i].F_DeptName;
- model.headerid = categorylist[i].F_Header ?? 0; //部门权限范围:9全部,1区域,2项目,3期
- tab2 = new BLL.T_Sys_Department().GetList("F_ParentId=" + currentID + " and F_State=1 ").Tables[0];
- if (tab2 != null && tab2.Rows.Count > 0)
- {
- model.children = BindTree(tab2, currentID);
- }
- modelList.Add(model);
- }
- return modelList;
- }
- else
- {
- return null;
- }
- }
- public class DepartmentTreeList
- {
- /// <summary>
- /// 文章ID
- /// </summary>
- public int id { get; set; }
- /// <summary>
- /// 父ID
- /// </summary>
- public int ParentId { get; set; }
- /// <summary>
- /// 分类名称
- /// </summary>
- public string text { get; set; }
- /// <summary>
- /// 排序
- /// </summary>
- public int sort { get; set; }
- }
- }
- }
|