123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- package db
- import (
- "context"
- "fmt"
- "github.com/caixw/lib.go/conv"
- "github.com/sirupsen/logrus"
- "strconv"
- "youngee_m_api/consts"
- "youngee_m_api/model/gorm_model"
- "youngee_m_api/model/http_model"
- )
- func SelectionReviewNumber(ctx context.Context) (*http_model.ReviewNums, error) {
- var reviewNums int64
- db := GetReadDB(ctx)
- err := db.Model(gorm_model.YounggeeSelectionInfo{}).Where("selection_status = 2").Count(&reviewNums).Error
- if err != nil {
- return nil, err
- }
- ReviewNums := new(http_model.ReviewNums)
- ReviewNums.ReviewNums = reviewNums
- return ReviewNums, err
- }
- func GetSelectionInfo(ctx context.Context, req *http_model.GetSelectionInfoRequest) (selectionInfoData http_model.SelectionInfoData, err error) {
- db := GetReadDB(ctx)
- db = db.Debug().Model(gorm_model.YounggeeSelectionInfo{}).Where("enterprise_id = ?", req.EnterpriseId)
- if req.UpdateAt != "" {
- db = db.Where(fmt.Sprintf("updated_at like '%s%%'", req.UpdateAt))
- }
- // 查询总数
- var total int64
- if err = db.Count(&total).Error; err != nil {
- logrus.WithContext(ctx).Errorf("[GetSelectionInfo] error query mysql total, err:%+v", err)
- return
- }
- var selectionInfos []*gorm_model.YounggeeSelectionInfo
- // 查询该页数据
- limit := req.PageSize
- offset := req.PageSize * req.PageNum // assert pageNum start with 0
- err = db.Order("updated_at desc").Limit(int(limit)).Offset(int(offset)).Find(&selectionInfos).Error
- if err != nil {
- logrus.WithContext(ctx).Errorf("[GetSelectionInfo] error query mysql limit, err:%+v", err)
- return
- }
- var selectionInfoPreviews []*http_model.SelectionInfoPreview
- for _, selectionInfo := range selectionInfos {
- selectionInfoPreview := new(http_model.SelectionInfoPreview)
- selectionInfoPreview.SelectionId = selectionInfo.SelectionID
- selectionInfoPreview.SelectionName = selectionInfo.SelectionName
- selectionInfoPreview.UpdateAt = conv.MustString(selectionInfo.UpdatedAt, "")[:19]
- selectionInfoPreview.TaskModel = consts.GetTaskModel(selectionInfo.TaskMode)
- selectionInfoPreview.SampleModel = consts.GetSampleModel(selectionInfo.SampleMode)
- selectionInfoPreviews = append(selectionInfoPreviews, selectionInfoPreview)
- }
- selectionInfoData.SelectionInfoPreview = selectionInfoPreviews
- selectionInfoData.Total = strconv.FormatInt(total, 10)
- return
- }
|