english_report.go 28 KB

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