1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package dao
- import (
- "errors"
- "gorm.io/gorm"
- "time"
- "youngee_b_api/app/entity"
- )
- type SelectionInfoDAO struct{}
- func (d SelectionInfoDAO) GetSelectionInfoById(selectionId string) (*entity.SelectionInfo, error) {
- var selectionInfo entity.SelectionInfo
- err := Db.Where("selection_id = ?", selectionId).First(&selectionInfo).Error
- if err != nil {
- if errors.Is(err, gorm.ErrRecordNotFound) {
- return nil, nil
- } else {
- return nil, err
- }
- }
- return &selectionInfo, err
- }
- // 根据enterpriseId查询指定某天的所有带货数据
- func (d SelectionInfoDAO) GetSelectionInfoListOfDay(enterpriseId string, date time.Time) ([]entity.SelectionInfo, error) {
- var selectionInfos []entity.SelectionInfo
- // 构建查询
- query := Db.Model(&entity.SelectionInfo{})
- if enterpriseId != "" {
- query = query.Where("enterprise_id = ?", enterpriseId)
- }
- // 将日期部分提取出来进行匹配
- query = query.Where("DATE(created_at) = ?", date.Format("2006-01-02"))
- err := query.Find(&selectionInfos).Error
- return selectionInfos, err
- }
- func (d SelectionInfoDAO) CreateSelectionInfo(selectionInfo entity.SelectionInfo) error {
- err := Db.Omit("task_ddl", "submit_at", "pass_at", "pay_at", "finish_at", "auto_fail_at").Create(&selectionInfo).Error
- if err != nil {
- return err
- }
- return nil
- }
- func (d SelectionInfoDAO) UpdateSelectionInfo(selectionInfo entity.SelectionInfo) error {
- err := Db.Model(&entity.SelectionInfo{}).Where("selection_id = ?", selectionInfo.SelectionID).Updates(selectionInfo).Error
- if err != nil {
- return err
- }
- return nil
- }
|