BaseSystemController.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using System.Web;
  7. using System.Web.Mvc;
  8. using Abp.Auditing;
  9. using Abp.Domain.Repositories;
  10. using Abp.MultiTenancy;
  11. using Abp.Runtime.Caching;
  12. using Abp.Timing;
  13. using Abp.Web.Models;
  14. using Abp.Web.Mvc.Authorization;
  15. using Abp.Web.Security.AntiForgery;
  16. using WeOnlineApp.Authorization;
  17. using WeOnlineApp.Authorization.Roles;
  18. using WeOnlineApp.BaseInfo;
  19. using WeOnlineApp.BaseSystem.AuditLog;
  20. using WeOnlineApp.BaseSystem.Sessions.Dto;
  21. using WeOnlineApp.Configuration;
  22. using IwbZero.Auditing;
  23. using IwbZero.Authorization.Base.Users;
  24. using IwbZero.ToolCommon.LogHelpers;
  25. using IwbZero.ToolCommon.StringModel;
  26. namespace WeOnlineApp.Controllers
  27. {
  28. [DisableAuditing]
  29. [AbpMvcAuthorize(PermissionNames.PagesSystemMg), AuditLog("ϵͳ��Ϣ����")]
  30. public class BaseSystemController : IwbControllerBase
  31. {
  32. public BaseSystemController(ICacheManager cacheManager, IRepository<Role> roleRepository, IRepository<SysFunction> functionRepository, IAuditLogsAppService logsAppService)
  33. {
  34. RoleRepository = roleRepository;
  35. FunctionRepository = functionRepository;
  36. LogsAppService = logsAppService;
  37. CacheManager = cacheManager;
  38. }
  39. private IRepository<Role> RoleRepository { get; }
  40. private IRepository<SysFunction> FunctionRepository { get; }
  41. private IAuditLogsAppService LogsAppService { get; }
  42. [AbpMvcAuthorize(PermissionNames.PagesSystemMgTenantMg), AuditLog("ϵͳ�⻧")]
  43. public async Task<ActionResult> SysTenants()
  44. {
  45. if (AbpSession.MultiTenancySide != MultiTenancySides.Host)
  46. {
  47. ThrowError(IwbLanguageMessage.NoPermissionOperation);
  48. }
  49. ViewBag.IsActive = await StatesManager.GetSelectListAsync("Active", "Status");
  50. return View();
  51. }
  52. [AbpMvcAuthorize(PermissionNames.PagesSystemMgRoleMg), AuditLog("ϵͳ��ɫ")]
  53. public async Task<ActionResult> SysRoles()
  54. {
  55. var user = AbpSession.GetCurrentUser();
  56. ViewBag.IsActive = await StatesManager.GetSelectListAsync("Active", "Status");
  57. ViewBag.RoleType = await StatesManager.GetSelectListAsync("UserRole", "UserRoleType");
  58. var accountType = await StatesManager.GetSelectListAsync("Account", "AccountType");
  59. ViewBag.AccountType = accountType;
  60. ViewBag.AccountTypeName = accountType.FirstOrDefault(a => a.Value == (user.AccountType + ""))?.Text ?? "";
  61. ViewBag.CurrentUser = user;
  62. return View();
  63. }
  64. [AbpMvcAuthorize(PermissionNames.PagesSystemMgUserMg), AuditLog("ϵͳ�û�")]
  65. public async Task<ActionResult> SysUsers()
  66. {
  67. var user = AbpSession.GetCurrentUser();
  68. ViewBag.IsActive = await StatesManager.GetSelectListAsync("Active", "Status");
  69. ViewBag.UserType = await StatesManager.GetSelectListAsync("UserRole", "UserRoleType");
  70. var accountType = await StatesManager.GetSelectListAsync("Account", "AccountType");
  71. ViewBag.AccountType = accountType;
  72. ViewBag.AccountTypeName = accountType.FirstOrDefault(a => a.Value == (user.AccountType + ""))?.Text ?? "";
  73. ViewBag.CurrentUser = user;
  74. if (AbpSession.UserType == UsersAndRolesTypeDefinition.Supper ||
  75. AbpSession.UserType == UsersAndRolesTypeDefinition.System)
  76. {
  77. var sList = new List<SelectListItem>();
  78. var list = RoleRepository.GetAllList(a =>
  79. (AbpSession.UserName == UserBase.AdminUserName || a.RoleType > AbpSession.UserType) &&
  80. (AbpSession.AccountType == AccountTypeDefinition.System || a.AccountType == AbpSession.AccountType));
  81. foreach (var l in list)
  82. {
  83. sList.Add(new SelectListItem { Text = l.DisplayName, Value = l.Name });
  84. }
  85. ViewBag.Roles = sList;
  86. }
  87. return View();
  88. }
  89. [AbpMvcAuthorize(PermissionNames.PagesSystemMgStateMg), AuditLog("ϵͳ�ֵ�")]
  90. public ActionResult SysStates()
  91. {
  92. return View();
  93. }
  94. [AbpMvcAuthorize(PermissionNames.PagesSystemMgSettingMg), AuditLog("ϵͳ����")]
  95. public ActionResult SysSettings()
  96. {
  97. return View();
  98. }
  99. [AbpMvcAuthorize(PermissionNames.PagesSystemMgFunctionMg), AuditLog("���ܲ˵�")]
  100. public async Task<ActionResult> SysFunctions()
  101. {
  102. ViewBag.FunctionType = await StatesManager.GetSelectListAsync("Function", "FunctionType");
  103. return View();
  104. }
  105. [AbpMvcAuthorize(PermissionNames.PagesSystemMgLogMg), AuditLog("ϵͳ��־")]
  106. public ActionResult SysLogs()
  107. {
  108. ViewBag.ServiceNames = LogsAppService.GetLogServiceSelectListStrs();
  109. return View();
  110. }
  111. public ActionResult Notification()
  112. {
  113. return View();
  114. }
  115. [AbpMvcAuthorize(PermissionNames.PagesSystemMgHelpMg), AuditLog("ϵͳ����")]
  116. public async Task<ActionResult> SysHelps()
  117. {
  118. ViewBag.Classification = await StatesManager.GetSelectListAsync("SysHelp", "Classification");
  119. var funs = await FunctionRepository.GetAllListAsync(a =>
  120. a.FunctionType == FunctionTypeDefinition.Catalog || a.FunctionType == FunctionTypeDefinition.Menu);
  121. ViewBag.FunctionMenu = "";
  122. foreach (var fun in funs)
  123. {
  124. ViewBag.FunctionMenu += fun.ParentNo == "0"
  125. ? $"<option value=\"{fun.FunctionNo}\" disabled selected>{fun.FunctionName}</option>"
  126. : $"<option value=\"{fun.FunctionNo}\" parent=\"{fun.ParentNo}\">{fun.FunctionName}</option>";
  127. }
  128. return View();
  129. }
  130. [DisableAbpAntiForgeryTokenValidation]
  131. [DontWrapResult]
  132. public ActionResult KindEditorUploadFile()
  133. {
  134. try
  135. {
  136. if (!int.TryParse(SettingManager.GetValue(IwbSettingNames.UploadFileMaxSize), out int maxSize))
  137. {
  138. maxSize = 10;
  139. }
  140. maxSize = maxSize < 1 ? 1 : maxSize > 100 ? 100 : maxSize;
  141. HttpPostedFileBase file = Request.Files["imgFile"];
  142. if (file == null)
  143. {
  144. return Json(new { error = 1, message = L("FileUploadNoFile") });
  145. }
  146. if (file.ContentLength >= 1024 * 1024 * maxSize)
  147. {
  148. return Json(new { error = 1, message = string.Format(L("FileUploadMaxSize"), $"{maxSize}M") });
  149. }
  150. var fileName = $"{Clock.Now:yyyyMMddHHmmss}_{file.FileName}";
  151. string lcPath = SettingManager.GetValue(IwbSettingNames.DownloadPath) + "/KindEditorUploadFile";
  152. string dir = Request["dir"];
  153. if (!string.IsNullOrEmpty(dir))
  154. {
  155. lcPath = Path.Combine(lcPath, dir);
  156. }
  157. var filePath = Server.MapPath($"~/{lcPath}");
  158. if (!Directory.Exists(filePath))
  159. {
  160. Directory.CreateDirectory(filePath);
  161. }
  162. file.SaveAs(Path.Combine(filePath, fileName));
  163. return Json(new { error = 0, url = Path.Combine(lcPath, fileName), fileName = file.FileName }, "text/html;charset=UTF-8");
  164. }
  165. catch (Exception e)
  166. {
  167. this.LogError(e);
  168. return Json(new { error = 1, message = L("FileUploadException") }, "text/html;charset=UTF-8");
  169. }
  170. }
  171. }
  172. [DisableAuditing]
  173. [AbpMvcAuthorize(PermissionNames.PagesUserHelpInfo), AuditLog("ϵͳ����")]
  174. public class HelpController : IwbControllerBase
  175. {
  176. public HelpController(IRepository<SysHelp> helpRepository)
  177. {
  178. HelpRepository = helpRepository;
  179. }
  180. private IRepository<SysHelp> HelpRepository { get; }
  181. [AbpMvcAuthorize(PermissionNames.PagesUserHelpInfo), AuditLog("ϵͳ����")]
  182. public async Task<ActionResult> Index()
  183. {
  184. var helps = (await HelpRepository.GetAllListAsync()).OrderBy(a => a.Sequence).ToList();
  185. return View(helps);
  186. }
  187. }
  188. }