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.

206 lines
8.7 KiB

using Entity.Api.Req;
using Entity.Api.Resp;
using Entity.Base;
7 months ago
using Entity.Dto.Req;
using HybirdFrameworkCore.Entity;
7 months ago
using Microsoft.AspNetCore.Mvc;
using NetTaste;
using NewLife.Reflection;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Org.BouncyCastle.Ocsp;
using Qiniu.Storage;
using Service.Mgr;
using Service.Station;
7 months ago
using Service.System;
using SqlSugar;
using System.ComponentModel.DataAnnotations;
using System.Reflection;
using Entity.DbModel.System;
5 months ago
using Microsoft.Extensions.Localization;
using Service.Init;
7 months ago
namespace WebStarter.Controllers.System
{
[Produces("application/json")]
[ApiController]
[Route("api/[controller]")]
7 months ago
public class SysConfigController
{
private readonly SysConfigService _sysConfigService;
private readonly IWebHostEnvironment _webHostEnvironment;
5 months ago
private readonly IStringLocalizer<SysConfigController> _localizer;
5 months ago
public SysConfigController(IStringLocalizer<SysConfigController> localizer,SysConfigService sysConfigService, IWebHostEnvironment webHostEnvironment)
7 months ago
{
5 months ago
_localizer = localizer;
7 months ago
_sysConfigService = sysConfigService;
_webHostEnvironment = webHostEnvironment;
7 months ago
}
[HttpPost]
[Route("page")]
7 months ago
public async Task<Result<PageResult<SysConfig>>> Page(PageConfigReq input)
7 months ago
{
7 months ago
return Result<PageResult<SysConfig>>.Success(await _sysConfigService.Page(input));
7 months ago
}
[HttpGet]
[Route("list")]
7 months ago
public async Task<List<SysConfig>> GetList()
{
return await _sysConfigService.GetList();
}
[HttpGet]
[Route("detail")]
7 months ago
public async Task<SysConfig> GetDetail([FromQuery] ConfigReq input)
{
return await _sysConfigService.GetDetail(input);
}
[HttpGet]
[Route("groupList")]
7 months ago
public async Task<List<string>> GetGroupList()
{
return await _sysConfigService.GetGroupList();
}
[HttpPost]
[Route("add")]
7 months ago
public async Task Add(AddConfigReq input)
{
await _sysConfigService.AddConfig(input);
}
[HttpPost]
[Route("update")]
7 months ago
public async Task Update(UpdateConfigReq input)
{
await _sysConfigService.UpdateConfig(input);
}
[HttpPost]
[Route("delete")]
7 months ago
public async Task Delete(DeleteConfigReq input)
{
await _sysConfigService.DeleteConfig(input);
}
[HttpPost]
[Route("batchDelete")]
7 months ago
public async Task BatchDelete(List<long> input)
{
await _sysConfigService.BatchDeleteConfig(input);
}
7 months ago
/// <summary>
/// 返回 站点基础信息
/// </summary>
[HttpGet("StationBaseInfo")]
public async Task<Result<StationBaseInfoResp>> StationBaseInfo()
7 months ago
{
StationBaseInfoResp stationBaseInfoResp = new StationBaseInfoResp();
List<SysConfig> sysConfigs = await _sysConfigService.GetGroupList("Station");
foreach (var item in sysConfigs)
{
switch (item.Code)
{
case "StationNo": stationBaseInfoResp.StationNo = item.Value; break;
case "StationName": stationBaseInfoResp.StationName = item.Value; break;
case "StationType": stationBaseInfoResp.StationType = item.Value; break;
case "StationSn": stationBaseInfoResp.StationSn = item.Value; break;
case "StationLocation": stationBaseInfoResp.StationLocation = item.Value; break;
case "Longitude": stationBaseInfoResp.Longitude = item.Value; break;
case "Latitude": stationBaseInfoResp.Latitude = item.Value; break;
case "AreaCode": stationBaseInfoResp.AreaCode = item.Value; break;
case "AreaName": stationBaseInfoResp.AreaName = item.Value; break;
case "Operatetionstime": stationBaseInfoResp.Operatetionstime = item.Value; break;
case "Sevstatus": stationBaseInfoResp.Sevstatus = Convert.ToSByte(item.Value); break;
case "Operatetionetime": stationBaseInfoResp.Operatetionetime = item.Value; break;
case "StationStatus": stationBaseInfoResp.StationStatus = StaticStationInfo.StationStatus; break;
case "LaunchTime": stationBaseInfoResp.LaunchTime = item.Value; break;
case "ContactWay": stationBaseInfoResp.ContactWay = item.Value; break;
case "Principal": stationBaseInfoResp.Principal = item.Value; break;
case "StationCompany": stationBaseInfoResp.StationCompany = item.Value; break;
case "SocialCreditCode": stationBaseInfoResp.SocialCreditCode = item.Value; break;
case "StationSftVer": stationBaseInfoResp.StationSftVer = item.Value; break;
case "SupplierCode": stationBaseInfoResp.SupplierCode = item.Value; break;
case "StationVersion": stationBaseInfoResp.StationVersion = item.Value; break;
case "HardwareVersion": stationBaseInfoResp.HardwareVersion = Convert.ToSByte(item.Value); break;
case "Cover": stationBaseInfoResp.Cover = item.Value; break;
case "Faultlevel": stationBaseInfoResp.Faultlevel = Convert.ToInt32(item.Value); break;
case "LockType": stationBaseInfoResp.LockType = Convert.ToSByte(item.Value); break;
case "AccessType": stationBaseInfoResp.AccessType = Convert.ToSByte(item.Value); break;
case "RiseType": stationBaseInfoResp.RiseType = Convert.ToSByte(item.Value); break;
case "ModifyTime": stationBaseInfoResp.ModifyTime = item.Value; break;
case "DistributionCapacity": stationBaseInfoResp.DistributionCapacity = Convert.ToInt32(item.Value); break;
case "TotalPower": stationBaseInfoResp.TotalPower = Convert.ToInt32(item.Value); break;
case "StationProvince": stationBaseInfoResp.StationProvince = item.Value; break;
case "StationCity": stationBaseInfoResp.StationCity = item.Value; break;
case "OrganizationId": stationBaseInfoResp.OrganizationId = Convert.ToInt32(item.Value); break;
case "StationMac": stationBaseInfoResp.StationMac = item.Value; break;
}
}
5 months ago
stationBaseInfoResp.AreaName = _localizer["AreaName"];
stationBaseInfoResp.StationCity = _localizer["StationCity"];
stationBaseInfoResp.StationName = _localizer["StationName"];
stationBaseInfoResp.StationProvince = _localizer["StationProvince"];
stationBaseInfoResp.StationType = _localizer["StationType"];
stationBaseInfoResp.Principal = _localizer["Principal"];
return Result<StationBaseInfoResp>.Success(stationBaseInfoResp);
7 months ago
}
/// <summary>
/// 站点编辑
/// </summary>
[HttpPost("StationInfoEditor")]
public Result<bool> StationInfoEditor([FromBody] StationBaseInfoReq listStationBaseInfoReq)
{
bool setResult = false;
PropertyInfo[] props = typeof(StationBaseInfoReq).GetProperties();
foreach (PropertyInfo fieldInfo in props)
{
string newConstConfigInfo = "Station" + "." + fieldInfo.Name;
object getContent = fieldInfo.GetValue(listStationBaseInfoReq);
if (fieldInfo.Name == "ModifyTime")
{
if (getContent == null)
{
setResult = _sysConfigService.Set(newConstConfigInfo, DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
}
else
setResult = _sysConfigService.Set(newConstConfigInfo, getContent);
}
if (getContent != null)
setResult = _sysConfigService.Set(newConstConfigInfo, getContent);
}
return Result<bool>.Success(setResult);
}
/// <summary>
/// 系统基础配置 上传图片
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
[HttpPost("ImgUpLoad")]
public async Task<Result<SysFile>> ImgUpLoad([Required] IFormFile file)
7 months ago
{
SysFile sysFile = await _sysConfigService.UploadAvatar(file, _webHostEnvironment.WebRootPath);
if (sysFile != null)
return Result<SysFile>.Success(sysFile);
else
return Result<SysFile>.Fail();
7 months ago
}
7 months ago
}
}