english_report.go 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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. }
  202. func GetEnglishReportById(reportId int) (item *EnglishReportDetail, err error) {
  203. o := orm.NewOrmUsingDB("rddp")
  204. sql := `SELECT * FROM english_report WHERE id=?`
  205. err = o.Raw(sql, reportId).QueryRow(&item)
  206. return
  207. }
  208. func GetEnglishReportItemById(reportId int) (item *EnglishReport, err error) {
  209. o := orm.NewOrmUsingDB("rddp")
  210. sql := `SELECT * FROM english_report WHERE id = ? LIMIT 1`
  211. err = o.Raw(sql, reportId).QueryRow(&item)
  212. return
  213. }
  214. type EnglishReportList struct {
  215. Id int `description:"报告Id"`
  216. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  217. ClassifyIdFirst int `description:"一级分类id"`
  218. ClassifyNameFirst string `description:"一级分类名称"`
  219. ClassifyIdSecond int `description:"二级分类id"`
  220. ClassifyNameSecond string `description:"二级分类名称"`
  221. Title string `description:"标题"`
  222. Abstract string `description:"摘要"`
  223. Author string `description:"作者"`
  224. Frequency string `description:"频度"`
  225. CreateTime string `description:"创建时间"`
  226. ModifyTime time.Time `description:"修改时间"`
  227. State int `description:"1:未发布,2:已发布"`
  228. PublishTime string `description:"发布时间"`
  229. PrePublishTime string `description:"预发布时间"`
  230. Stage int `description:"期数"`
  231. Content string `description:"内容"`
  232. VideoUrl string `description:"音频文件URL"`
  233. VideoName string `description:"音频文件名称"`
  234. VideoPlaySeconds string `description:"音频播放时长"`
  235. ContentSub string `description:"内容前两个章节"`
  236. ReportCode string `description:"报告唯一编码"`
  237. Pv int `description:"Pv"`
  238. ShareUrl string `description:"分享url"`
  239. PvEmail int `description:"邮箱PV"`
  240. EmailState int `description:"群发邮件状态: 0-未发送; 1-已发送"`
  241. EmailAuth bool `description:"是否有权限群发邮件"`
  242. EmailHasFail bool `description:"是否存在邮件发送失败的记录"`
  243. CanEdit bool `description:"是否可编辑"`
  244. Editor string `description:"编辑人"`
  245. FromReportId int `description:"继承的报告ID(英文策略报告ID)"`
  246. AdminId int `description:"创建者账号"`
  247. AdminRealName string `description:"创建者姓名"`
  248. }
  249. type EnglishReportListResp struct {
  250. List []*EnglishReportList
  251. Paging *paging.PagingItem `description:"分页数据"`
  252. }
  253. func GetEnglishReportListCount(condition string, pars []interface{}, companyType string) (count int, err error) {
  254. //产品权限
  255. companyTypeSqlStr := ``
  256. if companyType == "ficc" {
  257. companyTypeSqlStr = " AND classify_id_first != 40 "
  258. } else if companyType == "权益" {
  259. companyTypeSqlStr = " AND classify_id_first = 40 "
  260. }
  261. oRddp := orm.NewOrmUsingDB("rddp")
  262. sql := `SELECT COUNT(1) AS count FROM english_report WHERE 1=1 ` + companyTypeSqlStr
  263. if condition != "" {
  264. sql += condition
  265. }
  266. err = oRddp.Raw(sql, pars).QueryRow(&count)
  267. return
  268. }
  269. func GetEnglishReportList(condition string, pars []interface{}, companyType string, startSize, pageSize int) (items []*EnglishReportList, err error) {
  270. o := orm.NewOrmUsingDB("rddp")
  271. //产品权限
  272. companyTypeSqlStr := ``
  273. if companyType == "ficc" {
  274. companyTypeSqlStr = " AND classify_id_first != 40 "
  275. } else if companyType == "权益" {
  276. companyTypeSqlStr = " AND classify_id_first = 40 "
  277. }
  278. sql := `SELECT *
  279. FROM english_report WHERE 1=1 ` + companyTypeSqlStr
  280. if condition != "" {
  281. sql += condition
  282. }
  283. sql += `ORDER BY state ASC, modify_time DESC LIMIT ?,?`
  284. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  285. return
  286. }
  287. func GetEnglishReportByCondition(condition string, pars []interface{}) (items []*EnglishReport, err error) {
  288. o := orm.NewOrmUsingDB("rddp")
  289. sql := `SELECT *
  290. FROM english_report WHERE 1=1 `
  291. if condition != "" {
  292. sql += condition
  293. }
  294. _, err = o.Raw(sql, pars).QueryRows(&items)
  295. return
  296. }
  297. // 发布报告
  298. func PublishEnglishReportById(reportId int, publishTime string) (err error) {
  299. o := orm.NewOrmUsingDB("rddp")
  300. sql := `UPDATE english_report SET state=2,publish_time=?,pre_publish_time=null,modify_time=NOW() WHERE id = ? `
  301. _, err = o.Raw(sql, publishTime, reportId).Exec()
  302. return
  303. }
  304. // 取消发布报告
  305. func PublishCancelEnglishReport(reportIds int) (err error) {
  306. o := orm.NewOrmUsingDB("rddp")
  307. sql := ` UPDATE english_report SET state=1,pre_publish_time=null WHERE id =? `
  308. _, err = o.Raw(sql, reportIds).Exec()
  309. return
  310. }
  311. // SetPrePublishEnglishReportById 设置定时发布
  312. func SetPrePublishEnglishReportById(reportId int, prePublishTime string) (err error) {
  313. o := orm.NewOrmUsingDB("rddp")
  314. sql := `UPDATE english_report SET pre_publish_time=? WHERE id = ? and state = 1 `
  315. _, err = o.Raw(sql, prePublishTime, reportId).Exec()
  316. return
  317. }
  318. // DeleteEnglishReportAndChapter 删除报告及章节
  319. func DeleteEnglishReportAndChapter(reportInfo *EnglishReportDetail) (err error) {
  320. reportId := reportInfo.Id
  321. if reportInfo.State == 2 {
  322. err = errors.New("报告已发布,不可删除")
  323. return
  324. }
  325. err = DeleteEnglishReport(reportId)
  326. if err != nil {
  327. err = errors.New("删除失败, Err: " + err.Error())
  328. return
  329. }
  330. return
  331. }
  332. // 删除报告
  333. func DeleteEnglishReport(reportIds int) (err error) {
  334. o := orm.NewOrmUsingDB("rddp")
  335. sql := ` DELETE FROM english_report WHERE id =? `
  336. _, err = o.Raw(sql, reportIds).Exec()
  337. return
  338. }
  339. func EditEnglishReportContent(reportId int, content, contentSub string) (err error) {
  340. o := orm.NewOrmUsingDB("rddp")
  341. sql := ` UPDATE english_report SET content=?,content_sub=?,modify_time=NOW() WHERE id=? `
  342. _, err = o.Raw(sql, content, contentSub, reportId).Exec()
  343. return
  344. }
  345. func AddEnglishReportSaveLog(reportId, adminId int, content, contentSub, adminName string) (err error) {
  346. o := orm.NewOrmUsingDB("rddp")
  347. sql := ` INSERT INTO english_report_save_log(report_id, content,content_sub,admin_id,admin_name) VALUES (?,?,?,?,?) `
  348. _, err = o.Raw(sql, reportId, content, contentSub, adminId, adminName).Exec()
  349. return
  350. }
  351. type EnglishClassifyList struct {
  352. Id int `orm:"column(id);pk"`
  353. ClassifyName string `description:"分类名称"`
  354. Sort int `description:"排序"`
  355. ParentId int `description:"父级分类id"`
  356. CreateTime time.Time `description:"创建时间"`
  357. ModifyTime time.Time `description:"修改时间"`
  358. ClassifyLabel string `description:"分类标签"`
  359. ShowType int `description:"展示类型:1-列表 2-专栏"`
  360. IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  361. ClassifyType int `description:"分类类型:0英文报告,1英文线上路演"`
  362. Child []*EnglishClassify
  363. }
  364. type EnglishClassifyListResp struct {
  365. List []*EnglishClassifyList
  366. Paging *paging.PagingItem `description:"分页数据"`
  367. }
  368. // 获取分类列表
  369. func GetEnglishClassifyList(startSize, pageSize int, keyWord string, classifyType int) (items []*EnglishClassifyList, err error) {
  370. sql := ``
  371. o := orm.NewOrmUsingDB("rddp")
  372. if keyWord != "" {
  373. sql = `SELECT * FROM (
  374. SELECT * FROM english_classify
  375. WHERE parent_id=0 AND classify_name LIKE '%` + keyWord + `%' AND classify_type = ?
  376. UNION
  377. SELECT * FROM english_classify
  378. WHERE id IN(SELECT parent_id FROM english_classify
  379. WHERE parent_id>0 AND classify_name LIKE '%` + keyWord + `%') AND classify_type = ?
  380. )AS t
  381. ORDER BY sort ASC,create_time ASC
  382. LIMIT ?,? `
  383. _, err = o.Raw(sql, classifyType, classifyType, startSize, pageSize).QueryRows(&items)
  384. } else {
  385. sql = `SELECT * FROM english_classify WHERE parent_id=0 AND classify_type = ? ORDER BY sort ASC,create_time ASC LIMIT ?,? `
  386. _, err = o.Raw(sql, classifyType, startSize, pageSize).QueryRows(&items)
  387. }
  388. return
  389. }
  390. func GetEnglishClassifyListCount(keyWord string, classifyType int) (count int, err error) {
  391. sqlCount := ``
  392. o := orm.NewOrmUsingDB("rddp")
  393. if keyWord != "" {
  394. sqlCount = `SELECT COUNT(1) AS count FROM (
  395. SELECT * FROM english_classify
  396. WHERE parent_id=0 AND classify_name LIKE '%` + keyWord + `%' AND classify_type = ?
  397. UNION
  398. SELECT * FROM english_classify
  399. WHERE id IN(SELECT parent_id FROM english_classify
  400. WHERE parent_id>0 AND classify_name LIKE '%` + keyWord + `%' AND classify_type = ?)
  401. )AS t `
  402. err = o.Raw(sqlCount, classifyType, classifyType).QueryRow(&count)
  403. } else {
  404. sqlCount = `SELECT COUNT(1) AS count FROM english_classify WHERE parent_id=0 AND classify_type = ?`
  405. err = o.Raw(sqlCount, classifyType).QueryRow(&count)
  406. }
  407. return
  408. }
  409. func GetEnglishClassifyChild(parentId int, keyWord string, classifyType int) (items []*EnglishClassify, err error) {
  410. o := orm.NewOrmUsingDB("rddp")
  411. sql := ``
  412. if keyWord != "" {
  413. sql = `SELECT * FROM english_classify WHERE parent_id=? AND classify_type = ? AND classify_name LIKE '%` + keyWord + `%' ORDER BY create_time ASC `
  414. } else {
  415. sql = `SELECT * FROM english_classify WHERE parent_id=? AND classify_type = ? ORDER BY create_time ASC `
  416. }
  417. _, err = o.Raw(sql, parentId, classifyType).QueryRows(&items)
  418. return
  419. }
  420. func GetEnglishClassifyChildByParentIds(parentIds []int, keyWord string, classifyType int) (items []*EnglishClassify, err error) {
  421. o := orm.NewOrmUsingDB("rddp")
  422. sql := ``
  423. if keyWord != "" {
  424. sql = `SELECT * FROM english_classify WHERE parent_id IN (` + utils.GetOrmInReplace(len(parentIds)) + `) AND classify_type = ? AND classify_name LIKE '%` + keyWord + `%' ORDER BY create_time ASC `
  425. } else {
  426. sql = `SELECT * FROM english_classify WHERE parent_id IN (` + utils.GetOrmInReplace(len(parentIds)) + `) AND classify_type = ? ORDER BY create_time ASC `
  427. }
  428. _, err = o.Raw(sql, parentIds, classifyType).QueryRows(&items)
  429. return
  430. }
  431. func GetEnglishReportDetailByClassifyId(classifyIdFirst, classifyIdSecond int) (item *EnglishReport, err error) {
  432. o := orm.NewOrmUsingDB("rddp")
  433. sql := ` SELECT * FROM english_report WHERE 1=1 `
  434. if classifyIdSecond > 0 {
  435. sql = sql + ` AND classify_id_second=? ORDER BY stage DESC LIMIT 1`
  436. err = o.Raw(sql, classifyIdSecond).QueryRow(&item)
  437. } else {
  438. sql = sql + ` AND classify_id_first=? ORDER BY stage DESC LIMIT 1`
  439. err = o.Raw(sql, classifyIdFirst).QueryRow(&item)
  440. }
  441. return
  442. }
  443. // Update 更新
  444. func (item *EnglishReport) Update(cols []string) (err error) {
  445. o := orm.NewOrmUsingDB("rddp")
  446. _, err = o.Update(item, cols...)
  447. return
  448. }
  449. // ModifyEnglishReportAuthor 更改英文报告作者
  450. func ModifyEnglishReportAuthor(condition string, pars []interface{}, authorName string) (count int, err error) {
  451. //产品权限
  452. oRddp := orm.NewOrmUsingDB("rddp")
  453. sql := `UPDATE english_report set author = ? WHERE 1=1 `
  454. if condition != "" {
  455. sql += condition
  456. }
  457. err = oRddp.Raw(sql, authorName, pars).QueryRow(&count)
  458. return
  459. }
  460. type EnglishClassify struct {
  461. Id int `orm:"column(id);pk"`
  462. ClassifyName string `description:"分类名称"`
  463. Sort int `description:"排序"`
  464. ParentId int `description:"父级分类id"`
  465. CreateTime time.Time `description:"创建时间"`
  466. ModifyTime time.Time `description:"修改时间"`
  467. ClassifyLabel string `description:"分类标签"`
  468. ShowType int `description:"展示类型:1-列表 2-专栏"`
  469. IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  470. ClassifyType int `description:"分类类型:0英文报告,1英文线上路演"`
  471. }
  472. func AddEnglishClassify(item *EnglishClassify) (lastId int64, err error) {
  473. o := orm.NewOrmUsingDB("rddp")
  474. lastId, err = o.Insert(item)
  475. return
  476. }
  477. func ModifyEnglishClassify(item *EnglishClassify) (err error) {
  478. o := orm.NewOrmUsingDB("rddp")
  479. sql := `UPDATE english_classify
  480. SET
  481. classify_name = ?,
  482. sort = ?,
  483. parent_id = ?,
  484. modify_time = ?
  485. WHERE id = ? `
  486. _, err = o.Raw(sql, item.ClassifyName, item.Sort, item.ParentId, item.ModifyTime, item.Id).Exec()
  487. return
  488. }
  489. // UpdateClassify 更新分类
  490. func (classifyInfo *EnglishClassify) UpdateEnglishClassify(cols []string) (err error) {
  491. o := orm.NewOrmUsingDB("rddp")
  492. _, err = o.Update(classifyInfo, cols...)
  493. return
  494. }
  495. // DeleteEnglishClassify 删除英文分类
  496. func DeleteEnglishClassify(classifyId int) (err error) {
  497. o := orm.NewOrmUsingDB("rddp")
  498. sql := ` DELETE FROM english_classify WHERE id =? `
  499. _, err = o.Raw(sql, classifyId).Exec()
  500. return
  501. }
  502. func GetEnglishClassifyChildCounts(parentId int) (count int, err error) {
  503. o := orm.NewOrmUsingDB("rddp")
  504. sql := `SELECT COUNT(1) AS count FROM english_classify WHERE parent_id=? `
  505. err = o.Raw(sql, parentId).QueryRow(&count)
  506. return
  507. }
  508. func GetEnglishReportCounts(classifyId, parentId int) (count int, err error) {
  509. o := orm.NewOrmUsingDB("rddp")
  510. sql := ``
  511. if parentId == 0 {
  512. sql = `SELECT COUNT(1) AS count FROM english_report WHERE classify_id_first=? `
  513. } else {
  514. sql = `SELECT COUNT(1) AS count FROM english_report WHERE classify_id_second=? `
  515. }
  516. err = o.Raw(sql, classifyId).QueryRow(&count)
  517. return
  518. }
  519. func GetEnglishClassifyCountsByName(name string, parentId int, classifyType int) (count int, err error) {
  520. o := orm.NewOrmUsingDB("rddp")
  521. sql := `SELECT COUNT(1) AS count FROM english_classify WHERE classify_name=? AND parent_id = ? AND classify_type = ? `
  522. err = o.Raw(sql, name, parentId, classifyType).QueryRow(&count)
  523. return
  524. }
  525. // 获取分类列表
  526. func GetEnglishFirstClassifyList(classifyType, startSize, pageSize int) (items []*EnglishClassifyList, err error) {
  527. sql := ``
  528. sql = `SELECT * FROM english_classify WHERE parent_id=0 AND classify_type = ? ORDER BY sort ASC,create_time ASC LIMIT ?,? `
  529. o := orm.NewOrmUsingDB("rddp")
  530. _, err = o.Raw(sql, classifyType, startSize, pageSize).QueryRows(&items)
  531. return
  532. }
  533. func GetEnglishFirstClassifyListCount(classifyType int) (count int, err error) {
  534. sqlCount := ``
  535. sqlCount = `SELECT COUNT(1) AS count FROM english_classify WHERE parent_id=0 AND classify_type = ? `
  536. o := orm.NewOrmUsingDB("rddp")
  537. err = o.Raw(sqlCount, classifyType).QueryRow(&count)
  538. return
  539. }
  540. func GetEnglishReportClassifyById(classifyId int) (item *EnglishClassify, err error) {
  541. sql := `SELECT * FROM english_classify WHERE id=?`
  542. o := orm.NewOrmUsingDB("rddp")
  543. err = o.Raw(sql, classifyId).QueryRow(&item)
  544. return
  545. }
  546. func GetEnglishReportClassifyByIds(classifyIds []int) (list []*EnglishClassify, err error) {
  547. o := orm.NewOrmUsingDB("rddp")
  548. sql := `SELECT * FROM english_classify WHERE id IN (` + utils.GetOrmInReplace(len(classifyIds)) + `)`
  549. _, err = o.Raw(sql, classifyIds).QueryRows(&list)
  550. return
  551. }
  552. // UpdateEnglishReportSecondClassifyNameByClassifyId 更新报告分类名称字段
  553. func UpdateEnglishReportSecondClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  554. o := orm.NewOrmUsingDB("rddp")
  555. sql := " UPDATE english_report SET classify_name_second = ? WHERE classify_id_second = ? "
  556. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  557. return
  558. }
  559. // UpdateEnglishReportFirstClassifyNameByClassifyId 更新报告分类名称字段
  560. func UpdateEnglishReportFirstClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  561. o := orm.NewOrmUsingDB("rddp")
  562. sql := " UPDATE english_report SET classify_name_first = ? WHERE classify_id_first = ? "
  563. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  564. return
  565. }
  566. // UpdateEnglishReportFirstClassifyNameByClassifyId 更新报告分类名称字段
  567. func UpdateEnglishReportByClassifyId(classifyFirstName, classifySecondName string, firstClassifyId, secondClassifyId int, ids string) (err error) {
  568. o := orm.NewOrmUsingDB("rddp")
  569. sql := " UPDATE english_report SET classify_name_first = ?,classify_name_second = ?,classify_id_first=?, classify_id_second =? WHERE id IN (" + ids + ") "
  570. _, err = o.Raw(sql, classifyFirstName, classifySecondName, firstClassifyId, secondClassifyId).Exec()
  571. return
  572. }
  573. // FetchEnglishReportById 主键获取英文报告
  574. func FetchEnglishReportById(reportId int) (item *EnglishReport, err error) {
  575. o := orm.NewOrmUsingDB("rddp")
  576. sql := `SELECT * FROM english_report WHERE id=?`
  577. err = o.Raw(sql, reportId).QueryRow(&item)
  578. return
  579. }
  580. // UpdateReport 更新英文报告
  581. func (reportInfo *EnglishReport) UpdateReport(cols []string) (err error) {
  582. o := orm.NewOrmUsingDB("rddp")
  583. _, err = o.Update(reportInfo, cols...)
  584. return
  585. }
  586. // GetAllEnglishClassify 获取所有英文分类
  587. func GetAllEnglishClassify(classifyType int) (list []*Classify, err error) {
  588. o := orm.NewOrmUsingDB("rddp")
  589. sql := ` SELECT * FROM english_classify where classify_type = ? `
  590. _, err = o.Raw(sql, classifyType).QueryRows(&list)
  591. return
  592. }
  593. // GetEnglishReportByIds 根据IDs获取英文报告列表
  594. func GetEnglishReportByIds(reportIds []int, fieldArr []string) (list []*EnglishReport, err error) {
  595. listLen := len(reportIds)
  596. if listLen == 0 {
  597. return
  598. }
  599. fields := ` * `
  600. if len(fieldArr) > 0 {
  601. fields = strings.Join(fieldArr, ",")
  602. }
  603. o := orm.NewOrmUsingDB("rddp")
  604. sql := `SELECT ` + fields + ` FROM english_report WHERE id IN (` + utils.GetOrmInReplace(listLen) + `)`
  605. _, err = o.Raw(sql, reportIds).QueryRows(&list)
  606. return
  607. }
  608. // MarkEditEnReport 标记编辑英文研报的请求数据
  609. type MarkEditEnReport struct {
  610. ReportId int `description:"研报id"`
  611. Status int `description:"标记状态,1:编辑中,2:编辑完成"`
  612. }
  613. type EnglishClassifyNameParentName struct {
  614. Id int `description:"分类ID"`
  615. ClassifyName string `description:"分类名称"`
  616. Sort int `description:"排序"`
  617. ParentId int `description:"父级分类id"`
  618. CreateTime time.Time `description:"创建时间"`
  619. ModifyTime time.Time `description:"修改时间"`
  620. ClassifyLabel string `description:"分类标签"`
  621. ShowType int `description:"展示类型:1-列表 2-专栏"`
  622. IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  623. ParentClassifyName string `description:"父级分类名称"`
  624. }
  625. func GetEnglishClassifyByClassifyNameAndParentName(parentClassiyName, classifyName string) (item EnglishClassifyNameParentName, err error) {
  626. o := orm.NewOrmUsingDB("rddp")
  627. 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= ?"
  628. err = o.Raw(sql, parentClassiyName, classifyName).QueryRow(&item)
  629. return
  630. }
  631. type RSClassifyList []*EnglishClassifyList
  632. func (m RSClassifyList) Len() int {
  633. return len(m)
  634. }
  635. func (m RSClassifyList) Less(i, j int) bool {
  636. return m[i].Sort < m[j].Sort
  637. }
  638. func (m RSClassifyList) Swap(i, j int) {
  639. m[i], m[j] = m[j], m[i]
  640. }
  641. type RSChildClassifyList []*EnglishClassify
  642. func (m RSChildClassifyList) Len() int {
  643. return len(m)
  644. }
  645. func (m RSChildClassifyList) Less(i, j int) bool {
  646. return m[i].Sort < m[j].Sort
  647. }
  648. func (m RSChildClassifyList) Swap(i, j int) {
  649. m[i], m[j] = m[j], m[i]
  650. }
  651. // GetEnglishClassifyByClassifyNameParentId 获取英文分类
  652. func GetEnglishClassifyByClassifyNameParentId(classifyName string, parentId, classifyType int) (item *Classify, err error) {
  653. o := orm.NewOrmUsingDB("rddp")
  654. sql := ` SELECT * FROM english_classify where classify_name = ? and parent_id = ? and classify_type = ? `
  655. err = o.Raw(sql, classifyName, parentId, classifyType).QueryRow(&item)
  656. return
  657. }