askserie_video.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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) (newId int64, 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. if newIndustrialId == 0 {
  94. continue
  95. }
  96. itemIndustrialManagementGroup.CreateTime = time.Now()
  97. itemIndustrialManagementGroup.AskserieVideoId = int(newId)
  98. itemIndustrialManagementGroup.IndustrialManagementId = newIndustrialId
  99. _, err = to.Insert(itemIndustrialManagementGroup)
  100. if err != nil {
  101. return
  102. }
  103. }
  104. return
  105. }
  106. // 修改
  107. func UpdateCygxAskserieVideo(item *CygxAskserieVideo, industrialManagementIds string) (err error) {
  108. o := orm.NewOrmUsingDB("hz_cygx")
  109. to, err := o.Begin()
  110. if err != nil {
  111. return
  112. }
  113. defer func() {
  114. if err != nil {
  115. _ = to.Rollback()
  116. } else {
  117. _ = to.Commit()
  118. }
  119. }()
  120. updateParams := make(map[string]interface{})
  121. updateParams["VideoName"] = item.VideoName
  122. updateParams["VideoUrl"] = item.VideoUrl
  123. updateParams["VideoDuration"] = item.VideoDuration
  124. updateParams["ChartPermissionId"] = item.ChartPermissionId
  125. updateParams["ChartPermissionName"] = item.ChartPermissionName
  126. updateParams["BackgroundImg"] = item.BackgroundImg
  127. updateParams["ShareImg"] = item.ShareImg
  128. updateParams["ModifyDate"] = time.Now()
  129. ptrStructOrTableName := "cygx_askserie_video"
  130. whereParam := map[string]interface{}{"askserie_video_id": item.AskserieVideoId}
  131. qs := to.QueryTable(ptrStructOrTableName)
  132. for expr, exprV := range whereParam {
  133. qs = qs.Filter(expr, exprV)
  134. }
  135. _, err = qs.Update(updateParams)
  136. if err != nil {
  137. return
  138. }
  139. //删除关联产业 (避免截断表时产生的脏数据,故不用update而是先删除再增加)
  140. sql := ` DELETE FROM cygx_industrial_askserie_video_group_management WHERE askserie_video_id = ?`
  141. _, err = to.Raw(sql, item.AskserieVideoId).Exec()
  142. if err != nil {
  143. return
  144. }
  145. industrialManagementIdList := strings.Split(industrialManagementIds, ",")
  146. for _, v := range industrialManagementIdList {
  147. itemIndustrialManagementGroup := new(CygxIndustrialAskserieVideoGroupManagement)
  148. newIndustrialId, _ := strconv.Atoi(v)
  149. itemIndustrialManagementGroup.CreateTime = time.Now()
  150. itemIndustrialManagementGroup.AskserieVideoId = item.AskserieVideoId
  151. itemIndustrialManagementGroup.IndustrialManagementId = newIndustrialId
  152. _, err = to.Insert(itemIndustrialManagementGroup)
  153. if err != nil {
  154. return
  155. }
  156. }
  157. return
  158. }
  159. // 获取数量
  160. func GetCygxAskserieVideoCount(condition string, pars []interface{}) (count int, err error) {
  161. o := orm.NewOrmUsingDB("hz_cygx")
  162. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_askserie_video as art WHERE 1= 1 `
  163. if condition != "" {
  164. sqlCount += condition
  165. }
  166. err = o.Raw(sqlCount, pars).QueryRow(&count)
  167. return
  168. }
  169. // 列表
  170. func GetCygxAskserieVideoList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxAskserieVideoResp, err error) {
  171. o := orm.NewOrmUsingDB("hz_cygx")
  172. sql := `SELECT * FROM cygx_askserie_video as art WHERE 1= 1 `
  173. if condition != "" {
  174. sql += condition
  175. }
  176. sql += ` LIMIT ?,? `
  177. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  178. return
  179. }
  180. type GetCygxAskserieVideoRespListResp struct {
  181. Paging *paging.PagingItem `description:"分页数据"`
  182. List []*CygxAskserieVideoResp
  183. }
  184. // 修改是否展示
  185. func EditCygxAskserieVideoStatus(status, askserieVideoId int) (err error) {
  186. o := orm.NewOrmUsingDB("hz_cygx")
  187. sql := `UPDATE cygx_askserie_video SET publish_status=?,publish_date = NOW() , modify_date=NOW() WHERE askserie_video_id=? `
  188. _, err = o.Raw(sql, status, askserieVideoId).Exec()
  189. return
  190. }
  191. // 修改是否展示
  192. func EditCygxAskserieVideoShareImg(shareImg string, askserieVideoId int) (err error) {
  193. o := orm.NewOrmUsingDB("hz_cygx")
  194. sql := `UPDATE cygx_askserie_video SET share_img=? WHERE askserie_video_id=? `
  195. _, err = o.Raw(sql, shareImg, askserieVideoId).Exec()
  196. return
  197. }