RightDicController.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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 RightDicController : BaseController
  23. {
  24. public RightDicController(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(RightDic 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(RightDic data, int page = 1, int limit = 30)
  46. {
  47. List<RightDic> diclist = bsdb.RightDic.OrderBy(m => m.Id).ToList();
  48. foreach (RightDic dic in diclist)
  49. {
  50. int nameLength = dic.Id.Split('_').Length;
  51. for (int i = 1; i < nameLength; i++)
  52. {
  53. dic.Name = "  " + dic.Name;
  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 Edit(string right, string Id = "")
  70. {
  71. ViewBag.RightInfo = RightInfo;
  72. ViewBag.right = right;
  73. RightDic editData = bsdb.RightDic.FirstOrDefault(m => m.Id == Id) ?? new RightDic();
  74. ViewBag.data = editData;
  75. string PColId = "";
  76. if (editData.Id.Contains("_"))
  77. {
  78. PColId = editData.Id.Substring(0, editData.Id.LastIndexOf("_"));
  79. }
  80. else
  81. {
  82. PColId = editData.Id;
  83. }
  84. ViewBag.OldPColId = PColId;
  85. ViewBag.PColId = PColId;
  86. return View();
  87. }
  88. [HttpPost]
  89. public string EditPost(RightDic data, string OldPColId, string PColId)
  90. {
  91. RightDic adddic = new RightDic();
  92. bool op = false;
  93. RightDic dic = bsdb.RightDic.FirstOrDefault(m => m.Id == data.Id);
  94. if (dic != null)
  95. {
  96. if (OldPColId != PColId)
  97. {
  98. string words = "123456789abcdefghijklmnopqrstuvwxyz";
  99. if (!string.IsNullOrEmpty(PColId))
  100. {
  101. int Len = PColId.Length + 2;
  102. int checkcount = bsdb.RightDic.Count(m => m.Id.StartsWith(PColId) && m.Id.Length == Len);
  103. if (checkcount > 0)
  104. {
  105. RightDic checkdic = bsdb.RightDic.Where(m => m.Id.StartsWith(PColId) && m.Id.Length == Len).OrderByDescending(m => m.Id).FirstOrDefault();
  106. string last_id = "";
  107. string[] idlist = checkdic.Id.Split('_');
  108. last_id = idlist[idlist.Length - 1];
  109. last_id = words.Substring(words.IndexOf(last_id) + 1, 1);
  110. adddic.Id = PColId + "_" + last_id;
  111. }
  112. else
  113. {
  114. adddic.Id = PColId + "_1";
  115. }
  116. }
  117. else
  118. {
  119. int checkcount = bsdb.RightDic.Count(m => m.Id.Length == 1);
  120. if (checkcount > 0)
  121. {
  122. RightDic checkdic = bsdb.RightDic.Where(m => m.Id.Length == 1).OrderByDescending(m => m.Id).FirstOrDefault();
  123. string last_id = words.Substring(words.IndexOf(checkdic.Id) + 1, 1);
  124. adddic.Id = PColId + "_" + last_id;
  125. }
  126. else
  127. {
  128. adddic.Id = "1";
  129. }
  130. }
  131. adddic.Name = data.Name;
  132. adddic.MainMenu = data.MainMenu;
  133. adddic.MainStat = data.MainStat;
  134. adddic.MainDataList = data.MainDataList;
  135. adddic.Url = dic.Url;
  136. adddic.RightLevel = dic.RightLevel;
  137. bsdb.RightDic.Remove(dic);
  138. op = true;
  139. }
  140. else
  141. {
  142. dic.Name = data.Name;
  143. dic.MainMenu = data.MainMenu;
  144. dic.MainStat = data.MainStat;
  145. dic.MainDataList = data.MainDataList;
  146. }
  147. }
  148. AddSysLog(data.Id.ToString(), "RightDic", "update");
  149. bsdb.SaveChanges();
  150. if (op)
  151. {
  152. bsdb.RightDic.Add(adddic);
  153. bsdb.SaveChanges();
  154. }
  155. return "success";
  156. }
  157. #endregion
  158. #region 修改
  159. /// <summary>
  160. /// 修改
  161. /// </summary>
  162. /// <returns></returns>
  163. public IActionResult RightSet(string Id = "")
  164. {
  165. List<OperateRightList> rights = bsdb.OperateRightList.ToList();
  166. ViewBag.rights = rights;
  167. ViewBag.Id = Id;
  168. List<string> RightList = new List<string>();
  169. List<MenuRight> MenuRights = bsdb.MenuRight.Where(m => m.MenuId.StartsWith(Id)).ToList();
  170. foreach (MenuRight sub in MenuRights)
  171. {
  172. RightList.Add(sub.MenuId.Replace(Id + "_", "") + "_" + sub.Name);
  173. }
  174. ViewBag.RightList = RightList;
  175. RightDic editData = bsdb.RightDic.FirstOrDefault(m => m.Id == Id) ?? new RightDic();
  176. ViewBag.OtherRight = editData.OtherRight;
  177. return View();
  178. }
  179. [HttpPost]
  180. public string RightSetPost(string Id, string OtherRight, string RightList)
  181. {
  182. IQueryable<MenuRight> MenuRights = bsdb.MenuRight.Where(m => m.MenuId.StartsWith(Id));
  183. foreach (MenuRight sub in MenuRights)
  184. {
  185. bsdb.MenuRight.Remove(sub);
  186. }
  187. bsdb.SaveChanges();
  188. if (!string.IsNullOrEmpty(RightList))
  189. {
  190. string[] Rights = RightList.TrimEnd(',').Split(',');
  191. foreach (string Right in Rights)
  192. {
  193. string[] list = Right.Split('_');
  194. bsdb.MenuRight.Add(new MenuRight()
  195. {
  196. MenuId = Id + "_" + list[0],
  197. Name = list[1],
  198. });
  199. }
  200. }
  201. RightDic edit = bsdb.RightDic.FirstOrDefault(m => m.Id == Id);
  202. if(edit != null)
  203. {
  204. edit.OtherRight = OtherRight;
  205. }
  206. bsdb.SaveChanges();
  207. return "success";
  208. }
  209. #endregion
  210. #region 排序
  211. /// <summary>
  212. /// 排序
  213. /// </summary>
  214. /// <param name="Id"></param>
  215. public string Sort(string Id, int Sort)
  216. {
  217. RightDic edit = bsdb.RightDic.FirstOrDefault(m => m.Id == Id);
  218. if (edit != null)
  219. {
  220. edit.Sort = Sort;
  221. bsdb.SaveChanges();
  222. }
  223. return "success";
  224. }
  225. #endregion
  226. #region 设置快捷方式
  227. /// <summary>
  228. /// 设置快捷方式
  229. /// </summary>
  230. /// <param name="Id"></param>
  231. public string SetMainMenu(string Id, bool value)
  232. {
  233. RightDic edit = bsdb.RightDic.FirstOrDefault(m => m.Id == Id);
  234. if (edit != null)
  235. {
  236. if (value)
  237. {
  238. edit.MainMenu = 1;
  239. }
  240. else
  241. {
  242. edit.MainMenu = 0;
  243. }
  244. bsdb.SaveChanges();
  245. }
  246. return "success";
  247. }
  248. #endregion
  249. #region 统计
  250. /// <summary>
  251. /// 统计
  252. /// </summary>
  253. /// <param name="Id"></param>
  254. public string SetMainStat(string Id, bool value)
  255. {
  256. RightDic edit = bsdb.RightDic.FirstOrDefault(m => m.Id == Id);
  257. if (edit != null)
  258. {
  259. if (value)
  260. {
  261. edit.MainStat = 1;
  262. }
  263. else
  264. {
  265. edit.MainStat = 0;
  266. }
  267. bsdb.SaveChanges();
  268. }
  269. return "success";
  270. }
  271. #endregion
  272. #region 主界面数据列表
  273. /// <summary>
  274. /// 主界面数据列表
  275. /// </summary>
  276. /// <param name="Id"></param>
  277. public string SetMainDataList(string Id, bool value)
  278. {
  279. RightDic edit = bsdb.RightDic.FirstOrDefault(m => m.Id == Id);
  280. if (edit != null)
  281. {
  282. if (value)
  283. {
  284. edit.MainDataList = 1;
  285. }
  286. else
  287. {
  288. edit.MainDataList = 0;
  289. }
  290. bsdb.SaveChanges();
  291. }
  292. return "success";
  293. }
  294. #endregion
  295. #region 设置图标
  296. /// <summary>
  297. /// 设置图标
  298. /// </summary>
  299. /// <param name="Id"></param>
  300. public string SetIcon(string Id, string value)
  301. {
  302. RightDic edit = bsdb.RightDic.FirstOrDefault(m => m.Id == Id);
  303. if (edit != null)
  304. {
  305. edit.Icon = value;
  306. bsdb.SaveChanges();
  307. }
  308. return "success";
  309. }
  310. #endregion
  311. }
  312. }