english_report.go 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. package models
  2. import (
  3. "errors"
  4. "eta/eta_mobile/utils"
  5. "github.com/beego/beego/v2/client/orm"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "strings"
  8. "time"
  9. )
  10. type EnglishReport struct {
  11. Id int `orm:"column(id)" description:"报告Id"`
  12. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  13. ClassifyIdFirst int `description:"一级分类id"`
  14. ClassifyNameFirst string `description:"一级分类名称"`
  15. ClassifyIdSecond int `description:"二级分类id"`
  16. ClassifyNameSecond string `description:"二级分类名称"`
  17. Title string `description:"标题"`
  18. Abstract string `description:"摘要"`
  19. Author string `description:"作者"`
  20. Frequency string `description:"频度"`
  21. CreateTime string `description:"创建时间"`
  22. ModifyTime time.Time `description:"修改时间"`
  23. State int `description:"1:未发布,2:已发布"`
  24. PublishTime time.Time `description:"发布时间"`
  25. PrePublishTime time.Time `description:"预发布时间"`
  26. Stage int `description:"期数"`
  27. Content string `description:"内容"`
  28. VideoUrl string `description:"音频文件URL"`
  29. VideoName string `description:"音频文件名称"`
  30. VideoPlaySeconds string `description:"音频播放时长"`
  31. VideoSize string `description:"音频文件大小,单位M"`
  32. ContentSub string `description:"内容前两个章节"`
  33. ReportCode string `description:"报告唯一编码"`
  34. Pv int `description:"Pv"`
  35. PvEmail int `description:"邮箱PV"`
  36. EmailState int `description:"群发邮件状态: 0-未发送; 1-已发送"`
  37. Overview string `description:"英文概述部分"`
  38. KeyTakeaways string `description:"关键点"`
  39. FromReportId int `description:"继承的报告ID(英文策略报告ID)"`
  40. AdminId int `description:"创建者账号"`
  41. AdminRealName string `description:"创建者姓名"`
  42. }
  43. func GetEnglishReportStage(classifyIdFirst, classifyIdSecond int) (count int, err error) {
  44. o := orm.NewOrmUsingDB("rddp")
  45. sql := ``
  46. if classifyIdSecond > 0 {
  47. sql = "SELECT MAX(stage) AS max_stage FROM english_report WHERE classify_id_second=? "
  48. o.Raw(sql, classifyIdSecond).QueryRow(&count)
  49. } else {
  50. sql = "SELECT MAX(stage) AS max_stage FROM english_report WHERE classify_id_first=? "
  51. o.Raw(sql, classifyIdFirst).QueryRow(&count)
  52. }
  53. return
  54. }
  55. func GetEnglishReportStageEdit(classifyIdFirst, classifyIdSecond, reportId int) (count int, err error) {
  56. o := orm.NewOrmUsingDB("rddp")
  57. sql := ``
  58. if classifyIdSecond > 0 {
  59. sql = "SELECT MAX(stage) AS max_stage FROM english_report WHERE classify_id_second=? AND id<>? "
  60. o.Raw(sql, classifyIdSecond, reportId).QueryRow(&count)
  61. } else {
  62. sql = "SELECT MAX(stage) AS max_stage FROM english_report WHERE classify_id_first=? AND id<>? "
  63. o.Raw(sql, classifyIdFirst, reportId).QueryRow(&count)
  64. }
  65. return
  66. }
  67. func AddEnglishReport(item *EnglishReport) (lastId int64, err error) {
  68. o := orm.NewOrmUsingDB("rddp")
  69. lastId, err = o.Insert(item)
  70. return
  71. }
  72. func ModifyEnglishReportCode(reportId int64, reportCode string) (err error) {
  73. o := orm.NewOrmUsingDB("rddp")
  74. sql := `UPDATE english_report SET report_code=? WHERE id=? `
  75. _, err = o.Raw(sql, reportCode, reportId).Exec()
  76. return
  77. }
  78. type AddEnglishReportReq struct {
  79. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  80. ClassifyIdFirst int `description:"一级分类id"`
  81. ClassifyNameFirst string `description:"一级分类名称"`
  82. ClassifyIdSecond int `description:"二级分类id"`
  83. ClassifyNameSecond string `description:"二级分类名称"`
  84. Title string `description:"标题"`
  85. Abstract string `description:"摘要"`
  86. Author string `description:"作者"`
  87. Frequency string `description:"频度"`
  88. State int `description:"状态:1:未发布,2:已发布"`
  89. Content string `description:"内容"`
  90. CreateTime string `description:"创建时间"`
  91. Overview string `description:"英文概述部分"`
  92. }
  93. type AddEnglishReportResp struct {
  94. ReportId int64 `description:"报告id"`
  95. ReportCode string `description:"报告code"`
  96. }
  97. type EditEnglishReportReq struct {
  98. ReportId int64 `description:"报告id"`
  99. ClassifyIdFirst int `description:"一级分类id"`
  100. ClassifyNameFirst string `description:"一级分类名称"`
  101. ClassifyIdSecond int `description:"二级分类id"`
  102. ClassifyNameSecond string `description:"二级分类名称"`
  103. Title string `description:"标题"`
  104. Abstract string `description:"摘要"`
  105. Author string `description:"作者"`
  106. Frequency string `description:"频度"`
  107. State int `description:"状态:1:未发布,2:已发布"`
  108. Content string `description:"内容"`
  109. CreateTime string `description:"创建时间"`
  110. Overview string `description:"英文概述部分"`
  111. }
  112. type EditEnglishReportFromPolicyReq struct {
  113. ReportId int64 `description:"报告id"`
  114. Title string `description:"标题"`
  115. Abstract string `description:"摘要"`
  116. Author string `description:"作者"`
  117. Frequency string `description:"频度"`
  118. CreateTime string `description:"创建时间"`
  119. //Overview string `description:"英文概述部分"`
  120. }
  121. type EditEnglishReportResp struct {
  122. ReportId int64 `description:"报告id"`
  123. ReportCode string `description:"报告code"`
  124. }
  125. type ElasticEnglishReportDetail struct {
  126. Id string `description:"报告id或者线上路演Id"`
  127. ReportId int `description:"报告id"`
  128. VideoId int `description:"线上路演Id"`
  129. ClassifyIdFirst int `description:"一级分类id"`
  130. ClassifyNameFirst string `description:"一级分类名称"`
  131. ClassifyIdSecond int `description:"二级分类id"`
  132. ClassifyNameSecond string `description:"二级分类名称"`
  133. StageStr string `description:"报告期数"`
  134. Title string `description:"标题"`
  135. Abstract string `description:"摘要"`
  136. Author string `description:"作者"`
  137. Frequency string `description:"频度"`
  138. PublishState int `description:"状态:1:未发布,2:已发布"`
  139. BodyContent string `description:"内容"`
  140. ContentSub string `description:"前两段内容"`
  141. CreateTime string `description:"创建时间"`
  142. PublishTime string `description:"发布时间"`
  143. ReportCode string `description:"报告唯一编码"`
  144. Overview string `description:"英文概述部分"`
  145. }
  146. func EditEnglishReport(item *EnglishReport, reportId int64) (err error) {
  147. o := orm.NewOrmUsingDB("rddp")
  148. sql := `UPDATE english_report
  149. SET
  150. classify_id_first =?,
  151. classify_name_first = ?,
  152. classify_id_second = ?,
  153. classify_name_second = ?,
  154. title = ?,
  155. abstract = ?,
  156. author = ?,
  157. frequency = ?,
  158. state = ?,
  159. content = ?,
  160. content_sub = ?,
  161. stage =?,
  162. create_time = ?,
  163. modify_time = ?,
  164. overview = ?
  165. WHERE id = ? `
  166. _, err = o.Raw(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title,
  167. item.Abstract, item.Author, item.Frequency, item.State, item.Content, item.ContentSub, item.Stage, item.CreateTime, time.Now(), item.Overview, reportId).Exec()
  168. return
  169. }
  170. type EnglishReportDetail struct {
  171. Id int `orm:"column(id)" description:"报告Id"`
  172. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  173. ClassifyIdFirst int `description:"一级分类id"`
  174. ClassifyNameFirst string `description:"一级分类名称"`
  175. ClassifyIdSecond int `description:"二级分类id"`
  176. ClassifyNameSecond string `description:"二级分类名称"`
  177. Title string `description:"标题"`
  178. Abstract string `description:"摘要"`
  179. Author string `description:"作者"`
  180. Frequency string `description:"频度"`
  181. CreateTime string `description:"创建时间"`
  182. ModifyTime string `description:"修改时间"`
  183. State int `description:"1:未发布,2:已发布"`
  184. PublishTime string `description:"发布时间"`
  185. PrePublishTime string `description:"预发布时间"`
  186. Stage int `description:"期数"`
  187. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  188. ReportCode string `description:"报告唯一编码"`
  189. Content string `description:"内容"`
  190. VideoUrl string `description:"音频文件URL"`
  191. VideoName string `description:"音频文件名称"`
  192. VideoPlaySeconds string `description:"音频播放时长"`
  193. ContentSub string `description:"内容前两个章节"`
  194. Pv int `description:"Pv"`
  195. Overview string `description:"英文概述部分"`
  196. FromReportId int `description:"继承的报告ID(英文策略报告ID)"`
  197. KeyTakeaways string `description:"关键点"`
  198. EmailState int `description:"群发邮件状态: 0-未发送; 1-已发送"`
  199. EmailAuth bool `description:"是否有权限群发邮件"`
  200. EmailHasFail bool `description:"是否存在邮件发送失败的记录"`
  201. ClassifyIdRoot int `description:"顶级分类id"`
  202. ClassifyNameRoot string `description:"顶级分类名称"`
  203. }
  204. func GetEnglishReportById(reportId int) (item *EnglishReportDetail, err error) {
  205. o := orm.NewOrmUsingDB("rddp")
  206. sql := `SELECT * FROM english_report WHERE id=?`
  207. err = o.Raw(sql, reportId).QueryRow(&item)
  208. return
  209. }
  210. func GetEnglishReportItemById(reportId int) (item *EnglishReport, err error) {
  211. o := orm.NewOrmUsingDB("rddp")
  212. sql := `SELECT * FROM english_report WHERE id = ? LIMIT 1`
  213. err = o.Raw(sql, reportId).QueryRow(&item)
  214. return
  215. }
  216. type EnglishReportList struct {
  217. Id int `description:"报告Id"`
  218. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  219. ClassifyIdFirst int `description:"一级分类id"`
  220. ClassifyNameFirst string `description:"一级分类名称"`
  221. ClassifyIdSecond int `description:"二级分类id"`
  222. ClassifyNameSecond string `description:"二级分类名称"`
  223. Title string `description:"标题"`
  224. Abstract string `description:"摘要"`
  225. Author string `description:"作者"`
  226. Frequency string `description:"频度"`
  227. CreateTime string `description:"创建时间"`
  228. ModifyTime time.Time `description:"修改时间"`
  229. State int `description:"1:未发布,2:已发布"`
  230. PublishTime string `description:"发布时间"`
  231. PrePublishTime string `description:"预发布时间"`
  232. Stage int `description:"期数"`
  233. Content string `description:"内容"`
  234. VideoUrl string `description:"音频文件URL"`
  235. VideoName string `description:"音频文件名称"`
  236. VideoPlaySeconds string `description:"音频播放时长"`
  237. ContentSub string `description:"内容前两个章节"`
  238. ReportCode string `description:"报告唯一编码"`
  239. Pv int `description:"Pv"`
  240. ShareUrl string `description:"分享url"`
  241. PvEmail int `description:"邮箱PV"`
  242. EmailState int `description:"群发邮件状态: 0-未发送; 1-已发送"`
  243. EmailAuth bool `description:"是否有权限群发邮件"`
  244. EmailHasFail bool `description:"是否存在邮件发送失败的记录"`
  245. CanEdit bool `description:"是否可编辑"`
  246. Editor string `description:"编辑人"`
  247. FromReportId int `description:"继承的报告ID(英文策略报告ID)"`
  248. AdminId int `description:"创建者账号"`
  249. AdminRealName string `description:"创建者姓名"`
  250. FullClassifyName string `description:"顶级分类名/父级分类名/当前分类名"`
  251. ClassifyIdRoot int `description:"顶级分类id"`
  252. ClassifyNameRoot string `description:"顶级分类名称"`
  253. }
  254. type EnglishReportListResp struct {
  255. List []*EnglishReportList
  256. Paging *paging.PagingItem `description:"分页数据"`
  257. }
  258. func GetEnglishReportListCount(condition string, pars []interface{}, companyType string) (count int, err error) {
  259. //产品权限
  260. companyTypeSqlStr := ``
  261. if companyType == "ficc" {
  262. companyTypeSqlStr = " AND classify_id_first != 40 "
  263. } else if companyType == "权益" {
  264. companyTypeSqlStr = " AND classify_id_first = 40 "
  265. }
  266. oRddp := orm.NewOrmUsingDB("rddp")
  267. sql := `SELECT COUNT(1) AS count FROM english_report WHERE 1=1 ` + companyTypeSqlStr
  268. if condition != "" {
  269. sql += condition
  270. }
  271. err = oRddp.Raw(sql, pars).QueryRow(&count)
  272. return
  273. }
  274. func GetEnglishReportList(condition string, pars []interface{}, companyType string, startSize, pageSize int) (items []*EnglishReportList, err error) {
  275. o := orm.NewOrmUsingDB("rddp")
  276. //产品权限
  277. companyTypeSqlStr := ``
  278. if companyType == "ficc" {
  279. companyTypeSqlStr = " AND classify_id_first != 40 "
  280. } else if companyType == "权益" {
  281. companyTypeSqlStr = " AND classify_id_first = 40 "
  282. }
  283. sql := `SELECT *
  284. FROM english_report WHERE 1=1 ` + companyTypeSqlStr
  285. if condition != "" {
  286. sql += condition
  287. }
  288. sql += `ORDER BY state ASC, modify_time DESC LIMIT ?,?`
  289. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  290. return
  291. }
  292. func GetEnglishReportByCondition(condition string, pars []interface{}) (items []*EnglishReport, err error) {
  293. o := orm.NewOrmUsingDB("rddp")
  294. sql := `SELECT *
  295. FROM english_report WHERE 1=1 `
  296. if condition != "" {
  297. sql += condition
  298. }
  299. _, err = o.Raw(sql, pars).QueryRows(&items)
  300. return
  301. }
  302. // 发布报告
  303. func PublishEnglishReportById(reportId int, publishTime string) (err error) {
  304. o := orm.NewOrmUsingDB("rddp")
  305. sql := `UPDATE english_report SET state=2,publish_time=?,pre_publish_time=null,modify_time=NOW() WHERE id = ? `
  306. _, err = o.Raw(sql, publishTime, reportId).Exec()
  307. return
  308. }
  309. // 取消发布报告
  310. func PublishCancelEnglishReport(reportIds int) (err error) {
  311. o := orm.NewOrmUsingDB("rddp")
  312. sql := ` UPDATE english_report SET state=1,pre_publish_time=null WHERE id =? `
  313. _, err = o.Raw(sql, reportIds).Exec()
  314. return
  315. }
  316. // SetPrePublishEnglishReportById 设置定时发布
  317. func SetPrePublishEnglishReportById(reportId int, prePublishTime string) (err error) {
  318. o := orm.NewOrmUsingDB("rddp")
  319. sql := `UPDATE english_report SET pre_publish_time=? WHERE id = ? and state = 1 `
  320. _, err = o.Raw(sql, prePublishTime, reportId).Exec()
  321. return
  322. }
  323. // DeleteEnglishReportAndChapter 删除报告及章节
  324. func DeleteEnglishReportAndChapter(reportInfo *EnglishReportDetail) (err error) {
  325. reportId := reportInfo.Id
  326. if reportInfo.State == 2 {
  327. err = errors.New("报告已发布,不可删除")
  328. return
  329. }
  330. err = DeleteEnglishReport(reportId)
  331. if err != nil {
  332. err = errors.New("删除失败, Err: " + err.Error())
  333. return
  334. }
  335. return
  336. }
  337. // 删除报告
  338. func DeleteEnglishReport(reportIds int) (err error) {
  339. o := orm.NewOrmUsingDB("rddp")
  340. sql := ` DELETE FROM english_report WHERE id =? `
  341. _, err = o.Raw(sql, reportIds).Exec()
  342. return
  343. }
  344. func EditEnglishReportContent(reportId int, content, contentSub string) (err error) {
  345. o := orm.NewOrmUsingDB("rddp")
  346. sql := ` UPDATE english_report SET content=?,content_sub=?,modify_time=NOW() WHERE id=? `
  347. _, err = o.Raw(sql, content, contentSub, reportId).Exec()
  348. return
  349. }
  350. func AddEnglishReportSaveLog(reportId, adminId int, content, contentSub, adminName string) (err error) {
  351. o := orm.NewOrmUsingDB("rddp")
  352. sql := ` INSERT INTO english_report_save_log(report_id, content,content_sub,admin_id,admin_name) VALUES (?,?,?,?,?) `
  353. _, err = o.Raw(sql, reportId, content, contentSub, adminId, adminName).Exec()
  354. return
  355. }
  356. type EnglishClassifyList struct {
  357. Id int `orm:"column(id);pk"`
  358. ClassifyName string `description:"分类名称"`
  359. Sort int `description:"排序"`
  360. ParentId int `description:"父级分类id"`
  361. RootId int `description:"一级分类ID"`
  362. CreateTime time.Time `description:"创建时间"`
  363. ModifyTime time.Time `description:"修改时间"`
  364. ClassifyLabel string `description:"分类标签"`
  365. ShowType int `description:"展示类型:1-列表 2-专栏"`
  366. IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  367. //ClassifyType int `description:"分类类型:0英文报告,1英文线上路演"`
  368. EnPermissions []int `description:"英文权限IDs"`
  369. Child []*EnglishClassifyList
  370. }
  371. type EnglishClassifyListResp struct {
  372. List []*EnglishClassifyList
  373. Paging *paging.PagingItem `description:"分页数据"`
  374. }
  375. // GetEnglishClassifyRootId 获取一级分类列表
  376. func GetEnglishClassifyRootId(startSize, pageSize int, keyWord string) (items []*EnglishClassifyList, err error) {
  377. sql := ``
  378. o := orm.NewOrmUsingDB("rddp")
  379. if keyWord != "" {
  380. sql = `SELECT * FROM (
  381. SELECT * FROM english_classify
  382. WHERE parent_id=0 AND classify_name LIKE '%` + keyWord + `%'
  383. UNION
  384. SELECT * FROM english_classify
  385. WHERE id IN(SELECT parent_id FROM english_classify
  386. WHERE parent_id>0 AND classify_name LIKE '%` + keyWord + `%')
  387. )AS t
  388. ORDER BY sort ASC,create_time ASC
  389. LIMIT ?,? `
  390. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  391. } else {
  392. sql = `SELECT * FROM english_classify WHERE parent_id=0 ORDER BY sort ASC,create_time ASC LIMIT ?,? `
  393. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  394. }
  395. return
  396. }
  397. func GetEnglishClassifyListCount(keyWord string) (count int, err error) {
  398. sqlCount := ``
  399. o := orm.NewOrmUsingDB("rddp")
  400. if keyWord != "" {
  401. sqlCount = `SELECT COUNT(1) AS count FROM (
  402. SELECT * FROM english_classify
  403. WHERE parent_id=0 AND classify_name LIKE '%` + keyWord + `%'
  404. UNION
  405. SELECT * FROM english_classify
  406. WHERE id IN(SELECT parent_id FROM english_classify
  407. WHERE parent_id>0 AND classify_name LIKE '%` + keyWord + `%')
  408. )AS t `
  409. err = o.Raw(sqlCount).QueryRow(&count)
  410. } else {
  411. sqlCount = `SELECT COUNT(1) AS count FROM english_classify WHERE parent_id=0`
  412. err = o.Raw(sqlCount).QueryRow(&count)
  413. }
  414. return
  415. }
  416. func GetEnglishClassifyListByRootId(rootIds []int, keyWord string) (items []*EnglishClassifyList, err error) {
  417. sql := ``
  418. o := orm.NewOrmUsingDB("rddp")
  419. if keyWord != "" {
  420. sql = `SELECT
  421. a.*
  422. FROM
  423. english_classify a
  424. LEFT JOIN english_classify b ON a.root_id = b.id
  425. LEFT JOIN english_classify c ON a.parent_id = c.id
  426. WHERE a.parent_id >0 and a.classify_name LIKE '%` + keyWord + `%' and a.root_id IN (` + utils.GetOrmInReplace(len(rootIds)) + `)`
  427. _, err = o.Raw(sql, rootIds).QueryRows(&items)
  428. } else {
  429. sql = `SELECT * FROM english_classify WHERE parent_id >0 and root_id IN (` + utils.GetOrmInReplace(len(rootIds)) + `) `
  430. _, err = o.Raw(sql, rootIds).QueryRows(&items)
  431. }
  432. return
  433. }
  434. func GetEnglishClassifyChildByIds(ids []int) (items []*EnglishClassifyList, err error) {
  435. o := orm.NewOrmUsingDB("rddp")
  436. sql := `SELECT * FROM english_classify WHERE id IN (` + utils.GetOrmInReplace(len(ids)) + `) ORDER BY create_time ASC `
  437. _, err = o.Raw(sql, ids).QueryRows(&items)
  438. return
  439. }
  440. func GetEnglishReportDetailByClassifyId(classifyIdFirst, classifyIdSecond int) (item *EnglishReportDetail, err error) {
  441. o := orm.NewOrmUsingDB("rddp")
  442. sql := ` SELECT * FROM english_report WHERE 1=1 `
  443. if classifyIdSecond > 0 {
  444. sql = sql + ` AND classify_id_second=? ORDER BY stage DESC LIMIT 1`
  445. err = o.Raw(sql, classifyIdSecond).QueryRow(&item)
  446. } else {
  447. sql = sql + ` AND classify_id_first=? ORDER BY stage DESC LIMIT 1`
  448. err = o.Raw(sql, classifyIdFirst).QueryRow(&item)
  449. }
  450. return
  451. }
  452. // Update 更新
  453. func (item *EnglishReport) Update(cols []string) (err error) {
  454. o := orm.NewOrmUsingDB("rddp")
  455. _, err = o.Update(item, cols...)
  456. return
  457. }
  458. // ModifyEnglishReportAuthor 更改英文报告作者
  459. func ModifyEnglishReportAuthor(condition string, pars []interface{}, authorName string) (count int, err error) {
  460. //产品权限
  461. oRddp := orm.NewOrmUsingDB("rddp")
  462. sql := `UPDATE english_report set author = ? WHERE 1=1 `
  463. if condition != "" {
  464. sql += condition
  465. }
  466. err = oRddp.Raw(sql, authorName, pars).QueryRow(&count)
  467. return
  468. }
  469. type EnglishClassify struct {
  470. Id int `orm:"column(id);pk"`
  471. ClassifyName string `description:"分类名称"`
  472. Sort int `description:"排序"`
  473. ParentId int `description:"父级分类id"`
  474. RootId int `description:"一级分类ID"`
  475. CreateTime time.Time `description:"创建时间"`
  476. ModifyTime time.Time `description:"修改时间"`
  477. ClassifyLabel string `description:"分类标签"`
  478. ShowType int `description:"展示类型:1-列表 2-专栏"`
  479. IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  480. //ClassifyType int `description:"分类类型:0英文报告,1英文线上路演"`
  481. }
  482. func AddEnglishClassify(item *EnglishClassify) (lastId int64, err error) {
  483. o := orm.NewOrmUsingDB("rddp")
  484. lastId, err = o.Insert(item)
  485. return
  486. }
  487. func ModifyEnglishClassify(item *EnglishClassify) (err error) {
  488. o := orm.NewOrmUsingDB("rddp")
  489. sql := `UPDATE english_classify
  490. SET
  491. classify_name = ?,
  492. sort = ?,
  493. parent_id = ?,
  494. root_id = ?,
  495. modify_time = ?
  496. WHERE id = ? `
  497. _, err = o.Raw(sql, item.ClassifyName, item.Sort, item.ParentId, item.RootId, item.ModifyTime, item.Id).Exec()
  498. return
  499. }
  500. // UpdateClassify 更新分类
  501. func (classifyInfo *EnglishClassify) UpdateEnglishClassify(cols []string) (err error) {
  502. o := orm.NewOrmUsingDB("rddp")
  503. _, err = o.Update(classifyInfo, cols...)
  504. return
  505. }
  506. // DeleteEnglishClassify 删除英文分类
  507. func DeleteEnglishClassify(classifyId int) (err error) {
  508. o := orm.NewOrmUsingDB("rddp")
  509. sql := ` DELETE FROM english_classify WHERE id =? `
  510. _, err = o.Raw(sql, classifyId).Exec()
  511. return
  512. }
  513. func GetEnglishClassifyChildCounts(parentId int) (count int, err error) {
  514. o := orm.NewOrmUsingDB("rddp")
  515. sql := `SELECT COUNT(1) AS count FROM english_classify WHERE parent_id=? `
  516. err = o.Raw(sql, parentId).QueryRow(&count)
  517. return
  518. }
  519. func GetEnglishReportCounts(classifyId, parentId int) (count int, err error) {
  520. o := orm.NewOrmUsingDB("rddp")
  521. sql := ``
  522. if parentId == 0 {
  523. sql = `SELECT COUNT(1) AS count FROM english_report WHERE classify_id_first=? `
  524. } else {
  525. sql = `SELECT COUNT(1) AS count FROM english_report WHERE classify_id_second=? `
  526. }
  527. err = o.Raw(sql, classifyId).QueryRow(&count)
  528. return
  529. }
  530. func GetEnglishClassifyCountsByName(name string, parentId int) (count int, err error) {
  531. o := orm.NewOrmUsingDB("rddp")
  532. sql := `SELECT COUNT(1) AS count FROM english_classify WHERE classify_name=? AND parent_id = ? `
  533. err = o.Raw(sql, name, parentId).QueryRow(&count)
  534. return
  535. }
  536. // GetEnglishFirstClassifyList 获取一级、二级分类列表
  537. func GetEnglishFirstClassifyList(startSize, pageSize int) (items []*EnglishClassifyList, err error) {
  538. o := orm.NewOrmUsingDB("rddp")
  539. sql := `SELECT * FROM english_classify WHERE parent_id =0 ORDER BY sort ASC,create_time ASC LIMIT ?,? `
  540. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  541. return
  542. }
  543. // GetEnglishSecondClassifyList 获取一级、二级分类列表
  544. func GetEnglishSecondClassifyList(rootIds []int) (items []*EnglishClassifyList, err error) {
  545. o := orm.NewOrmUsingDB("rddp")
  546. sql := `SELECT * FROM english_classify WHERE root_id IN (` + utils.GetOrmInReplace(len(rootIds)) + `) and parent_id>0 and root_id=parent_id ORDER BY sort ASC,create_time ASC`
  547. _, err = o.Raw(sql, rootIds).QueryRows(&items)
  548. return
  549. }
  550. func GetEnglishFirstClassifyListCount() (count int, err error) {
  551. o := orm.NewOrmUsingDB("rddp")
  552. sqlCount := `SELECT COUNT(1) AS count FROM english_classify WHERE parent_id=0`
  553. err = o.Raw(sqlCount).QueryRow(&count)
  554. return
  555. }
  556. func GetEnglishReportClassifyById(classifyId int) (item *EnglishClassify, err error) {
  557. sql := `SELECT * FROM english_classify WHERE id=?`
  558. o := orm.NewOrmUsingDB("rddp")
  559. err = o.Raw(sql, classifyId).QueryRow(&item)
  560. return
  561. }
  562. func GetEnglishReportClassifyByIds(classifyIds []int) (list []*EnglishClassify, err error) {
  563. o := orm.NewOrmUsingDB("rddp")
  564. sql := `SELECT * FROM english_classify WHERE id IN (` + utils.GetOrmInReplace(len(classifyIds)) + `)`
  565. _, err = o.Raw(sql, classifyIds).QueryRows(&list)
  566. return
  567. }
  568. // UpdateEnglishReportSecondClassifyNameByClassifyId 更新报告分类名称字段
  569. func UpdateEnglishReportSecondClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  570. o := orm.NewOrmUsingDB("rddp")
  571. sql := " UPDATE english_report SET classify_name_second = ? WHERE classify_id_second = ? "
  572. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  573. return
  574. }
  575. // UpdateEnglishReportFirstClassifyNameByClassifyId 更新报告分类名称字段
  576. func UpdateEnglishReportFirstClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  577. o := orm.NewOrmUsingDB("rddp")
  578. sql := " UPDATE english_report SET classify_name_first = ? WHERE classify_id_first = ? "
  579. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  580. return
  581. }
  582. // UpdateEnglishReportFirstClassifyNameByClassifyId 更新报告分类名称字段
  583. func UpdateEnglishReportByClassifyId(classifyFirstName, classifySecondName string, firstClassifyId, secondClassifyId int, ids string) (err error) {
  584. o := orm.NewOrmUsingDB("rddp")
  585. sql := " UPDATE english_report SET classify_name_first = ?,classify_name_second = ?,classify_id_first=?, classify_id_second =? WHERE id IN (" + ids + ") "
  586. _, err = o.Raw(sql, classifyFirstName, classifySecondName, firstClassifyId, secondClassifyId).Exec()
  587. return
  588. }
  589. // FetchEnglishReportById 主键获取英文报告
  590. func FetchEnglishReportById(reportId int) (item *EnglishReport, err error) {
  591. o := orm.NewOrmUsingDB("rddp")
  592. sql := `SELECT * FROM english_report WHERE id=?`
  593. err = o.Raw(sql, reportId).QueryRow(&item)
  594. return
  595. }
  596. // UpdateReport 更新英文报告
  597. func (reportInfo *EnglishReport) UpdateReport(cols []string) (err error) {
  598. o := orm.NewOrmUsingDB("rddp")
  599. _, err = o.Update(reportInfo, cols...)
  600. return
  601. }
  602. // GetAllEnglishClassify 获取所有英文分类
  603. func GetAllEnglishClassify() (list []*Classify, err error) {
  604. o := orm.NewOrmUsingDB("rddp")
  605. sql := ` SELECT * FROM english_classify `
  606. _, err = o.Raw(sql).QueryRows(&list)
  607. return
  608. }
  609. // GetEnglishReportByIds 根据IDs获取英文报告列表
  610. func GetEnglishReportByIds(reportIds []int, fieldArr []string) (list []*EnglishReport, err error) {
  611. listLen := len(reportIds)
  612. if listLen == 0 {
  613. return
  614. }
  615. fields := ` * `
  616. if len(fieldArr) > 0 {
  617. fields = strings.Join(fieldArr, ",")
  618. }
  619. o := orm.NewOrmUsingDB("rddp")
  620. sql := `SELECT ` + fields + ` FROM english_report WHERE id IN (` + utils.GetOrmInReplace(listLen) + `)`
  621. _, err = o.Raw(sql, reportIds).QueryRows(&list)
  622. return
  623. }
  624. // MarkEditEnReport 标记编辑英文研报的请求数据
  625. type MarkEditEnReport struct {
  626. ReportId int `description:"研报id"`
  627. Status int `description:"标记状态,1:编辑中,2:编辑完成"`
  628. }
  629. type EnglishClassifyNameParentName struct {
  630. Id int `description:"分类ID"`
  631. ClassifyName string `description:"分类名称"`
  632. Sort int `description:"排序"`
  633. ParentId int `description:"父级分类id"`
  634. CreateTime time.Time `description:"创建时间"`
  635. ModifyTime time.Time `description:"修改时间"`
  636. ClassifyLabel string `description:"分类标签"`
  637. ShowType int `description:"展示类型:1-列表 2-专栏"`
  638. IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  639. ParentClassifyName string `description:"父级分类名称"`
  640. }
  641. func GetEnglishClassifyByClassifyNameAndParentName(parentClassiyName, classifyName string) (item EnglishClassifyNameParentName, err error) {
  642. o := orm.NewOrmUsingDB("rddp")
  643. sql := "SELECT c1.*, c2.classify_name as parent_classify_name FROM english_classify c1 LEFT JOIN english_classify c2 on c1.parent_id = c2.id where c1.parent_id > 0 and c2.classify_name = ? and c1.classify_name= ?"
  644. err = o.Raw(sql, parentClassiyName, classifyName).QueryRow(&item)
  645. return
  646. }
  647. type RSClassifyList []*EnglishClassifyList
  648. func (m RSClassifyList) Len() int {
  649. return len(m)
  650. }
  651. func (m RSClassifyList) Less(i, j int) bool {
  652. return m[i].Sort < m[j].Sort
  653. }
  654. func (m RSClassifyList) Swap(i, j int) {
  655. m[i], m[j] = m[j], m[i]
  656. }
  657. type RSChildClassifyList []*EnglishClassifyList
  658. func (m RSChildClassifyList) Len() int {
  659. return len(m)
  660. }
  661. func (m RSChildClassifyList) Less(i, j int) bool {
  662. return m[i].Sort < m[j].Sort
  663. }
  664. func (m RSChildClassifyList) Swap(i, j int) {
  665. m[i], m[j] = m[j], m[i]
  666. }
  667. // GetEnglishClassifyByClassifyNameParentId 获取英文分类
  668. func GetEnglishClassifyByClassifyNameParentId(classifyName string, parentId int) (item *Classify, err error) {
  669. o := orm.NewOrmUsingDB("rddp")
  670. sql := ` SELECT * FROM english_classify where classify_name = ? and parent_id = ? `
  671. err = o.Raw(sql, classifyName, parentId).QueryRow(&item)
  672. return
  673. }
  674. type EnglishClassifyFullName struct {
  675. Id int `description:"分类ID"`
  676. ParentId int `description:"父级分类id"`
  677. RootId int `description:"一级分类ID"`
  678. RootName string `description:"一级分类名"`
  679. ParentName string `description:"二级分类名"`
  680. ClassifyName string `description:"分类名称"`
  681. }
  682. // GetEnglishClassifyFullNameByIds 获取英文分类名一级/二级/三级
  683. func GetEnglishClassifyFullNameByIds(classifyIds []int) (list []*EnglishClassifyFullName, err error) {
  684. o := orm.NewOrmUsingDB("rddp")
  685. sql := ` SELECT
  686. a.id,
  687. a.parent_id,
  688. a.root_id,
  689. a.classify_name,
  690. b.classify_name AS root_name,
  691. c.classify_name AS parent_name
  692. FROM
  693. english_classify a
  694. LEFT JOIN english_classify b ON a.root_id = b.id
  695. LEFT JOIN english_classify c ON a.parent_id = c.id
  696. where a.id IN (` + utils.GetOrmInReplace(len(classifyIds)) + `)`
  697. _, err = o.Raw(sql, classifyIds).QueryRows(&list)
  698. return
  699. }