kobe6258 8 月之前
父节点
当前提交
56fb370547
共有 5 个文件被更改,包括 180 次插入18 次删除
  1. 125 14
      controllers/message.go
  2. 24 1
      models/media.go
  3. 10 0
      models/media_permission_mapping.go
  4. 3 3
      models/response/media.go
  5. 18 0
      routers/commentsRouter.go

+ 125 - 14
controllers/message.go

@@ -5,6 +5,7 @@ import (
 	"eta/eta_mini_crm_ht/models/response"
 	"eta/eta_mini_crm_ht/utils"
 	"github.com/rdlucklib/rdluck_tools/paging"
+	"strconv"
 	"strings"
 )
 
@@ -33,6 +34,7 @@ func (this *MessageController) ReportList() {
 	permissionIds := this.GetString("PermissionIds")
 	analystNames := this.GetString("AnalystNames")
 	sortType := this.GetString("SortType")
+	var permissionCondition string
 	var condition string
 	var pars []interface{}
 
@@ -44,14 +46,16 @@ func (this *MessageController) ReportList() {
 	}
 	if permissionIds != "" {
 		permissionArr := strings.Split(permissionIds, ",")
-		condition += " AND permission_id in (" + utils.GetOrmReplaceHolder(len(permissionArr)) + ")"
+		permissionCondition += "permission_id in (" + utils.GetOrmReplaceHolder(len(permissionArr)) + ")"
 		pars = append(pars, permissionArr)
 	}
+
 	if analystNames != "" {
 		analystNameArr := strings.Split(analystNames, ",")
 		condition += " AND author in (" + utils.GetOrmReplaceHolder(len(analystNameArr)) + ")"
 		pars = append(pars, analystNameArr)
 	}
+
 	sortCondition := " ORDER BY published_time "
 	if sortType == "" {
 		sortType = "DESC"
@@ -59,8 +63,8 @@ func (this *MessageController) ReportList() {
 	sortCondition = sortCondition + sortType
 	total, err := models.GetReportCountByCondition(condition, pars)
 	if err != nil {
-		br.Msg = "获取研报列表失败"
-		br.ErrMsg = "获取研报列表统计失败,Err:" + err.Error()
+		br.Msg = "获取音频列表失败"
+		br.ErrMsg = "获取音频列表统计失败,Err:" + err.Error()
 		return
 	}
 
@@ -106,8 +110,9 @@ func (this *MessageController) AudioList() {
 	pageSize, _ := this.GetInt("PageSize")
 	currentIndex, _ := this.GetInt("CurrentIndex")
 	permissionIds := this.GetString("PermissionIds")
-	analystNames := this.GetString("AnalystNames")
+	analystIds := this.GetString("AnalystIds")
 	sortType := this.GetString("SortType")
+	var permissionCondition string
 	var condition string
 	var pars []interface{}
 
@@ -117,22 +122,37 @@ func (this *MessageController) AudioList() {
 	if currentIndex <= 0 {
 		currentIndex = 1
 	}
+	var permissionPars []interface{}
 	if permissionIds != "" {
 		permissionArr := strings.Split(permissionIds, ",")
-		condition += " AND permission_id in (" + utils.GetOrmReplaceHolder(len(permissionArr)) + ")"
-		pars = append(pars, permissionArr)
+		for _, permissionId := range permissionArr {
+			perId, _ := strconv.Atoi(permissionId)
+			permissionPars = append(permissionPars, perId)
+		}
+		permissionCondition += " AND permission_id in (" + utils.GetOrmReplaceHolder(len(permissionPars)) + ")"
+		ids, err := models.GetMappingsByCondition(permissionCondition, permissionPars)
+		if err != nil {
+			condition += " AND id in (" + utils.GetOrmReplaceHolder(len(ids)) + ")"
+			pars = append(pars, ids)
+		}
 	}
-	if analystNames != "" {
-		analystNameArr := strings.Split(analystNames, ",")
-		condition += " AND author in (" + utils.GetOrmReplaceHolder(len(analystNameArr)) + ")"
-		pars = append(pars, analystNameArr)
+
+	if analystIds != "" {
+		analystIdArr := strings.Split(analystIds, ",")
+		var authorIds []int
+		for _, analystId := range analystIdArr {
+			id, _ := strconv.Atoi(analystId)
+			authorIds = append(authorIds, id)
+		}
+		condition += " AND author_id in (" + utils.GetOrmReplaceHolder(len(authorIds)) + ")"
+		pars = append(pars, authorIds)
 	}
 	sortCondition := " ORDER BY published_time "
 	if sortType == "" {
 		sortType = "DESC"
 	}
 	sortCondition = sortCondition + sortType
-	total, err := models.GetReportCountByCondition(condition, pars)
+	total, err := models.GetMediaCountByCondition(models.Audio, condition, pars)
 	if err != nil {
 		br.Msg = "获取研报列表失败"
 		br.ErrMsg = "获取研报列表统计失败,Err:" + err.Error()
@@ -140,19 +160,110 @@ func (this *MessageController) AudioList() {
 	}
 
 	startSize := utils.StartIndex(currentIndex, pageSize)
-	reportList, err := models.GetReportByCondition(condition, sortCondition, pars, startSize, pageSize)
+	reportList, err := models.GetMediaByCondition(models.Audio, condition, sortCondition, pars, startSize, pageSize)
 	if err != nil {
 		br.Msg = "获取研报列表失败"
 		br.ErrMsg = "获取研报列表失败,Err:" + err.Error()
 		return
 	}
-	var reportViewList []*models.ReportView
+	var reportViewList []*models.ESMedia
 	for _, report := range reportList {
 		reportView := report.ToView()
 		reportViewList = append(reportViewList, reportView)
 	}
 	page := paging.GetPaging(currentIndex, pageSize, total)
-	resp := new(response.ReportListResp)
+	resp := new(response.MediaListResp)
+	resp.List = reportViewList
+	resp.Paging = page
+
+	br.Ret = 200
+	br.Success = true
+	br.Data = resp
+	br.Msg = "获取成功"
+}
+
+// VideoList
+// @Title 研报列表
+// @Description pdf研报列表
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   ClassifyIds   query   string  true       "二级分类id,可多选用英文,隔开"
+// @Param   KeyWord   query   string  true       "报告标题/创建人"
+// @Param   SortType   query   string  true       "排序方式"
+// @Success 200 {object} models.ReportAuthorResp
+// @router /videoList [get]
+func (this *MessageController) VideoList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	permissionIds := this.GetString("PermissionIds")
+	analystIds := this.GetString("AnalystIds")
+	sortType := this.GetString("SortType")
+	var permissionCondition string
+	var condition string
+	var pars []interface{}
+
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	var permissionPars []interface{}
+	if permissionIds != "" {
+		permissionArr := strings.Split(permissionIds, ",")
+		for _, permissionId := range permissionArr {
+			perId, _ := strconv.Atoi(permissionId)
+			permissionPars = append(permissionPars, perId)
+		}
+		permissionCondition += " AND permission_id in (" + utils.GetOrmReplaceHolder(len(permissionPars)) + ")"
+		ids, err := models.GetMappingsByCondition(permissionCondition, permissionPars)
+		if err != nil {
+			condition += " AND id in (" + utils.GetOrmReplaceHolder(len(ids)) + ")"
+			pars = append(pars, ids)
+		}
+	}
+
+	if analystIds != "" {
+		analystIdArr := strings.Split(analystIds, ",")
+		var authorIds []int
+		for _, analystId := range analystIdArr {
+			id, _ := strconv.Atoi(analystId)
+			authorIds = append(authorIds, id)
+		}
+		condition += " AND author_id in (" + utils.GetOrmReplaceHolder(len(authorIds)) + ")"
+		pars = append(pars, authorIds)
+	}
+	sortCondition := " ORDER BY published_time "
+	if sortType == "" {
+		sortType = "DESC"
+	}
+	sortCondition = sortCondition + sortType
+	total, err := models.GetMediaCountByCondition(models.Video, condition, pars)
+	if err != nil {
+		br.Msg = "获取研报列表失败"
+		br.ErrMsg = "获取研报列表统计失败,Err:" + err.Error()
+		return
+	}
+
+	startSize := utils.StartIndex(currentIndex, pageSize)
+	List, err := models.GetMediaByCondition(models.Video, condition, sortCondition, pars, startSize, pageSize)
+	if err != nil {
+		br.Msg = "获取研报列表失败"
+		br.ErrMsg = "获取研报列表失败,Err:" + err.Error()
+		return
+	}
+	var reportViewList []*models.ESMedia
+	for _, report := range List {
+		reportView := report.ToView()
+		reportViewList = append(reportViewList, reportView)
+	}
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	resp := new(response.MediaListResp)
 	resp.List = reportViewList
 	resp.Paging = page
 

+ 24 - 1
models/media.go

@@ -65,6 +65,29 @@ type Media struct {
 	UpdatedTime           time.Time  `description:"updated_time"`
 }
 
+func GetMediaCountByCondition(media MediaType, condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT COUNT(*) AS count FROM media WHERE 1=1  AND media_type=? `
+	if condition != "" {
+		sql += condition
+	}
+	err = o.Raw(sql, media, pars).QueryRow(&count)
+	return
+}
+
+func GetMediaByCondition(media MediaType, condition string, sortCondition string, pars []interface{}, startPage, pageSize int) (items []*Media, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM media WHERE 1=1 AND media_type=?`
+	if condition != "" {
+		sql += condition
+	}
+	if sortCondition != "" {
+		sql += sortCondition // 排序
+	}
+	sql += ` LIMIT ?,?`
+	_, err = o.Raw(sql, media, pars, startPage, pageSize).QueryRows(&items)
+	return
+}
 func InsertMedia(m *Media) (err error) {
 	tx, err := orm.NewOrm().Begin()
 	if err != nil {
@@ -158,7 +181,7 @@ func UpdateMedia(m *Media) (updateId int64, err error) {
 		_ = tx.Rollback()
 		return
 	}
-	updateId, err = o.Update(m, "author_id", "author_name", "")
+	updateId, err = o.Update(m, "author_id", "author_name", "cover_src", "src", "media_play_milliseconds", "permission_ids")
 	if err != nil {
 		_ = tx.Rollback()
 		return

+ 10 - 0
models/media_permission_mapping.go

@@ -25,3 +25,13 @@ func DeleteMappingsById(mediaId int) (err error) {
 	_, err = o.QueryTable(new(MediaPermissionMapping)).Filter("media_id", mediaId).Update(orm.Params{"deleted": 1})
 	return
 }
+
+func GetMappingsByCondition(condition string, pars []interface{}) (items []int64, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT distinct  media_id FROM media_permission_mappings WHERE DELETED=0 `
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 3 - 3
models/response/media.go

@@ -6,12 +6,12 @@ import (
 )
 
 type MediaListResp struct {
-	List   []*models.ReportPdf
+	List   []*models.ESMedia
 	Paging *paging.PagingItem `description:"分页数据"`
 }
 
 type MediaUploadResp struct {
-	Url                 string `description:"文件URL"`
-	FileName            string `description:"文件名称"`
+	FileName            string `description:"上传文件名称"`
+	Url                 string `description:"上传文件URL"`
 	DurationMillisecond int    `description:"时长"`
 }

+ 18 - 0
routers/commentsRouter.go

@@ -234,6 +234,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:MessageController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:MessageController"],
+        beego.ControllerComments{
+            Method: "AudioList",
+            Router: `/audioList`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:MessageController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:MessageController"],
         beego.ControllerComments{
             Method: "ReportList",
@@ -243,6 +252,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:MessageController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:MessageController"],
+        beego.ControllerComments{
+            Method: "VideoList",
+            Router: `/videoList`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:SysDepartmentController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:SysDepartmentController"],
         beego.ControllerComments{
             Method: "Add",