Esempio n. 1
0
        public Result TCLCallInfoUpdate(string infomation)
        {
            // Logs
            var log = new TmpLogServiceInfo
            {
                Time        = DateTime.Now,
                Description = infomation,
                CallType    = (int)CallType.IncomingUpdate,
            };

            if (string.IsNullOrEmpty(infomation))
            {
                // Logs
                log.Status      = 1;
                log.Description = "Thông tin cuộc gọi đến rỗng";
                TmpLogServiceRepository.Create(log);

                // Return
                return(new Result
                {
                    Code = (int)ErrorServiceType.NullOrEmpty,
                    Description = "Thông tin cuộc gọi đến rỗng",
                });
            }

            infomation = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><CallInforUpdate>" + infomation + "</CallInforUpdate>";
            var callInfo = ObjectHelper.CreateObject <CallInforUpdate>(infomation);

            if (callInfo == null)
            {
                // Logs
                log.Status      = 1;
                log.Description = "Thông tin cuộc gọi không đúng định dạng: " + infomation;
                TmpLogServiceRepository.Create(log);

                // Return
                return(new Result
                {
                    Code = (int)ErrorServiceType.NotFormat,
                    Description = "Thông tin cuộc gọi không đúng định dạng",
                });
            }

            try
            {
                if (callInfo.station_id.IsStringNullOrEmpty())
                {
                    var arr = callInfo.agent_code.Split('/');
                    if (arr.Length > 1)
                    {
                        callInfo.station_id = arr[1];
                    }
                }
                callInfo.mobile_phone = callInfo.mobile_phone.Trim();
                if (callInfo.mobile_phone.StartsWith("0"))
                {
                    callInfo.mobile_phone = callInfo.mobile_phone.Substring(1);
                }

                var contactInfo    = ContactRepository.GetByMobile(callInfo.mobile_phone);
                var callHitoryInfo = CallHistoryRepository.GetInfoIdentifyTcl(callInfo.call_id, (int)EmployeeType.Collaborator) ??
                                     new CallHistoryInfo();

                callHitoryInfo.CallTimeLength = 0;
                callHitoryInfo.CallTime       = DateTime.Now;
                callHitoryInfo.Status         = callInfo.status;
                callHitoryInfo.CallId         = callInfo.call_id;
                callHitoryInfo.CreatedDate    = DateTime.Now;
                callHitoryInfo.Duration       = callInfo.duration;
                callHitoryInfo.RingTime       = callInfo.ringtime;
                callHitoryInfo.CallCenterInfo = string.Empty;
                callHitoryInfo.StationId      = callInfo.station_id;
                callHitoryInfo.AgentCode      = callInfo.agent_code;
                callHitoryInfo.ErrorCode      = callInfo.error_code;
                callHitoryInfo.ErrorDesc      = callInfo.error_desc;
                callHitoryInfo.MessageCode    = callInfo.message_code;
                callHitoryInfo.MobilePhone    = callInfo.mobile_phone;
                callHitoryInfo.CallType       = (int)CallType.IncomingUpdate;
                callHitoryInfo.StatusUpdate   = contactInfo == null ? -1 : 2;
                callHitoryInfo.UserLogType    = (int)EmployeeType.Collaborator;
                callHitoryInfo.LinkRecord     = callInfo.link_down_record.IsStringNullOrEmpty()
                                        ? string.Empty
                                        : callInfo.link_down_record.Replace("/var/spool/asterisk/monitor/5678/", StoreData.LinkRecordTCL(contactInfo == null ? 0 : contactInfo.BranchId));
                callHitoryInfo.EndTime      = callInfo.end_time.ToDateTime("yyyyMMddHHmmss");
                callHitoryInfo.StartTime    = callInfo.start_time.ToDateTime("yyyyMMddHHmmss");
                callHitoryInfo.ResponseTime = callInfo.datetime_response.ToDateTime("yyyyMMddHHmmss");
                if (callHitoryInfo.ContactId.IsIntegerNull())
                {
                    callHitoryInfo.ContactId = contactInfo == null ? 0 : contactInfo.Id;
                }
                if (callHitoryInfo.LevelId.IsIntegerNull())
                {
                    callHitoryInfo.LevelId = contactInfo == null ? 0 : contactInfo.LevelId;
                }
                if (callHitoryInfo.CreatedBy.IsIntegerNull())
                {
                    callHitoryInfo.CreatedBy = contactInfo == null ? 0 : contactInfo.UserConsultantId;
                }
                if (callHitoryInfo.RecallTime == null)
                {
                    callHitoryInfo.RecallTime = contactInfo == null ? null : contactInfo.AppointmentConsultantDate;
                }
                if (callHitoryInfo.StatusMapId.IsIntegerNull())
                {
                    callHitoryInfo.StatusMapId = contactInfo == null ? 0 : contactInfo.StatusMapConsultantId;
                }
                if (callHitoryInfo.StatusCareId.IsIntegerNull())
                {
                    callHitoryInfo.StatusCareId = contactInfo == null ? 0 : contactInfo.StatusCareConsultantId;
                }
                if (callHitoryInfo.CallCenterInfo.IsStringNullOrEmpty())
                {
                    callHitoryInfo.CallCenterInfo = contactInfo == null ? string.Empty : contactInfo.CallInfoConsultant;
                }
                CallHistoryRepository.Create(callHitoryInfo);

                // Logs
                log.Status      = 0;
                log.Description = infomation + " ==> BranchId: " + (contactInfo == null ? 0 : contactInfo.BranchId);
                TmpLogServiceRepository.Create(log);

                // Return
                return(new Result
                {
                    Code = (int)ErrorServiceType.Success,
                    Description = "Cập nhật cuộc gọi đến thành công",
                });
            }
            catch (Exception ex)
            {
                // Logs
                log.Status      = 0;
                log.Description = ex + " ---- input" + infomation;
                TmpLogServiceRepository.Create(log);

                // Return
                return(new Result
                {
                    Code = (int)ErrorServiceType.Exception,
                    Description = "Cập nhật cuộc gọi đến không thành công, lỗi hệ thống",
                });
            }
        }