report_selection.go 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "github.com/tealeg/xlsx"
  7. "hongze/hz_crm_api/controllers"
  8. "hongze/hz_crm_api/models"
  9. "hongze/hz_crm_api/models/cygx"
  10. "hongze/hz_crm_api/models/system"
  11. "hongze/hz_crm_api/services"
  12. cygxService "hongze/hz_crm_api/services/cygx"
  13. "hongze/hz_crm_api/utils"
  14. "os"
  15. "path/filepath"
  16. "strconv"
  17. "strings"
  18. "time"
  19. )
  20. // 报告精选
  21. type ReportSelectionController struct {
  22. controllers.BaseAuthController
  23. }
  24. // @Title 报告精选内容的保存与发布
  25. // @Description 报告精选内容的保存与发布接口
  26. // @Param request body cygx.AddCygxReportSelection true "type json string"
  27. // @Success 200 操作成功
  28. // @router /reportSelection/PreserveAndPublish [post]
  29. func (this *ReportSelectionController) PreserveAndPublish() {
  30. br := new(models.BaseResponse).Init()
  31. defer func() {
  32. this.Data["json"] = br
  33. this.ServeJSON()
  34. }()
  35. AdminUser := this.SysUser
  36. if AdminUser == nil {
  37. br.Msg = "请登录"
  38. br.ErrMsg = "请登录,用户信息为空"
  39. br.Ret = 408
  40. return
  41. }
  42. var req cygx.AddCygxReportSelection
  43. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  44. if err != nil {
  45. br.Msg = "参数解析异常!"
  46. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  47. return
  48. }
  49. if req.AddType != "1" && req.AddType != "2" {
  50. br.Msg = "请选择正确的添加方式!"
  51. return
  52. }
  53. if req.AddType == "2" && req.InheritPeriods == "" {
  54. br.Msg = "请选择继承第几期!"
  55. return
  56. }
  57. list := req.List
  58. listChartSummary := req.ListChartSummary
  59. reportLink := req.ReportLink
  60. if len(list) < 1 {
  61. br.Msg = "产业资源内容不可为空!"
  62. return
  63. }
  64. if len(listChartSummary) < 1 {
  65. br.Msg = "行业核心逻辑汇总不能为空!"
  66. return
  67. }
  68. if reportLink == "" {
  69. br.Msg = "详细报告链接,不能为空!"
  70. return
  71. }
  72. articleIdLink, err := cygxService.GetReportLinkToArticleid(reportLink)
  73. if err != nil {
  74. br.Msg = "操作失败"
  75. br.ErrMsg = "解析报告链接ID失败,Err:" + err.Error()
  76. return
  77. }
  78. if articleIdLink == 0 {
  79. br.Msg = "详细报告链接格式错误"
  80. br.ErrMsg = "解析报告链接ID失败,报告链接:" + reportLink
  81. return
  82. }
  83. var items []*cygx.CygxReportSelectionLog
  84. var itemsChart []*cygx.CygxReportSelectionChartLog
  85. condition := ` AND have_publish = 1 `
  86. var pars []interface{}
  87. total, err := cygx.GetCygxReportSelection(condition, pars)
  88. if err != nil {
  89. br.Msg = "获取失败"
  90. br.ErrMsg = "获取失败,Err:" + err.Error()
  91. return
  92. }
  93. itemCrs := new(cygx.CygxReportSelection)
  94. itemCrs.AdminId = AdminUser.AdminId
  95. itemCrs.AdminName = AdminUser.RealName
  96. itemCrs.Title = req.Title
  97. itemCrs.Department = req.Department
  98. itemCrs.AddType = req.AddType
  99. itemCrs.PublishStatus = req.DoType
  100. if req.DoType == 1 {
  101. itemCrs.HavePublish = 1
  102. itemCrs.Periods = strconv.Itoa(total + 1)
  103. }
  104. itemCrs.PublishDate = utils.StrTimeToTime(req.PublishDate + " 00:00:00")
  105. itemCrs.CreateTime = time.Now()
  106. itemCrs.LastUpdatedTime = time.Now()
  107. itemCrs.InheritPeriods = req.InheritPeriods
  108. itemCrs.ProductDescription = req.ProductDescription
  109. itemCrs.UpdateDescription = req.UpdateDescription
  110. itemCrs.ReportLink = req.ReportLink
  111. itemCrs.FocusOn = cygxService.GetRichtext(req.FocusOn)
  112. itemCrs.MarketStrategy = cygxService.GetRichtext(req.MarketStrategy)
  113. for _, v := range list {
  114. item := new(cygx.CygxReportSelectionLog)
  115. item.ChartPermissionId = v.ChartPermissionId
  116. item.CreateTime = time.Now()
  117. item.Body = cygxService.GetRichtext(v.Body)
  118. item.IndustrialSubjectId = v.IndustrialSubjectId
  119. item.SubjectName = v.IndustrialSubjectName
  120. item.IndustrialManagementId = v.IndustrialManagementId
  121. item.IndustrialManagementNames = v.IndustrialManagementName
  122. if v.IndustrialManagementNames != "" {
  123. item.IndustrialManagementNames = v.IndustrialManagementNames
  124. }
  125. item.OverviewArticleId = v.OverviewArticleId
  126. item.IsNew = v.IsNew
  127. item.IsShowOverviewArticle = v.IsShowOverviewArticle
  128. if len(v.CompanyLabel) > 0 {
  129. item.CompanyLabel = cygxService.ArticleComPanyLabelToStr(v.CompanyLabel)
  130. }
  131. items = append(items, item)
  132. }
  133. for _, v := range listChartSummary {
  134. item := new(cygx.CygxReportSelectionChartLog)
  135. item.ChartPermissionId = v.ChartPermissionId
  136. item.CreateTime = time.Now()
  137. item.Body = cygxService.GetRichtext(v.BodyChartSummary)
  138. itemsChart = append(itemsChart, item)
  139. }
  140. if req.ArticleId == 0 {
  141. articleId, err := cygx.AddCygxReportSelectionOrm(itemCrs, items, itemsChart)
  142. if err != nil {
  143. br.Msg = "操作失败"
  144. br.ErrMsg = "发布失败,Err:" + err.Error()
  145. return
  146. }
  147. req.ArticleId = int(articleId)
  148. } else {
  149. detail, err := cygx.GetCygxReportSelectionInfoById(req.ArticleId)
  150. if err != nil {
  151. br.Msg = "内容不存在"
  152. br.ErrMsg = "操作失败,Err:" + err.Error()
  153. return
  154. }
  155. if itemCrs.PublishStatus == 0 {
  156. itemCrs.PublishStatus = detail.PublishStatus
  157. itemCrs.AdminId = detail.AdminId
  158. itemCrs.AdminName = detail.AdminName
  159. }
  160. if detail.HavePublish == 1 {
  161. itemCrs.Periods = detail.Periods
  162. itemCrs.HavePublish = detail.HavePublish
  163. }
  164. itemCrs.ArticleId = req.ArticleId
  165. _, err = cygx.UpdateCygxReportSelectionOrm(itemCrs, items, itemsChart)
  166. if err != nil {
  167. br.Msg = "操作失败"
  168. br.ErrMsg = "发布失败,Err:" + err.Error()
  169. return
  170. }
  171. }
  172. //if req.DoType == 1 {
  173. //cygxService.DoThisWeekLastWeekWxTemplateMsg(itemCrs.Title, itemCrs.PublishDate.Format(utils.FormatDateTime), itemCrs.ProductDescription, req.ArticleId, 1)
  174. //}
  175. //生成音频文件
  176. //articleId := req.ArticleId
  177. //existMap := make(map[int]int)
  178. //var content string
  179. //content = "产品说明" + req.ProductDescription + "变更说明" + req.UpdateDescription + "近期重点关注方向" + req.FocusOn
  180. //listLog, err := cygx.GetReportSelectionlogListAll(articleId)
  181. //if err != nil {
  182. // br.Msg = "获取失败"
  183. // br.ErrMsg = "获取失败,Err:" + err.Error()
  184. // return
  185. //}
  186. //for _, v := range listLog {
  187. // if existMap[v.ChartPermissionId] == 0 {
  188. // content += v.PermissionName + "领域深度调研和报告"
  189. // listSonLog, err := cygx.GetReportSelectionlogSonListAll(articleId, v.ChartPermissionId)
  190. // if err != nil && err.Error() != utils.ErrNoRow() {
  191. // br.Msg = "获取信息失败"
  192. // br.ErrMsg = "获取信息失败,Err:" + err.Error()
  193. // return
  194. // }
  195. // if len(listSonLog) > 0 {
  196. // for _, v2 := range listSonLog {
  197. // content += v2.SubjectName + v2.Body
  198. // }
  199. // }
  200. // }
  201. // existMap[v.ChartPermissionId] = v.ChartPermissionId 0
  202. //}
  203. go cygxService.UpdateReportSelectionResourceData(req.ArticleId) //首页最新页面数据逻辑处理 V11.1.1
  204. br.Ret = 200
  205. br.Success = true
  206. br.Msg = "操作成功"
  207. br.IsAddLog = true
  208. }
  209. // @Title 删除报告精选内容
  210. // @Description 删除报告精选内容接口
  211. // @Param request body cygx.ResearchSummaryId true "type json string"
  212. // @Success Ret=200
  213. // @router /reportSelection/delete [post]
  214. func (this *ReportSelectionController) Delete() {
  215. br := new(models.BaseResponse).Init()
  216. defer func() {
  217. this.Data["json"] = br
  218. this.ServeJSON()
  219. }()
  220. AdminUser := this.SysUser
  221. if AdminUser == nil {
  222. br.Msg = "请登录"
  223. br.ErrMsg = "请登录,SysUser Is Empty"
  224. br.Ret = 408
  225. return
  226. }
  227. var req cygx.ResearchSummaryId
  228. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  229. if err != nil {
  230. br.Msg = "参数解析异常!"
  231. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  232. return
  233. }
  234. articleId := req.ArticleId
  235. detail, err := cygx.GetCygxReportSelectionInfoById(articleId)
  236. if err != nil {
  237. br.Msg = "内容不存在"
  238. br.ErrMsg = "操作失败,Err:" + err.Error()
  239. return
  240. }
  241. if detail.HavePublish != 0 {
  242. br.Msg = "删除失败"
  243. br.ErrMsg = "已经存在期数无法删除"
  244. return
  245. }
  246. err = cygx.DeleteCygxReportSelection(articleId)
  247. if err != nil {
  248. br.Msg = "删除信息失败"
  249. br.ErrMsg = "删除信息失败,Err:" + err.Error()
  250. return
  251. }
  252. br.Ret = 200
  253. br.Success = true
  254. br.Msg = "已删除"
  255. br.IsAddLog = true
  256. }
  257. // @Title 报告精选内容详情
  258. // @Description 报告精选内容详情接口
  259. // @Param ArticleId query int true "报告Id"
  260. // @Param Periods query string true "期数Id"
  261. // @Success Ret=200 {object} cygx.DetailCygxReportSelectionRep
  262. // @router /reportSelection/detail [get]
  263. func (this *ReportSelectionController) Detail() {
  264. br := new(models.BaseResponse).Init()
  265. defer func() {
  266. this.Data["json"] = br
  267. this.ServeJSON()
  268. }()
  269. AdminUser := this.SysUser
  270. if AdminUser == nil {
  271. br.Msg = "请登录"
  272. br.ErrMsg = "请登录,用户信息为空"
  273. br.Ret = 408
  274. return
  275. }
  276. var errArt error
  277. detail := new(cygx.CygxReportSelectionRep)
  278. articleId, _ := this.GetInt("ArticleId")
  279. periods := this.GetString("Periods")
  280. if articleId > 0 && periods == "" {
  281. detail, errArt = cygx.GetCygxReportSelectionInfoById(articleId)
  282. if errArt != nil {
  283. br.Msg = "内容不存在"
  284. br.ErrMsg = "内容不存在,Err:" + errArt.Error()
  285. return
  286. }
  287. } else {
  288. detail, errArt = cygx.GetCygxReportSelectionInfoByPeriods(periods)
  289. if errArt != nil {
  290. br.Msg = "内容不存在"
  291. br.ErrMsg = "内容不存在通过期数获取详情错误,Err:" + errArt.Error() + "期数:" + periods
  292. return
  293. }
  294. }
  295. articleId = detail.ArticleId
  296. resp := new(cygx.DetailCygxReportSelectionRep)
  297. resp.ArticleId = detail.ArticleId
  298. resp.AddType = detail.AddType
  299. resp.InheritPeriods = detail.InheritPeriods
  300. resp.Title = detail.Title
  301. resp.Department = detail.Department
  302. resp.PublishStatus = detail.PublishStatus
  303. resp.PublishDate = utils.StrTimeToTime(detail.PublishDate).Format("2006-01-02")
  304. resp.ProductDescription = detail.ProductDescription
  305. resp.UpdateDescription = detail.UpdateDescription
  306. resp.FocusOn = detail.FocusOn
  307. resp.MarketStrategy = detail.MarketStrategy
  308. resp.ReportLink = detail.ReportLink
  309. if detail.InheritPeriods != "" {
  310. resp.InheritPeriodsName = "第" + detail.InheritPeriods + "期"
  311. }
  312. var condition string
  313. condition = ` AND chart_permission_id IN (19,20,21,22) `
  314. listMore, err := cygx.GetChartPermissionDetail(condition)
  315. var list []*cygx.CygxReportSelectionChart
  316. //排序方式修改
  317. permissionNameList := []cygx.CygxChartPermissionName{}
  318. //获取行业核心逻辑汇总
  319. listChartLog, err := cygx.GetCygxReportSelectionChartLogRepList(articleId)
  320. if err != nil {
  321. br.Msg = "获取失败"
  322. br.ErrMsg = "获取失败,Err:" + err.Error()
  323. return
  324. }
  325. permissionNameMap, err := services.GetPermissionNameMap()
  326. if err != nil {
  327. br.Msg = "获取失败"
  328. br.ErrMsg = "获取失败 GetPermissionNameMap,Err:" + err.Error()
  329. return
  330. }
  331. mapChartLog := make(map[string]string)
  332. for _, v := range listChartLog {
  333. v.ChartPermissionName = permissionNameMap[v.ChartPermissionId]
  334. mapChartLog[v.ChartPermissionName] = v.BodyChartSummary
  335. permissionNameList = append(permissionNameList, cygx.CygxChartPermissionName{v.ChartPermissionName})
  336. }
  337. for _, v := range permissionNameList {
  338. for _, v2 := range listMore {
  339. v2.ChartPermissionName = permissionNameMap[v2.ChartPermissionId]
  340. if v.ChartPermissionName == v2.ChartPermissionName {
  341. item := new(cygx.CygxReportSelectionChart)
  342. item.ChartPermissionName = v2.ChartPermissionName
  343. item.ChartPermissionId = v2.ChartPermissionId
  344. //item.List = make([]string, 0)
  345. list = append(list, item)
  346. }
  347. }
  348. }
  349. //获取关联的文章信息
  350. mapArticle := make(map[int]string)
  351. listSelectionLog, err := cygx.GetReportSelectionlogListAll(articleId)
  352. if err != nil {
  353. br.Msg = "获取失败"
  354. br.ErrMsg = "GetReportSelectionlogListAll,Err:" + err.Error()
  355. return
  356. }
  357. articleStockMap, _ := cygxService.GetArticleStockMap()
  358. var overviewArticleIdArr []int
  359. for _, v := range listSelectionLog {
  360. if v.OverviewArticleId > 0 {
  361. overviewArticleIdArr = append(overviewArticleIdArr, v.OverviewArticleId)
  362. }
  363. }
  364. for _, v := range articleStockMap {
  365. overviewArticleIdArr = append(overviewArticleIdArr, v)
  366. }
  367. lenActivityIds := len(overviewArticleIdArr)
  368. if lenActivityIds > 0 {
  369. var pars []interface{}
  370. conditionArticle := ` AND article_id IN (` + utils.GetOrmInReplace(lenActivityIds) + `) `
  371. pars = append(pars, overviewArticleIdArr)
  372. articleList, err := cygx.GetCygxArticleList(conditionArticle, pars, 0, lenActivityIds)
  373. if err != nil {
  374. br.Msg = "获取失败"
  375. br.ErrMsg = "GetCygxArticleList,Err:" + err.Error()
  376. return
  377. }
  378. for _, v := range articleList {
  379. mapArticle[v.ArticleId] = v.Title
  380. }
  381. }
  382. //获取标的关联的日志
  383. for k, v := range list {
  384. listSon, err := cygx.GetCygxReportSelectionLogRepListSon(articleId, v.ChartPermissionId)
  385. if err != nil {
  386. br.Msg = "获取失败"
  387. br.ErrMsg = "获取子分类失败,Err:" + err.Error()
  388. return
  389. }
  390. for kIndustrial, vIndustrial := range listSon {
  391. var industrialNames string
  392. //如果报告精选关联的产业被删除了 则做以下处理
  393. if vIndustrial.IndustrialSubjectName == "" {
  394. industrialNames = vIndustrial.IndustrialManagementNames
  395. } else {
  396. industrialNames, err = cygx.GetindustrialManagementNamesBySubjectName(vIndustrial.IndustrialSubjectName, vIndustrial.ChartPermissionId)
  397. if err != nil {
  398. br.Msg = "获取失败!"
  399. br.ErrMsg = "获取删除删除之后的产业失败,Err:" + err.Error() + vIndustrial.IndustrialSubjectId
  400. return
  401. }
  402. }
  403. if vIndustrial.Label != "" {
  404. vIndustrial.CompanyLabel = strings.Split(vIndustrial.Label, "{|}")
  405. }
  406. listSon[kIndustrial].IndustrialManagementName = industrialNames
  407. listSon[kIndustrial].IndustrialManagementNames = industrialNames
  408. listSon[kIndustrial].OverviewArticleId = articleStockMap[vIndustrial.IndustrialSubjectName]
  409. listSon[kIndustrial].OverviewArticleTitle = mapArticle[listSon[kIndustrial].OverviewArticleId]
  410. if periods != "" {
  411. listSon[kIndustrial].IsNew = 0
  412. }
  413. if vIndustrial.SubjectName == "" {
  414. listSon[kIndustrial].ShowName = vIndustrial.IndustrialManagementNames
  415. } else {
  416. listSon[kIndustrial].ShowName = vIndustrial.SubjectName
  417. }
  418. }
  419. list[k].List = listSon
  420. list[k].BodyChartSummary = mapChartLog[v.ChartPermissionName]
  421. }
  422. resp.List = list
  423. br.Ret = 200
  424. br.Success = true
  425. br.Msg = "获取成功"
  426. br.Data = resp
  427. }
  428. // @Title 报告精选列表
  429. // @Description 获取报告精选列表接口
  430. // @Param PageSize query int true "每页数据条数"
  431. // @Param CurrentIndex query int true "当前页页码,从1开始"
  432. // @Param PublishStatus query int false "发布状态 ,1未发布,1已发布,传2查询所有"
  433. // @Param StartDate query string false "开始时间 ,列如2021-03-06 "
  434. // @Param EndDate query string false "结束时间,列如2021-03-06 "
  435. // @Success 200 {object} cygx.CygxReportSelectionListRep
  436. // @router /reportSelection/list [get]
  437. func (this *ReportSelectionController) List() {
  438. br := new(models.BaseResponse).Init()
  439. defer func() {
  440. this.Data["json"] = br
  441. this.ServeJSON()
  442. }()
  443. AdminUser := this.SysUser
  444. if AdminUser == nil {
  445. br.Msg = "请登录"
  446. br.ErrMsg = "请登录,SysUser Is Empty"
  447. return
  448. }
  449. pageSize, _ := this.GetInt("PageSize")
  450. currentIndex, _ := this.GetInt("CurrentIndex")
  451. publishStatus, _ := this.GetInt("PublishStatus")
  452. startDate := this.GetString("StartDate")
  453. endDate := this.GetString("EndDate")
  454. var startSize int
  455. if pageSize <= 0 {
  456. pageSize = utils.PageSize20
  457. }
  458. if currentIndex <= 0 {
  459. currentIndex = 1
  460. }
  461. startSize = utils.StartIndex(currentIndex, pageSize)
  462. var condition string
  463. var pars []interface{}
  464. if startDate != "" {
  465. condition += ` AND rs.publish_date >= ` + "'" + startDate + " 00:00:00'"
  466. }
  467. if endDate != "" {
  468. condition += ` AND rs.publish_date <= ` + "'" + endDate + " 23:59:59'"
  469. }
  470. if publishStatus == 0 || publishStatus == 1 {
  471. condition += ` AND rs.publish_status = ` + strconv.Itoa(publishStatus)
  472. }
  473. total, err := cygx.GetCygxReportSelection(condition, pars)
  474. if err != nil {
  475. br.Msg = "获取失败"
  476. br.ErrMsg = "获取失败,Err:" + err.Error()
  477. return
  478. }
  479. list, err := cygx.GetReportSelectionList(condition, pars, startSize, pageSize)
  480. if err != nil {
  481. br.Msg = "获取失败"
  482. br.ErrMsg = "获取失败,Err:" + err.Error()
  483. return
  484. }
  485. for k, v := range list {
  486. if v.Periods != "" && v.Periods != "0" {
  487. list[k].Periods = "第" + v.Periods + "期"
  488. } else {
  489. list[k].Periods = ""
  490. }
  491. list[k].PublishDate = utils.StrTimeToTime(v.PublishDate).Format("2006-01-02")
  492. }
  493. page := paging.GetPaging(currentIndex, pageSize, total)
  494. resp := new(cygx.CygxReportSelectionListRep)
  495. resp.List = list
  496. resp.Paging = page
  497. br.Ret = 200
  498. br.Success = true
  499. br.Msg = "获取成功"
  500. br.Data = resp
  501. }
  502. // @Title 报告精选的发布与取消发布
  503. // @Description 报告精选的发布与取消发布接口
  504. // @Param request body cygx.ResearchSummaryId true "type json string"
  505. // @Success 200 操作成功
  506. // @router /reportSelection/PublishAndCancel [post]
  507. func (this *ReportSelectionController) PublishAndCancel() {
  508. br := new(models.BaseResponse).Init()
  509. defer func() {
  510. this.Data["json"] = br
  511. this.ServeJSON()
  512. }()
  513. AdminUser := this.SysUser
  514. if AdminUser == nil {
  515. br.Msg = "请登录"
  516. br.ErrMsg = "请登录,用户信息为空"
  517. br.Ret = 408
  518. return
  519. }
  520. var req cygx.ResearchSummaryId
  521. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  522. if err != nil {
  523. br.Msg = "参数解析异常!"
  524. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  525. return
  526. }
  527. articleId := req.ArticleId
  528. detail, err := cygx.GetCygxReportSelectionInfoById(articleId)
  529. if err != nil {
  530. br.Msg = "内容不存在"
  531. br.ErrMsg = "操作失败,Err:" + err.Error()
  532. return
  533. }
  534. item := new(cygx.CygxReportSelectionRep)
  535. item.ArticleId = articleId
  536. if detail.PublishStatus == 0 {
  537. item.PublishStatus = 1
  538. item.AdminId = AdminUser.AdminId
  539. item.AdminName = AdminUser.RealName
  540. //cygxService.DoThisWeekLastWeekWxTemplateMsg(detail.Title, detail.PublishDate, detail.ProductDescription, req.ArticleId, 1)
  541. } else {
  542. item.AdminId = detail.AdminId
  543. item.AdminName = detail.AdminName
  544. item.PublishStatus = 0
  545. }
  546. if detail.HavePublish == 0 {
  547. condition := ` AND have_publish = 1 `
  548. var pars []interface{}
  549. total, err := cygx.GetCygxReportSelection(condition, pars)
  550. if err != nil {
  551. br.Msg = "获取失败"
  552. br.ErrMsg = "获取失败,Err:" + err.Error()
  553. return
  554. }
  555. item.Periods = strconv.Itoa(total + 1)
  556. } else {
  557. item.Periods = detail.Periods
  558. }
  559. err = cygx.ReportSelectionPublishAndCancel(item)
  560. if err != nil {
  561. br.Msg = "操作失败"
  562. br.ErrMsg = "操作失败,Err:" + err.Error()
  563. return
  564. }
  565. go cygxService.UpdateReportSelectionResourceData(articleId) //首页最新页面数据逻辑处理 V11.1.1
  566. br.Ret = 200
  567. br.Success = true
  568. br.Msg = "操作成功"
  569. br.IsAddLog = true
  570. }
  571. // @Title 报告精选初始模板
  572. // @Description 报告精选初始模板接口
  573. // @Success Ret=200 {object} cygx.CygxRSlChartPermissionIcoTmpList
  574. // @router /reportSelection/detailTemplate [get]
  575. func (this *ReportSelectionController) DetailTemplate() {
  576. br := new(models.BaseResponse).Init()
  577. defer func() {
  578. this.Data["json"] = br
  579. this.ServeJSON()
  580. }()
  581. AdminUser := this.SysUser
  582. if AdminUser == nil {
  583. br.Msg = "请登录"
  584. br.ErrMsg = "请登录,用户信息为空"
  585. br.Ret = 408
  586. return
  587. }
  588. resp := new(cygx.CygxRSlChartPermissionIcoTmpList)
  589. var condition string
  590. var list []*cygx.CygxRSlChartPermissionIcoTmp
  591. condition = ` AND chart_permission_id IN (19,20,21,22) `
  592. listMore, err := cygx.GetChartPermissionIcoNew(condition)
  593. if err != nil {
  594. br.Msg = "获取失败"
  595. br.ErrMsg = "获取失败,Err:" + err.Error()
  596. return
  597. }
  598. //排序方式修改
  599. permissionNameList := []cygx.CygxChartPermissionName{{ChartPermissionName: "消费"}, {ChartPermissionName: "医药"}, {ChartPermissionName: "科技"}, {ChartPermissionName: "智造"}}
  600. for _, v := range permissionNameList {
  601. for _, v2 := range listMore {
  602. if v.ChartPermissionName == v2.ChartPermissionName {
  603. item := new(cygx.CygxRSlChartPermissionIcoTmp)
  604. item.ChartPermissionName = v2.ChartPermissionName
  605. item.ChartPermissionSort = v2.ChartPermissionSort
  606. item.ChartPermissionId = v2.ChartPermissionId
  607. item.IcoLink = v2.IcoLink
  608. item.List = make([]string, 0)
  609. list = append(list, item)
  610. }
  611. }
  612. }
  613. resp.List = list
  614. br.Ret = 200
  615. br.Success = true
  616. br.Msg = "获取成功"
  617. br.Data = resp
  618. }
  619. // @Title 期数列表
  620. // @Description 获取期数列表接口
  621. // @Param PageSize query int true "每页数据条数"
  622. // @Param CurrentIndex query int true "当前页页码,从1开始"
  623. // @Success 200 {object} cygx.CygxReportSelectionPeriodsListRep
  624. // @router /reportSelection/listPeriods [get]
  625. func (this *ReportSelectionController) ListPeriods() {
  626. br := new(models.BaseResponse).Init()
  627. defer func() {
  628. this.Data["json"] = br
  629. this.ServeJSON()
  630. }()
  631. AdminUser := this.SysUser
  632. if AdminUser == nil {
  633. br.Msg = "请登录"
  634. br.ErrMsg = "请登录,SysUser Is Empty"
  635. return
  636. }
  637. pageSize, _ := this.GetInt("PageSize")
  638. currentIndex, _ := this.GetInt("CurrentIndex")
  639. var startSize int
  640. if pageSize <= 0 {
  641. pageSize = 1000
  642. }
  643. if currentIndex <= 0 {
  644. currentIndex = 1
  645. }
  646. startSize = utils.StartIndex(currentIndex, pageSize)
  647. var condition string
  648. var pars []interface{}
  649. total, err := cygx.GetCygxReportSelection(condition, pars)
  650. if err != nil {
  651. br.Msg = "获取失败"
  652. br.ErrMsg = "获取失败,Err:" + err.Error()
  653. return
  654. }
  655. list, err := cygx.GetReportSelectionListPeriods(condition, pars, startSize, pageSize)
  656. if err != nil {
  657. br.Msg = "获取失败"
  658. br.ErrMsg = "获取失败,Err:" + err.Error()
  659. return
  660. }
  661. for k, v := range list {
  662. if v.Periods != "" {
  663. list[k].InheritPeriodsName = "第" + v.Periods + "期"
  664. }
  665. }
  666. page := paging.GetPaging(currentIndex, pageSize, total)
  667. resp := new(cygx.CygxReportSelectionPeriodsListRep)
  668. resp.List = list
  669. resp.Paging = page
  670. br.Ret = 200
  671. br.Success = true
  672. br.Msg = "获取成功"
  673. br.Data = resp
  674. }
  675. // @Title 阅读明细下载
  676. // @Description 获取阅读明细下载接口
  677. // @Param ArticleId query int true "文章ID"
  678. // @Param Source query int true "来源 1:报告精选、2:路演精华、3:本周研究汇总、4:上周纪要汇总"
  679. // @Success 200 导出成功
  680. // @router /reportSelection/articleHistoryExport [get]
  681. func (this *ReportSelectionController) ArticleHistoryExport() {
  682. br := new(models.BaseResponse).Init()
  683. defer func() {
  684. this.Data["json"] = br
  685. this.ServeJSON()
  686. }()
  687. AdminUser := this.SysUser
  688. if AdminUser == nil {
  689. br.Msg = "请登录"
  690. br.ErrMsg = "请登录,SysUser Is Empty"
  691. return
  692. }
  693. articleId, _ := this.GetInt("ArticleId")
  694. source, _ := this.GetInt("Source")
  695. resp := new(cygx.CanDownload)
  696. adminInfo, errAdmin := system.GetSysUserById(AdminUser.AdminId)
  697. if errAdmin != nil {
  698. br.Msg = "获取失败"
  699. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  700. return
  701. }
  702. if adminInfo.Role == "admin" || adminInfo.Role == "researcher" || adminInfo.RealName == "汪洋" {
  703. resp.IsCanDownload = true
  704. }
  705. var condition string
  706. if resp.IsCanDownload == false {
  707. //权益申请销售只能看到自己名下的客户的申请
  708. companyIds, err := cygxService.GetAdminLookUserCompanyIds(AdminUser)
  709. if err != nil {
  710. br.Msg = "获取失败"
  711. br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error()
  712. return
  713. }
  714. var companyIdstr []string
  715. for _, v := range companyIds {
  716. companyIdstr = append(companyIdstr, strconv.Itoa(v))
  717. }
  718. condition = ` AND h.company_id IN (` + strings.Join(companyIdstr, ",") + `)`
  719. }
  720. condition += ` AND h.company_id != ` + strconv.Itoa(utils.HZ_COMPANY_ID) // 过滤弘则来源
  721. var list []*cygx.ArticleHistoryRep
  722. var err error
  723. var table string
  724. //"来源 1:报告精选、2:路演精华、3:本周研究汇总、4:上周纪要汇总"
  725. //报告类型,bgjx:报告精选、bzyjhz:本周研究汇总、szjyhz:上周纪要汇总
  726. if source != 2 {
  727. if source == 1 {
  728. table = "cygx_report_selection"
  729. condition += ` AND h.report_type = 'bgjx'`
  730. } else if source == 3 {
  731. table = "cygx_research_summary"
  732. condition += ` AND h.report_type = 'bzyjhz'`
  733. } else {
  734. table = "cygx_minutes_summary"
  735. condition += ` AND h.report_type = 'szjyhz'`
  736. }
  737. list, err = cygx.GetReportSelectionHistoryList(articleId, condition)
  738. if err != nil {
  739. br.Msg = "获取失败"
  740. br.ErrMsg = "获取失败,Err:" + err.Error()
  741. return
  742. }
  743. } else {
  744. table = "cygx_article"
  745. list, err = cygx.GetArticleHistoryListOld(articleId, condition)
  746. if err != nil {
  747. br.Msg = "获取失败"
  748. br.ErrMsg = "获取失败,Err:" + err.Error()
  749. return
  750. }
  751. }
  752. //根据不同类型获取不同报告的详情
  753. articleInfo, err := cygx.GetArticleInfoByIdAndTable(table, articleId)
  754. if err != nil {
  755. br.Msg = "获取失败"
  756. br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
  757. return
  758. }
  759. fmt.Println(articleInfo)
  760. //
  761. //创建excel
  762. dir, err := os.Executable()
  763. exPath := filepath.Dir(dir)
  764. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  765. xlsxFile := xlsx.NewFile()
  766. if err != nil {
  767. br.Msg = "生成文件失败"
  768. br.ErrMsg = "生成文件失败"
  769. return
  770. }
  771. style := xlsx.NewStyle()
  772. alignment := xlsx.Alignment{
  773. Horizontal: "center",
  774. Vertical: "center",
  775. WrapText: true,
  776. }
  777. style.Alignment = alignment
  778. style.ApplyAlignment = true
  779. sheet, err := xlsxFile.AddSheet("名单")
  780. if err != nil {
  781. br.Msg = "新增Sheet失败"
  782. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  783. return
  784. }
  785. //标头
  786. rowTitle := sheet.AddRow()
  787. cellA := rowTitle.AddCell()
  788. cellA.Value = "姓名"
  789. cellB := rowTitle.AddCell()
  790. cellB.Value = "手机号"
  791. cellC := rowTitle.AddCell()
  792. cellC.Value = "公司名称"
  793. cellD := rowTitle.AddCell()
  794. cellD.Value = "所属权益销售"
  795. cellF := rowTitle.AddCell()
  796. cellF.Value = "阅读时间"
  797. for _, item := range list {
  798. row := sheet.AddRow()
  799. cellA := row.AddCell()
  800. cellA.Value = item.RealName
  801. cellB := row.AddCell()
  802. cellB.Value = item.Mobile
  803. cellC := row.AddCell()
  804. cellC.Value = item.CompanyName
  805. cellD := row.AddCell()
  806. cellD.Value = item.SellerName
  807. cellF := row.AddCell()
  808. cellF.Value = item.CreateTime
  809. }
  810. err = xlsxFile.Save(downLoadnFilePath)
  811. if err != nil {
  812. br.Msg = "保存文件失败"
  813. br.ErrMsg = "保存文件失败"
  814. return
  815. }
  816. //randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  817. downloadFileName := articleInfo.Title + ".xlsx"
  818. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  819. defer func() {
  820. //os.Remove(downLoadnFilePath)
  821. }()
  822. br.Success = true
  823. br.Ret = 200
  824. br.Msg = "导出成功"
  825. }
  826. // @Title 通过标的ID获取相关连的产文章信息
  827. // @Description 通过标的ID获取相关连的产文章信息接口
  828. // @Param IndustrialSubjectId query int true "标的id "
  829. // @Success 200 {object} cygx.OverviewArticle
  830. // @router /reportSelection/getArticle [get]
  831. func (this *ReportSelectionController) GetArticle() {
  832. br := new(models.BaseResponse).Init()
  833. defer func() {
  834. this.Data["json"] = br
  835. this.ServeJSON()
  836. }()
  837. AdminUser := this.SysUser
  838. if AdminUser == nil {
  839. br.Msg = "请登录"
  840. br.ErrMsg = "请登录,SysUser Is Empty"
  841. return
  842. }
  843. resp := new(cygx.OverviewArticle)
  844. industrialSubjectId, _ := this.GetInt("IndustrialSubjectId")
  845. if industrialSubjectId > 0 {
  846. detailSubjecj, err := cygx.GetIndustrialSubjectDetailById(industrialSubjectId)
  847. if err != nil && err.Error() != utils.ErrNoRow() {
  848. br.Msg = "获取信息失败"
  849. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  850. return
  851. }
  852. if detailSubjecj != nil {
  853. var pars []interface{}
  854. conditionArticle := ` AND type_name = '综述报告' AND stock LIKE ? `
  855. subjectName := "%" + detailSubjecj.SubjectName + "%"
  856. pars = append(pars, subjectName)
  857. articleList, err := cygx.GetCygxArticleList(conditionArticle, pars, 0, 10)
  858. if err != nil {
  859. br.Msg = "获取失败"
  860. br.ErrMsg = "GetCygxArticleList,Err:" + err.Error()
  861. return
  862. }
  863. //一对一精准匹配
  864. for _, v := range articleList {
  865. sliceSubjects := strings.Split(v.Stock, "/")
  866. if len(sliceSubjects) > 0 {
  867. for _, vSubject := range sliceSubjects {
  868. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  869. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  870. subject := sliceXiahuaxian[0]
  871. if subject == detailSubjecj.SubjectName {
  872. resp.ArticleId = v.ArticleId
  873. resp.Title = v.Title
  874. continue
  875. }
  876. }
  877. }
  878. }
  879. }
  880. }
  881. br.Ret = 200
  882. br.Success = true
  883. br.Msg = "获取成功"
  884. br.Data = resp
  885. }
  886. // @Title 报告精选的可见范围修改
  887. // @Description 报告精选的可见范围修改接口
  888. // @Param request body cygx.ResearchSummaryId true "type json string"
  889. // @Success 200 操作成功
  890. // @router /reportSelection/visibleRange [post]
  891. func (this *ReportSelectionController) VisibleRange() {
  892. br := new(models.BaseResponse).Init()
  893. defer func() {
  894. this.Data["json"] = br
  895. this.ServeJSON()
  896. }()
  897. AdminUser := this.SysUser
  898. if AdminUser == nil {
  899. br.Msg = "请登录"
  900. br.ErrMsg = "请登录,用户信息为空"
  901. br.Ret = 408
  902. return
  903. }
  904. var req cygx.ResearchSummaryId
  905. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  906. if err != nil {
  907. br.Msg = "参数解析异常!"
  908. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  909. return
  910. }
  911. articleId := req.ArticleId
  912. detail, err := cygx.GetCygxReportSelectionInfoById(articleId)
  913. if err != nil {
  914. br.Msg = "内容不存在"
  915. br.ErrMsg = "操作失败,Err:" + err.Error()
  916. return
  917. }
  918. item := new(cygx.CygxReportSelectionRep)
  919. item.ArticleId = articleId
  920. if detail.VisibleRange == 0 {
  921. item.VisibleRange = 1
  922. item.AdminId = AdminUser.AdminId
  923. item.AdminName = AdminUser.RealName
  924. if detail.IsSendWxMsg == 0 {
  925. cygxService.DoThisWeekLastWeekWxTemplateMsg(detail.Title, detail.PublishDate, detail.ProductDescription, req.ArticleId, 1)
  926. }
  927. } else {
  928. item.AdminId = detail.AdminId
  929. item.AdminName = detail.AdminName
  930. item.VisibleRange = 0
  931. }
  932. err = cygx.ReportSelectionVisibleRange(item)
  933. if err != nil {
  934. br.Msg = "操作失败"
  935. br.ErrMsg = "操作失败,Err:" + err.Error()
  936. return
  937. }
  938. go cygxService.UpdateReportSelectionResourceData(articleId) //首页最新页面数据逻辑处理 V11.1.1
  939. br.Ret = 200
  940. br.Success = true
  941. br.Msg = "操作成功"
  942. br.IsAddLog = true
  943. }
  944. // @Title 报告精选内容详情
  945. // @Description 报告精选内容详情接口
  946. // @Param ArticleId query int true "报告Id"
  947. // @Success Ret=200 {object} cygx.DetailCygxReportSelectionRep
  948. // @router /reportSelection/history [get]
  949. func (this *ReportSelectionController) History() {
  950. br := new(models.BaseResponse).Init()
  951. defer func() {
  952. this.Data["json"] = br
  953. this.ServeJSON()
  954. }()
  955. AdminUser := this.SysUser
  956. if AdminUser == nil {
  957. br.Msg = "请登录"
  958. br.ErrMsg = "请登录,用户信息为空"
  959. br.Ret = 408
  960. return
  961. }
  962. var errArt error
  963. detail := new(cygx.CygxReportSelectionRep)
  964. articleId, _ := this.GetInt("ArticleId")
  965. detail, errArt = cygx.GetCygxReportSelectionInfoById(articleId)
  966. if errArt != nil {
  967. br.Msg = "内容不存在"
  968. br.ErrMsg = "内容不存在,Err:" + errArt.Error()
  969. return
  970. }
  971. articleId = detail.ArticleId
  972. resp := new(cygx.HistoryReportSelectionRep)
  973. permissionNameMap, err := services.GetPermissionNameMap()
  974. if err != nil {
  975. br.Msg = "获取失败"
  976. br.ErrMsg = "获取失败 GetPermissionNameMap,Err:" + err.Error()
  977. return
  978. }
  979. listSelectionLog, err := cygx.GetReportSelectionlogListAll(articleId)
  980. if err != nil {
  981. br.Msg = "获取失败"
  982. br.ErrMsg = "GetReportSelectionlogListAll,Err:" + err.Error()
  983. return
  984. }
  985. for k, v := range listSelectionLog {
  986. listSelectionLog[k].PermissionName = permissionNameMap[v.ChartPermissionId]
  987. }
  988. //获取标的的点击次数
  989. listSelectionSubjectHistory, err := cygx.GetCygxReportSelectionSubjectHistoryList(articleId)
  990. if err != nil && err.Error() != utils.ErrNoRow() {
  991. br.Msg = "获取失败"
  992. br.ErrMsg = "GetCygxReportSelectionSubjectHistoryList,Err:" + err.Error()
  993. return
  994. }
  995. mapSubjectHistory := make(map[string]int) // 标的点击数量
  996. mapIndustrialHistory := make(map[string]int) // 产业点击数量
  997. for _, v := range listSelectionSubjectHistory {
  998. mapSubjectHistory[v.IndustrialSubjectId]++
  999. if v.IndustrialSubjectId == "0" && v.IndustrialManagementId > 0 {
  1000. mapIndustrialHistory[strconv.Itoa(v.IndustrialManagementId)]++
  1001. }
  1002. }
  1003. //排序方式修改
  1004. permissionNameList := []*cygx.HistoryReportSelectionChart{{ChartPermissionName: "消费"}, {ChartPermissionName: "医药"}, {ChartPermissionName: "科技"}, {ChartPermissionName: "智造"}}
  1005. for _, v := range permissionNameList {
  1006. v.List = make([]*cygx.HistoryReportSelectionLogResp, 0)
  1007. for _, v2 := range listSelectionLog {
  1008. if v.ChartPermissionName == v2.PermissionName {
  1009. item := new(cygx.HistoryReportSelectionLogResp)
  1010. if (v2.IndustrialSubjectId == "" || v2.IndustrialSubjectId == "0") && v2.IndustrialManagementId != "" {
  1011. item.SubjectName = v2.IndustrialManagementNames
  1012. item.Count = mapIndustrialHistory[v2.IndustrialManagementId]
  1013. } else {
  1014. item.SubjectName = v2.SubjectName
  1015. item.IndustrialSubjectId = v2.IndustrialSubjectId
  1016. item.Count = mapSubjectHistory[v2.IndustrialSubjectId]
  1017. }
  1018. item.IsNew = v2.IsNew
  1019. resp.Count += item.Count
  1020. v.List = append(v.List, item)
  1021. }
  1022. }
  1023. }
  1024. resp.List = permissionNameList
  1025. br.Ret = 200
  1026. br.Success = true
  1027. br.Msg = "获取成功"
  1028. br.Data = resp
  1029. }
  1030. // @Title 报告精选申请记录
  1031. // @Description 报告精选申请记录接口
  1032. // @Param ArticleId query int true "报告Id"
  1033. // @Success Ret=200 {object} cygx.DetailCygxReportSelectionRep
  1034. // @router /reportSelection/tarryList [get]
  1035. func (this *ReportSelectionController) RarryList() {
  1036. br := new(models.BaseResponse).Init()
  1037. defer func() {
  1038. this.Data["json"] = br
  1039. this.ServeJSON()
  1040. }()
  1041. AdminUser := this.SysUser
  1042. if AdminUser == nil {
  1043. br.Msg = "请登录"
  1044. br.ErrMsg = "请登录,用户信息为空"
  1045. br.Ret = 408
  1046. return
  1047. }
  1048. articleId, _ := this.GetInt("ArticleId")
  1049. resp := new(cygx.CygxReportSelectionLogApplyListResp)
  1050. var condition string
  1051. var pars []interface{}
  1052. condition = " AND article_id = ? ORDER BY create_time DESC "
  1053. pars = append(pars, articleId)
  1054. list, err := cygx.GetCygxReportSelectionLogApplyRespList(condition, pars, 0, 0)
  1055. if err != nil {
  1056. br.Msg = "获取信息失败"
  1057. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1058. return
  1059. }
  1060. if len(list) == 0 {
  1061. list = make([]*cygx.CygxReportSelectionLogApplyResp, 0)
  1062. }
  1063. resp.List = list
  1064. br.Ret = 200
  1065. br.Success = true
  1066. br.Msg = "获取成功"
  1067. br.Data = resp
  1068. }