You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AUCMA_SCADA/Admin.Core.Api/Controllers/Business/ElectricalinspectionControl...

111 lines
4.5 KiB
C#

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
{
/// <summary>
/// 电检数据接口
/// </summary>
[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;
/// <summary>
/// 构造方法
/// </summary>
/// <param name="SysConfigService"></param>
/// <param name="sysUserService"></param>
/// <param name="recordElectricalinspectionService"></param>
/// <param name="detailElectricalinspectionService"></param>
public ElectricalinspectionController(ISysConfigService SysConfigService, ISysUserService sysUserService,IRecordElectricalinspectionService recordElectricalinspectionService, IDetailElectricalinspectionService detailElectricalinspectionService) : base(sysUserService)
{
_sysConfigService = SysConfigService;
_sysUserService = sysUserService;
_recordElectricalinspectionService = recordElectricalinspectionService;
_detailElectricalinspectionService = detailElectricalinspectionService;
}
/// <summary>
/// 保存电检数据
/// </summary>
/// <param name="electricalinspection"></param>
/// <returns></returns>
[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<DetailElectricalinspection> detailElectricalinspections = new List<DetailElectricalinspection>();
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();
}
}
}