activity_video.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  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/utils"
  11. "os"
  12. "path/filepath"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. // 活动
  18. type ActivityVideoCoAntroller struct {
  19. controllers.BaseAuthController
  20. }
  21. // @Title 活动列表
  22. // @Description 获取活动列表接口
  23. // @Param PageSize query int true "每页数据条数"
  24. // @Param CurrentIndex query int true "当前页页码,从1开始"
  25. // @Param ChartPermissionId query string false "行业id"
  26. // @Param ActivityTypeId query string false "活动类型id"
  27. // @Param StartDate query string false "开始时间 ,列如2021-03-06 "
  28. // @Param EndDate query string false "结束时间,列如2021-03-06 "
  29. // @Param KeyWord query string false "搜索关键词"
  30. // @Param SortType query string false "排序顺序:asc、desc"
  31. // @Success 200 {object} cygx.CygxActivityVideoListRep
  32. // @router /activityVideo/list [get]
  33. func (this *ActivityVideoCoAntroller) ActivityVideoList() {
  34. br := new(models.BaseResponse).Init()
  35. defer func() {
  36. this.Data["json"] = br
  37. this.ServeJSON()
  38. }()
  39. sysUser := this.SysUser
  40. if sysUser == nil {
  41. br.Msg = "请登录"
  42. br.ErrMsg = "请登录,SysUser Is Empty"
  43. return
  44. }
  45. pageSize, _ := this.GetInt("PageSize")
  46. currentIndex, _ := this.GetInt("CurrentIndex")
  47. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  48. ActivityTypeId, _ := this.GetInt("ActivityTypeId")
  49. startDate := this.GetString("StartDate")
  50. endDate := this.GetString("EndDate")
  51. keyWord := this.GetString("KeyWord")
  52. sortType := this.GetString("SortType")
  53. var startSize int
  54. if pageSize <= 0 {
  55. pageSize = utils.PageSize20
  56. }
  57. if currentIndex <= 0 {
  58. currentIndex = 1
  59. }
  60. startSize = utils.StartIndex(currentIndex, pageSize)
  61. var condition string
  62. var pars []interface{}
  63. if keyWord != "" {
  64. condition += ` AND (v.video_name LIKE '%` + keyWord + `%' ) `
  65. }
  66. //行业名称
  67. if chartPermissionId > 0 {
  68. condition += ` AND art.chart_permission_id = ? `
  69. pars = append(pars, chartPermissionId)
  70. }
  71. if startDate != "" {
  72. condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'"
  73. }
  74. if endDate != "" {
  75. condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'"
  76. }
  77. if ActivityTypeId > 0 {
  78. condition += ` AND art.activity_type_id = ? `
  79. pars = append(pars, ActivityTypeId)
  80. }
  81. total, err := cygx.GetActivityVideoCount(condition, pars)
  82. if err != nil {
  83. br.Msg = "获取失败"
  84. br.ErrMsg = "获取失败,Err:" + err.Error()
  85. return
  86. }
  87. if sortType == "asc" || sortType == "desc" {
  88. condition += ` ORDER BY v.video_counts ` + sortType
  89. } else {
  90. condition += ` ORDER BY art.activity_time DESC `
  91. }
  92. list, errList := cygx.GetActivityVideoListAll(condition, pars, startSize, pageSize)
  93. if errList != nil {
  94. br.Msg = "获取失败"
  95. br.ErrMsg = "获取失败,Err:" + errList.Error()
  96. return
  97. }
  98. var activityIds string
  99. for k, v := range list {
  100. if v.ChartPermissionNames != "" {
  101. list[k].ChartPermissionName = v.ChartPermissionNames
  102. }
  103. activityIds += strconv.Itoa(v.ActivityId) + ","
  104. }
  105. activityIds = strings.TrimRight(activityIds, ",")
  106. mapIndustrial := make(map[int]string)
  107. mapSubject := make(map[string]string)
  108. if activityIds != "" {
  109. industrialList, err := cygx.GetIndustrialActivityGroupListByactivityIds(activityIds)
  110. if err != nil {
  111. br.Msg = "获取失败"
  112. br.ErrMsg = "获取失败,GetIndustrialActivityGroupListByactivityIds Err:" + err.Error()
  113. return
  114. }
  115. subjectList, err := cygx.GetSubjectActivityGroupListByactivityIds(activityIds)
  116. if err != nil {
  117. br.Msg = "获取失败"
  118. br.ErrMsg = "获取失败,GetSubjectActivityGroupListByactivityIds Err:" + err.Error()
  119. return
  120. }
  121. //合并活动对应的多个标的
  122. for _, v := range subjectList {
  123. mapSubject[fmt.Sprint(v.ActivityId, "_", v.IndustrialManagementId)] += v.SubjectName + "/"
  124. }
  125. //活动对应的产业
  126. for _, v := range industrialList {
  127. var labelSubject string
  128. labelSubject = mapSubject[fmt.Sprint(v.ActivityId, "_", v.IndustrialManagementId)]
  129. if labelSubject != "" {
  130. mapIndustrial[v.ActivityId] += v.IndustryName + "--" + strings.TrimRight(labelSubject, "/") + ","
  131. } else {
  132. mapIndustrial[v.ActivityId] += v.IndustryName + ","
  133. }
  134. }
  135. }
  136. for k, v := range list {
  137. if mapIndustrial[v.ActivityId] != "" && v.TemporaryLabel == "" {
  138. list[k].Label = strings.TrimRight(mapIndustrial[v.ActivityId], ",")
  139. }
  140. }
  141. if len(list) == 0 {
  142. list = make([]*cygx.CygxActivityVideoListResp, 0)
  143. }
  144. page := paging.GetPaging(currentIndex, pageSize, total)
  145. resp := new(cygx.CygxActivityVideoListRep)
  146. resp.List = list
  147. resp.Paging = page
  148. br.Ret = 200
  149. br.Success = true
  150. br.Msg = "获取成功"
  151. br.Data = resp
  152. }
  153. // @Title 音频播放详情
  154. // @Description 音频播放详情接口
  155. // @Param VideoId query int true "视频Id"
  156. // @Success Ret=200 发布成功
  157. // @router /activityVideo/deatil [get]
  158. func (this *ActivityVideoCoAntroller) VideoDeatil() {
  159. br := new(models.BaseResponse).Init()
  160. defer func() {
  161. this.Data["json"] = br
  162. this.ServeJSON()
  163. }()
  164. sysUser := this.SysUser
  165. if sysUser == nil {
  166. br.Msg = "请登录"
  167. br.ErrMsg = "请登录,SysUser Is Empty"
  168. br.Ret = 408
  169. return
  170. }
  171. videoId, _ := this.GetInt("VideoId")
  172. if videoId <= 0 {
  173. br.Msg = "参数错误"
  174. return
  175. }
  176. var condition string
  177. var pars []interface{}
  178. condition += `AND v.video_id= ? `
  179. pars = append(pars, videoId)
  180. list, err := cygx.GetActivityVideoHistoryById(condition, pars)
  181. if err != nil {
  182. br.Msg = "获取失败"
  183. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  184. return
  185. }
  186. for _, v := range list {
  187. v.RegisterPlatform = utils.CYGX_REGISTER_PLATFORM_MAP[v.RegisterPlatform]
  188. }
  189. br.Ret = 200
  190. br.Success = true
  191. br.Msg = "获取成功"
  192. br.Data = list
  193. }
  194. // @Title 留言详情excel表格下载
  195. // @Description 留言详情excel表格下载接口
  196. // @Param VideoId query int true "视频ID"
  197. // @Success 200 导出成功
  198. // @router /activityVideo/commnetListExport [get]
  199. func (this *ActivityVideoCoAntroller) CommentListExport() {
  200. br := new(models.BaseResponse).Init()
  201. defer func() {
  202. this.Data["json"] = br
  203. this.ServeJSON()
  204. }()
  205. sysUser := this.SysUser
  206. if sysUser == nil {
  207. br.Msg = "请登录"
  208. br.ErrMsg = "请登录,SysUser Is Empty"
  209. return
  210. }
  211. videoId, _ := this.GetInt("VideoId")
  212. videoInfo, _ := cygx.GetCygxActivityVideoReqDetailByVideoId(videoId)
  213. if videoInfo == nil {
  214. br.Msg = "操作失败"
  215. br.ErrMsg = "报告ID错误"
  216. return
  217. }
  218. var condition string
  219. var pars []interface{}
  220. condition += ` AND activity_id = ? AND video_id = ? `
  221. pars = append(pars, videoInfo.ActivityId, videoInfo.VideoId)
  222. list, err := cygx.GetArticleCommentListSearch(condition, pars)
  223. if err != nil {
  224. br.Msg = "获取失败"
  225. br.ErrMsg = "获取失败,Err:" + err.Error()
  226. return
  227. }
  228. //创建excel
  229. dir, err := os.Executable()
  230. exPath := filepath.Dir(dir)
  231. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  232. xlsxFile := xlsx.NewFile()
  233. if err != nil {
  234. br.Msg = "生成文件失败"
  235. br.ErrMsg = "生成文件失败"
  236. return
  237. }
  238. style := xlsx.NewStyle()
  239. alignment := xlsx.Alignment{
  240. Horizontal: "center",
  241. Vertical: "center",
  242. WrapText: true,
  243. }
  244. style.Alignment = alignment
  245. style.ApplyAlignment = true
  246. sheet, err := xlsxFile.AddSheet("名单")
  247. if err != nil {
  248. br.Msg = "新增Sheet失败"
  249. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  250. return
  251. }
  252. //标头
  253. rowTitle := sheet.AddRow()
  254. cellA := rowTitle.AddCell()
  255. cellA.Value = "姓名"
  256. cellB := rowTitle.AddCell()
  257. cellB.Value = "公司名称"
  258. cellC := rowTitle.AddCell()
  259. cellC.Value = "留言"
  260. cellD := rowTitle.AddCell()
  261. cellD.Value = "提交时间"
  262. for _, item := range list {
  263. row := sheet.AddRow()
  264. cellA := row.AddCell()
  265. cellA.Value = item.RealName
  266. cellB := row.AddCell()
  267. cellB.Value = item.CompanyName
  268. cellC := row.AddCell()
  269. cellC.Value = item.Content
  270. cellD := row.AddCell()
  271. cellD.Value = item.CreateTime
  272. }
  273. err = xlsxFile.Save(downLoadnFilePath)
  274. if err != nil {
  275. br.Msg = "保存文件失败"
  276. br.ErrMsg = "保存文件失败"
  277. return
  278. }
  279. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  280. downloadFileName := "留言列表" + randStr + ".xlsx"
  281. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  282. defer func() {
  283. os.Remove(downLoadnFilePath)
  284. }()
  285. br.Success = true
  286. br.Ret = 200
  287. br.Msg = "导出成功"
  288. }
  289. // @Title 留言列表详情
  290. // @Description 获取留言列表详情接口
  291. // @Param VideoId query int true "视频ID"
  292. // @Success 200 {object} cygx.ArticleCommentListResp
  293. // @router /activityVideo/commentList [get]
  294. func (this *ActivityVideoCoAntroller) CommentList() {
  295. br := new(models.BaseResponse).Init()
  296. defer func() {
  297. this.Data["json"] = br
  298. this.ServeJSON()
  299. }()
  300. sysUser := this.SysUser
  301. if sysUser == nil {
  302. br.Msg = "请登录"
  303. br.ErrMsg = "请登录,SysUser Is Empty"
  304. return
  305. }
  306. videoId, _ := this.GetInt("VideoId")
  307. videoInfo, _ := cygx.GetCygxActivityVideoReqDetailByVideoId(videoId)
  308. if videoInfo == nil {
  309. br.Msg = "操作失败"
  310. br.ErrMsg = "报告ID错误"
  311. return
  312. }
  313. var condition string
  314. var pars []interface{}
  315. condition += ` AND activity_id = ? AND video_id = ? `
  316. pars = append(pars, videoInfo.ActivityId, videoInfo.VideoId)
  317. list, err := cygx.GetArticleCommentListSearch(condition, pars)
  318. if err != nil {
  319. br.Msg = "获取失败"
  320. br.ErrMsg = "获取失败,Err:" + err.Error()
  321. return
  322. }
  323. //list, err := cygx.GetArticleCommentListByActivityVideoId(videoId)
  324. //if err != nil {
  325. // br.Msg = "获取失败"
  326. // br.ErrMsg = "获取失败,Err:" + err.Error()
  327. // return
  328. //}
  329. resp := new(cygx.ArticleCommentListResp)
  330. resp.List = list
  331. br.Ret = 200
  332. br.Success = true
  333. br.Msg = "获取成功"
  334. br.Data = resp
  335. }
  336. // @Title 获取音视频上传之后的封面图
  337. // @Description 获取音视频上传之后的封面图
  338. // @Param ActivityId query int true "活动ID"
  339. // @Param FileType query int true "音视频文件类型 。1:音频。2:视频"
  340. // @Param ChartPermissionId query int true "行业ID"
  341. // @Success 200 {object} cygx.ChartPermissionRepMoreList
  342. // @router /activityVideo/video_and_voice/img [get]
  343. func (this *ActivityVideoCoAntroller) VideoAndVoice() {
  344. br := new(models.BaseResponse).Init()
  345. defer func() {
  346. this.Data["json"] = br
  347. this.ServeJSON()
  348. }()
  349. AdminUser := this.SysUser
  350. if AdminUser == nil {
  351. br.Msg = "请登录"
  352. br.ErrMsg = "请登录,用户信息为空"
  353. br.Ret = 408
  354. return
  355. }
  356. conf, err := cygx.GetCygxConfigDetailByCode("activity_video_default_img")
  357. if err != nil {
  358. br.Msg = "获取微路演默认图配置失败" + err.Error()
  359. return
  360. }
  361. list := new(cygx.ActivityVideoDefaultImgList)
  362. if err = json.Unmarshal([]byte(conf.ConfigValue), &list); err != nil {
  363. br.Msg = "微路演默认图配置配置值解析失败" + err.Error()
  364. return
  365. }
  366. resp := new(cygx.ActivityVideoDefaultImgListResp)
  367. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  368. activityId, _ := this.GetInt("ActivityId")
  369. fileType, _ := this.GetInt("FileType")
  370. if chartPermissionId > 0 {
  371. for _, v := range list.Audio {
  372. if v.ChartPermissionId == chartPermissionId {
  373. resp.List = v.List
  374. }
  375. }
  376. } else {
  377. if activityId < 1 {
  378. br.Msg = "请输入活动ID"
  379. return
  380. }
  381. activityInfo, err := cygx.GetAddActivityInfoById(activityId)
  382. if err != nil {
  383. br.Msg = "活动不存在"
  384. br.ErrMsg = "活动ID错误,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  385. return
  386. }
  387. if activityInfo.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN { // 研选的音视频看全部行业
  388. if fileType == 1 {
  389. for _, v := range list.Audio {
  390. for _, vFile := range v.List {
  391. resp.List = append(resp.List, vFile)
  392. }
  393. }
  394. } else {
  395. for _, v := range list.Video {
  396. for _, vFile := range v.List {
  397. resp.List = append(resp.List, vFile)
  398. }
  399. }
  400. }
  401. } else {
  402. if fileType == 1 {
  403. for _, v := range list.Audio {
  404. if v.ChartPermissionId == activityInfo.ChartPermissionId {
  405. resp.List = v.List
  406. }
  407. }
  408. } else {
  409. for _, v := range list.Video {
  410. if v.ChartPermissionId == activityInfo.ChartPermissionId {
  411. resp.List = v.List
  412. }
  413. }
  414. }
  415. }
  416. //key := utils.MicroRoadshowDefaultImgKey
  417. }
  418. br.Ret = 200
  419. br.Success = true
  420. br.Msg = "获取成功"
  421. br.Data = resp
  422. }
  423. // @Title 路演反馈、调研反馈列表
  424. // @Description 路演反馈、调研反馈列表接口
  425. // @Param PageSize query int true "每页数据条数"
  426. // @Param CurrentIndex query int true "当前页页码,从1开始"
  427. // @Param ChartPermissionId query string false "行业id"
  428. // @Param ActivityTypeId query string false "活动类型id"
  429. // @Param StartDate query string false "开始时间 ,列如2021-03-06 "
  430. // @Param EndDate query string false "结束时间,列如2021-03-06 "
  431. // @Param KeyWord query string false "搜索关键词"
  432. // @Param SortType query string false "排序顺序:asc、desc"
  433. // @Param SearchType query int false "类型 1 路演回放 ,2:调研反馈"
  434. // @Param IsResearch query bool true "是否为研选"
  435. // @Success 200 {object} cygx.CygxActivityVideoListRep
  436. // @router /activity_voice_and_video/list [get]
  437. func (this *ActivityVideoCoAntroller) ActivityVoiceAndVideoList() {
  438. br := new(models.BaseResponse).Init()
  439. defer func() {
  440. this.Data["json"] = br
  441. this.ServeJSON()
  442. }()
  443. sysUser := this.SysUser
  444. if sysUser == nil {
  445. br.Msg = "请登录"
  446. br.ErrMsg = "请登录,SysUser Is Empty"
  447. return
  448. }
  449. pageSize, _ := this.GetInt("PageSize")
  450. currentIndex, _ := this.GetInt("CurrentIndex")
  451. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  452. ActivityTypeId, _ := this.GetInt("ActivityTypeId")
  453. searchType, _ := this.GetInt("SearchType", 1)
  454. startDate := this.GetString("StartDate")
  455. endDate := this.GetString("EndDate")
  456. keyWord := this.GetString("KeyWord")
  457. sortType := this.GetString("SortType")
  458. isResearch, _ := this.GetBool("IsResearch")
  459. var startSize int
  460. if pageSize <= 0 {
  461. pageSize = utils.PageSize20
  462. }
  463. if currentIndex <= 0 {
  464. currentIndex = 1
  465. }
  466. startSize = utils.StartIndex(currentIndex, pageSize)
  467. var condition string
  468. var conditionVideo string
  469. var conditionVoice string
  470. var pars []interface{}
  471. if keyWord != "" {
  472. conditionVideo += ` AND (v.video_name LIKE '%` + keyWord + `%' ) `
  473. conditionVoice += ` AND (v.voice_name LIKE '%` + keyWord + `%' ) `
  474. }
  475. if isResearch {
  476. chartPermissionId = utils.CHART_PERMISSION_ID_YANXUAN //如果是研选添加一个研选行业的筛选
  477. searchType = 0
  478. } else {
  479. condition += ` AND art.chart_permission_id != ? `
  480. pars = append(pars, utils.CHART_PERMISSION_ID_YANXUAN)
  481. }
  482. //行业名称
  483. if chartPermissionId > 0 {
  484. condition += ` AND art.chart_permission_id = ? `
  485. pars = append(pars, chartPermissionId)
  486. }
  487. if startDate != "" {
  488. condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'"
  489. }
  490. if endDate != "" {
  491. condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'"
  492. }
  493. if ActivityTypeId > 0 {
  494. condition += ` AND art.activity_type_id = ? `
  495. pars = append(pars, ActivityTypeId)
  496. }
  497. //类型 1 路演反馈 ,2:调研反馈
  498. if searchType == 1 {
  499. condition += ` AND v.file_type = 1 `
  500. } else if searchType == 2 {
  501. condition += ` AND v.file_type = 2 `
  502. }
  503. var conditionOrder string
  504. if sortType == "asc" || sortType == "desc" {
  505. conditionOrder += ` ORDER BY video_counts ` + sortType
  506. } else {
  507. conditionOrder += ` ORDER BY activity_time DESC `
  508. }
  509. list, total, err := cygx.GetActivityVoiceAndVideoList(condition, conditionVoice, conditionVideo, conditionOrder, pars, startSize, pageSize)
  510. if err != nil {
  511. br.Msg = "获取失败"
  512. br.ErrMsg = "获取失败,Err:" + err.Error()
  513. return
  514. }
  515. var activityIds string
  516. for k, v := range list {
  517. if v.ChartPermissionNames != "" {
  518. list[k].ChartPermissionName = v.ChartPermissionNames
  519. }
  520. activityIds += strconv.Itoa(v.ActivityId) + ","
  521. }
  522. activityIds = strings.TrimRight(activityIds, ",")
  523. mapIndustrial := make(map[int]string)
  524. mapSubject := make(map[string]string)
  525. if activityIds != "" {
  526. industrialList, err := cygx.GetIndustrialActivityGroupListByactivityIds(activityIds)
  527. if err != nil {
  528. br.Msg = "获取失败"
  529. br.ErrMsg = "获取失败,GetIndustrialActivityGroupListByactivityIds Err:" + err.Error()
  530. return
  531. }
  532. subjectList, err := cygx.GetSubjectActivityGroupListByactivityIds(activityIds)
  533. if err != nil {
  534. br.Msg = "获取失败"
  535. br.ErrMsg = "获取失败,GetSubjectActivityGroupListByactivityIds Err:" + err.Error()
  536. return
  537. }
  538. //合并活动对应的多个标的
  539. for _, v := range subjectList {
  540. mapSubject[fmt.Sprint(v.ActivityId, "_", v.IndustrialManagementId)] += v.SubjectName + "/"
  541. }
  542. //活动对应的产业
  543. for _, v := range industrialList {
  544. var labelSubject string
  545. labelSubject = mapSubject[fmt.Sprint(v.ActivityId, "_", v.IndustrialManagementId)]
  546. if labelSubject != "" {
  547. mapIndustrial[v.ActivityId] += v.IndustryName + "--" + strings.TrimRight(labelSubject, "/") + ","
  548. } else {
  549. mapIndustrial[v.ActivityId] += v.IndustryName + ","
  550. }
  551. }
  552. //处理音视文件标识
  553. mapVoice := make(map[int]bool)
  554. //var conditionVoice string
  555. var parsVoice []interface{}
  556. conditionVoice = " AND activity_id IN (" + activityIds + ") "
  557. listVoice, err := cygx.GetActivityVoiceList(conditionVoice, parsVoice)
  558. if err != nil && err.Error() != utils.ErrNoRow() {
  559. br.Msg = "获取失败"
  560. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  561. return
  562. }
  563. if len(listVoice) > 0 {
  564. for _, v := range listVoice {
  565. mapVoice[v.ActivityId] = true
  566. }
  567. }
  568. for k, v := range list {
  569. if mapIndustrial[v.ActivityId] != "" && v.TemporaryLabel == "" {
  570. list[k].Label = strings.TrimRight(mapIndustrial[v.ActivityId], ",")
  571. }
  572. if mapVoice[v.ActivityId] {
  573. v.FileName = "音频"
  574. } else {
  575. v.FileName = "视频"
  576. }
  577. }
  578. if len(list) == 0 {
  579. list = make([]*cygx.CygxActivityVideoListResp, 0)
  580. }
  581. }
  582. page := paging.GetPaging(currentIndex, pageSize, total)
  583. resp := new(cygx.CygxActivityVideoListRep)
  584. resp.List = list
  585. resp.Paging = page
  586. br.Ret = 200
  587. br.Success = true
  588. br.Msg = "获取成功"
  589. br.Data = resp
  590. }
  591. // @Title 留言列表详情
  592. // @Description 获取留言列表详情接口
  593. // @Param ActivityId query int true "活动ID"
  594. // @Param IsExport query bool false "是否导出excel,默认是false"
  595. // @Success 200 {object} cygx.ArticleCommentListResp
  596. // @router /activity_voice_and_video/commentList [get]
  597. func (this *ActivityVideoCoAntroller) VoiceAndVideoCommentList() {
  598. br := new(models.BaseResponse).Init()
  599. defer func() {
  600. this.Data["json"] = br
  601. this.ServeJSON()
  602. }()
  603. sysUser := this.SysUser
  604. if sysUser == nil {
  605. br.Msg = "请登录"
  606. br.ErrMsg = "请登录,SysUser Is Empty"
  607. return
  608. }
  609. activityId, _ := this.GetInt("ActivityId")
  610. //是否导出报表
  611. isExport, _ := this.GetBool("IsExport")
  612. var condition string
  613. var pars []interface{}
  614. videoInfo, _ := cygx.GetCygxActivityVideoReqDetail(activityId)
  615. if videoInfo != nil {
  616. condition += ` AND activity_id = ? AND video_id = ? `
  617. pars = append(pars, videoInfo.ActivityId, videoInfo.VideoId)
  618. } else {
  619. videoInfo, _ := cygx.GetMicroRoadshowVoiceById(activityId)
  620. if videoInfo == nil {
  621. br.Msg = "操作失败"
  622. br.ErrMsg = "音频ID错误"
  623. return
  624. }
  625. condition += ` AND activity_voice_id = ? `
  626. pars = append(pars, videoInfo.ActivityVoiceId)
  627. }
  628. list, err := cygx.GetArticleCommentListSearch(condition, pars)
  629. if err != nil {
  630. br.Msg = "获取失败"
  631. br.ErrMsg = "获取失败,Err:" + err.Error()
  632. return
  633. }
  634. resp := new(cygx.ArticleCommentListResp)
  635. resp.List = list
  636. //导出excel
  637. if isExport {
  638. VoiceAndVideoCommentListExport(this, resp, br)
  639. return
  640. }
  641. br.Ret = 200
  642. br.Success = true
  643. br.Msg = "获取成功"
  644. br.Data = resp
  645. }
  646. // VoiceAndVideoCommentListExport 导出Excel
  647. func VoiceAndVideoCommentListExport(this *ActivityVideoCoAntroller, resp *cygx.ArticleCommentListResp, br *models.BaseResponse) {
  648. //创建excel
  649. dir, err := os.Executable()
  650. exPath := filepath.Dir(dir)
  651. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  652. xlsxFile := xlsx.NewFile()
  653. if err != nil {
  654. br.Msg = "生成文件失败"
  655. br.ErrMsg = "生成文件失败"
  656. return
  657. }
  658. style := xlsx.NewStyle()
  659. alignment := xlsx.Alignment{
  660. Horizontal: "center",
  661. Vertical: "center",
  662. WrapText: true,
  663. }
  664. style.Alignment = alignment
  665. style.ApplyAlignment = true
  666. sheet, err := xlsxFile.AddSheet("阅读明细")
  667. if err != nil {
  668. br.Msg = "新增Sheet失败"
  669. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  670. return
  671. }
  672. //标头
  673. rowTitle := sheet.AddRow()
  674. cellA := rowTitle.AddCell()
  675. cellA.Value = "姓名"
  676. cellB := rowTitle.AddCell()
  677. cellB.Value = "公司名称"
  678. cellC := rowTitle.AddCell()
  679. cellC.Value = "留言"
  680. cellD := rowTitle.AddCell()
  681. cellD.Value = "提交时间"
  682. for _, item := range resp.List {
  683. row := sheet.AddRow()
  684. cellA := row.AddCell()
  685. cellA.Value = item.RealName
  686. cellB := row.AddCell()
  687. cellB.Value = item.CompanyName
  688. cellC := row.AddCell()
  689. cellC.Value = item.Content
  690. cellD := row.AddCell()
  691. cellD.Value = item.CreateTime
  692. }
  693. err = xlsxFile.Save(downLoadnFilePath)
  694. if err != nil {
  695. br.Msg = "保存文件失败"
  696. br.ErrMsg = "保存文件失败"
  697. return
  698. }
  699. downloadFileName := time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  700. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  701. defer func() {
  702. os.Remove(downLoadnFilePath)
  703. }()
  704. br.Ret = 200
  705. br.Success = true
  706. br.Msg = "导出成功"
  707. }