package mysql import ( "context" "database/sql" "errors" "hyapp/pkg/appcode" taskdomain "hyapp/services/activity-service/internal/domain/task" ) func (r *Repository) GetActiveTaskRewardAssetType(ctx context.Context, nowMS int64) (string, bool, error) { row := r.db.QueryRowContext(ctx, ` SELECT reward_asset_type FROM task_reward_policy_instances WHERE app_code = ? AND status = 'active' ORDER BY published_at_ms DESC, instance_code DESC LIMIT 1`, appcode.FromContext(ctx), ) var assetType string if err := row.Scan(&assetType); err != nil { if errors.Is(err, sql.ErrNoRows) { return "", false, nil } return "", false, err } return assetType, true, nil } func (r *Repository) PublishTaskRewardPolicy(ctx context.Context, command taskdomain.RewardPolicyCommand, nowMS int64) error { _, err := r.db.ExecContext(ctx, ` INSERT INTO task_reward_policy_instances ( app_code, instance_code, template_code, template_version, status, reward_asset_type, rule_json, published_by_admin_id, published_at_ms, created_at_ms, updated_at_ms ) VALUES (?, ?, ?, ?, ?, ?, CAST(? AS JSON), ?, ?, ?, ?) ON DUPLICATE KEY UPDATE template_code = VALUES(template_code), template_version = VALUES(template_version), status = VALUES(status), reward_asset_type = VALUES(reward_asset_type), rule_json = VALUES(rule_json), published_by_admin_id = VALUES(published_by_admin_id), published_at_ms = VALUES(published_at_ms), updated_at_ms = VALUES(updated_at_ms)`, appcode.FromContext(ctx), command.InstanceCode, command.TemplateCode, command.TemplateVersion, command.Status, command.RewardAssetType, command.RuleJSON, command.OperatorAdminID, command.PublishedAtMS, nowMS, nowMS, ) return err }