diff --git a/internal/models/order/order_profit_info.go b/internal/models/order/order_profit_info.go index f6cccc4..4f1caa9 100644 --- a/internal/models/order/order_profit_info.go +++ b/internal/models/order/order_profit_info.go @@ -1,6 +1,7 @@ package order import ( + datastructure "github.com/duke-git/lancet/v2/datastructure/list" "github.com/duke-git/lancet/v2/slice" "strings" "time" @@ -54,21 +55,28 @@ func GetOrderProfitByBankOrderId(bankOrderId string) OrderProfitInfo { func GetOrderProfitListByBankOrderIdList(bankOrderIdList []string) []OrderProfitInfo { o := orm.NewOrm() - orderProfitList := make([]OrderProfitInfo, 0) + orderProfitList := datastructure.NewCopyOnWriteList([]OrderProfitInfo{}) + orderProfitListUnsafe := make([]OrderProfitInfo, 0) if len(bankOrderIdList) == 0 { - return orderProfitList + orderProfitList.ForEach(func(info OrderProfitInfo) { + orderProfitListUnsafe = append(orderProfitListUnsafe, info) + }) + return orderProfitListUnsafe } bankOrderIdList = slice.Unique(bankOrderIdList) - slice.ForEach(slice.Chunk(bankOrderIdList, 100), func(index int, item []string) { - tmpOrderProfitList := make([]OrderProfitInfo, 0) - _, err := o.QueryTable(ORDER_PROFIT_INFO).Filter("bank_order_id__in", item).All(&tmpOrderProfitList) + slice.ForEachConcurrent(slice.Chunk(bankOrderIdList, 100), func(index int, item []string) { + tmpOrderProfitListTmp := make([]OrderProfitInfo, 0) + _, err := o.QueryTable(ORDER_PROFIT_INFO).Filter("bank_order_id__in", item).All(&tmpOrderProfitListTmp) if err != nil { logs.Error("GetOrderProfitByBankOrderId fail:", err) return } - orderProfitList = append(orderProfitList, tmpOrderProfitList...) + orderProfitList.AddAll(tmpOrderProfitListTmp) + }, 20) + orderProfitList.ForEach(func(info OrderProfitInfo) { + orderProfitListUnsafe = append(orderProfitListUnsafe, info) }) - return orderProfitList + return orderProfitListUnsafe } func GetAllOrderProfit(params map[string]string) []OrderProfitInfo {