Aucune description

DepartmentController.cs 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. using CallCenter.Utility;
  2. using CallCenterApi.Common;
  3. using CallCenterApi.DB;
  4. using CallCenterApi.Interface.Controllers.Base;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Linq;
  9. using System.Web;
  10. using System.Web.Mvc;
  11. namespace CallCenterApi.Interface.Controllers
  12. {
  13. [Authority]
  14. public class DepartmentController : BaseController
  15. {
  16. private BLL.T_Sys_Department departmentBLL = new BLL.T_Sys_Department();
  17. #region 部门
  18. /// <summary>
  19. /// 获取部门列表
  20. /// </summary>
  21. /// <returns></returns>
  22. public ActionResult GetDeptList(string deptname ,int iscbdw=0)
  23. {
  24. DataTable dt = new DataTable();
  25. string sql = "";
  26. if (!string .IsNullOrEmpty (deptname))
  27. {
  28. sql += " and F_DeptName like '%" + deptname.Trim() + "%'";
  29. }
  30. if (User.F_RoleCode == "GLY" || User.F_RoleCode == "ZXLD" || User.F_RoleCode == "SPZ" || User.F_RoleCode == "SPZJZ" || User.F_RoleCode == "ZXHWY"
  31. || User.F_RoleCode == "DBZY" || User.F_RoleCode == "DMTSH")
  32. {
  33. if (iscbdw == 0)
  34. {
  35. dt = departmentBLL.GetList( "F_State=0" + sql, " F_Sort").Tables[0];
  36. }
  37. else if (iscbdw == 1)
  38. {
  39. dt = departmentBLL.GetList( "F_State=0 and ISNULL(F_IsDept, '0') ='1'" + sql, " F_Sort").Tables[0];
  40. }
  41. else if (iscbdw == 2)
  42. {
  43. dt = departmentBLL.GetList("F_State=0 and F_IsDept in(1,2)" + sql, " F_Sort").Tables[0];
  44. }
  45. }
  46. else
  47. {
  48. if (iscbdw == 0)
  49. {
  50. dt = departmentBLL.GetListNoCache("F_State=0 and ( F_PartentId='" + User.F_DeptId + "' or EXISTS (select 1 from dbo.SplitToNvarchar(F_Remark, ',') a join" +
  51. " dbo.SplitToNvarchar((select F_Remark from T_Sys_Department where F_DeptId = '" + User.F_DeptId + "' AND F_Remark !='' AND F_Remark IS NOT NULL ), ',') b on a.col = b.col) ) " +
  52. "and F_IsDept =2" + sql, " F_Sort").Tables[0];
  53. }
  54. else if (iscbdw == 2)
  55. {
  56. dt = departmentBLL.GetList("F_State=0 and ( F_DeptId='" + User.F_DeptId + "' or F_PartentId='" + User.F_DeptId + "'" +
  57. ") " + sql, " F_Sort").Tables[0];
  58. }
  59. else
  60. {
  61. dt = departmentBLL.GetList("F_State=0 and ISNULL(F_IsDept, '0') ='1' and F_PartentId='" + User.F_DeptId + "' " + sql, " F_Sort").Tables[0];
  62. }
  63. }
  64. return Success("加载成功", dt);
  65. }
  66. public ActionResult GetZTreeNew()
  67. {
  68. DataTable dt = new DataTable();
  69. dt = new BLL.T_Sys_Department ().GetList(" 1=1 and F_IsDept =1 and F_State = 0 and F_PartentId=155", "F_Sort ").Tables[0];
  70. string sqltest = " with cte(F_DeptId ,F_DeptName ,F_PartentId ,F_Layer,F_State,F_IsDept) as (select F_DeptId, F_DeptName, F_PartentId, F_Layer, F_State, F_IsDept from T_Sys_Department where F_IsDept =1 and F_State = 0 and F_PartentId=155 UNION all select t.F_DeptId, t.F_DeptName,t.F_PartentId,t.F_Layer,t.F_State,t.F_IsDept from T_Sys_Department as t inner join cte as c on c.F_DeptId = t.F_PartentId )select * from cte ";
  71. var tab2 = DbHelperSQL.Query(sqltest).Tables[0];
  72. List<TreeModelNew> modelList = BindTreeNew(dt, "0", tab2);
  73. if (modelList.Count > 0)
  74. {
  75. return Success("加载成功", modelList.ToJson());
  76. }
  77. else
  78. return Error("加载失败");
  79. }
  80. public ActionResult GetDeptUser(int deptid)
  81. {
  82. var dt = "select count(1) from T_Sys_UserAccount with(nolock) where F_DeptId='" + deptid + "'";
  83. int usercount = int.Parse(DbHelperSQL.GetSingle(dt).ToString());
  84. if (usercount>0)
  85. {
  86. return Success("成功", true);
  87. }
  88. else
  89. {
  90. return Success("成功", false );
  91. }
  92. }
  93. public class TreeModelNew
  94. {
  95. private string _id;
  96. /// <summary>
  97. /// Id
  98. /// </summary>
  99. public string id
  100. {
  101. set { _id = value; }
  102. get { return _id; }
  103. }
  104. private string _title;
  105. /// <summary>
  106. /// 树节点显示文本
  107. /// </summary>
  108. public string title
  109. {
  110. set { _title = value; }
  111. get { return _title; }
  112. }
  113. private List<TreeModelNew> _child;
  114. public List<TreeModelNew> child
  115. {
  116. set { _child = value; }
  117. get { return _child; }
  118. }
  119. }
  120. ///// <summary>
  121. ///// 获取部门列表
  122. ///// </summary>
  123. ///// <returns></returns>
  124. //public ActionResult GetDeptList(string deptname, int iscbdw = 0)
  125. //{
  126. // DataTable dt = new DataTable();
  127. // string sql = "";
  128. // if (!string.IsNullOrEmpty(deptname))
  129. // {
  130. // sql += " and F_DeptName like '%" + deptname.Trim() + "%'";
  131. // }
  132. // if (User.F_RoleCode == "GLY" || User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "MTDD" || User.F_RoleCode == "ZXHWY"
  133. // || User.F_RoleCode == "DBZY")
  134. // {
  135. // if (iscbdw == 0)
  136. // {
  137. // // dt = departmentBLL.GetList( "F_State=0" + sql, " F_Sort").Tables[0];
  138. // string SY = " select(select COUNT(1) from T_Sys_UserAccount b WITH(NOLOCK) where F_DeptId = a.F_DeptId and b.F_CreateOn = b.F_LastActiveTime) as JIHUO ,* from T_Sys_Department a WITH(NOLOCK) where F_State = 0 " + sql + "order by F_Sort";
  139. // dt = DbHelperSQL.Query(SY).Tables[0];
  140. // }
  141. // else if (iscbdw == 1)
  142. // {
  143. // // dt = departmentBLL.GetList( "F_State=0 and ISNULL(F_IsDept, '0') ='1'" + sql, " F_Sort").Tables[0];
  144. // string SY = " select(select COUNT(1) from T_Sys_UserAccount b WITH(NOLOCK) where F_DeptId = a.F_DeptId and b.F_CreateOn = b.F_LastActiveTime) as JIHUO ,* from T_Sys_Department a WITH(NOLOCK) where F_State = 0 and ISNULL(F_IsDept, '0') ='1'" + sql + "order by F_Sort";
  145. // dt = DbHelperSQL.Query(SY).Tables[0];
  146. // }
  147. // else if (iscbdw == 2)
  148. // {
  149. // // dt = departmentBLL.GetList("F_State=0 and F_IsDept in(1,2)" + sql, " F_Sort").Tables[0];
  150. // string SY = " select(select COUNT(1) from T_Sys_UserAccount b WITH(NOLOCK) where F_DeptId = a.F_DeptId and b.F_CreateOn = b.F_LastActiveTime) as JIHUO ,* from T_Sys_Department a WITH(NOLOCK) where F_State = 0 and F_IsDept in(1,2)" + sql + "order by F_Sort";
  151. // dt = DbHelperSQL.Query(SY).Tables[0];
  152. // }
  153. // }
  154. // else
  155. // {
  156. // if (iscbdw == 0)
  157. // {
  158. // // dt = departmentBLL.GetList("F_State=0 and ( F_PartentId='" + User.F_DeptId + "')"+ sql, " F_Sort").Tables[0];
  159. // string SY = " select(select COUNT(1) from T_Sys_UserAccount b WITH(NOLOCK) where F_DeptId = a.F_DeptId and b.F_CreateOn = b.F_LastActiveTime) as JIHUO ,* from T_Sys_Department a WITH(NOLOCK) where F_State = 0 and ( F_PartentId='" + User.F_DeptId + "')" + sql + "order by F_Sort";
  160. // dt = DbHelperSQL.Query(SY).Tables[0];
  161. // }
  162. // else if (iscbdw == 2)
  163. // {
  164. // // dt = departmentBLL.GetList("F_State=0 and ( F_DeptId='" + User.F_DeptId + "' or F_PartentId='" + User.F_DeptId + "')" + sql, " F_Sort").Tables[0];
  165. // string SY = " select(select COUNT(1) from T_Sys_UserAccount b WITH(NOLOCK) where F_DeptId = a.F_DeptId and b.F_CreateOn = b.F_LastActiveTime) as JIHUO ,* from T_Sys_Department a WITH(NOLOCK) where F_State = 0 and ( F_DeptId='" + User.F_DeptId + "' or F_PartentId='" + User.F_DeptId + "')" + sql + "order by F_Sort";
  166. // dt = DbHelperSQL.Query(SY).Tables[0];
  167. // }
  168. // else
  169. // {
  170. // // dt = departmentBLL.GetList("F_State=0 and ISNULL(F_IsDept, '0') ='1' and F_PartentId='" + User.F_DeptId + "'" + sql, " F_Sort").Tables[0];
  171. // string SY = " select(select COUNT(1) from T_Sys_UserAccount b WITH(NOLOCK) where F_DeptId = a.F_DeptId and b.F_CreateOn = b.F_LastActiveTime) as JIHUO ,* from T_Sys_Department a WITH(NOLOCK) where F_State = 0 and ISNULL(F_IsDept, '0') ='1' and F_PartentId='" + User.F_DeptId + "'" + sql + "order by F_Sort";
  172. // dt = DbHelperSQL.Query(SY).Tables[0];
  173. // }
  174. // }
  175. // return Success("加载成功", dt);
  176. //}
  177. /// <summary>
  178. /// 得到一个对象实体
  179. /// </summary>
  180. public CallCenterApi.Model.T_Sys_Department DataRowToModel1(DataRow row)
  181. {
  182. CallCenterApi.Model.T_Sys_Department model = new CallCenterApi.Model.T_Sys_Department();
  183. if (row != null)
  184. {
  185. if (row["F_DeptId"] != null && row["F_DeptId"].ToString() != "")
  186. {
  187. model.F_DeptId = int.Parse(row["F_DeptId"].ToString());
  188. }
  189. if (row["F_DeptName"] != null)
  190. {
  191. model.F_DeptName = row["F_DeptName"].ToString();
  192. }
  193. if (row["F_PartentId"] != null && row["F_PartentId"].ToString() != "")
  194. {
  195. model.F_PartentId = int.Parse(row["F_PartentId"].ToString());
  196. }
  197. if (row["F_layer"] != null && row["F_layer"].ToString() != "")
  198. {
  199. model.F_layer = int.Parse(row["F_layer"].ToString());
  200. }
  201. if (row["F_State"] != null && row["F_State"].ToString() != "")
  202. {
  203. model.F_State = int.Parse(row["F_State"].ToString());
  204. }
  205. if (row["F_IsDept"] != null && row["F_IsDept"].ToString() != "")
  206. {
  207. model.F_IsDept = int.Parse(row["F_IsDept"].ToString());
  208. }
  209. }
  210. return model;
  211. }
  212. public List<CallCenterApi.Model.T_Sys_Department> DataTableToList1(DataTable dt)
  213. {
  214. List<CallCenterApi.Model.T_Sys_Department> modelList = new List<CallCenterApi.Model.T_Sys_Department>();
  215. int rowsCount = dt.Rows.Count;
  216. if (rowsCount > 0)
  217. {
  218. CallCenterApi.Model.T_Sys_Department model;
  219. for (int n = 0; n < rowsCount; n++)
  220. {
  221. model = DataRowToModel1(dt.Rows[n]);
  222. if (model != null)
  223. {
  224. modelList.Add(model);
  225. }
  226. }
  227. }
  228. return modelList;
  229. }
  230. private List<TreeModelNew> BindTreeNew(DataTable tab, string parentid, DataTable tabtwo)
  231. {
  232. // DataTable tab2 = new DataTable();
  233. if (tab != null && tab.Rows.Count > 0)
  234. {
  235. List<Model.T_Sys_Department > categorylist = DataTableToList1(tab);
  236. List<TreeModelNew> modelList = new List<TreeModelNew>(categorylist.Count);
  237. for (int i = 0; i < categorylist.Count; i++)
  238. {
  239. TreeModelNew model = new TreeModelNew();
  240. string currentID = categorylist[i].F_DeptId .ToString();//当前功能ID
  241. model.id = currentID;
  242. model.title = categorylist[i].F_DeptName ;
  243. DataTable newdt = new DataTable();
  244. newdt = tabtwo.Clone();
  245. DataRow[] dr = tabtwo.Select(" F_PartentId=" + currentID + " and F_State=0 ");
  246. for (int j = 0; j < dr.Length; j++)
  247. {
  248. newdt.ImportRow((DataRow)dr[j]);
  249. }
  250. if (newdt != null && newdt.Rows.Count > 0)
  251. {
  252. model.child = BindTreeNew(newdt, currentID, tabtwo);
  253. }
  254. modelList.Add(model);
  255. }
  256. return modelList;
  257. }
  258. else
  259. {
  260. return null;
  261. }
  262. }
  263. public ActionResult GetDeptListByDept(string dept,int iscbdw = 0)
  264. {
  265. string depts = RequestString.FilterSql(dept, 1);
  266. DataTable dt = new DataTable();
  267. var sql = " F_State=0 and F_PartentId>0 "
  268. + "and F_PartentId not in (select F_DeptId from T_Sys_Department where F_PartentId = 0)";
  269. if (iscbdw == 0)
  270. sql += " and ISNULL(F_IsDealDept, '0') ='1' ";
  271. if (!string.IsNullOrEmpty(depts))
  272. {
  273. sql += " and F_DeptName like '%" + depts.Trim() + "%'";
  274. dt = departmentBLL.GetList(0, sql, "F_Sort").Tables[0];
  275. }
  276. return Success("加载成功", dt);
  277. }
  278. /// <summary>
  279. /// 获取二级部门列表
  280. /// </summary>
  281. /// <returns></returns>
  282. //[Authority]
  283. public ActionResult GetSecondDeptList()
  284. {
  285. DataTable dt = new DataTable();
  286. if (User.F_RoleCode == "GLY")
  287. {
  288. dt = departmentBLL.GetList("F_State=0 and ISNULL(F_IsDept, '0') ='2' " , " F_Sort").Tables[0];
  289. }
  290. if (User.F_RoleCode == "WLDW")
  291. {
  292. dt = departmentBLL.GetList("F_State=0 and ISNULL(F_IsDept, '0') ='2' and F_PartentId='" + User.F_DeptId + "'", " F_Sort").Tables[0];
  293. }
  294. return Success("加载成功", dt);
  295. }
  296. /// <summary>
  297. /// 获取部门列表
  298. /// </summary>
  299. /// <returns></returns>
  300. //[Authority]
  301. public ActionResult GetDeptListtree(int pId = 0)
  302. {
  303. DataTable dt = new DataTable();
  304. dt = new BLL.T_Sys_Department().GetList(" F_State=0 and ISNULL(F_IsDealDept, '0') ='1' and F_PartentId=" + pId).Tables[0];
  305. List<Model.TreeModel> modelList = BindTree(dt, "0");
  306. if (modelList != null)
  307. {
  308. if (modelList.Count > 0)
  309. return Success("加载成功", modelList);
  310. }
  311. return Error("加载失败");
  312. }
  313. /// <summary>
  314. /// tree 树形部门
  315. /// </summary>
  316. /// <param name="tab"></param>
  317. /// <param name="parentid"></param>
  318. /// <returns></returns>
  319. //[Authority]
  320. private List<Model.TreeModel> BindTree(DataTable tab, string parentid)
  321. {
  322. DataTable tab2 = new DataTable();
  323. if (tab != null && tab.Rows.Count > 0)
  324. {
  325. List<Model.T_Sys_Department> categorylist = new BLL.T_Sys_Department().DataTableToList(tab);
  326. List<Model.TreeModel> modelList = new List<Model.TreeModel>(categorylist.Count);
  327. for (int i = 0; i < categorylist.Count; i++)
  328. {
  329. Model.TreeModel model = new Model.TreeModel();
  330. string currentID = categorylist[i].F_DeptId.ToString();//当前功能ID
  331. model.id = currentID;
  332. model.IconCls = "";//图标
  333. model.text = categorylist[i].F_DeptName;
  334. tab2 = new BLL.T_Sys_Department().GetList("F_PartentId=" + currentID + " and F_State=0 and ISNULL(F_IsDealDept, '0') ='1' ", "f_sort").Tables[0];
  335. if (tab2 != null && tab2.Rows.Count > 0)
  336. {
  337. model.children = BindTree(tab2, currentID);
  338. }
  339. modelList.Add(model);
  340. }
  341. return modelList;
  342. }
  343. else
  344. {
  345. return null;
  346. }
  347. }
  348. /// <summary>
  349. /// 获取部门
  350. /// </summary>
  351. /// <param name="deptId"></param>
  352. /// <returns></returns>
  353. //[Authority]
  354. public ActionResult GetDept()
  355. {
  356. int id = RequestString.GetInt("id", 0);
  357. Model.T_Sys_Department dModel = departmentBLL.GetModel(id);
  358. if (dModel != null)
  359. {
  360. string value = "";
  361. if (dModel.F_Valueid != null)
  362. {
  363. var dicvalue = new BLL.T_Sys_DictionaryValue ().GetModel((int)dModel.F_Valueid);
  364. if (dicvalue != null)
  365. value = dicvalue.F_Value ;
  366. }
  367. var obj = new
  368. {
  369. F_Address = dModel.F_Address,
  370. F_CreateDate = dModel.F_CreateDate,
  371. F_CreateUser = dModel.F_CreateUser,
  372. F_DeptId = dModel.F_DeptId,
  373. F_DeptName = dModel.F_DeptName,
  374. F_DeptNameSpell = dModel.F_DeptNameSpell,
  375. F_DeptNameSpells = dModel.F_DeptNameSpells,
  376. F_DeptPhone = dModel.F_DeptPhone,
  377. F_DeptPhone2 = dModel.F_DeptPhone2,
  378. F_DeptTelphone = dModel.F_DeptTelphone,
  379. F_IsDealDept = dModel.F_IsDealDept,
  380. F_IsDept = dModel.F_IsDept,
  381. F_LeaderUser = dModel.F_LeaderUser,
  382. F_LeaderUserName = dModel.F_LeaderUserName,
  383. F_PartentId = dModel.F_PartentId,
  384. F_Remark = dModel.F_Remark,
  385. F_Sort = dModel.F_Sort,
  386. F_State = dModel.F_State,
  387. F_TopLeaderUser = dModel.F_TopLeaderUser,
  388. F_TopLeaderUserName = dModel.F_TopLeaderUserName,
  389. F_TopSplitUser = dModel.F_TopSplitUser,
  390. F_TopSplitUserName = dModel.F_TopSplitUserName,
  391. F_Type = dModel.F_Type,
  392. F_layer = dModel.F_layer,
  393. F_Valueid = dModel.F_Valueid,
  394. F_Value = value,
  395. };
  396. return Success("获取信息成功", dModel);
  397. }
  398. return Error("获取信息失败");
  399. }
  400. /// <summary>
  401. /// 添加部门
  402. /// </summary>
  403. /// <param name="input"></param>
  404. /// <returns></returns>
  405. //[Authority]
  406. [HttpPost]
  407. public ActionResult AddDept()
  408. {
  409. int id = RequestString.GetInt("id", 0);
  410. int did = RequestString.GetInt("did", 0);
  411. int sort = RequestString.GetInt("sort", 0);
  412. int isdept = RequestString.GetInt("isdept", 0);
  413. int isdealdept = RequestString.GetInt("isdealdept", 0);
  414. int valueid = RequestString.GetInt("valueid", 0);
  415. string name = RequestString.GetFormString("name");
  416. string phone = RequestString.GetFormString("phone");
  417. string leader = RequestString.GetFormString("leader");
  418. string split = RequestString.GetFormString("split");
  419. string topleader = RequestString.GetFormString("topleader");
  420. string remark = RequestString.GetFormString("remark");
  421. Model.T_Sys_Department dModel = new Model.T_Sys_Department();
  422. if (id == 0)
  423. {
  424. var list = departmentBLL.GetModelList(" F_State=0 and F_PartentId='" + did + "' and F_DeptName='" + name + "' ");
  425. if (list.Count > 0)
  426. {
  427. return Error("已经存在此部门");
  428. }
  429. else
  430. {
  431. dModel.F_PartentId = did;
  432. dModel.F_Sort = sort;
  433. dModel.F_DeptName = name;
  434. dModel.F_DeptPhone = phone;
  435. dModel.F_layer = did > 0 ? 1 : 0;
  436. dModel.F_Type = 0;
  437. dModel.F_LeaderUser = leader;
  438. dModel.F_TopSplitUser = split;
  439. dModel.F_TopLeaderUser = topleader;
  440. dModel.F_State = 0;
  441. dModel.F_IsDept = isdept;
  442. dModel.F_IsDealDept = isdealdept;
  443. dModel.F_CreateDate = DateTime.Now;
  444. dModel.F_CreateUser = User.F_UserCode;
  445. dModel.F_Valueid = valueid;
  446. dModel.F_Remark = remark ;
  447. int n = departmentBLL.Add(dModel);
  448. if (n > 0)
  449. {
  450. string content = $"{User.F_UserName}({User.F_UserCode })添加部门{ dModel.F_DeptName }";
  451. string Operation = OperationLogController
  452. .AddOperationList(content, User.F_UserCode, Common.DTRequest.GetIP(), 0, 4596, n);
  453. if (valueid > 0)
  454. {
  455. var value = new BLL.T_Sys_DictionaryValue ().GetModel(valueid);
  456. if (value != null)
  457. {
  458. value.F_Deptid = n;
  459. }
  460. var b = new BLL.T_Sys_DictionaryValue().Update(value);
  461. }
  462. return Success("添加成功", n);
  463. }
  464. else
  465. return Error("添加失败");
  466. }
  467. }
  468. else
  469. {
  470. dModel = departmentBLL.GetModel(id);
  471. if (dModel != null)
  472. {
  473. var list = departmentBLL.GetModelListNoCache(" F_State=0 and F_PartentId='" + did + "' and F_DeptName='" + name + "' and F_DeptId<>'" + id + "' ","");
  474. if (list.Count > 0)
  475. {
  476. return Error("已经存在此部门");
  477. }
  478. else
  479. {
  480. dModel.F_PartentId = did;
  481. dModel.F_Sort = sort;
  482. dModel.F_DeptName = name;
  483. dModel.F_DeptPhone = phone;
  484. dModel.F_LeaderUser = leader;
  485. dModel.F_TopSplitUser = split;
  486. dModel.F_TopLeaderUser = topleader;
  487. dModel.F_IsDept = isdept;
  488. dModel.F_IsDealDept = isdealdept;
  489. dModel.F_Valueid = valueid;
  490. dModel.F_Remark = remark;
  491. if (departmentBLL.Update(dModel))
  492. {
  493. string content = $"{User.F_UserName}({User.F_UserCode })修改部门{ dModel.F_DeptName }";
  494. string Operation = OperationLogController
  495. .AddOperationList(content, User.F_UserCode, Common.DTRequest.GetIP(), 1, 4596, dModel.F_DeptId);
  496. if (valueid > 0)
  497. {
  498. var value = new BLL.T_Sys_DictionaryValue().GetModel(valueid);
  499. if (value != null)
  500. {
  501. value.F_Deptid = dModel.F_DeptId ;
  502. }
  503. var b = new BLL.T_Sys_DictionaryValue().Update(value);
  504. }
  505. return Success("修改成功");
  506. }
  507. else
  508. return Error("修改失败");
  509. }
  510. }
  511. else
  512. {
  513. return Error("修改失败");
  514. }
  515. }
  516. }
  517. //[Authority]
  518. [HttpPost]
  519. public ActionResult UpdateDeptRemark()
  520. {
  521. if(User==null)
  522. return Error("权限不足!");
  523. int id = RequestString.GetInt("id", 0);
  524. string remark = RequestString.GetFormString("remark");
  525. if (id <= 0)
  526. return Error("参数错误");
  527. Model.T_Sys_Department dModel = departmentBLL.GetModel(id);
  528. if(dModel==null)
  529. return Error("参数错误!");
  530. dModel.F_Remark = remark;
  531. if (departmentBLL.Update(dModel))
  532. return Success("修改成功");
  533. else
  534. return Error("修改失败");
  535. }
  536. public ActionResult UpdateSMSList(string ids,int state)
  537. {
  538. if (User == null)
  539. return Error("权限不足!");
  540. if (string .IsNullOrEmpty (ids) )
  541. return Error("请选择部门");
  542. if (departmentBLL.UpdateSMS(0))
  543. {
  544. if (departmentBLL.UpdateSMSList(ids, state))
  545. return Success("修改成功");
  546. }
  547. return Error("修改失败");
  548. }
  549. /// <summary>
  550. /// 删除部门
  551. /// </summary>
  552. /// <param name="ids"></param>
  553. /// <returns></returns>
  554. //[Authority]
  555. public ActionResult DelDept(string[] ids)
  556. {
  557. if (ids == null || ids.Length <= 0)
  558. return Error("请选择要删除的部门");
  559. var idStr = string.Join(",", ids);
  560. if (string.IsNullOrEmpty(idStr.Trim()))
  561. return Error("请选择要删除的部门");
  562. foreach (var it in ids)
  563. {
  564. var dModel = new BLL.T_Sys_Department().GetModel(int.Parse(it));
  565. if (dModel != null)
  566. {
  567. string content = $"{User.F_UserName}({User.F_UserCode })删除部门{ dModel.F_DeptName }";
  568. string Operation = OperationLogController
  569. .AddOperationList(content, User.F_UserCode, Common.DTRequest.GetIP(), 2, 4596, dModel.F_DeptId);
  570. }
  571. }
  572. if (departmentBLL.DeleteList(idStr))
  573. {
  574. return Success("删除成功");
  575. }
  576. return Error("删除失败");
  577. }
  578. /// <summary>
  579. /// 删除部门和其下级部门
  580. /// </summary>
  581. /// <param name="ids"></param>
  582. /// <returns></returns>
  583. //[Authority]
  584. public ActionResult DelDepts(int id)
  585. {
  586. if (id > 0)
  587. {
  588. var model = new BLL.T_Sys_Department().GetModel(id);
  589. if (DelDeptsByPId(id))
  590. {
  591. string content = $"{User.F_UserName}({User.F_UserCode })删除部门{ model.F_DeptName }";
  592. string Operation = OperationLogController
  593. .AddOperationList(content, User.F_UserCode, Common.DTRequest.GetIP(), 2, 4596, model.F_DeptId);
  594. new BLL.T_Sys_Department().Delete(id);
  595. }
  596. return Success("删除成功");
  597. }
  598. else
  599. {
  600. return Error("删除失败");
  601. }
  602. }
  603. //[Authority]
  604. public bool DelDeptsByPId(int id)
  605. {
  606. bool bl = true;
  607. var list = new BLL.T_Sys_Department().GetModelList(" F_PartentId ='" + id + "'");
  608. foreach (var l in list)
  609. {
  610. if (DelDeptsByPId(l.F_DeptId))
  611. {
  612. try
  613. {
  614. var dModel = new BLL.T_Sys_Department().GetModel(l.F_DeptId);
  615. if (dModel != null)
  616. {
  617. string content = $"{User.F_UserName}({User.F_UserCode })删除部门{ dModel.F_DeptName }";
  618. string Operation = OperationLogController
  619. .AddOperationList(content, User.F_UserCode, Common.DTRequest.GetIP(), 2, 4596, dModel.F_DeptId);
  620. }
  621. }
  622. catch
  623. {
  624. }
  625. new BLL.T_Sys_Department().Delete(l.F_DeptId);
  626. }
  627. }
  628. return bl;
  629. }
  630. #endregion
  631. }
  632. }