english_report.go 36 KB

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