roadshow_essence.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hz_crm_api/controllers"
  6. "hongze/hz_crm_api/models"
  7. "hongze/hz_crm_api/models/cygx"
  8. "hongze/hz_crm_api/services"
  9. cygxService "hongze/hz_crm_api/services/cygx"
  10. "hongze/hz_crm_api/utils"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. // 路演精华
  16. type RoadshowEssenceController struct {
  17. controllers.BaseAuthController
  18. }
  19. // @Title 路演精华内容的保存与发布
  20. // @Description 研究汇总内容的保存与发布接口
  21. // @Param request body cygx.AddArticleRoadshowEssenceRep true "type json string"
  22. // @Success 200 操作成功
  23. // @router /roadshowEssence/PreserveAndPublish [post]
  24. func (this *RoadshowEssenceController) PreserveAndPublish() {
  25. br := new(models.BaseResponse).Init()
  26. defer func() {
  27. this.Data["json"] = br
  28. this.ServeJSON()
  29. }()
  30. AdminUser := this.SysUser
  31. if AdminUser == nil {
  32. br.Msg = "请登录"
  33. br.ErrMsg = "请登录,用户信息为空"
  34. br.Ret = 408
  35. return
  36. }
  37. var req cygx.AddArticleRoadshowEssenceRep
  38. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  39. if err != nil {
  40. br.Msg = "参数解析异常!"
  41. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  42. return
  43. }
  44. var pars []interface{}
  45. var condition string
  46. chartPermissionId := req.ChartPermissionId
  47. industrialManagementIdStr := req.IndustrialManagementId
  48. industrialSubjectIdStr := req.IndustrialSubjectIdStr
  49. condition = ` AND chart_permission_id = ` + strconv.Itoa(chartPermissionId)
  50. total, _ := cygx.GetChartPermissionCount(condition, pars)
  51. if total < 1 {
  52. br.Msg = "分类ID不存在,请重新填写"
  53. br.ErrMsg = "分类ID不存在,请重新填写:" + strconv.Itoa(req.ChartPermissionId)
  54. return
  55. }
  56. industrialStrList := strings.Split(industrialManagementIdStr, ",")
  57. for _, v := range industrialStrList {
  58. condition = `AND industrial_management_id = ` + v
  59. totalIndustrialManagement, _ := cygx.GetIndustrialManagementCount(condition, pars)
  60. if totalIndustrialManagement < 1 {
  61. br.Msg = "操作失败,对应产业不存在"
  62. br.ErrMsg = "操作失败,产业不存在IndustrialManagementId:" + v
  63. return
  64. }
  65. }
  66. if industrialSubjectIdStr != "0" && industrialSubjectIdStr != "" {
  67. strList := strings.Split(industrialSubjectIdStr, ",")
  68. for _, v := range strList {
  69. condition = `AND industrial_subject_id = ` + v + ` AND industrial_management_id IN ( ` + industrialManagementIdStr + `)`
  70. totalIndustrialSubject, _ := cygx.GetIndustrialSubjectCount(condition, pars)
  71. if totalIndustrialSubject < 1 {
  72. br.Msg = "操作失败"
  73. br.ErrMsg = "操作失败,标的不存在IndustrialSubjectId:" + v
  74. return
  75. }
  76. }
  77. }
  78. charInfo, errCategory := cygx.GetCategoryInfoById(chartPermissionId)
  79. if errCategory != nil {
  80. br.Msg = "获取品种信息失败"
  81. br.ErrMsg = "获取品种信息失败,Err:" + errCategory.Error()
  82. return
  83. }
  84. var articleId int
  85. maxArticleIdArticleInfo, errMax := cygx.GetMaxArticleIdInfo()
  86. if errMax != nil {
  87. br.Msg = "发布失败"
  88. br.ErrMsg = "发布失败,Err:" + errMax.Error()
  89. return
  90. }
  91. if maxArticleIdArticleInfo.ArticleId < utils.SummaryArticleId {
  92. articleId = utils.SummaryArticleId
  93. } else {
  94. articleId = maxArticleIdArticleInfo.ArticleId + 1
  95. }
  96. detailMap, err := cygx.GetMatchTypeNameByPermissionId(chartPermissionId)
  97. if err != nil {
  98. br.Msg = "保存失败"
  99. br.ErrMsg = "归类配置信息,Err:" + err.Error()
  100. return
  101. }
  102. item := new(cygx.CygxArticle)
  103. item.AdminId = AdminUser.AdminId
  104. item.AdminName = AdminUser.RealName
  105. item.Title = req.Title
  106. item.SellerAndMobile = req.SellerAndMobile
  107. item.PublishDate = utils.StrTimeToTime(req.PublishDate + " 00:00:00")
  108. item.ChartPermissionIds = strconv.Itoa(req.ChartPermissionId)
  109. item.Abstract = req.Abstract
  110. item.Body = cygxService.GetRichtext(req.Body)
  111. item.BodyText, _ = cygx.GetReportContentTextSub(req.Body)
  112. item.ReportLink = req.ReportLink
  113. if item.ReportLink != "" {
  114. articleIdLink, err := cygxService.GetReportLinkToArticleid(item.ReportLink)
  115. if err != nil {
  116. br.Msg = "操作失败"
  117. br.ErrMsg = "解析报告链接ID失败,Err:" + err.Error()
  118. return
  119. }
  120. item.LinkArticleId = articleIdLink
  121. }
  122. item.IsReport = 1
  123. item.Source = 1
  124. item.ReportType = 2
  125. item.ArticleIdMd5 = utils.MD5(strconv.Itoa(articleId))
  126. item.Department = "弘则产品组"
  127. item.ArticleType = "lyjh"
  128. item.IsClass = 1
  129. item.CreateDate = time.Now()
  130. item.UpdateFrequency = "unknow"
  131. item.CategoryName = charInfo.PermissionName
  132. item.CategoryId = detailMap.CategoryId
  133. item.SubCategoryName = "路演精华"
  134. if req.DoType == 1 {
  135. item.HavePublish = 1
  136. item.PublishStatus = 1
  137. }
  138. if req.ArticleId == 0 {
  139. if req.DoType == 1 {
  140. condition = ` AND article_type = 'lyjh' AND art.have_publish = 1 `
  141. total, err := cygx.GetCygxArticleCount(condition, pars)
  142. if err != nil {
  143. br.Msg = "添加失败"
  144. br.ErrMsg = "新增获取期数信息失败,Err:" + err.Error()
  145. return
  146. }
  147. item.Periods = strconv.Itoa(total + 1)
  148. }
  149. item.ArticleId = articleId
  150. _, err := cygx.AddArticleRoadshowEssence(item, industrialManagementIdStr, industrialSubjectIdStr)
  151. if err != nil {
  152. br.Msg = "添加失败"
  153. br.ErrMsg = "添加失败,Err:" + err.Error()
  154. return
  155. }
  156. } else {
  157. articleInfo, errInfo := cygx.GetArticleIdInfoByArticleId(req.ArticleId)
  158. if errInfo != nil {
  159. br.Msg = "报告不存在"
  160. br.ErrMsg = "发布失败,Err:" + errInfo.Error()
  161. return
  162. }
  163. if req.DoType == 1 {
  164. condition = ` AND article_type = 'lyjh' AND art.have_publish = 1 `
  165. total, err := cygx.GetCygxArticleCount(condition, pars)
  166. if err != nil {
  167. br.Msg = "添加失败"
  168. br.ErrMsg = "修改获取期数信息失败,Err:" + err.Error()
  169. return
  170. }
  171. item.Periods = strconv.Itoa(total + 1)
  172. } else {
  173. item.Periods = articleInfo.Periods
  174. item.HavePublish = articleInfo.HavePublish
  175. }
  176. if articleInfo.HavePublish == 1 {
  177. item.Periods = articleInfo.Periods
  178. }
  179. if item.PublishStatus == 0 {
  180. item.PublishStatus = articleInfo.PublishStatus
  181. item.AdminId = articleInfo.AdminId
  182. item.AdminName = articleInfo.AdminName
  183. }
  184. item.ArticleId = req.ArticleId
  185. item.SummaryManageId = articleInfo.SummaryManageId
  186. err = cygx.UpdateArticleRoadshowEssence(item, industrialManagementIdStr, industrialSubjectIdStr)
  187. if err != nil {
  188. br.Msg = "添加失败"
  189. br.ErrMsg = "获取期数信息失败,Err:" + err.Error()
  190. return
  191. }
  192. }
  193. //同步数据到最新表
  194. if req.ArticleId == 0 {
  195. if item.PublishStatus == 1 {
  196. go cygxService.UpdateResourceData(item.ArticleId, "article", "add", time.Now().Format(utils.FormatDateTime))
  197. }
  198. } else {
  199. if item.PublishStatus == 1 {
  200. go cygxService.UpdateResourceData(item.ArticleId, "article", "update", time.Now().Format(utils.FormatDateTime))
  201. }
  202. if req.DoType == 1 {
  203. go cygxService.UpdateResourceData(item.ArticleId, "article", "add", time.Now().Format(utils.FormatDateTime))
  204. }
  205. }
  206. if req.DoType == 1 {
  207. go cygxService.SendWxMsgWithroadshowEssence(articleId)
  208. }
  209. //生成音频文件
  210. var content string
  211. content = "摘要" + item.Abstract + item.Body
  212. go services.CreateVideoWhithContent(item.ArticleId, item.Title, content, "cygx_article")
  213. br.Ret = 200
  214. br.Success = true
  215. br.Msg = "操作成功"
  216. br.IsAddLog = true
  217. }
  218. // @Title 删除路演精华内容
  219. // @Description 删除路演精华内容接口
  220. // @Param request body cygx.ResearchSummaryId true "type json string"
  221. // @Success Ret=200
  222. // @router /roadshowEssence/delete [post]
  223. func (this *RoadshowEssenceController) Delete() {
  224. br := new(models.BaseResponse).Init()
  225. defer func() {
  226. this.Data["json"] = br
  227. this.ServeJSON()
  228. }()
  229. AdminUser := this.SysUser
  230. if AdminUser == nil {
  231. br.Msg = "请登录"
  232. br.ErrMsg = "请登录,SysUser Is Empty"
  233. br.Ret = 408
  234. return
  235. }
  236. var req cygx.ResearchSummaryId
  237. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  238. if err != nil {
  239. br.Msg = "参数解析异常!"
  240. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  241. return
  242. }
  243. articleId := req.ArticleId
  244. articleInfo, errInfo := cygx.GetArticleIdInfoByArticleId(articleId)
  245. if errInfo != nil {
  246. br.Msg = "删除失败"
  247. br.ErrMsg = "删除失败,Err:" + errInfo.Error()
  248. return
  249. }
  250. if articleInfo.HavePublish == 1 {
  251. br.Msg = "删除失败"
  252. br.ErrMsg = "已经存在期数无法删除"
  253. return
  254. }
  255. err = cygx.DeleteArticleReport(articleId)
  256. if err != nil {
  257. br.Msg = "删除信息失败"
  258. br.ErrMsg = "删除信息失败,Err:" + err.Error()
  259. return
  260. }
  261. br.Ret = 200
  262. br.Success = true
  263. br.Msg = "已删除"
  264. br.IsAddLog = true
  265. }
  266. // @Title 路演精华内容详情
  267. // @Description 路演精华内容详情接口
  268. // @Param ArticleId query int true "报告Id"
  269. // @Success Ret=200 {object} cygx.ArticleRoadshowEssenceDetail
  270. // @router /roadshowEssence/detail [get]
  271. func (this *RoadshowEssenceController) Detail() {
  272. br := new(models.BaseResponse).Init()
  273. defer func() {
  274. this.Data["json"] = br
  275. this.ServeJSON()
  276. }()
  277. AdminUser := this.SysUser
  278. if AdminUser == nil {
  279. br.Msg = "请登录"
  280. br.ErrMsg = "请登录,用户信息为空"
  281. br.Ret = 408
  282. return
  283. }
  284. articleId, _ := this.GetInt("ArticleId")
  285. detail, err := cygx.GetArticleRoadshowEssenceDetail(articleId)
  286. if err != nil {
  287. br.Msg = "内容不存在"
  288. br.ErrMsg = "操作失败,Err:" + err.Error()
  289. return
  290. }
  291. detail.PublishDate = utils.StrTimeToTime(detail.PublishDate).Format("2006-01-02")
  292. br.Ret = 200
  293. br.Success = true
  294. br.Msg = "获取成功"
  295. br.Data = detail
  296. }
  297. // @Title 路演精华列表
  298. // @Description 获取路演精华列表接口
  299. // @Param PageSize query int true "每页数据条数"
  300. // @Param CurrentIndex query int true "当前页页码,从1开始"
  301. // @Param PublishStatus query int false "发布状态 ,1未发布,1已发布,传2查询所有"
  302. // @Param StartDate query string false "开始时间 ,列如2021-03-06 "
  303. // @Param EndDate query string false "结束时间,列如2021-03-06 "
  304. // @Param KeyWord query string false "搜索关键词"
  305. // @Param ChartPermissionId query string false "行业id"
  306. // @Success 200 {object} cygx.CygxResearchSummaryListRep
  307. // @router /roadshowEssence/list [get]
  308. func (this *RoadshowEssenceController) List() {
  309. br := new(models.BaseResponse).Init()
  310. defer func() {
  311. this.Data["json"] = br
  312. this.ServeJSON()
  313. }()
  314. AdminUser := this.SysUser
  315. if AdminUser == nil {
  316. br.Msg = "请登录"
  317. br.ErrMsg = "请登录,SysUser Is Empty"
  318. return
  319. }
  320. pageSize, _ := this.GetInt("PageSize")
  321. currentIndex, _ := this.GetInt("CurrentIndex")
  322. publishStatus, _ := this.GetInt("PublishStatus")
  323. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  324. startDate := this.GetString("StartDate")
  325. endDate := this.GetString("EndDate")
  326. keyWord := this.GetString("KeyWord")
  327. var startSize int
  328. if pageSize <= 0 {
  329. pageSize = utils.PageSize20
  330. }
  331. if currentIndex <= 0 {
  332. currentIndex = 1
  333. }
  334. startSize = utils.StartIndex(currentIndex, pageSize)
  335. var condition string
  336. var pars []interface{}
  337. condition += ` AND art.article_type = 'lyjh' `
  338. if startDate != "" {
  339. condition += ` AND art.publish_date >= ` + "'" + startDate + " 00:00:00'"
  340. }
  341. if endDate != "" {
  342. condition += ` AND art.publish_date <= ` + "'" + endDate + " 23:59:59'"
  343. }
  344. if publishStatus == 0 || publishStatus == 1 {
  345. condition += ` AND art.publish_status = ` + strconv.Itoa(publishStatus)
  346. }
  347. if keyWord != "" {
  348. condition += ` AND (art.title LIKE '%` + keyWord + `%' ) `
  349. }
  350. if chartPermissionId > 0 {
  351. condition += ` AND art.chart_permission_ids = ` + strconv.Itoa(chartPermissionId)
  352. }
  353. total, err := cygx.GetCygxArticleCount(condition, pars)
  354. if err != nil {
  355. br.Msg = "获取失败"
  356. br.ErrMsg = "获取失败,Err:" + err.Error()
  357. return
  358. }
  359. condition += ` ORDER BY art.publish_date DESC `
  360. list, err := cygx.GetArticleRoadshowEssenceList(condition, pars, startSize, pageSize)
  361. if err != nil {
  362. br.Msg = "获取失败"
  363. br.ErrMsg = "获取失败,Err:" + err.Error()
  364. return
  365. }
  366. for k, v := range list {
  367. if v.Periods != "" && v.Periods != "0" {
  368. list[k].Periods = "第" + v.Periods + "期"
  369. } else {
  370. list[k].Periods = ""
  371. }
  372. list[k].PublishDate = utils.StrTimeToTime(v.PublishDate).Format("2006-01-02")
  373. }
  374. page := paging.GetPaging(currentIndex, pageSize, total)
  375. resp := new(cygx.CygxResearchSummaryListRep)
  376. resp.List = list
  377. resp.Paging = page
  378. br.Ret = 200
  379. br.Success = true
  380. br.Msg = "获取成功"
  381. br.Data = resp
  382. }
  383. // @Title 路演精华的发布与取消发布
  384. // @Description 路演精华的发布与取消发布接口
  385. // @Param request body cygx.ResearchSummaryId true "type json string"
  386. // @Success 200 操作成功
  387. // @router /roadshowEssence/PublishAndCancel [post]
  388. func (this *RoadshowEssenceController) PublishAndCancel() {
  389. br := new(models.BaseResponse).Init()
  390. defer func() {
  391. this.Data["json"] = br
  392. this.ServeJSON()
  393. }()
  394. AdminUser := this.SysUser
  395. if AdminUser == nil {
  396. br.Msg = "请登录"
  397. br.ErrMsg = "请登录,用户信息为空"
  398. br.Ret = 408
  399. return
  400. }
  401. var req cygx.ResearchSummaryId
  402. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  403. if err != nil {
  404. br.Msg = "参数解析异常!"
  405. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  406. return
  407. }
  408. articleId := req.ArticleId
  409. detail, err := cygx.GetArticleIdInfoByArticleId(articleId)
  410. if err != nil {
  411. br.Msg = "内容不存在"
  412. br.ErrMsg = "操作失败,Err:" + err.Error()
  413. return
  414. }
  415. item := new(cygx.CygxResearchSummaryRep)
  416. item.ArticleId = articleId
  417. if detail.PublishStatus == 0 {
  418. item.PublishStatus = 1
  419. item.AdminId = AdminUser.AdminId
  420. item.AdminName = AdminUser.RealName
  421. go cygxService.SendWxMsgWithroadshowEssence(articleId)
  422. } else {
  423. item.AdminId = detail.AdminId
  424. item.AdminName = detail.AdminName
  425. item.PublishStatus = 0
  426. }
  427. if detail.HavePublish == 0 {
  428. var pars []interface{}
  429. var condition string
  430. condition = ` AND article_type = 'lyjh' AND art.have_publish = 1 `
  431. total, err := cygx.GetCygxArticleCount(condition, pars)
  432. if err != nil {
  433. br.Msg = "获取失败"
  434. br.ErrMsg = "获取失败,Err:" + err.Error()
  435. return
  436. }
  437. item.Periods = strconv.Itoa(total + 1)
  438. } else {
  439. item.Periods = detail.Periods
  440. }
  441. err = cygx.RoadshowEssencePublishAndCancel(item)
  442. if err != nil {
  443. br.Msg = "操作失败"
  444. br.ErrMsg = "操作失败,Err:" + err.Error()
  445. return
  446. }
  447. br.Ret = 200
  448. br.Success = true
  449. br.Msg = "操作成功"
  450. br.IsAddLog = true
  451. }
  452. // @Title 文章的见范围修改
  453. // @Description 文章的见范围修改接口
  454. // @Param request body cygx.SummaryManageIdRep true "type json string"
  455. // @Success 200 操作成功
  456. // @router /roadshowEssence/visibleRange [post]
  457. func (this *RoadshowEssenceController) VisibleRange() {
  458. br := new(models.BaseResponse).Init()
  459. defer func() {
  460. this.Data["json"] = br
  461. this.ServeJSON()
  462. }()
  463. AdminUser := this.SysUser
  464. if AdminUser == nil {
  465. br.Msg = "请登录"
  466. br.ErrMsg = "请登录,用户信息为空"
  467. br.Ret = 408
  468. return
  469. }
  470. var req cygx.SummaryManageIdRep
  471. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  472. if err != nil {
  473. br.Msg = "参数解析异常!"
  474. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  475. return
  476. }
  477. articleId := req.ArticleId
  478. item := new(cygx.CygxArticle)
  479. articleInfo, errInfo := cygx.GetArticleInfoOtherByArticleId(articleId)
  480. if articleInfo == nil {
  481. br.Msg = "操作失败"
  482. br.ErrMsg = "纪要ID错误"
  483. return
  484. }
  485. if errInfo != nil {
  486. br.Msg = "操作失败"
  487. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  488. return
  489. }
  490. item.ArticleId = articleId
  491. item.Title = articleInfo.Title
  492. item.BodyText = articleInfo.BodyText
  493. item.Body = articleInfo.Body
  494. item.PublishDate = articleInfo.PublishDate
  495. item.ExpertBackground = articleInfo.ExpertBackground
  496. item.CategoryId = articleInfo.CategoryId
  497. if articleInfo.VisibleRange == 0 {
  498. item.VisibleRange = 1
  499. item.AdminId = AdminUser.AdminId
  500. item.AdminName = AdminUser.RealName
  501. go cygxService.SendWxMsgWithroadshowEssence(articleId)
  502. } else {
  503. item.AdminId = articleInfo.AdminId
  504. item.AdminName = articleInfo.AdminName
  505. item.PublishStatus = 0
  506. }
  507. err = cygx.ArticleVisibleRange(item)
  508. if err != nil {
  509. br.Msg = "操作失败"
  510. br.ErrMsg = "操作失败,Err:" + err.Error()
  511. return
  512. }
  513. br.Ret = 200
  514. br.Success = true
  515. br.Msg = "操作成功"
  516. br.IsAddLog = true
  517. }