| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560 |
- 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>
- /// 获取部门列表
- /// </summary>
- /// <returns></returns>
- public ActionResult GetAllList()
- {
- if (Request.IsAuthenticated)
- {
- //int userId = CurrentUser.UserData.F_UserId;
- //Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
- string where = "F_State='1'";
- //if (!string.IsNullOrEmpty(userModel.groupcode))
- //{
- // where += " and F_GroupCode = '" + userModel.groupcode + "'";
- //}
- DataTable dt = departmentBLL.GetList(0, where, " F_Sort asc").Tables[0];
- return Success("加载成功", dt);
- }
- return NoToken("未知错误,请重新登录");
- }
- /// <summary>
- /// 获取大区列表
- /// </summary>
- /// <returns></returns>
- public ActionResult GetDepartmentList(int pId = 1, int F_Layer = 1)
- {
- if (Request.IsAuthenticated)
- {
- DataTable dt = new DataTable();
- string where = " ";
- where = " isnull(F_DeptId,0) = '" + 1 + "' and F_State = 1" ;
- dt = new BLL.T_Sys_Department().GetList(0, where, " F_Sort asc").Tables[0];
- List<Model.TreeModel> modelList = BindAreaTree(dt, "0", 1);
- return Success("加载成功", modelList);
- }
- return NoToken("未知错误,请重新登录");
- }
- /// <summary>
- /// 获取大区列表
- /// </summary>
- /// <returns></returns>
- public ActionResult GetCusAreaList(string keyword, int pId = 1,int F_Layer=1)
- {
- if (Request.IsAuthenticated)
- {
- DataTable dt = new DataTable();
- string where = "isnull(F_ParentId, 1) = '" + pId + "' ";
- if (!string .IsNullOrEmpty (keyword))
- {
- where += "and F_DeptName like '%" + keyword.Trim () + "%'";
- }
- where += " and F_State = 1 and F_Layer = "+ F_Layer;
- dt = new BLL.T_Sys_Department().GetList(0, where, " F_Sort asc").Tables[0];
- return Success("加载成功", dt);
- }
- return NoToken("未知错误,请重新登录");
- }
- public ActionResult GetSubordinate()
- {
- if (Request.IsAuthenticated)
- {
- DataTable dt = new DataTable();
- string where = " ";
- //if (!string.IsNullOrEmpty(userModel.groupcode))
- //{
- // where += " and F_GroupCode = '" + userModel.groupcode + "'";
- //}
- int userId = CurrentUser.UserData.F_UserId;
- Model.T_Sys_UserAccount userModel = new BLL .T_Sys_UserAccount ().GetModel(userId);
- int pId = 1;
- if (userModel != null)
- pId = userModel.F_DeptId;
- if (pId == 1)
- where = "isnull(F_ParentId, 1) = '" + pId + "' and F_State = 1 and F_Layer = 1";
- else
- where = "F_DeptId=" + pId;
- dt = new BLL.T_Sys_Department().GetList(0, where, " F_Sort asc").Tables[0];
- List<Model.TreeModel> modelList = BindAreaTree(dt, "0");
- if (modelList != null)
- {
- if (modelList.Count > 0)
- return Success("加载成功", modelList);
- }
- return Error("加载失败");
- }
- return NoToken("未知错误,请重新登录");
- }
- private BLL.T_Sys_UserAccount userBLL = new BLL.T_Sys_UserAccount();
- private BLL.T_Sys_RoleInfo rolebll = new BLL.T_Sys_RoleInfo();
- public ActionResult GetAPPAreaList(int pId = 1)
- {
- if (Request.IsAuthenticated)
- {
- DataTable dt = new DataTable();
- string where = " ";
- if (pId == 1)
- where = "isnull(F_ParentId, 1) = '" + pId + "' and F_State = 1 and F_Layer = 1";
- else
- where = "F_DeptId=" + pId;
- dt = new BLL.T_Sys_Department().GetList(0, where, " F_Sort asc").Tables[0];
- List<Model.TreeModel> modelList = BindAreaTree(dt, "0");
- int userId = CurrentUser.UserData.F_UserId;
- Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);
- Model.T_Sys_RoleInfo ro = rolebll.GetModel(userModel.F_RoleId);
- if (ro.F_RoleCode == "CLZY")
- {
- Model.TreeModel model = new Model.TreeModel();
- string currentID = "0";//当前功能ID
- model.id = currentID;
- model.IconCls = "";//图标
- model.text = "双汇集团";
- List<Model.TreeModel> modelList1 = new List<Model.TreeModel>();
- Model.TreeModel model1 = new Model.TreeModel();
- model1.id = currentID;
- model1.IconCls = "";//图标
- model1.text = "管理区域";
- modelList1.Add(model1);
- model.children = modelList1;
- modelList.Add(model);
- }
- modelList.Sort((a, c) => a.id.CompareTo(c.id));
- if (modelList != null)
- {
- if (modelList.Count > 0)
- return Success("加载成功", modelList);
- }
- return Error("加载失败");
- }
- return NoToken("未知错误,请重新登录");
- }
- /// <summary>
- /// 获取大区列表
- /// </summary>
- /// <returns></returns>
- public ActionResult GetAreaList(int pId = 1)
- {
- if (Request.IsAuthenticated)
- {
-
- DataTable dt = new DataTable();
- string where = " ";
- if (pId == 1)
- where = "isnull(F_ParentId, 1) = '" + pId + "' and F_State = 1 and F_Layer = 1";
- else
- where = "F_DeptId="+ pId;
- dt = new BLL.T_Sys_Department().GetList(0, where, " F_Sort asc").Tables[0];
-
- List<Model.TreeModel> modelList = BindAreaTree(dt, "0");
- int userId = CurrentUser.UserData.F_UserId;
- Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);
- Model.T_Sys_RoleInfo ro = rolebll.GetModel(userModel.F_RoleId);
- if (ro.F_RoleCode == "CLZY")
- {
- Model.TreeModel model = new Model.TreeModel();
- string currentID = "0";//当前功能ID
- model.id = currentID;
- model.IconCls = "";//图标
- model.text = "双汇集团";
- List<Model.TreeModel> modelList1 = new List<Model.TreeModel>();
- Model.TreeModel model1 = new Model.TreeModel();
- model1.id = currentID;
- model1.IconCls = "";//图标
- model1.text = "管理区域";
- modelList1.Add(model1);
- model.children = modelList1;
- modelList.Add(model);
- }
- modelList.Sort((a, c) => a.id.CompareTo(c.id));
- if (modelList != null)
- {
- if (modelList.Count > 0)
- return Success("加载成功", modelList);
- }
- return Error("加载失败");
- }
- return NoToken("未知错误,请重新登录");
- }
- /// <summary>
- /// tree 树形部门
- /// </summary>
- /// <param name="tab"></param>
- /// <param name="parentid"></param>
- /// <returns></returns>
- private List<Model.TreeModel> BindAreaTree(DataTable tab, string parentid,int pid=0)
- {
- 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.IconCls = "";//图标
- model.text = categorylist[i].F_DeptName;
- if (pid==1)
- {
- tab2 = new BLL.T_Sys_Department().GetList("F_ParentId=" + currentID + " and F_State=1 and F_Layer = 1 order by f_sort").Tables[0];
- }
- else
- {
- tab2 = new BLL.T_Sys_Department().GetList("F_ParentId=" + currentID + " and F_State=1 order by f_sort").Tables[0];
- }
-
- if (tab2 != null && tab2.Rows.Count > 0)
- {
- model.children = BindBreaTree(tab2, currentID, pid);
- }
- modelList.Add(model);
- }
- return modelList;
- }
- else
- {
- return null;
- }
- }
- /// <summary>
- /// tree 树形部门
- /// </summary>
- /// <param name="tab"></param>
- /// <param name="parentid"></param>
- /// <returns></returns>
- private List<Model.TreeModel> BindBreaTree(DataTable tab, string parentid,int pid=0)
- {
- 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.IconCls = "";//图标
- model.text = categorylist[i].F_DeptName;
- tab2 = new BLL.T_Sys_Department().GetList("F_ParentId=" + currentID + " and F_State=1 order by f_sort").Tables[0];
- if (pid >0)
- {
- if (tab2 != null && tab2.Rows.Count > 0)
- {
- model.children = BindBreaTree(tab2, currentID, 0);
- }
- }
- modelList.Add(model);
- }
- return modelList;
- }
- else
- {
- return null;
- }
- }
- /// <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,
- layer= dModel.F_Layer
- });
- return Error("获取部门信息失败");
- }
- return NoToken("未知错误,请重新登录");
- }
- /// <summary>
- /// 获取部门
- /// </summary>
- /// <param name="deptId"></param>
- /// <returns></returns>
- public ActionResult GetwhereDept()
- {
- if (Request.IsAuthenticated)
- {
- int userId = CurrentUser.UserData.F_UserId;
- Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
- int deptId = 0;
- if (userModel!=null )
- {
- deptId = userModel.F_DeptId;
- }
- 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,
- F_Layer = dModel.F_Layer,
- parentid = dModel.F_ParentId,
- parentname = dModel.F_ParentName
- });
- return Error("获取部门信息失败");
- }
- return NoToken("未知错误,请重新登录");
- }
- /// <summary>
- /// 添加部门
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult AddDept(DepartmentInput input)
- {
-
- if (Request.IsAuthenticated)
- {
- //int userId = CurrentUser.UserData.F_UserId;
- //Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
- 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;
- if (pdModel.F_Layer ==1)
- dModel.F_Layer = 2;
- else if (pdModel.F_Layer == 2)
- dModel.F_Layer = 3;
- dModel.F_ParentName = pdModel.F_DeptName;
- }
- }
- dModel.F_Sort = input.Sort;
- dModel.F_DeptName = input.DeptName;
- dModel.F_State = 1;
- dModel.F_Layer = input.F_Layer;
- //dModel.F_GroupCode = userModel.groupcode;
- int id = departmentBLL.Add(dModel);
- if (id> 0)
- {
- departmentBLL.UpdateDeptCode(pcode + id.ToString() + "|", id);
- return Success("添加成功");
- }
- else
- return Success("添加失败");
- }
- return NoToken("未知错误,请重新登录");
- }
- /// <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() + "|";
- if (pdModel.F_Layer == 1)
- dModel.F_Layer = 2;
- else if (pdModel.F_Layer == 2)
- dModel.F_Layer = 3;
- dModel.F_ParentName = pdModel.F_DeptName;
- }
- }
- dModel.F_Sort = input.Sort;
- dModel.F_DeptName = input.DeptName;
- dModel.F_Layer = input.F_Layer;
- 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)
- {
- int userId = CurrentUser.UserData.F_UserId;
- Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
-
- if (userModel != null)
- pId = userModel.F_DeptId;
- Model.T_Sys_RoleInfo ro = rolebll.GetModel(userModel.F_RoleId);
- string where = "";
- DataTable dt = new DataTable();
- if (ro != null)
- {
- if (ro.F_RoleCode == "CLZY")
- pId=1;
- else if (ro.F_RoleCode == "ZR")
- pId = 1;
- else if (ro.F_RoleCode == "XTGLY")
- pId = 1;
- }
- if (pId == 2)
- {
- where = "(isnull(F_DeptId,0)='" + pId + "'or F_Layer=1 ) and F_State=1";
- }
- else if (pId == 421)
- {
- where = "isnull(F_DeptId,0)='" + 1+ "'and F_State=1";
- }
- else
- {
- where = " isnull(F_DeptId,0)='" + pId + "' and F_State=1 ";
- }
- //if (!string.IsNullOrEmpty(userModel.groupcode))
- //{
- // where += " and F_GroupCode = '" + userModel.groupcode + "'";
- //}
- if (pId == 0)
- {
- var strList = RedisHelper.StringGet("ZTreeList_Shuanghui");
- if (strList != null)
- {
- return Success("加载成功", strList.ToString().ToObject<List<Model.TreeModel>>());
- }
- }
- dt = new BLL.T_Sys_Department().GetList(0, where, " F_Sort asc").Tables[0];
- List<Model.TreeModel> modelList = BindTree(dt, "0");
- if (pId == 0)
- {
- RedisHelper.StringSet("ZTreeList_Shuanghui", modelList.ToJson());
- }
- if (modelList != null)
- {
- if (modelList.Count > 0)
- return Success("加载成功", modelList);
- }
- return Error("加载失败");
- }
- return NoToken("未知错误,请重新登录");
- }
- /// <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.IconCls = "";//图标
- model.text = categorylist[i].F_DeptName;
- tab2 = new BLL.T_Sys_Department().GetList("F_ParentId=" + currentID + " and F_State=1 order by f_sort").Tables[0];
- if (tab2 != null && tab2.Rows.Count > 0)
- {
- model.children = BindTree(tab2, currentID);
- }
- modelList.Add(model);
- }
- return modelList;
- }
- else
- {
- return null;
- }
- }
- }
- }
|