47 lines
1.5 KiB
Go
47 lines
1.5 KiB
Go
package dao
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
|
|
"36wisdom/biz/consts"
|
|
"36wisdom/biz/model/entity"
|
|
"36wisdom/common"
|
|
)
|
|
|
|
type lifeTaskDao struct{ common.BaseDao }
|
|
|
|
var LifeTask = &lifeTaskDao{BaseDao: common.BaseDao{Table: consts.TableLifeTask}}
|
|
|
|
func (d *lifeTaskDao) Init(ctx context.Context) error {
|
|
_, err := g.DB().Exec(ctx, `
|
|
CREATE TABLE IF NOT EXISTS life_task (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
strategy_id INTEGER NOT NULL,
|
|
title TEXT NOT NULL,
|
|
description TEXT NOT NULL,
|
|
guide TEXT NOT NULL,
|
|
reward_points INTEGER NOT NULL DEFAULT 20,
|
|
status INTEGER NOT NULL DEFAULT 1
|
|
);
|
|
CREATE INDEX IF NOT EXISTS idx_life_task_strategy ON life_task(strategy_id);`)
|
|
return err
|
|
}
|
|
|
|
// GetByPk 主键查询(无缓存);不存在返回 nil, nil。
|
|
func (d *lifeTaskDao) GetByPk(ctx context.Context, id int64) (*entity.LifeTask, error) {
|
|
return common.GetOne[entity.LifeTask](d.Model().Ctx(ctx).WherePri(id))
|
|
}
|
|
|
|
// ListEnabledCached 启用任务(内容缓存),按 id 排序。
|
|
func (d *lifeTaskDao) ListEnabledCached(ctx context.Context) ([]*entity.LifeTask, error) {
|
|
return common.GetList[entity.LifeTask](d.Model().Ctx(ctx).Cache(d.ContentCache(ctx)).
|
|
Where("status", consts.StatusEnabled).Order("id ASC"))
|
|
}
|
|
|
|
// ListAll 全部生活任务(含下架),按 id 排序。
|
|
func (d *lifeTaskDao) ListAll(ctx context.Context) ([]*entity.LifeTask, error) {
|
|
return common.GetList[entity.LifeTask](d.Model().Ctx(ctx).Order("id ASC"))
|
|
}
|