| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- 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
- {
- [Authority]
- public class DepartmentController : BaseController
- {
- private BLL.T_Sys_Department departmentBLL = new BLL.T_Sys_Department();
- #region 部门
- /// <summary>
- /// 获取部门列表
- /// </summary>
- /// <returns></returns>
- public ActionResult GetDeptList()
- {
- DataTable dt = new DataTable();
- dt = departmentBLL.GetList(0, "F_State=0", " F_Sort").Tables[0];
- return Success("加载成功", dt);
- }
- /// <summary>
- /// 获取部门
- /// </summary>
- /// <param name="deptId"></param>
- /// <returns></returns>
- public ActionResult GetDept()
- {
- int id = RequestString.GetInt("id", 0);
- Model.T_Sys_Department dModel = departmentBLL.GetModel(id);
- if (dModel != null)
- return Success("获取信息成功", dModel);
- return Error("获取信息失败");
- }
- /// <summary>
- /// 添加部门
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult AddDept()
- {
- Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(User.UserData["F_UserCode"]);
- int id = RequestString.GetInt("id", 0);
- int did = RequestString.GetInt("did", 0);
- int sort = RequestString.GetInt("sort", 0);
- int isdept = RequestString.GetInt("isdept", 0);
- int isdealdept = RequestString.GetInt("isdealdept", 0);
- string name = RequestString.GetFormString("name");
- string phone = RequestString.GetFormString("phone");
- string leader = RequestString.GetFormString("leader");
- string split = RequestString.GetFormString("split");
- string topleader = RequestString.GetFormString("topleader");
- Model.T_Sys_Department dModel = new Model.T_Sys_Department();
- if (id == 0)
- {
- var list = departmentBLL.GetModelList(" F_PartentId='" + did + "' and F_DeptName='" + name + "' ");
- if (list.Count > 0)
- {
- return Error("已经存在此部门");
- }
- else
- {
- dModel.F_PartentId = did;
- dModel.F_Sort = sort;
- dModel.F_DeptName = name;
- dModel.F_DeptPhone = phone;
- dModel.F_layer = did > 0 ? 1 : 0;
- dModel.F_Type = 0;
- dModel.F_LeaderUser = leader;
- dModel.F_TopSplitUser = split;
- dModel.F_TopLeaderUser = topleader;
- dModel.F_State = 0;
- dModel.F_IsDept = isdept;
- dModel.F_IsDealDept = isdealdept;
- dModel.F_CreateDate = DateTime.Now;
- dModel.F_CreateUser = userModel.F_UserCode;
- int n = departmentBLL.Add(dModel);
- if (n > 0)
- return Success("添加成功", n);
- else
- return Error("添加失败");
- }
- }
- else
- {
- dModel = departmentBLL.GetModel(id);
- if (dModel != null)
- {
- var list = departmentBLL.GetModelList(" F_PartentId='" + did + "' and F_DeptName='" + name + "' and F_DeptId!='" + id + "' ");
- if (list.Count > 0)
- {
- return Error("已经存在此部门");
- }
- else
- {
- dModel.F_PartentId = did;
- dModel.F_Sort = sort;
- dModel.F_DeptName = name;
- dModel.F_DeptPhone = phone;
- dModel.F_LeaderUser = leader;
- dModel.F_TopSplitUser = split;
- dModel.F_TopLeaderUser = topleader;
- dModel.F_IsDept = isdept;
- dModel.F_IsDealDept = isdealdept;
- if (departmentBLL.Update(dModel))
- return Success("修改成功");
- else
- return Error("修改失败");
- }
- }
- else
- {
- return Error("修改失败");
- }
- }
- }
- /// <summary>
- /// 删除部门
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- public ActionResult DelDept(string[] ids)
- {
- 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("删除失败");
- }
- /// <summary>
- /// 删除部门和其下级部门
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- public ActionResult DelDepts(int id)
- {
- if (id > 0)
- {
- var model = new BLL.T_Sys_Department().GetModel(id);
- if (DelDeptsByPId(id))
- {
- new BLL.T_Sys_Department().Delete(id);
- }
- return Success("删除成功");
- }
- else
- {
- return Error("删除失败");
- }
- }
- public bool DelDeptsByPId(int id)
- {
- bool bl = true;
- var list = new BLL.T_Sys_Department().GetModelList(" F_PartentId ='" + id + "'");
- foreach (var l in list)
- {
- if (DelDeptsByPId(l.F_DeptId))
- {
- new BLL.T_Sys_Department().Delete(l.F_DeptId);
- }
- }
- return bl;
- }
- #endregion
- public ActionResult GetDeptList1(string branchcode)
- {
- string sqlwhere = " F_IsDelete=0 ";
- if (!string.IsNullOrEmpty(branchcode))
- {
- sqlwhere += " and F_Code='" + branchcode + "'";
- }
- else
- {
- return Error("请选择区县");
- }
- var list = new BLL.T_Branch_List().GetModelList(sqlwhere);
- if (list.Count == 0)
- {
- return Error("查询失败");
- }
- string controllername = RouteData.Values["controller"].ToString();
- string actionname = RouteData.Values["action"].ToString();
- if (!string.IsNullOrEmpty(list[0].F_Url))
- {
- string signcode = CommonHelper.getsigncode(controllername, actionname, list[0].F_Sign);
- string strparams = "?signcode=" + signcode;
- string result = HttpMethods.HttpGet(list[0].F_Url + "/" + controllername + "/" + actionname + strparams);
- return Content(result);
- }
- else
- {
- return Error("查询失败");
- }
- }
- }
- }
|