diff --git a/langguanApi.xml b/langguanApi.xml index 66a2272..ed20068 100644 --- a/langguanApi.xml +++ b/langguanApi.xml @@ -1151,6 +1151,21 @@ 原始数据 是否通过 + + + 接收dto + + + + + 数据类型,1 门禁 2台账,3 运输 4 地磅, + + + + + 数据内容 json格式 + + RespModel @@ -3370,6 +3385,11 @@ + + + 接收数据服务 + + 根据角色ID获取角色菜单 @@ -3528,6 +3548,11 @@ + + + 地磅服务 + + 新加 @@ -3535,6 +3560,13 @@ + + + 新加 + + + + 获取地磅集合 diff --git a/langguanApi/Controllers/ReceiveController.cs b/langguanApi/Controllers/ReceiveController.cs new file mode 100644 index 0000000..fa8b4ce --- /dev/null +++ b/langguanApi/Controllers/ReceiveController.cs @@ -0,0 +1,34 @@ +using langguanApi.Model.Dto; +using langguanApi.Service; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace langguanApi.Controllers +{ + /// + /// 接收数据 + /// + [Route("api/[controller]")] + [ApiController] + public class ReceiveController : ControllerBase + { + private readonly ReceiveDataService _receiveService; + /// + /// 接收数据 + public ReceiveController(ReceiveDataService receiveService) + { + _receiveService = receiveService; + } + /// + /// 接收数据 + /// + /// + /// + [HttpPost("receive")] + public async Task Post([FromBody] ReceiveDto input) + { + var result = await _receiveService.ReceiveData(input); + return Ok(result); + } + } +} diff --git a/langguanApi/Model/Dto/ReceiveDto.cs b/langguanApi/Model/Dto/ReceiveDto.cs new file mode 100644 index 0000000..7f6678a --- /dev/null +++ b/langguanApi/Model/Dto/ReceiveDto.cs @@ -0,0 +1,17 @@ +namespace langguanApi.Model.Dto +{ + /// + /// 接收dto + /// + public class ReceiveDto + { + /// + /// 数据类型,1 门禁 2台账,3 运输 4 地磅, + /// + public int dataType { get; set; } + /// + /// 数据内容 json格式 + /// + public string content { get; set; } + } +} diff --git a/langguanApi/Service/Hj212Service.cs b/langguanApi/Service/Hj212Service.cs index a1d56ae..b62c5b9 100644 --- a/langguanApi/Service/Hj212Service.cs +++ b/langguanApi/Service/Hj212Service.cs @@ -63,35 +63,6 @@ namespace langguanApi.Service }); } return result; - //var temp = result.Select(s => new - //{ - // s.a34001, - // s.a34002, - // s.a34004, - // date = s.CreateDateTime.AddHours(8).ToString("MM-dd") - //}).ToList(); - //return temp.GroupBy(g => new - //{ - // g.date - //}) - // .Select(s => new - // { - // s.Key.date, - // a34001 = Math.Round(s.Sum(t => t.a34001), 2), - // a34002 = Math.Round(s.Sum(t => t.a34002), 2), - // a34004 = Math.Round(s.Sum(t => t.a34004), 2) - // }).ToList(); - - - //temp.GroupBy(g => new { g.date }).ToList().ForEach(s => - //{ - // var v1 = temp.Where(m => m.date == s.Key.date).Sum(t => t.a34001); - // var v2 = temp.Where(m => m.date == s.Key.date).Sum(t => t.a34002); - // var v3 = temp.Where(m => m.date == s.Key.date).Sum(t => t.a34004); - // list.Add(new columnView() { hour = s.Key.date, type = "a34001", value = v1 }); - // list.Add(new columnView() { hour = s.Key.date, type = "a34002", value = Math.Round(v2, 2) }); - // list.Add(new columnView() { hour = s.Key.date, type = "a34004", value = Math.Round(v3, 2) }); - //}); } /// diff --git a/langguanApi/Service/ReceiveDataService.cs b/langguanApi/Service/ReceiveDataService.cs new file mode 100644 index 0000000..7833e43 --- /dev/null +++ b/langguanApi/Service/ReceiveDataService.cs @@ -0,0 +1,61 @@ + +using langguanApi.Model; +using langguanApi.Model.Dto; +using langguanApi.Model.Entity; +using Newtonsoft.Json; + +namespace langguanApi.Service +{ + /// + /// 接收数据服务 + /// + public class ReceiveDataService + { + public ReceiveDataService() + { + + } + /// + /// 接收数据 + /// + /// + /// + public async Task ReceiveData(ReceiveDto jsonData) + { + try + { + //TODO: 接收到数据后处理 + switch (jsonData.dataType) + { + case 1: + //TODO: 1门禁 + //var accessData = JsonConvert.DeserializeObject(jsonData.content); + //var _service = ServiceLocator.Instance.GetService(); + break; + case 2: + //TODO: 2 台账 + var LedgerData = JsonConvert.DeserializeObject(jsonData.content); + var _service = ServiceLocator.Instance.GetService(); + break; + case 3: + //TODO: 3 运输 + var TransportData = JsonConvert.DeserializeObject(jsonData.content); + var _Transporservice = ServiceLocator.Instance.GetService(); + await _Transporservice.addTransport(TransportData); + break; + case 4: + var truckScalesData = JsonConvert.DeserializeObject(jsonData.content); + var _TruckScalesService = ServiceLocator.Instance.GetService(); + await _TruckScalesService.AddTruckScales(truckScalesData); + //TODO: 4 地磅 + break; + } + } + catch (Exception ex) + { + return new ApiResult() { code = 1, msg = ex.Message }; + } + return new ApiResult() { code = 0, msg = "success" }; + } + } +} diff --git a/langguanApi/Service/TruckScalesService.cs b/langguanApi/Service/TruckScalesService.cs index c989092..9da552b 100644 --- a/langguanApi/Service/TruckScalesService.cs +++ b/langguanApi/Service/TruckScalesService.cs @@ -5,6 +5,9 @@ using System.Linq.Expressions; namespace langguanApi.Service { + /// + /// 地磅服务 + /// [ServiceInjection(InjectionType.Transient)] public class TruckScalesService : BaseService { @@ -19,16 +22,22 @@ namespace langguanApi.Service /// public async Task AddTruckScalesList(List input) { - var list = new List(); - foreach (var item in input) - { - list.Add(item.Adapt()); - } + var list = input.Adapt>(); if (list.Any()) { await base.CreateManyAsync(list); } } + /// + /// 新加 + /// + /// + /// + public async Task AddTruckScales(AddTruckScalesDto input) + { + var list = input.Adapt(); + await base.CreateAsync(list); + } /// /// 获取地磅集合