english_report.go 39 KB

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