示例#1
0
 /// <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 }));
     }
 }
示例#2
0
 public IActionResult Load()
 {
     try
     {
         Ship ship = new Ship();
         if (base.user.IsLandHome)
         {
             string browsertoken = HttpContext.Session.GetString("comtoken");
             string XMQComId     = base.user.ShipId + ":" + ManagerHelp.GetLandToId(browsertoken);
             assembly.SendStatusQuery(XMQComId);
             bool flag = true;
             new TaskFactory().StartNew(() =>
             {
                 while (ManagerHelp.StatusReponse == "" && flag)
                 {
                     Thread.Sleep(1000);
                 }
             }).Wait(3000);
             flag = false;
             if (ManagerHelp.StatusReponse != "")
             {
                 var response = JsonConvert.DeserializeObject <StatusResponse>(ManagerHelp.StatusReponse);
                 if (response != null)
                 {
                     ship.Flag = response.flag;
                     ship.Name = response.name.Split('|')[0];
                     if (response.name.Split('|').Length > 1)
                     {
                         ship.type = (Ship.Type)Convert.ToInt32(response.name.Split('|')[1]);
                     }
                 }
             }
         }
         else
         {
             ship = _context.Ship.FirstOrDefault();
         }
         var result = new
         {
             code  = 0,
             data  = ship,
             isSet = base.user.EnableConfigure
         };
         return(new JsonResult(result));
     }
     catch (Exception ex)
     {
         return(new JsonResult(new { code = 1, msg = "获取数据失败!" + ex.Message }));
     }
 }
示例#3
0
 /// <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 }));
     }
 }
示例#4
0
 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 }));
 }
示例#5
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 }));
            }
        }
示例#6
0
        /// <summary>
        /// 陆地端查看设备信息
        /// </summary>
        /// <returns></returns>
        private IActionResult LandLoad()
        {
            List <Device> list = new List <Device>();
            //XMQ的组件ID
            string XMQComId = base.user.ShipId;
            string tokenstr = HttpContext.Session.GetString("comtoken");
            //获取XMQ组件里的WEB组件ID
            string webIdentity = ManagerHelp.GetLandToId(tokenstr);
            var    result      = new
            {
                code  = 0,
                data  = list,
                isSet = !string.IsNullOrEmpty(base.user.ShipId) ? base.user.EnableConfigure : false
            };

            if (webIdentity == "")
            {
                return(new JsonResult(result));
            }
            //发送查询设备请求
            assembly.SendDeveiceQuery(XMQComId + ":" + webIdentity);
            bool flag = true;

            new TaskFactory().StartNew(() =>
            {
                while (flag && ManagerHelp.DeviceReponse == "")
                {
                    Thread.Sleep(500);
                }
            }).Wait(timeout);
            flag = false;
            if (ManagerHelp.DeviceReponse != "")
            {
                List <ProtoBuffer.Models.DeviceInfo> devices = JsonConvert.DeserializeObject <List <ProtoBuffer.Models.DeviceInfo> >(ManagerHelp.DeviceReponse);
                ManagerHelp.DeviceReponse = "";
                foreach (var item in devices)
                {
                    Device model = new Device()
                    {
                        Enable   = item.enable,
                        factory  = (Device.Factory)((int)item.factory),
                        Id       = item.did,
                        IP       = item.ip,
                        Name     = item.name,
                        Nickname = item.nickname,
                        Password = item.password,
                        Port     = item.port,
                        type     = (Device.Type)((int)item.type)
                    };
                    var cam = item.camerainfos;
                    model.CameraModelList = new List <Camera>();
                    if (cam != null)
                    {
                        foreach (var it in cam)
                        {
                            model.CameraModelList.Add(new Camera()
                            {
                                Index    = it.index,
                                Id       = it.cid,
                                Enable   = it.enable,
                                IP       = it.ip,
                                NickName = it.nickname,
                                DeviceId = item.did
                            });
                        }
                    }
                    list.Add(model);
                }
            }
            //var result = new
            //{
            //    code = 0,
            //    data = list,
            //    isSet = !string.IsNullOrEmpty(base.user.ShipId) ? base.user.EnableConfigure : false
            //};
            return(new JsonResult(result));
        }
