using Admin.Core.Api; using Admin.Core.Common; using Admin.Core.IService; using Admin.Core.IService.ISys; using Admin.Core.Model; using Admin.Core.Service; using Admin.Core.Service.Sys; using log4net; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using StackExchange.Profiling.Internal; using System; using System.Collections.Generic; namespace Aucma.Scada.Api.Controllers { /// /// 电检数据接口 /// [Route("api/[controller]/[action]")] [ApiController] [Authorize(Permissions.Name)] public class ElectricalinspectionController : BaseApiUserController { private static readonly log4net.ILog _logger = LogManager.GetLogger(typeof(ElectricalinspectionController)); private readonly ISysConfigService _sysConfigService; private IRecordElectricalinspectionService _recordElectricalinspectionService; private IDetailElectricalinspectionService _detailElectricalinspectionService; /// /// 构造方法 /// /// /// /// /// public ElectricalinspectionController(ISysConfigService SysConfigService, ISysUserService sysUserService,IRecordElectricalinspectionService recordElectricalinspectionService, IDetailElectricalinspectionService detailElectricalinspectionService) : base(sysUserService) { _sysConfigService = SysConfigService; _sysUserService = sysUserService; _recordElectricalinspectionService = recordElectricalinspectionService; _detailElectricalinspectionService = detailElectricalinspectionService; } /// /// 保存电检数据 /// /// /// [HttpPost] public IActionResult save([FromBody]RecordElectricalinspection electricalinspection) { _logger.Info($"收到电检数据:{electricalinspection.ToJson()}"); if (electricalinspection == null) { return BadRequest(); } try { electricalinspection.Recordtime = DateTime.Now; var testDataStr = electricalinspection.Testdata; electricalinspection.Testdata = System.Guid.NewGuid().ToString(); #region 解析TestData string[] str = testDataStr.ToString().Split(";"); List detailElectricalinspections = new List(); foreach (string item in str) { if (!string.IsNullOrEmpty(item)) { string[] items = item.Split("|"); if (items.Length == 5) { DetailElectricalinspection detailElectricalinspection = new DetailElectricalinspection(); detailElectricalinspection.Uuid = electricalinspection.Testdata; detailElectricalinspection.Serialnumber = Convert.ToDecimal(items[0]); detailElectricalinspection.Projectname = items[1].ToString(); detailElectricalinspection.Testcondition = items[2].ToString(); detailElectricalinspection.Testvalue = items[3].ToString(); detailElectricalinspection.Testresult = items[4].ToString(); detailElectricalinspection.Recordtime = DateTime.Now; detailElectricalinspections.Add(detailElectricalinspection); } } } #endregion _logger.Info($"电检明细解析完成:{detailElectricalinspections.ToJson()}"); _recordElectricalinspectionService.InsertRecordElectricalinspection(electricalinspection); _detailElectricalinspectionService.InsertRangeDetailElectricalinspection(detailElectricalinspections); } catch(Exception ex) { _logger.Error($"电检数据处理异常:{ex.Message}"); } return Ok(); } } }