ppt_v2.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. package models
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "fmt"
  6. "strings"
  7. "time"
  8. "github.com/rdlucklib/rdluck_tools/paging"
  9. )
  10. // PptV2 表
  11. type PptV2 struct {
  12. PptId int `gorm:"column:ppt_id;primaryKey;autoIncrement:true" description:"ppt的Id"`
  13. TemplateType int `gorm:"column:template_type" description:"模版类型"`
  14. BackgroundImg string `gorm:"column:background_img" description:"背景图片"`
  15. Title string `gorm:"column:title" description:"标题"`
  16. ReportType string `gorm:"column:report_type" description:"报告类型"`
  17. PptDate string `gorm:"column:ppt_date" description:"选择日期"`
  18. Content string `gorm:"column:content" description:"ppt内容"`
  19. PptUrl string `gorm:"column:ppt_url" description:"ppt下载地址"`
  20. PptxUrl string `gorm:"column:pptx_url" description:"pptx下载地址"`
  21. CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
  22. ModifyTime time.Time `gorm:"column:modify_time" description:"修改时间"`
  23. AdminId int `gorm:"column:admin_id" description:"系统用户id"`
  24. AdminRealName string `gorm:"column:admin_real_name" description:"系统用户名称"`
  25. PptVersion int8 `gorm:"column:ppt_version" description:"是否ppt的旧版本;1:旧的,2:新的"`
  26. ReportId int `gorm:"column:report_id" description:"关联的报告ID"`
  27. ReportCode string `gorm:"column:report_code" description:"关联的报告code"`
  28. IsShare int8 `gorm:"column:is_share" description:"是否分享,0:不分享,1:分享"`
  29. PublishTime time.Time `gorm:"column:publish_time" description:"发布时间"`
  30. CoverContent string `gorm:"column:cover_content" description:"PPT内容-JSON"`
  31. PptPage int `gorm:"column:ppt_page" description:"PPT页数"`
  32. TitleSetting string `gorm:"column:title_setting" description:"PPT标题设置"`
  33. ClassifyId int `gorm:"column:classify_id" description:"报告分类ID"`
  34. AddType int `gorm:"column:add_type" description:"新增方式:1-新增报告;2-继承报告"`
  35. InheritReportId int `gorm:"column:inherit_report_id" description:"继承的报告ID"`
  36. CollaborateType int `gorm:"column:collaborate_type" description:"协作方式:1-个人;2-多人协作"`
  37. CollaborateUsers string `gorm:"column:collaborate_users" description:"协作人IDs, 英文逗号分隔"`
  38. IsPublicPublish int `gorm:"column:is_public_publish" description:"是否公开发布:1-是;2-否"`
  39. SubmitTime time.Time `gorm:"column:submit_time" description:"提交时间"`
  40. ApproveTime time.Time `gorm:"column:approve_time" description:"审批时间"`
  41. ReportSource int `gorm:"column:report_source" description:"报告来源:1-系统内;2-智力共享"`
  42. OutReportId string `gorm:"column:out_report_id" description:"外部报告ID(或编码)"`
  43. State int `gorm:"column:state" description:"报告状态:1-未发布;2-已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  44. TopicEndTime time.Time `gorm:"column:topic_end_time" description:"课题结束时间"`
  45. }
  46. type PptV2Item struct {
  47. PptId int `gorm:"column:ppt_id;primaryKey" description:"ppt的Id"`
  48. TemplateType int `gorm:"column:template_type" description:"模版类型"`
  49. BackgroundImg string `gorm:"column:background_img" description:"背景图片"`
  50. Title string `gorm:"column:title" description:"标题"`
  51. ReportType string `gorm:"column:report_type" description:"报告类型"`
  52. PptDate string `gorm:"column:ppt_date" description:"选择日期"`
  53. Content string `gorm:"column:content" description:"ppt内容"`
  54. PptUrl string `gorm:"column:ppt_url" description:"ppt下载地址"`
  55. PptxUrl string `gorm:"column:pptx_url" description:"pptx下载地址"`
  56. CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
  57. ModifyTime time.Time `gorm:"column:modify_time" description:"修改时间"`
  58. AdminId int `gorm:"column:admin_id" description:"系统用户id"`
  59. AdminRealName string `gorm:"column:admin_real_name" description:"系统用户名称"`
  60. PptVersion int8 `gorm:"column:ppt_version" description:"是否ppt的旧版本;1:旧的,2:新的"`
  61. IsAuth bool `gorm:"column:is_auth" description:"true:有操作权限,false:无操作权限"`
  62. ReportId int `gorm:"column:report_id" description:"报告ID"`
  63. ReportCode string `gorm:"column:report_code" description:"关联的报告code"`
  64. IsShare int8 `gorm:"column:is_share" description:"是否分享,0:不分享,1:分享"`
  65. PublishTime time.Time `gorm:"column:publish_time" description:"发布时间"`
  66. CoverContent string `gorm:"column:cover_content" description:"PPT内容-JSON"`
  67. PptPage int `gorm:"column:ppt_page" description:"PPT页数"`
  68. TitleSetting string `gorm:"column:title_setting" description:"PPT标题设置"`
  69. }
  70. func GetPptV2List(condition string, pars []interface{}, startSize, pageSize int) (items []*PptV2Item, err error) {
  71. sql := `SELECT * FROM ppt_v2 WHERE 1=1 `
  72. if condition != "" {
  73. sql += condition
  74. }
  75. //
  76. sql += `ORDER BY modify_time DESC LIMIT ?,?`
  77. pars = append(pars, startSize)
  78. pars = append(pars, pageSize)
  79. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  80. return
  81. }
  82. func GetPptV2ByCondition(condition string, pars []interface{}) (items []*PptV2, err error) {
  83. sql := `SELECT * FROM ppt_v2 WHERE 1=1 `
  84. if condition != "" {
  85. sql += condition
  86. }
  87. //
  88. sql += `ORDER BY modify_time DESC`
  89. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  90. return
  91. }
  92. func GetPptV2ListCount(condition string, pars []interface{}) (count int, err error) {
  93. sql := `SELECT COUNT(1) AS count FROM ppt_v2 WHERE 1=1 `
  94. if condition != "" {
  95. sql += condition
  96. }
  97. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  98. return
  99. }
  100. type PptV2ListResp struct {
  101. List []*PptV2Item
  102. Paging *paging.PagingItem `description:"分页数据"`
  103. }
  104. // AddPptV2 新增PPT
  105. func AddPptV2(item *PptV2) (lastId int64, err error) {
  106. err = global.DmSQL["rddp"].Create(item).Error
  107. lastId = int64(item.PptId)
  108. return
  109. }
  110. // DeletePptV2 删除ppt
  111. func DeletePptV2(pptId int) (err error) {
  112. sql := `DELETE FROM ppt_v2 WHERE ppt_id=? `
  113. err = global.DmSQL["rddp"].Exec(sql, pptId).Error
  114. return
  115. }
  116. type AddPptV2Req struct {
  117. PptId int64 `description:"ppt_id"`
  118. FirstPage struct {
  119. Title string `description:"标题"`
  120. ReportType string `description:"类型"`
  121. PptDate string `description:"日期"`
  122. ImgUrl string `description:"图片"`
  123. BackIndex int `description:"背景图片下标"`
  124. TemplateType int `description:"模版id"`
  125. } `description:"首页"`
  126. Content string `description:"ppt的json数据"`
  127. GroupId int64 `description:"目录id"`
  128. CoverContent string `description:"封面图内容-JSON数据"`
  129. TitleSetting string `description:"PPT标题设置"`
  130. }
  131. type AddPptResp struct {
  132. PptId int64 `description:"PptId"`
  133. }
  134. // Update 更新ppt基础信息
  135. func (item *PptV2) Update(cols []string) (err error) {
  136. err = global.DmSQL["rddp"].Select(cols).Updates(item).Error
  137. return
  138. }
  139. type DeletePptV2Req struct {
  140. PptId int `description:"PptId" `
  141. }
  142. // SavePptV2PathReq 保存ppt的下载地址请求
  143. type SavePptV2PathReq struct {
  144. PptId int `description:"PptId" `
  145. PptxUrl string `description:"PptxUrl" `
  146. }
  147. func GetPptV2ById(pptId int) (item *PptV2, err error) {
  148. sql := `SELECT * FROM ppt_v2 WHERE 1=1 AND ppt_id=? `
  149. err = global.DmSQL["rddp"].Raw(sql, pptId).Find(&item).Error
  150. return
  151. }
  152. func GetPptV2ByIds(pptIds []int) (list []*PptV2, err error) {
  153. err = global.DmSQL["rddp"].Table("ppt_v2").Where("ppt_id IN ?", pptIds).Find(&list).Error
  154. return
  155. }
  156. // EditPptV2Path 编辑Ppt的下载地址
  157. func EditPptV2Path(pptId int, pptxPath string) (err error) {
  158. sql := `UPDATE ppt_v2 SET pptx_url=?,modify_time=NOW(),publish_time=NOW() WHERE ppt_id=? `
  159. err = global.DmSQL["rddp"].Exec(sql, pptxPath, pptId).Error
  160. return
  161. }
  162. // PptV2PublishRecord 发布记录表
  163. type PptV2PublishRecord struct {
  164. Id int `gorm:"primaryKey" `
  165. PptId int
  166. PptUrl string
  167. CreateTime time.Time
  168. }
  169. // AddPptV2PublishRecord 添加发布记录,主要是记录每次发布的时候,当前的ppt
  170. func AddPptV2PublishRecord(item *PptV2PublishRecord) (lastId int64, err error) {
  171. err = global.DmSQL["rddp"].Create(item).Error
  172. lastId = int64(item.Id)
  173. return
  174. }
  175. // PptV2SaveLog ppt记录表
  176. type PptV2SaveLog struct {
  177. Id int `gorm:"column:id;primaryKey;autoIncrement" description:"自增Id"`
  178. PptId int `gorm:"column:ppt_id" description:"ppt的Id"`
  179. TemplateType int `gorm:"column:template_type" description:"模版类型"`
  180. BackgroundImg string `gorm:"column:background_img" description:"背景图片"`
  181. Title string `gorm:"column:title" description:"标题"`
  182. ReportType string `gorm:"column:report_type" description:"报告类型"`
  183. PptDate string `gorm:"column:ppt_date" description:"选择日期"`
  184. Content string `gorm:"column:content" description:"ppt内容"`
  185. AdminId int `gorm:"column:admin_id" description:"系统用户id"`
  186. AdminRealName string `gorm:"column:admin_real_name" description:"系统用户名称"`
  187. CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
  188. CoverContent string `gorm:"column:cover_content" description:"PPT内容-JSON"`
  189. TitleSetting string `gorm:"column:title_setting" description:"PPT标题设置"`
  190. }
  191. // AddPptV2SaveLog 新增PPT日志
  192. func AddPptV2SaveLog(item *PptV2SaveLog) (lastId int64, err error) {
  193. err = global.DmSQL["rddp"].Create(item).Error
  194. lastId = int64(item.Id)
  195. return
  196. }
  197. type PptV2ConfigResp struct {
  198. PptNum int `description:"ppt数量" json:"ppt_num"`
  199. ChartNum int `description:"图片数量" json:"chart_num"`
  200. }
  201. type PPT2ReportReq struct {
  202. PptId int `description:"PPT主键"`
  203. ClassifyId int `description:"报告二级分类ID"`
  204. Title string `description:"标题"`
  205. }
  206. // AddPptV2Multi 批量新增ppt
  207. func AddPptV2Multi(list []*PptV2) (err error) {
  208. err = global.DmSQL["rddp"].CreateInBatches(list, utils.MultiAddNum).Error
  209. return
  210. }
  211. // GetAllPptTitle 获取当前目录的所有名称
  212. func GetAllPptTitle() (names []string, err error) {
  213. sql := "select title from ppt_v2"
  214. err = global.DmSQL["rddp"].Raw(sql).Scan(&names).Error
  215. return
  216. }
  217. // PPT2ReportResp PPT转报告响应体
  218. type PPT2ReportResp struct {
  219. ReportId int `description:"关联的报告ID" json:"report_id"`
  220. ReportCode string `description:"关联的报告编码" json:"report_code"`
  221. }
  222. // GetPptV2ByReportId 通过关联的报告ID获取PPT
  223. func GetPptV2ByReportId(reportId int) (item *PptV2, err error) {
  224. sql := `SELECT * FROM ppt_v2 WHERE 1=1 AND report_id=? LIMIT 1`
  225. err = global.DmSQL["rddp"].Raw(sql, reportId).First(&item).Error
  226. return
  227. }
  228. // GetSharePptV2 获取公开分享的ppt
  229. func GetSharePptV2(IsNewPpt int) (items []*PptV2, err error) {
  230. sql := `SELECT * FROM ppt_v2 WHERE 1=1 AND is_share = 1 `
  231. if IsNewPpt > 0 {
  232. sql += ` AND ppt_version = 2 `
  233. }
  234. sql += `ORDER BY create_time DESC`
  235. err = global.DmSQL["rddp"].Raw(sql).Find(&items).Error
  236. return
  237. }
  238. // GetAllPptV2List 根据条件获取所有的Ppt
  239. func GetAllPptV2List(condition string, pars []interface{}) (items []*PptV2Item, err error) {
  240. sql := `SELECT * FROM ppt_v2 WHERE 1=1 `
  241. if condition != "" {
  242. sql += condition
  243. }
  244. //
  245. sql += `ORDER BY modify_time DESC `
  246. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  247. return
  248. }
  249. type EnPPT2CnReq struct {
  250. PptId int `description:"英文PPT主键"`
  251. GroupId int `description:"目录ID"`
  252. }
  253. type BatchEnPPT2CnReq struct {
  254. PptIds string `description:"英文PPT主键s"`
  255. GroupId int `description:"目录ID"`
  256. }
  257. func GetPptV2ByTitleAndId(title string, adminId int) (item *PptV2, err error) {
  258. sql := `SELECT * FROM ppt_v2 WHERE 1=1 AND title=? AND admin_id=? `
  259. err = global.DmSQL["rddp"].Raw(sql, title, adminId).First(&item).Error
  260. return
  261. }
  262. // PPTEditingReq 标记编辑中请求体
  263. type PPTEditingReq struct {
  264. PptId int `description:"PPT主键ID"`
  265. Status int `description:"标记状态: 1-编辑中; 2-编辑完成"`
  266. }
  267. // PPTDetailResp PPT详情响应体
  268. type PPTDetailResp struct {
  269. *PptV2
  270. Editor PPTEditingCache `description:"编辑人信息"`
  271. HasAuth bool `description:"是否有权限"`
  272. }
  273. // PPTEditingCache PPT编辑缓存信息
  274. type PPTEditingCache struct {
  275. IsEditing bool `description:"是否有人编辑"`
  276. AdminId int `description:"编辑者ID"`
  277. Editor string `description:"编辑者姓名"`
  278. Tips string `description:"提示信息"`
  279. }
  280. func (m *PptV2) TableName() string {
  281. return "ppt_v2"
  282. }
  283. func (m *PptV2) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*PptV2, err error) {
  284. fields := strings.Join(fieldArr, ",")
  285. if len(fieldArr) == 0 {
  286. fields = `*`
  287. }
  288. order := `ORDER BY create_time DESC`
  289. if orderRule != "" {
  290. order = ` ORDER BY ` + orderRule
  291. }
  292. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  293. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  294. return
  295. }
  296. func (m *PptV2) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*PptV2, err error) {
  297. fields := strings.Join(fieldArr, ",")
  298. if len(fieldArr) == 0 {
  299. fields = `*`
  300. }
  301. order := `ORDER BY create_time DESC`
  302. if orderRule != "" {
  303. order = ` ORDER BY ` + orderRule
  304. }
  305. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  306. pars = append(pars, startSize, pageSize)
  307. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  308. return
  309. }
  310. func (m *PptV2) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  311. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  312. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  313. return
  314. }
  315. // PptReportQueryFields 除富文本的常用查询字段
  316. var PptReportQueryFields = []string{
  317. "ppt_id", "title", "classify_id", "ppt_version", "pptx_url", "ppt_page", "title_setting", "state", "report_source", "publish_time", "submit_time", "approve_time", "create_time", "modify_time", "admin_id", "admin_real_name", "collaborate_type", "collaborate_users",
  318. }
  319. type PptReportItem struct {
  320. PptId int `description:"主键Id"`
  321. Title string `description:"标题"`
  322. ClassifyId int `description:"报告分类ID"`
  323. PptVersion int `description:"是否ppt的旧版本;1:旧的,2:新的"`
  324. PptxUrl string `description:"pptx下载地址"`
  325. PptPage int `description:"PPT总页数"`
  326. //Content string `description:"内容"`
  327. TitleSetting string `description:"PPT标题设置"`
  328. State int `description:"报告状态:1-未发布;2-已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  329. ReportSource int `description:"报告来源:1-系统内;2-智力共享"`
  330. PublishTime string `description:"发布时间"`
  331. SubmitTime string `description:"提交时间"`
  332. ApproveTime string `description:"审批时间"`
  333. CreateTime string `description:"创建时间"`
  334. ModifyTime string `description:"更新时间"`
  335. FullClassify string `description:"分类完整路径, /分隔"`
  336. CollaborateType int `description:"协作方式:1-个人;2-多人协作"`
  337. CollaborateUsers []PptReportCollaborateUser `description:"协作人信息"`
  338. HasAuth bool `description:"是否创建人/协作人"`
  339. Editor PPTEditingCache `description:"编辑人信息"`
  340. AdminId int `description:"创建人ID"`
  341. AdminRealName string `description:"创建人姓名"`
  342. }
  343. type PptReportCollaborateUser struct {
  344. AdminId int `description:"用户ID"`
  345. RealName string `description:"用户姓名"`
  346. }
  347. func (m *PptV2) Format2ReportItem(origin *PptV2) (item *PptReportItem) {
  348. if origin == nil {
  349. return
  350. }
  351. item = new(PptReportItem)
  352. item.PptId = origin.PptId
  353. item.Title = origin.Title
  354. item.ClassifyId = origin.ClassifyId
  355. item.PptVersion = int(origin.PptVersion)
  356. item.PptxUrl = origin.PptxUrl
  357. item.PptPage = origin.PptPage
  358. //item.Content = origin.Content
  359. item.TitleSetting = origin.TitleSetting
  360. item.State = origin.State
  361. item.ReportSource = origin.ReportSource
  362. item.PublishTime = utils.TimeTransferString(utils.FormatDateTime, origin.PublishTime)
  363. item.SubmitTime = utils.TimeTransferString(utils.FormatDateTime, origin.SubmitTime)
  364. item.ApproveTime = utils.TimeTransferString(utils.FormatDateTime, origin.ApproveTime)
  365. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  366. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  367. item.AdminId = origin.AdminId
  368. item.AdminRealName = origin.AdminRealName
  369. item.CollaborateType = origin.CollaborateType
  370. return
  371. }
  372. type PptReportClassifyItem struct {
  373. Id int `description:"分类ID"`
  374. ClassifyName string `description:"分类名称"`
  375. Sort int `description:"排序"`
  376. ParentId int `description:"父级分类ID"`
  377. Enabled int `description:"是否可用,1可用,0禁用"`
  378. Level int `description:"层级"`
  379. HasChild int `description:"是否有子级别,0:下面没有子分类,1:下面有子分类;默认:0"`
  380. ClassifyType int `description:"分类类型:1-研报;2-PPT"`
  381. ReportNum int `description:"分类下的报告数"`
  382. PptList []*PptReportItem `description:"ppt报告"`
  383. Child []*PptReportClassifyItem `description:"子分类"`
  384. }
  385. type PptPageReportResp struct {
  386. List []*PptReportItem
  387. Paging *paging.PagingItem `description:"分页数据"`
  388. }
  389. type PptReportCreateReq struct {
  390. Title string `description:"标题"`
  391. ClassifyId int `description:"分类ID"`
  392. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  393. InheritPptId int `description:"待继承的报告ID"`
  394. CollaborateType int `description:"协作方式,1:个人,2:多人协作。默认:1"`
  395. CollaborateUserIds []int `description:"协作人IDs"`
  396. FirstPage struct {
  397. Title string `description:"标题"`
  398. ReportType string `description:"类型"`
  399. PptDate string `description:"日期"`
  400. ImgUrl string `description:"图片"`
  401. BackIndex int `description:"背景图片下标"`
  402. TemplateType int `description:"模版id"`
  403. } `description:"首页"`
  404. Content string `description:"ppt的json数据"`
  405. CoverContent string `description:"封面图内容-JSON数据"`
  406. TitleSetting string `description:"PPT标题设置"`
  407. }
  408. // MovePptReportClassify 转移PPT报告分类
  409. func MovePptReportClassify(newClassifyId, originClassifyId int) (err error) {
  410. sql := `UPDATE ppt_v2 SET classify_id = ? WHERE classify_id = ?`
  411. err = global.DmSQL["rddp"].Exec(sql, newClassifyId, originClassifyId).Error
  412. return
  413. }