report.go 60 KB

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