From 33cb945846604a5962826caed378b2bee8c8543c Mon Sep 17 00:00:00 2001 From: lmk <1095689763@qq.com> Date: Tue, 21 Apr 2026 13:31:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/data/anchor_dao.go | 14 +++++--- dao/data/live_account_dao.go | 14 +++++--- dao/data/schedule_dao.go | 52 ++++++++++++++++++++++++++++++ main.go | 1 - model/dto/data/anchor_dto.go | 11 ++++--- model/dto/data/live_account_dto.go | 11 ++++--- model/dto/data/schedule_dto.go | 43 ++++++++++++------------ service/data/schedule_service.go | 20 +++++++----- 8 files changed, 119 insertions(+), 47 deletions(-) diff --git a/dao/data/anchor_dao.go b/dao/data/anchor_dao.go index 5d44bf3..c355a62 100644 --- a/dao/data/anchor_dao.go +++ b/dao/data/anchor_dao.go @@ -85,11 +85,17 @@ func (d *anchorDao) buildListFilter(ctx context.Context, req *dto.ListAnchorReq) 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 !g.IsEmpty(req.Name) { + model.WhereLike(entity.AnchorCols.Name, "%"+req.Name+"%") + } + if !g.IsEmpty(req.Phone) { + model.WhereLike(entity.AnchorCols.Phone, "%"+req.Phone+"%") + } + if !g.IsEmpty(req.Code) { + model.WhereLike(entity.AnchorCols.Code, "%"+req.Code+"%") + } if req.Status != nil { - model.Where(entity.AnchorCols.Status, *req.Status) + model.Where("status = ?", *req.Status) } model.OmitEmptyWhere() return model diff --git a/dao/data/live_account_dao.go b/dao/data/live_account_dao.go index f5aae1b..9bc61c7 100644 --- a/dao/data/live_account_dao.go +++ b/dao/data/live_account_dao.go @@ -85,11 +85,17 @@ func (d *liveAccountDao) buildListFilter(ctx context.Context, req *dto.ListLiveA 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 !g.IsEmpty(req.Platform) { + model.WhereLike(entity.LiveAccountCols.Platform, "%"+req.Platform+"%") + } + if !g.IsEmpty(req.AccountName) { + model.WhereLike(entity.LiveAccountCols.AccountName, "%"+req.AccountName+"%") + } + if !g.IsEmpty(req.AccountId) { + model.WhereLike(entity.LiveAccountCols.AccountId, "%"+req.AccountId+"%") + } if req.Status != nil { - model.Where(entity.LiveAccountCols.Status, *req.Status) + model.Where("status = ?", *req.Status) } model.OmitEmptyWhere() return model diff --git a/dao/data/schedule_dao.go b/dao/data/schedule_dao.go index 9665db9..a1b5061 100644 --- a/dao/data/schedule_dao.go +++ b/dao/data/schedule_dao.go @@ -95,9 +95,61 @@ func (d *scheduleDao) buildListFilter(ctx context.Context, req *dto.ListSchedule if !req.EndDate.IsZero() { model.WhereLTE(entity.ScheduleCols.StartTime, req.EndDate.Format("2006-01-02")+" 23:59:59") } + // 根据主播名字模糊查询 + if req.AnchorName != "" { + anchorIds, _ := d.getAnchorIdsByName(ctx, req.AnchorName) + if len(anchorIds) > 0 { + model.WhereIn(entity.ScheduleCols.AnchorId, anchorIds) + } else { + // 如果没有匹配的主播,返回空结果 + model.Where("1=0") + } + } + // 根据直播账号名字模糊查询 + if req.AccountName != "" { + accountIds, _ := d.getAccountIdsByName(ctx, req.AccountName) + if len(accountIds) > 0 { + model.WhereIn(entity.ScheduleCols.AccountId, accountIds) + } else { + // 如果没有匹配的账号,返回空结果 + model.Where("1=0") + } + } return model } +// getAnchorIdsByName 根据主播名字模糊查询获取主播ID列表 +func (d *scheduleDao) getAnchorIdsByName(ctx context.Context, name string) ([]interface{}, error) { + r, err := gfdb.DB(ctx).Model(ctx, consts.AnchorTable). + WhereLike("name", "%"+name+"%"). + Fields("id"). + All() + if err != nil { + return nil, err + } + ids := make([]interface{}, 0) + for _, record := range r { + ids = append(ids, record["id"]) + } + return ids, nil +} + +// getAccountIdsByName 根据直播账号名字模糊查询获取账号ID列表 +func (d *scheduleDao) getAccountIdsByName(ctx context.Context, name string) ([]interface{}, error) { + r, err := gfdb.DB(ctx).Model(ctx, consts.LiveAccountTable). + WhereLike("account_name", "%"+name+"%"). + Fields("id"). + All() + if err != nil { + return nil, err + } + ids := make([]interface{}, 0) + for _, record := range r { + ids = append(ids, record["id"]) + } + return ids, nil +} + // 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). diff --git a/main.go b/main.go index 9f2b248..4828c3c 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,6 @@ import ( "gitea.com/red-future/common/http" "gitea.com/red-future/common/jaeger" - _ "gitea.com/red-future/common/ragflow" // RAGFlow 客户端自动初始化 _ "github.com/gogf/gf/contrib/drivers/mysql/v2" _ "github.com/gogf/gf/contrib/drivers/pgsql/v2" _ "github.com/gogf/gf/contrib/nosql/redis/v2" diff --git a/model/dto/data/anchor_dto.go b/model/dto/data/anchor_dto.go index 5216c74..1a759f6 100644 --- a/model/dto/data/anchor_dto.go +++ b/model/dto/data/anchor_dto.go @@ -20,13 +20,14 @@ type CreateAnchorReq struct { // CreateAnchorRes 创建主播响应 type CreateAnchorRes struct { - Id int64 `json:"id" dc:"主播ID"` + Id int64 `json:"id,string" dc:"主播ID"` } // ListAnchorReq 获取主播列表请求 type ListAnchorReq struct { g.Meta `path:"/listAnchors" method:"get" tags:"主播管理" summary:"获取主播列表" dc:"分页查询主播列表"` *beans.Page + Id int64 `json:"id,string" dc:"主播ID"` Name string `json:"name" dc:"主播姓名"` Phone string `json:"phone" dc:"联系电话"` Code string `json:"code" dc:"工号"` @@ -56,7 +57,7 @@ type AnchorItem struct { // GetAnchorReq 获取主播详情请求 type GetAnchorReq struct { g.Meta `path:"/getAnchor" method:"get" tags:"主播管理" summary:"获取主播详情" dc:"获取主播详情"` - Id int64 `json:"id" v:"required" dc:"主播ID"` + Id int64 `json:"id,string" v:"required" dc:"主播ID"` } // GetAnchorRes 获取主播详情响应 @@ -67,7 +68,7 @@ type GetAnchorRes struct { // UpdateAnchorReq 更新主播请求 type UpdateAnchorReq struct { g.Meta `path:"/updateAnchor" method:"put" tags:"主播管理" summary:"更新主播" dc:"更新主播信息"` - Id int64 `json:"id" v:"required" dc:"主播ID"` + Id int64 `json:"id,string" v:"required" dc:"主播ID"` Name string `json:"name" dc:"主播姓名"` Phone string `json:"phone" dc:"联系电话"` Code string `json:"code" dc:"工号"` @@ -78,12 +79,12 @@ type UpdateAnchorReq struct { // DeleteAnchorReq 删除主播请求 type DeleteAnchorReq struct { g.Meta `path:"/deleteAnchor" method:"delete" tags:"主播管理" summary:"删除主播" dc:"删除主播"` - Id int64 `json:"id" v:"required" dc:"主播ID"` + Id int64 `json:"id,string" v:"required" dc:"主播ID"` } // UpdateAnchorStatusReq 更新主播状态请求 type UpdateAnchorStatusReq struct { g.Meta `path:"/updateAnchorStatus" method:"put" tags:"主播管理" summary:"更新主播状态" dc:"更新主播状态"` - Id int64 `json:"id" v:"required" dc:"主播ID"` + Id int64 `json:"id,string" v:"required" dc:"主播ID"` Status data.AnchorStatus `json:"status" v:"required" dc:"状态(0停用 1正常)"` } diff --git a/model/dto/data/live_account_dto.go b/model/dto/data/live_account_dto.go index 7af9cfe..53dbe9b 100644 --- a/model/dto/data/live_account_dto.go +++ b/model/dto/data/live_account_dto.go @@ -20,13 +20,14 @@ type CreateLiveAccountReq struct { // CreateLiveAccountRes 创建直播账号响应 type CreateLiveAccountRes struct { - Id int64 `json:"id" dc:"账号ID"` + Id int64 `json:"id,string" dc:"账号ID"` } // ListLiveAccountReq 获取直播账号列表请求 type ListLiveAccountReq struct { g.Meta `path:"/listLiveAccounts" method:"get" tags:"直播账号管理" summary:"获取直播账号列表" dc:"分页查询直播账号列表"` *beans.Page + Id int64 `json:"id,string" dc:"账号ID"` Platform string `json:"platform" dc:"直播平台"` AccountName string `json:"accountName" dc:"账号名称"` AccountId string `json:"accountId" dc:"账号ID"` @@ -56,7 +57,7 @@ type LiveAccountItem struct { // GetLiveAccountReq 获取直播账号详情请求 type GetLiveAccountReq struct { g.Meta `path:"/getLiveAccount" method:"get" tags:"直播账号管理" summary:"获取直播账号详情" dc:"获取直播账号详情"` - Id int64 `json:"id" v:"required" dc:"账号ID"` + Id int64 `json:"id,string" v:"required" dc:"账号ID"` } // GetLiveAccountRes 获取直播账号详情响应 @@ -67,7 +68,7 @@ type GetLiveAccountRes struct { // UpdateLiveAccountReq 更新直播账号请求 type UpdateLiveAccountReq struct { g.Meta `path:"/updateLiveAccount" method:"put" tags:"直播账号管理" summary:"更新直播账号" dc:"更新直播账号信息"` - Id int64 `json:"id" v:"required" dc:"账号ID"` + Id int64 `json:"id,string" v:"required" dc:"账号ID"` Platform string `json:"platform" dc:"直播平台"` AccountName string `json:"accountName" dc:"账号名称"` AccountId string `json:"accountId" dc:"账号ID"` @@ -78,12 +79,12 @@ type UpdateLiveAccountReq struct { // DeleteLiveAccountReq 删除直播账号请求 type DeleteLiveAccountReq struct { g.Meta `path:"/deleteLiveAccount" method:"delete" tags:"直播账号管理" summary:"删除直播账号" dc:"删除直播账号"` - Id int64 `json:"id" v:"required" dc:"账号ID"` + Id int64 `json:"id,string" v:"required" dc:"账号ID"` } // UpdateLiveAccountStatusReq 更新直播账号状态请求 type UpdateLiveAccountStatusReq struct { g.Meta `path:"/updateLiveAccountStatus" method:"put" tags:"直播账号管理" summary:"更新直播账号状态" dc:"更新直播账号状态"` - Id int64 `json:"id" v:"required" dc:"账号ID"` + Id int64 `json:"id,string" v:"required" dc:"账号ID"` Status data.AnchorStatus `json:"status" v:"required" dc:"状态(0停用 1正常)"` } diff --git a/model/dto/data/schedule_dto.go b/model/dto/data/schedule_dto.go index 051aebf..32ef6fa 100644 --- a/model/dto/data/schedule_dto.go +++ b/model/dto/data/schedule_dto.go @@ -12,30 +12,33 @@ import ( // CreateScheduleReq 创建排班请求 type CreateScheduleReq struct { g.Meta `path:"/createSchedule" method:"post" tags:"排班管理" summary:"创建排班" dc:"创建新的排班"` - AnchorId int `json:"anchorId" v:"required" dc:"主播ID"` - AccountId int `json:"accountId" v:"required" dc:"直播账号ID"` + AnchorId int `json:"anchorId,string" v:"required" dc:"主播ID"` + AccountId int `json:"accountId,string" v:"required" dc:"直播账号ID"` StartTime time.Time `json:"startTime" v:"required" dc:"开始时间"` EndTime time.Time `json:"endTime" v:"required" dc:"结束时间"` Status int `json:"status" d:"0" dc:"状态(0待直播 1直播中 2已结束 3已取消)"` - ProductId int64 `json:"productId" dc:"商品ID"` - OrderId int64 `json:"orderId" dc:"订单ID"` + ProductId int64 `json:"productId,string" dc:"商品ID"` + OrderId int64 `json:"orderId,string" dc:"订单ID"` Remark string `json:"remark" dc:"备注"` } // CreateScheduleRes 创建排班响应 type CreateScheduleRes struct { - Id int64 `json:"id" dc:"排班ID"` + Id int64 `json:"id,string" dc:"排班ID"` } // ListScheduleReq 获取排班列表请求 type ListScheduleReq struct { g.Meta `path:"/listSchedules" method:"get" tags:"排班管理" summary:"获取排班列表" dc:"分页查询排班列表"` *beans.Page - AnchorId *int `json:"anchorId" dc:"主播ID"` - AccountId *int `json:"accountId" dc:"直播账号ID"` - Status *int `json:"status" dc:"状态"` - StartDate time.Time `json:"startDate" dc:"开始日期(筛选)"` - EndDate time.Time `json:"endDate" dc:"结束日期(筛选)"` + Id int64 `json:"id,string" dc:"排班ID"` + AnchorId *int `json:"anchorId" dc:"主播ID"` + AnchorName string `json:"anchorName" dc:"主播名字(模糊查询)"` + AccountId *int `json:"accountId" dc:"直播账号ID"` + AccountName string `json:"accountName" dc:"直播账号名字(模糊查询)"` + Status *int `json:"status" dc:"状态"` + StartDate time.Time `json:"startDate" dc:"开始日期(筛选)"` + EndDate time.Time `json:"endDate" dc:"结束日期(筛选)"` } // ListScheduleRes 获取排班列表响应 @@ -47,17 +50,17 @@ type ListScheduleRes struct { // ScheduleItem 排班列表项 type ScheduleItem struct { Id int64 `json:"id,string"` - AnchorId int `json:"anchorId"` + AnchorId int `json:"anchorId,string"` AnchorName string `json:"anchorName"` - AccountId int `json:"accountId"` + AccountId int `json:"accountId,string"` AccountName string `json:"accountName"` Platform string `json:"platform"` StartTime int64 `json:"startTime"` EndTime int64 `json:"endTime"` Status int `json:"status"` StatusName string `json:"statusName"` - ProductId int64 `json:"productId"` - OrderId int64 `json:"orderId"` + ProductId int64 `json:"productId,string"` + OrderId int64 `json:"orderId,string"` Remark string `json:"remark"` CreatedAt int64 `json:"createdAt"` UpdatedAt int64 `json:"updatedAt"` @@ -66,7 +69,7 @@ type ScheduleItem struct { // GetScheduleReq 获取排班详情请求 type GetScheduleReq struct { g.Meta `path:"/getSchedule" method:"get" tags:"排班管理" summary:"获取排班详情" dc:"获取排班详情"` - Id int64 `json:"id" v:"required" dc:"排班ID"` + Id int64 `json:"id,string" v:"required" dc:"排班ID"` } // GetScheduleRes 获取排班详情响应 @@ -77,9 +80,9 @@ type GetScheduleRes struct { // UpdateScheduleReq 更新排班请求 type UpdateScheduleReq struct { g.Meta `path:"/updateSchedule" method:"put" tags:"排班管理" summary:"更新排班" dc:"更新排班信息"` - Id int64 `json:"id" v:"required" dc:"排班ID"` - AnchorId *int `json:"anchorId" dc:"主播ID"` - AccountId *int `json:"accountId" dc:"直播账号ID"` + Id int64 `json:"id,string" v:"required" dc:"排班ID"` + AnchorId *int `json:"anchorId,string" dc:"主播ID"` + AccountId *int `json:"accountId,string" dc:"直播账号ID"` StartTime *time.Time `json:"startTime" dc:"开始时间"` EndTime *time.Time `json:"endTime" dc:"结束时间"` Status *int `json:"status" dc:"状态(0待直播 1直播中 2已结束 3已取消)"` @@ -91,12 +94,12 @@ type UpdateScheduleReq struct { // DeleteScheduleReq 删除排班请求 type DeleteScheduleReq struct { g.Meta `path:"/deleteSchedule" method:"delete" tags:"排班管理" summary:"删除排班" dc:"删除排班"` - Id int64 `json:"id" v:"required" dc:"排班ID"` + Id int64 `json:"id,string" v:"required" dc:"排班ID"` } // UpdateScheduleStatusReq 更新排班状态请求 type UpdateScheduleStatusReq struct { g.Meta `path:"/updateScheduleStatus" method:"put" tags:"排班管理" summary:"更新排班状态" dc:"更新排班状态"` - Id int64 `json:"id" v:"required" dc:"排班ID"` + Id int64 `json:"id,string" v:"required" dc:"排班ID"` Status data.ScheduleStatus `json:"status" v:"required" dc:"状态(0待直播 1直播中 2已结束 3已取消)"` } diff --git a/service/data/schedule_service.go b/service/data/schedule_service.go index 494f0fa..7aead89 100644 --- a/service/data/schedule_service.go +++ b/service/data/schedule_service.go @@ -68,22 +68,26 @@ func (s *scheduleService) List(ctx context.Context, req *dto.ListScheduleReq) (r for _, item := range scheduleList { // 获取主播信息 anchorName := "" - anchor, _ := dao.Anchor.GetOne(ctx, &dto.GetAnchorReq{Id: int64(item.AnchorId)}) - if anchor != nil { - anchorName = anchor.Name + if item.AnchorId > 0 { + anchor, _ := dao.Anchor.GetOne(ctx, &dto.GetAnchorReq{Id: int64(item.AnchorId)}) + if anchor != nil { + anchorName = anchor.Name + } } // 获取账号信息 accountName := "" platform := "" - account, _ := dao.LiveAccount.GetOne(ctx, &dto.GetLiveAccountReq{Id: int64(item.AccountId)}) - if account != nil { - accountName = account.AccountName - platform = account.Platform + if item.AccountId > 0 { + account, _ := dao.LiveAccount.GetOne(ctx, &dto.GetLiveAccountReq{Id: int64(item.AccountId)}) + if account != nil { + accountName = account.AccountName + platform = account.Platform + } } list = append(list, dto.ScheduleItem{ - Id: item.Id, + Id: int64(item.Id), AnchorId: item.AnchorId, AnchorName: anchorName, AccountId: item.AccountId,