english_report.go 33 KB

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