示例#7
0
        /// <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 }));
            }
        }
示例#8
0
        /// <summary>
        /// 陆地端查看船员信息
        /// </summary>
        /// <returns></returns>
        private IActionResult LandLoad()
        {
            //XMQ的组件ID
            string XMQComId = base.user.ShipId;
            string tokenstr = HttpContext.Session.GetString("comtoken");
            //获取XMQ组件里的WEB组件ID
            string webIdentity = ManagerHelp.GetLandToId(tokenstr);

            assembly.SendCrewQuery(XMQComId + ":" + webIdentity);
            List <ProtoBuffer.Models.CrewInfo> crewInfos = new List <ProtoBuffer.Models.CrewInfo>();

            try
            {
                bool flag = true;
                new TaskFactory().StartNew(() =>
                {
                    while (flag)
                    {
                        if (ManagerHelp.CrewReponse != "")
                        {
                            crewInfos = JsonConvert.DeserializeObject <List <ProtoBuffer.Models.CrewInfo> >(ManagerHelp.CrewReponse);
                            flag      = false;
                        }
                        Thread.Sleep(500);
                    }
                }).Wait(timeout);
                flag = false;
            }
            catch (Exception)
            {
            }
            ManagerHelp.CrewReponse = "";
            crewVMList = new List <CrewViewModel>();
            foreach (var item in crewInfos)
            {
                CrewViewModel model = new CrewViewModel()
                {
                    Id   = Convert.ToInt32(item.uid),
                    Job  = item.job,
                    Name = item.name,
                    crewPictureViewModels = new List <CrewPictureViewModel>()
                };
                if (item.pictures != null)
                {
                    foreach (var pic in item.pictures)
                    {
                        CrewPictureViewModel vm = new CrewPictureViewModel()
                        {
                            Id      = Guid.NewGuid().ToString(),
                            Picture = pic
                        };
                        model.crewPictureViewModels.Add(vm);
                    }
                }
                crewVMList.Add(model);
            }
            var result = new
            {
                code  = 0,
                data  = crewVMList,
                count = crewInfos.Count(),
                isSet = !string.IsNullOrEmpty(XMQComId) ? base.user.EnableConfigure : false
            };

            return(new JsonResult(result));
        }
示例#9
0
        public IActionResult LandLoad()
        {
            string identtity    = base.user.ShipId;
            string browsertoken = HttpContext.Session.GetString("comtoken");
            string webId        = ManagerHelp.GetLandToId(browsertoken);
            List <AlgorithmViewModel> algorithms = new List <AlgorithmViewModel>();
            List <ProtoBuffer.Models.AlgorithmInfo> protoDate = new List <ProtoBuffer.Models.AlgorithmInfo>();

            if (string.IsNullOrEmpty(webId))
            {
                return(new JsonResult(new { code = 0, data = algorithms }));
            }
            assembly.SendAlgorithmQuery(identtity + ":" + webId);
            assembly.SendDeveiceQuery(identtity + ":" + webId);
            bool flag = true;

            new TaskFactory().StartNew(() =>
            {
                while (flag)
                {
                    if (ManagerHelp.AlgorithmReponse != "" && ManagerHelp.DeviceReponse != "")
                    {
                        flag = false;
                    }
                    Thread.Sleep(100);
                }
            }).Wait(timeout);
            flag = false;
            try
            {
                if (ManagerHelp.AlgorithmReponse != "")
                {
                    protoDate = JsonConvert.DeserializeObject <List <ProtoBuffer.Models.AlgorithmInfo> >(ManagerHelp.AlgorithmReponse);
                }
                if (ManagerHelp.DeviceReponse != "")
                {
                    boatDevices = JsonConvert.DeserializeObject <List <ProtoBuffer.Models.DeviceInfo> >(ManagerHelp.DeviceReponse);
                }
                ManagerHelp.AlgorithmReponse = "";
                ManagerHelp.DeviceReponse    = "";
            }
            catch (Exception)
            {
            }
            cameras = new List <Camera>();
            foreach (var item in boatDevices)
            {
                if (item.camerainfos != null)
                {
                    foreach (var cam in item.camerainfos)
                    {
                        Camera model = new Camera()
                        {
                            Id       = cam.cid,
                            NickName = cam.nickname,
                            DeviceId = item.did,
                            Index    = cam.index
                        };
                        cameras.Add(model);
                    }
                }
            }
            foreach (var item in protoDate)
            {
                string cid      = item.cid;
                string nickName = "";
                if (cameras.Where(c => c.Id == cid).Any())
                {
                    nickName = cameras.FirstOrDefault(c => c.Id == cid).NickName;
                }
                algorithms.Add(new AlgorithmViewModel()
                {
                    Cid           = cid,
                    NickName      = nickName,
                    DectectFirst  = item.dectectfirst,
                    DectectSecond = item.dectectsecond,
                    GPU           = item.gpu,
                    Id            = item.aid,
                    Similar       = item.similar,
                    Track         = item.track,
                    Type          = (int)item.type
                });
            }

            var result = new
            {
                code   = 0,
                data   = algorithms,
                camera = cameras
            };

            return(new JsonResult(result));
        }
