12345678910111213141516171819202122232425262728293031323334353637 |
- package db
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "youngee_b_api/model/gorm_model"
- )
- // CreateProjectTaskLinkStatistic 创建一条统计记录
- func CreateProjectTaskLinkStatistic(ctx context.Context, stat *gorm_model.ProjectTaskLinkStatistic) error {
- // 基本校验
- if stat == nil {
- return errors.New("nil statistic data")
- }
- // 获取写数据库连接
- db := GetWriteDB(ctx)
- if db == nil {
- return errors.New("database connection not available")
- }
- // 设置默认时间
- if stat.CreateTime.IsZero() {
- var currentTime time.Time
- stat.CreateTime = ¤tTime
- }
- // 执行创建
- if err := db.WithContext(ctx).Create(stat).Error; err != nil {
- // 可以在这里添加特定错误处理
- return fmt.Errorf("failed to create statistic: %w", err)
- }
- return nil
- }
|