这两份代码的区别是什么:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// getExpectSettledDateV2 获取预估结算日,考虑基金公司节假日
func (t *Worker) getExpectSettledDateV2(ctx context.Context, startTime time.Time, productSymbol string, settlementDay int, fundHolidays []*mktmapping.FundCalendar) (time.Time, error) {
var (
startDate = carbon.ParseByLayout(startTime.Format(carbon.DateTimeLayout), carbon.DateTimeLayout, carbon.Local).ToDateStruct()
)

fundHoliday, getFundHoliday := lo.Find[*mktmapping.FundCalendar](fundHolidays, func(item *mktmapping.FundCalendar) bool {
return item.Symbol == productSymbol
})

if !getFundHoliday {
return time.Time{}, fmt.Errorf("wrong result from mkt service,lack fund info symbol %s", productSymbol)
}

expectSettledDate := fundHoliday.NextSettlementDay(startDate, settlementDay)

return expectSettledDate.ToStdTime(), nil
}

// getExpectSettledDateV3 获取预估结算日,考虑基金公司节假日
func (t *Worker) getExpectSettledDateV3(ctx context.Context, startTime time.Time, productCode string, productSymbol string, dir int, fundHolidayMap map[string]*mktmapping.FundCalendar) (time.Time, error) {
var (
startDate = carbon.ParseByLayout(startTime.Format(carbon.DateTimeLayout), carbon.DateTimeLayout, carbon.Local).ToDateStruct()
)
productBasicInfo, err := t.mktWealthClient.GetProductBasicInfo(ctx, mktmapping.ProductBasicInfoParams{ProductCode: productCode})
if err != nil {
return time.Time{}, err
}

settlementDay := productBasicInfo.GetSettlementDayByDirection(dir)

fundHoliday, getFundHoliday := fundHolidayMap[productSymbol]

if !getFundHoliday {
return time.Time{}, fmt.Errorf("wrong result from mkt service,lack fund info symbol %s", productSymbol)
}

expectSettledDate := fundHoliday.NextSettlementDay(startDate, settlementDay)

return expectSettledDate.ToStdTime(), nil
这两段代码主要用于获取预估结算日,考虑基金公司节假日。它们的主要区别在于输入参数和部分逻辑上的不同。以下是具体的区别:
  1. 参数不同

    • getExpectSettledDateV2 接收 productSymbolsettlementDay 作为参数。
    • getExpectSettledDateV3 多了一个 productCodedir 参数,并用 productCode 获取产品的基本信息。
  2. 获取结算日的方式不同

    • getExpectSettledDateV2 直接使用传入的 settlementDay
    • getExpectSettledDateV3 通过 productCode 从市场服务 (t.mktWealthClient) 获取产品的基本信息,然后根据 dir 获取相应的 settlementDay
  3. 获取基金假期信息的方式不同

    • getExpectSettledDateV2 使用 lo.FindfundHolidays 列表中查找对应的 fundHoliday
    • getExpectSettledDateV3 使用 fundHolidayMap 直接查找 fundHoliday
  4. 错误处理信息不同

    • getExpectSettledDateV2 的错误信息中指出 “lack fund info symbol”。
    • getExpectSettledDateV3 的错误信息中同样指出 “lack fund info symbol”,但它在获取 productBasicInfo 时也可能会返回错误。

总结:

  • getExpectSettledDateV2 更加简单,直接使用传入的参数进行操作。
  • getExpectSettledDateV3 更加复杂,先通过 productCode 获取产品的基本信息,然后根据 dir 获取结算日,再通过 fundHolidayMap 查找基金假期。

这种设计使得 getExpectSettledDateV3 具备了更强的灵活性和扩展性,适用于更复杂的业务场景。

——来自AI问答宝 https://ai.wendabao.net
}