ppt.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. package models
  2. import (
  3. "rdluck_tools/orm"
  4. "time"
  5. )
  6. type Ppt struct {
  7. PptId int `orm:"column(id)" description:"报告Id"`
  8. Title string `description:"标题"`
  9. TemplateType string `description:"模版类型"`
  10. PptDate string `description:"选择日期"`
  11. PptUrl string `description:"ppt地址"`
  12. CreateTime time.Time `description:"创建时间"`
  13. ModifyTime time.Time `description:"修改时间"`
  14. ReportType string `description:"报告类型"`
  15. }
  16. type PptImages struct {
  17. PptImagesId int `description:"Id"`
  18. ImageUrl string `description:"图片地址"`
  19. ImageType int `description:"图片类型,0:首页背景模板"`
  20. }
  21. type PptPages struct {
  22. PptPagesId int `orm:"column(ppt_pages_id)" description:"报告章节Id"`
  23. PptId int64 `description:"ppt_id"`
  24. Title string `description:"标题"`
  25. ImgUrl string `description:"图片路径"`
  26. CreateTime time.Time `description:"创建时间"`
  27. ModifyTime time.Time `description:"修改时间"`
  28. PageCode string `description:"编码"`
  29. Width int `description:"宽度"`
  30. Height int `description:"高端"`
  31. ResourceId int `description:"来源id,来自上海策略组提供的图表id"`
  32. }
  33. func GetPptList(condition string, pars []interface{}, startSize, pageSize int) (items []*Ppt, err error) {
  34. o := orm.NewOrm()
  35. o.Using("rddp")
  36. sql := `SELECT * FROM ppt WHERE 1=1 `
  37. if condition != "" {
  38. sql += condition
  39. }
  40. sql += `ORDER BY create_time DESC LIMIT ?,?`
  41. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  42. return
  43. }
  44. func GetPptListCount(condition string, pars []interface{}) (count int, err error) {
  45. o := orm.NewOrm()
  46. o.Using("rddp")
  47. sql := `SELECT COUNT(1) AS count FROM ppt WHERE 1=1 `
  48. if condition != "" {
  49. sql += condition
  50. }
  51. sql += `ORDER BY create_time DESC LIMIT ?,?`
  52. err = o.Raw(sql, pars).QueryRow(&count)
  53. return
  54. }
  55. type PptListResp struct {
  56. List []*Ppt
  57. Paging *PagingItem `description:"分页数据"`
  58. }
  59. //新增PPT
  60. func AddPpt(item *Ppt) (lastId int64, err error) {
  61. o := orm.NewOrm()
  62. o.Using("rddp")
  63. lastId, err = o.Insert(item)
  64. return
  65. }
  66. //删除ppt
  67. func DeletePpt(pptId int) (err error) {
  68. o := orm.NewOrm()
  69. o.Using("rddp")
  70. sql := `DELETE FROM ppt WHERE ppt_id=? `
  71. _, err = o.Raw(sql, pptId).Exec()
  72. return
  73. }
  74. type AddPptReq struct {
  75. FirstPage struct {
  76. Title string `json:"title"`
  77. ReportType string `json:"report_type"`
  78. PptDate string `json:"ppt_date"`
  79. ImgUrl string `json:"img_url"`
  80. } `json:"first_page"`
  81. ContentPage []ContentPageItems `json:"content_page"`
  82. }
  83. type ContentPageItems struct {
  84. PptId int64 `json:"ppt_id" description:"ppt_id" `
  85. PptPagesId int `json:"ppt_pages_id" description:"章节id,新增时传0"`
  86. Title string `json:"title" description:"标题"`
  87. ResourceId int `json:"resource_id" description:"来源id,来自上海策略组提供的图表id"`
  88. }
  89. func AddPptPages(item *PptPages) (lastId int64, err error) {
  90. o := orm.NewOrm()
  91. o.Using("rddp")
  92. lastId, err = o.Insert(item)
  93. return
  94. }
  95. type EditPptReq struct {
  96. PptId int64 `json:"ppt_id"`
  97. FirstPage struct {
  98. PptPagesId int `json:"ppt_pages_id" description:"ppt_page_id"`
  99. Title string `json:"title" description:"标题"`
  100. ReportType string `json:"report_type" description:"类型"`
  101. PptDate string `json:"ppt_date" description:"日期"`
  102. ImgUrl string `json:"img_url" description:"图片路径"`
  103. } `json:"first_page"`
  104. ContentPage []ContentPageItems `json:"content_page"`
  105. }
  106. func EditPpt(item *Ppt) (err error) {
  107. o := orm.NewOrm()
  108. o.Using("rddp")
  109. sql := `UPDATE ppt SET title = ?, ppt_date= ?, modify_time=NOW(), report_type=? WHERE ppt_id = ? `
  110. _, err = o.Raw(sql, item.Title, item.PptDate, item.ReportType, item.PptId).Exec()
  111. return
  112. }
  113. func EditPptPages(item *PptPages) (err error) {
  114. o := orm.NewOrm()
  115. o.Using("rddp")
  116. sql := `UPDATE ppt_pages SET title= ?, img_url= ?, modify_time = now(), resource_id = ? WHERE ppt_pages_id= ? `
  117. _, err = o.Raw(sql, item.Title, item.ImgUrl, item.ResourceId, item.PptPagesId).Exec()
  118. return
  119. }
  120. type DeletePptReq struct {
  121. PptId int `json:"ppt_id" description:"ppt_id" `
  122. }
  123. func GetPptById(pptId int) (item *Ppt, err error) {
  124. o := orm.NewOrm()
  125. o.Using("rddp")
  126. sql := `SELECT * FROM ppt WHERE 1=1 AND id=? `
  127. err = o.Raw(sql, pptId).QueryRow(&item)
  128. return
  129. }
  130. func GetPptPagesById(pptId int) (items []*PptPages, err error) {
  131. o := orm.NewOrm()
  132. o.Using("rddp")
  133. sql := `SELECT * FROM ppt_pages WHERE ppt_id=? `
  134. _, err = o.Raw(sql, pptId).QueryRows(&items)
  135. return
  136. }
  137. type PptDetailResp struct {
  138. PptPages []*PptPages `description:"ppt详情数据"`
  139. Ppt *Ppt `description:"ppt数据"`
  140. }
  141. type Base64UploadReq struct {
  142. Img string `json:"img" description:"图片img base64" `
  143. PptId string `json:"title" description:"ppt_id"`
  144. ResourceId int `json:"resource_id" description:"来源id,来自上海策略组提供的图表id"`
  145. }
  146. //编辑ppt章节图片
  147. func ModifyPptPages(imgUrl string, resourceId, pptId, pptPagesId, width, height int) (err error) {
  148. sql := "UPDATE ppt_pages SET img_url=?,width=?,height=? WHERE ppt_pages_id=? AND ppt_id=? AND resource_id=? "
  149. o := orm.NewOrm()
  150. o.Using("rddp")
  151. _, err = o.Raw(sql, imgUrl, width, height, pptPagesId, pptId, resourceId).Exec()
  152. return
  153. }
  154. func GetImages(imageType int) (items []*PptImages, err error) {
  155. sql := `SELECT * FROM ppt_images WHERE image_type=? `
  156. o := orm.NewOrm()
  157. o.Using("rddp")
  158. _, err = o.Raw(sql, imageType).QueryRows(&items)
  159. return
  160. }
  161. type PptImagesResp struct {
  162. List []*PptImages `description:"ppt背景图片"`
  163. }
  164. type PptPublishReq struct {
  165. PptId int `json:"ppt_id"`
  166. ScreenHeight int `description:"屏幕宽高"`
  167. }
  168. func GetPptFirstPage(pptId int) (item *PptPages, err error) {
  169. sql := `SELECT * FROM ppt_pages WHERE ppt_id=? ORDER BY ppt_pages_id ASC LIMIT 1 `
  170. o := orm.NewOrm()
  171. o.Using("rddp")
  172. err = o.Raw(sql, pptId).QueryRow(&item)
  173. return
  174. }
  175. func GetPptContentPages(pptId, pptPageId int) (item []*PptPages, err error) {
  176. sql := `SELECT * FROM ppt_pages WHERE ppt_id=? AND ppt_pages_id<>? ORDER BY ppt_pages_id ASC `
  177. o := orm.NewOrm()
  178. o.Using("rddp")
  179. _, err = o.Raw(sql, pptId, pptPageId).QueryRows(&item)
  180. return
  181. }
  182. func EditPptPath(pptId int, pptPath string) (err error) {
  183. sql := `UPDATE ppt SET ppt_url=? WHERE ppt_id=? `
  184. o := orm.NewOrm()
  185. o.Using("rddp")
  186. _, err = o.Raw(sql, pptPath, pptId).Exec()
  187. return
  188. }