rts-sim-testing-service/service/publishedGi.go

66 lines
1.7 KiB
Go

package service
import (
"fmt"
"gorm.io/gorm/clause"
"joylink.club/bj-rtsts-server/db/dbquery"
"joylink.club/bj-rtsts-server/db/model"
"joylink.club/bj-rtsts-server/dto"
"time"
)
func PageQueryPublishedGi(req *dto.PublishedGiReqDto) (*dto.PageDto, error) {
where := dbquery.PublishedGi.Where()
if req.Name != "" {
where.Where(dbquery.PublishedGi.Name.Like(fmt.Sprintf("%%%s%%", req.Name)))
}
result, count, err := where.Debug().FindByPage(req.Offset(), req.Size)
return &dto.PageDto{
Total: int(count),
PageQueryDto: req.PageQueryDto,
Records: result,
}, err
}
func ListQueryPublishedGi(req *dto.PublishedGiReqDto) ([]*model.PublishedGi, error) {
where := dbquery.PublishedGi.Where()
if req.Name != "" {
where.Where(dbquery.PublishedGi.Name.Like(fmt.Sprintf("%%%s%%", req.Name)))
}
return where.Debug().Find()
}
func GetPublishedGiById(id int) (*model.PublishedGi, error) {
return dbquery.PublishedGi.Where(dbquery.PublishedGi.ID.Eq(int32(id))).Debug().First()
}
func PublishFormDraft(req *dto.PublishReqDto, user model.User) {
draft := QueryDrafting(req.DraftId)
if draft.Proto == nil || len(draft.Proto) == 0 {
panic(fmt.Sprintf("草稿[%v]绘图数据信息为空", req.DraftId))
}
entity := model.PublishedGi{
Name: req.Name,
Proto: draft.Proto,
UserID: user.ID,
PublishAt: time.Now(),
}
query := dbquery.PublishedGi.Debug()
if req.Overwrite {
query.Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "name"}},
UpdateAll: true,
})
} else {
query.Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "name"}},
})
}
_ = query.Create(&entity)
}
func DeletePublishedGiById(id int) {
_, _ = dbquery.PublishedGi.Debug().Where(dbquery.PublishedGi.ID.Eq(int32(id))).Delete()
}