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