| | |
| | | using HslCommunication; |
| | | using Newtonsoft.Json; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; |
| | | using Quartz.Util; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Security.Claims; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Common; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.BaseRepository; |
| | | using WIDESEA_Core.BaseServices; |
| | | using WIDESEA_Core.Helper; |
| | | using WIDESEA_DTO.SquareCabin; |
| | | using WIDESEA_IWMsInfoServices; |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEA_Model.Models.WMSInfo; |
| | | using static WIDESEA_DTO.SquareCabin.AlarmDto; |
| | | using static WIDESEA_DTO.SquareCabin.TowcsDto; |
| | | |
| | | namespace WIDESEA_WMsInfoServices |
| | | { |
| | | public class ContainerService : ServiceBase<Dt_Container, IRepository<Dt_Container>>, IContainerService |
| | | { |
| | | public ContainerService(IRepository<Dt_Container> BaseDal) : base(BaseDal) |
| | | private readonly IMessageInfoService _messageInfoService; |
| | | public ContainerService(IRepository<Dt_Container> BaseDal, IMessageInfoService messageInfoService) : base(BaseDal) |
| | | { |
| | | _messageInfoService = messageInfoService; |
| | | } |
| | | |
| | | public IRepository<Dt_Container> Repository => BaseDal; |
| | | |
| | | public WebResponseContent Sensor() |
| | | { |
| | | try |
| | | { |
| | | var url = "http://172.16.1.4:8082/api/environment/sensor"; |
| | | var result = HttpHelper.Get(url); |
| | | var response = JsonConvert.DeserializeObject<CollResponse<CoolDto>>(result); |
| | | |
| | | if (response.code != "000" || response.data == null) |
| | | { |
| | | return new WebResponseContent { Status = false, Message = "æ¥å£è¿åæ°æ®æ¥é" }; |
| | | } |
| | | |
| | | // ä½¿ç¨æ¹éæä½æé«æ§è½ |
| | | var updateList = new List<Dt_Container>(); |
| | | var addList = new List<Dt_Container>(); |
| | | var currentTime = DateTime.Now; |
| | | |
| | | // å
æ¥è¯¢ææè®¾å¤ï¼é¿å
循ç¯ä¸å¤æ¬¡æ¥è¯¢æ°æ®åº |
| | | var deviceNames = response.data.Select(x => x.name).Distinct().ToList(); |
| | | var existingDevices = BaseDal.QueryData(x => deviceNames.Contains(x.deviceName)) |
| | | .ToDictionary(x => x.deviceName, x => x); |
| | | |
| | | foreach (var item in response.data) |
| | | { |
| | | if (existingDevices.TryGetValue(item.name, out var cool)) |
| | | { |
| | | // æ´æ°ç°æè®°å½ |
| | | cool.CurrentTemperature = item.temperature; |
| | | cool.Humidity = item.humidity; |
| | | cool.Alarm = item.alarm; |
| | | cool.AlarmInformation = item.message; |
| | | cool.ModifyDate = currentTime; |
| | | updateList.Add(cool); |
| | | if (cool.Alarm!="æ£å¸¸") |
| | | { |
| | | _messageInfoService.AddMessageInfo(MessageGroupByEnum.EquipmentAlarm, $"å·æ{item.alarm}", item.message, MessageStatusEnum.Undisposed); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | // å建æ°è®°å½ |
| | | var dto = new Dt_Container |
| | | { |
| | | deviceName = item.name, |
| | | CurrentTemperature = item.temperature, |
| | | Humidity = item.humidity, |
| | | Alarm = item.alarm, |
| | | AlarmInformation = item.message, |
| | | CreateDate = currentTime, |
| | | Creater = "System", |
| | | ModifyDate = currentTime, |
| | | Modifier = "System" |
| | | }; |
| | | addList.Add(dto); |
| | | if (item.alarm != "æ£å¸¸") |
| | | { |
| | | _messageInfoService.AddMessageInfo(MessageGroupByEnum.EquipmentAlarm, $"å·æ{item.alarm}", item.message, MessageStatusEnum.Undisposed); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // å¼å§äºå¡ |
| | | Db.Ado.BeginTran(); |
| | | |
| | | try |
| | | { |
| | | // æ¹éæå
¥æ°è®°å½ |
| | | if (addList.Any()) |
| | | { |
| | | BaseDal.Db.Insertable(addList).ExecuteCommand(); |
| | | } |
| | | |
| | | // æ¹éæ´æ°ç°æè®°å½ |
| | | if (updateList.Any()) |
| | | { |
| | | BaseDal.Db.Updateable(updateList).ExecuteCommand(); |
| | | } |
| | | |
| | | // æäº¤äºå¡ |
| | | Db.Ado.CommitTran(); |
| | | |
| | | return new WebResponseContent |
| | | { |
| | | Status = true, |
| | | Message = $"忥æåï¼æ°å¢{addList.Count}æ¡ï¼æ´æ°{updateList.Count}æ¡" |
| | | }; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Db.Ado.RollbackTran(); |
| | | return new WebResponseContent |
| | | { |
| | | Status = false, |
| | | Message = $"æ°æ®ä¿å失败ï¼{ex.Message}" |
| | | }; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return new WebResponseContent |
| | | { |
| | | Status = false, |
| | | Message = $"æ¥å£è°ç¨å¤±è´¥ï¼{ex.Message}" |
| | | }; |
| | | } |
| | | } |
| | | } |
| | | } |