english_report.go 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. package models
  2. import (
  3. "errors"
  4. "eta/eta_api/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. }
  255. type EnglishReportListResp struct {
  256. List []*EnglishReportList
  257. Paging *paging.PagingItem `description:"分页数据"`
  258. }
  259. func GetEnglishReportListCount(condition string, pars []interface{}, companyType string) (count int, err error) {
  260. //产品权限
  261. companyTypeSqlStr := ``
  262. if companyType == "ficc" {
  263. companyTypeSqlStr = " AND classify_id_first != 40 "
  264. } else if companyType == "权益" {
  265. companyTypeSqlStr = " AND classify_id_first = 40 "
  266. }
  267. oRddp := orm.NewOrmUsingDB("rddp")
  268. sql := `SELECT COUNT(1) AS count FROM english_report WHERE 1=1 ` + companyTypeSqlStr
  269. if condition != "" {
  270. sql += condition
  271. }
  272. err = oRddp.Raw(sql, pars).QueryRow(&count)
  273. return
  274. }
  275. func GetEnglishReportList(condition string, pars []interface{}, companyType string, startSize, pageSize int, fieldArr []string) (items []*EnglishReportList, err error) {
  276. o := orm.NewOrmUsingDB("rddp")
  277. //产品权限
  278. companyTypeSqlStr := ``
  279. if companyType == "ficc" {
  280. companyTypeSqlStr = " AND classify_id_first != 40 "
  281. } else if companyType == "权益" {
  282. companyTypeSqlStr = " AND classify_id_first = 40 "
  283. }
  284. fields := "*"
  285. if len(fieldArr) > 0 {
  286. fields = strings.Join(fieldArr, ",")
  287. }
  288. sql := fmt.Sprintf(`SELECT %s FROM english_report WHERE 1=1 %s `, fields, companyTypeSqlStr)
  289. if condition != "" {
  290. sql += condition
  291. }
  292. // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  293. sql += `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
  294. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  295. return
  296. }
  297. func GetEnglishReportByCondition(condition string, pars []interface{}) (items []*EnglishReport, err error) {
  298. o := orm.NewOrmUsingDB("rddp")
  299. sql := `SELECT *
  300. FROM english_report WHERE 1=1 `
  301. if condition != "" {
  302. sql += condition
  303. }
  304. _, err = o.Raw(sql, pars).QueryRows(&items)
  305. return
  306. }
  307. func GetEnglishReportCountByCondition(condition string, pars []interface{}) (count int, err error) {
  308. o := orm.NewOrmUsingDB("rddp")
  309. sql := `SELECT count(*)
  310. FROM english_report WHERE 1=1 `
  311. if condition != "" {
  312. sql += condition
  313. }
  314. err = o.Raw(sql, pars).QueryRow(&count)
  315. return
  316. }
  317. // PublishEnglishReportById 发布报告
  318. func PublishEnglishReportById(reportId int, publishTime string) (err error) {
  319. o := orm.NewOrmUsingDB("rddp")
  320. sql := `UPDATE english_report SET state=2,publish_time=?,pre_publish_time=null,modify_time=NOW() WHERE id = ? `
  321. _, err = o.Raw(sql, publishTime, reportId).Exec()
  322. return
  323. }
  324. // ResetEnglishReportById 重置报告状态
  325. func ResetEnglishReportById(reportId, state int) (err error) {
  326. o := orm.NewOrmUsingDB("rddp")
  327. sql := `UPDATE english_report SET state = ?, pre_publish_time = null, modify_time = NOW() WHERE id = ?`
  328. _, err = o.Raw(sql, state, reportId).Exec()
  329. return
  330. }
  331. // PublishCancelEnglishReport 取消发布报告
  332. func PublishCancelEnglishReport(reportIds, state int) (err error) {
  333. o := orm.NewOrmUsingDB("rddp")
  334. sql := ` UPDATE english_report SET state=?, pre_publish_time=null WHERE id =? `
  335. _, err = o.Raw(sql, state, reportIds).Exec()
  336. return
  337. }
  338. // SetPrePublishEnglishReportById 设置定时发布
  339. func SetPrePublishEnglishReportById(reportId int, prePublishTime string) (err error) {
  340. o := orm.NewOrmUsingDB("rddp")
  341. sql := `UPDATE english_report SET pre_publish_time=? WHERE id = ? and state = 1 `
  342. _, err = o.Raw(sql, prePublishTime, reportId).Exec()
  343. return
  344. }
  345. // DeleteEnglishReportAndChapter 删除报告及章节
  346. func DeleteEnglishReportAndChapter(reportInfo *EnglishReportDetail) (err error) {
  347. reportId := reportInfo.Id
  348. if reportInfo.State == 2 {
  349. err = errors.New("报告已发布,不可删除")
  350. return
  351. }
  352. err = DeleteEnglishReport(reportId)
  353. if err != nil {
  354. err = errors.New("删除失败, Err: " + err.Error())
  355. return
  356. }
  357. return
  358. }
  359. // 删除报告
  360. func DeleteEnglishReport(reportIds int) (err error) {
  361. o := orm.NewOrmUsingDB("rddp")
  362. sql := ` DELETE FROM english_report WHERE id =? `
  363. _, err = o.Raw(sql, reportIds).Exec()
  364. return
  365. }
  366. func EditEnglishReportContent(reportId int, content, contentSub string) (err error) {
  367. o := orm.NewOrmUsingDB("rddp")
  368. sql := ` UPDATE english_report SET content=?,content_sub=?,modify_time=NOW() WHERE id=? `
  369. _, err = o.Raw(sql, content, contentSub, reportId).Exec()
  370. return
  371. }
  372. func AddEnglishReportSaveLog(reportId, adminId int, content, contentSub, adminName string) (err error) {
  373. o := orm.NewOrmUsingDB("rddp")
  374. sql := ` INSERT INTO english_report_save_log(report_id, content,content_sub,admin_id,admin_name) VALUES (?,?,?,?,?) `
  375. _, err = o.Raw(sql, reportId, content, contentSub, adminId, adminName).Exec()
  376. return
  377. }
  378. type EnglishClassifyList struct {
  379. Id int `orm:"column(id);pk"`
  380. ClassifyName string `description:"分类名称"`
  381. Sort int `description:"排序"`
  382. ParentId int `description:"父级分类id"`
  383. RootId int `description:"一级分类ID"`
  384. CreateTime time.Time `description:"创建时间"`
  385. ModifyTime time.Time `description:"修改时间"`
  386. ClassifyLabel string `description:"分类标签"`
  387. ShowType int `description:"展示类型:1-列表 2-专栏"`
  388. IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  389. //ClassifyType int `description:"分类类型:0英文报告,1英文线上路演"`
  390. EnPermissions []int `description:"英文权限IDs"`
  391. Child []*EnglishClassifyList
  392. }
  393. type EnglishClassifyListResp struct {
  394. List []*EnglishClassifyList
  395. Paging *paging.PagingItem `description:"分页数据"`
  396. }
  397. // GetEnglishClassifyRootId 获取一级分类列表
  398. func GetEnglishClassifyRootId(startSize, pageSize int, keyword string) (items []*EnglishClassifyList, err error) {
  399. sql := ``
  400. o := orm.NewOrmUsingDB("rddp")
  401. if keyword != "" {
  402. sql = `SELECT * FROM (
  403. SELECT * FROM english_classify
  404. WHERE parent_id=0 AND classify_name ?
  405. UNION
  406. SELECT * FROM english_classify
  407. WHERE id IN(SELECT parent_id FROM english_classify
  408. WHERE parent_id>0 AND classify_name LIKE ?)
  409. )AS t
  410. ORDER BY sort ASC,create_time ASC
  411. LIMIT ?,? `
  412. _, err = o.Raw(sql, utils.GetLikeKeyword(keyword), utils.GetLikeKeyword(keyword), startSize, pageSize).QueryRows(&items)
  413. } else {
  414. sql = `SELECT * FROM english_classify WHERE parent_id=0 ORDER BY sort ASC,create_time ASC LIMIT ?,? `
  415. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  416. }
  417. return
  418. }
  419. func GetEnglishClassifyListCount(keyword string) (count int, err error) {
  420. sqlCount := ``
  421. o := orm.NewOrmUsingDB("rddp")
  422. if keyword != "" {
  423. sqlCount = `SELECT COUNT(1) AS count FROM (
  424. SELECT * FROM english_classify
  425. WHERE parent_id=0 AND classify_name LIKE ?
  426. UNION
  427. SELECT * FROM english_classify
  428. WHERE id IN(SELECT parent_id FROM english_classify
  429. WHERE parent_id>0 AND classify_name LIKE ?)
  430. )AS t `
  431. err = o.Raw(sqlCount, utils.GetLikeKeyword(keyword), utils.GetLikeKeyword(keyword)).QueryRow(&count)
  432. } else {
  433. sqlCount = `SELECT COUNT(1) AS count FROM english_classify WHERE parent_id=0`
  434. err = o.Raw(sqlCount).QueryRow(&count)
  435. }
  436. return
  437. }
  438. func GetEnglishClassifyListByRootId(rootIds []int, keyword string) (items []*EnglishClassifyList, err error) {
  439. sql := ``
  440. pars := make([]interface{}, 0)
  441. o := orm.NewOrmUsingDB("rddp")
  442. if keyword != "" {
  443. sql = `SELECT
  444. a.*
  445. FROM
  446. english_classify a
  447. LEFT JOIN english_classify b ON a.root_id = b.id
  448. LEFT JOIN english_classify c ON a.parent_id = c.id
  449. WHERE a.parent_id>0 and a.classify_name LIKE ? and a.root_id IN (` + utils.GetOrmInReplace(len(rootIds)) + `)`
  450. pars = append(pars, utils.GetLikeKeyword(keyword))
  451. pars = append(pars, rootIds)
  452. _, err = o.Raw(sql, pars).QueryRows(&items)
  453. } else {
  454. sql = `SELECT * FROM english_classify WHERE parent_id>0 and root_id IN (` + utils.GetOrmInReplace(len(rootIds)) + `) `
  455. _, err = o.Raw(sql, rootIds).QueryRows(&items)
  456. }
  457. return
  458. }
  459. func GetEnglishClassifyChildByIds(ids []int) (items []*EnglishClassifyList, err error) {
  460. o := orm.NewOrmUsingDB("rddp")
  461. sql := `SELECT * FROM english_classify WHERE id IN (` + utils.GetOrmInReplace(len(ids)) + `) ORDER BY create_time ASC `
  462. _, err = o.Raw(sql, ids).QueryRows(&items)
  463. return
  464. }
  465. func GetEnglishReportDetailByClassifyId(classifyIdFirst, classifyIdSecond int) (item *EnglishReportDetail, err error) {
  466. o := orm.NewOrmUsingDB("rddp")
  467. sql := ` SELECT * FROM english_report WHERE 1=1 `
  468. if classifyIdSecond > 0 {
  469. sql = sql + ` AND classify_id_second=? ORDER BY stage DESC LIMIT 1`
  470. err = o.Raw(sql, classifyIdSecond).QueryRow(&item)
  471. } else {
  472. sql = sql + ` AND classify_id_first=? ORDER BY stage DESC LIMIT 1`
  473. err = o.Raw(sql, classifyIdFirst).QueryRow(&item)
  474. }
  475. return
  476. }
  477. // Update 更新
  478. func (item *EnglishReport) Update(cols []string) (err error) {
  479. o := orm.NewOrmUsingDB("rddp")
  480. _, err = o.Update(item, cols...)
  481. return
  482. }
  483. // ModifyEnglishReportAuthor 更改英文报告作者
  484. func ModifyEnglishReportAuthor(condition string, pars []interface{}, authorName string) (count int, err error) {
  485. //产品权限
  486. oRddp := orm.NewOrmUsingDB("rddp")
  487. sql := `UPDATE english_report set author = ? WHERE 1=1 `
  488. if condition != "" {
  489. sql += condition
  490. }
  491. err = oRddp.Raw(sql, authorName, pars).QueryRow(&count)
  492. return
  493. }
  494. type EnglishClassify struct {
  495. Id int `orm:"column(id);pk"`
  496. ClassifyName string `description:"分类名称"`
  497. Sort int `description:"排序"`
  498. ParentId int `description:"父级分类id"`
  499. RootId int `description:"一级分类ID"`
  500. CreateTime time.Time `description:"创建时间"`
  501. ModifyTime time.Time `description:"修改时间"`
  502. ClassifyLabel string `description:"分类标签"`
  503. ShowType int `description:"展示类型:1-列表 2-专栏"`
  504. IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  505. //ClassifyType int `description:"分类类型:0英文报告,1英文线上路演"`
  506. }
  507. func AddEnglishClassify(item *EnglishClassify) (lastId int64, err error) {
  508. o := orm.NewOrmUsingDB("rddp")
  509. lastId, err = o.Insert(item)
  510. return
  511. }
  512. func ModifyEnglishClassify(item *EnglishClassify) (err error) {
  513. o := orm.NewOrmUsingDB("rddp")
  514. sql := `UPDATE english_classify
  515. SET
  516. classify_name = ?,
  517. sort = ?,
  518. parent_id = ?,
  519. root_id = ?,
  520. modify_time = ?
  521. WHERE id = ? `
  522. _, err = o.Raw(sql, item.ClassifyName, item.Sort, item.ParentId, item.RootId, item.ModifyTime, item.Id).Exec()
  523. return
  524. }
  525. // UpdateEnglishClassifyRootIdByParentId 更新报告分类的顶级ID
  526. func UpdateEnglishClassifyRootIdByParentId(parentId, rootId int) (err error) {
  527. o := orm.NewOrmUsingDB("rddp")
  528. sql := " UPDATE english_classify SET root_id = ? WHERE parent_id=? "
  529. _, err = o.Raw(sql, rootId, parentId).Exec()
  530. return
  531. }
  532. // UpdateClassify 更新分类
  533. func (classifyInfo *EnglishClassify) UpdateEnglishClassify(cols []string) (err error) {
  534. o := orm.NewOrmUsingDB("rddp")
  535. _, err = o.Update(classifyInfo, cols...)
  536. return
  537. }
  538. // DeleteEnglishClassify 删除英文分类
  539. func DeleteEnglishClassify(classifyId int) (err error) {
  540. o := orm.NewOrmUsingDB("rddp")
  541. sql := ` DELETE FROM english_classify WHERE id =? `
  542. _, err = o.Raw(sql, classifyId).Exec()
  543. return
  544. }
  545. func GetEnglishClassifyChildCounts(parentId int) (count int, err error) {
  546. o := orm.NewOrmUsingDB("rddp")
  547. sql := `SELECT COUNT(1) AS count FROM english_classify WHERE parent_id=? `
  548. err = o.Raw(sql, parentId).QueryRow(&count)
  549. return
  550. }
  551. func GetEnglishReportCounts(classifyId, parentId int) (count int, err error) {
  552. o := orm.NewOrmUsingDB("rddp")
  553. sql := ``
  554. if parentId == 0 {
  555. sql = `SELECT COUNT(1) AS count FROM english_report WHERE classify_id_first=? `
  556. } else {
  557. sql = `SELECT COUNT(1) AS count FROM english_report WHERE classify_id_second=? `
  558. }
  559. err = o.Raw(sql, classifyId).QueryRow(&count)
  560. return
  561. }
  562. func GetEnglishClassifyCountsByName(name string, parentId int) (count int, err error) {
  563. o := orm.NewOrmUsingDB("rddp")
  564. sql := `SELECT COUNT(1) AS count FROM english_classify WHERE classify_name=? AND parent_id = ? `
  565. err = o.Raw(sql, name, parentId).QueryRow(&count)
  566. return
  567. }
  568. // GetEnglishFirstClassifyList 获取一级、二级分类列表
  569. func GetEnglishFirstClassifyList(startSize, pageSize int) (items []*EnglishClassifyList, err error) {
  570. o := orm.NewOrmUsingDB("rddp")
  571. sql := `SELECT * FROM english_classify WHERE parent_id=0 ORDER BY sort ASC,create_time ASC LIMIT ?,? `
  572. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  573. return
  574. }
  575. // GetEnglishSecondClassifyList 获取一级、二级分类列表
  576. func GetEnglishSecondClassifyList(rootIds []int) (items []*EnglishClassifyList, err error) {
  577. o := orm.NewOrmUsingDB("rddp")
  578. 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`
  579. _, err = o.Raw(sql, rootIds).QueryRows(&items)
  580. return
  581. }
  582. func GetEnglishFirstClassifyListCount() (count int, err error) {
  583. o := orm.NewOrmUsingDB("rddp")
  584. sqlCount := `SELECT COUNT(1) AS count FROM english_classify WHERE parent_id=0`
  585. err = o.Raw(sqlCount).QueryRow(&count)
  586. return
  587. }
  588. func GetEnglishReportClassifyById(classifyId int) (item *EnglishClassify, err error) {
  589. sql := `SELECT * FROM english_classify WHERE id=?`
  590. o := orm.NewOrmUsingDB("rddp")
  591. err = o.Raw(sql, classifyId).QueryRow(&item)
  592. return
  593. }
  594. func GetEnglishReportClassifyByIds(classifyIds []int) (list []*EnglishClassify, err error) {
  595. o := orm.NewOrmUsingDB("rddp")
  596. sql := `SELECT * FROM english_classify WHERE id IN (` + utils.GetOrmInReplace(len(classifyIds)) + `)`
  597. _, err = o.Raw(sql, classifyIds).QueryRows(&list)
  598. return
  599. }
  600. // UpdateEnglishReportSecondClassifyNameByClassifyId 更新报告分类名称字段
  601. func UpdateEnglishReportSecondClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  602. o := orm.NewOrmUsingDB("rddp")
  603. sql := " UPDATE english_report SET classify_name_second = ? WHERE classify_id_second = ? "
  604. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  605. return
  606. }
  607. // UpdateEnglishReportFirstClassifyNameByClassifyId 更新报告分类名称字段
  608. func UpdateEnglishReportFirstClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  609. o := orm.NewOrmUsingDB("rddp")
  610. sql := " UPDATE english_report SET classify_name_first = ? WHERE classify_id_first = ? "
  611. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  612. return
  613. }
  614. // UpdateEnglishReportFirstClassifyNameByClassifyId 更新报告分类名称字段
  615. func UpdateEnglishReportByClassifyId(classifyFirstName, classifySecondName string, firstClassifyId, secondClassifyId int, ids string) (err error) {
  616. o := orm.NewOrmUsingDB("rddp")
  617. sql := " UPDATE english_report SET classify_name_first = ?,classify_name_second = ?,classify_id_first=?, classify_id_second =? WHERE id IN (" + ids + ") "
  618. _, err = o.Raw(sql, classifyFirstName, classifySecondName, firstClassifyId, secondClassifyId).Exec()
  619. return
  620. }
  621. func UpdateEnglishReportClassifyByFirstSecondClassifyId(classifyId, parentId int) (err error) {
  622. o := orm.NewOrmUsingDB("rddp")
  623. // 更新相关联的二级分类的parentId,和classify_name_second
  624. sql := `update english_report r
  625. LEFT JOIN english_classify c ON r.classify_id_second = c.id
  626. SET r.classify_id_first=c.parent_id, r.classify_name_second=c.classify_name
  627. where (r.classify_id_first != c.parent_id or r.classify_name_second != c.classify_name) and r.classify_id_second =?`
  628. _, err = o.Raw(sql, classifyId).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, parentId).Exec()
  638. if err != nil {
  639. return
  640. }
  641. //更新一级分类名
  642. sql = `update english_report r
  643. LEFT JOIN english_classify c ON r.classify_id_first = c.id
  644. SET r.classify_name_first=c.classify_name
  645. where r.classify_name_first != c.classify_name and r.classify_id_first=?`
  646. _, err = o.Raw(sql, classifyId).Exec()
  647. return
  648. }
  649. // FetchEnglishReportById 主键获取英文报告
  650. func FetchEnglishReportById(reportId int) (item *EnglishReport, err error) {
  651. o := orm.NewOrmUsingDB("rddp")
  652. sql := `SELECT * FROM english_report WHERE id=?`
  653. err = o.Raw(sql, reportId).QueryRow(&item)
  654. return
  655. }
  656. // UpdateReport 更新英文报告
  657. func (reportInfo *EnglishReport) UpdateReport(cols []string) (err error) {
  658. o := orm.NewOrmUsingDB("rddp")
  659. _, err = o.Update(reportInfo, cols...)
  660. return
  661. }
  662. // GetAllEnglishClassify 获取所有英文分类
  663. func GetAllEnglishClassify() (list []*Classify, err error) {
  664. o := orm.NewOrmUsingDB("rddp")
  665. sql := ` SELECT * FROM english_classify `
  666. _, err = o.Raw(sql).QueryRows(&list)
  667. return
  668. }
  669. // GetEnglishReportByIds 根据IDs获取英文报告列表
  670. func GetEnglishReportByIds(reportIds []int, fieldArr []string) (list []*EnglishReport, err error) {
  671. listLen := len(reportIds)
  672. if listLen == 0 {
  673. return
  674. }
  675. fields := ` * `
  676. if len(fieldArr) > 0 {
  677. fields = strings.Join(fieldArr, ",")
  678. }
  679. o := orm.NewOrmUsingDB("rddp")
  680. sql := `SELECT ` + fields + ` FROM english_report WHERE id IN (` + utils.GetOrmInReplace(listLen) + `)`
  681. _, err = o.Raw(sql, reportIds).QueryRows(&list)
  682. return
  683. }
  684. // MarkEditEnReport 标记编辑英文研报的请求数据
  685. type MarkEditEnReport struct {
  686. ReportId int `description:"研报id"`
  687. Status int `description:"标记状态,1:编辑中,2:编辑完成"`
  688. }
  689. type EnglishClassifyNameParentName struct {
  690. Id int `description:"分类ID"`
  691. ClassifyName string `description:"分类名称"`
  692. Sort int `description:"排序"`
  693. ParentId int `description:"父级分类id"`
  694. CreateTime time.Time `description:"创建时间"`
  695. ModifyTime time.Time `description:"修改时间"`
  696. ClassifyLabel string `description:"分类标签"`
  697. ShowType int `description:"展示类型:1-列表 2-专栏"`
  698. IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  699. ParentClassifyName string `description:"父级分类名称"`
  700. }
  701. func GetEnglishClassifyByClassifyNameAndParentName(parentClassiyName, classifyName string) (item EnglishClassifyNameParentName, err error) {
  702. o := orm.NewOrmUsingDB("rddp")
  703. 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= ?"
  704. err = o.Raw(sql, parentClassiyName, classifyName).QueryRow(&item)
  705. return
  706. }
  707. type RSClassifyList []*EnglishClassifyList
  708. func (m RSClassifyList) Len() int {
  709. return len(m)
  710. }
  711. func (m RSClassifyList) Less(i, j int) bool {
  712. return m[i].Sort < m[j].Sort
  713. }
  714. func (m RSClassifyList) Swap(i, j int) {
  715. m[i], m[j] = m[j], m[i]
  716. }
  717. type RSChildClassifyList []*EnglishClassifyList
  718. func (m RSChildClassifyList) Len() int {
  719. return len(m)
  720. }
  721. func (m RSChildClassifyList) Less(i, j int) bool {
  722. return m[i].Sort < m[j].Sort
  723. }
  724. func (m RSChildClassifyList) Swap(i, j int) {
  725. m[i], m[j] = m[j], m[i]
  726. }
  727. // GetEnglishClassifyByClassifyNameParentId 获取英文分类
  728. func GetEnglishClassifyByClassifyNameParentId(classifyName string, parentId int) (item *Classify, err error) {
  729. o := orm.NewOrmUsingDB("rddp")
  730. sql := ` SELECT * FROM english_classify where classify_name = ? and parent_id = ? `
  731. err = o.Raw(sql, classifyName, parentId).QueryRow(&item)
  732. return
  733. }
  734. type EnglishClassifyFullName struct {
  735. Id int `description:"分类ID"`
  736. ParentId int `description:"父级分类id"`
  737. RootId int `description:"一级分类ID"`
  738. RootName string `description:"一级分类名"`
  739. ParentName string `description:"二级分类名"`
  740. ClassifyName string `description:"分类名称"`
  741. }
  742. // GetEnglishClassifyFullNameByIds 获取英文分类名一级/二级/三级
  743. func GetEnglishClassifyFullNameByIds(classifyIds []int) (list []*EnglishClassifyFullName, err error) {
  744. o := orm.NewOrmUsingDB("rddp")
  745. sql := ` SELECT
  746. a.id,
  747. a.parent_id,
  748. a.root_id,
  749. a.classify_name,
  750. b.classify_name AS root_name,
  751. c.classify_name AS parent_name
  752. FROM
  753. english_classify a
  754. LEFT JOIN english_classify b ON a.root_id = b.id
  755. LEFT JOIN english_classify c ON a.parent_id = c.id
  756. where a.id IN (` + utils.GetOrmInReplace(len(classifyIds)) + `)`
  757. _, err = o.Raw(sql, classifyIds).QueryRows(&list)
  758. return
  759. }
  760. func (m *EnglishReport) GetItemById(id int) (item *EnglishReport, err error) {
  761. o := orm.NewOrmUsingDB("rddp")
  762. sql := `SELECT * FROM english_report WHERE id = ? LIMIT 1`
  763. err = o.Raw(sql, id).QueryRow(&item)
  764. return
  765. }
  766. // GetEnglishClassifies 获取所有英文分类
  767. func GetEnglishClassifies() (list []*EnglishClassify, err error) {
  768. o := orm.NewOrmUsingDB("rddp")
  769. sql := ` SELECT * FROM english_classify `
  770. _, err = o.Raw(sql).QueryRows(&list)
  771. return
  772. }
  773. // GetEnglishReportStateCount 获取指定状态的报告数量
  774. func GetEnglishReportStateCount(state int) (count int, err error) {
  775. o := orm.NewOrmUsingDB("rddp")
  776. sql := `SELECT COUNT(1) AS count FROM english_report WHERE state = ?`
  777. err = o.Raw(sql, state).QueryRow(&count)
  778. return
  779. }
  780. // UpdateEnglishReportsStateByCond 批量更新报告状态
  781. func UpdateEnglishReportsStateByCond(classifyFirstId, classifySecondId, oldState, newState int) (err error) {
  782. o := orm.NewOrmUsingDB("rddp")
  783. cond := ``
  784. if classifyFirstId > 0 {
  785. cond += fmt.Sprintf(` AND classify_id_first = %d`, classifyFirstId)
  786. }
  787. if classifySecondId > 0 {
  788. cond += fmt.Sprintf(` AND classify_id_second = %d`, classifySecondId)
  789. }
  790. sql := fmt.Sprintf(`UPDATE english_report SET state = ?, pre_publish_time = NULL WHERE state = ? %s`, cond)
  791. _, err = o.Raw(sql, newState, oldState).Exec()
  792. return
  793. }
  794. // UpdateEnglishReportsStateBySecondIds 批量更新二级分类报告状态
  795. func UpdateEnglishReportsStateBySecondIds(oldState, newState int, secondIds []int) (err error) {
  796. if len(secondIds) <= 0 {
  797. return
  798. }
  799. o := orm.NewOrmUsingDB("rddp")
  800. // (有审批流的)未发布->待提交
  801. sql := fmt.Sprintf(`UPDATE english_report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  802. _, err = o.Raw(sql, newState, oldState, secondIds).Exec()
  803. if err != nil {
  804. return
  805. }
  806. // (无审批流的)待提交->未发布
  807. 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)))
  808. _, err = o.Raw(sql, oldState, newState, secondIds).Exec()
  809. return
  810. }