Exemplo n.º 1
0
        public List <CampaignDetail> GetCampaignListByCustomer(AuditLogEntity auditLog, string cardNo, string hasOffered,
                                                               string isInterested, string customerFlag, int campaignNum)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Call CmtService.GetCampaignByCustomers").Add("CardNo", cardNo.MaskCardNo())
                        .Add("HasOffered", hasOffered).Add("IsInterested", isInterested).Add("CustomerFlag", customerFlag).ToInputLogString());

            RecommendCampaignResponse resCamp = GetCampaignByCustomer(auditLog, cardNo, hasOffered, isInterested, customerFlag, campaignNum);

            //RecommendCampaignResponse resCamp = new RecommendCampaignResponse()
            //{
            //    RecommendCampaignDetails = new List<CampaignDetail>()
            //    {
            //          new CampaignDetail { CampaignId = "XXXXX"},
            //          new CampaignDetail { CampaignId = "XXXXX"},
            //          new CampaignDetail { CampaignId = "XXXXX"}
            //    }
            //};

            return(resCamp != null ? resCamp.RecommendCampaignDetails : null);
        }
Exemplo n.º 2
0
        private RecommendCampaignResponse GetCampaignByCustomer(AuditLogEntity auditLog, string cardNo, string hasOffered,
                                                                string isInterested, string customerFlag, int campaignNum)
        {
            var stopwatch = System.Diagnostics.Stopwatch.StartNew();

            Logger.Debug("I:--START--:--CmtService.CampaignByCustomer--");

            try
            {
                Header      profile = GetHeaderByServiceName <Header>(Constants.ServiceName.CampaignByCustomer);
                CMT.Header2 header  = new CMT.Header2
                {
                    password         = profile.password,
                    reference_no     = profile.reference_no,
                    service_name     = profile.service_name,
                    system_code      = profile.system_code,
                    transaction_date = profile.transaction_date,
                    user_name        = profile.user_name
                };

                CMT.CampaignByCustomersRequest reqCamp = new CMT.CampaignByCustomersRequest
                {
                    header = header,
                    CampByCitizenIdBody = new CMT.ReqCampByCusEntity
                    {
                        CitizenId     = cardNo,
                        HasOffered    = hasOffered,
                        IsInterested  = isInterested,
                        CustomerFlag  = customerFlag,
                        Command       = profile.command,
                        RequestDate   = DateTime.Now.FormatDateTime("yyyyMMdd"),
                        Channel       = profile.channel_id,
                        CampaignNum   = campaignNum,
                        ProductTypeId = "0,2"
                    }
                };

                CMT.CampaignByCustomersResponse resCamp = null;

                #region "Call Service"

                string flgCatchErrorCode = string.Empty;

                // Avoid error codes
                _commonFacade = new CommonFacade();
                List <string> exceptionErrorCodes = _commonFacade.GetExceptionErrorCodes(Constants.SystemName.CMT, Constants.ServiceName.CampaignByCustomer);

                try
                {
                    Retry.Do(() =>
                    {
                        flgCatchErrorCode = string.Empty;
                        Logger.DebugFormat("-- XMLRequest --\n{0}", reqCamp.SerializeObject());
                        using (var client = new CMT.CmtServiceClient())
                        {
                            resCamp = ((CMT.ICmtService)client).CampaignByCustomers(reqCamp);
                            if (client != null)
                            {
                                ((ICommunicationObject)client).Abort();
                            }
                        }
                    }, TimeSpan.FromSeconds(WebConfig.GetServiceRetryInterval()), WebConfig.GetServiceRetryNo());
                }
                catch (AggregateException aex)
                {
                    aex.Handle((x) =>
                    {
                        if (x is EndpointNotFoundException)
                        {
                            flgCatchErrorCode = Constants.ErrorCode.CSM0002;
                            Logger.Error("EndpointNotFoundException occur:\n", x);
                            return(true);
                        }
                        else if (x is CommunicationException)
                        {
                            flgCatchErrorCode = Constants.ErrorCode.CSM0002;
                            Logger.Error("CommunicationException occur:\n", x);
                            return(true);
                        }
                        else if (x is TimeoutException)
                        {
                            flgCatchErrorCode = Constants.ErrorCode.CSM0001;
                            Logger.Error("TimeoutException occur:\n", x);
                            return(true);
                        }
                        else
                        {
                            flgCatchErrorCode = Constants.ErrorCode.CSM0003;
                            Logger.Error("Exception occur:\n", x);
                            return(true);
                        }
                    });
                }

                if (!string.IsNullOrEmpty(flgCatchErrorCode))
                {
                    AppLog.AuditLog(auditLog, LogStatus.Fail, GetMessageResource(flgCatchErrorCode, true));
                    throw new CustomException(GetMessageResource(flgCatchErrorCode, false));
                }

                #endregion

                if (resCamp != null)
                {
                    Logger.DebugFormat("-- XMLResponse --\n{0}", resCamp.SerializeObject());

                    RecommendCampaignResponse response = new RecommendCampaignResponse();
                    response.StatusResponse.Status      = resCamp.status.status;
                    response.StatusResponse.ErrorCode   = resCamp.status.error_code;
                    response.StatusResponse.Description = resCamp.status.description;

                    if (exceptionErrorCodes != null && exceptionErrorCodes.Contains(resCamp.status.error_code))
                    {
                        response.StatusResponse.Status = Constants.StatusResponse.Success;
                    }

                    if (Constants.StatusResponse.Success.Equals(response.StatusResponse.Status))
                    {
                        if (resCamp.detail != null)
                        {
                            response.CitizenId = resCamp.detail.CitizenId;

                            if (resCamp.detail.CitizenIds != null && resCamp.detail.CitizenIds.Count() > 0)
                            {
                                var results = resCamp.detail.CitizenIds.Where(x => x != null).Select(x => new CampaignDetail
                                {
                                    CampaignCriteria = x.CampaignCreiteria,
                                    CampaignDesc     = x.CampaignDescription,
                                    CampaignId       = x.CampaignId,
                                    CampaignName     = x.CampaignName,
                                    CampaignOffer    = x.CampaignOffer,
                                    CampaignScore    = x.CampaignScore,
                                    Channel          = x.Channel,
                                    CitizenIds       = x.CitizenIds,
                                    DescCust         = x.DescCust,
                                    StrExpireDate    = x.ExpireDate,
                                    IsInterested     = x.IsInterested,
                                    ContractNoRefer  = x.ContractNo,
                                    ProductTypeId    = x.ProductTypeId,
                                    ProductTypeName  = x.ProductTypeName
                                });

                                response.RecommendCampaignDetails = results.OrderBy(x => x.ExpireDate).ToList();
                            }
                        }

                        AppLog.AuditLog(auditLog, LogStatus.Success, string.Empty);
                        return(response);
                    }

                    // Log DB
                    AppLog.AuditLog(auditLog, LogStatus.Fail, GetMessageResource(Constants.SystemName.CMT, Constants.ServiceName.CampaignByCustomer,
                                                                                 response.StatusResponse.ErrorCode, true));
                    throw new CustomException(GetMessageResource(Constants.SystemName.CMT, Constants.ServiceName.CampaignByCustomer,
                                                                 response.StatusResponse.ErrorCode, false));
                }
            }
            finally
            {
                stopwatch.Stop();
                Logger.DebugFormat("O:--Finish--:ElapsedMilliseconds/{0}", stopwatch.ElapsedMilliseconds);
            }

            return(null);
        }