report.go 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586
  1. package models
  2. import (
  3. sql2 "database/sql"
  4. "errors"
  5. "eta/eta_api/global"
  6. "eta/eta_api/utils"
  7. "fmt"
  8. "strings"
  9. "time"
  10. "github.com/rdlucklib/rdluck_tools/paging"
  11. )
  12. // 报告状态
  13. const (
  14. ReportStateUnpublished = 1 // 未发布
  15. ReportStatePublished = 2 // 已发布
  16. ReportStateWaitSubmit = 3 // 待提交
  17. ReportStateWaitApprove = 4 // 审批中
  18. ReportStateRefused = 5 // 已驳回
  19. ReportStatePass = 6 // 已通过
  20. )
  21. // 报告操作
  22. const (
  23. ReportOperateAdd = 1 // 新增报告
  24. ReportOperateEdit = 2 // 编辑报告
  25. ReportOperatePublish = 3 // 发布报告
  26. ReportOperateCancelPublish = 4 // 取消发布报告
  27. ReportOperateSubmitApprove = 5 // 提交审批
  28. ReportOperateCancelApprove = 6 // 撤回审批
  29. )
  30. type Report struct {
  31. Id int `gorm:"column:id;primaryKey;autoIncrement" description:"报告Id"`
  32. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  33. ClassifyIdFirst int `description:"一级分类id"`
  34. ClassifyNameFirst string `description:"一级分类名称"`
  35. ClassifyIdSecond int `description:"二级分类id"`
  36. ClassifyNameSecond string `description:"二级分类名称"`
  37. Title string `description:"标题"`
  38. Abstract string `description:"摘要"`
  39. Author string `description:"作者"`
  40. Frequency string `description:"频度"`
  41. CreateTime string `description:"创建时间"`
  42. ModifyTime time.Time `description:"修改时间"`
  43. State int `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  44. PublishTime time.Time `description:"发布时间"`
  45. Stage int `description:"期数"`
  46. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  47. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  48. Content string `description:"内容"`
  49. VideoUrl string `description:"音频文件URL"`
  50. VideoName string `description:"音频文件名称"`
  51. VideoPlaySeconds string `description:"音频播放时长"`
  52. VideoSize string `description:"音频文件大小,单位M"`
  53. ContentSub string `description:"内容前两个章节"`
  54. ReportCode string `description:"报告唯一编码"`
  55. ReportVersion int `description:"1:旧版,2:新版"`
  56. HasChapter int `description:"是否有章节 0-否 1-是"`
  57. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  58. OldReportId int `description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  59. MsgSendTime time.Time `description:"模版消息发送时间"`
  60. AdminId int `description:"创建者账号"`
  61. AdminRealName string `description:"创建者姓名"`
  62. ApproveTime time.Time `description:"审批时间"`
  63. ApproveId int `description:"审批ID"`
  64. DetailImgUrl string `description:"报告详情长图地址"`
  65. DetailPdfUrl string `description:"报告详情PDF地址"`
  66. ContentStruct string `description:"内容组件"`
  67. LastModifyAdminId int `description:"最后更新人ID"`
  68. LastModifyAdminName string `description:"最后更新人姓名"`
  69. ContentModifyTime time.Time `description:"内容更新时间"`
  70. Pv int `description:"pv"`
  71. Uv int `description:"uv"`
  72. HeadImg string `description:"报告头图地址"`
  73. EndImg string `description:"报告尾图地址"`
  74. CanvasColor string `description:"画布颜色"`
  75. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  76. HeadResourceId int `description:"版头资源ID"`
  77. EndResourceId int `description:"版尾资源ID"`
  78. ClassifyIdThird int `description:"三级分类id"`
  79. ClassifyNameThird string `description:"三级分类名称"`
  80. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  81. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  82. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  83. ReportCreateTime time.Time `description:"报告时间创建时间"`
  84. InheritReportId int `description:"待继承的报告ID"`
  85. VoiceGenerateType int `description:"音频生成方式,0:系统生成,1:人工上传"`
  86. }
  87. type ReportList struct {
  88. Id int `gorm:"column:id;primaryKey;autoIncrement" description:"报告Id"`
  89. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  90. ClassifyIdFirst int `description:"一级分类id"`
  91. ClassifyNameFirst string `description:"一级分类名称"`
  92. ClassifyIdSecond int `description:"二级分类id"`
  93. ClassifyNameSecond string `description:"二级分类名称"`
  94. Title string `description:"标题"`
  95. Abstract string `description:"摘要"`
  96. Author string `description:"作者"`
  97. Frequency string `description:"频度"`
  98. CreateTime string `description:"创建时间"`
  99. ModifyTime string `description:"修改时间"`
  100. State int `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  101. PublishTime string `description:"发布时间"`
  102. PrePublishTime string `description:"预发布时间"`
  103. Stage int `description:"期数"`
  104. MsgIsSend int `description:"模板消息是否已发送,0:否,1:是"`
  105. Content string `description:"内容"`
  106. VideoUrl string `description:"音频文件URL"`
  107. VideoName string `description:"音频文件名称"`
  108. VideoPlaySeconds string `description:"音频播放时长"`
  109. ContentSub string `description:"内容前两个章节"`
  110. Pv int `description:"Pv"`
  111. Uv int `description:"Uv"`
  112. ReportCode string `description:"报告唯一编码"`
  113. ReportVersion int `description:"1:旧版,2:新版"`
  114. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  115. NeedThsMsg int `description:"是否需要推送客群消息 0-否 1-是"`
  116. HasChapter int `description:"是否有章节 0-否 1-是"`
  117. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  118. ChapterVideoList []*ReportChapterVideoList `gorm:"-" description:"章节音频列表"`
  119. OldReportId int `description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  120. MsgSendTime string `description:"模版消息发送时间"`
  121. CanEdit bool `description:"是否可编辑"`
  122. HasAuth bool `description:"是否可操作"`
  123. Editor string `description:"编辑人"`
  124. AdminId int `description:"创建者账号"`
  125. AdminRealName string `description:"创建者姓名"`
  126. ApproveTime string `description:"审批时间"`
  127. DetailImgUrl string `description:"报告详情长图地址"`
  128. DetailPdfUrl string `description:"报告详情PDF地址"`
  129. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  130. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  131. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  132. ReportCreateTime time.Time `description:"报告时间创建时间"`
  133. ContentStruct string `description:"内容组件"`
  134. LastModifyAdminId int `description:"最后更新人ID"`
  135. LastModifyAdminName string `description:"最后更新人姓名"`
  136. ContentModifyTime time.Time `description:"内容更新时间"`
  137. HeadImg string `description:"报告头图地址"`
  138. EndImg string `description:"报告尾图地址"`
  139. CanvasColor string `description:"画布颜色"`
  140. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  141. HeadResourceId int `description:"版头资源ID"`
  142. EndResourceId int `description:"版尾资源ID"`
  143. ClassifyIdThird int `description:"三级分类id"`
  144. ClassifyNameThird string `description:"三级分类名称"`
  145. InheritReportId int `description:"待继承的报告ID"`
  146. }
  147. type ReportListResp struct {
  148. List []*ReportList
  149. Paging *paging.PagingItem `description:"分页数据"`
  150. }
  151. // GetReportListCountV1
  152. // @Description: 获取普通报告列表的报告数量
  153. // @author: Roc
  154. // @datetime 2024-05-30 15:14:43
  155. // @param condition string
  156. // @param pars []interface{}
  157. // @return count int
  158. // @return err error
  159. func GetReportListCountV1(condition string, pars []interface{}) (count int, err error) {
  160. o := global.DbMap[utils.DbNameReport]
  161. sql := `SELECT COUNT(DISTINCT a.id) AS count FROM report as a WHERE 1=1 `
  162. if condition != "" {
  163. sql += condition
  164. }
  165. var countNull sql2.NullInt64
  166. err = o.Raw(sql, pars...).Scan(&countNull).Error
  167. if err != nil {
  168. return
  169. }
  170. if countNull.Valid {
  171. count = int(countNull.Int64)
  172. }
  173. return
  174. }
  175. // GetReportListV1
  176. // @Description: 获取普通报告列表的数据
  177. // @author: Roc
  178. // @datetime 2024-05-30 15:14:25
  179. // @param condition string
  180. // @param pars []interface{}
  181. // @param startSize int
  182. // @param pageSize int
  183. // @return items []*ReportList
  184. // @return err error
  185. func GetReportListV1(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  186. o := global.DbMap[utils.DbNameReport]
  187. sql := `SELECT * FROM report as a WHERE 1=1 `
  188. if condition != "" {
  189. sql += condition
  190. }
  191. // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  192. sql += ` ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
  193. err = o.Raw(sql, pars, startSize, pageSize).Find(&items).Error
  194. return
  195. }
  196. // GetReportListByCondition 获取报告列表
  197. func GetReportListByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  198. o := global.DbMap[utils.DbNameReport]
  199. sql := `SELECT DISTINCT a.id, a.title, a.author, a.modify_time, a.publish_time,a.classify_id_first,
  200. a.classify_name_first,a.classify_id_second,a.classify_name_second,a.classify_id_third,
  201. a.classify_name_third,a.abstract,a.admin_id,a.admin_real_name,a.last_modify_admin_id,a.last_modify_admin_name FROM report as a WHERE 1=1 `
  202. if condition != "" {
  203. sql += condition
  204. }
  205. sql += ` LIMIT ?,?`
  206. pars = append(pars, (startSize-1)*pageSize, pageSize)
  207. err = o.Raw(sql, pars...).Find(&items).Error
  208. return
  209. }
  210. type ReportPvUv struct {
  211. ReportId int
  212. PvTotal int
  213. UvTotal int
  214. }
  215. func GetReportPvUvByReportIdList(reportIdList []int) (items []ReportPvUv, err error) {
  216. num := len(reportIdList)
  217. if num <= 0 {
  218. return
  219. }
  220. o := global.DbMap[utils.DbNameReport]
  221. 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`
  222. err = o.Raw(sql, reportIdList).Find(&items).Error
  223. return
  224. }
  225. // GetReportListCountByGrant
  226. // @Description: 获取共享报告列表的报告数量
  227. // @author: Roc
  228. // @datetime 2024-05-30 15:14:01
  229. // @param condition string
  230. // @param pars []interface{}
  231. // @return count int
  232. // @return err error
  233. func GetReportListCountByGrant(condition string, pars []interface{}) (count int, err error) {
  234. o := global.DbMap[utils.DbNameReport]
  235. sql := `SELECT a.id FROM report as a
  236. JOIN report_grant b on a.id=b.report_id
  237. WHERE 1=1 `
  238. if condition != "" {
  239. sql += condition
  240. }
  241. sql += " GROUP BY a.id "
  242. sql = `SELECT COUNT(1) AS count FROM (` + sql + `) d`
  243. var countNull sql2.NullInt64
  244. err = o.Raw(sql, pars...).Scan(&countNull).Error
  245. if err != nil {
  246. return
  247. }
  248. if countNull.Valid {
  249. count = int(countNull.Int64)
  250. }
  251. return
  252. }
  253. // GetReportListByGrant
  254. // @Description: 获取共享报告列表的数据
  255. // @author: Roc
  256. // @datetime 2024-05-30 15:15:07
  257. // @param condition string
  258. // @param pars []interface{}
  259. // @param startSize int
  260. // @param pageSize int
  261. // @return items []*ReportList
  262. // @return err error
  263. func GetReportListByGrant(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  264. o := global.DbMap[utils.DbNameReport]
  265. sql := `SELECT a.* FROM report as a JOIN report_grant b on a.id = b.report_id WHERE 1=1 `
  266. if condition != "" {
  267. sql += condition
  268. }
  269. // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  270. sql += ` GROUP BY a.id ORDER BY FIELD(state,3,1,4,5,6,2), a.modify_time DESC LIMIT ?,?`
  271. pars = append(pars, startSize, pageSize)
  272. err = o.Raw(sql, pars...).Find(&items).Error
  273. return
  274. }
  275. func GetReportListCount(condition string, pars []interface{}) (count int, err error) {
  276. o := global.DbMap[utils.DbNameReport]
  277. sql := `SELECT COUNT(1) AS count FROM report WHERE 1=1 `
  278. if condition != "" {
  279. sql += condition
  280. }
  281. var countNull sql2.NullInt64
  282. err = o.Raw(sql, pars...).Scan(&countNull).Error
  283. if err != nil {
  284. return
  285. }
  286. if countNull.Valid {
  287. count = int(countNull.Int64)
  288. }
  289. return
  290. }
  291. //func GetReportList(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  292. // o := global.DbMap[utils.DbNameReport]
  293. // sql := `SELECT *,
  294. // (SELECT COUNT(1) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS pv,
  295. // (SELECT COUNT(DISTINCT user_id) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS uv
  296. // FROM report WHERE 1=1 `
  297. // if condition != "" {
  298. // sql += condition
  299. // }
  300. // // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  301. // sql += `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
  302. // err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  303. // return
  304. //}
  305. // PublishReport 发布报告
  306. //func PublishReport(reportIds []int) (err error) {
  307. // if len(reportIds) == 0 {
  308. // return
  309. // }
  310. // o := global.DbMap[utils.DbNameReport]
  311. // sql := `UPDATE report SET state=2,publish_time=now(),modify_time=NOW() WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
  312. // err = o.Raw(sql).Error
  313. // return
  314. //}
  315. // PublishCancelReport 取消发布报告
  316. func PublishCancelReport(reportId, state int, publishTimeNullFlag bool, lastModifyAdminId int, lastModifyAdminName string) (err error) {
  317. o := global.DbMap[utils.DbNameReport]
  318. var sql string
  319. if publishTimeNullFlag {
  320. 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 =?`
  321. } else {
  322. 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 =?`
  323. }
  324. err = o.Exec(sql, state, lastModifyAdminId, lastModifyAdminName, reportId).Error
  325. return
  326. }
  327. // 删除报告
  328. func DeleteReport(reportIds int) (err error) {
  329. o := global.DbMap[utils.DbNameReport]
  330. sql := ` DELETE FROM report WHERE id =? `
  331. err = o.Exec(sql, reportIds).Error
  332. return
  333. }
  334. type ReportDetail struct {
  335. Id int `gorm:"column:id;primaryKey;autoIncrement" description:"报告Id"`
  336. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  337. ClassifyIdFirst int `description:"一级分类id"`
  338. ClassifyNameFirst string `description:"一级分类名称"`
  339. ClassifyIdSecond int `description:"二级分类id"`
  340. ClassifyNameSecond string `description:"二级分类名称"`
  341. Title string `description:"标题"`
  342. Abstract string `description:"摘要"`
  343. Author string `description:"作者"`
  344. Frequency string `description:"频度"`
  345. CreateTime string `description:"创建时间"`
  346. ModifyTime string `description:"修改时间"`
  347. State int `description:"1:未发布,2:已发布"`
  348. PublishTime string `description:"发布时间"`
  349. PrePublishTime string `description:"预发布时间"`
  350. Stage int `description:"期数"`
  351. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  352. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  353. Content string `description:"内容"`
  354. VideoUrl string `description:"音频文件URL"`
  355. VideoName string `description:"音频文件名称"`
  356. VideoPlaySeconds string `description:"音频播放时长"`
  357. ContentSub string `description:"内容前两个章节"`
  358. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  359. HasChapter int `description:"是否有章节 0-否 1-是"`
  360. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  361. AdminId int `description:"创建者账号"`
  362. AdminRealName string `description:"创建者姓名"`
  363. ReportCode string `description:"报告唯一编码"`
  364. // eta1.8.3(研报改版)相关内容
  365. ContentStruct string `description:"内容组件"`
  366. LastModifyAdminId int `description:"最后更新人ID"`
  367. LastModifyAdminName string `description:"最后更新人姓名"`
  368. ContentModifyTime time.Time `description:"内容更新时间"`
  369. Pv int `description:"pv"`
  370. Uv int `description:"uv"`
  371. HeadImg string `description:"报告头图地址"`
  372. EndImg string `description:"报告尾图地址"`
  373. HeadStyle string `description:"版头样式"`
  374. EndStyle string `description:"版尾样式"`
  375. CanvasColor string `description:"画布颜色"`
  376. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  377. HeadResourceId int `description:"版头资源ID"`
  378. EndResourceId int `description:"版尾资源ID"`
  379. ClassifyIdThird int `description:"三级分类id"`
  380. ClassifyNameThird string `description:"三级分类名称"`
  381. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  382. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  383. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  384. ReportCreateTime time.Time `description:"报告时间创建时间"`
  385. }
  386. func GetReportById(reportId int) (item *ReportDetail, err error) {
  387. o := global.DbMap[utils.DbNameReport]
  388. sql := `SELECT * FROM report WHERE id=?`
  389. err = o.Raw(sql, reportId).First(&item).Error
  390. return
  391. }
  392. func GetReportByIds(reportIds string) (list []*ReportDetail, err error) {
  393. o := global.DbMap[utils.DbNameReport]
  394. sql := `SELECT * FROM report WHERE id in ` + reportIds
  395. err = o.Raw(sql).Find(&list).Error
  396. return
  397. }
  398. // GetSimpleReportByIds 根据报告ID查询报告基本信息
  399. func GetSimpleReportByIds(reportIds []int) (list []*Report, err error) {
  400. if len(reportIds) == 0 {
  401. return
  402. }
  403. o := global.DbMap[utils.DbNameReport]
  404. sql := `SELECT id, title, report_code FROM report WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
  405. err = o.Raw(sql, reportIds).Find(&list).Error
  406. return
  407. }
  408. // GetReportStage
  409. // @Description: 获取报告的最大期数(每一年的最大期数)
  410. // @author: Roc
  411. // @datetime 2024-06-03 17:44:14
  412. // @param classifyIdFirst int
  413. // @param classifyIdSecond int
  414. // @param classifyIdThird int
  415. // @return count int
  416. // @return err error
  417. func GetReportStage(classifyIdFirst, classifyIdSecond, classifyIdThird int) (count int, err error) {
  418. o := global.DbMap[utils.DbNameReport]
  419. classifyId := classifyIdThird
  420. if classifyId <= 0 {
  421. classifyId = classifyIdSecond
  422. }
  423. if classifyId <= 0 {
  424. classifyId = classifyIdFirst
  425. }
  426. if classifyId <= 0 {
  427. err = errors.New("错误的分类id")
  428. return
  429. }
  430. yearStart := time.Date(time.Now().Local().Year(), 1, 1, 0, 0, 0, 0, time.Local)
  431. sql := `SELECT MAX(stage) AS max_stage FROM report WHERE create_time > ? `
  432. if classifyIdThird > 0 {
  433. sql += " AND classify_id_third = ? "
  434. } else if classifyIdSecond > 0 {
  435. sql += " AND classify_id_second = ? "
  436. } else {
  437. sql += " AND classify_id_first = ? "
  438. }
  439. var maxNull sql2.NullInt64
  440. err = o.Raw(sql, yearStart, classifyId).Scan(&maxNull).Error
  441. if err != nil {
  442. return
  443. }
  444. if maxNull.Valid {
  445. count = int(maxNull.Int64)
  446. }
  447. return
  448. }
  449. // GetReportStageEdit
  450. // @Description: 获取报告的最大期数(每一年的最大期数)
  451. // @author: Roc
  452. // @datetime 2024-06-04 13:50:34
  453. // @param classifyIdFirst int
  454. // @param classifyIdSecond int
  455. // @param classifyIdThird int
  456. // @param reportId int
  457. // @return count int
  458. // @return err error
  459. //func GetReportStageEdit(classifyIdFirst, classifyIdSecond, classifyIdThird, reportId int) (count int, err error) {
  460. // classifyId := classifyIdThird
  461. // if classifyId <= 0 {
  462. // classifyId = classifyIdSecond
  463. // }
  464. // if classifyId <= 0 {
  465. // classifyId = classifyIdFirst
  466. // }
  467. // if classifyId <= 0 {
  468. // err = errors.New("错误的分类id")
  469. // return
  470. // }
  471. // yearStart := time.Date(time.Now().Local().Year(), 1, 1, 0, 0, 0, 0, time.Local)
  472. //
  473. // sql := `SELECT MAX(stage) AS max_stage FROM report WHERE create_time > ? AND id<>? `
  474. // if classifyIdThird > 0 {
  475. // sql += " AND classify_id_third = ? "
  476. // } else if classifyIdSecond > 0 {
  477. // sql += " AND classify_id_second = ? "
  478. // } else {
  479. // sql = " AND classify_id_first = ? "
  480. // }
  481. //
  482. // o := global.DbMap[utils.DbNameReport]
  483. // o.Raw(sql, yearStart, reportId, classifyId).QueryRow(&count)
  484. //
  485. // return
  486. //}
  487. type PublishReq struct {
  488. ReportIds string `description:"报告id,多个用英文逗号隔开"`
  489. ReportUrl string `description:"报告Url"`
  490. }
  491. type PublishCancelReq struct {
  492. ReportIds int `description:"报告id"`
  493. }
  494. type DeleteReq struct {
  495. ReportIds int `description:"报告id"`
  496. }
  497. type AddReq struct {
  498. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  499. ClassifyIdFirst int `description:"一级分类id"`
  500. ClassifyNameFirst string `description:"一级分类名称"`
  501. ClassifyIdSecond int `description:"二级分类id"`
  502. ClassifyNameSecond string `description:"二级分类名称"`
  503. ClassifyIdThird int `description:"三级分类id"`
  504. ClassifyNameThird string `description:"三级分类名称"`
  505. Title string `description:"标题"`
  506. Abstract string `description:"摘要"`
  507. Author string `description:"作者"`
  508. Frequency string `description:"频度"`
  509. State int `description:"状态:1:未发布,2:已发布"`
  510. Content string `description:"内容"`
  511. CreateTime string `description:"创建时间"`
  512. ReportVersion int `description:"1:旧版,2:新版"`
  513. ContentStruct string `description:"内容组件"`
  514. HeadImg string `description:"报告头图地址"`
  515. EndImg string `description:"报告尾图地址"`
  516. CanvasColor string `description:"画布颜色"`
  517. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  518. HeadResourceId int `description:"版头资源ID"`
  519. EndResourceId int `description:"版尾资源ID"`
  520. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  521. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  522. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  523. InheritReportId int `description:"待继承的报告ID"`
  524. GrantAdminIdList []int `description:"授权用户id列表"`
  525. }
  526. type PrePublishReq struct {
  527. ReportId int `description:"报告id"`
  528. PrePublishTime string `description:"预发布时间"`
  529. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  530. ReportUrl string `description:"报告Url"`
  531. }
  532. type AddResp struct {
  533. ReportId int64 `description:"报告id"`
  534. ReportCode string `description:"报告code"`
  535. }
  536. func AddReport(item *Report) (lastId int64, err error) {
  537. o := global.DbMap[utils.DbNameReport]
  538. err = o.Create(item).Error
  539. if err != nil {
  540. return
  541. }
  542. lastId = int64(item.Id)
  543. return
  544. }
  545. type EditReq struct {
  546. ReportId int64 `description:"报告id"`
  547. ClassifyIdFirst int `description:"一级分类id"`
  548. ClassifyNameFirst string `description:"一级分类名称"`
  549. ClassifyIdSecond int `description:"二级分类id"`
  550. ClassifyNameSecond string `description:"二级分类名称"`
  551. ClassifyIdThird int `description:"三级分类id"`
  552. ClassifyNameThird string `description:"三级分类名称"`
  553. Title string `description:"标题"`
  554. Abstract string `description:"摘要"`
  555. Author string `description:"作者"`
  556. Frequency string `description:"频度"`
  557. State int `description:"状态:1:未发布,2:已发布"`
  558. Content string `description:"内容"`
  559. CreateTime string `description:"创建时间"`
  560. ContentStruct string `description:"内容组件"`
  561. HeadImg string `description:"报告头图地址"`
  562. EndImg string `description:"报告尾图地址"`
  563. CanvasColor string `description:"画布颜色"`
  564. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  565. HeadResourceId int `description:"版头资源ID"`
  566. EndResourceId int `description:"版尾资源ID"`
  567. //CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  568. //ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  569. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  570. GrantAdminIdList []int `description:"授权用户id列表"`
  571. }
  572. type EditResp struct {
  573. ReportId int64 `description:"报告id"`
  574. ReportCode string `description:"报告code"`
  575. }
  576. func EditReport(item *Report, reportId int64) (err error) {
  577. o := global.DbMap[utils.DbNameReport]
  578. sql := `UPDATE report
  579. SET
  580. classify_id_first =?,
  581. classify_name_first = ?,
  582. classify_id_second = ?,
  583. classify_name_second = ?,
  584. title = ?,
  585. abstract = ?,
  586. author = ?,
  587. frequency = ?,
  588. state = ?,
  589. content = ?,
  590. content_sub = ?,
  591. stage =?,
  592. create_time = ?,
  593. modify_time = ?
  594. WHERE id = ? `
  595. err = o.Exec(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title,
  596. item.Abstract, item.Author, item.Frequency, item.State, item.Content, item.ContentSub, item.Stage, item.CreateTime, time.Now(), reportId).Error
  597. return
  598. }
  599. func (m *Report) Update(cols []string) (err error) {
  600. o := global.DbMap[utils.DbNameReport]
  601. err = o.Select(cols).Updates(m).Error
  602. return
  603. }
  604. type ReportDetailReq struct {
  605. ReportId int `description:"报告id"`
  606. }
  607. type ClassifyIdDetailReq struct {
  608. ClassifyIdFirst int `description:"报告一级分类id"`
  609. ClassifyIdSecond int `description:"报告二级分类id"`
  610. }
  611. func GetReportDetailByClassifyId(classifyIdFirst, classifyIdSecond int) (item *Report, err error) {
  612. o := global.DbMap[utils.DbNameReport]
  613. sql := ` SELECT * FROM report WHERE 1=1 `
  614. if classifyIdSecond > 0 {
  615. sql = sql + ` AND classify_id_second=? ORDER BY stage DESC LIMIT 1`
  616. err = o.Raw(sql, classifyIdSecond).First(&item).Error
  617. } else {
  618. sql = sql + ` AND classify_id_first=? ORDER BY stage DESC LIMIT 1`
  619. err = o.Raw(sql, classifyIdFirst).First(&item).Error
  620. }
  621. return
  622. }
  623. type SendTemplateMsgReq struct {
  624. ReportId int `description:"报告id"`
  625. }
  626. // SendTemplateMsgResp
  627. // @Description: 报告推送返回结构体
  628. type SendTemplateMsgResp struct {
  629. ReportId int `description:"报告id"`
  630. MsgSendTime string `description:"报告推送时间"`
  631. }
  632. func ModifyReportMsgIsSend(reportId int) (err error) {
  633. o := global.DbMap[utils.DbNameReport]
  634. report, err := GetReportById(reportId)
  635. if err != nil {
  636. return
  637. }
  638. if report.MsgIsSend == 0 {
  639. sql := `UPDATE report SET msg_is_send = 1, msg_send_time=NOW() WHERE id = ? `
  640. err = o.Exec(sql, reportId).Error
  641. }
  642. return
  643. }
  644. func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  645. o := global.DbMap[utils.DbNameReport]
  646. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? `
  647. err = o.Exec(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Error
  648. return
  649. }
  650. // ModifyReportVideoByNoVideo
  651. // @Description: 修改无音频的报告音频信息
  652. // @author: Roc
  653. // @datetime 2024-07-25 18:03:05
  654. // @param reportId int
  655. // @param videoUrl string
  656. // @param videoName string
  657. // @param videoSize string
  658. // @param playSeconds float64
  659. // @return err error
  660. func ModifyReportVideoByNoVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  661. o := global.DbMap[utils.DbNameReport]
  662. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? AND video_url=""`
  663. err = o.Exec(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Error
  664. return
  665. }
  666. type ReportItem struct {
  667. Id int `gorm:"column:id;primaryKey;autoIncrement" description:"报告Id"`
  668. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  669. ClassifyIdFirst int `description:"一级分类id"`
  670. ClassifyNameFirst string `description:"一级分类名称"`
  671. ClassifyIdSecond int `description:"二级分类id"`
  672. ClassifyNameSecond string `description:"二级分类名称"`
  673. Title string `description:"标题"`
  674. Abstract string `description:"摘要"`
  675. Author string `description:"作者"`
  676. Frequency string `description:"频度"`
  677. CreateTime time.Time `description:"创建时间"`
  678. ModifyTime time.Time `description:"修改时间"`
  679. State int `description:"1:未发布,2:已发布"`
  680. PublishTime time.Time `description:"发布时间"`
  681. Stage int `description:"期数"`
  682. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  683. Content string `description:"内容"`
  684. VideoUrl string `description:"音频文件URL"`
  685. VideoName string `description:"音频文件名称"`
  686. VideoPlaySeconds string `description:"音频播放时长"`
  687. ContentSub string `description:"内容前两个章节"`
  688. }
  689. //func GetReportItemById(reportId int) (item *ReportItem, err error) {
  690. // o := global.DbMap[utils.DbNameReport]
  691. // sql := `SELECT * FROM report WHERE id=?`
  692. // err = o.Raw(sql, reportId).First(&item).Error
  693. // return
  694. //}
  695. type SaveReportContent struct {
  696. Content string `description:"内容"`
  697. ReportId int `description:"报告id"`
  698. NoChange int `description:"内容是否未改变:1:内容未改变"`
  699. // 以下是智能研报相关
  700. ContentStruct string `description:"内容组件"`
  701. HeadImg string `description:"报告头图地址"`
  702. EndImg string `description:"报告尾图地址"`
  703. CanvasColor string `description:"画布颜色"`
  704. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  705. HeadResourceId int `description:"版头资源ID"`
  706. EndResourceId int `description:"版尾资源ID"`
  707. }
  708. //func EditReportContent(reportId int, content, contentSub string) (err error) {
  709. // o := global.DbMap[utils.DbNameReport]
  710. // sql := ` UPDATE report SET content=?,content_sub=?,modify_time=NOW() WHERE id=? `
  711. // err = o.Exec(sql, content, contentSub, reportId).Error
  712. // return
  713. //}
  714. func AddReportSaveLog(reportId, adminId int, content, contentSub, contentStruct, canvasColor, adminName string, headResourceId, endResourceId int) (err error) {
  715. o := global.DbMap[utils.DbNameReport]
  716. 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 (?,?,?,?,?,?,?,?,?) `
  717. err = o.Exec(sql, reportId, content, contentSub, contentStruct, canvasColor, headResourceId, endResourceId, adminId, adminName).Error
  718. return
  719. }
  720. func MultiAddReportChaptersSaveLog(items []*ReportChapter, adminId int, adminRealName string) (err error) {
  721. o := global.DbMap[utils.DbNameReport]
  722. sql := `INSERT INTO report_save_log(report_id, report_chapter_id, content, content_sub,content_struct,admin_id, admin_name) VALUES (?,?,?,?,?,?,?)`
  723. for _, v := range items {
  724. err = o.Exec(sql, v.ReportId, v.ReportChapterId, v.Content, v.ContentSub, v.ContentStruct, adminId, adminRealName).Error
  725. if err != nil {
  726. return
  727. }
  728. }
  729. return
  730. }
  731. type SaveReportContentResp struct {
  732. ReportId int `description:"报告id"`
  733. }
  734. func ModifyReportCode(reportId int64, reportCode string) (err error) {
  735. o := global.DbMap[utils.DbNameReport]
  736. sql := `UPDATE report SET report_code=? WHERE id=? `
  737. err = o.Exec(sql, reportCode, reportId).Error
  738. return
  739. }
  740. func ModifyReportThsMsgIsSend(item *ReportDetail) (err error) {
  741. o := global.DbMap[utils.DbNameReport]
  742. if item.ThsMsgIsSend == 0 {
  743. sql := `UPDATE report SET ths_msg_is_send = 1 WHERE id = ? `
  744. err = o.Exec(sql, item.Id).Error
  745. }
  746. return
  747. }
  748. type ThsSendTemplateMsgReq struct {
  749. ReportId []int `description:"报告id"`
  750. }
  751. type PublishDayWeekReportReq struct {
  752. ReportId int `description:"报告ID"`
  753. }
  754. // SaveDayWeekReportReq 新增晨报周报请求体
  755. type SaveDayWeekReportReq struct {
  756. ReportId int `description:"报告ID"`
  757. Title string `description:"标题"`
  758. ReportType string `description:"一级分类ID"`
  759. Author string `description:"作者"`
  760. CreateTime string `description:"创建时间"`
  761. }
  762. // GetDayWeekReportStage 获取晨报周报期数
  763. //func GetDayWeekReportStage(classifyIdFirst int, yearStart time.Time) (count int, err error) {
  764. // o := global.DbMap[utils.DbNameReport]
  765. // sql := " SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first = ? AND create_time > ? "
  766. // o.Raw(sql, classifyIdFirst, yearStart).QueryRow(&count)
  767. // return
  768. //}
  769. // GetReportByReportId 主键获取报告
  770. func GetReportByReportId(reportId int) (item *Report, err error) {
  771. o := global.DbMap[utils.DbNameReport]
  772. sql := `SELECT * FROM report WHERE id = ?`
  773. err = o.Raw(sql, reportId).First(&item).Error
  774. return
  775. }
  776. // GetReportByOldReportId 根据老报告id主键获取报告
  777. func GetReportByOldReportId(reportId int) (item *Report, err error) {
  778. o := global.DbMap[utils.DbNameReport]
  779. sql := `SELECT * FROM report WHERE old_report_id = ?`
  780. err = o.Raw(sql, reportId).First(&item).Error
  781. return
  782. }
  783. // DeleteDayWeekReportAndChapter 删除晨周报及章节
  784. func DeleteDayWeekReportAndChapter(reportId int) (err error) {
  785. to := global.DbMap[utils.DbNameReport].Begin()
  786. defer func() {
  787. if err != nil {
  788. _ = to.Rollback()
  789. } else {
  790. _ = to.Commit()
  791. }
  792. }()
  793. sql := ` DELETE FROM report WHERE id = ? LIMIT 1 `
  794. if err = to.Exec(sql, reportId).Error; err != nil {
  795. return
  796. }
  797. sql = ` DELETE FROM report_chapter WHERE report_id = ? `
  798. if err = to.Exec(sql, reportId).Error; err != nil {
  799. return
  800. }
  801. return
  802. }
  803. // UpdateReport 更新报告
  804. func (reportInfo *Report) UpdateReport(cols []string) (err error) {
  805. err = global.DbMap[utils.DbNameReport].Select(cols).Updates(reportInfo).Error
  806. return
  807. }
  808. // ReportDetailView
  809. // @Description: 晨周报详情
  810. type ReportDetailView struct {
  811. *ReportDetail
  812. ChapterList []*ReportChapter
  813. GrandAdminList []ReportDetailViewAdmin
  814. PermissionList []ReportDetailViewPermission
  815. }
  816. // ReportDetailViewAdmin
  817. // @Description: 报告里面的授权人
  818. type ReportDetailViewAdmin struct {
  819. AdminId int
  820. AdminName string
  821. }
  822. // ReportDetailViewPermission
  823. // @Description: 报告分类关联的品种权限
  824. type ReportDetailViewPermission struct {
  825. PermissionId int
  826. PermissionName string
  827. }
  828. //func GetUnPublishDayReport(startTime time.Time, endTime time.Time) (item *Report, err error) {
  829. // o := global.DbMap[utils.DbNameReport]
  830. // sql := ` SELECT
  831. // *
  832. // FROM
  833. // report AS a
  834. // WHERE
  835. // a.has_chapter = 1
  836. // AND a.chapter_type = "day"
  837. // AND a.state = 1
  838. // AND (
  839. // a.create_time BETWEEN ? AND ?
  840. // )
  841. // ORDER BY
  842. // a.create_time DESC
  843. // LIMIT 1 `
  844. // err = o.Raw(sql, startTime, endTime).First(&item).Error
  845. // return
  846. //}
  847. type ElasticReportDetail struct {
  848. ReportId int `description:"报告ID"`
  849. ReportChapterId int `description:"报告章节ID"`
  850. Title string `description:"标题"`
  851. Abstract string `description:"摘要"`
  852. BodyContent string `description:"内容"`
  853. PublishTime string `description:"发布时间"`
  854. PublishState int `description:"发布状态 1-未发布 2-已发布"`
  855. Author string `description:"作者"`
  856. ClassifyIdFirst int `description:"一级分类ID"`
  857. ClassifyNameFirst string `description:"一级分类名称"`
  858. ClassifyIdSecond int `description:"二级分类ID"`
  859. ClassifyNameSecond string `description:"二级分类名称"`
  860. ClassifyId int `description:"最小单元的分类ID"`
  861. ClassifyName string `description:"最小单元的分类名称"`
  862. Categories string `description:"关联的品种名称(包括品种别名)"`
  863. StageStr string `description:"报告期数"`
  864. }
  865. // GetLastPublishDayWeekReport 获取上一篇已发布的晨周报
  866. //func GetLastPublishDayWeekReport(chapterType string) (item *Report, err error) {
  867. // o := global.DbMap[utils.DbNameReport]
  868. // sql := ` SELECT * FROM report WHERE has_chapter = 1 AND chapter_type = ? AND state = 2 ORDER BY publish_time DESC LIMIT 1 `
  869. // err = o.Raw(sql, chapterType).First(&item).Error
  870. //
  871. // return
  872. //}
  873. // GetNewReportExist
  874. //func GetNewReportExist(oldReportId int) (item *Report, err error) {
  875. // o := global.DbMap[utils.DbNameReport]
  876. // sql := ` SELECT id FROM report WHERE old_report_id = ? LIMIT 1 `
  877. // err = o.Raw(sql, oldReportId).First(&item).Error
  878. // return
  879. //}
  880. // PublishReportAndChapter 发布报告及章节
  881. func PublishReportAndChapter(reportInfo *Report, isPublishReport bool, cols []string) (err error) {
  882. to := global.DbMap[utils.DbNameReport].Begin()
  883. defer func() {
  884. if err != nil {
  885. _ = to.Rollback()
  886. } else {
  887. _ = to.Commit()
  888. }
  889. }()
  890. // 更新报告
  891. if isPublishReport {
  892. err = to.Select(cols).Updates(reportInfo).Error
  893. if err != nil {
  894. return
  895. }
  896. }
  897. // 发布该报告的所有章节
  898. sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? `
  899. err = to.Exec(sql, reportInfo.PublishTime, reportInfo.Id).Error
  900. // 发布章节
  901. //if len(publishIds) > 0 {
  902. // sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(publishIds)) + `) `
  903. // err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id, publishIds).Error
  904. //}
  905. //if len(unPublishIds) > 0 {
  906. // sql := ` UPDATE report_chapter SET publish_state = 1, publish_time = NULL, is_edit = 0 WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(unPublishIds)) + `) `
  907. // err = to.Raw(sql, reportInfo.Id, unPublishIds).Error
  908. //}
  909. return
  910. }
  911. //func GetSyncEmptyVideoReport() (list []*Report, err error) {
  912. // o := global.DbMap[utils.DbNameReport]
  913. // sql := ` SELECT id FROM report WHERE old_report_id > 0 AND state = 2 AND chapter_type = "" AND (video_size = "" OR video_play_seconds = "")
  914. //UNION ALL
  915. //SELECT DISTINCT report_id FROM report_chapter WHERE publish_state = 2 AND (video_size = "" OR video_play_seconds = "") `
  916. // err = o.Raw(sql).Find(&list).Error
  917. // return
  918. //}
  919. // PublishReportById 发布报告
  920. func PublishReportById(reportId int, publishTime time.Time, lastModifyAdminId int, lastModifyAdminName string) (err error) {
  921. o := global.DbMap[utils.DbNameReport]
  922. 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 = ? `
  923. err = o.Exec(sql, publishTime, lastModifyAdminId, lastModifyAdminName, reportId).Error
  924. return
  925. }
  926. // ResetReportById 重置报告状态
  927. func ResetReportById(reportId, state int, lastModifyAdminId int, lastModifyAdminName string) (err error) {
  928. o := global.DbMap[utils.DbNameReport]
  929. 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 = ?`
  930. err = o.Exec(sql, state, lastModifyAdminId, lastModifyAdminName, reportId).Error
  931. return
  932. }
  933. // GetCommentReportByReportId 查询有留言的报告列表
  934. //func GetCommentReportByReportId(condition string, pars []interface{}, startSize, pageSize int) (list []*Report, err error) {
  935. // o := global.DbMap[utils.DbNameReport]
  936. // sql := `SELECT
  937. // id,
  938. // create_time,
  939. // title,
  940. // classify_name_first,
  941. // classify_id_first,
  942. // classify_name_second,
  943. // classify_id_second,
  944. // state,
  945. //IF
  946. // ( publish_time, publish_time, create_time ) AS publish_time
  947. //FROM
  948. // report
  949. //WHERE
  950. // 1=1
  951. // `
  952. // if condition != "" {
  953. // sql += condition
  954. // }
  955. // sql += ` ORDER BY publish_time DESC , title ASC LIMIT ?,?`
  956. // pars = append(pars, startSize, pageSize)
  957. // err = o.Raw(sql, pars...).Find(&list).Error
  958. // return
  959. //}
  960. // GetCommentReportByReportIdOrderBy 查询有留言的报告列表(指定排序)
  961. //func GetCommentReportByReportIdOrderBy(condition string, pars []interface{}, startSize, pageSize int, orderBy string) (list []*Report, err error) {
  962. // o := global.DbMap[utils.DbNameReport]
  963. // sql := `SELECT
  964. // id,
  965. // create_time,
  966. // title,
  967. // classify_name_first,
  968. // classify_id_first,
  969. // classify_name_second,
  970. // classify_id_second,
  971. // state,
  972. //IF
  973. // ( publish_time, publish_time, create_time ) AS publish_time
  974. //FROM
  975. // report
  976. //WHERE
  977. // 1=1
  978. // `
  979. // if condition != "" {
  980. // sql += condition
  981. // }
  982. // if orderBy == `` {
  983. // sql += ` ORDER BY publish_time DESC , title ASC `
  984. // } else {
  985. // sql += orderBy
  986. // }
  987. // sql += ` LIMIT ?,? `
  988. // pars = append(pars, startSize, pageSize)
  989. // err = o.Raw(sql, pars...).Find(&list).Error
  990. // return
  991. //}
  992. // GetCommentReportTotalByReportId 查询有留言的报告列表总数
  993. //func GetCommentReportTotalByReportId(condition string, pars []interface{}) (total int64, err error) {
  994. // o := global.DbMap[utils.DbNameReport]
  995. // sql := `SELECT count(*)
  996. // FROM report WHERE 1=1`
  997. // if condition != "" {
  998. // sql += condition
  999. // }
  1000. // err = o.Raw(sql, pars...).QueryRow(&total)
  1001. // return
  1002. //}
  1003. // LikeReportItem 点赞相关的报告列表
  1004. type LikeReportItem struct {
  1005. ReportId int `description:"报告Id"`
  1006. ReportChapterId int `description:"报告章节Id"`
  1007. ClassifyIdFirst int `description:"一级分类id"`
  1008. ClassifyNameFirst string `description:"一级分类名称"`
  1009. ClassifyIdSecond int `description:"二级分类id"`
  1010. ClassifyNameSecond string `description:"二级分类名称"`
  1011. ReportChapterTypeId int `description:"章节类型"`
  1012. ReportChapterTypeName string `description:"品种名称"`
  1013. PublishTime time.Time `description:"发布时间" `
  1014. Title string `description:"标题"`
  1015. }
  1016. // GetLikeReportByReportIdReportChapterId 获取有被点赞的报告列表
  1017. //func GetLikeReportByReportIdReportChapterId(reportIds string, chapterIds string, orderStr string, startSize, pageSize int) (list []*LikeReportItem, err error) {
  1018. // o := global.DbMap[utils.DbNameReport]
  1019. // sql := `( SELECT
  1020. //id AS report_id,
  1021. //0 AS report_chapter_id,
  1022. //classify_id_first,
  1023. //classify_id_second,
  1024. //classify_name_first,
  1025. //classify_name_second,
  1026. //0 as report_chapter_type_id,
  1027. //"" as report_chapter_type_name,
  1028. //publish_time,
  1029. //title
  1030. //FROM
  1031. // report
  1032. //WHERE
  1033. // classify_name_first != "晨报"
  1034. // AND classify_name_first != "周报"
  1035. // AND id in (` + reportIds + `)
  1036. // )
  1037. //UNION
  1038. //
  1039. //( SELECT
  1040. //report_id,
  1041. //report_chapter_id,
  1042. //classify_id_first,
  1043. //0 as classify_id_second,
  1044. //classify_name_first,
  1045. //null as classify_name_second,
  1046. //type_id as report_chapter_type_id,
  1047. //type_name as report_chapter_type_name,
  1048. //publish_time,
  1049. //title
  1050. //FROM
  1051. // report_chapter
  1052. //WHERE
  1053. // report_chapter_id in (` + chapterIds + `)
  1054. // )`
  1055. // if orderStr != "" {
  1056. // sql += ` ORDER BY FIELD(CONCAT(report_id, "-",report_chapter_id),` + orderStr + `)`
  1057. // } else {
  1058. // sql += ` ORDER BY publish_time DESC, report_id Desc`
  1059. // }
  1060. // sql += ` LIMIT ?,?`
  1061. // err = o.Raw(sql, startSize, pageSize).QueryRows(&list)
  1062. // return
  1063. //}
  1064. // GetLikeReportTotalByReportIdReportChapterId 获取有被点赞的报告列表总数
  1065. //func GetLikeReportTotalByReportIdReportChapterId(reportIds string, chapterIds string) (total int64, err error) {
  1066. // o := global.DbMap[utils.DbNameReport]
  1067. // sql := `select count(*) from (( SELECT
  1068. //id AS report_id,
  1069. //0 AS report_chapter_id,
  1070. //classify_id_first,
  1071. //classify_id_second,
  1072. //classify_name_first,
  1073. //classify_name_second,
  1074. //0 as report_chapter_type_id,
  1075. //publish_time,
  1076. //title
  1077. //FROM
  1078. // report
  1079. //WHERE
  1080. // classify_name_first != "晨报"
  1081. // AND classify_name_first != "周报"
  1082. // AND id in (` + reportIds + `)
  1083. // )
  1084. //UNION
  1085. //
  1086. //( SELECT
  1087. //report_id,
  1088. //report_chapter_id,
  1089. //classify_id_first,
  1090. //0 as classify_id_second,
  1091. //classify_name_first,
  1092. //null as classify_name_second,
  1093. //type_id as report_chapter_type_id,
  1094. //publish_time,
  1095. //title
  1096. //FROM
  1097. // report_chapter
  1098. //WHERE
  1099. //report_chapter_id in (` + chapterIds + `)
  1100. // )) r`
  1101. // err = o.Raw(sql).QueryRow(&total)
  1102. // return
  1103. //}
  1104. // GetPageReportList 分页获取报告列表
  1105. //func GetPageReportList(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*ReportList, err error) {
  1106. // o := global.DbMap[utils.DbNameReport]
  1107. // sql := `SELECT * FROM report WHERE 1=1 `
  1108. // sql += condition
  1109. // sql += ` ORDER BY modify_time DESC`
  1110. // totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  1111. // err = o.Raw(totalSql, pars...).QueryRow(&total)
  1112. // if err != nil {
  1113. // return
  1114. // }
  1115. // sql += ` LIMIT ?,? `
  1116. // err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1117. // return
  1118. //}
  1119. // SunCodeReq 获取太阳码请求体
  1120. type SunCodeReq struct {
  1121. CodePage string `json:"CodePage" description:"太阳码page"`
  1122. CodeScene string `json:"CodeScene" description:"太阳码scene"`
  1123. }
  1124. // YbPcSuncode 活动海报表
  1125. type YbPcSuncode struct {
  1126. SuncodeID uint32 `gorm:"column:suncode_id;primaryKey;autoIncrement"`
  1127. Scene string `gorm:"column:scene;type:varchar(255);not null;default:0" json:"scene"` // 微信scene
  1128. SceneMd5 string `gorm:"column:scene_md5;type:varchar(255);not null" json:"sceneMd5"`
  1129. CodePage string `gorm:"column:code_page;type:varchar(255);not null;default:''" json:"codePage"` // 路径
  1130. SuncodeUrl string `gorm:"column:suncode_url;type:varchar(255);not null;default:''" json:"suncodeUrl"` // 太阳码储存地址
  1131. CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"`
  1132. }
  1133. // GetYbPcSunCode 获取太阳码
  1134. func GetYbPcSunCode(scene, page string) (item *YbPcSuncode, err error) {
  1135. o := global.DbMap[utils.DbNameWeekly]
  1136. sql := `SELECT * FROM yb_pc_suncode WHERE scene = ? AND code_page = ? `
  1137. err = o.Raw(sql, scene, page).First(&item).Error
  1138. return
  1139. }
  1140. func AddYbPcSunCode(item *YbPcSuncode) (err error) {
  1141. o := global.DbMap[utils.DbNameWeekly]
  1142. err = o.Create(item).Error
  1143. return
  1144. }
  1145. // YbSuncodePars 小程序太阳码scene参数
  1146. type YbSuncodePars struct {
  1147. ID uint32 `gorm:"column:id;primaryKey;autoIncrement"`
  1148. Scene string `gorm:"column:scene;type:varchar(255);not null;default:''" json:"scene"` // scene参数
  1149. SceneKey string `gorm:"column:scene_key;type:varchar(32);not null;default:''" json:"scene_key"` // MD5值
  1150. CreateTime time.Time `gorm:"column:create_time;type:datetime;default:CURRENT_TIMESTAMP" json:"createTime"`
  1151. }
  1152. func AddYbSuncodePars(item *YbSuncodePars) (err error) {
  1153. o := global.DbMap[utils.DbNameWeekly]
  1154. err = o.Create(item).Error
  1155. return
  1156. }
  1157. // UpdateReportSecondClassifyNameByClassifyId 更新报告分类名称字段
  1158. func UpdateReportSecondClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1159. o := global.DbMap[utils.DbNameReport]
  1160. sql := " UPDATE report SET classify_name_second = ? WHERE classify_id_second = ? "
  1161. err = o.Exec(sql, classifyName, classifyId).Error
  1162. return
  1163. }
  1164. // UpdateReportFirstClassifyNameByClassifyId 更新报告分类一级名称字段
  1165. func UpdateReportFirstClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1166. o := global.DbMap[utils.DbNameReport]
  1167. sql := " UPDATE report SET classify_name_first = ? WHERE classify_id_first = ? "
  1168. err = o.Exec(sql, classifyName, classifyId).Error
  1169. return
  1170. }
  1171. // UpdateReportThirdClassifyNameByClassifyId 更新报告的三级分类名称字段
  1172. func UpdateReportThirdClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1173. o := global.DbMap[utils.DbNameReport]
  1174. sql := " UPDATE report SET classify_name_third = ? WHERE classify_id_third = ? "
  1175. err = o.Exec(sql, classifyName, classifyId).Error
  1176. return
  1177. }
  1178. // UpdateReportSecondClassifyFirstNameByClassifyId 更新报告二级分类的一级分类名称和id
  1179. //func UpdateReportSecondClassifyFirstNameByClassifyId(classifyId, newClassifyId int, classifyName string) (err error) {
  1180. // o := global.DbMap[utils.DbNameReport]
  1181. // sql := " UPDATE report SET classify_name_first = ?, classify_id_first = ? WHERE classify_id_second = ? "
  1182. // err = o.Exec(sql, classifyName, newClassifyId, classifyId).Error
  1183. // return
  1184. //}
  1185. // GetEmptyContentSubPPTReport 获取前两章为空的PPT报告
  1186. //func GetEmptyContentSubPPTReport() (list []*Report, err error) {
  1187. // sql := `SELECT
  1188. // r.id,
  1189. // r.content,
  1190. // r.content_sub
  1191. // FROM
  1192. // report AS r
  1193. // JOIN ppt_v2 AS p ON r.id = p.report_id
  1194. // WHERE
  1195. // p.report_id > 0 AND r.content_sub = ""`
  1196. // err = orm.NewOrmUsingDB("rddp").Raw(sql).QueryRows(&list)
  1197. // return
  1198. //}
  1199. // ModifyReportAuthor 更改报告作者
  1200. func ModifyReportAuthor(condition string, pars []interface{}, authorName string) (count int, err error) {
  1201. sql := `UPDATE english_report set author = ? WHERE 1=1 `
  1202. if condition != "" {
  1203. sql += condition
  1204. }
  1205. res := global.DbMap[utils.DbNameReport].Exec(sql, utils.ForwardPars(pars, authorName)...)
  1206. if res.Error != nil {
  1207. err = res.Error
  1208. return
  1209. }
  1210. count = int(res.RowsAffected)
  1211. return
  1212. }
  1213. func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
  1214. o := global.DbMap[utils.DbNameReport]
  1215. sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
  1216. err = o.Exec(sql1, reportId).Error
  1217. if err != nil {
  1218. return
  1219. }
  1220. //修改音频标题
  1221. sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !="" and video_name is not null)`
  1222. err = o.Exec(sql2, reportId).Error
  1223. return
  1224. }
  1225. func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
  1226. o := global.DbMap[utils.DbNameReport]
  1227. sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
  1228. err = o.Exec(sql1, reportId).Error
  1229. if err != nil {
  1230. return
  1231. }
  1232. //修改音频标题
  1233. 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)`
  1234. err = o.Exec(sql2, reportId).Error
  1235. return
  1236. }
  1237. // MarkEditReport 标记编辑英文研报的请求数据
  1238. type MarkEditReport struct {
  1239. ReportId int `description:"研报id"`
  1240. ReportChapterId int `description:"研报章节id"`
  1241. Status int `description:"标记状态,1:编辑中,2:查询状态,3:编辑完成"`
  1242. }
  1243. type MarkReportResp struct {
  1244. Status int `description:"状态:0:无人编辑, 1:当前有人在编辑"`
  1245. Msg string `description:"提示信息"`
  1246. Editor string `description:"编辑者姓名"`
  1247. }
  1248. type MarkReportItem struct {
  1249. AdminId int `description:"编辑者ID"`
  1250. Editor string `description:"编辑者姓名"`
  1251. ReportClassifyNameFirst string
  1252. }
  1253. // GetReportByCondition 获取报告
  1254. func GetReportByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, isPage bool, startSize, pageSize int) (items []*Report, err error) {
  1255. o := global.DbMap[utils.DbNameReport]
  1256. fields := `*`
  1257. if len(fieldArr) > 0 {
  1258. fields = strings.Join(fieldArr, ",")
  1259. }
  1260. sql := `SELECT ` + fields + ` FROM report WHERE 1=1 `
  1261. sql += condition
  1262. order := ` ORDER BY modify_time DESC`
  1263. if orderRule != `` {
  1264. order = orderRule
  1265. }
  1266. sql += order
  1267. if isPage {
  1268. sql += ` LIMIT ?,?`
  1269. pars = append(pars, startSize, pageSize)
  1270. err = o.Raw(sql, pars...).Find(&items).Error
  1271. } else {
  1272. err = o.Raw(sql, pars...).Find(&items).Error
  1273. }
  1274. return
  1275. }
  1276. // ModifyReportMsgIsSendV2 更新报告消息状态
  1277. func ModifyReportMsgIsSendV2(reportId int) (err error) {
  1278. o := global.DbMap[utils.DbNameReport]
  1279. sql := `UPDATE report SET msg_is_send = 1, ths_msg_is_send = 1, msg_send_time = NOW() WHERE id = ? LIMIT 1`
  1280. err = o.Exec(sql, reportId).Error
  1281. return
  1282. }
  1283. // SetPrePublishReportById 设置定时发布
  1284. func SetPrePublishReportById(reportId int, prePublishTime string, preMsgSend int) (err error) {
  1285. o := global.DbMap[utils.DbNameReport]
  1286. sql := `UPDATE report SET pre_publish_time=?, pre_msg_send=? WHERE id = ? and state = 1 `
  1287. err = o.Exec(sql, prePublishTime, preMsgSend, reportId).Error
  1288. return
  1289. }
  1290. // ReportSubmitApproveReq 提交审批请求体
  1291. type ReportSubmitApproveReq struct {
  1292. ReportId int `description:"报告ID"`
  1293. }
  1294. // ReportCancelApproveReq 撤回审批请求体
  1295. type ReportCancelApproveReq struct {
  1296. ReportId int `description:"报告ID"`
  1297. }
  1298. func (m *Report) GetItemById(id int) (item *Report, err error) {
  1299. o := global.DbMap[utils.DbNameReport]
  1300. sql := `SELECT * FROM report WHERE id = ? LIMIT 1`
  1301. err = o.Raw(sql, id).First(&item).Error
  1302. return
  1303. }
  1304. // GetReportStateCount 获取指定状态的报告数量
  1305. func GetReportStateCount(state int) (count int, err error) {
  1306. o := global.DbMap[utils.DbNameReport]
  1307. sql := `SELECT COUNT(1) AS count FROM report WHERE state = ?`
  1308. var countNull sql2.NullInt64
  1309. err = o.Raw(sql, state).Scan(&countNull).Error
  1310. if err != nil {
  1311. return
  1312. }
  1313. if countNull.Valid {
  1314. count = int(countNull.Int64)
  1315. }
  1316. return
  1317. }
  1318. // UpdateReportsStateByCond 批量更新报告状态
  1319. func UpdateReportsStateByCond(classifyFirstId, classifySecondId, classifyThirdId, oldState, newState int) (err error) {
  1320. o := global.DbMap[utils.DbNameReport]
  1321. cond := ``
  1322. if classifyFirstId > 0 {
  1323. cond += fmt.Sprintf(` AND classify_id_first = %d`, classifyFirstId)
  1324. }
  1325. if classifySecondId > 0 {
  1326. cond += fmt.Sprintf(` AND classify_id_second = %d`, classifySecondId)
  1327. }
  1328. if classifyThirdId > 0 {
  1329. cond += fmt.Sprintf(` AND classify_id_third = %d`, classifyThirdId)
  1330. }
  1331. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? %s`, cond)
  1332. err = o.Exec(sql, newState, oldState).Error
  1333. return
  1334. }
  1335. // UpdateReportsStateBySecondIds 批量更新二级分类报告状态
  1336. func UpdateReportsStateBySecondIds(oldState, newState int, secondIds []int) (err error) {
  1337. if len(secondIds) <= 0 {
  1338. return
  1339. }
  1340. o := global.DbMap[utils.DbNameReport]
  1341. // (有审批流的)未发布->待提交
  1342. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1343. err = o.Exec(sql, newState, oldState, secondIds).Error
  1344. if err != nil {
  1345. return
  1346. }
  1347. // (无审批流的)待提交->未发布
  1348. sql = fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second NOT IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1349. err = o.Exec(sql, oldState, newState, secondIds).Error
  1350. return
  1351. }
  1352. // GetReportPdfUrlReq 获取报告pdf地址请求体
  1353. type GetReportPdfUrlReq struct {
  1354. ReportUrl string `description:"报告Url"`
  1355. ReportCode string `description:"报告Code"`
  1356. Type int `description:"类型 1-pdf 2-图片"`
  1357. }
  1358. func ModifyReportPdfUrl(reportId int, detailPdfUrl string) (err error) {
  1359. o := global.DbMap[utils.DbNameReport]
  1360. sql := `UPDATE report SET detail_pdf_url=? WHERE id=? `
  1361. err = o.Exec(sql, detailPdfUrl, reportId).Error
  1362. return
  1363. }
  1364. func ModifyReportImgUrl(reportId int, detailImgUrl string) (err error) {
  1365. o := global.DbMap[utils.DbNameReport]
  1366. sql := `UPDATE report SET detail_img_url=? WHERE id=? `
  1367. err = o.Exec(sql, detailImgUrl, reportId).Error
  1368. return
  1369. }
  1370. // UpdatePdfUrlReportById 清空pdf相关字段
  1371. func UpdatePdfUrlReportById(reportId int) (err error) {
  1372. o := global.DbMap[utils.DbNameReport]
  1373. sql := `UPDATE report SET detail_img_url = '',detail_pdf_url='',modify_time=NOW() WHERE id = ? `
  1374. err = o.Exec(sql, reportId).Error
  1375. return
  1376. }
  1377. // InsertMultiReport
  1378. // @Description: 批量新增报告
  1379. // @author: Roc
  1380. // @datetime 2024-06-27 15:55:25
  1381. // @param items []*Report
  1382. // @return err error
  1383. func InsertMultiReport(items []*Report) (err error) {
  1384. o := global.DbMap[utils.DbNameReport]
  1385. err = o.CreateInBatches(items, utils.MultiAddNum).Error
  1386. return
  1387. }
  1388. // ReportLayout
  1389. // @Description: 报告布局
  1390. type ReportLayout struct {
  1391. Id int
  1392. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  1393. }
  1394. // GetReportLayoutByReportId
  1395. // @Description: 根据报告id获取报告的布局
  1396. // @author: Roc
  1397. // @datetime 2024-07-15 15:27:05
  1398. // @param reportId int
  1399. // @return item ReportLayout
  1400. // @return err error
  1401. func GetReportLayoutByReportId(reportId int) (item ReportLayout, err error) {
  1402. o := global.DbMap[utils.DbNameReport]
  1403. sql := `SELECT id, report_layout FROM report WHERE id = ? `
  1404. err = o.Raw(sql, reportId).First(&item).Error
  1405. return
  1406. }
  1407. func GetReportFieldsByIds(ids []int, fields []string) (items []*Report, err error) {
  1408. if len(ids) == 0 {
  1409. return
  1410. }
  1411. o := global.DbMap[utils.DbNameReport]
  1412. field := " * "
  1413. if len(fields) > 0 {
  1414. field = fmt.Sprintf(" %s ", strings.Join(fields, ","))
  1415. }
  1416. sql := fmt.Sprintf(`SELECT %s FROM report WHERE id IN (%s)`, field, utils.GetOrmInReplace(len(ids)))
  1417. err = o.Raw(sql, ids).Find(&items).Error
  1418. return
  1419. }
  1420. // GetReportListByClassifyId 根据分类id 获取报告列表
  1421. func GetReportListByClassifyId(classifyId int) (items []*Report, err error) {
  1422. o := global.DbMap[utils.DbNameReport]
  1423. sql := `SELECT * FROM report WHERE classify_id_first = ? or classify_id_second = ? or classify_id_third = ?`
  1424. err = o.Raw(sql, classifyId, classifyId, classifyId).Find(&items).Error
  1425. return items, err
  1426. }
  1427. func GetExistReportClassifyIdByClassifyIds(classifyIds []int) (existClassifyIds []*Report, err error) {
  1428. if len(classifyIds) == 0 {
  1429. return
  1430. }
  1431. o := global.DbMap[utils.DbNameReport]
  1432. sql := `SELECT classify_id_first, classify_id_second, classify_id_third FROM report WHERE 1=1 `
  1433. sql += fmt.Sprintf(` AND (classify_id_first IN (%s) OR classify_id_second IN (%s) OR classify_id_third IN (%s))`, utils.GetOrmInReplace(len(classifyIds)), utils.GetOrmInReplace(len(classifyIds)), utils.GetOrmInReplace(len(classifyIds)))
  1434. err = o.Raw(sql, classifyIds, classifyIds, classifyIds).Find(&existClassifyIds).Error
  1435. return
  1436. }
  1437. // UpdateReportInfo 修改报告
  1438. func UpdateReportInfo(reports *Report) (err error) {
  1439. //o := global.DbMap[utils.DbNameReport]
  1440. //err = o.Update(reports)
  1441. //if err != nil {
  1442. // return err
  1443. //}
  1444. err = global.DbMap[utils.DbNameReport].Updates(reports).Error
  1445. return
  1446. }
  1447. func FindReportListByCondition(condition string, pars []interface{}) (items []*Report, err error) {
  1448. o := global.DbMap[utils.DbNameReport]
  1449. sql := `SELECT * FROM report WHERE 1=1 `
  1450. if condition != "" {
  1451. sql += condition
  1452. }
  1453. err = o.Raw(sql, pars...).Find(&items).Error
  1454. return
  1455. }