You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
2.8 KiB
127 lines
2.8 KiB
package notice |
|
|
|
import ( |
|
"server/call" |
|
"server/common" |
|
"server/db" |
|
"server/modules/backend/app" |
|
"server/modules/backend/values" |
|
"server/natsClient" |
|
"server/pb" |
|
|
|
"github.com/gin-gonic/gin" |
|
"github.com/liangdas/mqant/log" |
|
) |
|
|
|
// 添加广播 |
|
func AddBroadcast(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.AddAddBroadcastReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
|
|
if len(req.List) <= 0 { |
|
a.Code = values.CodeParam |
|
return |
|
} |
|
|
|
err := db.Mysql().C().Model(&common.SheetBroadcastConfig{}).CreateInBatches(&req.List, len(req.List)).Error |
|
if err != nil { |
|
log.Error(err.Error()) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
|
|
err = call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: common.ReloadBroadcast}) |
|
if err != nil { |
|
log.Error(err.Error()) |
|
} |
|
} |
|
|
|
// 获取广播 |
|
func GetBroadcast(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.GetBroadcastReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
|
|
var SheetBroadcastConfig []common.SheetBroadcastConfig |
|
_, err := db.Mysql().QueryAll("", "", &common.SheetBroadcastConfig{}, &SheetBroadcastConfig) |
|
if err != nil { |
|
log.Error(err.Error()) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
|
|
a.Data = SheetBroadcastConfig |
|
} |
|
|
|
// 编辑广播 |
|
func EditBroadcast(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.EditBroadcastReq) |
|
if !a.S(req) { |
|
a.Code = values.CodeParam |
|
return |
|
} |
|
|
|
err := db.Mysql().C().Model(&common.SheetBroadcastConfig{}).Where("id = ?", req.Id).Updates(map[string]interface{}{ |
|
"content": req.Broadcast.Content, |
|
"amount": req.Broadcast.Amount, |
|
"display_location": req.Broadcast.DisplayLocation, |
|
"event": req.Broadcast.Event, |
|
"radio_id": req.Broadcast.RadioId, |
|
"target_id": req.Broadcast.TargetID, |
|
"type": req.Broadcast.Type, |
|
"priority": req.Broadcast.Priority, |
|
"loop_frequency": req.Broadcast.LoopFrequency, |
|
"interval": req.Broadcast.Interval, |
|
"generation_type": req.Broadcast.GenerationType, |
|
"is_release": req.Broadcast.IsRelease, |
|
}).Error |
|
if err != nil { |
|
log.Error(err.Error()) |
|
a.Code = values.CodeParam |
|
return |
|
} |
|
|
|
err = call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: common.ReloadBroadcast}) |
|
if err != nil { |
|
log.Error(err.Error()) |
|
} |
|
} |
|
|
|
// 删除广播 |
|
func DeleteBroadcast(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.DeleteBroadcastReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
|
|
err := db.Mysql().C().Where("id = ?", req.Id).Unscoped().Delete(&common.SheetBroadcastConfig{}).Error |
|
if err != nil { |
|
log.Error(err.Error()) |
|
a.Code = values.CodeParam |
|
return |
|
} |
|
|
|
err = call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: common.ReloadBroadcast}) |
|
if err != nil { |
|
log.Error(err.Error()) |
|
} |
|
}
|
|
|