BaseSystemController.cs 8.1 KB

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