public BaseViewModel AddMultiple(AddMultipleInput input)
        {
            BaseViewModel viewModel = new BaseViewModel();

            try
            {
                //soucr转换
                int sourceold = SourceGroupAlgorithm.GetOldSource(input.Source);
                //判断list是否4种类型都有
                List <UrlAndType> urlType = input.UrlList;
                //if (urlType.Count < targetType.Length)
                //{
                //    return BaseViewModel.GetBaseViewModel(-10000, "每种照片至少传一张才可提交");
                //}
                //去掉类型限制
                //var acutalType = urlType.Select(o => o.Type).Distinct().ToArray();
                //if (!CommonHelper.ArrayCompare2(targetType, acutalType))
                //{
                //    return BaseViewModel.GetBaseViewModel(-10000, "缺少图片类型");
                //}

                //

                //检查buid的合法性
                if (!_userInfoRepository.IsExist(o => o.Id == input.BuId))
                {
                    return(BaseViewModel.GetBaseViewModel(-10000, "buid不存在"));
                }

                var picsJson = input.UrlList.ToJson();

                bx_picture pic = _pictureRepository.FirstOrDefault(o => o.b_uid == input.BuId && o.source == sourceold);
                if (pic == null)
                {
                    //不存在是插入
                    return(AddPicture(input.BuId, picsJson, sourceold));
                }
                else if (pic.state == 4)
                {//status=4 图片上传中不允许修改
                    return(BaseViewModel.GetBaseViewModel(-10002, "图片上传中不允许修改"));
                }
                else
                {//biud=>bx_picture存在 状态  !=4  直接更新
                    pic.picsJson    = picsJson;
                    pic.state       = 3;
                    pic.update_time = DateTime.Now;
                    pic.source      = sourceold;
                    return(UpdatePicture(pic));
                }
            }
            catch (Exception ex)
            {
                viewModel.BusinessStatus = -100003;
                logError.Info("上传图片发生异常:" + ex.Source + "\n" + ex.StackTrace + "\n" + ex.Message + "\n" + ex.InnerException);
            }
            return(viewModel);
        }
 private BaseViewModel UpdatePicture(bx_picture picture)
 {
     _pictureRepository.Update(picture);
     if (_pictureRepository.SaveChanges() > 0)
     {
         //调用中心的方法
         return(AddSuccessSendMsg(picture.b_uid.Value, picture.source.Value));
     }
     else
     {
         return(BaseViewModel.GetBaseViewModel(-10003, "添加失败"));
     }
 }
        public BaseViewModel ValidateTimes(UploadMultipleImgRequest request)
        {
            BaseViewModel viewModel = new BaseViewModel();

            viewModel.BusinessStatus = 1;
            //判断次数
            if (UpImgCount != 0)
            {                         //如果=0,没有上传限制
                int alreadyTimes = 0; //已经上传的次数
                if (!CheckTimes(request.BuId, out alreadyTimes))
                {
                    return(BaseViewModel.GetBaseViewModel(-10013, "上传次数过多,请直接去保险系统修改!"));
                }
            }
            return(viewModel);
        }
        /// <summary>
        /// 入库成功,调用中心的消息
        /// </summary>
        /// <param name="buid"></param>
        /// <returns></returns>
        private BaseViewModel AddSuccessSendMsg(long buid, int source)
        {
            //return BaseViewModel.GetBaseViewModel(1, "添加成功!");
            var ulImgKey = string.Format("{0}-upimg-{1}", buid, "key");

            SendMsg(buid, ulImgKey, source);
            ReMsg msg = ReadData(ulImgKey);//new ReMsg();//

            if (msg == null)
            {
                return(BaseViewModel.GetBaseViewModel(-10002, "添加失败!"));
            }
            if (msg.ErrCode == 0)
            {
                return(BaseViewModel.GetBaseViewModel(1, "添加成功!"));
            }
            else
            {
                return(BaseViewModel.GetBaseViewModel(-10002, msg.ErrMsg));
            }
        }
        /// <summary>
        /// 添加照片
        /// </summary>
        /// <param name="buId"></param>
        /// <param name="picsJson"></param>
        /// <returns></returns>
        private BaseViewModel AddPicture(long buId, string picsJson, int source)
        {
            bx_picture picture = new bx_picture
            {
                b_uid       = buId,
                picsJson    = picsJson,
                state       = 3,
                create_time = DateTime.Now,
                update_time = DateTime.Now,
                source      = source
            };

            _pictureRepository.Insert(picture);
            if (_pictureRepository.SaveChanges() > 0)
            {
                //调用中心的方法
                return(AddSuccessSendMsg(buId, source));
            }
            else
            {
                return(BaseViewModel.GetBaseViewModel(-10002, "添加失败"));
            }
        }
        public BaseViewModel Validate(UploadMultipleImgRequest request)
        {
            BaseViewModel viewModel = new BaseViewModel();

            #region 参数验证
            bx_userinfo userinfo = new bx_userinfo();
            if (request.BuId > 0)
            {
                //userinfo是否有值,buid是否正确
                userinfo = _userInfoRepository.FindByBuid(request.BuId);
            }
            //modifybygpj20181205修改,不开放前端传buid了
            else
            {
                //如果前端传子集代理Id,则用子集代理Id来查数据
                request.Agent = request.ChildAgent > 0 ? request.ChildAgent : request.Agent;
                //参数有效性校验
                if (string.IsNullOrWhiteSpace(request.LicenseNo) || string.IsNullOrWhiteSpace(request.CustKey) || request.Agent < 1)
                {
                    return(BaseViewModel.GetBaseViewModel(-10000, "车牌号、CustKey、Agent不允许为空"));
                }
                //根据车牌、代理、custkey来取数据库userinfo
                userinfo = _userInfoRepository.FindByOpenIdAndLicense(request.CustKey, request.LicenseNo, request.Agent.ToString(), request.RenewalCarType);
            }
            //如果userinfo没记录,直接提示错误参数
            if (userinfo == null || userinfo.Id == 0)
            {
                return(BaseViewModel.GetBaseViewModel(-10000, "参数错误,无法拿到请求的车辆信息"));
            }
            //给buid赋值
            if (request.BuId == 0)
            {
                request.BuId = userinfo.Id;
            }
            int source = SourceGroupAlgorithm.GetOldSource(request.Source);
            //submitinfo是否有值
            bx_submit_info submitInfo = _submitInfoRepository.GetSubmitInfo(request.BuId, source);
            if (submitInfo == null)
            {
                return(BaseViewModel.GetBaseViewModel(-10000, "未取到核保信息,请稍后再试"));
            }
            //是否需要上传图片
            if (request.Source == 2)
            {
                if (string.IsNullOrEmpty(submitInfo.documentGroupId))
                {
                    return(BaseViewModel.GetBaseViewModel(-10000, "请确认是否需要上传类型范围内的证件资料"));
                }
            }
            else
            {
                if (string.IsNullOrEmpty(submitInfo.biz_tno) && string.IsNullOrEmpty(submitInfo.force_tno))
                {
                    return(BaseViewModel.GetBaseViewModel(-10000, "请确认是否需要上传类型范围内的证件资料"));
                }
            }
            //上传的图片最少1张
            var dic = request.ListBaseContect;//JsonConvert.DeserializeObject<Dictionary<int, string>>(request.ListBaseContect);
            if (dic.Count == 0)
            {
                viewModel.BusinessStatus = -10000;
                viewModel.StatusMessage  = "输入参数错误,ListBaseContect为空";
                return(viewModel);
            }
            //不能超过11张上传图片//以前是8张的限制
            else if (dic.Count > 11)
            {
                viewModel.BusinessStatus = -10000;
                viewModel.StatusMessage  = "最多11张图片";
                return(viewModel);
            }
            #endregion
            //校验上传次数
            var timesValidate = _checkUploadImgTimes.ValidateTimes(request);
            if (timesValidate.BusinessStatus == -10013)
            {
                viewModel.BusinessStatus = -10013;
                viewModel.StatusMessage  = timesValidate.StatusMessage;
                return(viewModel);
            }
            return(BaseViewModel.GetBaseViewModel(1, "校验成功"));
        }