///<summary>
        ///修改:
        ///</summary>
        /// <param name="model">要修改的model</param>
        /// <returns>受影响的行数</returns>
        public Result <int> UpdateSignInformation(Epm_SignInformation model)
        {
            Result <int> result = new Result <int>();

            try
            {
                var rows = DataOperateBusiness <Epm_SignInformation> .Get().Update(model);

                result.Data = rows;
                result.Flag = EResultFlag.Success;
                WriteLog(AdminModule.AdminUserManager.GetText(), SystemRight.Modify.GetText(), "修改: " + model.Id);
            }
            catch (Exception ex)
            {
                result.Data      = -1;
                result.Flag      = EResultFlag.Failure;
                result.Exception = new ExceptionEx(ex, "UpdateSignInformation");
            }
            return(result);
        }
        ///<summary>
        ///添加:
        ///</summary>
        /// <param name="model">要添加的model</param>
        /// <returns>受影响的行数</returns>
        public Result <int> AddSignInformation(Epm_SignInformation model)
        {
            Result <int> result = new Result <int>();

            try
            {
                model = SetCurrentUser(model);
                model = SetCreateUser(model);
                var rows = DataOperateBusiness <Epm_SignInformation> .Get().Add(model);

                result.Data = rows;
                result.Flag = EResultFlag.Success;
                WriteLog(AdminModule.AdminUserManager.GetText(), SystemRight.Add.GetText(), "新增: " + model.Id);
            }
            catch (Exception ex)
            {
                result.Data      = -1;
                result.Flag      = EResultFlag.Failure;
                result.Exception = new ExceptionEx(ex, "AddSignInformation");
            }
            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// 人脸搜索
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Result <int> SearchUserFace(SignFaceAI model)
        {
            BasicDataContext    basedb    = new BasicDataContext();
            BusinessDataContext busdb     = new BusinessDataContext();
            Result <int>        resultObj = new Result <int>();

            resultObj.Data = -1;
            try
            {
                //查询用户是否注册人脸信息
                var userFaceList = DataOperateBusiness <EPM_AIUserFace> .Get(busdb).GetList(t => t.UserId == model.UserId);

                if (!userFaceList.Any())
                {
                    throw new Exception("您还没有注册人脸识别信息!");
                }
                else
                {
                    var    imageType   = "BASE64";
                    var    groupIdList = "group1";
                    string control     = "LOW";
                    model.Image = model.Image.Substring(model.Image.IndexOf(",") + 1);      //将‘,’以前的多余字符串删除
                    var options = new Dictionary <string, object> {
                        { "quality_control", control },
                        { "liveness_control", control },
                        { "user_id", model.UserId.ToString() }
                    };
                    //签到表
                    Epm_SignInformation modelSign = new Epm_SignInformation();
                    //人脸日志表
                    EPM_FaceOperateLog faceLog   = new EPM_FaceOperateLog();
                    Base_User          userModel = DataOperateBasic <Base_User> .Get(basedb).GetModel(model.UserId.Value);

                    List <Epm_ProjectCompany> proComList = DataOperateBusiness <Epm_ProjectCompany> .Get(busdb).GetList(t => t.ProjectId == model.ProjectId && (t.PMId == model.UserId || t.LinkManId == model.UserId || t.SafeManId == model.UserId)).ToList();

                    string type = "";
                    if (proComList.Any())
                    {
                        type = string.Join(",", proComList.Select(t => t.Type));
                    }

                    modelSign.userId         = model.UserId;
                    modelSign.userName       = userModel.UserName;
                    modelSign.projectId      = model.ProjectId;
                    modelSign.projectName    = model.ProjectName;
                    modelSign.Latitude       = model.Latitude;
                    modelSign.Longitude      = model.Longitude;
                    modelSign.gasstationName = model.OilStationName;
                    modelSign.jobInfo        = userModel.Post ?? "";
                    modelSign.type           = type;
                    modelSign.picStrength    = model.Image;
                    modelSign.SignTime       = DateTime.Now;

                    //日志
                    var requestJson = new
                    {
                        imageType = imageType,
                        groupId   = groupIdList,
                        options   = new
                        {
                            quality_control  = control,
                            liveness_control = control,
                            user_id          = model.UserId
                        }
                    };
                    faceLog.ModelId     = modelSign.Id;
                    faceLog.APIType     = FaceOperate.Search.ToString();
                    faceLog.RequestJson = requestJson.ToString();

                    JObject result = new JObject();
                    Face    client = GetFacaClient();
                    try
                    {
                        // 带参数调用人脸识别
                        result = client.Search(model.Image, imageType, groupIdList, options);
                    }
                    catch (Exception)
                    {
                        modelSign.SignResult = SignRes.Other.ToString();
                    }
                    if (result["error_code"].ToString() == "0" && result["error_msg"].ToString() == "SUCCESS")
                    {
                        var result_list = Newtonsoft.Json.JsonConvert.DeserializeObject(result["result"].ToString()) as JObject;
                        var user_list   = result_list["user_list"];
                        var Obj         = JArray.Parse(user_list.ToString());
                        foreach (var item in Obj)
                        {
                            //80分以上可以判断为同一人,此分值对应万分之一误识率
                            var score = Convert.ToInt32(item["score"]);
                            if (score > 80)
                            {
                                modelSign.SignResult = SignRes.Success.ToString();
                                faceLog.IsSuccess    = true;
                                resultObj.Data       = 1;
                                resultObj.Flag       = EResultFlag.Success;
                            }
                            else
                            {
                                modelSign.SignResult = SignRes.NoFace.ToString();
                                faceLog.IsSuccess    = false;
                            }
                        }
                    }
                    else
                    {
                        modelSign.SignResult = SignRes.Fail.ToString();
                    }

                    faceLog.ResponseJson = result.ToString();
                    faceLog = SetCurrentUser(faceLog);

                    DataOperateBusiness <EPM_FaceOperateLog> .Get(busdb).Add(faceLog);

                    var rows = DataOperateBusiness <Epm_SignInformation> .Get(busdb).Add(modelSign);

                    if (rows > 0)
                    {
                        resultObj.Flag = EResultFlag.Success;
                    }
                }
            }
            catch (Exception ex)
            {
                resultObj.Data      = -1;
                resultObj.Flag      = EResultFlag.Failure;
                resultObj.Exception = new ExceptionEx(ex, "SearchUserFace");
            }
            finally
            {
                if (basedb.Database.Connection.State != ConnectionState.Closed)
                {
                    basedb.Database.Connection.Close();
                    basedb.Database.Connection.Dispose();
                }
                if (busdb.Database.Connection.State != ConnectionState.Closed)
                {
                    busdb.Database.Connection.Close();
                    busdb.Database.Connection.Dispose();
                }
            }
            return(resultObj);
        }
 ///<summary>
 ///修改:
 ///</summary>
 ///<param name="model">要修改的model</param>
 ///<returns>受影响的行数</returns>
 public Result <int> UpdateSignInformation(Epm_SignInformation model)
 {
     return(base.Channel.UpdateSignInformation(model));
 }
 ///<summary>
 ///添加:
 ///</summary>
 ///<param name="model">要添加的model</param>
 ///<returns>受影响的行数</returns>
 public Result <int> AddSignInformation(Epm_SignInformation model)
 {
     return(base.Channel.AddSignInformation(model));
 }