using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using System.Web; using System.Web.Mvc; using Abp.Auditing; using Abp.Domain.Repositories; using Abp.MultiTenancy; using Abp.Runtime.Caching; using Abp.Timing; using Abp.Web.Models; using Abp.Web.Mvc.Authorization; using Abp.Web.Security.AntiForgery; using WePlatform.Authorization; using WePlatform.Authorization.Roles; using WePlatform.BaseInfo; using WePlatform.BaseSystem.AuditLog; using WePlatform.BaseSystem.Sessions.Dto; using WePlatform.Configuration; using IwbZero.Auditing; using IwbZero.Authorization.Base.Users; using IwbZero.ToolCommon.LogHelpers; using IwbZero.ToolCommon.StringModel; namespace WePlatform.Controllers { [DisableAuditing] [AbpMvcAuthorize(PermissionNames.PagesSystemMg), AuditLog("系统信息管理")] public class BaseSystemController : IwbControllerBase { public BaseSystemController(ICacheManager cacheManager, IRepository roleRepository, IRepository functionRepository, IAuditLogsAppService logsAppService) { RoleRepository = roleRepository; FunctionRepository = functionRepository; LogsAppService = logsAppService; CacheManager = cacheManager; } private IRepository RoleRepository { get; } private IRepository FunctionRepository { get; } private IAuditLogsAppService LogsAppService { get; } [AbpMvcAuthorize(PermissionNames.PagesSystemMgTenantMg), AuditLog("系统租户")] public async Task SysTenants() { if (AbpSession.MultiTenancySide != MultiTenancySides.Host) { ThrowError(IwbLanguageMessage.NoPermissionOperation); } ViewBag.IsActive = await StatesManager.GetSelectListAsync("Active", "Status"); return View(); } [AbpMvcAuthorize(PermissionNames.PagesSystemMgRoleMg), AuditLog("系统角色")] public async Task SysRoles() { var user = AbpSession.GetCurrentUser(); ViewBag.IsActive = await StatesManager.GetSelectListAsync("Active", "Status"); ViewBag.RoleType = await StatesManager.GetSelectListAsync("UserRole", "UserRoleType"); var accountType = await StatesManager.GetSelectListAsync("Account", "AccountType"); ViewBag.AccountType = accountType; ViewBag.AccountTypeName = accountType.FirstOrDefault(a => a.Value == (user.AccountType + ""))?.Text ?? ""; ViewBag.CurrentUser = user; return View(); } [AbpMvcAuthorize(PermissionNames.PagesSystemMgUserMg), AuditLog("系统用户")] public async Task SysUsers() { var user = AbpSession.GetCurrentUser(); ViewBag.IsActive = await StatesManager.GetSelectListAsync("Active", "Status"); ViewBag.UserType = await StatesManager.GetSelectListAsync("UserRole", "UserRoleType"); var accountType = await StatesManager.GetSelectListAsync("Account", "AccountType"); ViewBag.AccountType = accountType; ViewBag.AccountTypeName = accountType.FirstOrDefault(a => a.Value == (user.AccountType + ""))?.Text ?? ""; ViewBag.CurrentUser = user; if (AbpSession.UserType == UsersAndRolesTypeDefinition.Supper || AbpSession.UserType == UsersAndRolesTypeDefinition.System) { var sList = new List(); var list = RoleRepository.GetAllList(a => (AbpSession.UserName == UserBase.AdminUserName || a.RoleType > AbpSession.UserType) && (AbpSession.AccountType == AccountTypeDefinition.System || a.AccountType == AbpSession.AccountType)); foreach (var l in list) { sList.Add(new SelectListItem { Text = l.DisplayName, Value = l.Name }); } ViewBag.Roles = sList; } return View(); } [AbpMvcAuthorize(PermissionNames.PagesSystemMgStateMg), AuditLog("系统字典")] public ActionResult SysStates() { return View(); } [AbpMvcAuthorize(PermissionNames.PagesSystemMgSettingMg), AuditLog("系统配置")] public ActionResult SysSettings() { return View(); } [AbpMvcAuthorize(PermissionNames.PagesSystemMgFunctionMg), AuditLog("功能菜单")] public async Task SysFunctions() { ViewBag.FunctionType = await StatesManager.GetSelectListAsync("Function", "FunctionType"); return View(); } [AbpMvcAuthorize(PermissionNames.PagesSystemMgLogMg), AuditLog("系统日志")] public ActionResult SysLogs() { ViewBag.ServiceNames = LogsAppService.GetLogServiceSelectListStrs(); return View(); } public ActionResult Notification() { return View(); } [AbpMvcAuthorize(PermissionNames.PagesSystemMgHelpMg), AuditLog("系统帮助")] public async Task SysHelps() { ViewBag.Classification = await StatesManager.GetSelectListAsync("SysHelp", "Classification"); var funs = await FunctionRepository.GetAllListAsync(a => a.FunctionType == FunctionTypeDefinition.Catalog || a.FunctionType == FunctionTypeDefinition.Menu); ViewBag.FunctionMenu = ""; foreach (var fun in funs) { ViewBag.FunctionMenu += fun.ParentNo == "0" ? $"" : $""; } return View(); } [DisableAbpAntiForgeryTokenValidation] [DontWrapResult] public ActionResult KindEditorUploadFile() { try { if (!int.TryParse(SettingManager.GetValue(IwbSettingNames.UploadFileMaxSize), out int maxSize)) { maxSize = 10; } maxSize = maxSize < 1 ? 1 : maxSize > 100 ? 100 : maxSize; HttpPostedFileBase file = Request.Files["imgFile"]; if (file == null) { return Json(new { error = 1, message = L("FileUploadNoFile") }); } if (file.ContentLength >= 1024 * 1024 * maxSize) { return Json(new { error = 1, message = string.Format(L("FileUploadMaxSize"), $"{maxSize}M") }); } var fileName = $"{Clock.Now:yyyyMMddHHmmss}_{file.FileName}"; string lcPath = SettingManager.GetValue(IwbSettingNames.DownloadPath) + "/KindEditorUploadFile"; string dir = Request["dir"]; if (!string.IsNullOrEmpty(dir)) { lcPath = Path.Combine(lcPath, dir); } var filePath = Server.MapPath($"~/{lcPath}"); if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } file.SaveAs(Path.Combine(filePath, fileName)); return Json(new { error = 0, url = Path.Combine(lcPath, fileName), fileName = file.FileName }, "text/html;charset=UTF-8"); } catch (Exception e) { this.LogError(e); return Json(new { error = 1, message = L("FileUploadException") }, "text/html;charset=UTF-8"); } } } [DisableAuditing] [AbpMvcAuthorize(PermissionNames.PagesUserHelpInfo), AuditLog("系统帮助")] public class HelpController : IwbControllerBase { public HelpController(IRepository helpRepository) { HelpRepository = helpRepository; } private IRepository HelpRepository { get; } [AbpMvcAuthorize(PermissionNames.PagesUserHelpInfo), AuditLog("系统帮助")] public async Task Index() { var helps = (await HelpRepository.GetAllListAsync()).OrderBy(a => a.Sequence).ToList(); return View(helps); } } }