123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- package http
- import (
- "fmt"
- "go-common/app/admin/main/tv/model"
- "go-common/library/ecode"
- "go-common/library/log"
- bm "go-common/library/net/http/blademaster"
- )
- const (
- _jsonErr = "Incorrect Json Format"
- )
- func intervsRank(c *bm.Context) {
- var (
- form = new(model.RankListReq)
- request = new(model.IntervListReq)
- )
- if err := c.Bind(form); err != nil {
- return
- }
- request.FromRank(form)
- c.JSON(tvSrv.Intervs(request))
- }
- func intervsMod(c *bm.Context) {
- var (
- form = new(model.ModListReq)
- request = new(model.IntervListReq)
- )
- if err := c.Bind(form); err != nil {
- return
- }
- request.FromMod(form)
- c.JSON(tvSrv.Intervs(request))
- }
- func intervsIndex(c *bm.Context) {
- var (
- form = new(model.IdxListReq)
- request = new(model.IntervListReq)
- )
- if err := c.Bind(form); err != nil {
- return
- }
- request.FromIndex(form)
- c.JSON(tvSrv.Intervs(request))
- }
- func rankPub(c *bm.Context) {
- var (
- form = new(model.RankPubReq)
- req = new(model.IntervPubReq)
- )
- if err := c.Bind(form); err != nil {
- return
- }
- if err := req.FromRank(form); err != nil {
- renderErrMsg(c, ecode.RequestErr.Code(), _jsonErr)
- return
- }
- intervPublish(c, req)
- }
- func indexPub(c *bm.Context) {
- var (
- form = new(model.IdxPubReq)
- req = new(model.IntervPubReq)
- )
- if err := c.Bind(form); err != nil {
- return
- }
- if err := req.FromIndex(form); err != nil {
- renderErrMsg(c, ecode.RequestErr.Code(), _jsonErr)
- return
- }
- intervPublish(c, req)
- }
- func modPub(c *bm.Context) {
- var (
- form = new(model.ModPubReq)
- req = new(model.IntervPubReq)
- )
- if err := c.Bind(form); err != nil {
- return
- }
- if err := req.FromMod(form); err != nil {
- renderErrMsg(c, ecode.RequestErr.Code(), _jsonErr)
- return
- }
- intervPublish(c, req)
- }
- // combine the alert msg for too many interventions and cut the slice
- func alertMsg(items []*model.SimpleRank, nbLimit int) (msg string, restItems []*model.SimpleRank) {
- var (
- length = len(items)
- )
- if length <= nbLimit {
- return "", items
- }
- msg = "以下内容因超量未发布干预:"
- for i := nbLimit; i < length; i++ {
- if i+1 == length {
- msg = msg + fmt.Sprintf("id%d", items[i].ContID)
- continue
- }
- msg = msg + fmt.Sprintf("id%d,", items[i].ContID)
- }
- return msg, items[:nbLimit]
- }
- func intervPublish(c *bm.Context, req *model.IntervPubReq) {
- var (
- err error
- invalid *model.RankError
- alertInfo string // used when too many interventions published
- )
- alertInfo, req.Items = alertMsg(req.Items, tvSrv.IntervLimit) // too many intervention treatment
- invalid, err = tvSrv.RefreshIntervs(req)
- if err != nil {
- log.Error("RefreshIntervs Error %v", err)
- c.JSON(nil, err)
- return
- }
- if invalid != nil {
- renderErrMsg(c, ecode.RequestErr.Code(), fmt.Sprintf("发布失败,以下内容状态错误:id%d", invalid.SeasonID))
- return
- }
- if alertInfo != "" {
- renderErrMsg(c, ecode.OK.Code(), alertInfo)
- return
- }
- renderErrMsg(c, ecode.OK.Code(), "发布成功")
- }
|