12345678910111213141516171819202122232425262728293031323334353637383940 |
- package db
- import (
- "context"
- "time"
- "youngee_b_api/model/gorm_model"
- "github.com/sirupsen/logrus"
- )
- func CreateTaskLog(ctx context.Context, taskId string, log string) error {
- db := GetReadDB(ctx)
- taskLog := gorm_model.YounggeeTaskLog{
- TaskID: taskId,
- Content: log,
- LogAt: time.Now(),
- }
- err := db.Model(gorm_model.YounggeeTaskLog{}).Create(&taskLog).Error
- if err != nil {
- logrus.WithContext(ctx).Errorf("[Sketch db] Insert YounggeeTaskLog error,err:%+v", err)
- return err
- }
- return nil
- }
- // GetTaskLogsByTaskId 获取达人日志
- func GetTaskLogsByTaskId(ctx context.Context, taskId string) ([]*gorm_model.YounggeeTaskLog, int64, error) {
- db := GetReadDB(ctx)
- var total int64
- var taskLogs []*gorm_model.YounggeeTaskLog
- whereCondition := gorm_model.YounggeeTaskLog{TaskID: taskId}
- err := db.Model(gorm_model.YounggeeTaskLog{}).Where(whereCondition).Find(&taskLogs).Count(&total).Error
- if err != nil {
- return nil, 0, err
- }
- if total == 0 {
- return nil, 0, err
- }
- return taskLogs, total, nil
- }
|