RightDicNewController.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. /*
  2. * 单页内容
  3. */
  4. using System;
  5. using System.Web;
  6. using System.Collections.Generic;
  7. using System.Diagnostics;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. using Microsoft.AspNetCore.Mvc;
  11. using Microsoft.AspNetCore.Http;
  12. using Microsoft.Extensions.Logging;
  13. using Microsoft.Extensions.Options;
  14. using MySystem.BsModels;
  15. using Library;
  16. using LitJson;
  17. using MySystemLib;
  18. namespace MySystem.Areas.Admin.Controllers
  19. {
  20. [Area("Admin")]
  21. [Route("Admin/[controller]/[action]")]
  22. public class RightDicNewController : BaseController
  23. {
  24. public RightDicNewController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  25. {
  26. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["BsSqlConnStr"].ToString();
  27. }
  28. #region 单页内容列表
  29. /// <summary>
  30. /// 根据条件查询单页内容列表
  31. /// </summary>
  32. /// <returns></returns>
  33. public IActionResult Index(RightDicNew data, string right)
  34. {
  35. ViewBag.RightInfo = RightInfo;
  36. ViewBag.right = right;
  37. return View();
  38. }
  39. #endregion
  40. #region 根据条件查询单页内容列表
  41. /// <summary>
  42. /// 单页内容列表
  43. /// </summary>
  44. /// <returns></returns>
  45. public JsonResult IndexData(RightDicNew data, int page = 1, int limit = 30)
  46. {
  47. List<RightDicNew> diclist = bsdb.RightDicNew.OrderBy(m => m.Id).ToList();
  48. foreach (RightDicNew dic in diclist)
  49. {
  50. int nameLength = dic.Id.Split('_').Length;
  51. for (int i = 1; i < nameLength; i++)
  52. {
  53. dic.Title = "  " + dic.Title;
  54. }
  55. }
  56. Dictionary<string, object> obj = new Dictionary<string, object>();
  57. obj.Add("code", 0);
  58. obj.Add("msg", "");
  59. obj.Add("count", diclist.Count);
  60. obj.Add("data", diclist);
  61. return Json(obj);
  62. }
  63. #endregion
  64. #region 添加
  65. /// <summary>
  66. /// 添加
  67. /// </summary>
  68. /// <returns></returns>
  69. public IActionResult Add(string right)
  70. {
  71. ViewBag.RightInfo = RightInfo;
  72. ViewBag.right = right;
  73. return View();
  74. }
  75. [HttpPost]
  76. public string AddPost(RightDicNew data, string PColId)
  77. {
  78. RightDicNew adddic = new RightDicNew();
  79. string words = "123456789abcdefghijklmnopqrstuvwxyz";
  80. if (!string.IsNullOrEmpty(PColId))
  81. {
  82. int Len = PColId.Length + 2;
  83. int checkcount = bsdb.RightDicNew.Count(m => m.Id.StartsWith(PColId) && m.Id.Length == Len);
  84. if (checkcount > 0)
  85. {
  86. RightDicNew checkdic = bsdb.RightDicNew.Where(m => m.Id.StartsWith(PColId) && m.Id.Length == Len).OrderByDescending(m => m.Id).FirstOrDefault();
  87. string last_id = "";
  88. string[] idlist = checkdic.Id.Split('_');
  89. last_id = idlist[idlist.Length - 1];
  90. last_id = words.Substring(words.IndexOf(last_id) + 1, 1);
  91. adddic.Id = PColId + "_" + last_id;
  92. }
  93. else
  94. {
  95. adddic.Id = PColId + "_1";
  96. }
  97. }
  98. else
  99. {
  100. int checkcount = bsdb.RightDicNew.Count(m => m.Id.Length == 1);
  101. if (checkcount > 0)
  102. {
  103. RightDicNew checkdic = bsdb.RightDicNew.Where(m => m.Id.Length == 1).OrderByDescending(m => m.Id).FirstOrDefault();
  104. string last_id = words.Substring(words.IndexOf(checkdic.Id) + 1, 1);
  105. adddic.Id = PColId + "_" + last_id;
  106. }
  107. else
  108. {
  109. adddic.Id = "1";
  110. }
  111. }
  112. adddic.Name = data.Name;
  113. adddic.Icon = data.Icon;
  114. adddic.Path = data.Path;
  115. adddic.Title = data.Title;
  116. // adddic.MainMenu = data.MainMenu;
  117. // adddic.MainStat = data.MainStat;
  118. // adddic.MainDataList = data.MainDataList;
  119. adddic.Url = data.Url;
  120. adddic.RightLevel = adddic.Id.Split('_').Length;
  121. bsdb.RightDicNew.Add(adddic);
  122. AddSysLog(0, "RightDicNew", "add");
  123. bsdb.SaveChanges();
  124. return "success";
  125. }
  126. #endregion
  127. #region 修改
  128. /// <summary>
  129. /// 修改
  130. /// </summary>
  131. /// <returns></returns>
  132. public IActionResult Edit(string right, string Id = "")
  133. {
  134. ViewBag.RightInfo = RightInfo;
  135. ViewBag.right = right;
  136. RightDicNew editData = bsdb.RightDicNew.FirstOrDefault(m => m.Id == Id) ?? new RightDicNew();
  137. ViewBag.data = editData;
  138. string PColId = "";
  139. if (editData.Id.Contains("_"))
  140. {
  141. PColId = editData.Id.Substring(0, editData.Id.LastIndexOf("_"));
  142. }
  143. else
  144. {
  145. PColId = editData.Id;
  146. }
  147. ViewBag.OldPColId = PColId;
  148. ViewBag.PColId = PColId;
  149. return View();
  150. }
  151. [HttpPost]
  152. public string EditPost(RightDicNew data, string OldPColId, string PColId)
  153. {
  154. RightDicNew adddic = new RightDicNew();
  155. bool op = false;
  156. RightDicNew dic = bsdb.RightDicNew.FirstOrDefault(m => m.Id == data.Id);
  157. if (dic != null)
  158. {
  159. if (OldPColId != PColId)
  160. {
  161. string words = "123456789abcdefghijklmnopqrstuvwxyz";
  162. if (!string.IsNullOrEmpty(PColId))
  163. {
  164. int Len = PColId.Length + 2;
  165. int checkcount = bsdb.RightDicNew.Count(m => m.Id.StartsWith(PColId) && m.Id.Length == Len);
  166. if (checkcount > 0)
  167. {
  168. RightDicNew checkdic = bsdb.RightDicNew.Where(m => m.Id.StartsWith(PColId) && m.Id.Length == Len).OrderByDescending(m => m.Id).FirstOrDefault();
  169. string last_id = "";
  170. string[] idlist = checkdic.Id.Split('_');
  171. last_id = idlist[idlist.Length - 1];
  172. last_id = words.Substring(words.IndexOf(last_id) + 1, 1);
  173. adddic.Id = PColId + "_" + last_id;
  174. }
  175. else
  176. {
  177. adddic.Id = PColId + "_1";
  178. }
  179. }
  180. else
  181. {
  182. int checkcount = bsdb.RightDicNew.Count(m => m.Id.Length == 1);
  183. if (checkcount > 0)
  184. {
  185. RightDicNew checkdic = bsdb.RightDicNew.Where(m => m.Id.Length == 1).OrderByDescending(m => m.Id).FirstOrDefault();
  186. string last_id = words.Substring(words.IndexOf(checkdic.Id) + 1, 1);
  187. adddic.Id = PColId + "_" + last_id;
  188. }
  189. else
  190. {
  191. adddic.Id = "1";
  192. }
  193. }
  194. adddic.Name = data.Name;
  195. adddic.Icon = data.Icon;
  196. adddic.Path = data.Path;
  197. adddic.Title = data.Title;
  198. // adddic.MainMenu = data.MainMenu;
  199. // adddic.MainStat = data.MainStat;
  200. // adddic.MainDataList = data.MainDataList;
  201. adddic.Url = dic.Url;
  202. adddic.RightLevel = adddic.Id.Split('_').Length;
  203. bsdb.RightDicNew.Remove(dic);
  204. op = true;
  205. }
  206. else
  207. {
  208. dic.Name = data.Name;
  209. dic.Icon = data.Icon;
  210. dic.Path = data.Path;
  211. dic.Title = data.Title;
  212. dic.Url = dic.Url;
  213. // dic.MainMenu = data.MainMenu;
  214. // dic.MainStat = data.MainStat;
  215. // dic.MainDataList = data.MainDataList;
  216. }
  217. }
  218. AddSysLog(data.Id.ToString(), "RightDicNew", "update");
  219. bsdb.SaveChanges();
  220. if (op)
  221. {
  222. bsdb.RightDicNew.Add(adddic);
  223. bsdb.SaveChanges();
  224. }
  225. return "success";
  226. }
  227. #endregion
  228. #region 修改
  229. /// <summary>
  230. /// 修改
  231. /// </summary>
  232. /// <returns></returns>
  233. public IActionResult RightSet(string Id = "")
  234. {
  235. List<OperateRightList> rights = bsdb.OperateRightList.ToList();
  236. ViewBag.rights = rights;
  237. ViewBag.Id = Id;
  238. List<string> RightList = new List<string>();
  239. List<MenuRightNew> MenuRights = bsdb.MenuRightNew.Where(m => m.MenuId.StartsWith(Id)).ToList();
  240. foreach (MenuRightNew sub in MenuRights)
  241. {
  242. RightList.Add(sub.MenuId.Replace(Id + "_", "") + "_" + sub.Name);
  243. }
  244. ViewBag.RightList = RightList;
  245. RightDicNew editData = bsdb.RightDicNew.FirstOrDefault(m => m.Id == Id) ?? new RightDicNew();
  246. ViewBag.OtherRight = editData.OtherRight;
  247. return View();
  248. }
  249. [HttpPost]
  250. public string RightSetPost(string Id, string OtherRight, string RightList)
  251. {
  252. IQueryable<MenuRightNew> MenuRights = bsdb.MenuRightNew.Where(m => m.MenuId.StartsWith(Id));
  253. foreach (MenuRightNew sub in MenuRights)
  254. {
  255. bsdb.MenuRightNew.Remove(sub);
  256. }
  257. bsdb.SaveChanges();
  258. if (!string.IsNullOrEmpty(RightList))
  259. {
  260. string[] Rights = RightList.TrimEnd(',').Split(',');
  261. foreach (string Right in Rights)
  262. {
  263. string[] list = Right.Split('_');
  264. bsdb.MenuRightNew.Add(new MenuRightNew()
  265. {
  266. MenuId = Id + "_" + list[0],
  267. Name = list[1],
  268. });
  269. }
  270. }
  271. RightDicNew edit = bsdb.RightDicNew.FirstOrDefault(m => m.Id == Id);
  272. if(edit != null)
  273. {
  274. edit.OtherRight = OtherRight;
  275. }
  276. bsdb.SaveChanges();
  277. return "success";
  278. }
  279. #endregion
  280. #region 删除
  281. /// <summary>
  282. /// 删除
  283. /// </summary>
  284. /// <returns></returns>
  285. public string Delete(string Id)
  286. {
  287. string[] idlist = Id.Split(new char[] { ',' });
  288. foreach (string subid in idlist)
  289. {
  290. RightDicNew edit = bsdb.RightDicNew.FirstOrDefault(m => m.Id == subid);
  291. if(edit != null)
  292. {
  293. bsdb.RightDicNew.Remove(edit);
  294. }
  295. }
  296. AddSysLog(Id, "RightDicNew", "del");
  297. bsdb.SaveChanges();
  298. return "success";
  299. }
  300. #endregion
  301. #region 排序
  302. /// <summary>
  303. /// 排序
  304. /// </summary>
  305. /// <param name="Id"></param>
  306. public string Sort(string Id, int Sort)
  307. {
  308. RightDicNew edit = bsdb.RightDicNew.FirstOrDefault(m => m.Id == Id);
  309. if (edit != null)
  310. {
  311. edit.Sort = Sort;
  312. bsdb.SaveChanges();
  313. }
  314. return "success";
  315. }
  316. #endregion
  317. #region 设置快捷方式
  318. /// <summary>
  319. /// 设置快捷方式
  320. /// </summary>
  321. /// <param name="Id"></param>
  322. public string SetMainMenu(string Id, bool value)
  323. {
  324. RightDicNew edit = bsdb.RightDicNew.FirstOrDefault(m => m.Id == Id);
  325. if (edit != null)
  326. {
  327. if (value)
  328. {
  329. edit.MainMenu = 1;
  330. }
  331. else
  332. {
  333. edit.MainMenu = 0;
  334. }
  335. bsdb.SaveChanges();
  336. }
  337. return "success";
  338. }
  339. #endregion
  340. #region 统计
  341. /// <summary>
  342. /// 统计
  343. /// </summary>
  344. /// <param name="Id"></param>
  345. public string SetMainStat(string Id, bool value)
  346. {
  347. RightDicNew edit = bsdb.RightDicNew.FirstOrDefault(m => m.Id == Id);
  348. if (edit != null)
  349. {
  350. if (value)
  351. {
  352. edit.MainStat = 1;
  353. }
  354. else
  355. {
  356. edit.MainStat = 0;
  357. }
  358. bsdb.SaveChanges();
  359. }
  360. return "success";
  361. }
  362. #endregion
  363. #region 主界面数据列表
  364. /// <summary>
  365. /// 主界面数据列表
  366. /// </summary>
  367. /// <param name="Id"></param>
  368. public string SetMainDataList(string Id, bool value)
  369. {
  370. RightDicNew edit = bsdb.RightDicNew.FirstOrDefault(m => m.Id == Id);
  371. if (edit != null)
  372. {
  373. if (value)
  374. {
  375. edit.MainDataList = 1;
  376. }
  377. else
  378. {
  379. edit.MainDataList = 0;
  380. }
  381. bsdb.SaveChanges();
  382. }
  383. return "success";
  384. }
  385. #endregion
  386. #region 设置图标
  387. /// <summary>
  388. /// 设置图标
  389. /// </summary>
  390. /// <param name="Id"></param>
  391. public string SetIcon(string Id, string value)
  392. {
  393. RightDicNew edit = bsdb.RightDicNew.FirstOrDefault(m => m.Id == Id);
  394. if (edit != null)
  395. {
  396. edit.Icon = value;
  397. bsdb.SaveChanges();
  398. }
  399. return "success";
  400. }
  401. #endregion
  402. }
  403. }