askserie_video.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. package cygx
  2. import (
  3. //"github.com/beego/beego/v2/client/orm"
  4. //"github.com/rdlucklib/rdluck_tools/paging"
  5. //"strconv"
  6. //"strings"
  7. "github.com/beego/beego/v2/client/orm"
  8. "github.com/rdlucklib/rdluck_tools/paging"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. type CygxAskserieVideo struct {
  14. AskserieVideoId int `orm:"column(askserie_video_id);pk"description:"视频id"`
  15. VideoName string `description:"视频标题"`
  16. VideoUrl string `description:"视频地址"`
  17. VideoDuration string `description:"视频时长"`
  18. ChartPermissionId int `description:"行业ID"`
  19. ChartPermissionName string `description:"行业名称"`
  20. PublishStatus int `description:"发布状态 1发布 0没有"`
  21. VideoCounts int `description:"播放量"`
  22. BackgroundImg string `description:"封面图片"`
  23. ShareImg string `description:"分享图片"`
  24. AdminId int `description:"管理员、销售ID"`
  25. ModifyDate time.Time `description:"更新时间"`
  26. PublishDate time.Time `description:"发布时间"`
  27. CreateTime time.Time `description:"创建时间"`
  28. }
  29. type AddAskserieVideoReq struct {
  30. AskserieVideoId int `description:"askserie_video_id"`
  31. VideoName string `description:"视频标题"`
  32. VideoUrl string `description:"视频地址"`
  33. VideoDuration string `description:"视频时长"`
  34. ChartPermissionId int `description:"行业ID"`
  35. ChartPermissionName string `description:"行业名称"`
  36. IndustrialManagementIds string `description:"产业id 多个用 , 隔开"`
  37. BackgroundImg string `description:"封面图片"`
  38. ShareImg string `description:"分享图片"`
  39. }
  40. type CygxAskserieVideoResp struct {
  41. AskserieVideoId int `orm:"column(askserie_video_id);pk"description:"视频id"`
  42. VideoName string `description:"视频标题"`
  43. VideoUrl string `description:"视频地址"`
  44. VideoDuration string `description:"视频时长"`
  45. ChartPermissionId int `description:"行业ID"`
  46. ChartPermissionName string `description:"行业名称"`
  47. PublishStatus int `description:"发布状态 1发布 0没有"`
  48. VideoCounts int `description:"播放量"`
  49. CommentNum int `description:"留言总数"`
  50. BackgroundImg string `description:"封面图片"`
  51. ShareImg string `description:"分享图片"`
  52. AdminId int `description:"管理员、销售ID"`
  53. IndustryName string `description:"产业名称"`
  54. ModifyDate string `description:"更新时间"`
  55. PublishDate string `description:"发布时间"`
  56. CreateTime string `description:"创建时间"`
  57. ListIndustrial []*IndustrialActivityGroupManagementRep
  58. }
  59. type GetCygxAskserieVideoDetailResp struct {
  60. Detail *CygxAskserieVideoResp
  61. }
  62. // 通过ID获取详情
  63. func GetCygxAskserieVideoDetail(askserieVideoId int) (item *CygxAskserieVideoResp, err error) {
  64. o := orm.NewOrmUsingDB("hz_cygx")
  65. sql := `SELECT * FROM cygx_askserie_video WHERE askserie_video_id=? `
  66. err = o.Raw(sql, askserieVideoId).QueryRow(&item)
  67. return
  68. }
  69. // 添加
  70. func AddCygxAskserieVideo(item *CygxAskserieVideo, industrialManagementIds string) (err error) {
  71. o := orm.NewOrmUsingDB("hz_cygx")
  72. to, err := o.Begin()
  73. if err != nil {
  74. return
  75. }
  76. defer func() {
  77. if err != nil {
  78. _ = to.Rollback()
  79. } else {
  80. _ = to.Commit()
  81. }
  82. }()
  83. newId, err := to.Insert(item)
  84. if err != nil {
  85. return
  86. }
  87. //添加与产业的关联
  88. //new(cygx.CygxIndustrialAskserieVideoGroupManagement),
  89. industrialManagementIdList := strings.Split(industrialManagementIds, ",")
  90. for _, v := range industrialManagementIdList {
  91. itemIndustrialManagementGroup := new(CygxIndustrialAskserieVideoGroupManagement)
  92. newIndustrialId, _ := strconv.Atoi(v)
  93. itemIndustrialManagementGroup.CreateTime = time.Now()
  94. itemIndustrialManagementGroup.AskserieVideoId = int(newId)
  95. itemIndustrialManagementGroup.IndustrialManagementId = newIndustrialId
  96. _, err = to.Insert(itemIndustrialManagementGroup)
  97. if err != nil {
  98. return
  99. }
  100. }
  101. return
  102. }
  103. // 修改
  104. func UpdateCygxAskserieVideo(item *CygxAskserieVideo, industrialManagementIds string) (err error) {
  105. o := orm.NewOrmUsingDB("hz_cygx")
  106. to, err := o.Begin()
  107. if err != nil {
  108. return
  109. }
  110. defer func() {
  111. if err != nil {
  112. _ = to.Rollback()
  113. } else {
  114. _ = to.Commit()
  115. }
  116. }()
  117. updateParams := make(map[string]interface{})
  118. updateParams["VideoName"] = item.VideoName
  119. updateParams["VideoUrl"] = item.VideoUrl
  120. updateParams["VideoDuration"] = item.VideoDuration
  121. updateParams["ChartPermissionId"] = item.ChartPermissionId
  122. updateParams["ChartPermissionName"] = item.ChartPermissionName
  123. updateParams["BackgroundImg"] = item.BackgroundImg
  124. updateParams["ShareImg"] = item.ShareImg
  125. updateParams["ModifyDate"] = time.Now()
  126. ptrStructOrTableName := "cygx_askserie_video"
  127. whereParam := map[string]interface{}{"askserie_video_id": item.AskserieVideoId}
  128. qs := to.QueryTable(ptrStructOrTableName)
  129. for expr, exprV := range whereParam {
  130. qs = qs.Filter(expr, exprV)
  131. }
  132. _, err = qs.Update(updateParams)
  133. if err != nil {
  134. return
  135. }
  136. //删除关联产业 (避免截断表时产生的脏数据,故不用update而是先删除再增加)
  137. sql := ` DELETE FROM cygx_industrial_askserie_video_group_management WHERE askserie_video_id = ?`
  138. _, err = to.Raw(sql, item.AskserieVideoId).Exec()
  139. if err != nil {
  140. return
  141. }
  142. industrialManagementIdList := strings.Split(industrialManagementIds, ",")
  143. for _, v := range industrialManagementIdList {
  144. itemIndustrialManagementGroup := new(CygxIndustrialAskserieVideoGroupManagement)
  145. newIndustrialId, _ := strconv.Atoi(v)
  146. itemIndustrialManagementGroup.CreateTime = time.Now()
  147. itemIndustrialManagementGroup.AskserieVideoId = item.AskserieVideoId
  148. itemIndustrialManagementGroup.IndustrialManagementId = newIndustrialId
  149. _, err = to.Insert(itemIndustrialManagementGroup)
  150. if err != nil {
  151. return
  152. }
  153. }
  154. return
  155. }
  156. // 获取数量
  157. func GetCygxAskserieVideoCount(condition string, pars []interface{}) (count int, err error) {
  158. o := orm.NewOrmUsingDB("hz_cygx")
  159. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_askserie_video as art WHERE 1= 1 `
  160. if condition != "" {
  161. sqlCount += condition
  162. }
  163. err = o.Raw(sqlCount, pars).QueryRow(&count)
  164. return
  165. }
  166. // 列表
  167. func GetCygxAskserieVideoList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxAskserieVideoResp, err error) {
  168. o := orm.NewOrmUsingDB("hz_cygx")
  169. sql := `SELECT * FROM cygx_askserie_video as art WHERE 1= 1 `
  170. if condition != "" {
  171. sql += condition
  172. }
  173. sql += ` LIMIT ?,? `
  174. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  175. return
  176. }
  177. type GetCygxAskserieVideoRespListResp struct {
  178. Paging *paging.PagingItem `description:"分页数据"`
  179. List []*CygxAskserieVideoResp
  180. }