report_selection.go 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097
  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. //如果报告精选关联的产业被删除了 则做以下处理
  392. //if vIndustrial.IndustrialManagementName == "" {
  393. industrialNames, err := cygx.GetindustrialManagementNamesBySubjectName(vIndustrial.IndustrialSubjectName, vIndustrial.ChartPermissionId)
  394. if err != nil {
  395. br.Msg = "获取失败!"
  396. br.ErrMsg = "获取删除删除之后的产业失败,Err:" + err.Error() + vIndustrial.IndustrialSubjectId
  397. return
  398. }
  399. if vIndustrial.Label != "" {
  400. vIndustrial.CompanyLabel = strings.Split(vIndustrial.Label, "{|}")
  401. }
  402. listSon[kIndustrial].IndustrialManagementName = industrialNames
  403. listSon[kIndustrial].IndustrialManagementNames = industrialNames
  404. listSon[kIndustrial].OverviewArticleId = articleStockMap[vIndustrial.IndustrialSubjectName]
  405. listSon[kIndustrial].OverviewArticleTitle = mapArticle[listSon[kIndustrial].OverviewArticleId]
  406. if periods != "" {
  407. listSon[kIndustrial].IsNew = 0
  408. }
  409. if vIndustrial.SubjectName == "" {
  410. listSon[kIndustrial].ShowName = vIndustrial.IndustrialManagementNames
  411. } else {
  412. listSon[kIndustrial].ShowName = vIndustrial.SubjectName
  413. }
  414. }
  415. list[k].List = listSon
  416. list[k].BodyChartSummary = mapChartLog[v.ChartPermissionName]
  417. }
  418. resp.List = list
  419. br.Ret = 200
  420. br.Success = true
  421. br.Msg = "获取成功"
  422. br.Data = resp
  423. }
  424. // @Title 报告精选列表
  425. // @Description 获取报告精选列表接口
  426. // @Param PageSize query int true "每页数据条数"
  427. // @Param CurrentIndex query int true "当前页页码,从1开始"
  428. // @Param PublishStatus query int false "发布状态 ,1未发布,1已发布,传2查询所有"
  429. // @Param StartDate query string false "开始时间 ,列如2021-03-06 "
  430. // @Param EndDate query string false "结束时间,列如2021-03-06 "
  431. // @Success 200 {object} cygx.CygxReportSelectionListRep
  432. // @router /reportSelection/list [get]
  433. func (this *ReportSelectionController) List() {
  434. br := new(models.BaseResponse).Init()
  435. defer func() {
  436. this.Data["json"] = br
  437. this.ServeJSON()
  438. }()
  439. AdminUser := this.SysUser
  440. if AdminUser == nil {
  441. br.Msg = "请登录"
  442. br.ErrMsg = "请登录,SysUser Is Empty"
  443. return
  444. }
  445. pageSize, _ := this.GetInt("PageSize")
  446. currentIndex, _ := this.GetInt("CurrentIndex")
  447. publishStatus, _ := this.GetInt("PublishStatus")
  448. startDate := this.GetString("StartDate")
  449. endDate := this.GetString("EndDate")
  450. var startSize int
  451. if pageSize <= 0 {
  452. pageSize = utils.PageSize20
  453. }
  454. if currentIndex <= 0 {
  455. currentIndex = 1
  456. }
  457. startSize = utils.StartIndex(currentIndex, pageSize)
  458. var condition string
  459. var pars []interface{}
  460. if startDate != "" {
  461. condition += ` AND rs.publish_date >= ` + "'" + startDate + " 00:00:00'"
  462. }
  463. if endDate != "" {
  464. condition += ` AND rs.publish_date <= ` + "'" + endDate + " 23:59:59'"
  465. }
  466. if publishStatus == 0 || publishStatus == 1 {
  467. condition += ` AND rs.publish_status = ` + strconv.Itoa(publishStatus)
  468. }
  469. total, err := cygx.GetCygxReportSelection(condition, pars)
  470. if err != nil {
  471. br.Msg = "获取失败"
  472. br.ErrMsg = "获取失败,Err:" + err.Error()
  473. return
  474. }
  475. list, err := cygx.GetReportSelectionList(condition, pars, startSize, pageSize)
  476. if err != nil {
  477. br.Msg = "获取失败"
  478. br.ErrMsg = "获取失败,Err:" + err.Error()
  479. return
  480. }
  481. for k, v := range list {
  482. if v.Periods != "" && v.Periods != "0" {
  483. list[k].Periods = "第" + v.Periods + "期"
  484. } else {
  485. list[k].Periods = ""
  486. }
  487. list[k].PublishDate = utils.StrTimeToTime(v.PublishDate).Format("2006-01-02")
  488. }
  489. page := paging.GetPaging(currentIndex, pageSize, total)
  490. resp := new(cygx.CygxReportSelectionListRep)
  491. resp.List = list
  492. resp.Paging = page
  493. br.Ret = 200
  494. br.Success = true
  495. br.Msg = "获取成功"
  496. br.Data = resp
  497. }
  498. // @Title 报告精选的发布与取消发布
  499. // @Description 报告精选的发布与取消发布接口
  500. // @Param request body cygx.ResearchSummaryId true "type json string"
  501. // @Success 200 操作成功
  502. // @router /reportSelection/PublishAndCancel [post]
  503. func (this *ReportSelectionController) PublishAndCancel() {
  504. br := new(models.BaseResponse).Init()
  505. defer func() {
  506. this.Data["json"] = br
  507. this.ServeJSON()
  508. }()
  509. AdminUser := this.SysUser
  510. if AdminUser == nil {
  511. br.Msg = "请登录"
  512. br.ErrMsg = "请登录,用户信息为空"
  513. br.Ret = 408
  514. return
  515. }
  516. var req cygx.ResearchSummaryId
  517. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  518. if err != nil {
  519. br.Msg = "参数解析异常!"
  520. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  521. return
  522. }
  523. articleId := req.ArticleId
  524. detail, err := cygx.GetCygxReportSelectionInfoById(articleId)
  525. if err != nil {
  526. br.Msg = "内容不存在"
  527. br.ErrMsg = "操作失败,Err:" + err.Error()
  528. return
  529. }
  530. item := new(cygx.CygxReportSelectionRep)
  531. item.ArticleId = articleId
  532. if detail.PublishStatus == 0 {
  533. item.PublishStatus = 1
  534. item.AdminId = AdminUser.AdminId
  535. item.AdminName = AdminUser.RealName
  536. //cygxService.DoThisWeekLastWeekWxTemplateMsg(detail.Title, detail.PublishDate, detail.ProductDescription, req.ArticleId, 1)
  537. } else {
  538. item.AdminId = detail.AdminId
  539. item.AdminName = detail.AdminName
  540. item.PublishStatus = 0
  541. }
  542. if detail.HavePublish == 0 {
  543. condition := ` AND have_publish = 1 `
  544. var pars []interface{}
  545. total, err := cygx.GetCygxReportSelection(condition, pars)
  546. if err != nil {
  547. br.Msg = "获取失败"
  548. br.ErrMsg = "获取失败,Err:" + err.Error()
  549. return
  550. }
  551. item.Periods = strconv.Itoa(total + 1)
  552. } else {
  553. item.Periods = detail.Periods
  554. }
  555. err = cygx.ReportSelectionPublishAndCancel(item)
  556. if err != nil {
  557. br.Msg = "操作失败"
  558. br.ErrMsg = "操作失败,Err:" + err.Error()
  559. return
  560. }
  561. go cygxService.UpdateReportSelectionResourceData(articleId) //首页最新页面数据逻辑处理 V11.1.1
  562. br.Ret = 200
  563. br.Success = true
  564. br.Msg = "操作成功"
  565. br.IsAddLog = true
  566. }
  567. // @Title 报告精选初始模板
  568. // @Description 报告精选初始模板接口
  569. // @Success Ret=200 {object} cygx.CygxRSlChartPermissionIcoTmpList
  570. // @router /reportSelection/detailTemplate [get]
  571. func (this *ReportSelectionController) DetailTemplate() {
  572. br := new(models.BaseResponse).Init()
  573. defer func() {
  574. this.Data["json"] = br
  575. this.ServeJSON()
  576. }()
  577. AdminUser := this.SysUser
  578. if AdminUser == nil {
  579. br.Msg = "请登录"
  580. br.ErrMsg = "请登录,用户信息为空"
  581. br.Ret = 408
  582. return
  583. }
  584. resp := new(cygx.CygxRSlChartPermissionIcoTmpList)
  585. var condition string
  586. var list []*cygx.CygxRSlChartPermissionIcoTmp
  587. condition = ` AND chart_permission_id IN (19,20,21,22) `
  588. listMore, err := cygx.GetChartPermissionIcoNew(condition)
  589. if err != nil {
  590. br.Msg = "获取失败"
  591. br.ErrMsg = "获取失败,Err:" + err.Error()
  592. return
  593. }
  594. //排序方式修改
  595. permissionNameList := []cygx.CygxChartPermissionName{{ChartPermissionName: "消费"}, {ChartPermissionName: "医药"}, {ChartPermissionName: "科技"}, {ChartPermissionName: "智造"}}
  596. for _, v := range permissionNameList {
  597. for _, v2 := range listMore {
  598. if v.ChartPermissionName == v2.ChartPermissionName {
  599. item := new(cygx.CygxRSlChartPermissionIcoTmp)
  600. item.ChartPermissionName = v2.ChartPermissionName
  601. item.ChartPermissionSort = v2.ChartPermissionSort
  602. item.ChartPermissionId = v2.ChartPermissionId
  603. item.IcoLink = v2.IcoLink
  604. item.List = make([]string, 0)
  605. list = append(list, item)
  606. }
  607. }
  608. }
  609. resp.List = list
  610. br.Ret = 200
  611. br.Success = true
  612. br.Msg = "获取成功"
  613. br.Data = resp
  614. }
  615. // @Title 期数列表
  616. // @Description 获取期数列表接口
  617. // @Param PageSize query int true "每页数据条数"
  618. // @Param CurrentIndex query int true "当前页页码,从1开始"
  619. // @Success 200 {object} cygx.CygxReportSelectionPeriodsListRep
  620. // @router /reportSelection/listPeriods [get]
  621. func (this *ReportSelectionController) ListPeriods() {
  622. br := new(models.BaseResponse).Init()
  623. defer func() {
  624. this.Data["json"] = br
  625. this.ServeJSON()
  626. }()
  627. AdminUser := this.SysUser
  628. if AdminUser == nil {
  629. br.Msg = "请登录"
  630. br.ErrMsg = "请登录,SysUser Is Empty"
  631. return
  632. }
  633. pageSize, _ := this.GetInt("PageSize")
  634. currentIndex, _ := this.GetInt("CurrentIndex")
  635. var startSize int
  636. if pageSize <= 0 {
  637. pageSize = 1000
  638. }
  639. if currentIndex <= 0 {
  640. currentIndex = 1
  641. }
  642. startSize = utils.StartIndex(currentIndex, pageSize)
  643. var condition string
  644. var pars []interface{}
  645. total, err := cygx.GetCygxReportSelection(condition, pars)
  646. if err != nil {
  647. br.Msg = "获取失败"
  648. br.ErrMsg = "获取失败,Err:" + err.Error()
  649. return
  650. }
  651. list, err := cygx.GetReportSelectionListPeriods(condition, pars, startSize, pageSize)
  652. if err != nil {
  653. br.Msg = "获取失败"
  654. br.ErrMsg = "获取失败,Err:" + err.Error()
  655. return
  656. }
  657. for k, v := range list {
  658. if v.Periods != "" {
  659. list[k].InheritPeriodsName = "第" + v.Periods + "期"
  660. }
  661. }
  662. page := paging.GetPaging(currentIndex, pageSize, total)
  663. resp := new(cygx.CygxReportSelectionPeriodsListRep)
  664. resp.List = list
  665. resp.Paging = page
  666. br.Ret = 200
  667. br.Success = true
  668. br.Msg = "获取成功"
  669. br.Data = resp
  670. }
  671. // @Title 阅读明细下载
  672. // @Description 获取阅读明细下载接口
  673. // @Param ArticleId query int true "文章ID"
  674. // @Param Source query int true "来源 1:报告精选、2:路演精华、3:本周研究汇总、4:上周纪要汇总"
  675. // @Success 200 导出成功
  676. // @router /reportSelection/articleHistoryExport [get]
  677. func (this *ReportSelectionController) ArticleHistoryExport() {
  678. br := new(models.BaseResponse).Init()
  679. defer func() {
  680. this.Data["json"] = br
  681. this.ServeJSON()
  682. }()
  683. AdminUser := this.SysUser
  684. if AdminUser == nil {
  685. br.Msg = "请登录"
  686. br.ErrMsg = "请登录,SysUser Is Empty"
  687. return
  688. }
  689. articleId, _ := this.GetInt("ArticleId")
  690. source, _ := this.GetInt("Source")
  691. resp := new(cygx.CanDownload)
  692. adminInfo, errAdmin := system.GetSysUserById(AdminUser.AdminId)
  693. if errAdmin != nil {
  694. br.Msg = "获取失败"
  695. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  696. return
  697. }
  698. if adminInfo.Role == "admin" || adminInfo.Role == "researcher" || adminInfo.RealName == "汪洋" {
  699. resp.IsCanDownload = true
  700. }
  701. var condition string
  702. if resp.IsCanDownload == false {
  703. //权益申请销售只能看到自己名下的客户的申请
  704. companyIds, err := cygxService.GetAdminLookUserCompanyIds(AdminUser)
  705. if err != nil {
  706. br.Msg = "获取失败"
  707. br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error()
  708. return
  709. }
  710. var companyIdstr []string
  711. for _, v := range companyIds {
  712. companyIdstr = append(companyIdstr, strconv.Itoa(v))
  713. }
  714. condition = ` AND h.company_id IN (` + strings.Join(companyIdstr, ",") + `)`
  715. }
  716. condition += ` AND h.company_id != ` + strconv.Itoa(utils.HZ_COMPANY_ID) // 过滤弘则来源
  717. var list []*cygx.ArticleHistoryRep
  718. var err error
  719. var table string
  720. //"来源 1:报告精选、2:路演精华、3:本周研究汇总、4:上周纪要汇总"
  721. //报告类型,bgjx:报告精选、bzyjhz:本周研究汇总、szjyhz:上周纪要汇总
  722. if source != 2 {
  723. if source == 1 {
  724. table = "cygx_report_selection"
  725. condition += ` AND h.report_type = 'bgjx'`
  726. } else if source == 3 {
  727. table = "cygx_research_summary"
  728. condition += ` AND h.report_type = 'bzyjhz'`
  729. } else {
  730. table = "cygx_minutes_summary"
  731. condition += ` AND h.report_type = 'szjyhz'`
  732. }
  733. list, err = cygx.GetReportSelectionHistoryList(articleId, condition)
  734. if err != nil {
  735. br.Msg = "获取失败"
  736. br.ErrMsg = "获取失败,Err:" + err.Error()
  737. return
  738. }
  739. } else {
  740. table = "cygx_article"
  741. list, err = cygx.GetArticleHistoryListOld(articleId, condition)
  742. if err != nil {
  743. br.Msg = "获取失败"
  744. br.ErrMsg = "获取失败,Err:" + err.Error()
  745. return
  746. }
  747. }
  748. //根据不同类型获取不同报告的详情
  749. articleInfo, err := cygx.GetArticleInfoByIdAndTable(table, articleId)
  750. if err != nil {
  751. br.Msg = "获取失败"
  752. br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
  753. return
  754. }
  755. fmt.Println(articleInfo)
  756. //
  757. //创建excel
  758. dir, err := os.Executable()
  759. exPath := filepath.Dir(dir)
  760. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  761. xlsxFile := xlsx.NewFile()
  762. if err != nil {
  763. br.Msg = "生成文件失败"
  764. br.ErrMsg = "生成文件失败"
  765. return
  766. }
  767. style := xlsx.NewStyle()
  768. alignment := xlsx.Alignment{
  769. Horizontal: "center",
  770. Vertical: "center",
  771. WrapText: true,
  772. }
  773. style.Alignment = alignment
  774. style.ApplyAlignment = true
  775. sheet, err := xlsxFile.AddSheet("名单")
  776. if err != nil {
  777. br.Msg = "新增Sheet失败"
  778. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  779. return
  780. }
  781. //标头
  782. rowTitle := sheet.AddRow()
  783. cellA := rowTitle.AddCell()
  784. cellA.Value = "姓名"
  785. cellB := rowTitle.AddCell()
  786. cellB.Value = "手机号"
  787. cellC := rowTitle.AddCell()
  788. cellC.Value = "公司名称"
  789. cellD := rowTitle.AddCell()
  790. cellD.Value = "所属权益销售"
  791. cellF := rowTitle.AddCell()
  792. cellF.Value = "阅读时间"
  793. for _, item := range list {
  794. row := sheet.AddRow()
  795. cellA := row.AddCell()
  796. cellA.Value = item.RealName
  797. cellB := row.AddCell()
  798. cellB.Value = item.Mobile
  799. cellC := row.AddCell()
  800. cellC.Value = item.CompanyName
  801. cellD := row.AddCell()
  802. cellD.Value = item.SellerName
  803. cellF := row.AddCell()
  804. cellF.Value = item.CreateTime
  805. }
  806. err = xlsxFile.Save(downLoadnFilePath)
  807. if err != nil {
  808. br.Msg = "保存文件失败"
  809. br.ErrMsg = "保存文件失败"
  810. return
  811. }
  812. //randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  813. downloadFileName := articleInfo.Title + ".xlsx"
  814. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  815. defer func() {
  816. //os.Remove(downLoadnFilePath)
  817. }()
  818. br.Success = true
  819. br.Ret = 200
  820. br.Msg = "导出成功"
  821. }
  822. // @Title 通过标的ID获取相关连的产文章信息
  823. // @Description 通过标的ID获取相关连的产文章信息接口
  824. // @Param IndustrialSubjectId query int true "标的id "
  825. // @Success 200 {object} cygx.OverviewArticle
  826. // @router /reportSelection/getArticle [get]
  827. func (this *ReportSelectionController) GetArticle() {
  828. br := new(models.BaseResponse).Init()
  829. defer func() {
  830. this.Data["json"] = br
  831. this.ServeJSON()
  832. }()
  833. AdminUser := this.SysUser
  834. if AdminUser == nil {
  835. br.Msg = "请登录"
  836. br.ErrMsg = "请登录,SysUser Is Empty"
  837. return
  838. }
  839. resp := new(cygx.OverviewArticle)
  840. industrialSubjectId, _ := this.GetInt("IndustrialSubjectId")
  841. if industrialSubjectId > 0 {
  842. detailSubjecj, err := cygx.GetIndustrialSubjectDetailById(industrialSubjectId)
  843. if err != nil && err.Error() != utils.ErrNoRow() {
  844. br.Msg = "获取信息失败"
  845. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  846. return
  847. }
  848. if detailSubjecj != nil {
  849. var pars []interface{}
  850. conditionArticle := ` AND type_name = '综述报告' AND stock LIKE ? `
  851. subjectName := "%" + detailSubjecj.SubjectName + "%"
  852. pars = append(pars, subjectName)
  853. articleList, err := cygx.GetCygxArticleList(conditionArticle, pars, 0, 10)
  854. if err != nil {
  855. br.Msg = "获取失败"
  856. br.ErrMsg = "GetCygxArticleList,Err:" + err.Error()
  857. return
  858. }
  859. //一对一精准匹配
  860. for _, v := range articleList {
  861. sliceSubjects := strings.Split(v.Stock, "/")
  862. if len(sliceSubjects) > 0 {
  863. for _, vSubject := range sliceSubjects {
  864. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  865. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  866. subject := sliceXiahuaxian[0]
  867. if subject == detailSubjecj.SubjectName {
  868. resp.ArticleId = v.ArticleId
  869. resp.Title = v.Title
  870. continue
  871. }
  872. }
  873. }
  874. }
  875. }
  876. }
  877. br.Ret = 200
  878. br.Success = true
  879. br.Msg = "获取成功"
  880. br.Data = resp
  881. }
  882. // @Title 报告精选的可见范围修改
  883. // @Description 报告精选的可见范围修改接口
  884. // @Param request body cygx.ResearchSummaryId true "type json string"
  885. // @Success 200 操作成功
  886. // @router /reportSelection/visibleRange [post]
  887. func (this *ReportSelectionController) VisibleRange() {
  888. br := new(models.BaseResponse).Init()
  889. defer func() {
  890. this.Data["json"] = br
  891. this.ServeJSON()
  892. }()
  893. AdminUser := this.SysUser
  894. if AdminUser == nil {
  895. br.Msg = "请登录"
  896. br.ErrMsg = "请登录,用户信息为空"
  897. br.Ret = 408
  898. return
  899. }
  900. var req cygx.ResearchSummaryId
  901. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  902. if err != nil {
  903. br.Msg = "参数解析异常!"
  904. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  905. return
  906. }
  907. articleId := req.ArticleId
  908. detail, err := cygx.GetCygxReportSelectionInfoById(articleId)
  909. if err != nil {
  910. br.Msg = "内容不存在"
  911. br.ErrMsg = "操作失败,Err:" + err.Error()
  912. return
  913. }
  914. item := new(cygx.CygxReportSelectionRep)
  915. item.ArticleId = articleId
  916. if detail.VisibleRange == 0 {
  917. item.VisibleRange = 1
  918. item.AdminId = AdminUser.AdminId
  919. item.AdminName = AdminUser.RealName
  920. if detail.IsSendWxMsg == 0 {
  921. cygxService.DoThisWeekLastWeekWxTemplateMsg(detail.Title, detail.PublishDate, detail.ProductDescription, req.ArticleId, 1)
  922. }
  923. } else {
  924. item.AdminId = detail.AdminId
  925. item.AdminName = detail.AdminName
  926. item.VisibleRange = 0
  927. }
  928. err = cygx.ReportSelectionVisibleRange(item)
  929. if err != nil {
  930. br.Msg = "操作失败"
  931. br.ErrMsg = "操作失败,Err:" + err.Error()
  932. return
  933. }
  934. go cygxService.UpdateReportSelectionResourceData(articleId) //首页最新页面数据逻辑处理 V11.1.1
  935. br.Ret = 200
  936. br.Success = true
  937. br.Msg = "操作成功"
  938. br.IsAddLog = true
  939. }
  940. // @Title 报告精选内容详情
  941. // @Description 报告精选内容详情接口
  942. // @Param ArticleId query int true "报告Id"
  943. // @Success Ret=200 {object} cygx.DetailCygxReportSelectionRep
  944. // @router /reportSelection/history [get]
  945. func (this *ReportSelectionController) History() {
  946. br := new(models.BaseResponse).Init()
  947. defer func() {
  948. this.Data["json"] = br
  949. this.ServeJSON()
  950. }()
  951. AdminUser := this.SysUser
  952. if AdminUser == nil {
  953. br.Msg = "请登录"
  954. br.ErrMsg = "请登录,用户信息为空"
  955. br.Ret = 408
  956. return
  957. }
  958. var errArt error
  959. detail := new(cygx.CygxReportSelectionRep)
  960. articleId, _ := this.GetInt("ArticleId")
  961. detail, errArt = cygx.GetCygxReportSelectionInfoById(articleId)
  962. if errArt != nil {
  963. br.Msg = "内容不存在"
  964. br.ErrMsg = "内容不存在,Err:" + errArt.Error()
  965. return
  966. }
  967. articleId = detail.ArticleId
  968. resp := new(cygx.HistoryReportSelectionRep)
  969. permissionNameMap, err := services.GetPermissionNameMap()
  970. if err != nil {
  971. br.Msg = "获取失败"
  972. br.ErrMsg = "获取失败 GetPermissionNameMap,Err:" + err.Error()
  973. return
  974. }
  975. listSelectionLog, err := cygx.GetReportSelectionlogListAll(articleId)
  976. if err != nil {
  977. br.Msg = "获取失败"
  978. br.ErrMsg = "GetReportSelectionlogListAll,Err:" + err.Error()
  979. return
  980. }
  981. for k, v := range listSelectionLog {
  982. listSelectionLog[k].PermissionName = permissionNameMap[v.ChartPermissionId]
  983. }
  984. //获取标的的点击次数
  985. listSelectionSubjectHistory, err := cygx.GetCygxReportSelectionSubjectHistoryList(articleId)
  986. if err != nil && err.Error() != utils.ErrNoRow() {
  987. br.Msg = "获取失败"
  988. br.ErrMsg = "GetCygxReportSelectionSubjectHistoryList,Err:" + err.Error()
  989. return
  990. }
  991. mapSubjectHistory := make(map[string]int) // 标的点击数量
  992. mapIndustrialHistory := make(map[string]int) // 产业点击数量
  993. for _, v := range listSelectionSubjectHistory {
  994. mapSubjectHistory[v.IndustrialSubjectId]++
  995. if v.IndustrialSubjectId == "0" && v.IndustrialManagementId > 0 {
  996. mapIndustrialHistory[strconv.Itoa(v.IndustrialManagementId)]++
  997. }
  998. }
  999. //排序方式修改
  1000. permissionNameList := []*cygx.HistoryReportSelectionChart{{ChartPermissionName: "消费"}, {ChartPermissionName: "医药"}, {ChartPermissionName: "科技"}, {ChartPermissionName: "智造"}}
  1001. for _, v := range permissionNameList {
  1002. v.List = make([]*cygx.HistoryReportSelectionLogResp, 0)
  1003. for _, v2 := range listSelectionLog {
  1004. if v.ChartPermissionName == v2.PermissionName {
  1005. item := new(cygx.HistoryReportSelectionLogResp)
  1006. if (v2.IndustrialSubjectId == "" || v2.IndustrialSubjectId == "0") && v2.IndustrialManagementId != "" {
  1007. item.SubjectName = v2.IndustrialManagementNames
  1008. item.Count = mapIndustrialHistory[v2.IndustrialManagementId]
  1009. } else {
  1010. item.SubjectName = v2.SubjectName
  1011. item.IndustrialSubjectId = v2.IndustrialSubjectId
  1012. item.Count = mapSubjectHistory[v2.IndustrialSubjectId]
  1013. }
  1014. item.IsNew = v2.IsNew
  1015. resp.Count += item.Count
  1016. v.List = append(v.List, item)
  1017. }
  1018. }
  1019. }
  1020. resp.List = permissionNameList
  1021. br.Ret = 200
  1022. br.Success = true
  1023. br.Msg = "获取成功"
  1024. br.Data = resp
  1025. }
  1026. // @Title 报告精选申请记录
  1027. // @Description 报告精选申请记录接口
  1028. // @Param ArticleId query int true "报告Id"
  1029. // @Success Ret=200 {object} cygx.DetailCygxReportSelectionRep
  1030. // @router /reportSelection/tarryList [get]
  1031. func (this *ReportSelectionController) RarryList() {
  1032. br := new(models.BaseResponse).Init()
  1033. defer func() {
  1034. this.Data["json"] = br
  1035. this.ServeJSON()
  1036. }()
  1037. AdminUser := this.SysUser
  1038. if AdminUser == nil {
  1039. br.Msg = "请登录"
  1040. br.ErrMsg = "请登录,用户信息为空"
  1041. br.Ret = 408
  1042. return
  1043. }
  1044. articleId, _ := this.GetInt("ArticleId")
  1045. resp := new(cygx.CygxReportSelectionLogApplyListResp)
  1046. var condition string
  1047. var pars []interface{}
  1048. condition = " AND article_id = ? ORDER BY create_time DESC "
  1049. pars = append(pars, articleId)
  1050. list, err := cygx.GetCygxReportSelectionLogApplyRespList(condition, pars, 0, 0)
  1051. if err != nil {
  1052. br.Msg = "获取信息失败"
  1053. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1054. return
  1055. }
  1056. if len(list) == 0 {
  1057. list = make([]*cygx.CygxReportSelectionLogApplyResp, 0)
  1058. }
  1059. resp.List = list
  1060. br.Ret = 200
  1061. br.Success = true
  1062. br.Msg = "获取成功"
  1063. br.Data = resp
  1064. }