Пример #1
0
        private async Task <Adapters.Oal.dbo_ips_import> CreateDeliIpsImport(Adapters.Oal.dbo_delivery_event_new deli, string consignmentNo)
        {
            var ips = new Adapters.Oal.dbo_ips_import
            {
                id             = GenerateId(13),
                version        = 0,
                data_code_name = "deli",
                item_id        = consignmentNo,
                class_cd       = GetClassCode(consignmentNo),
                status         = "1",
                user_fid       = deli.courier_id,
                event_date_local_date_field = deli.date_field,
                event_date_g_m_t_date_field = (deli.date_field ?? DateTime.Now).AddHours(-8),
                postal_status_fcd           = "MINL",
                dest_country_cd             = "MY",
                condition_cd = "30",
                dt_created_oal_date_field = DateTime.Now,
                office_cd            = "MY" + deli.office_no,
                non_delivery_reason  = GetNonDeliveryReason(deli.delivery_code, ""),
                non_delivery_measure = GetNonDeliveryMeasure(deli.delivery_code, ""),
                tn_cd = GetDeliveryTransactionCode(deli.delivery_code, "")
            };
            var signatories = new[] { "01", "10", "11" };

            if (signatories.Contains(deli.delivery_code))
            {
                ips.signatory_nm = deli.receipent_name;
            }

            var consignmentInitialPolly = await Policy.Handle <SqlException>()
                                          .WaitAndRetryAsync(RetryCount, WaitInterval)
                                          .ExecuteAndCaptureAsync(async() => await SearchConsignmentInitialAsync(consignmentNo));

            if (null != consignmentInitialPolly.FinalException)
            {
                throw new Exception("Process pending deli import Polly failed", consignmentInitialPolly.FinalException);
            }

            var consignment = consignmentInitialPolly.Result;

            if (null != consignment)
            {
                ips.item_weight_double = consignment.weight_double;
                if (!string.IsNullOrEmpty(consignment.shipper_address_country))
                {
                    ips.orig_country_cd = consignment.shipper_address_country;
                }
                if (!string.IsNullOrEmpty(consignment.item_category))
                {
                    ips.content = consignment.item_category.Equals("01") ? "M" : "D";
                }
                else
                {
                    ips.content = "D";
                }
            }

            return(ips);
        }
Пример #2
0
        private async Task ProcessChildIpsImport(Adapters.Oal.dbo_ips_import parent, string consignmentNo)
        {
            var child = parent.Clone();

            child.id             = GenerateId(13);
            child.item_id        = consignmentNo;
            child.data_code_name = "deli";
            child.class_cd       = GetClassCode(consignmentNo);

            var consignmentInitialAdapter = new Adapters.Oal.dbo_consignment_initialAdapter();
            var consignmentInitialPolly   = await Policy.Handle <SqlException>()
                                            .WaitAndRetryAsync(3, c => TimeSpan.FromMilliseconds(c * 500))
                                            .ExecuteAndCaptureAsync(async() => await SearchConsignmentInitialAsync(consignmentNo));

            if (null != consignmentInitialPolly.FinalException)
            {
                throw new Exception("Process child IPS import Polly failed", consignmentInitialPolly.FinalException);
            }

            var consignment = consignmentInitialPolly.Result;

            if (null != consignment)
            {
                child.item_weight_double = consignment.weight_double;
                if (!string.IsNullOrEmpty(consignment.shipper_address_country))
                {
                    child.orig_country_cd = consignment.shipper_address_country;
                }
                if (!string.IsNullOrEmpty(consignment.item_category))
                {
                    child.content = consignment.item_category.Equals("01") ? "M" : "D";
                }
                else
                {
                    child.content = "D";
                }
            }


            var pattern = @"\w{2}\d{9}(?<country>\w{2})";
            var match   = System.Text.RegularExpressions.Regex.Match(consignmentNo, pattern);

            if (match.Success)
            {
                child.orig_country_cd = match.Groups["country"].Value;
            }


            if (null == child.item_weight_double)
            {
                child.item_weight_double = 0d;
            }

            m_deliIpsImportEventRows.Add(child);
        }