material.go 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. package material
  2. import (
  3. "eta/eta_mobile/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "time"
  7. )
  8. type Material struct {
  9. MaterialId int `orm:"column(material_id);pk" description:"素材id"`
  10. MaterialName string `description:"素材名称"`
  11. MaterialNameEn string `description:"英文素材名称"`
  12. ImgUrl string `description:"素材图片地址"`
  13. SysUserId int `description:"作者id"`
  14. SysUserRealName string `description:"作者名称"`
  15. ModifyTime time.Time `description:"修改时间"`
  16. CreateTime time.Time `description:"创建时间"`
  17. ClassifyId int `description:"分类id"`
  18. Sort int `description:"排序"`
  19. }
  20. // Update 素材字段变更
  21. func (material *Material) Update(cols []string) (err error) {
  22. o := orm.NewOrmUsingDB("rddp")
  23. _, err = o.Update(material, cols...)
  24. return
  25. }
  26. // GetMaterialById 根据素材id获取素材详情
  27. func GetMaterialById(MaterialId int) (materialInfo *Material, err error) {
  28. o := orm.NewOrmUsingDB("rddp")
  29. sql := `select * FROM material where material_id = ?`
  30. err = o.Raw(sql, MaterialId).QueryRow(&materialInfo)
  31. return
  32. }
  33. func DeleteByMaterialIds(ids []int) (err error) {
  34. o := orm.NewOrmUsingDB("rddp")
  35. sql := `DELETE FROM material WHERE material_id in (` + utils.GetOrmInReplace(len(ids)) + `)`
  36. _, err = o.Raw(sql, ids).Exec()
  37. return
  38. }
  39. func UpdateClassifyByMaterialIds(ids []int, classifyId int, now time.Time) (err error) {
  40. o := orm.NewOrmUsingDB("rddp")
  41. sql := `UPDATE material SET classify_id=?, modify_time=? WHERE material_id in (` + utils.GetOrmInReplace(len(ids)) + `) and classify_id != ?`
  42. _, err = o.Raw(sql, classifyId, now, ids, classifyId).Exec()
  43. return
  44. }
  45. // AddMultiMaterial 批量添加素材
  46. func AddMultiMaterial(materialInfoList []*Material) (err error) {
  47. o := orm.NewOrmUsingDB("rddp")
  48. _, err = o.InsertMulti(utils.MultiAddNum, materialInfoList)
  49. if err != nil {
  50. return
  51. }
  52. return
  53. }
  54. // MaterialListItem 素材推演列表数据
  55. type MaterialListItem struct {
  56. MaterialId int `description:"素材id"`
  57. MaterialName string `description:"素材名称"`
  58. MaterialNameEn string `description:"英文素材名称"`
  59. ImgUrl string `description:"素材图片地址"`
  60. ModifyTime string `description:"修改时间"`
  61. CreateTime string `description:"创建时间"`
  62. SysUserId int `description:"作者id"`
  63. SysUserRealName string `description:"作者名称"`
  64. }
  65. // MaterialSaveResp 保存素材响应体
  66. type MaterialSaveResp struct {
  67. *Material
  68. }
  69. type MaterialListItems struct {
  70. Material
  71. ModifyTime string `description:"修改时间"`
  72. CreateTime string `description:"创建时间"`
  73. //ParentIds string
  74. }
  75. func GetMaterialListPageByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*MaterialListItems, err error) {
  76. o := orm.NewOrmUsingDB("rddp")
  77. sql := ` SELECT * FROM material WHERE 1=1 `
  78. if condition != "" {
  79. sql += condition
  80. }
  81. sql += " ORDER BY create_time DESC, material_id DESC LIMIT ?,? "
  82. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&item)
  83. return
  84. }
  85. func GetMaterialListByCondition(condition string, pars []interface{}) (item []*MaterialListItems, err error) {
  86. o := orm.NewOrmUsingDB("rddp")
  87. sql := ` SELECT * FROM material WHERE 1=1 `
  88. if condition != "" {
  89. sql += condition
  90. }
  91. sql += " ORDER BY create_time DESC, material_id DESC"
  92. _, err = o.Raw(sql, pars).QueryRows(&item)
  93. return
  94. }
  95. func GetMaterialListCountByCondition(condition string, pars []interface{}) (count int, err error) {
  96. o := orm.NewOrmUsingDB("rddp")
  97. sql := ` SELECT COUNT(1) AS count FROM material WHERE 1=1 `
  98. if condition != "" {
  99. sql += condition
  100. }
  101. err = o.Raw(sql, pars).QueryRow(&count)
  102. return
  103. }
  104. type MaterialListResp struct {
  105. Paging *paging.PagingItem
  106. List []*MaterialListItems
  107. }
  108. func AddMaterial(item *Material) (lastId int64, err error) {
  109. o := orm.NewOrmUsingDB("rddp")
  110. lastId, err = o.Insert(item)
  111. return
  112. }
  113. // GetMaterialByClassifyIdAndName 根据分类id和素材名获取图表信息
  114. func GetMaterialByClassifyIdAndName(classifyId int, name string) (item *Material, err error) {
  115. o := orm.NewOrmUsingDB("rddp")
  116. sql := ` SELECT * FROM material WHERE classify_id = ? and material_name=? `
  117. err = o.Raw(sql, classifyId, name).QueryRow(&item)
  118. return
  119. }
  120. // GetMaterialByIds 根据素材id获取素材信息
  121. func GetMaterialByIds(ids []int) (items []*MaterialListItems, err error) {
  122. o := orm.NewOrmUsingDB("rddp")
  123. sql := ` SELECT * FROM material WHERE material_id in (` + utils.GetOrmInReplace(len(ids)) + `) `
  124. _, err = o.Raw(sql, ids).QueryRows(&items)
  125. return
  126. }
  127. // SaveAsMaterialReq 添加素材的请求数据
  128. type SaveAsMaterialReq struct {
  129. MaterialName string `description:"素材名称"`
  130. ClassifyId int `description:"分类id"`
  131. ObjectId int `description:"对象id"`
  132. ObjectType string `description:"对象类型:chart,excel,sandbox,sa_doc"`
  133. }
  134. // MyChartSaveAsMaterialReq 添加素材的
  135. type MyChartSaveAsMaterialReq struct {
  136. MaterialList []*MyChartSaveAsMaterialItem
  137. }
  138. type MyChartSaveAsMaterialItem struct {
  139. MaterialName string `description:"素材名称"`
  140. ChartInfoId int `description:"图表id"`
  141. MyChartId int `description:"我的图表ID"`
  142. ClassifyId int `description:"分类id"`
  143. }
  144. // BatchAddMaterialReq 批量添加素材的请求数据
  145. type BatchAddMaterialReq struct {
  146. MaterialList []BatchAddMaterialItem
  147. ClassifyId int `description:"分类id"`
  148. }
  149. type BatchAddMaterialItem struct {
  150. MaterialName string `description:"素材名称"`
  151. ImgUrl string `description:"素材图片地址"`
  152. }
  153. // DeleteMaterial 删除素材的请求数据
  154. type DeleteMaterial struct {
  155. MaterialId int `description:"素材id"`
  156. }
  157. // BatchDeleteMaterialReq 删除素材的请求数据
  158. type BatchDeleteMaterialReq struct {
  159. MaterialIds []int `description:"素材id"`
  160. ClassifyId int `description:"分类id"`
  161. IsShowMe bool `description:"操作人id,支持多选,用英文,隔开"`
  162. Keyword string `description:"关键字"`
  163. IsSelectAll bool `description:"是否选择所有素材"`
  164. }
  165. type BatchChangeClassifyMaterialReq struct {
  166. BatchDeleteMaterialReq
  167. NewClassifyId int `description:"新分类ID"`
  168. }
  169. type ChangeClassifyMaterialReq struct {
  170. MaterialId int `description:"素材id"`
  171. NewClassifyId int `description:"新分类ID"`
  172. }
  173. // RenameMaterialReq 添加/编辑素材的请求数据
  174. type RenameMaterialReq struct {
  175. MaterialId int `description:"素材id"`
  176. MaterialName string `description:"素材名称"`
  177. }
  178. func GetMaterialInfoCountByClassifyIds(classifyIds []string) (count int, err error) {
  179. o := orm.NewOrmUsingDB("rddp")
  180. sql := ` SELECT COUNT(1) AS count FROM material WHERE classify_id in(` + utils.GetOrmInReplace(len(classifyIds)) + `)`
  181. err = o.Raw(sql, classifyIds).QueryRow(&count)
  182. return
  183. }
  184. func GetMaterialByNames(materialNames []string) (items []*Material, err error) {
  185. o := orm.NewOrmUsingDB("rddp")
  186. sql := `SELECT * FROM material WHERE material_name in (` + utils.GetOrmInReplace(len(materialNames)) + `) limit 1`
  187. _, err = o.Raw(sql, materialNames).QueryRows(&items)
  188. return
  189. }
  190. func GetMaterialByNameEns(materialNames []string) (items []*Material, err error) {
  191. o := orm.NewOrmUsingDB("rddp")
  192. sql := `SELECT * FROM material WHERE material_name_en in (` + utils.GetOrmInReplace(len(materialNames)) + `) limit 1`
  193. _, err = o.Raw(sql, materialNames).QueryRows(&items)
  194. return
  195. }
  196. func GetMaterialByName(materialName string) (item *Material, err error) {
  197. o := orm.NewOrmUsingDB("rddp")
  198. sql := `SELECT * FROM material WHERE material_name = ?`
  199. err = o.Raw(sql, materialName).QueryRow(&item)
  200. return
  201. }
  202. func GetMaterialByNameEn(materialName string) (item *Material, err error) {
  203. o := orm.NewOrmUsingDB("rddp")
  204. sql := `SELECT * FROM material WHERE material_name_en = ?`
  205. err = o.Raw(sql, materialName).QueryRow(&item)
  206. return
  207. }
  208. // GetMaterialMaxSort 获取最大的排序数
  209. func GetMaterialMaxSort() (sort int, err error) {
  210. o := orm.NewOrmUsingDB("rddp")
  211. sql := `SELECT MAX(sort) AS sort FROM material `
  212. err = o.Raw(sql).QueryRow(&sort)
  213. return
  214. }