Exemplo n.º 1
0
        /// <summary>
        /// 从所有组中删除用户
        /// </summary>
        /// <param name="user"></param>
        /// <param name="tra"></param>
        /// <returns></returns>
        public static async Task <long> Remove_Storage_By_ApiUserID_All(user_face_storage user, IDbTransaction tra = null)
        {
            string set = "is_delete = @is_delete , updated_at = @updated_at";

            string where = " AND secret_id = @secret_id";
            return(await SqlDapperHelper.ExecuteSqlIntAsync(string.Format(Update + where, set),
                                                            new
            {
                is_delete = user.is_delete,
                updated_at = user.updated_at,
                secret_id = user.secret_id
            }, tra));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 删除用户
        /// </summary>
        /// <returns></returns>
        public async Task<ActionResult> RemoveUser(FaceDatabaseModel.GroupUserModel model)
        {
            // 一系列检查
            RequestFaceModel request = new RequestFaceModel()
            {
                Status = 500,
                Message = null,
                FaceList = null
            };

            var userFaceSet = Verify(ref request, model);
            // 基本验证
            if (userFaceSet == null)
            {
                return Ok(request);
            }

            // 判断是否存在此用户,是否存在此分组
            // 判断是否有同样的人,判断是否有此分组
            var group = await Service_user_face_storage_group.Get_storage_group_BySecretGroupAsync(model.secret_id, model.group_id);
            if (group == null)
            {
                request.Enum = RequestEnum.数据不存在;
                return Ok(request);
            }

            user_face_storage group_user = null;
            if (model.group_id == "@ALL")
            {
                group_user = await Service_user_face_storage.GetUser_By_UGS_ALL(model.user_id, model.secret_id);
            }
            else
            {
                group_user = await Service_user_face_storage.GetUser_By_UGS(model.user_id, group.id, model.secret_id);
            }
            if (group_user == null)
            {
                request.Enum = RequestEnum.数据不存在;
                return Ok(request);
            }



            user_face_storage user = new user_face_storage()
            {
                is_delete = true,
                updated_at = DateTime.Now,
                secret_id = model.secret_id
            };

            try
            {
                // 数据库删除,增加日志
                if (model.group_id == "@ALL")
                {
                    await Service_user_face_storage.Remove_Storage_By_ApiUserID_All(user);
                }
                else
                {
                    user.api_group_id = group.id;
                    await Service_user_face_storage.Remove_Storage_By_ApiUserID(user);
                }
                request.Enum = RequestEnum.Succeed;
            }
            catch (Exception ex)
            {
                LogHelperNLog.Error(ex, "操作日志添加失败");
                request.Enum = RequestEnum.操作日志添加失败;
            }

            return Ok(request);

        }
Exemplo n.º 3
0
        /// <summary>
        /// 人脸更新
        /// </summary>
        /// <returns></returns>
        public async Task<ActionResult> UpdateFace(FaceDatabaseModel.UserFaceModel model)
        {


            // 一系列检查
            RequestFaceModel request = new RequestFaceModel()
            {
                Status = 500,
                Message = null,
                FaceList = null
            };

            var userFaceSet = Verify(ref request, model);
            // 基本验证
            if (userFaceSet == null)
            {
                return Ok(request);
            }

            // 判断是否存在此用户,是否存在此分组
            // 判断是否有同样的人,判断是否有此分组
            var group = await Service_user_face_storage_group.Get_storage_group_BySecretGroupAsync(model.secret_id, model.group_id);
            if (group == null)
            {
                request.Enum = RequestEnum.数据不存在;
                return Ok(request);
            }

            user_face_storage group_user = null;
            if (model.group_id == "@ALL")
            {
                group_user = await Service_user_face_storage.GetUser_By_UGS_ALL(model.user_id, model.secret_id);
            }
            else
            {
                group_user = await Service_user_face_storage.GetUser_By_UGS(model.user_id, group.id, model.secret_id);
            }
            if (group_user == null)
            {
                request.Enum = RequestEnum.数据不存在;
                return Ok(request);
            }



            // 将以前的人脸状态变为删除
            user_face_storage user = new user_face_storage()
            {
                is_delete = true,
                updated_at = DateTime.Now,
                secret_id = model.secret_id
            };

            // 增加一个人脸
            #region 获取图片

            var face_token = string.Empty;
            (Bitmap, string) bitmap = (null, null);
            // 获取图片文件
            bitmap = model.image_type.ToUpper() == "BASE64" ? FileCommon.Base64ToBitmap(model.image) : FileCommon.UrlToBitmap(model.image);
            if (bitmap.Item1 == null && !string.IsNullOrEmpty(bitmap.Item2))
            {
                if (model.image_type.ToUpper() == "BASE64")
                {
                    request.Enum = RequestEnum.Base64图片格式错误;
                }
                else
                {
                    request.Enum = RequestEnum.从图片的url下载图片失败;
                }
                return Ok(request);
            }

            #endregion


            #region 图片以及数据处理

            // 查找是否有相同的图片
            face_token = model.image_type.ToUpper() == "BASE64" ? EncryptProvider.Md5(model.image) : EncryptProvider.Md5(FileCommon.BitmapToBase64(bitmap.Item1));

            // 查询 图片库
            var user_images = await Service_user_face_image_data.Getuser_face_image_data_By_Token_Async(face_token);

            if (user_images != null)
            {
                bitmap.Item2 = user_images.url;
            }
            else
            {
                try
                {
                    // 存入本地
                    bitmap.Item2 = FileCommon.SaveBitmap(bitmap.Item1, bitmap.Item2);

                }
                catch (Exception ex)
                {
                    LogHelperNLog.Error(ex);
                    request.Enum = RequestEnum.数据存储处理失败;
                    return Ok(request);
                }

            }

            // 获取人脸数据
            //var faceDate = FaceDetectionCompute.GetRectangle(bitmap.Item1);
            DlibDotNet.Rectangle[] faceDate = new DlibDotNet.Rectangle[0];
            try
            {
                // 截取人像,面积排序
                faceDate = FaceDetectionCompute.GetRectangle(bitmap.Item1).OrderByDescending(d => d.Area).Take(1).ToArray();
            }
            catch (Exception ex)
            {
                LogHelperNLog.Error(ex, "FaceDetectionCompute.GetRectangles:人脸获取坐标出错");
                request.Enum = RequestEnum.无法解析人脸;
                return Ok(request);
            }

            #endregion

            request.Enum = RequestEnum.Succeed;
            request.Location = faceDate;

            #region 日志&&扣费

            try
            {

                DateTime dateTime = DateTime.Now;

                // 图片保存到数据库
                user_images = new user_face_image_data()
                {
                    token = face_token,
                    url = bitmap.Item2,
                    created_at = dateTime,
                    updated_at = dateTime
                };


                //查找分组信息

                user.api_group_id = group.id;


                //用户信息
                user_face_storage face_Storage = new user_face_storage()
                {
                    user_id = userFaceSet.user_id,
                    secret_id = model.secret_id,
                    face_token = face_token,
                    image = bitmap.Item2,
                    image_type = model.image_type,
                    api_group_id = group.id,
                    api_user_id = model.user_id,
                    api_user_info = model.user_info,
                    quality_control = model.quality_control,
                    liveness_control = model.quality_control,
                    sign = model.sign,
                    timestamp = model.timestamp,
                    is_delete = false,
                    api_respone = JsonConvert.SerializeObject(request, UnderlineSplitContractResolver.GetSettings()),
                    created_at = dateTime,
                    updated_at = dateTime
                };

                using (var tra = SqlDapperHelper.GetOpenConnection().BeginTransaction())
                {
                    await Service_user_face_storage.Remove_Storage_By_ApiUserID(user, tra);
                    if (user_images == null)
                    {
                        await Service_user_face_image_data.Creatuser_face_image_data(user_images, tra);
                    }
                    await SqlDapperHelper.ExecuteInsertAsync(face_Storage, tra);
                    tra.Commit();
                }
            }
            catch (Exception ex)
            {
                LogHelperNLog.Error(ex, "操作日志添加失败");
                request.Enum = RequestEnum.操作日志添加失败;
            }

            #endregion

            return Ok(request);

        }