Example #1
0
        public HttpResponseMessage AddOrUpdateWorkOrder([FromBody] AddOrUpdateWorkOrderRequest request)
        {
            _logAppInfo.Info(string.Format("添加投保意向接口请求串:{0},参数:{1}", Request.RequestUri, request.ToJson()));

            var viewModel = new AddOrUpdateWorkOrderViewModel();

            if (!ModelState.IsValid)
            {
                viewModel.BusinessStatus = -10000;
                string msg = ModelState.Values.Where(a => a.Errors.Count == 1).Aggregate(string.Empty, (current, a) => current + (a.Errors[0].ErrorMessage + ";   "));
                viewModel.StatusMessage = "输入参数错误," + msg;
                return(viewModel.ResponseToJson());
            }
            var response = _workOrderService.AddOrUpdateWorkOrder(request, Request.GetQueryNameValuePairs());

            _logAppInfo.Info(string.Format("添加投保意向接口返回值:{0}", response.ToJson()));
            if (response.Status == HttpStatusCode.BadRequest || response.Status == HttpStatusCode.Forbidden)
            {
                viewModel.BusinessStatus = -10001;
                viewModel.StatusMessage  = "参数校验错误,请检查您的校验码";
                return(viewModel.ResponseToJson());
            }
            if (response.ErrCode == -1)
            {
                viewModel.BusinessStatus = -10000;
                viewModel.StatusMessage  = response.ErrMsg;
                return(viewModel.ResponseToJson());
            }
            else if (response.ErrCode == 1)
            {
                viewModel.BusinessStatus = 1;
                viewModel.WorkOrderId    = response.WorkOrderId;
                viewModel.AdvAgentId     = response.AdvAgentId;
                viewModel.StatusMessage  = "创建成功";
            }
            else
            {
                viewModel.BusinessStatus = response.ErrCode;
                viewModel.StatusMessage  = response.ErrMsg;
            }
            return(viewModel.ResponseToJson());
        }
        /// <summary>
        /// 业务:sa用。第一次创建WorkOrder
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public AddOrUpdateWorkOrderResponse AddOrUpdateWorkOrder(AddOrUpdateWorkOrderRequest request, IEnumerable <KeyValuePair <string, string> > pairs)
        {
            var response = new AddOrUpdateWorkOrderResponse();

            //bhToken校验
            if (!AppTokenValidateReqest(request.BhToken, request.ChildAgent))
            {
                response.ErrCode = -300;
                response.ErrMsg  = "登录信息已过期,请重新登录";
                return(response);
            }
            //传参校验
            IBxAgent agentModel = GetAgentModelFactory(request.Agent);

            //参数校验
            if (agentModel == null)// || childAgent == null)
            {
                response.Status = HttpStatusCode.BadRequest;
                return(response);
            }
            if (!AppValidateReqest(pairs, request.SecCode))
            {
                response.Status = HttpStatusCode.Forbidden;
                return(response);
            }
            if (request.IntentionView == 0)
            {
                response.ErrCode = -1;
                response.ErrMsg  = "意向不能为空";
                return(response);
            }
            if (request.OwnerAgent == 0)
            {
                response.ErrCode = -2;
                response.ErrMsg  = "车辆当前受理人Id不能为空";
                return(response);
            }
            try
            {
                bx_userinfo bxUserInfo;
                if (request.Buid.HasValue && request.Buid.Value != 0)
                {
                    //如果传buid过来,重新赋值request
                    bxUserInfo = _userInfoRepository.FindByBuid(request.Buid.Value);
                    if (bxUserInfo != null)
                    {
                        request.LicenseNo  = bxUserInfo.LicenseNo;
                        request.OwnerAgent = int.Parse(bxUserInfo.Agent);
                    }
                }
                else
                {
                    //根据OpenId、车牌号、代理人Id找userinfo对象
                    bxUserInfo = _userInfoRepository.FindByAgentLicense(request.LicenseNo, request.OwnerAgent.ToString());
                }

                if (bxUserInfo == null)
                {
                    response.ErrCode = 0;
                    response.ErrMsg  = "查不到此续保信息";
                    return(response);
                }
                int      workOrderId = 0;//标记添加修改意向成功与否
                DateTime dateTime    = DateTime.Now;
                bx_userinfo_renewal_info workOrder = _userinfoRenewalInfoRepository.FindByBuid(bxUserInfo.Id);
                if (workOrder != null)
                {//如果库里有记录,执行更新
                    workOrder.sa_id            = request.ChildAgent;
                    workOrder.sa_name          = request.ChildName;
                    workOrder.client_name      = request.CustomerName;
                    workOrder.client_mobile    = request.Phone;
                    workOrder.client_intention = request.IntentionView;
                    workOrder.remark           = request.Remark;
                    workOrderId = _userinfoRenewalInfoRepository.Update(workOrder);
                }
                else
                {//如果库里无记录,执行插入
                    workOrder                  = new bx_userinfo_renewal_info();
                    workOrder.sa_id            = request.ChildAgent;
                    workOrder.sa_name          = request.ChildName;
                    workOrder.client_name      = request.CustomerName;
                    workOrder.client_mobile    = request.Phone;
                    workOrder.b_uid            = bxUserInfo.Id;
                    workOrder.client_intention = request.IntentionView;
                    workOrder.remark           = request.Remark;
                    workOrder.create_time      = dateTime;
                    workOrderId                = _userinfoRenewalInfoRepository.Add(workOrder);
                }
                if (workOrderId > 0)
                {
                    response.ErrCode     = 1;
                    response.WorkOrderId = workOrderId;
                }
                else
                {
                    response.ErrCode = -10002;
                    response.ErrMsg  = "添加意向失败,未存在可更新的内容";
                }
            }
            catch (Exception ex)
            {
                response.ErrCode = -10003;
                logError.Info("意向接口异常,添加意向信息:" + request.ToJson() + "\n 异常信息:" + ex.StackTrace + " \n " + ex.Message);
            }
            return(response);
        }