askserie_video.go 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. ActivityId int ` description:"活动ID"`
  29. }
  30. type AddAskserieVideoReq struct {
  31. AskserieVideoId int `description:"askserie_video_id"`
  32. VideoName string `description:"视频标题"`
  33. VideoUrl string `description:"视频地址"`
  34. VideoDuration string `description:"视频时长"`
  35. ChartPermissionId int `description:"行业ID"`
  36. ChartPermissionName string `description:"行业名称"`
  37. IndustrialManagementIds string `description:"产业id 多个用 , 隔开"`
  38. BackgroundImg string `description:"封面图片"`
  39. ShareImg string `description:"分享图片"`
  40. }
  41. type CygxAskserieVideoResp struct {
  42. AskserieVideoId int `orm:"column(askserie_video_id);pk"description:"视频id"`
  43. VideoName string `description:"视频标题"`
  44. VideoUrl string `description:"视频地址"`
  45. VideoDuration string `description:"视频时长"`
  46. ChartPermissionId int `description:"行业ID"`
  47. ChartPermissionName string `description:"行业名称"`
  48. PublishStatus int `description:"发布状态 1发布 0没有"`
  49. VideoCounts int `description:"播放量"`
  50. CommentNum int `description:"留言总数"`
  51. BackgroundImg string `description:"封面图片"`
  52. ShareImg string `description:"分享图片"`
  53. AdminId int `description:"管理员、销售ID"`
  54. IndustryName string `description:"产业名称"`
  55. ModifyDate string `description:"更新时间"`
  56. PublishDate string `description:"发布时间"`
  57. CreateTime string `description:"创建时间"`
  58. ListIndustrial []*IndustrialActivityGroupManagementRep
  59. }
  60. type GetCygxAskserieVideoDetailResp struct {
  61. Detail *CygxAskserieVideoResp
  62. }
  63. // 通过ID获取详情
  64. func GetCygxAskserieVideoDetail(askserieVideoId int) (item *CygxAskserieVideoResp, err error) {
  65. o := orm.NewOrmUsingDB("hz_cygx")
  66. sql := `SELECT * FROM cygx_askserie_video WHERE askserie_video_id=? `
  67. err = o.Raw(sql, askserieVideoId).QueryRow(&item)
  68. return
  69. }
  70. // 添加
  71. func AddCygxAskserieVideo(item *CygxAskserieVideo, industrialManagementIds string) (newId int64, err error) {
  72. o := orm.NewOrmUsingDB("hz_cygx")
  73. to, err := o.Begin()
  74. if err != nil {
  75. return
  76. }
  77. defer func() {
  78. if err != nil {
  79. _ = to.Rollback()
  80. } else {
  81. _ = to.Commit()
  82. }
  83. }()
  84. newId, err = to.Insert(item)
  85. if err != nil {
  86. return
  87. }
  88. //添加与产业的关联
  89. //new(cygx.CygxIndustrialAskserieVideoGroupManagement),
  90. industrialManagementIdList := strings.Split(industrialManagementIds, ",")
  91. for _, v := range industrialManagementIdList {
  92. itemIndustrialManagementGroup := new(CygxIndustrialAskserieVideoGroupManagement)
  93. newIndustrialId, _ := strconv.Atoi(v)
  94. if newIndustrialId == 0 {
  95. continue
  96. }
  97. itemIndustrialManagementGroup.CreateTime = time.Now()
  98. itemIndustrialManagementGroup.AskserieVideoId = int(newId)
  99. itemIndustrialManagementGroup.IndustrialManagementId = newIndustrialId
  100. _, err = to.Insert(itemIndustrialManagementGroup)
  101. if err != nil {
  102. return
  103. }
  104. }
  105. return
  106. }
  107. // 修改
  108. func UpdateCygxAskserieVideo(item *CygxAskserieVideo, industrialManagementIds string) (err error) {
  109. o := orm.NewOrmUsingDB("hz_cygx")
  110. to, err := o.Begin()
  111. if err != nil {
  112. return
  113. }
  114. defer func() {
  115. if err != nil {
  116. _ = to.Rollback()
  117. } else {
  118. _ = to.Commit()
  119. }
  120. }()
  121. updateParams := make(map[string]interface{})
  122. updateParams["VideoName"] = item.VideoName
  123. updateParams["VideoUrl"] = item.VideoUrl
  124. updateParams["VideoDuration"] = item.VideoDuration
  125. updateParams["ChartPermissionId"] = item.ChartPermissionId
  126. updateParams["ChartPermissionName"] = item.ChartPermissionName
  127. updateParams["BackgroundImg"] = item.BackgroundImg
  128. updateParams["ShareImg"] = item.ShareImg
  129. updateParams["ModifyDate"] = time.Now()
  130. ptrStructOrTableName := "cygx_askserie_video"
  131. whereParam := map[string]interface{}{"askserie_video_id": item.AskserieVideoId}
  132. qs := to.QueryTable(ptrStructOrTableName)
  133. for expr, exprV := range whereParam {
  134. qs = qs.Filter(expr, exprV)
  135. }
  136. _, err = qs.Update(updateParams)
  137. if err != nil {
  138. return
  139. }
  140. //删除关联产业 (避免截断表时产生的脏数据,故不用update而是先删除再增加)
  141. sql := ` DELETE FROM cygx_industrial_askserie_video_group_management WHERE askserie_video_id = ?`
  142. _, err = to.Raw(sql, item.AskserieVideoId).Exec()
  143. if err != nil {
  144. return
  145. }
  146. industrialManagementIdList := strings.Split(industrialManagementIds, ",")
  147. for _, v := range industrialManagementIdList {
  148. itemIndustrialManagementGroup := new(CygxIndustrialAskserieVideoGroupManagement)
  149. newIndustrialId, _ := strconv.Atoi(v)
  150. itemIndustrialManagementGroup.CreateTime = time.Now()
  151. itemIndustrialManagementGroup.AskserieVideoId = item.AskserieVideoId
  152. itemIndustrialManagementGroup.IndustrialManagementId = newIndustrialId
  153. _, err = to.Insert(itemIndustrialManagementGroup)
  154. if err != nil {
  155. return
  156. }
  157. }
  158. return
  159. }
  160. // 获取数量
  161. func GetCygxAskserieVideoCount(condition string, pars []interface{}) (count int, err error) {
  162. o := orm.NewOrmUsingDB("hz_cygx")
  163. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_askserie_video as art WHERE 1= 1 `
  164. if condition != "" {
  165. sqlCount += condition
  166. }
  167. err = o.Raw(sqlCount, pars).QueryRow(&count)
  168. return
  169. }
  170. // 列表
  171. func GetCygxAskserieVideoList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxAskserieVideoResp, err error) {
  172. o := orm.NewOrmUsingDB("hz_cygx")
  173. sql := `SELECT * FROM cygx_askserie_video as art WHERE 1= 1 `
  174. if condition != "" {
  175. sql += condition
  176. }
  177. sql += ` LIMIT ?,? `
  178. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  179. return
  180. }
  181. type GetCygxAskserieVideoRespListResp struct {
  182. Paging *paging.PagingItem `description:"分页数据"`
  183. List []*CygxAskserieVideoResp
  184. }
  185. // 修改是否展示
  186. func EditCygxAskserieVideoStatus(status, askserieVideoId int) (err error) {
  187. o := orm.NewOrmUsingDB("hz_cygx")
  188. sql := `UPDATE cygx_askserie_video SET publish_status=?,publish_date = NOW() , modify_date=NOW() WHERE askserie_video_id=? `
  189. _, err = o.Raw(sql, status, askserieVideoId).Exec()
  190. return
  191. }
  192. // 修改分享图片
  193. func EditCygxAskserieVideoShareImg(shareImg string, askserieVideoId int) (err error) {
  194. o := orm.NewOrmUsingDB("hz_cygx")
  195. sql := `UPDATE cygx_askserie_video SET share_img=? WHERE askserie_video_id=? `
  196. _, err = o.Raw(sql, shareImg, askserieVideoId).Exec()
  197. return
  198. }
  199. // 修改文件名称
  200. func EditCygxAskserieVideoVideoName(videoName string, askserieVideoId int) (err error) {
  201. o := orm.NewOrmUsingDB("hz_cygx")
  202. sql := `UPDATE cygx_askserie_video SET video_name=? WHERE askserie_video_id=? `
  203. _, err = o.Raw(sql, videoName, askserieVideoId).Exec()
  204. return
  205. }