排班管理、主播管理、直播账号管理
This commit is contained in:
120
dao/data/anchor_dao.go
Normal file
120
dao/data/anchor_dao.go
Normal file
@@ -0,0 +1,120 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"context"
|
||||
consts "erp/consts/public"
|
||||
dto "erp/model/dto/data"
|
||||
entity "erp/model/entity/data"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var Anchor = new(anchorDao)
|
||||
|
||||
type anchorDao struct{}
|
||||
|
||||
// Insert 插入主播
|
||||
func (d *anchorDao) Insert(ctx context.Context, req *dto.CreateAnchorReq) (id int64, err error) {
|
||||
var res *entity.Anchor
|
||||
if err = gconv.Struct(req, &res); err != nil {
|
||||
return
|
||||
}
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.AnchorTable).Data(&res).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
// Update 更新主播
|
||||
func (d *anchorDao) Update(ctx context.Context, req *dto.UpdateAnchorReq) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.AnchorTable).Data(&req).OmitEmpty().Where(entity.AnchorCols.Id, req.Id).Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// Delete 删除主播
|
||||
func (d *anchorDao) Delete(ctx context.Context, req *dto.DeleteAnchorReq) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.AnchorTable).Where(entity.AnchorCols.Id, req.Id).Delete()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// GetOne 获取单个主播
|
||||
func (d *anchorDao) GetOne(ctx context.Context, req *dto.GetAnchorReq) (res *entity.Anchor, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.AnchorTable).Where(entity.AnchorCols.Id, req.Id).One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// Count 获取主播数量
|
||||
func (d *anchorDao) Count(ctx context.Context, req *dto.ListAnchorReq) (count int, err error) {
|
||||
return d.buildListFilter(ctx, req).Count()
|
||||
}
|
||||
|
||||
// List 获取主播列表
|
||||
func (d *anchorDao) List(ctx context.Context, req *dto.ListAnchorReq) (res []entity.Anchor, total int, err error) {
|
||||
model := d.buildListFilter(ctx, req)
|
||||
model.OrderDesc(entity.AnchorCols.CreatedAt)
|
||||
if req.Page != nil {
|
||||
model.Page(int(req.Page.PageNum), int(req.Page.PageSize))
|
||||
}
|
||||
r, total, err := model.AllAndCount(false)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Structs(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// buildListFilter 构建列表查询的过滤条件
|
||||
func (d *anchorDao) buildListFilter(ctx context.Context, req *dto.ListAnchorReq) *gdb.Model {
|
||||
model := gfdb.DB(ctx).Model(ctx, consts.AnchorTable).Model
|
||||
if !g.IsEmpty(req.Keyword) {
|
||||
model.WhereLike(entity.AnchorCols.Name, "%"+req.Keyword+"%").
|
||||
WhereOrLike(entity.AnchorCols.Phone, "%"+req.Keyword+"%").
|
||||
WhereOrLike(entity.AnchorCols.Code, "%"+req.Keyword+"%")
|
||||
}
|
||||
model.Where(entity.AnchorCols.Name, req.Name)
|
||||
model.Where(entity.AnchorCols.Phone, req.Phone)
|
||||
model.Where(entity.AnchorCols.Code, req.Code)
|
||||
if req.Status != nil {
|
||||
model.Where(entity.AnchorCols.Status, *req.Status)
|
||||
}
|
||||
model.OmitEmptyWhere()
|
||||
return model
|
||||
}
|
||||
|
||||
// UpdateStatus 更新主播状态
|
||||
func (d *anchorDao) UpdateStatus(ctx context.Context, id int64, status int) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.AnchorTable).
|
||||
Data(map[string]interface{}{"status": status}).
|
||||
Where(entity.AnchorCols.Id, id).
|
||||
Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// GetByCode 根据工号获取主播
|
||||
func (d *anchorDao) GetByCode(ctx context.Context, code string) (res *entity.Anchor, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.AnchorTable).
|
||||
Where(entity.AnchorCols.Code, code).
|
||||
One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&res)
|
||||
return
|
||||
}
|
||||
120
dao/data/live_account_dao.go
Normal file
120
dao/data/live_account_dao.go
Normal file
@@ -0,0 +1,120 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"context"
|
||||
consts "erp/consts/public"
|
||||
dto "erp/model/dto/data"
|
||||
entity "erp/model/entity/data"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var LiveAccount = new(liveAccountDao)
|
||||
|
||||
type liveAccountDao struct{}
|
||||
|
||||
// Insert 插入直播账号
|
||||
func (d *liveAccountDao) Insert(ctx context.Context, req *dto.CreateLiveAccountReq) (id int64, err error) {
|
||||
var res *entity.LiveAccount
|
||||
if err = gconv.Struct(req, &res); err != nil {
|
||||
return
|
||||
}
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.LiveAccountTable).Data(&res).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
// Update 更新直播账号
|
||||
func (d *liveAccountDao) Update(ctx context.Context, req *dto.UpdateLiveAccountReq) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.LiveAccountTable).Data(&req).OmitEmpty().Where(entity.LiveAccountCols.Id, req.Id).Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// Delete 删除直播账号
|
||||
func (d *liveAccountDao) Delete(ctx context.Context, req *dto.DeleteLiveAccountReq) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.LiveAccountTable).Where(entity.LiveAccountCols.Id, req.Id).Delete()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// GetOne 获取单个直播账号
|
||||
func (d *liveAccountDao) GetOne(ctx context.Context, req *dto.GetLiveAccountReq) (res *entity.LiveAccount, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.LiveAccountTable).Where(entity.LiveAccountCols.Id, req.Id).One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// Count 获取直播账号数量
|
||||
func (d *liveAccountDao) Count(ctx context.Context, req *dto.ListLiveAccountReq) (count int, err error) {
|
||||
return d.buildListFilter(ctx, req).Count()
|
||||
}
|
||||
|
||||
// List 获取直播账号列表
|
||||
func (d *liveAccountDao) List(ctx context.Context, req *dto.ListLiveAccountReq) (res []entity.LiveAccount, total int, err error) {
|
||||
model := d.buildListFilter(ctx, req)
|
||||
model.OrderDesc(entity.LiveAccountCols.CreatedAt)
|
||||
if req.Page != nil {
|
||||
model.Page(int(req.Page.PageNum), int(req.Page.PageSize))
|
||||
}
|
||||
r, total, err := model.AllAndCount(false)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Structs(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// buildListFilter 构建列表查询的过滤条件
|
||||
func (d *liveAccountDao) buildListFilter(ctx context.Context, req *dto.ListLiveAccountReq) *gdb.Model {
|
||||
model := gfdb.DB(ctx).Model(ctx, consts.LiveAccountTable).Model
|
||||
if !g.IsEmpty(req.Keyword) {
|
||||
model.WhereLike(entity.LiveAccountCols.Platform, "%"+req.Keyword+"%").
|
||||
WhereOrLike(entity.LiveAccountCols.AccountName, "%"+req.Keyword+"%").
|
||||
WhereOrLike(entity.LiveAccountCols.AccountId, "%"+req.Keyword+"%")
|
||||
}
|
||||
model.Where(entity.LiveAccountCols.Platform, req.Platform)
|
||||
model.Where(entity.LiveAccountCols.AccountName, req.AccountName)
|
||||
model.Where(entity.LiveAccountCols.AccountId, req.AccountId)
|
||||
if req.Status != nil {
|
||||
model.Where(entity.LiveAccountCols.Status, *req.Status)
|
||||
}
|
||||
model.OmitEmptyWhere()
|
||||
return model
|
||||
}
|
||||
|
||||
// UpdateStatus 更新直播账号状态
|
||||
func (d *liveAccountDao) UpdateStatus(ctx context.Context, id int64, status int) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.LiveAccountTable).
|
||||
Data(map[string]interface{}{"status": status}).
|
||||
Where(entity.LiveAccountCols.Id, id).
|
||||
Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// GetByAccountId 根据账号ID获取直播账号
|
||||
func (d *liveAccountDao) GetByAccountId(ctx context.Context, accountId string) (res *entity.LiveAccount, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.LiveAccountTable).
|
||||
Where(entity.LiveAccountCols.AccountId, accountId).
|
||||
One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&res)
|
||||
return
|
||||
}
|
||||
140
dao/data/schedule_dao.go
Normal file
140
dao/data/schedule_dao.go
Normal file
@@ -0,0 +1,140 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"context"
|
||||
consts "erp/consts/public"
|
||||
dto "erp/model/dto/data"
|
||||
entity "erp/model/entity/data"
|
||||
"time"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var Schedule = new(scheduleDao)
|
||||
|
||||
type scheduleDao struct{}
|
||||
|
||||
// Insert 插入排班
|
||||
func (d *scheduleDao) Insert(ctx context.Context, req *dto.CreateScheduleReq) (id int64, err error) {
|
||||
var res *entity.Schedule
|
||||
if err = gconv.Struct(req, &res); err != nil {
|
||||
return
|
||||
}
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.ScheduleTable).Data(&res).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
// Update 更新排班
|
||||
func (d *scheduleDao) Update(ctx context.Context, req *dto.UpdateScheduleReq) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.ScheduleTable).Data(&req).OmitEmpty().Where(entity.ScheduleCols.Id, req.Id).Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// Delete 删除排班
|
||||
func (d *scheduleDao) Delete(ctx context.Context, req *dto.DeleteScheduleReq) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.ScheduleTable).Where(entity.ScheduleCols.Id, req.Id).Delete()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// GetOne 获取单个排班
|
||||
func (d *scheduleDao) GetOne(ctx context.Context, req *dto.GetScheduleReq) (res *entity.Schedule, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.ScheduleTable).Where(entity.ScheduleCols.Id, req.Id).One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// Count 获取排班数量
|
||||
func (d *scheduleDao) Count(ctx context.Context, req *dto.ListScheduleReq) (count int, err error) {
|
||||
return d.buildListFilter(ctx, req).Count()
|
||||
}
|
||||
|
||||
// List 获取排班列表
|
||||
func (d *scheduleDao) List(ctx context.Context, req *dto.ListScheduleReq) (res []entity.Schedule, total int, err error) {
|
||||
model := d.buildListFilter(ctx, req)
|
||||
model.OrderDesc(entity.ScheduleCols.StartTime)
|
||||
if req.Page != nil {
|
||||
model.Page(int(req.Page.PageNum), int(req.Page.PageSize))
|
||||
}
|
||||
r, total, err := model.AllAndCount(false)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Structs(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// buildListFilter 构建列表查询的过滤条件
|
||||
func (d *scheduleDao) buildListFilter(ctx context.Context, req *dto.ListScheduleReq) *gdb.Model {
|
||||
model := gfdb.DB(ctx).Model(ctx, consts.ScheduleTable).Model
|
||||
if req.AnchorId != nil {
|
||||
model.Where(entity.ScheduleCols.AnchorId, *req.AnchorId)
|
||||
}
|
||||
if req.AccountId != nil {
|
||||
model.Where(entity.ScheduleCols.AccountId, *req.AccountId)
|
||||
}
|
||||
if req.Status != nil {
|
||||
model.Where(entity.ScheduleCols.Status, *req.Status)
|
||||
}
|
||||
if !req.StartDate.IsZero() {
|
||||
model.WhereGTE(entity.ScheduleCols.StartTime, req.StartDate.Format("2006-01-02")+" 00:00:00")
|
||||
}
|
||||
if !req.EndDate.IsZero() {
|
||||
model.WhereLTE(entity.ScheduleCols.StartTime, req.EndDate.Format("2006-01-02")+" 23:59:59")
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
// UpdateStatus 更新排班状态
|
||||
func (d *scheduleDao) UpdateStatus(ctx context.Context, id int64, status int) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.ScheduleTable).
|
||||
Data(map[string]interface{}{"status": status}).
|
||||
Where(entity.ScheduleCols.Id, id).
|
||||
Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// CheckTimeConflict 检查时间冲突
|
||||
func (d *scheduleDao) CheckTimeConflict(ctx context.Context, anchorId int, startTime, endTime time.Time, excludeId ...int64) (count int, err error) {
|
||||
model := gfdb.DB(ctx).Model(ctx, consts.ScheduleTable).
|
||||
Where(entity.ScheduleCols.AnchorId, anchorId).
|
||||
Where(entity.ScheduleCols.Status, 0). // 只检查待直播的排班
|
||||
WhereLT(entity.ScheduleCols.StartTime, endTime.Format("2006-01-02 15:04:05")).
|
||||
WhereGT(entity.ScheduleCols.EndTime, startTime.Format("2006-01-02 15:04:05"))
|
||||
|
||||
if len(excludeId) > 0 && excludeId[0] > 0 {
|
||||
model.WhereNot(entity.ScheduleCols.Id, excludeId[0])
|
||||
}
|
||||
|
||||
return model.Count()
|
||||
}
|
||||
|
||||
// GetByAnchorAndTime 根据主播和时间获取排班
|
||||
func (d *scheduleDao) GetByAnchorAndTime(ctx context.Context, anchorId int, startTime time.Time) (res *entity.Schedule, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.ScheduleTable).
|
||||
Where(entity.ScheduleCols.AnchorId, anchorId).
|
||||
WhereLTE(entity.ScheduleCols.StartTime, startTime.Format("2006-01-02 15:04:05")).
|
||||
WhereGTE(entity.ScheduleCols.EndTime, startTime.Format("2006-01-02 15:04:05")).
|
||||
One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&res)
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user