english_report.go 40 KB

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