english_report.go 41 KB

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