コード例 #1
0
        public async Task <ResponseMessage> ClaimCustomer(UserInfo user, [FromBody] CustomerPoolClaimRequest customerPoolClaimRequest)
        {
            Logger.Trace($"用户{user?.UserName ?? ""}({user?.Id ?? ""})认领客户(ClaimCustomer):\r\n请求参数为:\r\n" + (customerPoolClaimRequest != null ? JsonHelper.ToJson(customerPoolClaimRequest) : ""));

            ResponseMessage response = new ResponseMessage();

            if (!ModelState.IsValid)
            {
                response.Code    = ResponseCodeDefines.ModelStateInvalid;
                response.Message = ModelState.GetAllErrors();
                Logger.Warn($"用户{user?.UserName ?? ""}({user?.Id ?? ""})认领客户(ClaimCustomer)模型验证失败:\r\n{response.Message ?? ""},\r\n请求参数为:\r\n" + (customerPoolClaimRequest != null ? JsonHelper.ToJson(customerPoolClaimRequest) : ""));
                return(response);
            }
            try
            {
                await _customerPoolManager.ClaimCustomer(user, customerPoolClaimRequest, HttpContext.RequestAborted);
            }
            catch (Exception e)
            {
                response.Code    = ResponseCodeDefines.ServiceError;
                response.Message = e.ToString();
                Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})认领客户(ClaimCustomer)请求失败:\r\n{response.Message ?? ""},\r\n请求参数为:\r\n" + (customerPoolClaimRequest != null ? JsonHelper.ToJson(customerPoolClaimRequest) : ""));
            }
            return(response);
        }
コード例 #2
0
 /// <summary>
 /// 认领客户
 /// </summary>
 /// <returns></returns>
 public async Task ClaimCustomer(UserInfo userInfo, CustomerPoolClaimRequest customerPoolClaimRequest, CancellationToken cancellationToken = default(CancellationToken))
 {
     if (customerPoolClaimRequest == null)
     {
         throw new ArgumentNullException(nameof(CustomerPoolClaimRequest));
     }
     await Store.ClaimCustomerAsync(userInfo, customerPoolClaimRequest, cancellationToken);
 }
コード例 #3
0
        public async Task <bool> ClaimCustomerAsync(UserInfo user, CustomerPoolClaimRequest customerPoolClaimRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            var customerpools = Context.CustomerPools.Where(a => customerPoolClaimRequest.CustomerIds.Contains(a.CustomerId) && !a.IsDeleted).ToList();

            customerpools = customerpools.Select(x =>
            {
                x.IsDeleted  = true;
                x.DeleteUser = user.Id;
                x.DeleteTime = DateTime.Now;
                return(x);
            }).ToList();
            if (customerpools != null)
            {
                Context.UpdateRange(customerpools);
            }

            var customerInfos = Context.CustomerInfos.Where(a => customerPoolClaimRequest.CustomerIds.Contains(a.Id)).ToList();

            foreach (var item in customerInfos)
            {
                var customerdemand = await Context.CustomerDemands.AsNoTracking().Where(a => a.CustomerId == item.Id).FirstOrDefaultAsync(cancellationToken);

                if (customerdemand == null)
                {
                    return(false);
                }

                item.UserId         = user.Id;
                item.DepartmentId   = user.OrganizationId;
                item.CustomerStatus = CustomerStatus.ExistingCustomers;

                customerdemand.UserId       = user.Id;
                customerdemand.DepartmentId = user.OrganizationId;

                //var newcustomerinfo = JsonConvert.DeserializeObject<CustomerInfo>(JsonConvert.SerializeObject(item));
                //newcustomerinfo.Id = Guid.NewGuid().ToString();
                //newcustomerinfo.IsDeleted = false;
                //newcustomerinfo.UserId = user.Id;
                //newcustomerinfo.DepartmentId = user.OrganizationId;
                //newcustomerinfo.UniqueId = item.UniqueId;
                //newcustomerinfo.CustomerStatus = CustomerStatus.ExistingCustomers;
                //newcustomerinfo.SourceId = item.Id;

                //var newcustomerdemand = JsonConvert.DeserializeObject<CustomerDemand>(JsonConvert.SerializeObject(customerdemand));
                //customerdemand.Id = Guid.NewGuid().ToString();
                //customerdemand.CustomerId = newcustomerinfo.Id;
                //customerdemand.IsDeleted = false;
                //customerdemand.UserId = user.Id;
                //customerdemand.DepartmentId = user.OrganizationId;

                var customerfu = new CustomerFollowUp
                {
                    Id               = Guid.NewGuid().ToString(),
                    CustomerId       = item.Id,
                    TypeId           = CustomerFollowUpType.ClaimCustomer,
                    UserId           = item.UserId,
                    DepartmentId     = item.DepartmentId,
                    FollowUpTime     = DateTime.Now,
                    TrueName         = item.CustomerName,
                    FollowUpContents = "认领客户",
                    CustomerNo       = item.CustomerNo,
                    IsRealFollow     = false,
                    CreateTime       = DateTime.Now,
                    CreateUser       = user.Id
                };

                if (item != null)
                {
                    Context.Update(item);
                }
                //Context.Add(newcustomerinfo);
                if (customerfu != null)
                {
                    Context.Add(customerfu);
                }
                if (customerdemand != null)
                {
                    Context.Update(customerdemand);
                }
            }
            try
            {
                await Context.SaveChangesAsync(cancellationToken);
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
            return(true);
        }