12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- package db
- import (
- "context"
- "errors"
- "github.com/sirupsen/logrus"
- "gorm.io/gorm"
- "time"
- "youngee_m_api/model/gorm_model"
- )
- // 根据enterpriseId查询指定某天的所有带货数据
- func GetSelectionInfoListOfDay(ctx context.Context, enterpriseId string, date time.Time) ([]gorm_model.YounggeeSelectionInfo, error) {
- db := GetWriteDB(ctx)
- var selectionInfos []gorm_model.YounggeeSelectionInfo
- query := db.Model(&gorm_model.YounggeeSelectionInfo{})
- // 构建查询条件
- if enterpriseId != "" {
- query = query.Where("enterprise_id = ?", enterpriseId)
- }
- // 将日期部分提取出来进行匹配
- query = query.Where("DATE(created_at) = ?", date.Format("2006-01-02"))
- // 执行查询
- result := query.Find(&selectionInfos)
- if result.Error != nil {
- if errors.Is(result.Error, gorm.ErrRecordNotFound) {
- return nil, nil
- }
- logrus.WithContext(ctx).Errorf("[GetSelectionInfoListOfDay] error query mysql takegoodsdata, err:%+v", result.Error)
- return nil, result.Error
- }
- return selectionInfos, nil
- }
- func CountBySelectionId(ctx context.Context, selectionId string) (int64, error) {
- var count int64
- db := GetWriteDB(ctx)
- err := db.Model(&gorm_model.YounggeeSecTaskInfo{}).Where("selection_id = ?", selectionId).Count(&count).Error
- return count, err
- }
|