worksapce.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package db
  2. import (
  3. "context"
  4. "errors"
  5. "github.com/sirupsen/logrus"
  6. "gorm.io/gorm"
  7. "time"
  8. "youngee_m_api/model/gorm_model"
  9. )
  10. // 根据enterpriseId查询指定某天的所有带货数据
  11. func GetSelectionInfoListOfDay(ctx context.Context, enterpriseId string, date time.Time) ([]gorm_model.YounggeeSelectionInfo, error) {
  12. db := GetWriteDB(ctx)
  13. var selectionInfos []gorm_model.YounggeeSelectionInfo
  14. query := db.Model(&gorm_model.YounggeeSelectionInfo{})
  15. // 构建查询条件
  16. if enterpriseId != "" {
  17. query = query.Where("enterprise_id = ?", enterpriseId)
  18. }
  19. // 将日期部分提取出来进行匹配
  20. query = query.Where("DATE(created_at) = ?", date.Format("2006-01-02"))
  21. // 执行查询
  22. result := query.Find(&selectionInfos)
  23. if result.Error != nil {
  24. if errors.Is(result.Error, gorm.ErrRecordNotFound) {
  25. return nil, nil
  26. }
  27. logrus.WithContext(ctx).Errorf("[GetSelectionInfoListOfDay] error query mysql takegoodsdata, err:%+v", result.Error)
  28. return nil, result.Error
  29. }
  30. return selectionInfos, nil
  31. }
  32. func CountBySelectionId(ctx context.Context, selectionId string) (int64, error) {
  33. var count int64
  34. db := GetWriteDB(ctx)
  35. err := db.Model(&gorm_model.YounggeeSecTaskInfo{}).Where("selection_id = ?", selectionId).Count(&count).Error
  36. return count, err
  37. }