/// <summary> /// 移除核銷週期未在費率明細裡出現過的代收通路項目 /// </summary> /// <param name="set"></param> private static void RemoveNotUsedPeriod(CollectionTypeSet set) { List <string> detail = set.CollectionTypeDetail.Select(p => p.ChannelId).Distinct().ToList(); Dictionary <string, CollectionTypeVerifyPeriodModel> period = set.CollectionTypeVerifyPeriod.ToDictionary(p => p.ChannelId, q => q); List <string> periodExpectChannels = period.Keys.Except(detail).ToList(); List <CollectionTypeVerifyPeriodModel> removePeriods = period.Where(p => p.Key.In(periodExpectChannels.ToArray())).Select(p => p.Value).ToList(); removePeriods.ForEach(row => set.CollectionTypeVerifyPeriod.Remove(row)); }
/// <summary> /// 設置欄位值 /// </summary> /// <param name="set"></param> /// <param name="action"></param> public static void SetData(ReceiptBillSet set, ApplicationDbContext dataAccess, Dictionary <string, BizCustomerSet> bizCustSetDic, Dictionary <string, CollectionTypeSet> colSetDic, Dictionary <DateTime, bool> workDic) { BizCustomerSet bizCustomerSet = GetBizCustomerSet(dataAccess, bizCustSetDic, set.ReceiptBill.VirtualAccountCode); CollectionTypeSet collectionTypeSet = GetCollectionTypeSet(dataAccess, colSetDic, set.ReceiptBill.CollectionTypeId); SetBizCustomer(set.ReceiptBill, bizCustomerSet.BizCustomer); SetBillNo(dataAccess, set.ReceiptBill); SetFee(set.ReceiptBill, bizCustomerSet, collectionTypeSet); SetRemitDate(set.ReceiptBill, collectionTypeSet, workDic); SetErrMessage(set.ReceiptBill); }
/// <summary> /// /// </summary> /// <param name="expectData"></param> /// <param name="actualData"></param> private void AssertSet(CollectionTypeSet expectData, CollectionTypeSet actualData) { //檢查通路總手續費是否計算錯誤 for (int i = 0; i < expectData.CollectionTypeDetail.Count; i++) { Assert.AreEqual(expectData.CollectionTypeDetail[i].ChannelTotalFee, actualData.CollectionTypeDetail[i].ChannelTotalFee); } //檢查是否有多餘的代收通路 foreach (var data in actualData.CollectionTypeVerifyPeriod) { Assert.Contains(data.ChannelId, expectData.CollectionTypeVerifyPeriod.Select(p => p.ChannelId).ToList()); } }
/// <summary> /// 檢查是否有通路尚未填寫核銷規則 /// </summary> /// <returns></returns> private static void CheckChannelVerifyPeriod(SysMessageLog message, CollectionTypeSet set) { Dictionary <string, string> detail = set.CollectionTypeDetail.Select(p => p.Channel).Distinct().ToDictionary(p => p.ChannelId, q => q.ChannelName); Dictionary <string, CollectionTypeVerifyPeriodModel> period = set.CollectionTypeVerifyPeriod.ToDictionary(p => p.ChannelId, q => q); List <string> detailExpectChannels = detail.Keys.Except(period.Keys).ToList(); string[] notWriteChannels = detail?.Where(p => p.Key.In(detailExpectChannels.ToArray())).Select(p => p.Value).Distinct().ToArray(); string channelName = LibData.Merge(",", false, notWriteChannels); if (!channelName.IsNullOrEmpty()) { message.AddCustErrorMessage(MessageCode.Code1014, channelName); } }
/// <summary> /// 設置預計匯款日 /// </summary> /// <param name="model"></param> /// <param name="periodModel"></param> /// <returns></returns> private static void SetRemitDate(ReceiptBillModel receiptBill, CollectionTypeSet collectionTypeSet, Dictionary <DateTime, bool> workDic) { DateTime expectRemitDate = receiptBill.ExpectRemitDate; if (!receiptBill.Channel.ChannelGroupType.In(ChannelGroupType.Bank, ChannelGroupType.Self)) { CollectionTypeVerifyPeriodModel period = collectionTypeSet.CollectionTypeVerifyPeriod.Where(p => p.ChannelId.Equals(receiptBill.ChannelId)).FirstOrDefault(); switch (period?.PayPeriodType) { case PayPeriodType.NDay_A: expectRemitDate = GetNDay_A(workDic, receiptBill.TransDate); break; case PayPeriodType.NDay_B: expectRemitDate = GetNDay_B(workDic, receiptBill.TransDate); break; case PayPeriodType.NDay_C: expectRemitDate = GetNDay_C(workDic, receiptBill.TransDate); break; case PayPeriodType.Week: expectRemitDate = GetWeekTime(workDic, receiptBill.TransDate); break; case PayPeriodType.TenDay: expectRemitDate = GetTenDayTime(workDic, receiptBill.TransDate); break; } } receiptBill.ExpectRemitDate = expectRemitDate; }
/// <summary> /// /// </summary> /// <param name="expectData"></param> /// <param name="actualData"></param> /// <param name="messageLog"></param> private void AssertCorrectData(CollectionTypeSet expectData, CollectionTypeSet actualData, bool isCheckInput = true) { Comm.CheckInputValueIsNull(actualData); AssertSet(expectData, actualData); AssertMessage(); }
public void C_CorrectData_MartA_100Time() { CollectionTypeSet expectData = new CollectionTypeSet() { CollectionType = new CollectionTypeModel(), CollectionTypeDetail = new List <CollectionTypeDetailModel>() { new CollectionTypeDetailModel() { ChannelTotalFee = 10 }, new CollectionTypeDetailModel() { ChannelTotalFee = 10 }, new CollectionTypeDetailModel() { ChannelTotalFee = 10 }, new CollectionTypeDetailModel() { ChannelTotalFee = 10 }, new CollectionTypeDetailModel() { ChannelTotalFee = 10 }, new CollectionTypeDetailModel() { ChannelTotalFee = 10 }, new CollectionTypeDetailModel() { ChannelTotalFee = 10 }, }, CollectionTypeVerifyPeriod = new List <CollectionTypeVerifyPeriodModel>() { new CollectionTypeVerifyPeriodModel() { ChannelId = "01" }, new CollectionTypeVerifyPeriodModel() { ChannelId = "02" }, new CollectionTypeVerifyPeriodModel() { ChannelId = "03" }, new CollectionTypeVerifyPeriodModel() { ChannelId = "04" }, new CollectionTypeVerifyPeriodModel() { ChannelId = "05" }, new CollectionTypeVerifyPeriodModel() { ChannelId = "12" }, new CollectionTypeVerifyPeriodModel() { ChannelId = "13" }, new CollectionTypeVerifyPeriodModel() { ChannelId = "14" }, }, }; Stopwatch sw = new Stopwatch(); for (int i = 0; i < 5000; i++) { var c = new CollectionTypeSet() { CollectionType = new CollectionTypeModel() { CollectionTypeId = "6V1", CollectionTypeName = "超商內扣", ChargePayType = ChargePayType.Deduction, }, CollectionTypeDetail = new List <CollectionTypeDetailModel>() { //new CollectionTypeDetailModel() { CollectionTypeId = "6V1", ChannelId = "05", SRange = 1, ERange = 20000, ChannelFee = 10, ChannelFeedBackFee = 0, ChannelRebateFee = 0, RowState= RowState.Insert }, new CollectionTypeDetailModel() { CollectionTypeId = "6V1", ChannelId = "02", SRange = 1, ERange = 20000, ChannelFee = 10, ChannelFeedBackFee = 0, ChannelRebateFee = 0, RowId = 2, RowState = RowState.Update }, new CollectionTypeDetailModel() { CollectionTypeId = "6V1", ChannelId = "03", SRange = 1, ERange = 20000, ChannelFee = 10, ChannelFeedBackFee = 0, ChannelRebateFee = 0, RowId = 3, RowState = RowState.Delete }, }, CollectionTypeVerifyPeriod = new List <CollectionTypeVerifyPeriodModel>() { //new CollectionTypeVerifyPeriodModel(){ CollectionTypeId="6V1", ChannelId="05", PayPeriodType= PayPeriodType.NDay_A, RowState= RowState.Insert }, new CollectionTypeVerifyPeriodModel() { CollectionTypeId = "6V1", ChannelId = "01", PayPeriodType = PayPeriodType.NDay_A }, new CollectionTypeVerifyPeriodModel() { CollectionTypeId = "6V1", ChannelId = "02", PayPeriodType = PayPeriodType.NDay_B }, new CollectionTypeVerifyPeriodModel() { CollectionTypeId = "6V1", ChannelId = "03", PayPeriodType = PayPeriodType.NDay_C }, new CollectionTypeVerifyPeriodModel() { CollectionTypeId = "6V1", ChannelId = "04", PayPeriodType = PayPeriodType.TenDay }, new CollectionTypeVerifyPeriodModel() { CollectionTypeId = "6V1", ChannelId = "12", PayPeriodType = PayPeriodType.Week }, new CollectionTypeVerifyPeriodModel() { CollectionTypeId = "6V1", ChannelId = "13", PayPeriodType = PayPeriodType.NDay_A }, new CollectionTypeVerifyPeriodModel() { CollectionTypeId = "6V1", ChannelId = "14", PayPeriodType = PayPeriodType.NDay_B }, }, }; if (i != 0) { sw.Start(); } Repo.Update(new object[] { "6V1" }, c); if (i != 0) { sw.Stop(); } //AssertCorrectData(expectData, actualData); Console.WriteLine($"Time={sw.ElapsedMilliseconds:n0}ms"); } }
public void C_CorrectData_MartA() { CollectionTypeSet expectData = new CollectionTypeSet() { CollectionType = new CollectionTypeModel(), CollectionTypeDetail = new List <CollectionTypeDetailModel>() { new CollectionTypeDetailModel() { ChannelTotalFee = 10 }, new CollectionTypeDetailModel() { ChannelTotalFee = 10 }, new CollectionTypeDetailModel() { ChannelTotalFee = 10 }, new CollectionTypeDetailModel() { ChannelTotalFee = 10 }, new CollectionTypeDetailModel() { ChannelTotalFee = 10 }, new CollectionTypeDetailModel() { ChannelTotalFee = 10 }, new CollectionTypeDetailModel() { ChannelTotalFee = 10 }, }, CollectionTypeVerifyPeriod = new List <CollectionTypeVerifyPeriodModel>() { new CollectionTypeVerifyPeriodModel() { ChannelId = "01" }, new CollectionTypeVerifyPeriodModel() { ChannelId = "02" }, new CollectionTypeVerifyPeriodModel() { ChannelId = "03" }, new CollectionTypeVerifyPeriodModel() { ChannelId = "04" }, new CollectionTypeVerifyPeriodModel() { ChannelId = "05" }, new CollectionTypeVerifyPeriodModel() { ChannelId = "12" }, new CollectionTypeVerifyPeriodModel() { ChannelId = "13" }, new CollectionTypeVerifyPeriodModel() { ChannelId = "14" }, }, }, actualData = Repo.Update(new object[] { "6V1" }, new CollectionTypeSet() { CollectionType = new CollectionTypeModel() { CollectionTypeId = "6V1", CollectionTypeName = "超商內扣", ChargePayType = ChargePayType.Deduction, }, CollectionTypeDetail = new List <CollectionTypeDetailModel>() { new CollectionTypeDetailModel() { CollectionTypeId = "6V1", ChannelId = "05", SRange = 1, ERange = 20000, ChannelFee = 10, ChannelFeedBackFee = 0, ChannelRebateFee = 0, RowState = RowState.Insert }, new CollectionTypeDetailModel() { CollectionTypeId = "6V1", ChannelId = "02", SRange = 1, ERange = 20000, ChannelFee = 10, ChannelFeedBackFee = 0, ChannelRebateFee = 0, RowId = 2, RowState = RowState.Update }, new CollectionTypeDetailModel() { CollectionTypeId = "6V1", ChannelId = "03", SRange = 1, ERange = 20000, ChannelFee = 10, ChannelFeedBackFee = 0, ChannelRebateFee = 0, RowId = 3, RowState = RowState.Delete }, }, CollectionTypeVerifyPeriod = new List <CollectionTypeVerifyPeriodModel>() { new CollectionTypeVerifyPeriodModel() { CollectionTypeId = "6V1", ChannelId = "05", PayPeriodType = PayPeriodType.NDay_A, RowState = RowState.Insert }, new CollectionTypeVerifyPeriodModel() { CollectionTypeId = "6V1", ChannelId = "01", PayPeriodType = PayPeriodType.NDay_A }, new CollectionTypeVerifyPeriodModel() { CollectionTypeId = "6V1", ChannelId = "02", PayPeriodType = PayPeriodType.NDay_B }, new CollectionTypeVerifyPeriodModel() { CollectionTypeId = "6V1", ChannelId = "03", PayPeriodType = PayPeriodType.NDay_C }, new CollectionTypeVerifyPeriodModel() { CollectionTypeId = "6V1", ChannelId = "04", PayPeriodType = PayPeriodType.TenDay }, new CollectionTypeVerifyPeriodModel() { CollectionTypeId = "6V1", ChannelId = "12", PayPeriodType = PayPeriodType.Week }, new CollectionTypeVerifyPeriodModel() { CollectionTypeId = "6V1", ChannelId = "13", PayPeriodType = PayPeriodType.NDay_A }, new CollectionTypeVerifyPeriodModel() { CollectionTypeId = "6V1", ChannelId = "14", PayPeriodType = PayPeriodType.NDay_B }, }, }); AssertCorrectData(expectData, actualData); }
public void C_CorrectData_MartB() { CollectionTypeSet expectData = new CollectionTypeSet() { CollectionType = new CollectionTypeModel(), CollectionTypeDetail = new List <CollectionTypeDetailModel>() { new CollectionTypeDetailModel() { ChannelTotalFee = 10 }, new CollectionTypeDetailModel() { ChannelTotalFee = 10 }, new CollectionTypeDetailModel() { ChannelTotalFee = 10 }, new CollectionTypeDetailModel() { ChannelTotalFee = 10 }, new CollectionTypeDetailModel() { ChannelTotalFee = 10 }, new CollectionTypeDetailModel() { ChannelTotalFee = 10 }, new CollectionTypeDetailModel() { ChannelTotalFee = 10 }, }, CollectionTypeVerifyPeriod = new List <CollectionTypeVerifyPeriodModel>() { new CollectionTypeVerifyPeriodModel() { ChannelId = "01" }, new CollectionTypeVerifyPeriodModel() { ChannelId = "02" }, new CollectionTypeVerifyPeriodModel() { ChannelId = "03" }, new CollectionTypeVerifyPeriodModel() { ChannelId = "04" }, new CollectionTypeVerifyPeriodModel() { ChannelId = "12" }, new CollectionTypeVerifyPeriodModel() { ChannelId = "13" }, new CollectionTypeVerifyPeriodModel() { ChannelId = "14" }, }, }, actualData = Repo.Create(new CollectionTypeSet() { CollectionType = new CollectionTypeModel() { CollectionTypeId = "6P2", CollectionTypeName = "超商內扣", ChargePayType = ChargePayType.Deduction, }, CollectionTypeDetail = new List <CollectionTypeDetailModel>() { new CollectionTypeDetailModel() { CollectionTypeId = "6P2", ChannelId = "01", SRange = 1, ERange = 20000, ChannelFee = 10, ChannelFeedBackFee = 0, ChannelRebateFee = 0, }, new CollectionTypeDetailModel() { CollectionTypeId = "6P2", ChannelId = "02", SRange = 1, ERange = 20000, ChannelFee = 10, ChannelFeedBackFee = 0, ChannelRebateFee = 0, }, new CollectionTypeDetailModel() { CollectionTypeId = "6P2", ChannelId = "03", SRange = 1, ERange = 20000, ChannelFee = 10, ChannelFeedBackFee = 0, ChannelRebateFee = 0, }, new CollectionTypeDetailModel() { CollectionTypeId = "6P2", ChannelId = "04", SRange = 1, ERange = 20000, ChannelFee = 10, ChannelFeedBackFee = 0, ChannelRebateFee = 0, }, new CollectionTypeDetailModel() { CollectionTypeId = "6P2", ChannelId = "12", SRange = 1, ERange = 20000, ChannelFee = 6, ChannelFeedBackFee = 4, ChannelRebateFee = 0, }, new CollectionTypeDetailModel() { CollectionTypeId = "6P2", ChannelId = "13", SRange = 1, ERange = 20000, ChannelFee = 8, ChannelFeedBackFee = 2, ChannelRebateFee = 0, }, new CollectionTypeDetailModel() { CollectionTypeId = "6P2", ChannelId = "14", SRange = 1, ERange = 20000, ChannelFee = 0, ChannelFeedBackFee = 0, ChannelRebateFee = 10, }, }, CollectionTypeVerifyPeriod = new List <CollectionTypeVerifyPeriodModel>() { new CollectionTypeVerifyPeriodModel() { CollectionTypeId = "6P2", ChannelId = "01", PayPeriodType = PayPeriodType.NDay_A }, new CollectionTypeVerifyPeriodModel() { CollectionTypeId = "6P2", ChannelId = "02", PayPeriodType = PayPeriodType.NDay_B }, new CollectionTypeVerifyPeriodModel() { CollectionTypeId = "6P2", ChannelId = "03", PayPeriodType = PayPeriodType.NDay_C }, new CollectionTypeVerifyPeriodModel() { CollectionTypeId = "6P2", ChannelId = "04", PayPeriodType = PayPeriodType.TenDay }, new CollectionTypeVerifyPeriodModel() { CollectionTypeId = "6P2", ChannelId = "12", PayPeriodType = PayPeriodType.Week }, new CollectionTypeVerifyPeriodModel() { CollectionTypeId = "6P2", ChannelId = "13", PayPeriodType = PayPeriodType.NDay_A }, new CollectionTypeVerifyPeriodModel() { CollectionTypeId = "6P2", ChannelId = "14", PayPeriodType = PayPeriodType.NDay_B }, new CollectionTypeVerifyPeriodModel() { CollectionTypeId = "6P2", ChannelId = "05", PayPeriodType = PayPeriodType.NDay_B }, new CollectionTypeVerifyPeriodModel() { CollectionTypeId = "6P2", ChannelId = "06", PayPeriodType = PayPeriodType.NDay_B }, new CollectionTypeVerifyPeriodModel() { CollectionTypeId = "6P2", ChannelId = "07", PayPeriodType = PayPeriodType.NDay_B }, }, }); AssertCorrectData(expectData, actualData); }
/// <summary> /// 設置資料 /// </summary> /// <param name="set"></param> public static void SetData(CollectionTypeSet set) { SetCollectionTypeDetail(set.CollectionTypeDetail); RemoveNotUsedPeriod(set); }
/// <summary> /// 檢查資料 /// </summary> /// <param name="set"></param> /// <param name="message"></param> public static void CheckData(CollectionTypeSet set, SysMessageLog message) { CheckIsOverlap(message, set.CollectionTypeDetail); CheckChannelVerifyPeriod(message, set); }
/// <summary> /// 設置費用 /// </summary> private static void SetFee(ReceiptBillModel receiptBill, BizCustomerSet bizCustomerSet, CollectionTypeSet collectionTypeSet) { CollectionTypeDetailModel collectionTypeDetailModel = collectionTypeSet.CollectionTypeDetail.FirstOrDefault(p => p.ChannelId.Equals(receiptBill.ChannelId) && (p.SRange <= receiptBill.PayAmount && p.ERange >= receiptBill.PayAmount)); BizCustomerFeeDetailModel bizCustomerFeeDetailModel = bizCustomerSet.BizCustomerFeeDetail.FirstOrDefault(p => p.ChannelGroupType.Equals(receiptBill.Channel.ChannelGroupType)); BizCustomerFeeDetailModel hiTrust = bizCustomerSet.BizCustomerFeeDetail.FirstOrDefault(p => p.BankFeeType.Equals(BankFeeType.Hitrust_ClearFee_CurMonth) || p.BankFeeType.Equals(BankFeeType.Hitrust_ClearFee_NextMonth)); receiptBill.ChargePayType = collectionTypeSet.CollectionType.ChargePayType; receiptBill.BankFeeType = bizCustomerFeeDetailModel.BankFeeType; if (receiptBill.BankFeeType.Equals(BankFeeType.TotalFee)) { switch (receiptBill.CollectionType.ChargePayType) { case ChargePayType.Deduction: { receiptBill.ThirdFee = FeeDeduct(bizCustomerFeeDetailModel.Fee, collectionTypeDetailModel.ChannelTotalFee, bizCustomerFeeDetailModel.IntroPercent); receiptBill.BankFee = bizCustomerFeeDetailModel.Fee - receiptBill.ThirdFee; } break; case ChargePayType.Increase: { receiptBill.ThirdFee = FeePlus(bizCustomerFeeDetailModel.Fee, bizCustomerFeeDetailModel.IntroPercent); receiptBill.BankFee = bizCustomerFeeDetailModel.Fee - receiptBill.ThirdFee; } break; } } else { receiptBill.BankFee = bizCustomerFeeDetailModel.Fee; receiptBill.ThirdFee = 0m; } receiptBill.ThirdFee = null != hiTrust ? hiTrust.IntroPercent : receiptBill.ThirdFee; receiptBill.ChannelFeedBackFee = collectionTypeDetailModel.ChannelFeedBackFee; receiptBill.ChannelRebateFee = collectionTypeDetailModel.ChannelRebateFee; receiptBill.ChannelFee = collectionTypeDetailModel.ChannelFee; receiptBill.ChannelTotalFee = collectionTypeDetailModel.ChannelTotalFee; receiptBill.TotalFee = receiptBill.BankFeeType.Equals(BankFeeType.TotalFee) ? bizCustomerFeeDetailModel.Fee : collectionTypeDetailModel.ChannelTotalFee; }