catface_backend_go/app/model_redis/selectedAnimal4Prefer.go

61 lines
1.6 KiB
Go
Raw Normal View History

2024-11-18 17:10:11 +08:00
package model_redis
// INFO 辅助 animal - list - prefer 模式下的查询特化。
func CreateSelectedAnimal4Prefer() *SelectedAnimal4Prefer { // 构造函数的必要性,这样才能调用【父类】的方法。
return &SelectedAnimal4Prefer{
BaseModel: NewBaseModel(),
}
}
2024-11-18 17:10:11 +08:00
type SelectedAnimal4Prefer struct {
*BaseModel `json:"-"` // TIP Go 中组合的概念。
EncounteredCatsId []int64 `json:"encountered_cats_id"` // #1 对应第一阶段:近期路遇关联
NewCatsId []int64 `json:"new_cats_id"` // #2 对应第二阶段:近期新增
2024-11-18 18:35:10 +08:00
notPassNewCat bool `json:"-"`
2024-11-18 17:10:11 +08:00
}
2024-11-18 18:35:10 +08:00
func (s *SelectedAnimal4Prefer) NotPassNew() bool {
return s.notPassNewCat
2024-11-18 17:10:11 +08:00
}
func (s *SelectedAnimal4Prefer) Length() int {
return len(s.NewCatsId) + len(s.EncounteredCatsId)
}
func (s *SelectedAnimal4Prefer) NumEnc() int {
return len(s.EncounteredCatsId)
}
func (s *SelectedAnimal4Prefer) GetAllIds() []int64 {
return append(s.EncounteredCatsId, s.NewCatsId...)
}
func (s *SelectedAnimal4Prefer) AppendEncIds(ids []int64) {
for _, id := range ids {
s.EncounteredCatsId = append(s.EncounteredCatsId, int64(id))
}
}
2024-11-18 18:35:10 +08:00
// BASE CURD
/**
* @description: 实现重写补充子类需要增加的操作
* @return {*}
*/
func (s *SelectedAnimal4Prefer) GenerateKey() int64 {
2024-11-18 18:35:10 +08:00
s.notPassNewCat = true
return s.BaseModel.GenerateKey()
2024-11-18 18:35:10 +08:00
}
// 调用 BaseModel 的 SetDataByKey 方法
func (s *SelectedAnimal4Prefer) SetDataByKey() (bool, error) {
return s.BaseModel.SetDataByKey(s)
2024-11-18 18:35:10 +08:00
}
// 调用 BaseModel 的 GetDataByKey 方法
2024-11-18 18:35:10 +08:00
func (s *SelectedAnimal4Prefer) GetDataByKey(key int64) (bool, error) {
return s.BaseModel.GetDataByKey(key, s)
2024-11-18 18:35:10 +08:00
}