english_report.go 28 KB

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