コード例 #1
0
 /// <summary>
 /// 船员请求
 /// </summary>
 /// <param name="nextIdentity"></param>
 public void InitCrew()
 {
     using (var con = new MyContext())
     {
         var component = con.Component.FirstOrDefault(c => c.Type != ComponentType.AI && c.Name == ManagerHelp.FaceName && c.Line == 0);
         if (component != null)
         {
             var crewInfos = ProtoBDManager.CrewQuery();
             foreach (var item in crewInfos)
             {
                 assembly.SendCrewAdd(item, component.Cid);
             }
         }
     }
 }
コード例 #2
0
ファイル: CrewController.cs プロジェクト: Colinwang531/web
        /// <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 }));
            }
        }