report.go 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286
  1. package models
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta_gn/eta_api/global"
  6. "eta_gn/eta_api/utils"
  7. "fmt"
  8. "strings"
  9. "time"
  10. "github.com/rdlucklib/rdluck_tools/paging"
  11. "gorm.io/gorm"
  12. )
  13. // 报告状态
  14. const (
  15. ReportStateUnpublished = 1 // 未发布
  16. ReportStatePublished = 2 // 已发布
  17. ReportStateWaitSubmit = 3 // 待提交
  18. ReportStateWaitApprove = 4 // 审批中
  19. ReportStateRefused = 5 // 已驳回
  20. ReportStatePass = 6 // 已通过
  21. )
  22. // 报告操作
  23. const (
  24. ReportOperateAdd = 1 // 新增报告
  25. ReportOperateEdit = 2 // 编辑报告
  26. ReportOperatePublish = 3 // 发布报告
  27. ReportOperateCancelPublish = 4 // 取消发布报告
  28. ReportOperateSubmitApprove = 5 // 提交审批
  29. ReportOperateCancelApprove = 6 // 撤回审批
  30. )
  31. type Report struct {
  32. Id int `gorm:"column:id;primaryKey;autoIncrement" description:"报告Id"`
  33. AddType int `gorm:"column:add_type" description:"新增方式:1:新增报告,2:继承报告"`
  34. ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类id"`
  35. ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
  36. ClassifyIdSecond int `gorm:"column:classify_id_second" description:"二级分类id"`
  37. ClassifyNameSecond string `gorm:"column:classify_name_second" description:"二级分类名称"`
  38. Title string `gorm:"column:title" description:"标题"`
  39. Abstract string `gorm:"column:abstract" description:"摘要"`
  40. Author string `gorm:"column:author" description:"作者"`
  41. Frequency string `gorm:"column:frequency" description:"频度"`
  42. CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
  43. ModifyTime time.Time `gorm:"column:modify_time;autoUpdateTime" description:"修改时间"`
  44. State int `gorm:"column:state" description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  45. PublishTime time.Time `gorm:"column:publish_time" description:"发布时间"`
  46. Stage int `gorm:"column:stage" description:"期数"`
  47. MsgIsSend int `gorm:"column:msg_is_send" description:"消息是否已发送,0:否,1:是"`
  48. ThsMsgIsSend int `gorm:"column:ths_msg_is_send" description:"客户群消息是否已发送,0:否,1:是"`
  49. Content string `gorm:"column:content" description:"内容"`
  50. VideoUrl string `gorm:"column:video_url" description:"音频文件URL"`
  51. VideoName string `gorm:"column:video_name" description:"音频文件名称"`
  52. VideoPlaySeconds string `gorm:"column:video_play_seconds" description:"音频播放时长"`
  53. VideoSize string `gorm:"column:video_size" description:"音频文件大小,单位M"`
  54. ContentSub string `gorm:"column:content_sub" description:"内容前两个章节"`
  55. ReportCode string `gorm:"column:report_code" description:"报告唯一编码"`
  56. ReportVersion int `gorm:"column:report_version" description:"1:旧版,2:新版"`
  57. HasChapter int `gorm:"column:has_chapter" description:"是否有章节 0-否 1-是"`
  58. ChapterType string `gorm:"column:chapter_type" description:"章节类型 day-晨报 week-周报"`
  59. OldReportId int `gorm:"column:old_report_id" description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  60. MsgSendTime time.Time `gorm:"column:msg_send_time" description:"模版消息发送时间"`
  61. AdminId int `gorm:"column:admin_id" description:"创建者账号"`
  62. AdminRealName string `gorm:"column:admin_real_name" description:"创建者姓名"`
  63. ApproveTime time.Time `gorm:"column:approve_time" description:"审批时间"`
  64. ApproveId int `gorm:"column:approve_id" description:"审批ID"`
  65. DetailImgUrl string `gorm:"column:detail_img_url" description:"报告详情长图地址"`
  66. DetailPdfUrl string `gorm:"column:detail_pdf_url" description:"报告详情PDF地址"`
  67. ContentStruct string `gorm:"column:content_struct" description:"内容组件"`
  68. LastModifyAdminId int `gorm:"column:last_modify_admin_id" description:"最后更新人ID"`
  69. LastModifyAdminName string `gorm:"column:last_modify_admin_name" description:"最后更新人姓名"`
  70. ContentModifyTime time.Time `gorm:"column:content_modify_time" description:"内容更新时间"`
  71. Pv int `gorm:"column:pv" description:"pv"`
  72. Uv int `gorm:"column:uv" description:"uv"`
  73. HeadImg string `gorm:"column:head_img" description:"报告头图地址"`
  74. EndImg string `gorm:"column:end_img" description:"报告尾图地址"`
  75. CanvasColor string `gorm:"column:canvas_color" description:"画布颜色"`
  76. NeedSplice int `gorm:"column:need_splice" description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  77. HeadResourceId int `gorm:"column:head_resource_id" description:"版头资源ID"`
  78. EndResourceId int `gorm:"column:end_resource_id" description:"版尾资源ID"`
  79. ClassifyIdThird int `gorm:"column:classify_id_third" description:"三级分类id"`
  80. ClassifyNameThird string `gorm:"column:classify_name_third" description:"三级分类名称"`
  81. CollaborateType int8 `gorm:"column:collaborate_type" description:"协作方式,1:个人,2:多人协作。默认:1"`
  82. ReportLayout int8 `gorm:"column:report_layout" description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  83. IsPublicPublish int8 `gorm:"column:is_public_publish" description:"是否公开发布,1:是,2:否"`
  84. ReportCreateTime time.Time `gorm:"column:report_create_time" description:"报告时间创建时间"`
  85. InheritReportId int `gorm:"column:inherit_report_id" description:"待继承的报告ID"`
  86. VoiceGenerateType int `gorm:"column:voice_generate_type" description:"音频生成方式,0:系统生成,1:人工上传"`
  87. ReportSource int `gorm:"column:report_source" description:"报告来源:1-系统内;2-智力共享"`
  88. OutReportId string `gorm:"column:out_report_id" description:"外部报告ID(或编码)"`
  89. PrePublishTime *time.Time `gorm:"column:pre_publish_time" description:"预发布时间"`
  90. PreMsgSend int `gorm:"column:pre_msg_send" description:"定时发布成功后是否立即推送模版消息,0:未发送,1:已发送"`
  91. TopicEndTime time.Time `gorm:"column:topic_end_time" description:"课题结束时间"`
  92. }
  93. type ReportList struct {
  94. Id int `gorm:"column:id" description:"报告Id"`
  95. AddType int `gorm:"column:add_type" description:"新增方式:1:新增报告,2:继承报告"`
  96. ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类id"`
  97. ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
  98. ClassifyIdSecond int `gorm:"column:classify_id_second" description:"二级分类id"`
  99. ClassifyNameSecond string `gorm:"column:classify_name_second" description:"二级分类名称"`
  100. Title string `gorm:"column:title" description:"标题"`
  101. Abstract string `gorm:"column:abstract" description:"摘要"`
  102. Author string `gorm:"column:author" description:"作者"`
  103. Frequency string `gorm:"column:frequency" description:"频度"`
  104. CreateTime *global.LocalTime `gorm:"column:create_time" description:"创建时间"`
  105. ModifyTime *global.LocalTime `gorm:"column:modify_time;autoUpdateTime" description:"修改时间"`
  106. State int `gorm:"column:state" description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  107. PublishTime *global.LocalTime `gorm:"column:publish_time" description:"发布时间"`
  108. PrePublishTime string `gorm:"column:pre_publish_time" description:"预发布时间"`
  109. Stage int `gorm:"column:stage" description:"期数"`
  110. MsgIsSend int `gorm:"column:msg_is_send" description:"模板消息是否已发送,0:否,1:是"`
  111. Content string `gorm:"column:content" description:"内容"`
  112. VideoUrl string `gorm:"column:video_url" description:"音频文件URL"`
  113. VideoName string `gorm:"column:video_name" description:"音频文件名称"`
  114. VideoPlaySeconds string `gorm:"column:video_play_seconds" description:"音频播放时长"`
  115. ContentSub string `gorm:"column:content_sub" description:"内容前两个章节"`
  116. Pv int `gorm:"column:pv" description:"Pv"`
  117. Uv int `gorm:"column:uv" description:"Uv"`
  118. ReportCode string `gorm:"column:report_code" description:"报告唯一编码"`
  119. ReportVersion int `gorm:"column:report_version" description:"1:旧版,2:新版"`
  120. ThsMsgIsSend int `gorm:"column:ths_msg_is_send" description:"客户群消息是否已发送,0:否,1:是"`
  121. NeedThsMsg int `gorm:"column:need_ths_msg" description:"是否需要推送客群消息 0-否 1-是"`
  122. HasChapter int `gorm:"column:has_chapter" description:"是否有章节 0-否 1-是"`
  123. ChapterType string `gorm:"column:chapter_type" description:"章节类型 day-晨报 week-周报"`
  124. ChapterVideoList []*ReportChapterVideoList `gorm:"-" description:"章节音频列表"` // 不映射到数据库
  125. OldReportId int `gorm:"column:old_report_id" description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  126. MsgSendTime *global.LocalTime `gorm:"column:msg_send_time" description:"模版消息发送时间"`
  127. CanEdit bool `gorm:"column:can_edit" description:"是否可编辑"`
  128. HasAuth bool `gorm:"column:has_auth" description:"是否可操作"`
  129. Editor string `gorm:"column:editor" description:"编辑人"`
  130. AdminId int `gorm:"column:admin_id" description:"创建者账号"`
  131. AdminRealName string `gorm:"column:admin_real_name" description:"创建者姓名"`
  132. ApproveTime *global.LocalTime `gorm:"column:approve_time" description:"审批时间"`
  133. DetailImgUrl string `gorm:"column:detail_img_url" description:"报告详情长图地址"`
  134. DetailPdfUrl string `gorm:"column:detail_pdf_url" description:"报告详情PDF地址"`
  135. CollaborateType int8 `gorm:"column:collaborate_type" description:"协作方式,1:个人,2:多人协作。默认:1"`
  136. ReportLayout int8 `gorm:"column:report_layout" description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  137. IsPublicPublish int8 `gorm:"column:is_public_publish" description:"是否公开发布,1:是,2:否"`
  138. ReportCreateTime *global.LocalTime `gorm:"column:report_create_time" description:"报告时间创建时间"`
  139. ContentStruct string `gorm:"column:content_struct" description:"内容组件"`
  140. LastModifyAdminId int `gorm:"column:last_modify_admin_id" description:"最后更新人ID"`
  141. LastModifyAdminName string `gorm:"column:last_modify_admin_name" description:"最后更新人姓名"`
  142. ContentModifyTime *global.LocalTime `gorm:"column:content_modify_time" description:"内容更新时间"`
  143. HeadImg string `gorm:"column:head_img" description:"报告头图地址"`
  144. EndImg string `gorm:"column:end_img" description:"报告尾图地址"`
  145. CanvasColor string `gorm:"column:canvas_color" description:"画布颜色"`
  146. NeedSplice int `gorm:"column:need_splice" description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  147. HeadResourceId int `gorm:"column:head_resource_id" description:"版头资源ID"`
  148. EndResourceId int `gorm:"column:end_resource_id" description:"版尾资源ID"`
  149. ClassifyIdThird int `gorm:"column:classify_id_third" description:"三级分类id"`
  150. ClassifyNameThird string `gorm:"column:classify_name_third" description:"三级分类名称"`
  151. InheritReportId int `gorm:"column:inherit_report_id" description:"待继承的报告ID"`
  152. ReportSource int `gorm:"column:report_source" description:"报告来源:1-系统内;2-智力共享"`
  153. }
  154. type ReportListResp struct {
  155. List []*ReportList
  156. Paging *paging.PagingItem `description:"分页数据"`
  157. }
  158. // GetReportListCountV1
  159. // @Description: 获取普通报告列表的报告数量
  160. // @author: Roc
  161. // @datetime 2024-05-30 15:14:43
  162. // @param condition string
  163. // @param pars []interface{}
  164. // @return count int
  165. // @return err error
  166. func GetReportListCountV1(condition string, pars []interface{}) (count int, err error) {
  167. sql := `SELECT COUNT(1) AS count FROM report as a WHERE 1=1 `
  168. if condition != "" {
  169. sql += condition
  170. }
  171. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  172. return
  173. }
  174. // func GetReportListCountV1(condition string, pars []interface{}) (count int, err error) {
  175. // sql := `SELECT COUNT(1) AS count FROM report as a
  176. // LEFT JOIN classify_visible c ON (
  177. // CASE
  178. // WHEN a.classify_id_third > 0 THEN a.classify_id_third
  179. // WHEN a.classify_id_second > 0 THEN a.classify_id_second
  180. // ELSE a.classify_id_first
  181. // END
  182. // ) = c.classify_id AND c.admin_id =?
  183. // WHERE 1=1 AND (c.admin_id IS NULL OR c.admin_id =?) AND a.id NOT IN (
  184. // SELECT id FROM report ta
  185. // JOIN classify_visible tb ON (
  186. // CASE
  187. // WHEN ta.classify_id_third > 0 THEN ta.classify_id_third
  188. // WHEN ta.classify_id_second > 0 THEN ta.classify_id_second
  189. // ELSE ta.classify_id_first
  190. // END
  191. // ) = tb.classify_id
  192. // GROUP BY ta."id"
  193. // HAVING SUM(CASE WHEN tb.admin_id = ? THEN 1 ELSE 0 END) = 0
  194. // ) `
  195. // if condition != "" {
  196. // sql += condition
  197. // }
  198. // err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  199. // return
  200. // }
  201. // GetReportListV1
  202. // @Description: 获取普通报告列表的数据
  203. // @author: Roc
  204. // @datetime 2024-05-30 15:14:25
  205. // @param condition string
  206. // @param pars []interface{}
  207. // @param startSize int
  208. // @param pageSize int
  209. // @return items []*ReportList
  210. // @return err error
  211. func GetReportListV1(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  212. sql := `SELECT * FROM report as a WHERE 1=1 `
  213. if condition != "" {
  214. sql += condition
  215. }
  216. // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  217. sql += `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
  218. pars = append(pars, startSize)
  219. pars = append(pars, pageSize)
  220. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  221. return
  222. }
  223. // func GetReportListV1(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  224. // sql := `SELECT * FROM report as a
  225. // LEFT JOIN classify_visible c ON (
  226. // CASE
  227. // WHEN a.classify_id_third > 0 THEN a.classify_id_third
  228. // WHEN a.classify_id_second > 0 THEN a.classify_id_second
  229. // ELSE a.classify_id_first
  230. // END
  231. // ) = c.classify_id AND c.admin_id =?
  232. // WHERE 1=1 AND (c.admin_id IS NULL OR c.admin_id =?) AND a.id NOT IN (
  233. // SELECT id FROM report ta
  234. // JOIN classify_visible tb ON (
  235. // CASE
  236. // WHEN ta.classify_id_third > 0 THEN ta.classify_id_third
  237. // WHEN ta.classify_id_second > 0 THEN ta.classify_id_second
  238. // ELSE ta.classify_id_first
  239. // END
  240. // ) = tb.classify_id
  241. // GROUP BY ta."id"
  242. // HAVING SUM(CASE WHEN tb.admin_id = ? THEN 1 ELSE 0 END) = 0
  243. // ) `
  244. // if condition != "" {
  245. // sql += condition
  246. // }
  247. // // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  248. // sql += `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
  249. // pars = append(pars, startSize)
  250. // pars = append(pars, pageSize)
  251. // err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  252. // return
  253. // }
  254. type ReportPvUv struct {
  255. ReportId int
  256. PvTotal int
  257. UvTotal int
  258. }
  259. func GetReportPvUvByReportIdList(reportIdList []int) (items []ReportPvUv, err error) {
  260. num := len(reportIdList)
  261. if num <= 0 {
  262. return
  263. }
  264. sql := `SELECT report_id, COUNT(1) as pv_total,COUNT(DISTINCT user_id) as uv_total FROM report_view_record WHERE report_id in (` + utils.GetOrmInReplace(num) + `) GROUP BY report_id`
  265. err = global.DmSQL["rddp"].Raw(sql, reportIdList).Find(&items).Error
  266. return
  267. }
  268. // GetReportListCountByGrant
  269. // @Description: 获取共享报告列表的报告数量
  270. // @author: Roc
  271. // @datetime 2024-05-30 15:14:01
  272. // @param condition string
  273. // @param pars []interface{}
  274. // @return count int
  275. // @return err error
  276. func GetReportListCountByGrant(condition string, pars []interface{}) (count int, err error) {
  277. sql := `SELECT a.id FROM report as a
  278. JOIN report_grant b on a.id=b.report_id
  279. WHERE 1=1 `
  280. if condition != "" {
  281. sql += condition
  282. }
  283. sql += " GROUP BY a.id "
  284. sql = `SELECT COUNT(1) AS count FROM (` + sql + `) d`
  285. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  286. return
  287. }
  288. // func GetReportListCountByGrant(condition string, pars []interface{}) (count int, err error) {
  289. // sql := `SELECT a.id FROM report as a
  290. // JOIN report_grant b on a.id=b.report_id
  291. // LEFT JOIN classify_visible c ON (
  292. // CASE
  293. // WHEN a.classify_id_third > 0 THEN a.classify_id_third
  294. // WHEN a.classify_id_second > 0 THEN a.classify_id_second
  295. // ELSE a.classify_id_first
  296. // END
  297. // ) = c.classify_id AND c.admin_id =?
  298. // WHERE 1=1 AND (c.admin_id IS NULL OR c.admin_id =?) AND a.id NOT IN (
  299. // SELECT id FROM report ta
  300. // JOIN classify_visible tb ON (
  301. // CASE
  302. // WHEN ta.classify_id_third > 0 THEN ta.classify_id_third
  303. // WHEN ta.classify_id_second > 0 THEN ta.classify_id_second
  304. // ELSE ta.classify_id_first
  305. // END
  306. // ) = tb.classify_id
  307. // GROUP BY ta."id"
  308. // HAVING SUM(CASE WHEN tb.admin_id = ? THEN 1 ELSE 0 END) = 0
  309. // ) `
  310. // if condition != "" {
  311. // sql += condition
  312. // }
  313. // sql += " GROUP BY a.id "
  314. // sql = `SELECT COUNT(1) AS count FROM (` + sql + `) d`
  315. // err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  316. // return
  317. // }
  318. // GetReportListByGrant
  319. // @Description: 获取共享报告列表的数据
  320. // @author: Roc
  321. // @datetime 2024-05-30 15:15:07
  322. // @param condition string
  323. // @param pars []interface{}
  324. // @param startSize int
  325. // @param pageSize int
  326. // @return items []*ReportList
  327. // @return err error
  328. func GetReportListByGrant(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  329. sql := `SELECT a.id,a.add_type,a.classify_id_first,a.classify_name_first,a.classify_id_second,a.classify_name_second,a.title,a.abstract,a.author,a.frequency,a.create_time,a.modify_time,a.state,a.publish_time,a.pre_publish_time,a.stage,a.msg_is_send,a.pre_msg_send,a.video_url,a.video_name,a.video_play_seconds,a.report_code,a.video_size,a.report_version,a.ths_msg_is_send,a.has_chapter,a.chapter_type,a.old_report_id,a.msg_send_time,a.admin_id,a.admin_real_name,a.approve_time,a.approve_id,a.detail_img_url,a.detail_pdf_url,a.last_modify_admin_id,a.last_modify_admin_name,a.content_modify_time,a.pv,a.uv,a.canvas_color,a.need_splice,a.head_resource_id,a.end_resource_id,a.classify_id_third,a.classify_name_third,a.collaborate_type,a.report_layout,a.is_public_publish,a.report_create_time,a.inherit_report_id,a.voice_generate_type,a.report_source FROM report as a JOIN report_grant b on a.id = b.report_id WHERE 1=1 `
  330. if condition != "" {
  331. sql += condition
  332. }
  333. // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  334. sql += ` GROUP BY a.id,a.add_type,a.classify_id_first,a.classify_name_first,a.classify_id_second,a.classify_name_second,a.title,a.abstract,a.author,a.frequency,a.create_time,a.modify_time,a.state,a.publish_time,a.pre_publish_time,a.stage,a.msg_is_send,a.pre_msg_send,a.video_url,a.video_name,a.video_play_seconds,a.report_code,a.video_size,a.report_version,a.ths_msg_is_send,a.has_chapter,a.chapter_type,a.old_report_id,a.msg_send_time,a.admin_id,a.admin_real_name,a.approve_time,a.approve_id,a.detail_img_url,a.detail_pdf_url,a.last_modify_admin_id,a.last_modify_admin_name,a.content_modify_time,a.pv,a.uv,a.canvas_color,a.need_splice,a.head_resource_id,a.end_resource_id,a.classify_id_third,a.classify_name_third,a.collaborate_type,a.report_layout,a.is_public_publish,a.report_create_time,a.inherit_report_id,a.voice_generate_type,a.report_source
  335. ORDER BY CASE a."state"
  336. WHEN 3 THEN 1
  337. WHEN 1 THEN 2
  338. WHEN 4 THEN 3
  339. WHEN 5 THEN 4
  340. WHEN 6 THEN 5
  341. ELSE 6
  342. END, a.modify_time DESC LIMIT ?,?`
  343. pars = append(pars, startSize)
  344. pars = append(pars, pageSize)
  345. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  346. return
  347. }
  348. // func GetReportListByGrant(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  349. // sql := `SELECT a.id,a.add_type,a.classify_id_first,a.classify_name_first,a.classify_id_second,a.classify_name_second,a.title,a.abstract,a.author,a.frequency,a.create_time,a.modify_time,a.state,a.publish_time,a.pre_publish_time,a.stage,a.msg_is_send,a.pre_msg_send,a.video_url,a.video_name,a.video_play_seconds,a.report_code,a.video_size,a.report_version,a.ths_msg_is_send,a.has_chapter,a.chapter_type,a.old_report_id,a.msg_send_time,a.admin_id,a.admin_real_name,a.approve_time,a.approve_id,a.detail_img_url,a.detail_pdf_url,a.last_modify_admin_id,a.last_modify_admin_name,a.content_modify_time,a.pv,a.uv,a.canvas_color,a.need_splice,a.head_resource_id,a.end_resource_id,a.classify_id_third,a.classify_name_third,a.collaborate_type,a.report_layout,a.is_public_publish,a.report_create_time,a.inherit_report_id,a.voice_generate_type,a.report_source FROM report as a JOIN report_grant b on a.id = b.report_id
  350. // LEFT JOIN classify_visible c ON (
  351. // CASE
  352. // WHEN a.classify_id_third > 0 THEN a.classify_id_third
  353. // WHEN a.classify_id_second > 0 THEN a.classify_id_second
  354. // ELSE a.classify_id_first
  355. // END
  356. // ) = c.classify_id AND c.admin_id =?
  357. // WHERE 1=1 AND (c.admin_id IS NULL OR c.admin_id =?) AND a.id NOT IN (
  358. // SELECT id FROM report ta
  359. // JOIN classify_visible tb ON (
  360. // CASE
  361. // WHEN ta.classify_id_third > 0 THEN ta.classify_id_third
  362. // WHEN ta.classify_id_second > 0 THEN ta.classify_id_second
  363. // ELSE ta.classify_id_first
  364. // END
  365. // ) = tb.classify_id
  366. // GROUP BY ta."id"
  367. // HAVING SUM(CASE WHEN tb.admin_id = ? THEN 1 ELSE 0 END) = 0
  368. // ) `
  369. // if condition != "" {
  370. // sql += condition
  371. // }
  372. // // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  373. // sql += ` GROUP BY a.id,a.add_type,a.classify_id_first,a.classify_name_first,a.classify_id_second,a.classify_name_second,a.title,a.abstract,a.author,a.frequency,a.create_time,a.modify_time,a.state,a.publish_time,a.pre_publish_time,a.stage,a.msg_is_send,a.pre_msg_send,a.video_url,a.video_name,a.video_play_seconds,a.report_code,a.video_size,a.report_version,a.ths_msg_is_send,a.has_chapter,a.chapter_type,a.old_report_id,a.msg_send_time,a.admin_id,a.admin_real_name,a.approve_time,a.approve_id,a.detail_img_url,a.detail_pdf_url,a.last_modify_admin_id,a.last_modify_admin_name,a.content_modify_time,a.pv,a.uv,a.canvas_color,a.need_splice,a.head_resource_id,a.end_resource_id,a.classify_id_third,a.classify_name_third,a.collaborate_type,a.report_layout,a.is_public_publish,a.report_create_time,a.inherit_report_id,a.voice_generate_type,a.report_source
  374. // ORDER BY CASE a."state"
  375. // WHEN 3 THEN 1
  376. // WHEN 1 THEN 2
  377. // WHEN 4 THEN 3
  378. // WHEN 5 THEN 4
  379. // WHEN 6 THEN 5
  380. // ELSE 6
  381. // END, a.modify_time DESC LIMIT ?,?`
  382. // pars = append(pars, startSize)
  383. // pars = append(pars, pageSize)
  384. // err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  385. // return
  386. // }
  387. func GetReportListCount(condition string, pars []interface{}) (count int, err error) {
  388. sql := `SELECT COUNT(1) AS count FROM report WHERE 1=1 `
  389. if condition != "" {
  390. sql += condition
  391. }
  392. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  393. return
  394. }
  395. // PublishCancelReport 取消发布报告
  396. func PublishCancelReport(reportId, state int, publishTimeNullFlag bool, lastModifyAdminId int, lastModifyAdminName string) (err error) {
  397. var sql string
  398. if publishTimeNullFlag {
  399. sql = ` UPDATE report SET state=?, publish_time=null, pre_publish_time=null, pre_msg_send=0,last_modify_admin_id=?,last_modify_admin_name=?,modify_time = NOW() WHERE id =?`
  400. } else {
  401. sql = ` UPDATE report SET state=?, pre_publish_time=null, pre_msg_send=0,last_modify_admin_id=?,last_modify_admin_name=?,modify_time = NOW() WHERE id =?`
  402. }
  403. err = global.DmSQL["rddp"].Exec(sql, state, lastModifyAdminId, lastModifyAdminName, reportId).Error
  404. return
  405. }
  406. // 删除报告
  407. func DeleteReport(reportIds int) (err error) {
  408. sql := ` DELETE FROM report WHERE id =? `
  409. err = global.DmSQL["rddp"].Exec(sql, reportIds).Error
  410. return
  411. }
  412. type ReportDetail struct {
  413. Id int `gorm:"column:id;primary_key;autoIncrement" description:"报告Id"`
  414. AddType int `gorm:"column:add_type" description:"新增方式:1:新增报告,2:继承报告"`
  415. ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类id"`
  416. ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
  417. ClassifyIdSecond int `gorm:"column:classify_id_second" description:"二级分类id"`
  418. ClassifyNameSecond string `gorm:"column:classify_name_second" description:"二级分类名称"`
  419. Title string `gorm:"column:title" description:"标题"`
  420. Abstract string `gorm:"column:abstract" description:"摘要"`
  421. Author string `gorm:"column:author" description:"作者"`
  422. Frequency string `gorm:"column:frequency" description:"频度"`
  423. CreateTime string `gorm:"column:create_time" description:"创建时间"`
  424. ModifyTime string `gorm:"column:modify_time" description:"修改时间"`
  425. State int `gorm:"column:state" description:"1:未发布,2:已发布"`
  426. PublishTime string `gorm:"column:publish_time" description:"发布时间"`
  427. PrePublishTime string `gorm:"column:pre_publish_time" description:"预发布时间"`
  428. Stage int `gorm:"column:stage" description:"期数"`
  429. MsgIsSend int `gorm:"column:msg_is_send" description:"消息是否已发送,0:否,1:是"`
  430. PreMsgSend int `gorm:"column:pre_msg_send" description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  431. Content string `gorm:"column:content" description:"内容"`
  432. VideoUrl string `gorm:"column:video_url" description:"音频文件URL"`
  433. VideoName string `gorm:"column:video_name" description:"音频文件名称"`
  434. VideoPlaySeconds string `gorm:"column:video_play_seconds" description:"音频播放时长"`
  435. ContentSub string `gorm:"column:content_sub" description:"内容前两个章节"`
  436. ThsMsgIsSend int `gorm:"column:ths_msg_is_send" description:"客户群消息是否已发送,0:否,1:是"`
  437. HasChapter int `gorm:"column:has_chapter" description:"是否有章节 0-否 1-是"`
  438. ChapterType string `gorm:"column:chapter_type" description:"章节类型 day-晨报 week-周报"`
  439. AdminId int `gorm:"column:admin_id" description:"创建者账号"`
  440. AdminRealName string `gorm:"column:admin_real_name" description:"创建者姓名"`
  441. ReportCode string `gorm:"column:report_code" description:"报告唯一编码"`
  442. ContentStruct string `gorm:"column:content_struct" description:"内容组件"`
  443. LastModifyAdminId int `gorm:"column:last_modify_admin_id" description:"最后更新人ID"`
  444. LastModifyAdminName string `gorm:"column:last_modify_admin_name" description:"最后更新人姓名"`
  445. ContentModifyTime string `gorm:"column:content_modify_time" description:"内容更新时间"`
  446. Pv int `gorm:"column:pv" description:"pv"`
  447. Uv int `gorm:"column:uv" description:"uv"`
  448. HeadImg string `gorm:"column:head_img" description:"报告头图地址"`
  449. EndImg string `gorm:"column:end_img" description:"报告尾图地址"`
  450. HeadStyle string `gorm:"column:head_style" description:"版头样式"`
  451. EndStyle string `gorm:"column:end_style" description:"版尾样式"`
  452. CanvasColor string `gorm:"column:canvas_color" description:"画布颜色"`
  453. NeedSplice int `gorm:"column:need_splice" description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  454. HeadResourceId int `gorm:"column:head_resource_id" description:"版头资源ID"`
  455. EndResourceId int `gorm:"column:end_resource_id" description:"版尾资源ID"`
  456. ClassifyIdThird int `gorm:"column:classify_id_third" description:"三级分类id"`
  457. ClassifyNameThird string `gorm:"column:classify_name_third" description:"三级分类名称"`
  458. CollaborateType int8 `gorm:"column:collaborate_type" description:"协作方式,1:个人,2:多人协作。默认:1"`
  459. ReportLayout int8 `gorm:"column:report_layout" description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  460. IsPublicPublish int8 `gorm:"column:is_public_publish" description:"是否公开发布,1:是,2:否"`
  461. ReportCreateTime string `gorm:"column:report_create_time" description:"报告时间创建时间"`
  462. ReportSource int `gorm:"column:report_source" description:"报告来源:1-系统内;2-智力共享"`
  463. OutReportId string `gorm:"column:out_report_id" description:"外部报告ID(或编码)"`
  464. }
  465. func GetReportById(reportId int) (item *ReportDetail, err error) {
  466. reportInfo, err := GetReportByReportId(reportId)
  467. if err != nil {
  468. return
  469. }
  470. item, err = convertReportToReportDetail(*reportInfo)
  471. return
  472. }
  473. func convertReportToReportDetail(report Report) (*ReportDetail, error) {
  474. jsonBytes, err := json.Marshal(report)
  475. if err != nil {
  476. return nil, fmt.Errorf("failed to marshal input: %w", err)
  477. }
  478. reportDetail := new(ReportDetail)
  479. err = json.Unmarshal(jsonBytes, reportDetail)
  480. if err != nil {
  481. return nil, fmt.Errorf("failed to unmarshal input: %w", err)
  482. }
  483. // 对于时间类型的字段,需要转换为字符串
  484. reportDetail.CreateTime = report.CreateTime.Format(utils.FormatDateTime)
  485. reportDetail.ModifyTime = report.ModifyTime.Format(utils.FormatDateTime)
  486. if !report.PublishTime.IsZero() {
  487. reportDetail.PublishTime = report.PublishTime.Format(utils.FormatDateTime)
  488. } else {
  489. reportDetail.PublishTime = ``
  490. }
  491. if !report.ContentModifyTime.IsZero() {
  492. reportDetail.ContentModifyTime = report.ContentModifyTime.Format(utils.FormatDateTime)
  493. } else {
  494. reportDetail.ContentModifyTime = ``
  495. }
  496. if !report.ReportCreateTime.IsZero() {
  497. reportDetail.ReportCreateTime = report.ReportCreateTime.Format(utils.FormatDateTime)
  498. } else {
  499. reportDetail.ReportCreateTime = ``
  500. }
  501. return reportDetail, nil
  502. }
  503. // GetSimpleReportByIds 根据报告ID查询报告基本信息
  504. func GetSimpleReportByIds(reportIds []int) (list []*Report, err error) {
  505. if len(reportIds) == 0 {
  506. return
  507. }
  508. sql := `SELECT id, title, report_code FROM report WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
  509. err = global.DmSQL["rddp"].Raw(sql, reportIds).Find(&list).Error
  510. return
  511. }
  512. // GetReportStage
  513. // @Description: 获取报告的最大期数(每一年的最大期数)
  514. // @author: Roc
  515. // @datetime 2024-06-03 17:44:14
  516. // @param classifyIdFirst int
  517. // @param classifyIdSecond int
  518. // @param classifyIdThird int
  519. // @return count int
  520. // @return err error
  521. func GetReportStage(classifyIdFirst, classifyIdSecond, classifyIdThird int) (count int, err error) {
  522. classifyId := classifyIdThird
  523. if classifyId <= 0 {
  524. classifyId = classifyIdSecond
  525. }
  526. if classifyId <= 0 {
  527. classifyId = classifyIdFirst
  528. }
  529. if classifyId <= 0 {
  530. err = errors.New("错误的分类id")
  531. return
  532. }
  533. yearStart := time.Date(time.Now().Local().Year(), 1, 1, 0, 0, 0, 0, time.Local)
  534. sql := `SELECT COALESCE(MAX(stage),0) AS count FROM report WHERE create_time > ? `
  535. if classifyIdThird > 0 {
  536. sql += " AND classify_id_third = ? "
  537. } else if classifyIdSecond > 0 {
  538. sql += " AND classify_id_second = ? "
  539. } else {
  540. sql += " AND classify_id_first = ? "
  541. }
  542. err = global.DmSQL["rddp"].Raw(sql, yearStart, classifyId).Scan(&count).Error
  543. return
  544. }
  545. type PublishReq struct {
  546. ReportIds string `description:"报告id,多个用英文逗号隔开"`
  547. //ReportUrl string `description:"报告Url"`
  548. }
  549. type PublishCancelReq struct {
  550. ReportIds int `description:"报告id"`
  551. }
  552. type DeleteReq struct {
  553. ReportIds int `description:"报告id"`
  554. }
  555. type AddReq struct {
  556. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  557. ClassifyIdFirst int `description:"一级分类id"`
  558. ClassifyNameFirst string `description:"一级分类名称"`
  559. ClassifyIdSecond int `description:"二级分类id"`
  560. ClassifyNameSecond string `description:"二级分类名称"`
  561. ClassifyIdThird int `description:"三级分类id"`
  562. ClassifyNameThird string `description:"三级分类名称"`
  563. Title string `description:"标题"`
  564. Abstract string `description:"摘要"`
  565. Author string `description:"作者"`
  566. Frequency string `description:"频度"`
  567. State int `description:"状态:1:未发布,2:已发布"`
  568. Content string `description:"内容"`
  569. CreateTime string `description:"创建时间"`
  570. ReportVersion int `description:"1:旧版,2:新版"`
  571. ContentStruct string `description:"内容组件"`
  572. HeadImg string `description:"报告头图地址"`
  573. EndImg string `description:"报告尾图地址"`
  574. CanvasColor string `description:"画布颜色"`
  575. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  576. HeadResourceId int `description:"版头资源ID"`
  577. EndResourceId int `description:"版尾资源ID"`
  578. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  579. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  580. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  581. InheritReportId int `description:"待继承的报告ID"`
  582. GrantAdminIdList []int `description:"授权用户id列表"`
  583. }
  584. type PrePublishReq struct {
  585. ReportId int `description:"报告id"`
  586. PrePublishTime string `description:"预发布时间"`
  587. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  588. ReportUrl string `description:"报告Url"`
  589. }
  590. type AddResp struct {
  591. ReportId int64 `description:"报告id"`
  592. ReportCode string `description:"报告code"`
  593. }
  594. type EditReq struct {
  595. ReportId int64 `description:"报告id"`
  596. ClassifyIdFirst int `description:"一级分类id"`
  597. ClassifyNameFirst string `description:"一级分类名称"`
  598. ClassifyIdSecond int `description:"二级分类id"`
  599. ClassifyNameSecond string `description:"二级分类名称"`
  600. ClassifyIdThird int `description:"三级分类id"`
  601. ClassifyNameThird string `description:"三级分类名称"`
  602. Title string `description:"标题"`
  603. Abstract string `description:"摘要"`
  604. Author string `description:"作者"`
  605. Frequency string `description:"频度"`
  606. State int `description:"状态:1:未发布,2:已发布"`
  607. Content string `description:"内容"`
  608. CreateTime string `description:"创建时间"`
  609. ContentStruct string `description:"内容组件"`
  610. HeadImg string `description:"报告头图地址"`
  611. EndImg string `description:"报告尾图地址"`
  612. CanvasColor string `description:"画布颜色"`
  613. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  614. HeadResourceId int `description:"版头资源ID"`
  615. EndResourceId int `description:"版尾资源ID"`
  616. //CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  617. //ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  618. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  619. GrantAdminIdList []int `description:"授权用户id列表"`
  620. }
  621. type EditResp struct {
  622. ReportId int64 `description:"报告id"`
  623. ReportCode string `description:"报告code"`
  624. }
  625. func EditReport(item *Report, reportId int64) (err error) {
  626. sql := `UPDATE report
  627. SET
  628. classify_id_first =?,
  629. classify_name_first = ?,
  630. classify_id_second = ?,
  631. classify_name_second = ?,
  632. title = ?,
  633. abstract = ?,
  634. author = ?,
  635. frequency = ?,
  636. state = ?,
  637. content = ?,
  638. content_sub = ?,
  639. stage =?,
  640. create_time = ?,
  641. modify_time = ?
  642. WHERE id = ? `
  643. err = global.DmSQL["rddp"].Exec(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title,
  644. item.Abstract, item.Author, item.Frequency, item.State, item.Content, item.ContentSub, item.Stage, item.CreateTime, time.Now(), reportId).Error
  645. return
  646. }
  647. func (m *Report) Update(cols []string) (err error) {
  648. err = global.DmSQL["rddp"].Select(cols).Updates(m).Error
  649. return
  650. }
  651. type ReportDetailReq struct {
  652. ReportId int `description:"报告id"`
  653. }
  654. type ClassifyIdDetailReq struct {
  655. ClassifyIdFirst int `description:"报告一级分类id"`
  656. ClassifyIdSecond int `description:"报告二级分类id"`
  657. }
  658. func GetReportDetailByClassifyId(classifyIdFirst, classifyIdSecond int) (item *Report, err error) {
  659. sql := ` SELECT * FROM report WHERE 1=1 `
  660. if classifyIdSecond > 0 {
  661. sql = sql + ` AND classify_id_second=? ORDER BY stage DESC LIMIT 1`
  662. err = global.DmSQL["rddp"].Raw(sql, classifyIdSecond).First(&item).Error
  663. } else {
  664. sql = sql + ` AND classify_id_first=? ORDER BY stage DESC LIMIT 1`
  665. err = global.DmSQL["rddp"].Raw(sql, classifyIdFirst).First(&item).Error
  666. }
  667. return
  668. }
  669. type SendTemplateMsgReq struct {
  670. ReportId int `description:"报告id"`
  671. }
  672. // SendTemplateMsgResp
  673. // @Description: 报告推送返回结构体
  674. type SendTemplateMsgResp struct {
  675. ReportId int `description:"报告id"`
  676. MsgSendTime string `description:"报告推送时间"`
  677. }
  678. func ModifyReportMsgIsSend(reportId int) (err error) {
  679. report, err := GetReportById(reportId)
  680. if err != nil {
  681. return
  682. }
  683. if report.MsgIsSend == 0 {
  684. sql := `UPDATE report SET msg_is_send = 1, msg_send_time=NOW() WHERE id = ? `
  685. err = global.DmSQL["rddp"].Exec(sql, reportId).Error
  686. }
  687. return
  688. }
  689. func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  690. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? `
  691. err = global.DmSQL["rddp"].Exec(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Error
  692. return
  693. }
  694. // ModifyReportVideoByNoVideo
  695. // @Description: 修改无音频的报告音频信息
  696. // @author: Roc
  697. // @datetime 2024-07-25 18:03:05
  698. // @param reportId int
  699. // @param videoUrl string
  700. // @param videoName string
  701. // @param videoSize string
  702. // @param playSeconds float64
  703. // @return err error
  704. func ModifyReportVideoByNoVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  705. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? AND video_url=''`
  706. err = global.DmSQL["rddp"].Exec(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Error
  707. return
  708. }
  709. type ReportItem struct {
  710. gorm.Model
  711. Id int `gorm:"column:id;primary_key;autoIncrement" description:"报告Id"`
  712. AddType int `gorm:"column:add_type" description:"新增方式:1:新增报告,2:继承报告"`
  713. ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类id"`
  714. ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
  715. ClassifyIdSecond int `gorm:"column:classify_id_second" description:"二级分类id"`
  716. ClassifyNameSecond string `gorm:"column:classify_name_second" description:"二级分类名称"`
  717. Title string `gorm:"column:title" description:"标题"`
  718. Abstract string `gorm:"column:abstract" description:"摘要"`
  719. Author string `gorm:"column:author" description:"作者"`
  720. Frequency string `gorm:"column:frequency" description:"频度"`
  721. CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
  722. ModifyTime time.Time `gorm:"column:modify_time" description:"修改时间"`
  723. State int `gorm:"column:state" description:"1:未发布,2:已发布"`
  724. PublishTime time.Time `gorm:"column:publish_time" description:"发布时间"`
  725. Stage int `gorm:"column:stage" description:"期数"`
  726. MsgIsSend int `gorm:"column:msg_is_send" description:"消息是否已发送,0:否,1:是"`
  727. Content string `gorm:"column:content" description:"内容"`
  728. VideoUrl string `gorm:"column:video_url" description:"音频文件URL"`
  729. VideoName string `gorm:"column:video_name" description:"音频文件名称"`
  730. VideoPlaySeconds string `gorm:"column:video_play_seconds" description:"音频播放时长"`
  731. ContentSub string `gorm:"column:content_sub" description:"内容前两个章节"`
  732. }
  733. type SaveReportContent struct {
  734. Content string `description:"内容"`
  735. ReportId int `description:"报告id"`
  736. NoChange int `description:"内容是否未改变:1:内容未改变"`
  737. // 以下是智能研报相关
  738. ContentStruct string `description:"内容组件"`
  739. HeadImg string `description:"报告头图地址"`
  740. EndImg string `description:"报告尾图地址"`
  741. CanvasColor string `description:"画布颜色"`
  742. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  743. HeadResourceId int `description:"版头资源ID"`
  744. EndResourceId int `description:"版尾资源ID"`
  745. IsManualSave bool `description:"是否手动保存:true:手动 false:自动"`
  746. }
  747. func AddReportSaveLog(reportId, adminId int, content, contentSub, contentStruct, canvasColor, adminName string, headResourceId, endResourceId int) (err error) {
  748. sql := ` INSERT INTO report_save_log(report_id, content,content_sub,content_struct,canvas_color,head_resource_id,end_resource_id,admin_id,admin_name) VALUES (?,?,?,?,?,?,?,?,?) `
  749. err = global.DmSQL["rddp"].Exec(sql, reportId, content, contentSub, contentStruct, canvasColor, headResourceId, endResourceId, adminId, adminName).Error
  750. return
  751. }
  752. func MultiAddReportChaptersSaveLog(items []*ReportChapter, adminId int, adminRealName string) (err error) {
  753. tx := global.DmSQL["rddp"].Begin()
  754. for _, v := range items {
  755. err = tx.Exec(`INSERT INTO report_save_log(report_id, report_chapter_id, content, content_sub,content_struct,admin_id, admin_name) VALUES (?,?,?,?,?,?,?)`, v.ReportId, v.ReportChapterId, v.Content, v.ContentSub, v.ContentStruct, adminId, adminRealName).Error
  756. if err != nil {
  757. tx.Rollback()
  758. return
  759. }
  760. }
  761. tx.Commit()
  762. return
  763. }
  764. type SaveReportContentResp struct {
  765. ReportId int `description:"报告id"`
  766. }
  767. func ModifyReportCode(reportId int64, reportCode string) (err error) {
  768. sql := `UPDATE report SET report_code=? WHERE id=? `
  769. err = global.DmSQL["rddp"].Exec(sql, reportCode, reportId).Error
  770. return
  771. }
  772. func ModifyReportThsMsgIsSend(item *ReportDetail) (err error) {
  773. if item.ThsMsgIsSend == 0 {
  774. sql := `UPDATE report SET ths_msg_is_send = 1 WHERE id = ? `
  775. err = global.DmSQL["rddp"].Exec(sql, item.Id).Error
  776. }
  777. return
  778. }
  779. type ThsSendTemplateMsgReq struct {
  780. ReportId []int `description:"报告id"`
  781. }
  782. type PublishDayWeekReportReq struct {
  783. ReportId int `description:"报告ID"`
  784. }
  785. // SaveDayWeekReportReq 新增晨报周报请求体
  786. type SaveDayWeekReportReq struct {
  787. ReportId int `description:"报告ID"`
  788. Title string `description:"标题"`
  789. ReportType string `description:"一级分类ID"`
  790. Author string `description:"作者"`
  791. CreateTime string `description:"创建时间"`
  792. }
  793. // GetReportByReportId 主键获取报告
  794. func GetReportByReportId(reportId int) (item *Report, err error) {
  795. sql := `SELECT * FROM report WHERE id = ?`
  796. err = global.DmSQL["rddp"].Raw(sql, reportId).First(&item).Error
  797. return
  798. }
  799. // DeleteDayWeekReportAndChapter 删除晨周报及章节
  800. func DeleteDayWeekReportAndChapter(reportId int) (err error) {
  801. to := global.DmSQL["rddp"].Begin()
  802. defer func() {
  803. if err != nil {
  804. _ = to.Rollback()
  805. } else {
  806. _ = to.Commit()
  807. }
  808. }()
  809. sql := ` DELETE FROM report WHERE id = ? LIMIT 1 `
  810. if err = to.Exec(sql, reportId).Error; err != nil {
  811. return
  812. }
  813. sql = ` DELETE FROM report_chapter WHERE report_id = ? `
  814. if err = to.Exec(sql, reportId).Error; err != nil {
  815. return
  816. }
  817. return
  818. }
  819. // UpdateReport 更新报告
  820. func (reportInfo *Report) UpdateReport(cols []string) (err error) {
  821. err = global.DmSQL["rddp"].Select(cols).Updates(reportInfo).Error
  822. return
  823. }
  824. // ReportDetailView
  825. // @Description: 晨周报详情
  826. type ReportDetailView struct {
  827. *ReportDetail
  828. ChapterList []*ReportChapter
  829. GrandAdminList []ReportDetailViewAdmin
  830. PermissionList []ReportDetailViewPermission
  831. }
  832. // ReportDetailViewAdmin
  833. // @Description: 报告里面的授权人
  834. type ReportDetailViewAdmin struct {
  835. AdminId int
  836. AdminName string
  837. }
  838. // ReportDetailViewPermission
  839. // @Description: 报告分类关联的品种权限
  840. type ReportDetailViewPermission struct {
  841. PermissionId int
  842. PermissionName string
  843. }
  844. type ElasticReportDetail struct {
  845. gorm.Model
  846. ReportId int `gorm:"column:report_id;index" description:"报告ID"`
  847. ReportChapterId int `gorm:"column:report_chapter_id" description:"报告章节ID"`
  848. Title string `gorm:"column:title" description:"标题"`
  849. Abstract string `gorm:"column:abstract" description:"摘要"`
  850. BodyContent string `gorm:"column:body_content" description:"内容"`
  851. PublishTime string `gorm:"column:publish_time" description:"发布时间"`
  852. PublishState int `gorm:"column:publish_state" description:"发布状态 1-未发布 2-已发布"`
  853. Author string `gorm:"column:author" description:"作者"`
  854. ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类ID"`
  855. ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
  856. ClassifyIdSecond int `gorm:"column:classify_id_second" description:"二级分类ID"`
  857. ClassifyNameSecond string `gorm:"column:classify_name_second" description:"二级分类名称"`
  858. ClassifyId int `gorm:"column:classify_id" description:"最小单元的分类ID"`
  859. ClassifyName string `gorm:"column:classify_name" description:"最小单元的分类名称"`
  860. Categories string `gorm:"column:categories" description:"关联的品种名称(包括品种别名)"`
  861. StageStr string `gorm:"column:stage_str" description:"报告期数"`
  862. }
  863. // PublishReportAndChapter 发布报告及章节
  864. func PublishReportAndChapter(reportInfo *Report, isPublishReport bool, cols []string) (err error) {
  865. to := global.DmSQL["rddp"].Begin()
  866. defer func() {
  867. if err != nil {
  868. _ = to.Rollback()
  869. } else {
  870. _ = to.Commit()
  871. }
  872. }()
  873. // 更新报告
  874. if isPublishReport {
  875. err = to.Select(cols).Updates(reportInfo).Error
  876. if err != nil {
  877. return
  878. }
  879. }
  880. // 发布该报告的所有章节
  881. sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? `
  882. err = to.Exec(sql, reportInfo.PublishTime, reportInfo.Id).Error
  883. return
  884. }
  885. // PublishReportById 发布报告
  886. func PublishReportById(reportId int, publishTime time.Time, lastModifyAdminId int, lastModifyAdminName string) (err error) {
  887. sql := `UPDATE report SET state = 2, publish_time = ?, pre_publish_time=null, pre_msg_send=0, modify_time = NOW(),last_modify_admin_id=?,last_modify_admin_name=? WHERE id = ? `
  888. err = global.DmSQL["rddp"].Exec(sql, publishTime, lastModifyAdminId, lastModifyAdminName, reportId).Error
  889. return
  890. }
  891. // ResetReportById 重置报告状态
  892. func ResetReportById(reportId, state int, lastModifyAdminId int, lastModifyAdminName string) (err error) {
  893. sql := `UPDATE report SET state = ?, pre_publish_time = null, pre_msg_send = 0, modify_time = NOW(),last_modify_admin_id=?,last_modify_admin_name=? WHERE id = ?`
  894. err = global.DmSQL["rddp"].Exec(sql, state, lastModifyAdminId, lastModifyAdminName, reportId).Error
  895. return
  896. }
  897. // 点赞相关的报告列表
  898. type LikeReportItem struct {
  899. gorm.Model
  900. ReportId int `gorm:"column:report_id;index" description:"报告Id"`
  901. ReportChapterId int `gorm:"column:report_chapter_id" description:"报告章节Id"`
  902. ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类id"`
  903. ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
  904. ClassifyIdSecond int `gorm:"column:classify_id_second" description:"二级分类id"`
  905. ClassifyNameSecond string `gorm:"column:classify_name_second" description:"二级分类名称"`
  906. ReportChapterTypeId int `gorm:"column:report_chapter_type_id" description:"章节类型"`
  907. ReportChapterTypeName string `gorm:"column:report_chapter_type_name" description:"品种名称"`
  908. PublishTime time.Time `gorm:"column:publish_time" description:"发布时间"`
  909. Title string `gorm:"column:title" description:"标题"`
  910. }
  911. // SunCodeReq 获取太阳码请求体
  912. type SunCodeReq struct {
  913. CodePage string `json:"CodePage" description:"太阳码page"`
  914. CodeScene string `json:"CodeScene" description:"太阳码scene"`
  915. }
  916. // YbPcSuncode 活动海报表
  917. type YbPcSuncode struct {
  918. SuncodeID uint32 `gorm:"column:suncode_id;primaryKey" json:"suncodeId"` //`orm:"column(suncode_id);pk" gorm:"primaryKey" `
  919. Scene string `gorm:"column:scene;type:varchar(255);not null;default:0" json:"scene"` // 微信scene
  920. SceneMd5 string `gorm:"column:scene_md5;type:varchar(255);not null" json:"sceneMd5"`
  921. CodePage string `gorm:"column:code_page;type:varchar(255);not null;default:''" json:"codePage"` // 路径
  922. SuncodeUrl string `gorm:"column:suncode_url;type:varchar(255);not null;default:''" json:"suncodeUrl"` // 太阳码储存地址
  923. CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"`
  924. }
  925. // GetYbPcSunCode 获取太阳码
  926. func GetYbPcSunCode(scene, page string) (item *YbPcSuncode, err error) {
  927. sql := `SELECT * FROM yb_pc_suncode WHERE scene = ? AND code_page = ? `
  928. err = global.DmSQL["weekly"].Raw(sql, scene, page).First(&item).Error
  929. return
  930. }
  931. func AddYbPcSunCode(item *YbPcSuncode) (err error) {
  932. err = global.DmSQL["weekly"].Create(item).Error
  933. return
  934. }
  935. // YbSuncodePars 小程序太阳码scene参数
  936. type YbSuncodePars struct {
  937. ID uint32 `gorm:"column:id;primaryKey" json:"id"` //`orm:"column(id);pk" gorm:"primaryKey" `
  938. Scene string `gorm:"column:scene;type:varchar(255);not null;default:''" json:"scene"` // scene参数
  939. SceneKey string `gorm:"column:scene_key;type:varchar(32);not null;default:''" json:"scene_key"` // MD5值
  940. CreateTime time.Time `gorm:"column:create_time;type:datetime;default:CURRENT_TIMESTAMP" json:"createTime"`
  941. }
  942. func AddYbSuncodePars(item *YbSuncodePars) (err error) {
  943. err = global.DmSQL["weekly"].Create(item).Error
  944. return
  945. }
  946. // UpdateReportSecondClassifyNameByClassifyId 更新报告分类名称字段
  947. func UpdateReportSecondClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  948. sql := " UPDATE report SET classify_name_second = ? WHERE classify_id_second = ? "
  949. err = global.DmSQL["rddp"].Exec(sql, classifyName, classifyId).Error
  950. return
  951. }
  952. // UpdateReportFirstClassifyNameByClassifyId 更新报告分类一级名称字段
  953. func UpdateReportFirstClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  954. sql := " UPDATE report SET classify_name_first = ? WHERE classify_id_first = ? "
  955. err = global.DmSQL["rddp"].Exec(sql, classifyName, classifyId).Error
  956. return
  957. }
  958. // UpdateReportThirdClassifyNameByClassifyId 更新报告的三级分类名称字段
  959. func UpdateReportThirdClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  960. sql := " UPDATE report SET classify_name_third = ? WHERE classify_id_third = ? "
  961. err = global.DmSQL["rddp"].Exec(sql, classifyName, classifyId).Error
  962. return
  963. }
  964. // ModifyReportAuthor 更改报告作者
  965. func ModifyReportAuthor(condition string, pars []interface{}, authorName string) (count int, err error) {
  966. //产品权限
  967. sql := `UPDATE english_report set author = ? WHERE 1=1 `
  968. if condition != "" {
  969. sql += condition
  970. }
  971. result := global.DmSQL["rddp"].Raw(sql, utils.ForwardPars(pars, authorName)...)
  972. count = int(result.RowsAffected)
  973. err = result.Error
  974. return
  975. }
  976. func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
  977. sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
  978. err = global.DmSQL["rddp"].Exec(sql1, reportId).Error
  979. if err != nil {
  980. return
  981. }
  982. //修改音频标题
  983. sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !='' and video_name is not null)`
  984. err = global.DmSQL["rddp"].Exec(sql2, reportId).Error
  985. return
  986. }
  987. func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
  988. sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
  989. err = global.DmSQL["rddp"].Exec(sql1, reportId).Error
  990. if err != nil {
  991. return
  992. }
  993. //修改音频标题
  994. sql2 := ` UPDATE report_chapter SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE report_id = ? and (video_name !='' and video_name is not null)`
  995. err = global.DmSQL["rddp"].Exec(sql2, reportId).Error
  996. return
  997. }
  998. // MarkEditReport 标记编辑英文研报的请求数据
  999. type MarkEditReport struct {
  1000. ReportId int `description:"研报id"`
  1001. ReportChapterId int `description:"研报章节id"`
  1002. Status int `description:"标记状态,1:编辑中,2:查询状态,3:编辑完成"`
  1003. }
  1004. type MarkReportResp struct {
  1005. Status int `description:"状态:0:无人编辑, 1:当前有人在编辑"`
  1006. Msg string `description:"提示信息"`
  1007. Editor string `description:"编辑者姓名"`
  1008. }
  1009. type MarkReportItem struct {
  1010. AdminId int `description:"编辑者ID"`
  1011. Editor string `description:"编辑者姓名"`
  1012. ReportClassifyNameFirst string
  1013. }
  1014. // GetReportByCondition 获取报告
  1015. func GetReportByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, isPage bool, startSize, pageSize int) (items []*Report, err error) {
  1016. fields := `*`
  1017. if len(fieldArr) > 0 {
  1018. fields = strings.Join(fieldArr, ",")
  1019. }
  1020. sql := `SELECT ` + fields + ` FROM report WHERE 1=1 `
  1021. sql += condition
  1022. order := ` ORDER BY modify_time DESC`
  1023. if orderRule != `` {
  1024. order = orderRule
  1025. }
  1026. sql += order
  1027. if isPage {
  1028. sql += ` LIMIT ?,?`
  1029. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  1030. } else {
  1031. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  1032. }
  1033. return
  1034. }
  1035. // SetPrePublishReportById 设置定时发布
  1036. func SetPrePublishReportById(reportId int, prePublishTime string, preMsgSend int) (err error) {
  1037. sql := `UPDATE report SET pre_publish_time=?, pre_msg_send=? WHERE id = ? and state = 1 `
  1038. err = global.DmSQL["rddp"].Exec(sql, prePublishTime, preMsgSend, reportId).Error
  1039. return
  1040. }
  1041. // ReportSubmitApproveReq 提交审批请求体
  1042. type ReportSubmitApproveReq struct {
  1043. ReportId int `description:"报告ID"`
  1044. }
  1045. // ReportCancelApproveReq 撤回审批请求体
  1046. type ReportCancelApproveReq struct {
  1047. ReportId int `description:"报告ID"`
  1048. }
  1049. func (m *Report) GetItemById(id int) (item *Report, err error) {
  1050. sql := `SELECT * FROM report WHERE id = ? LIMIT 1`
  1051. err = global.DmSQL["rddp"].Raw(sql, id).First(&item).Error
  1052. return
  1053. }
  1054. // GetReportStateCount 获取指定状态的报告数量
  1055. func GetReportStateCount(state int) (count int, err error) {
  1056. sql := `SELECT COUNT(1) AS count FROM report WHERE state = ?`
  1057. err = global.DmSQL["rddp"].Raw(sql, state).Scan(&count).Error
  1058. return
  1059. }
  1060. // UpdateReportsStateByCond 批量更新报告状态
  1061. func UpdateReportsStateByCond(classifyFirstId, classifySecondId, classifyThirdId, oldState, newState int) (err error) {
  1062. cond := ``
  1063. if classifyFirstId > 0 {
  1064. cond += fmt.Sprintf(` AND classify_id_first = %d`, classifyFirstId)
  1065. }
  1066. if classifySecondId > 0 {
  1067. cond += fmt.Sprintf(` AND classify_id_second = %d`, classifySecondId)
  1068. }
  1069. if classifyThirdId > 0 {
  1070. cond += fmt.Sprintf(` AND classify_id_third = %d`, classifyThirdId)
  1071. }
  1072. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? %s`, cond)
  1073. err = global.DmSQL["rddp"].Exec(sql, newState, oldState).Error
  1074. return
  1075. }
  1076. // UpdateReportsStateBySecondIds 批量更新二级分类报告状态
  1077. func UpdateReportsStateBySecondIds(oldState, newState int, secondIds []int) (err error) {
  1078. if len(secondIds) <= 0 {
  1079. return
  1080. }
  1081. // (有审批流的)未发布->待提交
  1082. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1083. err = global.DmSQL["rddp"].Exec(sql, newState, oldState, secondIds).Error
  1084. if err != nil {
  1085. return
  1086. }
  1087. // (无审批流的)待提交->未发布
  1088. sql = fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second NOT IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1089. err = global.DmSQL["rddp"].Exec(sql, oldState, newState, secondIds).Error
  1090. return
  1091. }
  1092. // GetReportPdfUrlReq 获取报告pdf地址请求体
  1093. type GetReportPdfUrlReq struct {
  1094. ReportUrl string `description:"报告Url"`
  1095. ReportCode string `description:"报告Code"`
  1096. Type int `description:"类型 1-pdf 2-图片"`
  1097. }
  1098. func ModifyReportPdfUrl(reportId int, detailPdfUrl string) (err error) {
  1099. sql := `UPDATE report SET detail_pdf_url=? WHERE id=? `
  1100. err = global.DmSQL["rddp"].Exec(sql, detailPdfUrl, reportId).Error
  1101. return
  1102. }
  1103. func ModifyReportImgUrl(reportId int, detailImgUrl string) (err error) {
  1104. sql := `UPDATE report SET detail_img_url=? WHERE id=? `
  1105. err = global.DmSQL["rddp"].Exec(sql, detailImgUrl, reportId).Error
  1106. return
  1107. }
  1108. // UpdatePdfUrlReportById 清空pdf相关字段
  1109. func UpdatePdfUrlReportById(reportId int) (err error) {
  1110. sql := `UPDATE report SET detail_img_url = '',detail_pdf_url='',modify_time=NOW() WHERE id = ? `
  1111. err = global.DmSQL["rddp"].Exec(sql, reportId).Error
  1112. return
  1113. }
  1114. // InsertMultiReport
  1115. // @Description: 批量新增报告
  1116. // @author: Roc
  1117. // @datetime 2024-06-27 15:55:25
  1118. // @param items []*Report
  1119. // @return err error
  1120. func InsertMultiReport(items []*Report) (err error) {
  1121. err = global.DmSQL["rddp"].CreateInBatches(items, utils.MultiAddNum).Error
  1122. return
  1123. }
  1124. // ReportLayout
  1125. // @Description: 报告布局
  1126. type ReportLayout struct {
  1127. Id int `gorm:"column:id;primaryKey"`
  1128. ReportLayout int8 `gorm:"column:report_layout"` //`description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  1129. }
  1130. // GetReportLayoutByReportId
  1131. // @Description: 根据报告id获取报告的布局
  1132. // @author: Roc
  1133. // @datetime 2024-07-15 15:27:05
  1134. // @param reportId int
  1135. // @return item ReportLayout
  1136. // @return err error
  1137. func GetReportLayoutByReportId(reportId int) (item ReportLayout, err error) {
  1138. sql := `SELECT id, report_layout FROM report WHERE id = ? `
  1139. err = global.DmSQL["rddp"].Raw(sql, reportId).First(&item).Error
  1140. return
  1141. }
  1142. func GetReportFieldsByIds(ids []int, fields []string) (items []*Report, err error) {
  1143. if len(ids) == 0 {
  1144. return
  1145. }
  1146. field := " * "
  1147. if len(fields) > 0 {
  1148. field = fmt.Sprintf(" %s ", strings.Join(fields, ","))
  1149. }
  1150. sql := fmt.Sprintf(`SELECT %s FROM report WHERE id IN (%s)`, field, utils.GetOrmInReplace(len(ids)))
  1151. err = global.DmSQL["rddp"].Raw(sql, ids).Find(&items).Error
  1152. return
  1153. }
  1154. func (m *Report) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  1155. sql := fmt.Sprintf(`SELECT COUNT(1) FROM report WHERE 1=1 %s`, condition)
  1156. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  1157. return
  1158. }
  1159. func (m *Report) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*Report, err error) {
  1160. fields := strings.Join(fieldArr, ",")
  1161. if len(fieldArr) == 0 {
  1162. fields = `*`
  1163. }
  1164. order := `ORDER BY create_time DESC`
  1165. if orderRule != "" {
  1166. order = ` ORDER BY ` + orderRule
  1167. }
  1168. sql := fmt.Sprintf(`SELECT %s FROM report WHERE 1=1 %s %s`, fields, condition, order)
  1169. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  1170. return
  1171. }