|
@@ -89,6 +89,8 @@ func (s *publishLibrariesService) Create(program *dao.Program, req model.ReqProg
|
|
|
KsTime: req.KsTime,
|
|
|
JsTime: req.JsTime,
|
|
|
FileId: program.ID,
|
|
|
+ PlayTime: req.PlayTime,
|
|
|
+ PlayInterval: req.PlayInterval,
|
|
|
}
|
|
|
libraries.CreateTime = time.Now()
|
|
|
if err := libraries.Create(); err != nil {
|
|
@@ -212,6 +214,7 @@ func (s *publishLibrariesService) LedPaying(ledId int, playing string) string {
|
|
|
cltLedLibraries.Imageinfo.InEffect.Type = "2"
|
|
|
//cltLedLibraries.Imageinfo.InEffect.Time = strconv.Itoa(relations[0].Duration)
|
|
|
cltLedLibraries.Imageinfo.InEffect.Time = "1500"
|
|
|
+ fmt.Printf("cltLedLibraries = %v \n", cltLedLibraries)
|
|
|
marshal, err := json.Marshal(cltLedLibraries)
|
|
|
if err != nil {
|
|
|
fmt.Printf("LedPaying err = %v \n", err)
|
|
@@ -223,3 +226,141 @@ func (s *publishLibrariesService) LedPaying(ledId int, playing string) string {
|
|
|
//fmt.Printf("str = %v \n", str)
|
|
|
return str
|
|
|
}
|
|
|
+
|
|
|
+type iPCastPayingMp3Info struct {
|
|
|
+ Type int `json:"Type"`
|
|
|
+ PlayTimes int `json:"PlayTimes"`
|
|
|
+ FileIds []int `json:"FileIds"`
|
|
|
+ TermIds []int `json:"TermIds"`
|
|
|
+}
|
|
|
+
|
|
|
+type iPCastPayingContentInfo struct {
|
|
|
+ Content string `json:"Content"`
|
|
|
+ Playtime int `json:"Playtime"`
|
|
|
+ TermIds []int `json:"TermIds"`
|
|
|
+ PlayVol int `json:"PlayVol"`
|
|
|
+ PromptTone int `json:"PromptTone"`
|
|
|
+}
|
|
|
+
|
|
|
+func (s *publishLibrariesService) IPCastPaying(id int) (string, int) {
|
|
|
+ publishLibraries := dao.PublishLibraries{}
|
|
|
+ libraries, err := publishLibraries.GetProgramByIpCastId(id)
|
|
|
+ if err != nil {
|
|
|
+ logger.Logger.Errorf("IPCastPaying err = %v \n", err)
|
|
|
+ return "", 0
|
|
|
+ }
|
|
|
+ if len(libraries) < 1 {
|
|
|
+ //没有新节目不更新
|
|
|
+ return "", 0
|
|
|
+ }
|
|
|
+ //fmt.Printf("libraries = %v \n", libraries)
|
|
|
+ var librarie dao.PublishLibraries
|
|
|
+ //判断当前到底要放哪个节目
|
|
|
+ for _, library := range libraries {
|
|
|
+ library.Ptype = 1
|
|
|
+ if library.JsTime == "" {
|
|
|
+ library.Ptype = 0
|
|
|
+ }
|
|
|
+ if library.Ptype == 1 && library.JsTime != "" {
|
|
|
+ currTime := time.Now()
|
|
|
+ parse, err := time.Parse("2006-01-02 15:04", fmt.Sprintf("%v %v", time.Now().Format("2006-01-02"), library.JsTime))
|
|
|
+ if err != nil {
|
|
|
+ fmt.Printf("IPCastPaying parse err = %v \n", err)
|
|
|
+ logger.Logger.Errorf("IPCastPaying parse err = %v \n", err)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if parse.Before(currTime) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ cTime := time.Now()
|
|
|
+ kTime, err := time.Parse("2006-01-02 15:04", fmt.Sprintf("%v %v", time.Now().Format("2006-01-02"), library.KsTime))
|
|
|
+ if err != nil {
|
|
|
+ fmt.Printf("IPCastPaying kTime err = %v \n", err)
|
|
|
+ logger.Logger.Errorf("IPCastPaying kTime err = %v \n", err)
|
|
|
+ }
|
|
|
+ //这里要作限制 ,只有是当前时分 才操作
|
|
|
+ if cTime.Minute() != kTime.Minute() || cTime.Hour() == kTime.Hour() {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
+ librarie = library
|
|
|
+ }
|
|
|
+ //fmt.Printf("librarie = %v \n", librarie)
|
|
|
+ program, _ := s.GetProgram(int(librarie.ID))
|
|
|
+ relation := &dao.ProgramRelation{
|
|
|
+ ProgramId: program,
|
|
|
+ TenantId: librarie.TenantId,
|
|
|
+ }
|
|
|
+ relations, err := relation.GetByProgram()
|
|
|
+ if err != nil {
|
|
|
+ logger.Logger.Errorf("IPCastPaying err = %s \n", err)
|
|
|
+ return "", 0
|
|
|
+ }
|
|
|
+ var libraryIds []int
|
|
|
+ for _, relation := range relations {
|
|
|
+ libraryIds = append(libraryIds, relation.LibraryId)
|
|
|
+ }
|
|
|
+ library := &dao.Library{TenantId: librarie.TenantId}
|
|
|
+ getLibrariesByIds, _ := library.GetLibrariesByIds(libraryIds)
|
|
|
+ if len(getLibrariesByIds) < 1 {
|
|
|
+ logger.Logger.Errorf("无素材")
|
|
|
+ return "", 0
|
|
|
+ }
|
|
|
+ //fmt.Printf("getLibrariesByIds = %v \n", getLibrariesByIds)
|
|
|
+ // 音频播放
|
|
|
+ if librarie.Ptype == 1 {
|
|
|
+ paytime := diffTime(librarie.KsTime, librarie.JsTime)
|
|
|
+ if paytime < 0 {
|
|
|
+ logger.Logger.Errorf("播放时间出错啦")
|
|
|
+ return "", 0
|
|
|
+ }
|
|
|
+ fileIds := []int{}
|
|
|
+ for _, libs := range getLibrariesByIds {
|
|
|
+ fid, _ := strconv.Atoi(libs.FileId)
|
|
|
+ fileIds = append(fileIds, fid)
|
|
|
+ }
|
|
|
+ info := iPCastPayingMp3Info{
|
|
|
+ Type: 1,
|
|
|
+ PlayTimes: paytime,
|
|
|
+ FileIds: fileIds,
|
|
|
+ TermIds: []int{1, 2, 3, 4, 5, 6, 7, 8},
|
|
|
+ }
|
|
|
+ marshal, err := json.Marshal(info)
|
|
|
+ if err != nil {
|
|
|
+ logger.Logger.Errorf("IPCastPaying iPCastPayingMp3Info err = %v \n", err)
|
|
|
+ return "", 0
|
|
|
+ }
|
|
|
+ return string(marshal), librarie.Ptype
|
|
|
+ //文字播放
|
|
|
+ } else {
|
|
|
+ contentInfo := iPCastPayingContentInfo{
|
|
|
+ Content: getLibrariesByIds[0].MaterialAddress,
|
|
|
+ Playtime: librarie.PlayTime,
|
|
|
+ TermIds: []int{1, 2, 3, 4, 5, 6, 7, 8},
|
|
|
+ PlayVol: 50,
|
|
|
+ PromptTone: librarie.PlayInterval,
|
|
|
+ }
|
|
|
+ marshal, err := json.Marshal(contentInfo)
|
|
|
+ if err != nil {
|
|
|
+ logger.Logger.Errorf("IPCastPaying contentInfo err = %v \n", err)
|
|
|
+ return "", 0
|
|
|
+ }
|
|
|
+ return string(marshal), librarie.Ptype
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 计算2个时间相差多少秒
|
|
|
+func diffTime(stime, etime string) int {
|
|
|
+ stimeT, err := time.Parse("2006-01-02 15:04", fmt.Sprintf("%v %v", time.Now().Format("2006-01-02"), stime))
|
|
|
+ if err != nil {
|
|
|
+ return -1
|
|
|
+ }
|
|
|
+ etimeT, err2 := time.Parse("2006-01-02 15:04", fmt.Sprintf("%v %v", time.Now().Format("2006-01-02"), etime))
|
|
|
+ if err2 != nil {
|
|
|
+ return -1
|
|
|
+ }
|
|
|
+ diff := int(etimeT.Sub(stimeT).Seconds())
|
|
|
+ return diff
|
|
|
+}
|