publishLibrariesService.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package service
  2. import (
  3. "fmt"
  4. "iot_manager_service/app/multimedia/dao"
  5. "iot_manager_service/app/multimedia/model"
  6. "iot_manager_service/util/common"
  7. "iot_manager_service/util/logger"
  8. "strings"
  9. "time"
  10. )
  11. var PublishLibrariesService = new(publishLibrariesService)
  12. type publishLibrariesService struct{}
  13. /**
  14. TODO: 此接口都未对接边缘端
  15. */
  16. func (s *publishLibrariesService) List(tenantId int, searchValue string, current, size int, sysType int) ([]dao.PublishLibraries, int64,
  17. *common.Errors) {
  18. program := &dao.PublishLibraries{
  19. TenantId: tenantId,
  20. SysType: sysType,
  21. }
  22. offset := (current - 1) * size
  23. limit := size
  24. if searchValue != "" {
  25. program.Name = searchValue
  26. }
  27. list, total, err := program.GetList(offset, limit)
  28. if err != nil {
  29. return nil, 0, common.FailResponse(err.Error(), nil)
  30. }
  31. return list, total, nil
  32. }
  33. // Audit 素材发布
  34. func (s *publishLibrariesService) Audit(req model.ReqProgramAudit) error {
  35. if !common.MultimediaEfficacyTime(req.StartTime, req.EndTime, req.KsTime) {
  36. panic("任务时间已过,请重新定义时间。")
  37. }
  38. program := dao.Program{ID: req.ProgramLibrariesId}
  39. err := program.Get()
  40. if err != nil {
  41. return err
  42. }
  43. update := PublishLibrariesService.Create(&program, req)
  44. fmt.Printf("update = %v", update)
  45. return nil
  46. }
  47. // SaveOrUpdate 保存
  48. func (s *publishLibrariesService) Create(program *dao.Program, req model.ReqProgramAudit) *common.Errors {
  49. fmt.Printf("program = %v", program)
  50. remarks := "多媒体系统"
  51. if program.SysType == 1 {
  52. remarks = "广播系统"
  53. }
  54. infoIds := req.InfoId
  55. infoIds = strings.Trim(infoIds, ",")
  56. infoIds = strings.ReplaceAll(infoIds, "-1", "")
  57. infoIds = strings.ReplaceAll(infoIds, ",-1", "") //新id
  58. libraries := &dao.PublishLibraries{
  59. Name: program.Name,
  60. Resolution: program.Resolution,
  61. Duration: program.Duration,
  62. FileSize: program.FileSize,
  63. InfoId: infoIds,
  64. ImgDuration: program.ImgDuration,
  65. StartTime: req.StartTime,
  66. EndTime: req.EndTime,
  67. NotificationType: "0",
  68. CreateTime: time.Now(),
  69. CreateUser: program.CreateUser,
  70. CreateName: "",
  71. UpdateTime: time.Now(),
  72. UpdateUser: "",
  73. IsDeleted: 0,
  74. Status: 1,
  75. TenantId: program.TenantId,
  76. Remarks: remarks,
  77. SysType: program.SysType,
  78. KsTime: req.KsTime,
  79. JsTime: req.JsTime,
  80. FileId: program.ID,
  81. }
  82. libraries.CreateTime = time.Now()
  83. if err := libraries.Create(); err != nil {
  84. logger.Logger.Errorf("Create err = %s \n", err.Error())
  85. return common.FailResponse(err.Error(), nil)
  86. }
  87. fmt.Printf("libraries = %v", libraries)
  88. //TODO: 日志保存
  89. return common.SuccessResponse(common.Succeeded, nil)
  90. }
  91. // GetProgram 取节目
  92. func (s *publishLibrariesService) GetProgram(id int) (int, error) {
  93. libraries := dao.PublishLibraries{ID: int64(id)}
  94. program, err := libraries.GetProgram()
  95. return program, err
  96. }
  97. func (s *publishLibrariesService) putPublishLibraries(programId int, publishLibraries dao.PublishLibraries) {
  98. }
  99. // UpdateStatus 状态变更
  100. func (s *publishLibrariesService) UpdateStatus(tenantId int, id int, status int, name string) (bool, error) {
  101. update := &dao.PublishLibraries{
  102. TenantId: tenantId,
  103. ID: int64(id),
  104. Status: status,
  105. Name: name,
  106. }
  107. err := update.Update()
  108. if err != nil {
  109. return false, err
  110. }
  111. return true, nil
  112. }