123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- /*
- * 单页内容
- */
- using System;
- using System.Web;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Options;
- using MySystem.BsModels;
- using Library;
- using LitJson;
- using MySystemLib;
- namespace MySystem.Areas.Admin.Controllers
- {
- [Area("Admin")]
- [Route("Admin/[controller]/[action]")]
- public class RightDicController : BaseController
- {
- public RightDicController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
- {
- OtherMySqlConn.connstr = ConfigurationManager.AppSettings["BsSqlConnStr"].ToString();
- }
- #region 单页内容列表
- /// <summary>
- /// 根据条件查询单页内容列表
- /// </summary>
- /// <returns></returns>
- public IActionResult Index(RightDic data, string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- #endregion
- #region 根据条件查询单页内容列表
- /// <summary>
- /// 单页内容列表
- /// </summary>
- /// <returns></returns>
- public JsonResult IndexData(RightDic data, int page = 1, int limit = 30)
- {
- List<RightDic> diclist = bsdb.RightDic.OrderBy(m => m.Id).ToList();
- foreach (RightDic dic in diclist)
- {
- int nameLength = dic.Id.Split('_').Length;
- for (int i = 1; i < nameLength; i++)
- {
- dic.Name = " " + dic.Name;
- }
- }
- Dictionary<string, object> obj = new Dictionary<string, object>();
- obj.Add("code", 0);
- obj.Add("msg", "");
- obj.Add("count", diclist.Count);
- obj.Add("data", diclist);
- return Json(obj);
- }
- #endregion
- #region 修改
- /// <summary>
- /// 修改
- /// </summary>
- /// <returns></returns>
- public IActionResult Edit(string right, string Id = "")
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- RightDic editData = bsdb.RightDic.FirstOrDefault(m => m.Id == Id) ?? new RightDic();
- ViewBag.data = editData;
- string PColId = "";
- if (editData.Id.Contains("_"))
- {
- PColId = editData.Id.Substring(0, editData.Id.LastIndexOf("_"));
- }
- else
- {
- PColId = editData.Id;
- }
- ViewBag.OldPColId = PColId;
- ViewBag.PColId = PColId;
- return View();
- }
- [HttpPost]
- public string EditPost(RightDic data, string OldPColId, string PColId)
- {
- RightDic adddic = new RightDic();
- bool op = false;
- RightDic dic = bsdb.RightDic.FirstOrDefault(m => m.Id == data.Id);
- if (dic != null)
- {
- if (OldPColId != PColId)
- {
- string words = "123456789abcdefghijklmnopqrstuvwxyz";
- if (!string.IsNullOrEmpty(PColId))
- {
- int Len = PColId.Length + 2;
- int checkcount = bsdb.RightDic.Count(m => m.Id.StartsWith(PColId) && m.Id.Length == Len);
- if (checkcount > 0)
- {
- RightDic checkdic = bsdb.RightDic.Where(m => m.Id.StartsWith(PColId) && m.Id.Length == Len).OrderByDescending(m => m.Id).FirstOrDefault();
- string last_id = "";
- string[] idlist = checkdic.Id.Split('_');
- last_id = idlist[idlist.Length - 1];
- last_id = words.Substring(words.IndexOf(last_id) + 1, 1);
- adddic.Id = PColId + "_" + last_id;
- }
- else
- {
- adddic.Id = PColId + "_1";
- }
- }
- else
- {
- int checkcount = bsdb.RightDic.Count(m => m.Id.Length == 1);
- if (checkcount > 0)
- {
- RightDic checkdic = bsdb.RightDic.Where(m => m.Id.Length == 1).OrderByDescending(m => m.Id).FirstOrDefault();
- string last_id = words.Substring(words.IndexOf(checkdic.Id) + 1, 1);
- adddic.Id = PColId + "_" + last_id;
- }
- else
- {
- adddic.Id = "1";
- }
- }
- adddic.Name = data.Name;
- adddic.MainMenu = data.MainMenu;
- adddic.MainStat = data.MainStat;
- adddic.MainDataList = data.MainDataList;
- adddic.Url = dic.Url;
- adddic.RightLevel = dic.RightLevel;
- bsdb.RightDic.Remove(dic);
- op = true;
- }
- else
- {
- dic.Name = data.Name;
- dic.MainMenu = data.MainMenu;
- dic.MainStat = data.MainStat;
- dic.MainDataList = data.MainDataList;
- }
- }
- AddSysLog(data.Id.ToString(), "RightDic", "update");
- bsdb.SaveChanges();
- if (op)
- {
- bsdb.RightDic.Add(adddic);
- bsdb.SaveChanges();
- }
- return "success";
- }
- #endregion
- #region 修改
- /// <summary>
- /// 修改
- /// </summary>
- /// <returns></returns>
- public IActionResult RightSet(string Id = "")
- {
- List<OperateRightList> rights = bsdb.OperateRightList.ToList();
- ViewBag.rights = rights;
- ViewBag.Id = Id;
- List<string> RightList = new List<string>();
- List<MenuRight> MenuRights = bsdb.MenuRight.Where(m => m.MenuId.StartsWith(Id)).ToList();
- foreach (MenuRight sub in MenuRights)
- {
- RightList.Add(sub.MenuId.Replace(Id + "_", "") + "_" + sub.Name);
- }
- ViewBag.RightList = RightList;
- RightDic editData = bsdb.RightDic.FirstOrDefault(m => m.Id == Id) ?? new RightDic();
- ViewBag.OtherRight = editData.OtherRight;
- return View();
- }
- [HttpPost]
- public string RightSetPost(string Id, string OtherRight, string RightList)
- {
- IQueryable<MenuRight> MenuRights = bsdb.MenuRight.Where(m => m.MenuId.StartsWith(Id));
- foreach (MenuRight sub in MenuRights)
- {
- bsdb.MenuRight.Remove(sub);
- }
- bsdb.SaveChanges();
- if (!string.IsNullOrEmpty(RightList))
- {
- string[] Rights = RightList.TrimEnd(',').Split(',');
- foreach (string Right in Rights)
- {
- string[] list = Right.Split('_');
- bsdb.MenuRight.Add(new MenuRight()
- {
- MenuId = Id + "_" + list[0],
- Name = list[1],
- });
- }
- }
- RightDic edit = bsdb.RightDic.FirstOrDefault(m => m.Id == Id);
- if(edit != null)
- {
- edit.OtherRight = OtherRight;
- }
- bsdb.SaveChanges();
- return "success";
- }
- #endregion
- #region 排序
- /// <summary>
- /// 排序
- /// </summary>
- /// <param name="Id"></param>
- public string Sort(string Id, int Sort)
- {
- RightDic edit = bsdb.RightDic.FirstOrDefault(m => m.Id == Id);
- if (edit != null)
- {
- edit.Sort = Sort;
- bsdb.SaveChanges();
- }
- return "success";
- }
- #endregion
- #region 设置快捷方式
- /// <summary>
- /// 设置快捷方式
- /// </summary>
- /// <param name="Id"></param>
- public string SetMainMenu(string Id, bool value)
- {
- RightDic edit = bsdb.RightDic.FirstOrDefault(m => m.Id == Id);
- if (edit != null)
- {
- if (value)
- {
- edit.MainMenu = 1;
- }
- else
- {
- edit.MainMenu = 0;
- }
- bsdb.SaveChanges();
- }
- return "success";
- }
- #endregion
- #region 统计
- /// <summary>
- /// 统计
- /// </summary>
- /// <param name="Id"></param>
- public string SetMainStat(string Id, bool value)
- {
- RightDic edit = bsdb.RightDic.FirstOrDefault(m => m.Id == Id);
- if (edit != null)
- {
- if (value)
- {
- edit.MainStat = 1;
- }
- else
- {
- edit.MainStat = 0;
- }
- bsdb.SaveChanges();
- }
- return "success";
- }
- #endregion
- #region 主界面数据列表
- /// <summary>
- /// 主界面数据列表
- /// </summary>
- /// <param name="Id"></param>
- public string SetMainDataList(string Id, bool value)
- {
- RightDic edit = bsdb.RightDic.FirstOrDefault(m => m.Id == Id);
- if (edit != null)
- {
- if (value)
- {
- edit.MainDataList = 1;
- }
- else
- {
- edit.MainDataList = 0;
- }
- bsdb.SaveChanges();
- }
- return "success";
- }
- #endregion
- #region 设置图标
- /// <summary>
- /// 设置图标
- /// </summary>
- /// <param name="Id"></param>
- public string SetIcon(string Id, string value)
- {
- RightDic edit = bsdb.RightDic.FirstOrDefault(m => m.Id == Id);
- if (edit != null)
- {
- edit.Icon = value;
- bsdb.SaveChanges();
- }
- return "success";
- }
- #endregion
- }
- }
|