report_selection.go 36 KB

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