测试用例
func (self *TestGeneralserviceTestSuite) Test066_CacheQueryFrontSumReportShopl() { var req = frontdto.NewStatRequest() req.ObjectType = esentity.OBJECT_TYPE_SHOP req.ShopIds = []int64{814560415908069377} var ret = reportsum.FindBeanReportSumShop().CacheQueryFrontSumReport(req) var ret1 = reportsum.FindBeanReportSumShop().CacheQueryFrontSumReport(req) golog.Info(ret, ret1, ret.Total) }
{
"baseEntity": {},
"code": 200,
"msg": "成功",
"total": 0,
"exist": false,
"data": [
{
"id": "F|shop|20241231|814560415908069377|0",
"sum_date": "20241231",
"created_at": "2025-01-01T02:00:00.228705277+08:00",
"page_flag": "F",
"object_type": "shop",
"object_id": 0,
"account_id": 814560530895962113,
"account_name": "",
"vendor_id": 0,
"shop_id": 814560415908069377,
"shop_name": "华南电子科技",
"parent_shop_id": 0,
"parent_shop_name": "",
"spu_id": 0,
"part_number_raw": "",
"brand_id": 0,
"brand_name": "",
"categ_id": 0,
"categ_name": "",
"avab_count": 30,
"avab_qty": 2884783,
"rfq_count": 280,
"rfq_qty": 42511,
"purchase_line_count": 3,
"purchase_line_qty": 804,
"sale_line_count": 4,
"sale_line_qty": 2165,
"ok_supplier_count": 3,
"purchase_amount_platform": 203443100,
"sale_amount_platform": 445692900,
"sale_count_platform": 1384,
"purchase_count_platform": 196,
"sale_qty_platform": 2272,
"purchase_qty_platform": 1879,
"txn_amount": 649136000,
"txn_count": 1580,
"count_spu": 0,
"count_brand": 0,
"count_categ": 0,
"count_categ_param": 0
}
]
} 1
缓存应用
package querybase import ( "git.ichub.com/general/webcli120/goconfig/base/basedto" "git.ichub.com/general/webcli120/goconfig/ichublog/golog" "git.ichub.com/general/webcli120/goweb/pagemodel" "icd/general-srv/esentity" "icd/general-srv/handler/computemetrics/computesum/queryfacade/querybase/querycache" "icd/general-srv/handler/report_dto/frontdto" ) type QueryCache struct { basedto.BaseEntity *QueryReportBase } func NewQueryCache() *QueryCache { return &QueryCache{} } func DefaultOf(base *QueryReportBase) *QueryCache { var ret = &QueryCache{ QueryReportBase: base, } return ret } func (self *QueryCache) CacheQuerySpuList(req *frontdto.StatRequest) *pagemodel.PageResult[*esentity.ServiceSumReportEs] { var ids []string = make([]string, 0) var list = make([]*esentity.ServiceSumReportEs, 0) for _, id := range req.ObjectIds { if r := querycache.FindBeanShopCache().GetSpuList(id); r != nil { list = append(list, r) } else { ids = append(ids, id) } } if len(ids) == 0 { return pagemodel.ResultOkPageResult(list) } req.ObjectIds = ids var ret = self.QueryFrontSumReport(req) if ret.IsFailed() { ret.Data = list golog.Error("ReportSumShop [CacheQuerySpuList] err =", ret) return ret } for _, i := range ret.Data { querycache.FindBeanShopCache().SetSpuList(i.SpuId, i) } ret.Data = append(ret.Data, list...) return ret } func (self *QueryCache) CacheQueryShopList(req *frontdto.StatRequest) *pagemodel.PageResult[*esentity.ServiceSumReportEs] { var ids []int64 = make([]int64, 0) var list = make([]*esentity.ServiceSumReportEs, 0) for _, id := range req.ShopIds { if r := querycache.FindBeanShopCache().GetShopList(id); r != nil { list = append(list, r) } else { ids = append(ids, id) } } if len(ids) == 0 { return pagemodel.ResultOkPageResult(list) } req.ShopIds = ids var ret = self.QueryFrontSumReport(req) if ret.IsFailed() { ret.Data = list golog.Error("ReportSumShop [CacheQueryShopList] err =", ret) return ret } for _, i := range ret.Data { querycache.FindBeanShopCache().SetShopList(i.ShopId, i) } ret.Data = append(ret.Data, list...) return ret }
func (self *QueryReportBase) CacheQueryFrontSumReport(req *frontdto.StatRequest) *pagemodel.PageResult[*esentity.ServiceSumReportEs] { var qc = DefaultOf(self) if req.IfShopObjectType() { return qc.CacheQueryShopList(req) } if req.IfSpuObjectType() { return qc.CacheQuerySpuList(req) } //brand categ return self.QueryFrontSumReport(req) } func (self *QueryReportBase) QueryFrontSumReport(req *frontdto.StatRequest) *pagemodel.PageResult[*esentity.ServiceSumReportEs] { req.SumChild = req.IfShopObjectType() && req.SumChild var ret = self.QueryRequest(req) if !ret.ExistRecord() { req.YesterdayLocal() //没有,找昨天 ret = self.QueryRequest(req) } if !req.SumChild { return ret } if ret.IsFailed() || ret.Data == nil { golog.Error("ReportSumShop [QueryFrontSumReport] err =", ret, req.QuerySource) return ret } if ret.ExistRecord() { var maps, err = third.FindBeanThirdProxy().CacheContactShopGetChilds(req.ShopIds) if err != nil { req.SumChild = req.IfShopObjectType() && req.SumChild golog.Error("ReportSumShop [QueryFrontSumReport] err = ", err) return ret } self.sumChilds(ret, maps, req.ObjectType) } return ret }
缓存机制
type ShopCache struct { basedto.BaseEntitySingle } func NewShopCache() *ShopCache { return &ShopCache{} } func (self *ShopCache) GetShopList(id int64) *esentity.ServiceSumReportEs { var key = cache_key_shoplist + ":" + gconv.String(id) ids, found := ichubcache.CacheGetOf[esentity.ServiceSumReportEs](thirdcache.FrontCache(), key) if found { return ids } return nil } func (self *ShopCache) SetShopList(id int64, value *esentity.ServiceSumReportEs) { var key = cache_key_shoplist + ":" + gconv.String(id) ichubcache.CacheSetOf[esentity.ServiceSumReportEs](thirdcache.FrontCache(), key, value) } func (self *ShopCache) GetSpuList(id string) *esentity.ServiceSumReportEs { var key = cache_key_spulist + ":" + gconv.String(id) ids, found := ichubcache.CacheGetOf[esentity.ServiceSumReportEs](thirdcache.FrontCache(), key) if found { return ids } return nil } func (self *ShopCache) SetSpuList(id int64, value *esentity.ServiceSumReportEs) { var key = cache_key_spulist + ":" + gconv.String(id) ichubcache.CacheSetOf[esentity.ServiceSumReportEs](thirdcache.FrontCache(), key, value) }
func Flush() { frontCache.Flush() } func FrontCache() *ichubcache.IchubCache { return frontCache } // var CacheNew=true var frontCache = ichubcache.DefaultOf("F-cache:", 2*30*time.Minute) func CacheSetShopChild(id int64, ids []int64) { var key = cache_key_shopchild + ":" + gconv.String(id) ichubcache.CacheSetOf[[]int64](frontCache, key, &ids) } func CacheGetShopChild(id int64) []int64 { var key = cache_key_shopchild + ":" + gconv.String(id) ids, found := ichubcache.CacheGetOf[[]int64](frontCache, key) if found { return *ids } return nil }标签:三十二,缓存,return,req,ids,ret,var,Go,id From: https://blog.csdn.net/leijmdas/article/details/144869717