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.

195 lines
8.1 KiB

using Entity.Api.Req;
using Entity.Api.Resp;
using Entity.Base;
5 months ago
using Entity.Dto.Req;
using HybirdFrameworkCore.Entity;
5 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;
5 months ago
using Service.System;
using SqlSugar;
using System.ComponentModel.DataAnnotations;
using System.Reflection;
using Entity.DbModel.System;
using Service.Init;
5 months ago
namespace WebStarter.Controllers.System
{
[Produces("application/json")]
[ApiController]
[Route("api/[controller]")]
5 months ago
public class SysConfigController
{
private readonly SysConfigService _sysConfigService;
private readonly IWebHostEnvironment _webHostEnvironment;
public SysConfigController(SysConfigService sysConfigService, IWebHostEnvironment webHostEnvironment)
5 months ago
{
_sysConfigService = sysConfigService;
_webHostEnvironment = webHostEnvironment;
5 months ago
}
[HttpPost]
[Route("page")]
5 months ago
public async Task<Result<PageResult<SysConfig>>> Page(PageConfigReq input)
5 months ago
{
5 months ago
return Result<PageResult<SysConfig>>.Success(await _sysConfigService.Page(input));
5 months ago
}
[HttpGet]
[Route("list")]
5 months ago
public async Task<List<SysConfig>> GetList()
{
return await _sysConfigService.GetList();
}
[HttpGet]
[Route("detail")]
5 months ago
public async Task<SysConfig> GetDetail([FromQuery] ConfigReq input)
{
return await _sysConfigService.GetDetail(input);
}
[HttpGet]
[Route("groupList")]
5 months ago
public async Task<List<string>> GetGroupList()
{
return await _sysConfigService.GetGroupList();
}
[HttpPost]
[Route("add")]
5 months ago
public async Task Add(AddConfigReq input)
{
await _sysConfigService.AddConfig(input);
}
[HttpPost]
[Route("update")]
5 months ago
public async Task Update(UpdateConfigReq input)
{
await _sysConfigService.UpdateConfig(input);
}
[HttpPost]
[Route("delete")]
5 months ago
public async Task Delete(DeleteConfigReq input)
{
await _sysConfigService.DeleteConfig(input);
}
[HttpPost]
[Route("batchDelete")]
5 months ago
public async Task BatchDelete(List<long> input)
{
await _sysConfigService.BatchDeleteConfig(input);
}
5 months ago
/// <summary>
/// 返回 站点基础信息
/// </summary>
[HttpGet("StationBaseInfo")]
public async Task<Result<StationBaseInfoResp>> StationBaseInfo()
5 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;
}
}
return Result<StationBaseInfoResp>.Success(stationBaseInfoResp);
5 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)
5 months ago
{
SysFile sysFile = await _sysConfigService.UploadAvatar(file, _webHostEnvironment.WebRootPath);
if (sysFile != null)
return Result<SysFile>.Success(sysFile);
else
return Result<SysFile>.Fail();
5 months ago
}
5 months ago
}
}