english_report.go 36 KB

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