Ver código fonte

媒体资源list

terry 2 anos atrás
pai
commit
6562a309ae

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+/build/

+ 0 - 4
app/device/dao/common.go

@@ -3,7 +3,6 @@ package dao
 import (
 	"fmt"
 	"github.com/jinzhu/gorm"
-	"iot_manager_service/app/system/dao"
 )
 
 var Db *gorm.DB
@@ -11,8 +10,6 @@ var Db *gorm.DB
 func InitDB(db *gorm.DB) {
 	Db = db
 	err := Db.AutoMigrate(
-		&dao.User{},
-		&dao.Dict{},
 		&LampPoleGroup{},
 		&LampPole{},
 		&Gateway{},
@@ -41,7 +38,6 @@ func InitDB(db *gorm.DB) {
 		&LightStrategy{},
 		&LightCondition{},
 		&DeviceVendor{},
-		&dao.OperationHistory{},
 	).Error
 	if err != nil {
 		panic(fmt.Sprintf("AutoMigrate err : %v", err))

+ 46 - 0
app/multimedia/controller/libraryController.go

@@ -0,0 +1,46 @@
+package controller
+
+import (
+	"github.com/gin-gonic/gin"
+	"iot_manager_service/app/middleware"
+	"iot_manager_service/app/multimedia/model"
+	"iot_manager_service/app/multimedia/service"
+	"iot_manager_service/util/common"
+	"math"
+	"net/http"
+	"strconv"
+)
+
+var Library = new(libraryCtl)
+
+type libraryCtl struct{}
+
+func (c *libraryCtl) List(ctx *gin.Context) {
+	searchValue := ctx.Query("searchValue")
+	current, _ := strconv.Atoi(ctx.Query("current"))
+	size, _ := strconv.Atoi(ctx.Query("size"))
+	if current == 0 {
+		current = 1
+	}
+	if size <= 0 || size > 100 {
+		size = 10
+	}
+
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
+	libraries, err := service.LibraryService.List(claims.TenantId, searchValue, current, size)
+	if err != nil {
+		ctx.JSON(http.StatusOK, err)
+		return
+	}
+	pages := math.Ceil(float64(len(libraries)) / float64(size))
+	rsp := model.RsqLibraryList{
+		Current: current,
+		Size:    size,
+		Total:   len(libraries),
+		Pages:   int(pages),
+		Records: libraries,
+	}
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp))
+}

+ 18 - 0
app/multimedia/dao/common.go

@@ -0,0 +1,18 @@
+package dao
+
+import (
+	"fmt"
+	"github.com/jinzhu/gorm"
+)
+
+var Db *gorm.DB
+
+func InitDB(db *gorm.DB) {
+	Db = db
+	err := Db.AutoMigrate(
+		&Library{},
+	).Error
+	if err != nil {
+		panic(fmt.Sprintf("AutoMigrate err : %v", err))
+	}
+}

+ 40 - 0
app/multimedia/dao/libraryDao.go

@@ -0,0 +1,40 @@
+package dao
+
+import (
+	"time"
+)
+
+type Library struct {
+	ID              int       `gorm:"primary_key" json:"id"`                      //编号
+	MaterialAddress string    `gorm:"type:varchar(10000)" json:"materialAddress"` //素材地址
+	LibName         string    `gorm:"type:varchar(64)" json:"libName"`            //素材名称
+	LibExplain      string    `gorm:"type:varchar(255)" json:"libExplain"`        //素材说明
+	LibType         int       `gorm:"type:int" json:"libType"`                    //素材类型:1-视频,2-图片,3-文字,4-音频
+	Resolution      string    `gorm:"type:varchar(64)" json:"resolution"`         //分辨率
+	FileSize        int64     `gorm:"type:bigint" json:"fileSize"`                //文件大小
+	LibDuration     int       `gorm:"type:int;default 0" json:"libDuration"`      //获取视频时长
+	FileId          string    `gorm:"type:varchar(255)" json:"fileId"`            //文件ID,系统类型为广播系统时使用
+	TalkSpeed       int       `gorm:"type:int;default 0" json:"talkSpeed"`        //语速(用于文字广播):0-正常,1-快一些,2-很快
+	TenantId        int       `gorm:"type:int" json:"tenantId"`                   //租户ID
+	CreateTime      time.Time `gorm:"type:datetime" json:"createTime"`            //新增时间
+	CreateUser      int64     `gorm:"type:bigint" json:"createUser"`              //新增记录操作用户ID
+	UpdateTime      time.Time `gorm:"type:datetime" json:"updateTime"`            //修改时间
+	UpdateUser      int64     `gorm:"type:bigint" json:"updateUser"`              //修改用户
+	IsDeleted       int       `gorm:"type:int;default 0" json:"isDeleted"`        //是否删除 0=未删除,1=删除
+	Status          int       `gorm:"type:int;default 2" json:"status"`           //状态 1=正常,2=异常
+}
+
+func (Library) TableName() string {
+	return "media_library"
+}
+
+func (c Library) GetLibraries(offset, limit int) ([]Library, error) {
+	var libraries []Library
+	db := Db.Debug().Model(&c)
+	if c.LibName != "" {
+		db = db.Where("lib_name like ?", "%"+c.LibName+"%")
+	}
+
+	err := db.Where("is_deleted = 0 and tenant_id = ?", c.TenantId).Offset(offset).Limit(limit).Find(&libraries).Error
+	return libraries, err
+}

+ 34 - 0
app/multimedia/model/library.go

@@ -0,0 +1,34 @@
+package model
+
+import "iot_manager_service/app/multimedia/dao"
+
+const (
+	LibraryTypeVideo    = 1
+	LibraryTypeImage    = 2
+	LibraryTypeVideoStr = "视频"
+	LibraryTypeImageStr = "图片"
+)
+
+func DaoToModel(library dao.Library) LibraryDetail {
+	typeName := LibraryTypeVideoStr
+	if library.LibType == LibraryTypeImage {
+		typeName = LibraryTypeImageStr
+	}
+	return LibraryDetail{
+		Library:  library,
+		TypeName: typeName,
+	}
+}
+
+type LibraryDetail struct {
+	dao.Library
+	TypeName string `json:"typeName"` //素材类型(中文) 视频 图片
+}
+
+type RsqLibraryList struct {
+	Records []LibraryDetail `json:"records"` //记录列表
+	Current int             `json:"current"` //当前分页
+	Size    int             `json:"size"`    //每页数量
+	Pages   int             `json:"pages"`   //总页数
+	Total   int             `json:"total"`   //总数
+}

+ 35 - 0
app/multimedia/service/libraryService.go

@@ -0,0 +1,35 @@
+package service
+
+import (
+	"iot_manager_service/app/multimedia/dao"
+	"iot_manager_service/app/multimedia/model"
+	"iot_manager_service/util/common"
+)
+
+var LibraryService = new(libraryService)
+
+type libraryService struct{}
+
+func (s *libraryService) List(tenantId int, searchValue string, current, size int) ([]model.LibraryDetail,
+	*common.Errors) {
+	library := &dao.Library{
+		TenantId: tenantId,
+	}
+
+	offset := (current - 1) * size
+	limit := size
+
+	if searchValue != "" {
+		library.LibName = searchValue
+	}
+	libraries, err := library.GetLibraries(offset, limit)
+	if err != nil {
+		return nil, common.FailResponse(err.Error(), nil)
+	}
+
+	var rsp []model.LibraryDetail
+	for _, lib := range libraries {
+		rsp = append(rsp, model.DaoToModel(lib))
+	}
+	return rsp, nil
+}

+ 2 - 0
app/system/dao/common.go

@@ -11,10 +11,12 @@ func InitDB(db *gorm.DB) {
 	Db = db
 	err := Db.AutoMigrate(
 		&User{},
+		&Dict{},
 		&Tenant{},
 		&Role{},
 		&RoleMenu{},
 		&Menu{},
+		&OperationHistory{},
 	).Error
 	if err != nil {
 		panic(fmt.Sprintf("AutoMigrate err : %v", err))

+ 2 - 0
main.go

@@ -5,6 +5,7 @@ import (
 	_ "github.com/go-sql-driver/mysql"
 	"github.com/jinzhu/gorm"
 	device "iot_manager_service/app/device/dao"
+	multimedia "iot_manager_service/app/multimedia/dao"
 	system "iot_manager_service/app/system/dao"
 	"iot_manager_service/config"
 	_ "iot_manager_service/config"
@@ -45,4 +46,5 @@ func initDB() {
 	}
 	device.InitDB(db)
 	system.InitDB(db)
+	multimedia.InitDB(db)
 }

+ 7 - 0
router/router.go

@@ -4,6 +4,7 @@ import (
 	"github.com/gin-gonic/gin"
 	device "iot_manager_service/app/device/controller"
 	"iot_manager_service/app/middleware"
+	multimedia "iot_manager_service/app/multimedia/controller"
 	record "iot_manager_service/app/record/controller"
 	security "iot_manager_service/app/security/controller"
 	system "iot_manager_service/app/system/controller"
@@ -455,4 +456,10 @@ func InitRouter(engine *gin.Engine) {
 	{
 		securityGroup.GET("/getCameraLiveList", security.Security.GetCameraLiveList)
 	}
+
+	// 媒体素材
+	multimediaGroup := engine.Group("/api/longchi/multimedia/library")
+	{
+		multimediaGroup.GET("/list", multimedia.Library.List)
+	}
 }