english_report.go 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  1. package models
  2. import (
  3. "errors"
  4. "eta/eta_mobile/utils"
  5. "fmt"
  6. "github.com/beego/beego/v2/client/orm"
  7. "github.com/rdlucklib/rdluck_tools/paging"
  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:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  25. PublishTime time.Time `description:"发布时间"`
  26. PrePublishTime time.Time `description:"预发布时间"`
  27. Stage int `description:"期数"`
  28. Content string `description:"内容"`
  29. VideoUrl string `description:"音频文件URL"`
  30. VideoName string `description:"音频文件名称"`
  31. VideoPlaySeconds string `description:"音频播放时长"`
  32. VideoSize string `description:"音频文件大小,单位M"`
  33. ContentSub string `description:"内容前两个章节"`
  34. ReportCode string `description:"报告唯一编码"`
  35. Pv int `description:"Pv"`
  36. PvEmail int `description:"邮箱PV"`
  37. UvEmail int `description:"邮箱UV"`
  38. EmailState int `description:"群发邮件状态: 0-未发送; 1-已发送"`
  39. Overview string `description:"英文概述部分"`
  40. KeyTakeaways string `description:"关键点"`
  41. FromReportId int `description:"继承的报告ID(英文策略报告ID)"`
  42. AdminId int `description:"创建者账号"`
  43. AdminRealName string `description:"创建者姓名"`
  44. ApproveTime time.Time `description:"审批时间"`
  45. ApproveId int `description:"审批ID"`
  46. DetailImgUrl string `description:"报告详情长图地址"`
  47. DetailPdfUrl string `description:"报告详情PDF地址"`
  48. EmailHasFail int `description:"是否存在邮件发送失败的记录: 0-否; 1-是"`
  49. }
  50. func GetEnglishReportStage(classifyIdFirst, classifyIdSecond int) (count int, err error) {
  51. o := orm.NewOrmUsingDB("rddp")
  52. sql := ``
  53. if classifyIdSecond > 0 {
  54. sql = "SELECT MAX(stage) AS max_stage FROM english_report WHERE classify_id_second=? "
  55. o.Raw(sql, classifyIdSecond).QueryRow(&count)
  56. } else {
  57. sql = "SELECT MAX(stage) AS max_stage FROM english_report WHERE classify_id_first=? "
  58. o.Raw(sql, classifyIdFirst).QueryRow(&count)
  59. }
  60. return
  61. }
  62. func GetEnglishReportStageEdit(classifyIdFirst, classifyIdSecond, reportId int) (count int, err error) {
  63. o := orm.NewOrmUsingDB("rddp")
  64. sql := ``
  65. if classifyIdSecond > 0 {
  66. sql = "SELECT MAX(stage) AS max_stage FROM english_report WHERE classify_id_second=? AND id<>? "
  67. o.Raw(sql, classifyIdSecond, reportId).QueryRow(&count)
  68. } else {
  69. sql = "SELECT MAX(stage) AS max_stage FROM english_report WHERE classify_id_first=? AND id<>? "
  70. o.Raw(sql, classifyIdFirst, reportId).QueryRow(&count)
  71. }
  72. return
  73. }
  74. func AddEnglishReport(item *EnglishReport) (lastId int64, err error) {
  75. o := orm.NewOrmUsingDB("rddp")
  76. lastId, err = o.Insert(item)
  77. return
  78. }
  79. func ModifyEnglishReportCode(reportId int64, reportCode string) (err error) {
  80. o := orm.NewOrmUsingDB("rddp")
  81. sql := `UPDATE english_report SET report_code=? WHERE id=? `
  82. _, err = o.Raw(sql, reportCode, reportId).Exec()
  83. return
  84. }
  85. type AddEnglishReportReq struct {
  86. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  87. ClassifyIdFirst int `description:"一级分类id"`
  88. ClassifyNameFirst string `description:"一级分类名称"`
  89. ClassifyIdSecond int `description:"二级分类id"`
  90. ClassifyNameSecond string `description:"二级分类名称"`
  91. ClassifyIdThird int `description:"三级分类id"`
  92. ClassifyNameThird string `description:"三级分类名称"`
  93. Title string `description:"标题"`
  94. Abstract string `description:"摘要"`
  95. Author string `description:"作者"`
  96. Frequency string `description:"频度"`
  97. State int `description:"状态:1:未发布,2:已发布"`
  98. Content string `description:"内容"`
  99. CreateTime string `description:"创建时间"`
  100. Overview string `description:"英文概述部分"`
  101. }
  102. type AddEnglishReportResp struct {
  103. ReportId int64 `description:"报告id"`
  104. ReportCode string `description:"报告code"`
  105. }
  106. type EditEnglishReportReq struct {
  107. ReportId int64 `description:"报告id"`
  108. ClassifyIdFirst int `description:"一级分类id"`
  109. ClassifyNameFirst string `description:"一级分类名称"`
  110. ClassifyIdSecond int `description:"二级分类id"`
  111. ClassifyNameSecond string `description:"二级分类名称"`
  112. Title string `description:"标题"`
  113. Abstract string `description:"摘要"`
  114. Author string `description:"作者"`
  115. Frequency string `description:"频度"`
  116. State int `description:"状态:1:未发布,2:已发布"`
  117. Content string `description:"内容"`
  118. CreateTime string `description:"创建时间"`
  119. Overview string `description:"英文概述部分"`
  120. }
  121. type EditEnglishReportFromPolicyReq struct {
  122. ReportId int64 `description:"报告id"`
  123. Title string `description:"标题"`
  124. Abstract string `description:"摘要"`
  125. Author string `description:"作者"`
  126. Frequency string `description:"频度"`
  127. CreateTime string `description:"创建时间"`
  128. //Overview string `description:"英文概述部分"`
  129. }
  130. type EditEnglishReportResp struct {
  131. ReportId int64 `description:"报告id"`
  132. ReportCode string `description:"报告code"`
  133. }
  134. type ElasticEnglishReportDetail struct {
  135. Id string `description:"报告id或者线上路演Id"`
  136. ReportId int `description:"报告id"`
  137. VideoId int `description:"线上路演Id"`
  138. ClassifyIdFirst int `description:"一级分类id"`
  139. ClassifyNameFirst string `description:"一级分类名称"`
  140. ClassifyIdSecond int `description:"二级分类id"`
  141. ClassifyNameSecond string `description:"二级分类名称"`
  142. StageStr string `description:"报告期数"`
  143. Title string `description:"标题"`
  144. Abstract string `description:"摘要"`
  145. Author string `description:"作者"`
  146. Frequency string `description:"频度"`
  147. PublishState int `description:"状态:1:未发布,2:已发布"`
  148. BodyContent string `description:"内容"`
  149. ContentSub string `description:"前两段内容"`
  150. CreateTime string `description:"创建时间"`
  151. PublishTime string `description:"发布时间"`
  152. ReportCode string `description:"报告唯一编码"`
  153. Overview string `description:"英文概述部分"`
  154. }
  155. func EditEnglishReport(item *EnglishReport, reportId int64) (err error) {
  156. o := orm.NewOrmUsingDB("rddp")
  157. sql := `UPDATE english_report
  158. SET
  159. classify_id_first =?,
  160. classify_name_first = ?,
  161. classify_id_second = ?,
  162. classify_name_second = ?,
  163. title = ?,
  164. abstract = ?,
  165. author = ?,
  166. frequency = ?,
  167. state = ?,
  168. content = ?,
  169. content_sub = ?,
  170. stage =?,
  171. create_time = ?,
  172. modify_time = ?,
  173. overview = ?
  174. WHERE id = ? `
  175. _, err = o.Raw(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title,
  176. item.Abstract, item.Author, item.Frequency, item.State, item.Content, item.ContentSub, item.Stage, item.CreateTime, time.Now(), item.Overview, reportId).Exec()
  177. return
  178. }
  179. type EnglishReportDetail struct {
  180. Id int `orm:"column(id)" description:"报告Id"`
  181. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  182. ClassifyIdFirst int `description:"一级分类id"`
  183. ClassifyNameFirst string `description:"一级分类名称"`
  184. ClassifyIdSecond int `description:"二级分类id"`
  185. ClassifyNameSecond string `description:"二级分类名称"`
  186. Title string `description:"标题"`
  187. Abstract string `description:"摘要"`
  188. Author string `description:"作者"`
  189. Frequency string `description:"频度"`
  190. CreateTime string `description:"创建时间"`
  191. ModifyTime string `description:"修改时间"`
  192. State int `description:"1:未发布,2:已发布"`
  193. PublishTime string `description:"发布时间"`
  194. PrePublishTime string `description:"预发布时间"`
  195. Stage int `description:"期数"`
  196. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  197. ReportCode string `description:"报告唯一编码"`
  198. Content string `description:"内容"`
  199. VideoUrl string `description:"音频文件URL"`
  200. VideoName string `description:"音频文件名称"`
  201. VideoPlaySeconds string `description:"音频播放时长"`
  202. ContentSub string `description:"内容前两个章节"`
  203. Pv int `description:"Pv"`
  204. Overview string `description:"英文概述部分"`
  205. FromReportId int `description:"继承的报告ID(英文策略报告ID)"`
  206. KeyTakeaways string `description:"关键点"`
  207. ClassifyIdRoot int `description:"顶级分类id"`
  208. ClassifyNameRoot string `description:"顶级分类名称"`
  209. }
  210. func GetEnglishReportById(reportId int) (item *EnglishReportDetail, err error) {
  211. o := orm.NewOrmUsingDB("rddp")
  212. sql := `SELECT * FROM english_report WHERE id=?`
  213. err = o.Raw(sql, reportId).QueryRow(&item)
  214. return
  215. }
  216. func GetEnglishReportItemById(reportId int) (item *EnglishReport, err error) {
  217. o := orm.NewOrmUsingDB("rddp")
  218. sql := `SELECT * FROM english_report WHERE id = ? LIMIT 1`
  219. err = o.Raw(sql, reportId).QueryRow(&item)
  220. return
  221. }
  222. type EnglishReportList struct {
  223. Id int `description:"报告Id"`
  224. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  225. ClassifyIdFirst int `description:"一级分类id"`
  226. ClassifyNameFirst string `description:"一级分类名称"`
  227. ClassifyIdSecond int `description:"二级分类id"`
  228. ClassifyNameSecond string `description:"二级分类名称"`
  229. Title string `description:"标题"`
  230. Abstract string `description:"摘要"`
  231. Author string `description:"作者"`
  232. Frequency string `description:"频度"`
  233. CreateTime string `description:"创建时间"`
  234. ModifyTime time.Time `description:"修改时间"`
  235. State int `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  236. PublishTime string `description:"发布时间"`
  237. PrePublishTime string `description:"预发布时间"`
  238. Stage int `description:"期数"`
  239. Content string `description:"内容"`
  240. VideoUrl string `description:"音频文件URL"`
  241. VideoName string `description:"音频文件名称"`
  242. VideoPlaySeconds string `description:"音频播放时长"`
  243. ContentSub string `description:"内容前两个章节"`
  244. ReportCode string `description:"报告唯一编码"`
  245. Pv int `description:"Pv"`
  246. ShareUrl string `description:"分享url"`
  247. PvEmail int `description:"邮箱PV"`
  248. UvEmail int `description:"邮箱UV"`
  249. EmailState int `description:"群发邮件状态: 0-未发送; 1-已发送"`
  250. EmailAuth bool `description:"是否有权限群发邮件"`
  251. EmailHasFail bool `description:"是否存在邮件发送失败的记录"`
  252. CanEdit bool `description:"是否可编辑"`
  253. Editor string `description:"编辑人"`
  254. FromReportId int `description:"继承的报告ID(英文策略报告ID)"`
  255. AdminId int `description:"创建者账号"`
  256. AdminRealName string `description:"创建者姓名"`
  257. FullClassifyName string `description:"顶级分类名/父级分类名/当前分类名"`
  258. ClassifyIdRoot int `description:"顶级分类id"`
  259. ClassifyNameRoot string `description:"顶级分类名称"`
  260. ApproveTime string `description:"审批时间"`
  261. DetailImgUrl string `description:"报告详情长图地址"`
  262. DetailPdfUrl string `description:"报告详情PDF地址"`
  263. }
  264. type EnglishReportListResp struct {
  265. List []*EnglishReportList
  266. Paging *paging.PagingItem `description:"分页数据"`
  267. }
  268. func GetEnglishReportListCount(condition string, pars []interface{}, companyType string) (count int, err error) {
  269. //产品权限
  270. companyTypeSqlStr := ``
  271. if companyType == "ficc" {
  272. companyTypeSqlStr = " AND classify_id_first != 40 "
  273. } else if companyType == "权益" {
  274. companyTypeSqlStr = " AND classify_id_first = 40 "
  275. }
  276. oRddp := orm.NewOrmUsingDB("rddp")
  277. sql := `SELECT COUNT(1) AS count FROM english_report WHERE 1=1 ` + companyTypeSqlStr
  278. if condition != "" {
  279. sql += condition
  280. }
  281. err = oRddp.Raw(sql, pars).QueryRow(&count)
  282. return
  283. }
  284. func GetEnglishReportList(condition string, pars []interface{}, companyType string, startSize, pageSize int, fieldArr []string) (items []*EnglishReport, err error) {
  285. o := orm.NewOrmUsingDB("rddp")
  286. //产品权限
  287. companyTypeSqlStr := ``
  288. if companyType == "ficc" {
  289. companyTypeSqlStr = " AND classify_id_first != 40 "
  290. } else if companyType == "权益" {
  291. companyTypeSqlStr = " AND classify_id_first = 40 "
  292. }
  293. fields := "*"
  294. if len(fieldArr) > 0 {
  295. fields = strings.Join(fieldArr, ",")
  296. }
  297. sql := fmt.Sprintf(`SELECT %s FROM english_report WHERE 1=1 %s `, fields, companyTypeSqlStr)
  298. if condition != "" {
  299. sql += condition
  300. }
  301. // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  302. sql += ` ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
  303. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  304. return
  305. }
  306. func GetEnglishReportByCondition(condition string, pars []interface{}) (items []*EnglishReport, err error) {
  307. o := orm.NewOrmUsingDB("rddp")
  308. sql := `SELECT *
  309. FROM english_report WHERE 1=1 `
  310. if condition != "" {
  311. sql += condition
  312. }
  313. _, err = o.Raw(sql, pars).QueryRows(&items)
  314. return
  315. }
  316. func GetEnglishReportCountByCondition(condition string, pars []interface{}) (count int, err error) {
  317. o := orm.NewOrmUsingDB("rddp")
  318. sql := `SELECT count(*)
  319. FROM english_report WHERE 1=1 `
  320. if condition != "" {
  321. sql += condition
  322. }
  323. err = o.Raw(sql, pars).QueryRow(&count)
  324. return
  325. }
  326. // PublishEnglishReportById 发布报告
  327. func PublishEnglishReportById(reportId int, publishTime string) (err error) {
  328. o := orm.NewOrmUsingDB("rddp")
  329. sql := `UPDATE english_report SET state=2,publish_time=?,pre_publish_time=null,modify_time=NOW() WHERE id = ? `
  330. _, err = o.Raw(sql, publishTime, reportId).Exec()
  331. return
  332. }
  333. // ResetEnglishReportById 重置报告状态
  334. func ResetEnglishReportById(reportId, state int) (err error) {
  335. o := orm.NewOrmUsingDB("rddp")
  336. sql := `UPDATE english_report SET state = ?, pre_publish_time = null, modify_time = NOW() WHERE id = ?`
  337. _, err = o.Raw(sql, state, reportId).Exec()
  338. return
  339. }
  340. // PublishCancelEnglishReport 取消发布报告
  341. func PublishCancelEnglishReport(reportIds, state int) (err error) {
  342. o := orm.NewOrmUsingDB("rddp")
  343. sql := ` UPDATE english_report SET state=?, pre_publish_time=null WHERE id =? `
  344. _, err = o.Raw(sql, state, reportIds).Exec()
  345. return
  346. }
  347. // SetPrePublishEnglishReportById 设置定时发布
  348. func SetPrePublishEnglishReportById(reportId int, prePublishTime string) (err error) {
  349. o := orm.NewOrmUsingDB("rddp")
  350. sql := `UPDATE english_report SET pre_publish_time=? WHERE id = ? and state = 1 `
  351. _, err = o.Raw(sql, prePublishTime, reportId).Exec()
  352. return
  353. }
  354. // DeleteEnglishReportAndChapter 删除报告及章节
  355. func DeleteEnglishReportAndChapter(reportInfo *EnglishReportDetail) (err error) {
  356. reportId := reportInfo.Id
  357. if reportInfo.State == 2 {
  358. err = errors.New("报告已发布,不可删除")
  359. return
  360. }
  361. err = DeleteEnglishReport(reportId)
  362. if err != nil {
  363. err = errors.New("删除失败, Err: " + err.Error())
  364. return
  365. }
  366. return
  367. }
  368. // 删除报告
  369. func DeleteEnglishReport(reportIds int) (err error) {
  370. o := orm.NewOrmUsingDB("rddp")
  371. sql := ` DELETE FROM english_report WHERE id =? `
  372. _, err = o.Raw(sql, reportIds).Exec()
  373. return
  374. }
  375. func EditEnglishReportContent(reportId int, content, contentSub string) (err error) {
  376. o := orm.NewOrmUsingDB("rddp")
  377. sql := ` UPDATE english_report SET content=?,content_sub=?,modify_time=NOW() WHERE id=? `
  378. _, err = o.Raw(sql, content, contentSub, reportId).Exec()
  379. return
  380. }
  381. func AddEnglishReportSaveLog(reportId, adminId int, content, contentSub, adminName string) (err error) {
  382. o := orm.NewOrmUsingDB("rddp")
  383. sql := ` INSERT INTO english_report_save_log(report_id, content,content_sub,admin_id,admin_name) VALUES (?,?,?,?,?) `
  384. _, err = o.Raw(sql, reportId, content, contentSub, adminId, adminName).Exec()
  385. return
  386. }
  387. type EnglishClassifyList struct {
  388. Id int `orm:"column(id);pk"`
  389. ClassifyName string `description:"分类名称"`
  390. Sort int `description:"排序"`
  391. ParentId int `description:"父级分类id"`
  392. RootId int `description:"一级分类ID"`
  393. CreateTime time.Time `description:"创建时间"`
  394. ModifyTime time.Time `description:"修改时间"`
  395. ClassifyLabel string `description:"分类标签"`
  396. ShowType int `description:"展示类型:1-列表 2-专栏"`
  397. IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  398. //ClassifyType int `description:"分类类型:0英文报告,1英文线上路演"`
  399. EnPermissions []int `description:"英文权限IDs"`
  400. Enabled int `description:"是否可用,1可用,0禁用"`
  401. Child []*EnglishClassifyList
  402. }
  403. type EnglishClassifyListResp struct {
  404. List []*EnglishClassifyList
  405. }
  406. // GetEnglishClassifyRootId 获取一级分类列表
  407. func GetEnglishClassifyRootId(keyword string, enabled int) (items []*EnglishClassifyList, err error) {
  408. sql := ``
  409. o := orm.NewOrmUsingDB("rddp")
  410. cond := ""
  411. if enabled == 1 {
  412. cond = " AND enabled=1 "
  413. }
  414. if keyword != "" {
  415. sql = `SELECT * FROM (
  416. SELECT * FROM english_classify
  417. WHERE parent_id=0 ` + cond + ` AND classify_name LIKE ?
  418. UNION
  419. SELECT * FROM english_classify
  420. WHERE id IN(SELECT parent_id FROM english_classify
  421. WHERE parent_id>0 ` + cond + ` AND classify_name LIKE ? )
  422. )AS t
  423. ORDER BY sort ASC,create_time ASC`
  424. _, err = o.Raw(sql, utils.GetLikeKeyword(keyword), utils.GetLikeKeyword(keyword)).QueryRows(&items)
  425. } else {
  426. sql = `SELECT * FROM english_classify WHERE parent_id=0 ` + cond + ` ORDER BY sort ASC,create_time ASC `
  427. _, err = o.Raw(sql).QueryRows(&items)
  428. }
  429. return
  430. }
  431. func GetEnglishClassifyListByRootId(rootIds []int, keyword string, enabled int) (items []*EnglishClassifyList, err error) {
  432. sql := ``
  433. pars := make([]interface{}, 0)
  434. o := orm.NewOrmUsingDB("rddp")
  435. cond := ""
  436. if enabled == 1 {
  437. cond = " AND enabled=1 "
  438. }
  439. if keyword != "" {
  440. sql = `SELECT
  441. a.*
  442. FROM
  443. english_classify a
  444. LEFT JOIN english_classify b ON a.root_id = b.id
  445. LEFT JOIN english_classify c ON a.parent_id = c.id
  446. WHERE a.parent_id>0 ` + cond + ` and a.classify_name LIKE ? and a.root_id IN (` + utils.GetOrmInReplace(len(rootIds)) + `)`
  447. pars = append(pars, utils.GetLikeKeyword(keyword))
  448. pars = append(pars, rootIds)
  449. _, err = o.Raw(sql, pars).QueryRows(&items)
  450. } else {
  451. sql = `SELECT * FROM english_classify WHERE parent_id>0 ` + cond + ` and root_id IN (` + utils.GetOrmInReplace(len(rootIds)) + `) `
  452. _, err = o.Raw(sql, rootIds).QueryRows(&items)
  453. }
  454. return
  455. }
  456. func GetEnglishClassifyChildByIds(ids []int) (items []*EnglishClassifyList, err error) {
  457. o := orm.NewOrmUsingDB("rddp")
  458. sql := `SELECT * FROM english_classify WHERE id IN (` + utils.GetOrmInReplace(len(ids)) + `) ORDER BY create_time ASC `
  459. _, err = o.Raw(sql, ids).QueryRows(&items)
  460. return
  461. }
  462. func GetEnglishReportDetailByClassifyId(classifyIdFirst, classifyIdSecond int) (item *EnglishReportDetail, err error) {
  463. o := orm.NewOrmUsingDB("rddp")
  464. sql := ` SELECT * FROM english_report WHERE 1=1 `
  465. if classifyIdSecond > 0 {
  466. sql = sql + ` AND classify_id_second=? ORDER BY stage DESC LIMIT 1`
  467. err = o.Raw(sql, classifyIdSecond).QueryRow(&item)
  468. } else {
  469. sql = sql + ` AND classify_id_first=? ORDER BY stage DESC LIMIT 1`
  470. err = o.Raw(sql, classifyIdFirst).QueryRow(&item)
  471. }
  472. return
  473. }
  474. // Update 更新
  475. func (item *EnglishReport) Update(cols []string) (err error) {
  476. o := orm.NewOrmUsingDB("rddp")
  477. _, err = o.Update(item, cols...)
  478. return
  479. }
  480. // ModifyEnglishReportAuthor 更改英文报告作者
  481. func ModifyEnglishReportAuthor(condition string, pars []interface{}, authorName string) (count int, err error) {
  482. //产品权限
  483. oRddp := orm.NewOrmUsingDB("rddp")
  484. sql := `UPDATE english_report set author = ? WHERE 1=1 `
  485. if condition != "" {
  486. sql += condition
  487. }
  488. err = oRddp.Raw(sql, authorName, pars).QueryRow(&count)
  489. return
  490. }
  491. type EnglishClassify struct {
  492. Id int `orm:"column(id);pk"`
  493. ClassifyName string `description:"分类名称"`
  494. Sort int `description:"排序"`
  495. ParentId int `description:"父级分类id"`
  496. RootId int `description:"一级分类ID"`
  497. CreateTime time.Time `description:"创建时间"`
  498. ModifyTime time.Time `description:"修改时间"`
  499. ClassifyLabel string `description:"分类标签"`
  500. ShowType int `description:"展示类型:1-列表 2-专栏"`
  501. IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  502. //ClassifyType int `description:"分类类型:0英文报告,1英文线上路演"`
  503. Enabled int `description:"是否可用,1可用,0禁用"`
  504. }
  505. func AddEnglishClassify(item *EnglishClassify) (lastId int64, err error) {
  506. o := orm.NewOrmUsingDB("rddp")
  507. lastId, err = o.Insert(item)
  508. return
  509. }
  510. func ModifyEnglishClassify(item *EnglishClassify) (err error) {
  511. o := orm.NewOrmUsingDB("rddp")
  512. sql := `UPDATE english_classify
  513. SET
  514. classify_name = ?,
  515. sort = ?,
  516. parent_id = ?,
  517. root_id = ?,
  518. modify_time = ?
  519. WHERE id = ? `
  520. _, err = o.Raw(sql, item.ClassifyName, item.Sort, item.ParentId, item.RootId, item.ModifyTime, item.Id).Exec()
  521. return
  522. }
  523. // UpdateEnglishClassifyRootIdByParentId 更新报告分类的顶级ID
  524. func UpdateEnglishClassifyRootIdByParentId(parentId, rootId int) (err error) {
  525. o := orm.NewOrmUsingDB("rddp")
  526. sql := " UPDATE english_classify SET root_id = ? WHERE parent_id=? "
  527. _, err = o.Raw(sql, rootId, parentId).Exec()
  528. return
  529. }
  530. // UpdateClassify 更新分类
  531. func (classifyInfo *EnglishClassify) UpdateEnglishClassify(cols []string) (err error) {
  532. o := orm.NewOrmUsingDB("rddp")
  533. _, err = o.Update(classifyInfo, cols...)
  534. return
  535. }
  536. // DeleteEnglishClassify 删除英文分类
  537. func DeleteEnglishClassify(classifyId int) (err error) {
  538. o := orm.NewOrmUsingDB("rddp")
  539. sql := ` DELETE FROM english_classify WHERE id =? `
  540. _, err = o.Raw(sql, classifyId).Exec()
  541. return
  542. }
  543. func GetEnglishClassifyChildCounts(parentId int) (count int, err error) {
  544. o := orm.NewOrmUsingDB("rddp")
  545. sql := `SELECT COUNT(1) AS count FROM english_classify WHERE parent_id=? `
  546. err = o.Raw(sql, parentId).QueryRow(&count)
  547. return
  548. }
  549. func GetEnglishReportCounts(classifyId, parentId int) (count int, err error) {
  550. o := orm.NewOrmUsingDB("rddp")
  551. sql := ``
  552. if parentId == 0 {
  553. sql = `SELECT COUNT(1) AS count FROM english_report WHERE classify_id_first=? `
  554. } else {
  555. sql = `SELECT COUNT(1) AS count FROM english_report WHERE classify_id_second=? `
  556. }
  557. err = o.Raw(sql, classifyId).QueryRow(&count)
  558. return
  559. }
  560. func GetEnglishClassifyCountsByName(name string, parentId int) (count int, err error) {
  561. o := orm.NewOrmUsingDB("rddp")
  562. sql := `SELECT COUNT(1) AS count FROM english_classify WHERE classify_name=? AND parent_id = ? `
  563. err = o.Raw(sql, name, parentId).QueryRow(&count)
  564. return
  565. }
  566. // GetEnglishFirstClassifyList 获取一级、二级分类列表
  567. func GetEnglishFirstClassifyList() (items []*EnglishClassifyList, err error) {
  568. o := orm.NewOrmUsingDB("rddp")
  569. sql := `SELECT * FROM english_classify WHERE parent_id=0 ORDER BY sort ASC,create_time`
  570. _, err = o.Raw(sql).QueryRows(&items)
  571. return
  572. }
  573. // GetEnglishSecondClassifyList 获取一级、二级分类列表
  574. func GetEnglishSecondClassifyList(rootIds []int) (items []*EnglishClassifyList, err error) {
  575. o := orm.NewOrmUsingDB("rddp")
  576. 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`
  577. _, err = o.Raw(sql, rootIds).QueryRows(&items)
  578. return
  579. }
  580. func GetEnglishFirstClassifyListCount() (count int, err error) {
  581. o := orm.NewOrmUsingDB("rddp")
  582. sqlCount := `SELECT COUNT(1) AS count FROM english_classify WHERE parent_id=0`
  583. err = o.Raw(sqlCount).QueryRow(&count)
  584. return
  585. }
  586. func GetEnglishReportClassifyById(classifyId int) (item *EnglishClassify, err error) {
  587. sql := `SELECT * FROM english_classify WHERE id=?`
  588. o := orm.NewOrmUsingDB("rddp")
  589. err = o.Raw(sql, classifyId).QueryRow(&item)
  590. return
  591. }
  592. func GetEnglishReportClassifyByIds(classifyIds []int) (list []*EnglishClassify, err error) {
  593. o := orm.NewOrmUsingDB("rddp")
  594. sql := `SELECT * FROM english_classify WHERE id IN (` + utils.GetOrmInReplace(len(classifyIds)) + `)`
  595. _, err = o.Raw(sql, classifyIds).QueryRows(&list)
  596. return
  597. }
  598. // UpdateEnglishReportSecondClassifyNameByClassifyId 更新报告分类名称字段
  599. func UpdateEnglishReportSecondClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  600. o := orm.NewOrmUsingDB("rddp")
  601. sql := " UPDATE english_report SET classify_name_second = ? WHERE classify_id_second = ? "
  602. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  603. return
  604. }
  605. // UpdateEnglishReportFirstClassifyNameByClassifyId 更新报告分类名称字段
  606. func UpdateEnglishReportFirstClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  607. o := orm.NewOrmUsingDB("rddp")
  608. sql := " UPDATE english_report SET classify_name_first = ? WHERE classify_id_first = ? "
  609. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  610. return
  611. }
  612. // UpdateEnglishReportFirstClassifyNameByClassifyId 更新报告分类名称字段
  613. func UpdateEnglishReportByClassifyId(classifyFirstName, classifySecondName string, firstClassifyId, secondClassifyId int, ids string) (err error) {
  614. o := orm.NewOrmUsingDB("rddp")
  615. sql := " UPDATE english_report SET classify_name_first = ?,classify_name_second = ?,classify_id_first=?, classify_id_second =? WHERE id IN (" + ids + ") "
  616. _, err = o.Raw(sql, classifyFirstName, classifySecondName, firstClassifyId, secondClassifyId).Exec()
  617. return
  618. }
  619. func UpdateEnglishReportClassifyByFirstSecondClassifyId(classifyId, parentId int) (err error) {
  620. o := orm.NewOrmUsingDB("rddp")
  621. // 更新相关联的二级分类的parentId,和classify_name_second
  622. sql := `update english_report r
  623. LEFT JOIN english_classify c ON r.classify_id_second = c.id
  624. SET r.classify_id_first=c.parent_id, r.classify_name_second=c.classify_name
  625. where (r.classify_id_first != c.parent_id or r.classify_name_second != c.classify_name) and r.classify_id_second =?`
  626. _, err = o.Raw(sql, classifyId).Exec()
  627. if err != nil {
  628. return
  629. }
  630. //更新一级分类名
  631. sql = `update english_report r
  632. LEFT JOIN english_classify c ON r.classify_id_first = c.id
  633. SET r.classify_name_first=c.classify_name
  634. where r.classify_name_first != c.classify_name and r.classify_id_first=?`
  635. _, err = o.Raw(sql, parentId).Exec()
  636. if err != nil {
  637. return
  638. }
  639. //更新一级分类名
  640. sql = `update english_report r
  641. LEFT JOIN english_classify c ON r.classify_id_first = c.id
  642. SET r.classify_name_first=c.classify_name
  643. where r.classify_name_first != c.classify_name and r.classify_id_first=?`
  644. _, err = o.Raw(sql, classifyId).Exec()
  645. return
  646. }
  647. // FetchEnglishReportById 主键获取英文报告
  648. func FetchEnglishReportById(reportId int) (item *EnglishReport, err error) {
  649. o := orm.NewOrmUsingDB("rddp")
  650. sql := `SELECT * FROM english_report WHERE id=?`
  651. err = o.Raw(sql, reportId).QueryRow(&item)
  652. return
  653. }
  654. // UpdateReport 更新英文报告
  655. func (reportInfo *EnglishReport) UpdateReport(cols []string) (err error) {
  656. o := orm.NewOrmUsingDB("rddp")
  657. _, err = o.Update(reportInfo, cols...)
  658. return
  659. }
  660. // GetAllEnglishClassify 获取所有英文分类
  661. func GetAllEnglishClassify() (list []*Classify, err error) {
  662. o := orm.NewOrmUsingDB("rddp")
  663. sql := ` SELECT * FROM english_classify `
  664. _, err = o.Raw(sql).QueryRows(&list)
  665. return
  666. }
  667. // GetEnglishReportByIds 根据IDs获取英文报告列表
  668. func GetEnglishReportByIds(reportIds []int, fieldArr []string) (list []*EnglishReport, err error) {
  669. listLen := len(reportIds)
  670. if listLen == 0 {
  671. return
  672. }
  673. fields := ` * `
  674. if len(fieldArr) > 0 {
  675. fields = strings.Join(fieldArr, ",")
  676. }
  677. o := orm.NewOrmUsingDB("rddp")
  678. sql := `SELECT ` + fields + ` FROM english_report WHERE id IN (` + utils.GetOrmInReplace(listLen) + `)`
  679. _, err = o.Raw(sql, reportIds).QueryRows(&list)
  680. return
  681. }
  682. // MarkEditEnReport 标记编辑英文研报的请求数据
  683. type MarkEditEnReport struct {
  684. ReportId int `description:"研报id"`
  685. Status int `description:"标记状态,1:编辑中,2:编辑完成"`
  686. }
  687. type EnglishClassifyNameParentName struct {
  688. Id int `description:"分类ID"`
  689. ClassifyName string `description:"分类名称"`
  690. Sort int `description:"排序"`
  691. ParentId int `description:"父级分类id"`
  692. CreateTime time.Time `description:"创建时间"`
  693. ModifyTime time.Time `description:"修改时间"`
  694. ClassifyLabel string `description:"分类标签"`
  695. ShowType int `description:"展示类型:1-列表 2-专栏"`
  696. IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  697. ParentClassifyName string `description:"父级分类名称"`
  698. }
  699. func GetEnglishClassifyByClassifyNameAndParentName(parentClassiyName, classifyName string) (item EnglishClassifyNameParentName, err error) {
  700. o := orm.NewOrmUsingDB("rddp")
  701. 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= ?"
  702. err = o.Raw(sql, parentClassiyName, classifyName).QueryRow(&item)
  703. return
  704. }
  705. type RSClassifyList []*EnglishClassifyList
  706. func (m RSClassifyList) Len() int {
  707. return len(m)
  708. }
  709. func (m RSClassifyList) Less(i, j int) bool {
  710. return m[i].Sort < m[j].Sort
  711. }
  712. func (m RSClassifyList) Swap(i, j int) {
  713. m[i], m[j] = m[j], m[i]
  714. }
  715. type RSChildClassifyList []*EnglishClassifyList
  716. func (m RSChildClassifyList) Len() int {
  717. return len(m)
  718. }
  719. func (m RSChildClassifyList) Less(i, j int) bool {
  720. return m[i].Sort < m[j].Sort
  721. }
  722. func (m RSChildClassifyList) Swap(i, j int) {
  723. m[i], m[j] = m[j], m[i]
  724. }
  725. // GetEnglishClassifyByClassifyNameParentId 获取英文分类
  726. func GetEnglishClassifyByClassifyNameParentId(classifyName string, parentId int) (item *Classify, err error) {
  727. o := orm.NewOrmUsingDB("rddp")
  728. sql := ` SELECT * FROM english_classify where classify_name = ? and parent_id = ? `
  729. err = o.Raw(sql, classifyName, parentId).QueryRow(&item)
  730. return
  731. }
  732. type EnglishClassifyFullName struct {
  733. Id int `description:"分类ID"`
  734. ParentId int `description:"父级分类id"`
  735. RootId int `description:"一级分类ID"`
  736. RootName string `description:"一级分类名"`
  737. ParentName string `description:"二级分类名"`
  738. ClassifyName string `description:"分类名称"`
  739. }
  740. // GetEnglishClassifyFullNameByIds 获取英文分类名一级/二级/三级
  741. func GetEnglishClassifyFullNameByIds(classifyIds []int) (list []*EnglishClassifyFullName, err error) {
  742. o := orm.NewOrmUsingDB("rddp")
  743. sql := ` SELECT
  744. a.id,
  745. a.parent_id,
  746. a.root_id,
  747. a.classify_name,
  748. b.classify_name AS root_name,
  749. c.classify_name AS parent_name
  750. FROM
  751. english_classify a
  752. LEFT JOIN english_classify b ON a.root_id = b.id
  753. LEFT JOIN english_classify c ON a.parent_id = c.id
  754. where a.id IN (` + utils.GetOrmInReplace(len(classifyIds)) + `)`
  755. _, err = o.Raw(sql, classifyIds).QueryRows(&list)
  756. return
  757. }
  758. func (m *EnglishReport) GetItemById(id int) (item *EnglishReport, err error) {
  759. o := orm.NewOrmUsingDB("rddp")
  760. sql := `SELECT * FROM english_report WHERE id = ? LIMIT 1`
  761. err = o.Raw(sql, id).QueryRow(&item)
  762. return
  763. }
  764. // GetEnglishClassifies 获取所有英文分类
  765. func GetEnglishClassifies() (list []*EnglishClassify, err error) {
  766. o := orm.NewOrmUsingDB("rddp")
  767. sql := ` SELECT * FROM english_classify `
  768. _, err = o.Raw(sql).QueryRows(&list)
  769. return
  770. }
  771. // GetEnglishReportStateCount 获取指定状态的报告数量
  772. func GetEnglishReportStateCount(state int) (count int, err error) {
  773. o := orm.NewOrmUsingDB("rddp")
  774. sql := `SELECT COUNT(1) AS count FROM english_report WHERE state = ?`
  775. err = o.Raw(sql, state).QueryRow(&count)
  776. return
  777. }
  778. // UpdateEnglishReportsStateByCond 批量更新报告状态
  779. func UpdateEnglishReportsStateByCond(classifyFirstId, classifySecondId, oldState, newState int) (err error) {
  780. o := orm.NewOrmUsingDB("rddp")
  781. cond := ``
  782. if classifyFirstId > 0 {
  783. cond += fmt.Sprintf(` AND classify_id_first = %d`, classifyFirstId)
  784. }
  785. if classifySecondId > 0 {
  786. cond += fmt.Sprintf(` AND classify_id_second = %d`, classifySecondId)
  787. }
  788. sql := fmt.Sprintf(`UPDATE english_report SET state = ?, pre_publish_time = NULL WHERE state = ? %s`, cond)
  789. _, err = o.Raw(sql, newState, oldState).Exec()
  790. return
  791. }
  792. // UpdateEnglishReportsStateBySecondIds 批量更新二级分类报告状态
  793. func UpdateEnglishReportsStateBySecondIds(oldState, newState int, secondIds []int) (err error) {
  794. if len(secondIds) <= 0 {
  795. return
  796. }
  797. o := orm.NewOrmUsingDB("rddp")
  798. // (有审批流的)未发布->待提交
  799. sql := fmt.Sprintf(`UPDATE english_report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  800. _, err = o.Raw(sql, newState, oldState, secondIds).Exec()
  801. if err != nil {
  802. return
  803. }
  804. // (无审批流的)待提交->未发布
  805. sql = fmt.Sprintf(`UPDATE english_report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second NOT IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  806. _, err = o.Raw(sql, oldState, newState, secondIds).Exec()
  807. return
  808. }
  809. type EnglishClassifySetEnabledReq struct {
  810. ClassifyId int `description:"分类ID"`
  811. Enabled int `description:"是否可用,1可用,0禁用"`
  812. }
  813. func (classifyInfo *EnglishClassify) SetEnabled(id, enabled int) (err error) {
  814. o := orm.NewOrmUsingDB("rddp")
  815. to, err := o.Begin()
  816. if err != nil {
  817. return
  818. }
  819. defer func() {
  820. if err != nil {
  821. _ = to.Rollback()
  822. } else {
  823. _ = to.Commit()
  824. }
  825. }()
  826. sql := ` UPDATE english_classify SET enabled =? WHERE id = ?`
  827. _, err = to.Raw(sql, enabled, id).Exec()
  828. if err != nil {
  829. return
  830. }
  831. sql = ` UPDATE english_classify SET enabled =? WHERE parent_id = ? or root_id = ?`
  832. _, err = to.Raw(sql, enabled, id, id).Exec()
  833. if err != nil {
  834. return
  835. }
  836. return
  837. }
  838. func ModifyEnglishReportPdfUrl(reportId int, detailPdfUrl string) (err error) {
  839. o := orm.NewOrmUsingDB("rddp")
  840. sql := `UPDATE english_report SET detail_pdf_url=? WHERE id=? `
  841. _, err = o.Raw(sql, detailPdfUrl, reportId).Exec()
  842. return
  843. }
  844. func ModifyEnglishReportImgUrl(reportId int, detailImgUrl string) (err error) {
  845. o := orm.NewOrmUsingDB("rddp")
  846. sql := `UPDATE english_report SET detail_img_url=? WHERE id=? `
  847. _, err = o.Raw(sql, detailImgUrl, reportId).Exec()
  848. return
  849. }
  850. // UpdatePdfUrlEnglishReportById 清空pdf相关字段
  851. func UpdatePdfUrlEnglishReportById(reportId int) (err error) {
  852. o := orm.NewOrmUsingDB("rddp")
  853. sql := `UPDATE english_report SET detail_img_url = '',detail_pdf_url='',modify_time=NOW() WHERE id = ? `
  854. _, err = o.Raw(sql, reportId).Exec()
  855. return
  856. }
  857. func FormatEnglishReport2ListItem(origin *EnglishReport) (item *EnglishReportList) {
  858. if origin == nil {
  859. return
  860. }
  861. item = new(EnglishReportList)
  862. item.Id = origin.Id
  863. item.AddType = origin.AddType
  864. item.ClassifyIdFirst = origin.ClassifyIdFirst
  865. item.ClassifyNameFirst = origin.ClassifyNameFirst
  866. item.ClassifyIdSecond = origin.ClassifyIdSecond
  867. item.ClassifyNameSecond = origin.ClassifyNameSecond
  868. item.Title = origin.Title
  869. item.Abstract = origin.Abstract
  870. item.Author = origin.Author
  871. item.Frequency = origin.Frequency
  872. item.CreateTime = origin.CreateTime
  873. item.ModifyTime = origin.ModifyTime
  874. item.State = origin.State
  875. item.PublishTime = utils.TimeTransferString(utils.FormatDateTime, origin.PublishTime)
  876. item.PrePublishTime = utils.TimeTransferString(utils.FormatDateTime, origin.PrePublishTime)
  877. item.Stage = origin.Stage
  878. //item.Content = origin.Content
  879. item.VideoUrl = origin.VideoUrl
  880. item.VideoName = origin.VideoName
  881. item.VideoPlaySeconds = origin.VideoPlaySeconds
  882. item.ContentSub = origin.ContentSub
  883. item.ReportCode = origin.ReportCode
  884. item.Pv = origin.Pv
  885. item.PvEmail = origin.PvEmail
  886. item.UvEmail = origin.UvEmail
  887. // 邮箱PV大于0的时候, 不展示最初版本的PV
  888. if item.PvEmail > 0 {
  889. item.Pv = 0
  890. }
  891. item.EmailState = origin.EmailState
  892. if origin.EmailHasFail == 1 {
  893. item.EmailHasFail = true
  894. }
  895. item.FromReportId = origin.FromReportId
  896. item.AdminId = origin.AdminId
  897. item.AdminRealName = origin.AdminRealName
  898. item.ApproveTime = utils.TimeTransferString(utils.FormatDateTime, origin.ApproveTime)
  899. item.DetailImgUrl = origin.DetailImgUrl
  900. item.DetailPdfUrl = origin.DetailPdfUrl
  901. return
  902. }