/// <summary> /// 删除船员 /// </summary> /// <param name="id"></param> /// <returns></returns> public IActionResult Delete(int id) { try { int code = 1; string errMsg = ""; //陆地端远程删除船员 if (base.user.IsLandHome) { string XMQComId = base.user.ShipId; string tokenstr = HttpContext.Session.GetString("comtoken"); string identity = ManagerHelp.GetLandToId(tokenstr); if (identity == "") { return(new JsonResult(new { code = 1, msg = "人脸组件未启动" })); } assembly.SendCrewDelete(id, XMQComId + ":" + identity); code = GetResult(); if (code == 400) { errMsg = "网络请求超时。。。"; } else if (code != 0) { errMsg = "船员删除失败"; } } else { var employee = _context.Crew.Find(id); if (employee == null) { return(NotFound()); } var employeePictures = _context.CrewPicture.Where(e => e.CrewId == employee.Id).ToList(); if (employeePictures.Count() > 0) { //删除船员图片 _context.CrewPicture.RemoveRange(employeePictures); } string identity = ManagerHelp.GetShipToId(ComponentType.AI, ManagerHelp.FaceName); if (identity == "") { return(new JsonResult(new { code = 1, msg = "人脸组件未启动" })); } assembly.SendCrewDelete(id, identity); //删除船员 _context.Crew.Remove(employee); _context.SaveChanges(); code = 0; } return(new JsonResult(new { code = code, msg = errMsg })); } catch (Exception ex) { return(new JsonResult(new { code = 1, msg = "删除失败!" + ex.Message })); } }
private void SendCrew() { if (ManagerHelp.isFaceAlgorithm && ManagerHelp.isInit == false) { string identity = ManagerHelp.GetShipToId(ComponentType.AI, ManagerHelp.FaceName); if (identity != "") { //等待15秒后发送底库数据 Thread.Sleep(15 * 1000); var crew = ProtoBDManager.CrewQuery(); foreach (var item in crew) { manager.SendCrewAdd(item, identity); } ManagerHelp.isFaceAlgorithm = false; } } }
/// <summary> /// 删除设备 /// </summary> /// <param name="id"></param> /// <returns></returns> public IActionResult Delete(string id, int factory) { try { if (id == null) { return(NotFound()); } int code = 1; string msg = ""; //陆地端删除设备 if (base.user.IsLandHome) { string shipId = base.user.ShipId; string tokenstr = HttpContext.Session.GetString("comtoken"); //获取设备的组件ID string identity = ManagerHelp.GetLandToId(tokenstr); if (identity == "") { return(new JsonResult(new { code = 1, msg = Enum.GetName(typeof(Device.Factory), Convert.ToInt32(factory)) + "组件未启动" })); } assembly.SendDeveiceDelete(shipId + ":" + identity, id); code = GetResult(); } else { var device = _context.Device.Find(id); if (device == null) { return(NotFound()); } var cameras = _context.Camera.Where(c => c.DeviceId == device.Id).ToList(); var cids = string.Join(',', cameras.Select(c => c.Id)); if (cids != "") { var cameraConfig = _context.Algorithm.Where(c => cids.Contains(c.Id)); if (cameraConfig.Count() > 0) { //删除摄像机配置表 _context.Algorithm.RemoveRange(cameraConfig); } //删除摄像机表 _context.Camera.RemoveRange(cameras); } //删除设备表 _context.Device.Remove(device); //获取设备的组件ID string identity = ManagerHelp.GetShipToId(ManagerHelp.GetComponentType(factory)); if (identity == "") { return(new JsonResult(new { code = 1, msg = Enum.GetName(typeof(Device.Factory), Convert.ToInt32(factory)) + "组件未启动" })); } assembly.SendDeveiceDelete(identity, device.Id); code = GetResult(); if (code == 0 || code == -5) { _context.SaveChanges(); code = 0; } } if (code == 2) { msg = "请求超时。。。"; } else if (code != 0) { msg = "删除失败"; } return(new JsonResult(new { code = code, msg = msg })); } catch (Exception ex) { _logger.LogError(ex, "删除设备异常", id); return(new JsonResult(new { code = 1, msg = "删除失败!" + ex.Message })); } }
public IActionResult CamSave(string id, string did, int factory, string nickName, string enable, int index = 0) { if (ModelState.IsValid) { try { int code = 1; string msg = ""; //陆地端远程修改摄像机信息 if (base.user.IsLandHome) { string XMQComId = base.user.ShipId; string tokenstr = HttpContext.Session.GetString("comtoken"); string identity = ManagerHelp.GetLandToId(tokenstr); if (identity == "") { return(new JsonResult(new { code = 1, msg = "当前船舶已失联,请重新连接" })); } //获取设备的组件ID string hkidentity = ManagerHelp.GetLandToId(tokenstr, ManagerHelp.GetComponentType(factory)); if (hkidentity == "") { return(new JsonResult(new { code = 1, msg = Enum.GetName(typeof(Device.Factory), Convert.ToInt32(factory)) + "组件未启动" })); } Device emb = new Device { Id = did, Enable = true, CameraModelList = new List <Camera>() { new Camera() { NickName = nickName, Enable = enable == "1" ? true : false, Index = index, Id = id } } }; assembly.SendDeveiceUpdate(emb, XMQComId + ":" + identity, did); code = GetResult(); } else { Camera camera = _context.Camera.FirstOrDefault(c => c.Id == id); if (camera == null) { return(new JsonResult(new { code = 1, msg = "数据不存在" })); } //获取设备的组件ID string identity = ManagerHelp.GetShipToId(ManagerHelp.GetComponentType(factory)); if (identity == "") { return(new JsonResult(new { code = 1, msg = Enum.GetName(typeof(Device.Factory), Convert.ToInt32(factory)) + "组件未启动" })); } camera.NickName = nickName; camera.Enable = enable == "1" ? true : false; var embModel = _context.Device.FirstOrDefault(e => e.Id == camera.DeviceId); if (embModel != null) { Device emb = new Device { Id = did, CameraModelList = new List <Camera>() { new Camera() { NickName = nickName, Enable = enable == "1" ? true : false, Id = id } } }; assembly.SendDeveiceUpdate(emb, identity, embModel.Id); code = GetResult(); if (code == 0) { _context.Update(camera); _context.SaveChangesAsync(); } } ; } if (code == 2) { msg = "请求超时。。。"; } else if (code != 0) { msg = "配置摄像机信息失败"; } return(new JsonResult(new { code = code, msg = msg })); } catch (Exception ex) { _logger.LogError("修改摄像机信息失败", "Save(" + id + "," + did + "," + nickName + "," + enable + ")"); return(new JsonResult(new { code = 1, msg = "数据保存失败!" + ex.Message })); } } return(new JsonResult(new { code = 0 })); }
public IActionResult Save(string strEmbed) { try { string shipId = base.user.ShipId; int code = 1; string msg = ""; if (shipId == "") { return(new JsonResult(new { code = 1, msg = "船不存在,无法添加数据" })); } var model = JsonConvert.DeserializeObject <DeviceViewModel>(strEmbed); //陆地端远程添加设备 if (base.user.IsLandHome) { string tokenstr = HttpContext.Session.GetString("comtoken"); string identity = ManagerHelp.GetLandToId(tokenstr); if (string.IsNullOrEmpty(identity)) { return(new JsonResult(new { code = 1, msg = "当前船舶已失联,请重新连接" })); } string devComId = ManagerHelp.GetLandToId(tokenstr, ManagerHelp.GetComponentType(model.Factory)); if (string.IsNullOrEmpty(devComId)) { return(new JsonResult(new { code = 1, msg = Enum.GetName(typeof(Device.Factory), Convert.ToInt32(model.Factory)) + "组件未启动" })); } Device emb = GetProtoDevice(model); if (!string.IsNullOrEmpty(model.Id)) { assembly.SendDeveiceUpdate(emb, shipId + ":" + identity, model.Id); } else { assembly.SendDeveiceAdd(emb, shipId + ":" + identity); } code = GetResult(); } else { string identity = ManagerHelp.GetShipToId(ManagerHelp.GetComponentType(model.Factory)); if (identity == "") { return(new JsonResult(new { code = 1, msg = Enum.GetName(typeof(Device.Factory), model.Factory) + "组件未启动" })); } Device device = new Device(); if (!string.IsNullOrEmpty(model.Id)) { device = _context.Device.FirstOrDefault(c => c.Id == model.Id); if (device == null) { return(new JsonResult(new { code = 1, msg = "数据不存在" })); } } device.IP = model.IP; device.Name = model.Name; device.Nickname = model.Nickname; device.Password = model.Password; device.Port = model.Port; device.type = (Device.Type)model.Type; device.factory = (Device.Factory)model.Factory; device.Enable = model.Enable; if (string.IsNullOrEmpty(model.Id)) { device.Id = Guid.NewGuid().ToString(); _context.Device.Add(device); _context.SaveChanges(); model.Id = device.Id; Device emb = GetProtoDevice(model); assembly.SendDeveiceAdd(emb, identity); } else { Device emb = GetProtoDevice(model); _context.Device.Update(device); _context.SaveChanges(); assembly.SendDeveiceUpdate(emb, identity, device.Id); } code = GetResult(); if (code == -2) { Device emb = GetProtoDevice(model); assembly.SendDeveiceAdd(emb, identity); code = GetResult(); } } if (code == 400) { msg = "请求超时。。。"; } else if (code != 0) { msg = "请输入正确的设备参数"; } return(new JsonResult(new { code = code, msg = msg })); } catch (Exception ex) { _logger.LogError(ex, "保存设备信息异常", strEmbed); return(new JsonResult(new { code = 1, msg = "数据保存失败!" + ex.Message })); } }
/// <summary> /// 保存(新增/修改) /// </summary> /// <param name="id"></param> /// <param name="name"></param> /// <param name="job"></param> /// <param name="picIds">图片ID</param> /// <returns></returns> public IActionResult Save(int id, string name, string job, string picIds) { try { if (base.user.ShipId == "") { return(new JsonResult(new { code = 1, msg = "船不存在,无法添加数据" })); } int code = 1; string errMsg = ""; List <string> ids = new List <string>(); if (picIds != null) { ids = picIds.Split(',').ToList(); } if (base.user.IsLandHome) { #region 陆地端添加/修改船员 //xmq的组件ID string XMQComId = base.user.ShipId; string tokenstr = HttpContext.Session.GetString("comtoken"); string identity = ManagerHelp.GetLandToId(tokenstr); if (identity == "") { return(new JsonResult(new { code = 1, msg = "当前船舶已失联,请重新连接" })); } string algoComId = ManagerHelp.GetLandToId(tokenstr, ComponentType.AI, ManagerHelp.FaceName); if (string.IsNullOrEmpty(algoComId)) { return(new JsonResult(new { code = 1, msg = "人脸组件未启动" })); } ProtoBuffer.Models.CrewInfo emp = GetCrewInfo(id, name, job, ids); if (id > 0) { assembly.SendCrewUpdate(emp, XMQComId + ":" + identity); } else { assembly.SendCrewAdd(emp, XMQComId + ":" + identity); } code = GetResult(); if (code == 2) { errMsg = "船员名称不能重复"; } if (code == 400) { errMsg = "网络请求超时。。。"; } else if (code != 0) { errMsg = "船员信息保存失败"; } //清除已经上传了的图片 foreach (var item in ids) { picBytes.Remove(item); } return(new JsonResult(new { code = code, msg = code == 2 ? "船员名称不能重复" : "数据保存失败" })); #endregion } else { Crew employee = new Crew(); if (!CheckData(id, name, ref employee, ref errMsg)) { return(new JsonResult(new { code = 1, msg = errMsg })); } string identity = ManagerHelp.GetShipToId(ComponentType.AI, ManagerHelp.FaceName); if (identity == "") { return(new JsonResult(new { code = 1, msg = "人脸组件未启动" })); } //增加或修改 AddOrUpdate(id, name, job, ids, ref employee); //发送netmq消息 var dbPic = _context.CrewPicture.Where(c => c.CrewId == employee.Id).ToList(); List <string> bytes = new List <string>(); foreach (var item in dbPic) { bytes.Add(Convert.ToBase64String(item.Picture)); } ProtoBuffer.Models.CrewInfo crewInfo = new ProtoBuffer.Models.CrewInfo() { job = employee.Job, name = employee.Name, uid = employee.Id.ToString(), pictures = bytes }; //if (id > 0) { assembly.SendCrewUpdate(crewInfo, identity); } //else { assembly.SendCrewAdd(crewInfo, identity); } assembly.SendCrewAdd(crewInfo, identity); code = GetResult(); if (code == 400) { errMsg = "网络请求超时。。。"; } else if (code != 0) { errMsg = "船员信息保存失败"; } } return(new JsonResult(new { code = code, msg = errMsg })); } catch (Exception ex) { return(new JsonResult(new { code = 1, msg = "保存失败!" + ex.Message })); } }
/// <summary> /// 保存算法 /// </summary> /// <param name="model"></param> /// <returns></returns> public IActionResult Save(string model) { try { string shipId = base.user.ShipId;//为陆地端时保存的是XMQ的组件ID if (shipId == "") { return(new JsonResult(new { code = 1, msg = "船不存在,无法添加数据" })); } var viewModel = JsonConvert.DeserializeObject <AlgorithmViewModel>(model); if (viewModel != null) { int code = 1; string errMsg = ""; string AIName = Enum.GetName(typeof(AlgorithmType), viewModel.Type); if (base.user.IsLandHome) { //获取当前船舶的组件ID(webId) string tokenstr = HttpContext.Session.GetString("comtoken"); string identity = ManagerHelp.GetLandToId(tokenstr); if (string.IsNullOrEmpty(identity)) { return(new JsonResult(new { code = 1, msg = "当前船舶已失联,请重新连接" })); } //获取当前组件下的某个算法 string algoComId = ManagerHelp.GetLandToId(tokenstr, ComponentType.AI, AIName); if (string.IsNullOrEmpty(algoComId) && viewModel.Type != (int)AlgorithmType.CAPTURE) { string name = GetViewName((AlgorithmType)viewModel.Type); return(new JsonResult(new { code = 1, msg = "算法【" + name + "】组件未启动" })); } var cam = cameras.FirstOrDefault(c => c.Id == viewModel.Cid); //算法里的摄像机ID=设备ID:摄像机ID:摄像机通道 string cid = cam.DeviceId + ":" + cam.Id + ":" + cam.Index; //向船舶端发送算法配置请求 ProtoBuffer.Models.AlgorithmInfo algorithm = GetProtoAlgorithm(viewModel, cid); code = SendData(algorithm, (shipId + ":" + identity)); if (code == 400) { errMsg = "网络请求超时。。。"; } else if (code != 0) { errMsg = "算法配置失败"; } } else { Algorithm algo = new Algorithm(); if (!DataCheck(viewModel, ref algo, ref errMsg)) { return(new JsonResult(new { code = 1, msg = errMsg })); } //获取船舶某个算法的组件ID string identity = ManagerHelp.GetShipToId(ComponentType.AI, AIName); if (string.IsNullOrEmpty(identity) && viewModel.Type != (int)AlgorithmType.CAPTURE) { string name = GetViewName((AlgorithmType)viewModel.Type); return(new JsonResult(new { code = 1, msg = "算法【" + name + "】组件未启动" })); } algo.GPU = viewModel.GPU; algo.Type = (AlgorithmType)viewModel.Type; algo.Similar = viewModel.Similar; algo.Cid = viewModel.Cid; algo.DectectFirst = viewModel.DectectFirst; algo.DectectSecond = viewModel.DectectSecond; algo.Track = viewModel.Track; if (!string.IsNullOrEmpty(viewModel.Id)) { algo.Id = viewModel.Id; _context.Algorithm.Update(algo); } else { algo.Id = Guid.NewGuid().ToString(); _context.Algorithm.Add(algo); } //缺岗直接进库不用发消息 if (viewModel.Type == (int)AlgorithmType.CAPTURE) { _context.SaveChanges(); code = 0; ManagerHelp.LiveTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } else { viewModel.Id = algo.Id; var camera = _context.Camera.FirstOrDefault(c => c.Id == viewModel.Cid); if (camera != null) { string cid = camera.DeviceId + ":" + camera.Id + ":" + camera.Index; ProtoBuffer.Models.AlgorithmInfo algorithm = GetProtoAlgorithm(viewModel, cid); ManagerHelp.isFaceAlgorithm = false; if (viewModel.Type == (int)AlgorithmType.ATTENDANCE_IN || viewModel.Type == (int)AlgorithmType.ATTENDANCE_OUT) { ManagerHelp.isFaceAlgorithm = true; } code = SendData(algorithm, identity); if (code == 0) { _context.SaveChanges(); } else if (code == 2) { errMsg = "网络请求超时。。。"; } else { errMsg = "算法配置失败"; } } } } return(new JsonResult(new { code = code, msg = errMsg })); } return(new JsonResult(new { code = 1, msg = "操作界面数据失败!" })); } catch (Exception ex) { _logger.LogError("保存算法配置失败", model); return(new JsonResult(new { code = 1, msg = "数据保存失败!" + ex.Message })); } }
/// <summary> /// 算法处理 /// </summary> /// <param name="fromId">算法来源</param> /// <param name="algorithm"></param> public void AlgorithmData(SmartWeb.ProtoBuffer.Models.Algorithm algorithm, string fromId) { //添加日志 ProtoBDManager.AddReceiveLog <SmartWeb.ProtoBuffer.Models.Algorithm>("Algorithm/" + Enum.GetName(typeof(Models.Component.Command), Convert.ToInt32(algorithm.command)), algorithm); switch (algorithm.command) { case Models.Algorithm.Command.CONFIGURE_REQ: #region 陆地端发送算法设置请求 var request = algorithm.algorithmrequest; if (request == null) { manager.SendAlgorithmRN(Models.Algorithm.Command.CONFIGURE_REP, null, 1); break; } var devcid = request.algorithminfo.cid.Split(":"); //cid=did:cid:index(设备ID:摄像机ID:摄像机通道) var cid = devcid[1]; request.algorithminfo.cid = cid; int result = ProtoBDManager.AlgorithmSet(request.algorithminfo); if (result == 0) { if (request.algorithminfo.type == AlgorithmInfo.Type.CAPTURE) { ManagerHelp.LiveTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } if (request.algorithminfo.type != AlgorithmInfo.Type.CAPTURE) { string name = Enum.GetName(typeof(AlgorithmType), request.algorithminfo.type); string identity = ManagerHelp.GetShipToId(ComponentType.AI, name); if (identity != "") { //向算法组件注册时只需要传入设备ID和摄像机通道 request.algorithminfo.cid = devcid[0] + ":" + devcid[1] + ":" + devcid[2]; ManagerHelp.isFaceAlgorithm = false; if (request.algorithminfo.type == AlgorithmInfo.Type.ATTENDANCE_IN || request.algorithminfo.type == AlgorithmInfo.Type.ATTENDANCE_OUT) { ManagerHelp.isFaceAlgorithm = true; } manager.SendAlgorithmSet(request.algorithminfo, identity); ManagerHelp.UpSend.Add("Algorithm"); } else { manager.SendAlgorithmRN(Models.Algorithm.Command.CONFIGURE_REP, null, 1); } } else { //向陆地端响应算法请求 manager.SendAlgorithmRN(Models.Algorithm.Command.CONFIGURE_REP, null, result); } } else { //向陆地端响应算法请求 manager.SendAlgorithmRN(Models.Algorithm.Command.CONFIGURE_REP, null, result); } break; #endregion case Models.Algorithm.Command.QUERY_REQ: #region 陆地端发送算法查询请求 //查询船舶端数据库获取所有算法数据 var algorithms = ProtoBDManager.AlgorithmQuery(true); //返回给陆地端 manager.SendAlgorithmRN(Models.Algorithm.Command.QUERY_REP, algorithms); break; #endregion case Models.Algorithm.Command.CONFIGURE_REP: if (ManagerHelp.UpSend.Where(c => c == "Algorithm").Any()) { //向陆地端响应请求 manager.SendAlgorithmRN(Models.Algorithm.Command.CONFIGURE_REP, null, algorithm.algorithmresponse.result); ManagerHelp.UpSend.Remove("Algorithm"); } else { ManagerHelp.AlgorithmResult = algorithm.algorithmresponse.result.ToString(); } if (ManagerHelp.IsShipPort) { //算法配置成功后把船状态推送给当前算法 if (algorithm.algorithmresponse.result == 0) { var ship = ProtoBDManager.StatusQuery(); manager.SendStatusSet(ship, StatusRequest.Type.SAIL, fromId); SendCrew(); } } break; case Models.Algorithm.Command.QUERY_REP: if (algorithm.algorithmresponse != null && algorithm.algorithmresponse.result == 0 && algorithm.algorithmresponse.configures != null) { ManagerHelp.AlgorithmReponse = JsonConvert.SerializeObject(algorithm.algorithmresponse.configures); } break; default: break; } }
/// <summary> /// 船员处理 /// </summary> /// <param name="crew"></param> public void CrewData(SmartWeb.ProtoBuffer.Models.Crew crew) { int result = 1;//响应状态 switch (crew.command) { case Models.Crew.Command.NEW_REQ: #region 陆地端添加船员请求 if (crew.crewrequest == null) { manager.SendCrewRN(Models.Crew.Command.NEW_REP, null, 1); } else { var crewInfo = crew.crewrequest.crewinfo; result = ProtoBDManager.CrewAdd(ref crewInfo); if (result == 0) { string identity = ManagerHelp.GetShipToId(ComponentType.AI, ManagerHelp.FaceName); if (identity != "") { //向组件发送船员请求 manager.SendCrewAdd(crewInfo, identity); ManagerHelp.UpSend.Add("CrewAdd"); } else { //向陆地端响应算法请求 manager.SendCrewRN(Models.Crew.Command.NEW_REP, null, result); } } else { //向陆地端响应算法请求 manager.SendCrewRN(Models.Crew.Command.NEW_REP, null, result); } } break; #endregion case Models.Crew.Command.DELETE_REQ: #region 陆地端删除船员请求 if (crew.crewrequest == null) { manager.SendCrewRN(Models.Crew.Command.DELETE_REP, null, 1); } else { result = ProtoBDManager.CrewDelete(crew.crewrequest.crewinfo.uid); if (result == 0) { string identity = ManagerHelp.GetShipToId(ComponentType.AI, ManagerHelp.FaceName); //向组件发送船员请求 manager.SendCrewDelete(Convert.ToInt32(crew.crewrequest.crewinfo.uid), identity); ManagerHelp.UpSend.Add("CrewDel"); } else { manager.SendCrewRN(Models.Crew.Command.DELETE_REP, null, result); } } break; #endregion case Models.Crew.Command.MODIFY_REQ: #region 陆地端修改船员请求 if (crew.crewrequest == null) { manager.SendCrewRN(Models.Crew.Command.MODIFY_REP, null, 1); } else { result = ProtoBDManager.CrewUpdate(crew.crewrequest.crewinfo); if (result == 0) { string identity = ManagerHelp.GetShipToId(ComponentType.AI, ManagerHelp.FaceName); if (identity != "") { //向组件发送船员请求 //manager.SendCrewUpdate(crew.crewrequest.crewinfo, identity); manager.SendCrewAdd(crew.crewrequest.crewinfo, identity); ManagerHelp.UpSend.Add("CrewEdit"); } else { manager.SendCrewRN(Models.Crew.Command.MODIFY_REP, null, result); } } else { manager.SendCrewRN(Models.Crew.Command.MODIFY_REP, null, result); } } break; #endregion case Models.Crew.Command.QUERY_REQ: #region 陆地端查询船员请求 int uid = crew.crewrequest != null && crew.crewrequest.crewinfo != null?Convert.ToInt32(crew.crewrequest.crewinfo.uid) : 0; var crews = ProtoBDManager.CrewQuery(uid); manager.SendCrewRN(Models.Crew.Command.QUERY_REP, crews); break; #endregion case Models.Crew.Command.NEW_REP: if (ManagerHelp.UpSend.Where(c => c == "CrewAdd").Any()) { //向陆地端响应请求 manager.SendCrewRN(Models.Crew.Command.NEW_REP, null, crew.crewresponse.result); ManagerHelp.UpSend.Remove("CrewAdd"); } else { ManagerHelp.CrewResult = crew.crewresponse.result.ToString(); } break; case Models.Crew.Command.DELETE_REP: if (ManagerHelp.UpSend.Where(c => c == "CrewDel").Any()) { //向陆地端响应请求 manager.SendCrewRN(Models.Crew.Command.DELETE_REP, null, crew.crewresponse.result); ManagerHelp.UpSend.Remove("CrewDel"); } else { ManagerHelp.CrewResult = crew.crewresponse.result.ToString(); } break; case Models.Crew.Command.MODIFY_REP: if (ManagerHelp.UpSend.Where(c => c == "CrewEdit").Any()) { //向陆地端响应请求 manager.SendCrewRN(Models.Crew.Command.MODIFY_REP, null, crew.crewresponse.result); ManagerHelp.UpSend.Remove("CrewEdit"); } else { ManagerHelp.CrewResult = crew.crewresponse.result.ToString(); } break; case Models.Crew.Command.QUERY_REP: if (crew.crewresponse != null && crew.crewresponse.result == 0 && crew.crewresponse.crewinfos != null) { ManagerHelp.CrewReponse = JsonConvert.SerializeObject(crew.crewresponse.crewinfos); } break; default: break; } }
/// <summary> /// 设备处理 /// </summary> /// <param name="device"></param> public void DeviceData(SmartWeb.ProtoBuffer.Models.Device device) { //添加日志 ProtoBDManager.AddReceiveLog <SmartWeb.ProtoBuffer.Models.Device>("Device/" + Enum.GetName(typeof(Models.Component.Command), Convert.ToInt32(device.command)), device); switch (device.command) { //上游陆地端的请求 case Models.Device.Command.NEW_REQ: #region 陆地端增加设备请求 if (device.devicerequest != null) { var model = ProtoBDManager.DeviceAdd(device.devicerequest.deviceinfo); if (model != null) { //获取设置的组件ID string identity = ManagerHelp.GetShipToId(ManagerHelp.GetComponentType((int)model.factory)); if (identity != "") { manager.SendDeveiceAdd(model, identity); ManagerHelp.UpSend.Add(model.Id + "Add"); } else { manager.SendDeviceRN(Models.Device.Command.MODIFY_REP, "", null, 1); } } } else { manager.SendDeviceRN(Models.Device.Command.NEW_REP, "", null, 1); } break; #endregion case Models.Device.Command.DELETE_REQ: #region 陆地端删除设备请求 if (device.devicerequest != null && !string.IsNullOrEmpty(device.devicerequest.deviceinfo.did)) { //删除船舶端数据 var result = ProtoBDManager.DeviceDelete(device.devicerequest.deviceinfo.did); manager.SendDeviceRN(Models.Device.Command.DELETE_REP, device.devicerequest.deviceinfo.did, null, result); } else { manager.SendDeviceRN(Models.Device.Command.DELETE_REP, "", null, 1); } break; #endregion case Models.Device.Command.MODIFY_REQ: #region 陆地端编辑设备请求 if (device.devicerequest != null && !string.IsNullOrEmpty(device.devicerequest.did)) { bool isSend = false; //修改船舶端数据库信息 var model = ProtoBDManager.DeviceUpdate(device.devicerequest.did, device.devicerequest.deviceinfo, ref isSend); if (model != null && isSend) { //获取设置的组件ID string identity = ManagerHelp.GetShipToId(ManagerHelp.GetComponentType((int)model.factory)); if (identity != "") { manager.SendDeveiceUpdate(model, identity); ManagerHelp.UpSend.Add(model.Id + "Edit"); } else { manager.SendDeviceRN(Models.Device.Command.MODIFY_REP, "", null, 1); } } else { manager.SendDeviceRN(Models.Device.Command.MODIFY_REP, "", null, isSend?0:1); } } else { manager.SendDeviceRN(Models.Device.Command.MODIFY_REP, "", null, 1); } break; #endregion case Models.Device.Command.QUERY_REQ: #region 陆地端查询设备请求 var info = device.devicerequest == null ? null : device.devicerequest.deviceinfo; string did = device.devicerequest != null ? device.devicerequest.did : ""; var devices = ProtoBDManager.DeviceQuery(info, did); manager.SendDeviceRN(Models.Device.Command.QUERY_REP, did, devices); break; #endregion case Models.Device.Command.NEW_REP: #region XMQ响应设备增加 did = ""; if (device.deviceresponse.result == 0 && device.deviceresponse.deviceinfos != null) { var dev = device.deviceresponse.deviceinfos[0]; ProtoBDManager.AddCameras(dev.camerainfos, dev.did); did = dev.did; } if (ManagerHelp.UpSend.Where(c => c == did + "Add").Any()) { //向陆地端响应请求 manager.SendDeviceRN(Models.Device.Command.NEW_REP, did); ManagerHelp.UpSend.Remove(did + "Add"); } else { ManagerHelp.DeviceResult = device.deviceresponse.result.ToString(); //-101设备已经存在 -2设备未添加就执行了修改 if (device.deviceresponse.result != 0 && device.deviceresponse.result != -2 && device.deviceresponse.result != -101) { if (device.deviceresponse != null && device.deviceresponse.deviceinfos != null && device.deviceresponse.deviceinfos.Count > 0) { did = device.deviceresponse.deviceinfos[0].did; ProtoBDManager.DeviceDelete(did); } } } break; #endregion case Models.Device.Command.DELETE_REP: ManagerHelp.DeviceResult = device.deviceresponse.result.ToString(); break; case Models.Device.Command.MODIFY_REP: #region XMQ响应设备修改 did = device.deviceresponse.did; if (device.deviceresponse.result == 0 && device.deviceresponse.deviceinfos != null) { ProtoBDManager.DeviceUpdate(did, device.deviceresponse.deviceinfos[0]); } if (ManagerHelp.UpSend.Where(c => c == did + "Edit").Any()) { //向陆地端响应请求 manager.SendDeviceRN(Models.Device.Command.MODIFY_REP, did); ManagerHelp.UpSend.Remove(did + "Edit"); } else { ManagerHelp.DeviceResult = device.deviceresponse.result.ToString(); } break; #endregion case Models.Device.Command.QUERY_REP: if (device.deviceresponse != null && device.deviceresponse.result == 0 && device.deviceresponse.deviceinfos != null) { ManagerHelp.DeviceReponse = JsonConvert.SerializeObject(device.deviceresponse.deviceinfos); } break; default: break; } }