示例#10
0
 /// <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 }));
     }
 }
示例#11
0
 /// <summary>
 /// 保存船状态
 /// </summary>
 /// <param name="ship"></param>
 /// <returns></returns>
 public IActionResult Save(string id, string name, int type)
 {
     try
     {
         if (!base.user.EnableConfigure)
         {
             new JsonResult(new { code = 1, msg = "您没有权限修改数据!" });
         }
         int    code   = 1;
         string errMsg = "";
         if (base.user.IsLandHome)
         {
             string cid      = base.user.ShipId;
             string tokenstr = HttpContext.Session.GetString("comtoken");
             string identity = ManagerHelp.GetLandToId(tokenstr);
             if (string.IsNullOrEmpty(identity))
             {
                 return(new JsonResult(new { code = 1, msg = "当前船舶已失联,请重新连接" }));
             }
             Ship ship = new Ship()
             {
                 type = (Ship.Type)type,
                 Name = name,
                 Flag = type == 1 ? true : false
             };
             string toId = cid + ":" + identity;
             assembly.SendStatusSet(ship, StatusRequest.Type.SAIL, toId);
             assembly.SendStatusSet(ship, StatusRequest.Type.NAME, toId);
             code = GetResult();
             if (code == 0)
             {
                 var component = _context.Component.FirstOrDefault(c => c.Cid == cid);
                 if (component != null)
                 {
                     var landship = _context.Ship.FirstOrDefault(c => c.Id == component.ShipId);
                     if (landship != null)
                     {
                         landship.Name = ship.Name;
                         landship.type = ship.type;
                         //航行类型为:自动时,默认状态为停港
                         landship.Flag = ship.Flag;
                         _context.Ship.Update(landship);
                         _context.SaveChanges();
                     }
                 }
             }
         }
         else
         {
             #region 船舶端修改船状态
             if (!string.IsNullOrEmpty(id))
             {
                 var ship = _context.Ship.FirstOrDefault(c => c.Id == id);
                 if (ship != null)
                 {
                     ship.Name = name;
                     ship.type = (Ship.Type)type;
                     //航行类型为:自动时,默认状态为停港
                     ship.Flag = type == 1 ? true : false;
                 }
                 _context.Ship.Update(ship);
                 _context.SaveChanges();
                 SendMqMsg(ship);
                 code = 0;
             }
             #endregion
         }
         if (code == 400)
         {
             errMsg = "网络超时。。。";
         }
         else if (code != 0)
         {
             errMsg = "数据保存失败";
         }
         return(new JsonResult(new { code = code, msg = errMsg }));
     }
     catch (Exception ex)
     {
         _logger.LogError("保存船信息异常Save(" + id + "," + name + "," + type + ")" + ex.Message);
         return(new JsonResult(new { code = 0, msg = "数据保存失败" + ex.Message }));
     }
 }