You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
295 lines
12 KiB
295 lines
12 KiB
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.IO;
|
|
using System.Runtime.InteropServices;
|
|
using System.Threading.Tasks;
|
|
using Znyc.Admin.AspNetCore.Controllers;
|
|
using Znyc.Admin.AspNetCore.Entitys;
|
|
using Znyc.Admin.AspNetCore.Mvc;
|
|
using Znyc.Admin.AspNetCore.Mvc.Filter;
|
|
using Znyc.Admin.Commons;
|
|
using Znyc.Admin.Commons.Cache;
|
|
using Znyc.Admin.Commons.Encrypt;
|
|
using Znyc.Admin.Commons.Entitys;
|
|
using Znyc.Admin.Commons.Extend;
|
|
using Znyc.Admin.Commons.Helpers;
|
|
using Znyc.Admin.Commons.Json;
|
|
using Znyc.Admin.Commons.Log;
|
|
using Znyc.Admin.Commons.Mapping;
|
|
using Znyc.Admin.Security.Dtos;
|
|
using Znyc.Admin.Security.Entitys;
|
|
using Znyc.Admin.Security.IServices;
|
|
using Znyc.Admin.WebApi.Areas.Security.Entitys;
|
|
|
|
namespace Znyc.Admin.WebApi.Areas.Security
|
|
{
|
|
/// <summary>
|
|
/// 系统基本信息
|
|
/// </summary>
|
|
[Route("api/Security/[controller]")]
|
|
[ApiController]
|
|
public class SysSettingController : ApiController
|
|
{
|
|
private readonly IWebHostEnvironment _hostingEnvironment;
|
|
private readonly IAdminUserService _adminUserService;
|
|
private readonly IMenuService _menuService;
|
|
private readonly IRoleService _roleService;
|
|
private readonly IAPPService _aPPService;
|
|
private readonly IUserService _userService;
|
|
private readonly IStatisticalService _statisticalService;
|
|
private readonly ICompanyService _companyService;
|
|
private readonly IVehicleService _vehicleService;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="hostingEnvironment"></param>
|
|
/// <param name="adminUserService"></param>
|
|
/// <param name="menuService"></param>
|
|
/// <param name="roleService"></param>
|
|
/// <param name="userService"></param>
|
|
/// <param name="statisticalService"></param>
|
|
/// <param name="vehicleService"></param>
|
|
/// <param name="companyService"></param>
|
|
/// <param name="aPPService"></param>
|
|
public SysSettingController(IWebHostEnvironment hostingEnvironment,
|
|
IAdminUserService adminUserService,
|
|
IMenuService menuService,
|
|
IRoleService roleService,
|
|
IUserService userService,
|
|
IStatisticalService statisticalService,
|
|
IVehicleService vehicleService,
|
|
ICompanyService companyService,
|
|
IAPPService aPPService)
|
|
{
|
|
_hostingEnvironment = hostingEnvironment;
|
|
_adminUserService = adminUserService;
|
|
_menuService = menuService;
|
|
_roleService = roleService;
|
|
_aPPService = aPPService;
|
|
_userService = userService;
|
|
_statisticalService = statisticalService;
|
|
_companyService = companyService;
|
|
_vehicleService = vehicleService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取系统信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("GetSysInfo")]
|
|
[FunctionAuthorize("GetSysInfo")]
|
|
public async Task<IActionResult> GetSysInfo()
|
|
{
|
|
CommonResult result = new CommonResult();
|
|
try
|
|
{
|
|
SysSetting sysSetting = XmlConverter.Deserialize<SysSetting>("xmlconfig/sys.config");
|
|
CacheHelper cacheHelper = new CacheHelper();
|
|
cacheHelper.Add("SysSetting", sysSetting);
|
|
DashboardOutModel dashboardOutModel = new DashboardOutModel
|
|
{
|
|
CertificatedCompany = sysSetting.CompanyName,
|
|
WebUrl = sysSetting.WebUrl,
|
|
Title = sysSetting.SoftName,
|
|
MachineName = Environment.MachineName,
|
|
ProcessorCount = Environment.ProcessorCount,
|
|
SystemPageSize = Environment.SystemPageSize,
|
|
WorkingSet = Environment.WorkingSet,
|
|
TickCount = Environment.TickCount,
|
|
RunTimeLength = (Environment.TickCount / 1000).ToBrowseTime(),
|
|
FrameworkDescription = RuntimeInformation.FrameworkDescription,
|
|
OSName = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "Linux" :
|
|
RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? "OSX" : "Windows",
|
|
OSDescription =
|
|
RuntimeInformation.OSDescription + " " + RuntimeInformation.OSArchitecture,
|
|
OSArchitecture = RuntimeInformation.OSArchitecture.ToString(),
|
|
ProcessArchitecture = RuntimeInformation.ProcessArchitecture.ToString(),
|
|
|
|
Directory = AppContext.BaseDirectory
|
|
};
|
|
Version version = Environment.Version;
|
|
dashboardOutModel.SystemVersion = version.Major + "." + version.Minor + "." + version.Build;
|
|
dashboardOutModel.Version = AppVersionHelper.Version;
|
|
dashboardOutModel.Manufacturer = AppVersionHelper.Manufacturer;
|
|
dashboardOutModel.WebSite = AppVersionHelper.WebSite;
|
|
dashboardOutModel.UpdateUrl = AppVersionHelper.UpdateUrl;
|
|
dashboardOutModel.IPAdress = Request.HttpContext.Connection.LocalIpAddress.ToString();
|
|
dashboardOutModel.Port = Request.HttpContext.Connection.LocalPort.ToString();
|
|
dashboardOutModel.TotalUser = await _adminUserService.GetCountByWhereAsync("1=1");
|
|
dashboardOutModel.TotalModule = await _menuService.GetCountByWhereAsync("1=1");
|
|
dashboardOutModel.TotalRole = await _roleService.GetCountByWhereAsync("1=1");
|
|
result.ResData = dashboardOutModel;
|
|
result.ErrCode = ErrCode.successCode;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log4NetHelper.Error("获取系统信息异常", ex);
|
|
result.ErrMsg = ErrCode.err60001;
|
|
result.ErrCode = "60001";
|
|
}
|
|
|
|
return ToJsonContent(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 首页统计数据
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("GetStatisticalDataInfo")]
|
|
[FunctionAuthorize("")]
|
|
public async Task<IActionResult> GetStatisticalDataInfo()
|
|
{
|
|
CommonResult result = new CommonResult();
|
|
try
|
|
{
|
|
var statistical = await _statisticalService.GetStatisticalAsync();
|
|
StatisticalOutputDto statisticalData = new StatisticalOutputDto()
|
|
{
|
|
Time = DateTime.Now.ToString("yyyy-MM-dd"),
|
|
UserAddTotal = await _userService.GetCountByWhereAsync("dayofmonth(CreatedTime) = dayofmonth(now())"),
|
|
UserSumTotal = await _userService.GetCountByWhereAsync(" Status=1"),
|
|
CompanyAddTotal = await _companyService.GetCountByWhereAsync("dayofmonth(CreatedTime) = dayofmonth(now())"),
|
|
CompanySumTotal = await _companyService.GetCountByWhereAsync("Status = 1"),
|
|
VehicleAddTotal = await _vehicleService.GetCountByWhereAsync("dayofmonth(CreatedTime) = dayofmonth(now())"),
|
|
VehicleSumTotal = await _vehicleService.GetCountByWhereAsync("Status = 1"),
|
|
ExpireAddTotal = await _vehicleService.GetCountByWhereAsync("dayofmonth(ExpireTime) = dayofmonth(now()) and Status=1"),
|
|
ExpireSumTotal = await _vehicleService.GetCountByWhereAsync("dayofmonth(ExpireTime) < dayofmonth(now()) and Status=1")
|
|
};
|
|
if (statistical == null)
|
|
{
|
|
statisticalData.UserAddTotalPercent = 0;
|
|
}
|
|
else
|
|
{
|
|
statisticalData.UserAddTotalPercent = statistical.UserAddTotalPercent;
|
|
|
|
}
|
|
|
|
result.ResData = statisticalData;
|
|
result.ErrCode = ErrCode.successCode;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log4NetHelper.Error("获取系统信息异常", ex);
|
|
result.ErrMsg = ErrCode.err60001;
|
|
result.ErrCode = "60001";
|
|
}
|
|
|
|
return ToJsonContent(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取系统基本信息不完整信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("GetInfo")]
|
|
[NoPermissionRequired]
|
|
public IActionResult GetInfo()
|
|
{
|
|
CommonResult result = new CommonResult();
|
|
CacheHelper cacheHelper = new CacheHelper();
|
|
SysSetting sysSetting = cacheHelper.Get("SysSetting").ToJson().ToObject<SysSetting>();
|
|
SysSettingOutputDto sysSettingOutputDto = new SysSettingOutputDto();
|
|
if (sysSetting == null)
|
|
{
|
|
sysSetting = XmlConverter.Deserialize<SysSetting>("xmlconfig/sys.config");
|
|
}
|
|
|
|
sysSetting.Email = "";
|
|
sysSettingOutputDto = sysSetting.MapTo<SysSettingOutputDto>();
|
|
if (sysSettingOutputDto != null)
|
|
{
|
|
sysSettingOutputDto.CopyRight = UIConstants.CopyRight;
|
|
result.ResData = sysSettingOutputDto;
|
|
result.Success = true;
|
|
result.ErrCode = ErrCode.successCode;
|
|
}
|
|
else
|
|
{
|
|
result.ErrMsg = ErrCode.err60001;
|
|
result.ErrCode = "60001";
|
|
}
|
|
|
|
System.Collections.Generic.IEnumerable<APP> appList = _aPPService.GetAllByIsNotDeleteAndEnabledMark();
|
|
cacheHelper.Add("AllowAppId", appList);
|
|
return ToJsonContent(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取系统基本信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("GetAllInfo")]
|
|
[FunctionAuthorize("GetSysInfo")]
|
|
public IActionResult GetAllInfo()
|
|
{
|
|
CommonResult result = new CommonResult();
|
|
CacheHelper cacheHelper = new CacheHelper();
|
|
SysSetting sysSetting = cacheHelper.Get("SysSetting").ToJson().ToObject<SysSetting>();
|
|
SysSettingOutputDto sysSettingOutputDto = new SysSettingOutputDto();
|
|
if (sysSetting == null)
|
|
{
|
|
sysSetting = XmlConverter.Deserialize<SysSetting>("xmlconfig/sys.config");
|
|
}
|
|
|
|
//对关键信息解密
|
|
if (!string.IsNullOrEmpty(sysSetting.Email))
|
|
{
|
|
sysSetting.Email = DEncrypt.Decrypt(sysSetting.Email);
|
|
}
|
|
|
|
sysSettingOutputDto = sysSetting.MapTo<SysSettingOutputDto>();
|
|
if (sysSettingOutputDto != null)
|
|
{
|
|
sysSettingOutputDto.CopyRight = UIConstants.CopyRight;
|
|
result.ResData = sysSettingOutputDto;
|
|
result.Success = true;
|
|
result.ErrCode = ErrCode.successCode;
|
|
}
|
|
else
|
|
{
|
|
result.ErrMsg = ErrCode.err60001;
|
|
result.ErrCode = "60001";
|
|
}
|
|
|
|
return ToJsonContent(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存系统设置信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost("Save")]
|
|
[FunctionAuthorize("Edit")]
|
|
public IActionResult Save(SysSetting info)
|
|
{
|
|
CommonResult result = new CommonResult();
|
|
info.LocalPath = _hostingEnvironment.WebRootPath;
|
|
SysSetting sysSetting = XmlConverter.Deserialize<SysSetting>("xmlconfig/sys.config");
|
|
sysSetting = info;
|
|
//对关键信息加密
|
|
string uploadPath = _hostingEnvironment.WebRootPath + "/" + sysSetting.Filepath;
|
|
if (!Directory.Exists(uploadPath))
|
|
{
|
|
Directory.CreateDirectory(uploadPath);
|
|
}
|
|
|
|
CacheHelper cacheHelper = new CacheHelper();
|
|
if (cacheHelper.Exists("SysSetting"))
|
|
{
|
|
cacheHelper.Replace("SysSetting", sysSetting);
|
|
}
|
|
else
|
|
{
|
|
//写入缓存
|
|
cacheHelper.Add("SysSetting", sysSetting);
|
|
}
|
|
|
|
XmlConverter.Serialize<SysSetting>(sysSetting, "xmlconfig/sys.config");
|
|
result.ErrCode = ErrCode.successCode;
|
|
return ToJsonContent(result);
|
|
}
|
|
}
|
|
}
|