english_report.go 43 KB

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