report_selection.go 33 KB

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