using Abp.Auditing; using Abp.Authorization; using Abp.Collections.Extensions; using Abp.Domain.Entities; using Abp.Domain.Repositories; using Abp.Domain.Uow; using Amazon.Runtime.Internal.Transform; using Microsoft.AspNetCore.Mvc; using MongoDB.Driver.Linq; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Dynamic.Core; using System.Text; using System.Threading.Tasks; using System.Xml.Serialization; using ToolLibrary.LogHelper; using YunDa.ISAS.Application.Core; using YunDa.ISAS.Application.Core.Session; using YunDa.ISAS.Application.Core.SwaggerHelper; using YunDa.ISAS.DataTransferObject; using YunDa.ISAS.Entities.GeneralInformation; using YunDa.ISAS.Redis.Repositories; using YunDa.ISMS.BASE.Entities.Models; using YunDa.SOMS.DataTransferObject.CommonDto; using YunDa.SOMS.DataTransferObject.GeneralInformation.ProtectionDeviceInfoDto; using YunDa.SOMS.DataTransferObject.GeneralInformation.ProtectionDeviceInfoDto.HistoryData; using YunDa.SOMS.DataTransferObject.GeneralInformation.ProtectionDeviceInfoDto.SearchCondition; using YunDa.SOMS.DataTransferObject.GeneralInformation.ProtectionSettingDto; using YunDa.SOMS.DataTransferObject.MainStationMaintenanceInfo.OperationReport; using YunDa.SOMS.Entities.GeneralInformation; namespace YunDa.ISAS.Application.GeneralInformation { /// /// 保护装置履历信息管理类 /// public class BoardCardInfoAppService : ISASAppServiceBase, IBoardCardInfoAppService { private readonly IRepository _equipmentInfoRepository; private readonly IRepository _protectionDeviceInfoRepository; private readonly IRepository _protectionDeviceTypeRepository; private readonly IRepository _protectionDeviceHistoryRepository; private readonly IRepository _boardCardInfoRepository; private readonly IRepository _boardCardHistoryRepository; private readonly IRepository _manufacturerInfoRepository; private readonly IRepository _imProtectDeviceRepository; private readonly IUnitOfWorkManager _unitOfWorkManager; IRedisRepository _deviceBoardStatesRedis; string deviceIORedisKey = "deviceIO"; IRedisRepository _deviceIOsRedis; // 定义 BoardType 与 BoardTypeId 的映射字典 Dictionary boardTypeMapping = new Dictionary { { "CPU插件", "J2CA" }, { "交流插件", "J2JA" }, { "开入插件", "J2IA" }, { "开出插件", "J2OA" }, { "操作插件", "J2OC" }, { "电源插件", "J2IA" }, { "液晶", "液晶" } }; public BoardCardInfoAppService( IRepository protectionDeviceInfoRepository, IUnitOfWorkManager unitOfWorkManager, IRepository imProtectDeviceRepository, IRepository equipmentInfoRepository, IRepository protectionDeviceHistoryRepository, IRepository boardCardInfoRepository, IRepository boardCardHistoryRepository, IRepository manufacturerInfoRepository, IRedisRepository deviceBoardStatesRedis, IRedisRepository deviceIOsRedis, IRepository protectionDeviceTypeRepository, ISessionAppService sessionAppService ) : base(sessionAppService) { _unitOfWorkManager = unitOfWorkManager; _equipmentInfoRepository = equipmentInfoRepository; _imProtectDeviceRepository = imProtectDeviceRepository; _protectionDeviceInfoRepository = protectionDeviceInfoRepository; _protectionDeviceHistoryRepository = protectionDeviceHistoryRepository; _boardCardInfoRepository = boardCardInfoRepository; _boardCardHistoryRepository = boardCardHistoryRepository; _manufacturerInfoRepository = manufacturerInfoRepository; _deviceBoardStatesRedis = deviceBoardStatesRedis; _deviceIOsRedis = deviceIOsRedis; _protectionDeviceTypeRepository = protectionDeviceTypeRepository; } public async Task> CreateOrUpdateAsync(EditBoardCardInput input) { RequestResult rst = new RequestResult(); try { if (boardTypeMapping.ContainsKey(input.BoardType)) { input.BoardTypeId = boardTypeMapping[input.BoardType]; } if (input.Id.HasValue) { var entity = _boardCardInfoRepository.GetAll().FirstOrDefault(t => t.Id == input.Id); if (entity!=null) { entity.LastModificationTime = DateTime.Now; entity.LastModifierUserId = base.GetCurrentUser().Id; ObjectMapper.Map(input, entity); } } else { var entity = ObjectMapper.Map(input); entity.CreatorUserId = base.GetCurrentUser().Id; entity.CreationTime = DateTime.Now; await _boardCardInfoRepository.InsertAsync(entity); } rst.Flag = true; } catch (Exception ex) { rst.Message = ex.Message; rst.Flag = false; Log4Helper.Error(this.GetType(), "线路管理服务", ex); } return rst; } /// /// 扫码枪输入设备信息 /// /// /// [ShowApi] [AbpAllowAnonymous] [HttpPost] public RequestEasyResult ScanDeviceQRCode(EditBoardCardQrCodeInput input) { RequestEasyResult rst = new RequestEasyResult(); try { var repo = _protectionDeviceInfoRepository.GetAllIncluding(t => t.EquipmentInfo,t=>t.ProtectionDeviceType).ToList(); var boardCards = _boardCardInfoRepository.GetAll().ToList(); var protectionDevice = repo.FirstOrDefault(t => t.Name.Contains(input.ProtectionDeviceName)); if (protectionDevice != null) { var deviceBoardCard = boardCards.FirstOrDefault(t => t.ProtectionDeviceInfoId == protectionDevice.Id&&t.BoardId == input.BoardId); if (deviceBoardCard!=null) { if (deviceBoardCard.SerialNumber != input.SerialNumber || deviceBoardCard.MaintenanceRecord != input.MaintenanceRecord || deviceBoardCard.VerificationRecords != input.VerificationRecords || deviceBoardCard.VerificationDate != input.VerificationDate || deviceBoardCard.VerificationPerson != input.VerificationPerson || deviceBoardCard.ProductionDate != input.ProductionDate ) { var deviceBoardCardHistory = _boardCardHistoryRepository.GetAll().Where(t => t.BoardCardInfoId == deviceBoardCard.Id).ToList(); var json = JsonConvert.SerializeObject(deviceBoardCard); var boardHistory = new BoardCardHistory { ContentJson = json, CreationTime = DateTime.Now, CreatorUserId = base.GetCurrentUser().Id, Name = deviceBoardCard.BoardId, RecodeDate = DateTime.Now, BoardId = input.BoardId, BoardCardInfoId = deviceBoardCard.Id, ProtectionDeviceInfoId = protectionDevice.Id, SeqNo = deviceBoardCardHistory.Count > 0 ? deviceBoardCardHistory.Max(t => t.SeqNo) + 1 : 1 }; deviceBoardCard.SerialNumber = input.SerialNumber; deviceBoardCard.ProductionDate = input.ProductionDate; deviceBoardCard.VerificationDate = input.VerificationDate; deviceBoardCard.VerificationPerson = input.VerificationPerson; deviceBoardCard.VerificationRecords = input.VerificationRecords; var newjson = JsonConvert.SerializeObject(deviceBoardCard); boardHistory.ContentNewJson = newjson; // 记录变更内容 var eventDescription = new StringBuilder(); // 通过判定每个字段是否发生变化,动态生成描述 if (deviceBoardCard.SerialNumber != input.SerialNumber) { eventDescription.AppendLine($"更换了设备的厂商序列号: {deviceBoardCard.SerialNumber} -> {input.SerialNumber}"); } if (deviceBoardCard.MaintenanceRecord != input.MaintenanceRecord) { eventDescription.AppendLine($"更新了设备的维修记录: {deviceBoardCard.MaintenanceRecord} -> {input.MaintenanceRecord}"); } if (deviceBoardCard.VerificationRecords != input.VerificationRecords) { eventDescription.AppendLine($"更改了设备的验证记录: {deviceBoardCard.VerificationRecords} -> {input.VerificationRecords}"); } if (deviceBoardCard.VerificationDate != input.VerificationDate) { eventDescription.AppendLine($"修改了设备的验证日期: {deviceBoardCard.VerificationDate} -> {input.VerificationDate}"); } if (deviceBoardCard.VerificationPerson != input.VerificationPerson) { eventDescription.AppendLine($"更新了设备的验证人员: {deviceBoardCard.VerificationPerson} -> {input.VerificationPerson}"); } if (deviceBoardCard.ProductionDate != input.ProductionDate) { eventDescription.AppendLine($"更改了设备的生产日期: {deviceBoardCard.ProductionDate} -> {input.ProductionDate}"); } boardHistory.EventDescription = eventDescription.ToString(); boardHistory.EventRecordType = EventRecordTypeEnum.Board; boardHistory.Remark = input.Remark; _boardCardHistoryRepository.Insert(boardHistory); } } else { //rst.Message = "未找到对应板卡"; } rst.Flag = true; } else { rst.Message = "未找到对应装置"; } } catch (Exception ex) { rst.Message = ex.Message; rst.Flag = false; Log4Helper.Error(this.GetType(), "", ex); } return rst; } public async Task DeleteByIdAsync(Guid id) { RequestEasyResult rst = new RequestEasyResult(); return rst; } /// /// 删除板卡信息 /// /// /// [HttpPost] public async Task DeleteByIdsAsync(List ids) { RequestEasyResult rst = new RequestEasyResult(); try { await _boardCardInfoRepository.DeleteAsync(t => ids.Contains(t.Id)); rst.Flag = true; } catch (Exception ex) { rst.Message = ex.Message; rst.Flag = false; Log4Helper.Error(this.GetType(), "保护装置信息管理服务", ex); } return rst; } /// /// 查询保护装置板卡信息 /// /// /// [ShowApi] [AbpAllowAnonymous] [DisableAuditing] [HttpPost] public RequestPageResult FindDatas(PageSearchCondition searchCondition) { RequestPageResult rst = new RequestPageResult(); try { var repo = _boardCardInfoRepository.GetAllIncluding(t=>t.ProtectionDeviceInfo,t=>t.ManufacturerInfo) .WhereIf(searchCondition.SearchCondition.EquipmentInfoId.HasValue, t => t.ProtectionDeviceInfo?.EquipmentInfoId == searchCondition.SearchCondition.EquipmentInfoId) .WhereIf(searchCondition.SearchCondition.ProtectionDeviceInfoId.HasValue, t => t.ProtectionDeviceInfoId == searchCondition.SearchCondition.ProtectionDeviceInfoId); rst.TotalCount = repo.Count(); if (searchCondition.PageSize>0&& searchCondition.PageIndex>0) { int skipCount = searchCondition.PageSize * (searchCondition.PageIndex - 1); var tmpData = repo.Skip(skipCount).Take(searchCondition.PageSize); rst.ResultData = ObjectMapper.Map>(tmpData); } else { rst.ResultData = ObjectMapper.Map>(repo); } rst.Flag = true; } catch (Exception ex) { rst.Message = ex.Message; rst.Flag = false; Log4Helper.Error(this.GetType(), "保护装置信息管理服务", ex); } return rst; } /// /// 查询板卡历史数据 /// /// /// [ShowApi] [AbpAllowAnonymous] [DisableAuditing] [HttpGet] public RequestResult> FindHistoryDataByEquipmentInfoId(Guid? equipmentInfoId) { RequestResult> rst = new RequestResult>(); try { List historys = new List(); var protectionDevice = _protectionDeviceInfoRepository.GetAllIncluding(t => t.EquipmentInfo) .FirstOrDefault(t => t.EquipmentInfoId == equipmentInfoId); if (protectionDevice != null) { var boards = _boardCardHistoryRepository.GetAll().Where(t => t.ProtectionDeviceInfoId == protectionDevice.Id); historys = ObjectMapper.Map>(boards); rst.Flag = true; rst.ResultData = historys; rst.TotalCount = historys.Count; } } catch (Exception ex) { rst.Message = ex.Message; rst.Flag = false; Log4Helper.Error(this.GetType(), "保护装置信息管理服务", ex); } return rst; } public RequestResult GetProtectionDeviceQRcode(Guid id) { RequestResult rst = new RequestResult(); return rst; } string deviceBoardStatesRedisKey = "deviceBoardStates"; List iopositions = new List { new NameIntValueProperty("运行", 0), new NameIntValueProperty("告警", 0), new NameIntValueProperty("IO插件1", 0), new NameIntValueProperty("IO插件2", 0), new NameIntValueProperty("IO插件3", 0), new NameIntValueProperty("IO插件4", 0), new NameIntValueProperty("电源插件(IO5)", 0), new NameIntValueProperty("液晶", 0) }; /// /// 获取板卡状态 /// /// /// /// [HttpGet] [AbpAllowAnonymous] [ShowApi] public async Task>> GetBoardStateInfo(Guid equipmentId,Guid deviceId) { RequestResult> rst = new RequestResult>(); try { ProtectionDeviceInfo protectionDeviceInfo = null; if (deviceId == default) { protectionDeviceInfo = _protectionDeviceInfoRepository.GetAll().FirstOrDefault(t => t.EquipmentInfoId == equipmentId); } else { protectionDeviceInfo = _protectionDeviceInfoRepository.Get(deviceId); } if (protectionDeviceInfo != null) { var state = await _deviceBoardStatesRedis.HashSetGetAllAsync(deviceBoardStatesRedisKey, protectionDeviceInfo.DeviceAddress.ToString()); if (state != null) { rst.ResultData = state.States.Select(t => new DeviceRunState { Name = t.Name, State = t.Value }).ToList(); } else { rst.ResultData = iopositions.Select(t => new DeviceRunState { Name = t.Name, State = t.Value }).ToList(); } rst.Flag = true; } } catch (Exception ex) { rst.Flag = false; rst.Message = ex.Message; } return rst; } /// /// 获取板卡IO信息 /// /// /// /// [HttpGet] [AbpAllowAnonymous] [ShowApi] public async Task>> GetBoardIOState(Guid equipmentId, Guid deviceId) { RequestResult> rst = new RequestResult>(); try { ProtectionDeviceInfo protectionDeviceInfo = null; if (deviceId == default) { protectionDeviceInfo = _protectionDeviceInfoRepository.GetAll().FirstOrDefault(t => t.EquipmentInfoId == equipmentId); } else { protectionDeviceInfo = _protectionDeviceInfoRepository.Get(deviceId); } if (protectionDeviceInfo != null) { var states =await _deviceIOsRedis.HashSetGetDicAllAsync(deviceIORedisKey); var datas = states.Where(t => t.Key.Contains($"{protectionDeviceInfo.DeviceAddress}_")).GroupBy(t=>t.Key.Split('_')[1]).Select(t => new IOStateList { Name ="B0"+ t.Key, IOStates =t.Select(x=>x.Value).ToList(), }).OrderBy(t=>t.Name); rst.ResultData = datas.ToList(); rst.Flag = true; } } catch (Exception ex) { rst.Flag = false; rst.Message = ex.Message; } return rst; } /// /// 生成板卡信息 /// /// [ShowApi] [AbpAllowAnonymous] [HttpGet] public RequestEasyResult SpwanBoardInfoList() { RequestEasyResult rst = new RequestEasyResult(); try { var boards = _boardCardInfoRepository.GetAll().ToList(); var devices = _protectionDeviceInfoRepository.GetAll(); var manfac = _manufacturerInfoRepository.GetAll().FirstOrDefault(t => t.ManufacturerName.Contains("运达")); foreach (var device in devices) { var boardInfos = boards.Where(t => t.ProtectionDeviceInfoId == device.Id); if (boardInfos.Count() > 0) { continue; } // 插件信息表 var pluginData = new BoardCardInfo[] { new BoardCardInfo{ BoardId = "B01", SeqNo = 1, SerialNumber = "1933CA00300001", BoardType = "CPU插件", BoardTypeId = "J2CA", ProductionDate = new DateTime(2019, 8, 13), Remark = "CPU 主插件" }, new BoardCardInfo{ BoardId = "B02", SeqNo = 2, SerialNumber = "1933JA04100001", BoardType = "交流插件", BoardTypeId = "J2JA", ProductionDate = new DateTime(2019, 8, 13), Remark = "交流插件" }, new BoardCardInfo{ BoardId = "B03", SeqNo = 3, SerialNumber = "2233IA220V400001", BoardType = "开入插件", BoardTypeId = "J2IA", ProductionDate = new DateTime(2022, 8, 13), Remark = "开入插件1" }, new BoardCardInfo{ BoardId = "B04", SeqNo = 4, SerialNumber = "2233IA220V400002", BoardType = "开入插件", BoardTypeId = "J2IA", ProductionDate = new DateTime(2022, 8, 13), Remark = "开入插件2" }, new BoardCardInfo{ BoardId = "B05", SeqNo = 5, SerialNumber = "2233OA0000400001", BoardType = "开出插件", BoardTypeId = "J2OA", ProductionDate = new DateTime(2022, 8, 13), Remark = "开出插件" }, new BoardCardInfo{ BoardId = "B06", SeqNo = 6, SerialNumber = "2233OC220V400001", BoardType = "操作插件", BoardTypeId = "J2OC", ProductionDate = new DateTime(2022, 8, 13), Remark = "操作插件" }, new BoardCardInfo{ BoardId = "B07", SeqNo = 7, SerialNumber = "1933DA00100001", BoardType = "电源插件", BoardTypeId = "J2IA", ProductionDate = new DateTime(2019, 8, 13), Remark = "电源插件" }, new BoardCardInfo{ BoardId = "液晶", SeqNo = 8, SerialNumber = "1933DA00100001", BoardType = "液晶", BoardTypeId = "液晶", ProductionDate = new DateTime(2019, 8, 13), Remark = "液晶" }, }; // 模拟插入插件数据 foreach (var plugin in pluginData) { var boardCardInfo = new BoardCardInfo { SeqNo = plugin.SeqNo, BoardId = plugin.BoardId, BoardType = plugin.BoardType, ManufacturerInfoId = manfac.Id, ProtectionDeviceInfoId = device.Id, IsActive = true, SerialNumber = plugin.SerialNumber, ProductionDate = plugin.ProductionDate, Remark = plugin.Remark, InstallationDate = DateTime.Now.AddMonths(-3) // 默认安装时间 }; if (plugin.SeqNo == 1) { boardCardInfo.HardwareVersion = "1.0.0"; boardCardInfo.InterfaceVersion = "2.0.0"; boardCardInfo.InterfaceChecksum = "8b18"; boardCardInfo.InterfaceDatabaseVersion = "v1.104"; boardCardInfo.ProtectionDatabaseVersion = "v1.104"; boardCardInfo.SystemVersion = "3.10.10-ADI-2013R1"; boardCardInfo.ProtectionVersion = "v5.3.1"; boardCardInfo.ProtectionChecksum = "8b18"; boardCardInfo.BootVersion = "BOOT2024"; boardCardInfo.Iec61850Version = "IEC61850-V2"; boardCardInfo.FpgaVersion = "v4.000"; boardCardInfo.CidChecksum = "CIDCHK2024"; boardCardInfo.CcdChecksum = "CCDCHK2024"; boardCardInfo.VerificationPerson = "贺严玲"; boardCardInfo.VerificationDate = "2024-01-01"; boardCardInfo.VerificationRecords = "全部通过"; boardCardInfo.CreationTime = DateTime.Now; } // 模拟插入数据库 var entity = _boardCardInfoRepository.Insert(boardCardInfo); var boardHistory = new BoardCardHistory { ContentJson = JsonConvert.SerializeObject(entity), CreationTime = DateTime.Now, CreatorUserId = base.GetCurrentUser().Id, Name = entity.BoardId, RecodeDate = DateTime.Now, BoardId = entity.BoardId, BoardCardInfoId = entity.Id, ProtectionDeviceInfoId = device.Id, EventDescription ="建立板卡信息台账", EventRecordType = EventRecordTypeEnum.Board, SeqNo = 1 }; _boardCardHistoryRepository.Insert(boardHistory); } } rst.Flag = true; } catch (Exception ex) { throw; } return rst; } /// /// 更新版本信息 /// /// [ShowApi] [AbpAllowAnonymous] [HttpPost] public RequestEasyResult ModifyBoardInfoList(ProtectionDeviceVersionInfo input) { RequestEasyResult rst = new RequestEasyResult(); try { var boards = _boardCardInfoRepository.GetAll().ToList(); var devices = _protectionDeviceInfoRepository.GetAll().Where(t => t.DeviceAddress == input.DeviceAddr).ToList(); var protectionDeviceTypes = _protectionDeviceTypeRepository.GetAll().ToList(); if (devices.Count > 0) { var device = devices[0]; device.ProtectionDeviceTypeId = protectionDeviceTypes.FirstOrDefault(t => t.Model == input.DeviceType)?.Id; var deviceBoards = boards.Where(t => t.ProtectionDeviceInfoId == device.Id).ToList(); // 记录历史数据的方法 void RecordBoardCardHistory(BoardCardInfo oldCardInfo, BoardCardInfo newCardInfo, string boardId) { if (oldCardInfo != null && newCardInfo != null) { var eventDescription = new StringBuilder(); var eventRecordType = EventRecordTypeEnum.Software; // 默认修改事件类型 // 比较各个字段,如果不一致则记录 if (oldCardInfo.FpgaVersion != newCardInfo.FpgaVersion) eventDescription.AppendLine($"FPGA版本更改: {oldCardInfo.FpgaVersion} -> {newCardInfo.FpgaVersion}"); if (oldCardInfo.InterfaceDatabaseVersion != newCardInfo.InterfaceDatabaseVersion) eventDescription.AppendLine($"接口数据库版本更改: {oldCardInfo.InterfaceDatabaseVersion} -> {newCardInfo.InterfaceDatabaseVersion}"); if (oldCardInfo.InterfaceVersion != newCardInfo.InterfaceVersion) eventDescription.AppendLine($"接口版本更改: {oldCardInfo.InterfaceVersion} -> {newCardInfo.InterfaceVersion}"); if (oldCardInfo.InterfaceChecksum != newCardInfo.InterfaceChecksum) eventDescription.AppendLine($"接口校验和更改: {oldCardInfo.InterfaceChecksum} -> {newCardInfo.InterfaceChecksum}"); if (oldCardInfo.SystemVersion != newCardInfo.SystemVersion) eventDescription.AppendLine($"系统版本更改: {oldCardInfo.SystemVersion} -> {newCardInfo.SystemVersion}"); if (oldCardInfo.ProtectionChecksum != newCardInfo.ProtectionChecksum) eventDescription.AppendLine($"保护校验和更改: {oldCardInfo.ProtectionChecksum} -> {newCardInfo.ProtectionChecksum}"); if (oldCardInfo.ProtectionDatabaseVersion != newCardInfo.ProtectionDatabaseVersion) eventDescription.AppendLine($"保护数据库版本更改: {oldCardInfo.ProtectionDatabaseVersion} -> {newCardInfo.ProtectionDatabaseVersion}"); if (oldCardInfo.ProtectionVersion != newCardInfo.ProtectionVersion) eventDescription.AppendLine($"保护版本更改: {oldCardInfo.ProtectionVersion} -> {newCardInfo.ProtectionVersion}"); if (oldCardInfo.YjVersion != newCardInfo.YjVersion) eventDescription.AppendLine($"液晶版本更改: {oldCardInfo.YjVersion} -> {newCardInfo.YjVersion}"); if (oldCardInfo.YjCrc != newCardInfo.YjCrc) eventDescription.AppendLine($"液晶CRC更改: {oldCardInfo.YjCrc} -> {newCardInfo.YjCrc}"); if (eventDescription.Length > 0) { var json = JsonConvert.SerializeObject(oldCardInfo); var newJson = JsonConvert.SerializeObject(newCardInfo); // 创建历史记录 var historyRecord = new BoardCardHistory { ProtectionDeviceInfoId = device.Id, BoardCardInfoId = oldCardInfo.Id, BoardId = boardId, RecodeDate = DateTime.Now, ContentJson = json, ContentNewJson = newJson, EventDescription = eventDescription.ToString(), EventRecordType = eventRecordType, SeqNo = deviceBoards.Count > 0 ? deviceBoards.Max(t => t.SeqNo) + 1 : 1, IsSend = false // 默认为未发送,您可以根据需要调整 }; // 记录历史 _boardCardHistoryRepository.Insert(historyRecord); } } } // 保护板卡 BoardCardInfo cpuCardInfo = deviceBoards.FirstOrDefault(t => t.BoardId == "B01"); if (cpuCardInfo != null) { var newCpuCardInfo = new BoardCardInfo { FpgaVersion = input.FpgaVer, InterfaceDatabaseVersion = input.CommcpuCfgVer, InterfaceVersion = input.CommcpuVer, InterfaceChecksum = input.CommcpuCrc, SystemVersion = input.LinuxVer, ProtectionChecksum = input.ProtectCrc, ProtectionDatabaseVersion = input.ProtectCfgVer, ProtectionVersion = input.ProtectVer }; RecordBoardCardHistory(cpuCardInfo, newCpuCardInfo, "B01"); } // 液晶板卡 BoardCardInfo ioyjCardInfo = deviceBoards.FirstOrDefault(t => t.BoardId == "液晶"); if (ioyjCardInfo != null) { var newIoyjCardInfo = new BoardCardInfo { YjVersion = input.YjVer, YjCrc = input.YjCrc }; RecordBoardCardHistory(ioyjCardInfo, newIoyjCardInfo, "液晶"); } // IO板卡 if (input.IoVersion.Count > 0) { var boardIdMap = new Dictionary { { "B03", 0 }, { "B04", 1 }, { "B05", 2 }, { "B06", 3 }, { "B07", 4 } }; foreach (var boardId in boardIdMap.Keys) { var boardCardInfo = deviceBoards.FirstOrDefault(t => t.BoardId == boardId); if (boardCardInfo != null) { var ioVersion = input.IoVersion[boardIdMap[boardId]]; var newIoCardInfo = new BoardCardInfo { IOVersion = ioVersion.IoVer, IOCrc = ioVersion.IoCrc }; RecordBoardCardHistory(boardCardInfo, newIoCardInfo, boardId); } } } } rst.Flag = true; } catch (Exception ex) { rst.Message = ex.Message; } return rst; } /// /// 生成板卡信息 /// /// [ShowApi] [AbpAllowAnonymous] public async Task SpwanBoardMancfactoryJDYDList() { RequestEasyResult rst = new RequestEasyResult(); try { var manfac = _manufacturerInfoRepository.GetAll().FirstOrDefault(t => t.ManufacturerName.Contains("运达")); if (manfac!=null) { using (var unitOfWork = _unitOfWorkManager.Begin()) { var boards = _boardCardInfoRepository.GetAll(); foreach (var board in boards) { board.ManufacturerInfoId = manfac.Id; board.BoardTypeId = "JDYD"; } await unitOfWork.CompleteAsync(); } using (var unitOfWork = _unitOfWorkManager.Begin()) { var devices = _protectionDeviceInfoRepository.GetAllIncluding(t => t.EquipmentInfo); foreach (var device in devices) { device.EquipmentInfo.ManufacturerInfoId = manfac.Id; } await unitOfWork.CompleteAsync(); } } } catch (Exception ex) { throw; } return rst; } /// /// 填充出厂编号 /// /// [ShowApi] [AbpAllowAnonymous] [HttpGet] public async Task UpdateProtetionInfoForHistoryTest() { RequestEasyResult rst = new RequestEasyResult(); try { List datas; using (var unitOfWork = _unitOfWorkManager.Begin()) { datas = _boardCardInfoRepository.GetAllIncluding(t=>t.ProtectionDeviceInfo).ToList(); await unitOfWork.CompleteAsync(); } Random random = new Random(); for (int i = 0; i < 3; i++) { foreach (var data in datas) { EditBoardCardQrCodeInput deviceInfo = new EditBoardCardQrCodeInput { ProtectionDeviceName = data.ProtectionDeviceInfo.Name, BoardId = data.BoardId, BoardType = data.BoardType, SerialNumber = "210" + random.Next(100000, 1000000).ToString(), // 出厂编号设为 "210" 开头 + 6 位随机数 ProductionDate = new DateTime(2023, 5, 15), // 示例生产日期 VerificationPerson = "贺严玲", // 示例检验人员 VerificationDate = DateTime.Now.AddDays(-100 + i).ToString("yyyy-MM-dd"), // 检验日期设为当前日期 VerificationRecords = "检验板卡外观及功能,均符合要求" // 示例检验记录 }; using (var unitOfWork = _unitOfWorkManager.Begin()) { ScanDeviceQRCode(deviceInfo); await unitOfWork.CompleteAsync(); } } } } catch (Exception ex) { throw; } return rst; } /// /// 生成初始的历史记录 /// /// [ShowApi] [AbpAllowAnonymous] [HttpGet] public RequestEasyResult SpawnBoardHistory() { var rst = new RequestEasyResult(); try { var boards = _boardCardInfoRepository.GetAllIncluding(t=>t.ProtectionDeviceInfo).ToList(); // 模拟插入数据库 foreach (var board in boards) { var boardHistory = new BoardCardHistory { ContentJson = JsonConvert.SerializeObject(board), CreationTime = DateTime.Now, CreatorUserId = base.GetCurrentUser().Id, Name = board.BoardId, RecodeDate = board.CreationTime, BoardId = board.BoardId, BoardCardInfoId = board.Id, EventRecordType = EventRecordTypeEnum.Board, EventDescription = "创建板卡信息台账", ProtectionDeviceInfoId = board.ProtectionDeviceInfoId, SeqNo = 1 }; _boardCardHistoryRepository.Insert(boardHistory); } rst.Flag = true; } catch (Exception e) { throw; } return rst; } } }