report_selection.go 34 KB

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