micro_roadshow.go 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "github.com/tealeg/xlsx"
  6. "hongze/hz_crm_api/controllers"
  7. "hongze/hz_crm_api/models"
  8. "hongze/hz_crm_api/models/cygx"
  9. cygxService "hongze/hz_crm_api/services/cygx"
  10. "hongze/hz_crm_api/utils"
  11. "os"
  12. "path/filepath"
  13. "strings"
  14. "time"
  15. )
  16. // 活动类型
  17. type MicroRoadshowController struct {
  18. controllers.BaseAuthController
  19. }
  20. // @Title 微路演视频列表
  21. // @Description 微路演视频列表
  22. // @Success 200 {object} cygx.MicroRoadshowVideoListResp
  23. // @Param PageSize query int true "每页数据条数"
  24. // @Param CurrentIndex query int true "当前页页码,从1开始"
  25. // @Param KeyWord query string false "搜索关键词"
  26. // @Param StartDate query string false "开始时间"
  27. // @Param EndDate query string false "结束时间"
  28. // @Param PublishStatus query string false "发布状态"
  29. // @Param ChartPermissionId query string false "行业Id"
  30. // @Param VideoId query string false "视频Id"
  31. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  32. // @Param SortParam query string false "排序字段参数,用来排序的字段 "
  33. // @router /microRoadshow/video/list [get]
  34. func (this *MicroRoadshowController) List() {
  35. br := new(models.BaseResponse).Init()
  36. defer func() {
  37. this.Data["json"] = br
  38. this.ServeJSON()
  39. }()
  40. sysUser := this.SysUser
  41. if sysUser == nil {
  42. br.Msg = "请登录"
  43. br.ErrMsg = "请登录,SysUser Is Empty"
  44. br.Ret = 408
  45. return
  46. }
  47. pageSize, _ := this.GetInt("PageSize")
  48. currentIndex, _ := this.GetInt("CurrentIndex")
  49. keyWord := this.GetString("KeyWord")
  50. startDate := this.GetString("StartDate")
  51. endDate := this.GetString("EndDate")
  52. publishStatus, _ := this.GetInt("PublishStatus", -1)
  53. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  54. sortParam := this.GetString("SortParam")
  55. sortType := this.GetString("SortType")
  56. keyWord = strings.Trim(keyWord, " ")
  57. keyWord = strings.Replace(keyWord, "'", "", -1)
  58. var condition string
  59. var pars []interface{}
  60. var startSize int
  61. if pageSize <= 0 {
  62. pageSize = utils.PageSize20
  63. }
  64. if currentIndex <= 0 {
  65. currentIndex = 1
  66. }
  67. startSize = paging.StartIndex(currentIndex, pageSize)
  68. if keyWord != "" {
  69. condition += ` AND (video_name LIKE '%` + keyWord + `%' ) `
  70. }
  71. if startDate != "" {
  72. condition += ` AND publish_date>=? `
  73. pars = append(pars, startDate)
  74. }
  75. if endDate != "" {
  76. condition += ` AND publish_date<=? `
  77. pars = append(pars, endDate)
  78. }
  79. if chartPermissionId > 0 {
  80. condition += ` AND chart_permission_id=? `
  81. pars = append(pars, chartPermissionId)
  82. }
  83. if publishStatus > -1 {
  84. condition += ` AND publish_status=? `
  85. pars = append(pars, publishStatus)
  86. }
  87. sortStr := ``
  88. if sortParam != "" && sortType != "" {
  89. if sortParam == "videoCounts" {
  90. if sortType == "asc" {
  91. sortStr = " ORDER BY video_counts "
  92. } else {
  93. sortStr = " ORDER BY video_counts DESC "
  94. }
  95. }
  96. } else {
  97. sortStr = " ORDER BY publish_date DESC "
  98. }
  99. total, err := cygx.GetMicroRoadshowVideoListCount(condition, pars)
  100. if err != nil {
  101. br.Msg = "获取失败"
  102. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  103. return
  104. }
  105. list, err := cygx.GetMicroRoadshowVideoList(condition, sortStr, pars, startSize, pageSize)
  106. if err != nil {
  107. br.Msg = "获取失败"
  108. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  109. return
  110. }
  111. respList := make([]*cygx.CygxMicroRoadshowVideoResp, 0)
  112. for _, video := range list {
  113. respItem := cygx.CygxMicroRoadshowVideoResp{
  114. VideoId: video.VideoId,
  115. VideoName: video.VideoName,
  116. ChartPermissionId: video.ChartPermissionId,
  117. ChartPermissionName: video.ChartPermissionName,
  118. IndustryId: video.IndustryId,
  119. IndustryName: video.IndustryName,
  120. PublishStatus: video.PublishStatus,
  121. ModifyDate: video.ModifyDate,
  122. PublishDate: video.PublishDate.Format(utils.FormatDate),
  123. VideoDuration: video.VideoDuration,
  124. VideoCounts: video.VideoCounts,
  125. VideoUrl: video.VideoUrl,
  126. CreateTime: video.CreateTime,
  127. ImgUrl: video.ImgUrl,
  128. ShareImgUrl: video.ShareImgUrl,
  129. DetailImgUrl: video.DetailImgUrl,
  130. CommentNum: video.CommentNum,
  131. }
  132. respList = append(respList, &respItem)
  133. }
  134. if list == nil {
  135. list = make([]*cygx.CygxMicroRoadshowVideo, 0)
  136. }
  137. resp := new(cygx.MicroRoadshowVideoListResp)
  138. page := paging.GetPaging(currentIndex, pageSize, total)
  139. resp.List = respList
  140. resp.Paging = page
  141. br.Ret = 200
  142. br.Success = true
  143. br.Msg = "获取成功"
  144. br.Data = resp
  145. }
  146. // @Title 保存视频
  147. // @Description 保存视频接口
  148. // @Param request body cygx.VideoAddReq true "type json string"
  149. // @Success 200 保存成功
  150. // @router /microRoadshow/video/add [post]
  151. func (this *MicroRoadshowController) Add() {
  152. br := new(models.BaseResponse).Init()
  153. defer func() {
  154. this.Data["json"] = br
  155. this.ServeJSON()
  156. }()
  157. sysUser := this.SysUser
  158. if sysUser == nil {
  159. br.Msg = "请登录"
  160. br.ErrMsg = "请登录,SysUser Is Empty"
  161. br.Ret = 408
  162. return
  163. }
  164. var req cygx.VideoAddReq
  165. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  166. if err != nil {
  167. br.Msg = "参数解析异常!"
  168. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  169. return
  170. }
  171. if req.VideoName == "" {
  172. br.Msg = "视频名不能为空"
  173. return
  174. }
  175. if req.VideoUrl == "" {
  176. br.Msg = "视频播放地址不能为空"
  177. return
  178. }
  179. if req.IndustryId == 0 {
  180. br.Msg = "产业不能为空"
  181. return
  182. }
  183. if req.ImgUrl == "" {
  184. br.Msg = "视频封面不能为空"
  185. return
  186. }
  187. if req.ShareImgUrl == "" {
  188. br.Msg = "视频分享图不能为空"
  189. return
  190. }
  191. if req.DetailImgUrl == "" {
  192. br.Msg = "详情页封面不能为空"
  193. return
  194. }
  195. var nameItem *cygx.PermissionNameAndIndustryName
  196. nameItem, err = cygx.GetPermissionNameAndIndustryNameByIndustryId(req.IndustryId)
  197. if err != nil {
  198. br.Msg = "查询行业及产业是否存在失败!"
  199. br.ErrMsg = "查询行业及产业是否存在失败,Err:" + err.Error()
  200. return
  201. }
  202. publishDate, err := time.Parse(utils.FormatDate, req.PublishDate)
  203. if err != nil {
  204. br.Msg = "时间格式转换失败"
  205. br.ErrMsg = "时间格式转换失败,Err:" + err.Error()
  206. return
  207. }
  208. //判断该产业下是否已经存在其他视频
  209. exist, err := cygx.GetMicroRoadshowVideoByIndustryId(req.IndustryId)
  210. if err != nil {
  211. if err.Error() != utils.ErrNoRow() {
  212. br.Msg = "查询视频详情失败"
  213. br.ErrMsg = "查询视频详情失败,Err:" + err.Error()
  214. return
  215. }
  216. } else {
  217. if req.VideoId > 0 && req.VideoId != exist.VideoId {
  218. br.Msg = "该产业下已有产业视频"
  219. return
  220. }
  221. if req.VideoId == 0 {
  222. br.Msg = "该产业下已有产业视频"
  223. return
  224. }
  225. }
  226. if req.VideoId > 0 {
  227. //更新
  228. item := cygx.CygxMicroRoadshowVideo{
  229. VideoId: req.VideoId,
  230. VideoName: "5min" + "【" + nameItem.IndustryName + "】" + "逻辑解析",
  231. ChartPermissionId: nameItem.PermissionId,
  232. ChartPermissionName: nameItem.PermissionName,
  233. IndustryId: req.IndustryId,
  234. IndustryName: nameItem.IndustryName,
  235. ModifyDate: time.Now().Format(utils.FormatDateTime),
  236. PublishStatus: req.PublishOrSave,
  237. PublishDate: publishDate,
  238. VideoDuration: req.VideoDuration,
  239. VideoUrl: req.VideoUrl,
  240. ImgUrl: req.ImgUrl,
  241. ShareImgUrl: req.ShareImgUrl,
  242. DetailImgUrl: req.DetailImgUrl,
  243. }
  244. err = cygx.EditVideo(&item)
  245. if err != nil {
  246. br.Msg = "编辑失败"
  247. br.ErrMsg = "编辑失败,Err:" + err.Error()
  248. return
  249. }
  250. if req.PublishOrSave == 1 {
  251. go cygxService.SendWxMsgWithCygxMicroRoadshowVideo(req.VideoId)
  252. }
  253. go cygxService.UpdateResourceData(req.VideoId, "roadshow", "update", publishDate.Format(utils.FormatDateTime))
  254. br.Ret = 200
  255. br.Success = true
  256. br.Msg = "编辑成功"
  257. } else {
  258. videoCount, err := cygx.GetMicroRoadshowVideoByTitle(req.VideoName)
  259. if err != nil {
  260. br.Msg = "判断标题是否存在失败!"
  261. br.ErrMsg = "判断标题是否存在失败,Err:" + err.Error()
  262. return
  263. }
  264. if videoCount > 0 {
  265. br.Msg = "标题已存在!"
  266. br.IsSendEmail = false
  267. return
  268. }
  269. item := cygx.CygxMicroRoadshowVideo{
  270. VideoName: "5min" + "【" + nameItem.IndustryName + "】" + "逻辑解析",
  271. ChartPermissionId: nameItem.PermissionId,
  272. ChartPermissionName: nameItem.PermissionName,
  273. IndustryId: req.IndustryId,
  274. IndustryName: nameItem.IndustryName,
  275. PublishStatus: req.PublishOrSave,
  276. ModifyDate: time.Now().Format(utils.FormatDateTime),
  277. PublishDate: publishDate,
  278. VideoDuration: req.VideoDuration,
  279. VideoUrl: req.VideoUrl,
  280. ImgUrl: req.ImgUrl,
  281. ShareImgUrl: req.ShareImgUrl,
  282. DetailImgUrl: req.DetailImgUrl,
  283. CreateTime: time.Now().Format(utils.FormatDateTime),
  284. }
  285. newId, err := cygx.AddMicroRoadshowVideo(&item)
  286. if err != nil {
  287. br.Msg = "保存失败"
  288. br.ErrMsg = "保存失败,Err:" + err.Error()
  289. return
  290. }
  291. if req.PublishOrSave == 1 {
  292. go cygxService.SendWxMsgWithCygxMicroRoadshowVideo(int(newId))
  293. go cygxService.UpdateResourceData(int(newId), "roadshow", "add", publishDate.Format(utils.FormatDateTime))
  294. }
  295. br.Ret = 200
  296. br.Success = true
  297. br.Msg = "保存成功"
  298. }
  299. }
  300. // @Title 编辑视频
  301. // @Description 编辑视频接口
  302. // @Param request body cygx.VideoEditReq true "type json string"
  303. // @Success Ret=200 编辑成功
  304. // @router /microRoadshow/video/edit [post]
  305. func (this *MicroRoadshowController) Edit() {
  306. br := new(models.BaseResponse).Init()
  307. defer func() {
  308. this.Data["json"] = br
  309. this.ServeJSON()
  310. }()
  311. sysUser := this.SysUser
  312. if sysUser == nil {
  313. br.Msg = "请登录"
  314. br.ErrMsg = "请登录,SysUser Is Empty"
  315. br.Ret = 408
  316. return
  317. }
  318. var req cygx.VideoEditReq
  319. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  320. if err != nil {
  321. br.Msg = "参数解析异常!"
  322. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  323. return
  324. }
  325. if req.VideoName == "" {
  326. br.Msg = "标题不能为空"
  327. return
  328. }
  329. if req.VideoUrl == "" {
  330. br.Msg = "视频地址不能为空"
  331. return
  332. }
  333. publishDate, err := time.Parse(utils.FormatDate, req.PublishDate)
  334. if err != nil {
  335. br.Msg = "时间格式转换失败"
  336. br.ErrMsg = "时间格式转换失败,Err:" + err.Error()
  337. return
  338. }
  339. var nameItem *cygx.PermissionNameAndIndustryName
  340. nameItem, err = cygx.GetPermissionNameAndIndustryNameByIndustryId(req.IndustryId)
  341. if err != nil {
  342. br.Msg = "查询行业及产业是否存在失败!"
  343. br.ErrMsg = "查询行业及产业是否存在失败,Err:" + err.Error()
  344. return
  345. }
  346. item := cygx.CygxMicroRoadshowVideo{
  347. VideoId: req.VideoId,
  348. VideoName: "5min" + "【" + nameItem.IndustryName + "】" + "逻辑解析",
  349. ChartPermissionId: req.ChartPermissionId,
  350. IndustryId: req.IndustryId,
  351. ModifyDate: time.Now().Format(utils.FormatDateTime),
  352. PublishDate: publishDate,
  353. VideoDuration: req.VideoDuration,
  354. VideoUrl: req.VideoUrl,
  355. }
  356. err = cygx.EditVideo(&item)
  357. if err != nil {
  358. br.Msg = "编辑失败"
  359. br.ErrMsg = "编辑失败,Err:" + err.Error()
  360. return
  361. }
  362. br.Ret = 200
  363. br.Success = true
  364. br.Msg = "编辑成功"
  365. }
  366. // @Title 取消视频发布
  367. // @Description 取消视频发布接口
  368. // @Param VideoId query int true "视频Id"
  369. // @Param PublishOrCancle query int true "发布或取消发布"
  370. // @Success Ret=200 发布成功
  371. // @router /microRoadshow/video/publish [get]
  372. func (this *MicroRoadshowController) PublishCancel() {
  373. br := new(models.BaseResponse).Init()
  374. defer func() {
  375. this.Data["json"] = br
  376. this.ServeJSON()
  377. }()
  378. sysUser := this.SysUser
  379. if sysUser == nil {
  380. br.Msg = "请登录"
  381. br.ErrMsg = "请登录,SysUser Is Empty"
  382. br.Ret = 408
  383. return
  384. }
  385. videoId, _ := this.GetInt("VideoId")
  386. publishOrCancle, _ := this.GetInt("PublishOrCancle")
  387. if videoId <= 0 {
  388. br.Msg = "参数错误"
  389. return
  390. }
  391. err := cygx.PublishVideoCancel(videoId, publishOrCancle)
  392. if err != nil {
  393. br.Msg = "取消发布失败"
  394. br.ErrMsg = "取消发布失败,Err:" + err.Error()
  395. return
  396. }
  397. videoInfo, _ := cygx.GetMicroRoadshowVideoByVideoId(videoId)
  398. if videoInfo == nil {
  399. br.Msg = "操作失败"
  400. br.ErrMsg = "视频ID错误"
  401. return
  402. }
  403. br.Ret = 200
  404. br.Success = true
  405. if publishOrCancle == 0 {
  406. br.Msg = "取消发布成功"
  407. go cygxService.UpdateResourceData(int(videoId), "roadshow", "delete", time.Now().Format(utils.FormatDateTime))
  408. } else {
  409. go cygxService.SendWxMsgWithCygxMicroRoadshowVideo(videoId)
  410. go cygxService.UpdateResourceData(int(videoId), "roadshow", "add", videoInfo.PublishDate.Format(utils.FormatDateTime))
  411. br.Msg = "发布成功"
  412. }
  413. }
  414. // @Title 视频详情
  415. // @Description 视频详情接口
  416. // @Param VideoId query int true "视频Id"
  417. // @Param PageSize query int true "每页数据条数"
  418. // @Param CurrentIndex query int true "当前页页码,从1开始"
  419. // @Success Ret=200 发布成功
  420. // @router /microRoadshow/video/deatil [get]
  421. func (this *MicroRoadshowController) Deatil() {
  422. br := new(models.BaseResponse).Init()
  423. defer func() {
  424. this.Data["json"] = br
  425. this.ServeJSON()
  426. }()
  427. sysUser := this.SysUser
  428. if sysUser == nil {
  429. br.Msg = "请登录"
  430. br.ErrMsg = "请登录,SysUser Is Empty"
  431. br.Ret = 408
  432. return
  433. }
  434. videoId, _ := this.GetInt("VideoId")
  435. //pageSize, _ := this.GetInt("PageSize")
  436. //currentIndex, _ := this.GetInt("CurrentIndex")
  437. if videoId <= 0 {
  438. br.Msg = "参数错误"
  439. return
  440. }
  441. //var startSize int
  442. //if pageSize <= 0 {
  443. // pageSize = utils.PageSize20
  444. //}
  445. //if currentIndex <= 0 {
  446. // currentIndex = 1
  447. //}
  448. //startSize = paging.StartIndex(currentIndex, pageSize)
  449. var condition string
  450. var pars []interface{}
  451. condition += `AND video_id= ? `
  452. pars = append(pars, videoId)
  453. //total, err := cygx.GetMicroRoadshowVideoListCount(condition, pars)
  454. //if err != nil {
  455. // br.Msg = "获取失败"
  456. // br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  457. // return
  458. //}
  459. list, err := cygx.GetMicroRoadshowVideoHistoryById(condition, pars)
  460. if err != nil && err.Error() != utils.ErrNoRow() {
  461. br.Msg = "获取历史详情失败"
  462. br.ErrMsg = "获取历史详情失败,Err:" + err.Error()
  463. return
  464. }
  465. //resp := new(cygx.MicroRoadshowVideoHistoryListResp)
  466. //page := paging.GetPaging(currentIndex, pageSize, total)
  467. //resp.List = list
  468. //resp.Paging = page
  469. br.Ret = 200
  470. br.Success = true
  471. br.Msg = "获取成功"
  472. br.Data = list
  473. }
  474. // @Title 微路演音频列表
  475. // @Description 微路演音频列表
  476. // @Success 200 {object} cygx.MicroRoadshowVideoListResp
  477. // @Param PageSize query int true "每页数据条数"
  478. // @Param CurrentIndex query int true "当前页页码,从1开始"
  479. // @Param KeyWord query string true "搜索关键词"
  480. // @Param StartDate query string true "开始时间"
  481. // @Param EndDate query string true "结束时间"
  482. // @Param ChartPermissionId query string true "行业Id"
  483. // @Param ActivityTypeId query string true "活动类型ID"
  484. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  485. // @Param SortParam query string false "排序字段参数,用来排序的字段 "
  486. // @router /microRoadshow/voice/list [get]
  487. func (this *MicroRoadshowController) VoiceList() {
  488. br := new(models.BaseResponse).Init()
  489. defer func() {
  490. this.Data["json"] = br
  491. this.ServeJSON()
  492. }()
  493. sysUser := this.SysUser
  494. if sysUser == nil {
  495. br.Msg = "请登录"
  496. br.ErrMsg = "请登录,SysUser Is Empty"
  497. br.Ret = 408
  498. return
  499. }
  500. pageSize, _ := this.GetInt("PageSize")
  501. currentIndex, _ := this.GetInt("CurrentIndex")
  502. keyWord := this.GetString("KeyWord")
  503. startDate := this.GetString("StartDate")
  504. endDate := this.GetString("EndDate")
  505. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  506. activityTypeId, _ := this.GetInt("ActivityTypeId")
  507. sortParam := this.GetString("SortParam")
  508. sortType := this.GetString("SortType")
  509. keyWord = strings.Trim(keyWord, " ")
  510. keyWord = strings.Replace(keyWord, "'", "", -1)
  511. var condition string
  512. var pars []interface{}
  513. var startSize int
  514. if pageSize <= 0 {
  515. pageSize = utils.PageSize20
  516. }
  517. if currentIndex <= 0 {
  518. currentIndex = 1
  519. }
  520. startSize = paging.StartIndex(currentIndex, pageSize)
  521. if keyWord != "" {
  522. condition += ` AND (v.voice_name LIKE '%` + keyWord + `%' ) `
  523. }
  524. if startDate != "" {
  525. condition += ` AND a.activity_time>=? `
  526. pars = append(pars, startDate)
  527. }
  528. if endDate != "" {
  529. condition += ` AND a.activity_time<=? `
  530. pars = append(pars, endDate)
  531. }
  532. if chartPermissionId > 0 {
  533. condition += ` AND a.chart_permission_id=? `
  534. pars = append(pars, chartPermissionId)
  535. }
  536. if activityTypeId > 0 {
  537. condition += ` AND a.activity_type_id=? `
  538. pars = append(pars, activityTypeId)
  539. }
  540. sortStr := ``
  541. if sortParam != "" && sortType != "" {
  542. if sortParam == "voiceCounts" {
  543. if sortType == "asc" {
  544. sortStr = " ORDER BY v.voice_counts "
  545. } else {
  546. sortStr = " ORDER BY v.voice_counts DESC "
  547. }
  548. }
  549. } else {
  550. sortStr = " ORDER BY a.activity_time DESC "
  551. }
  552. total, err := cygx.GetMicroRoadshowVoiceListCount(condition, pars)
  553. if err != nil {
  554. br.Msg = "获取失败"
  555. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  556. return
  557. }
  558. list, err := cygx.GetMicroRoadshowVoiceList(condition, sortStr, pars, startSize, pageSize)
  559. if err != nil {
  560. br.Msg = "获取失败"
  561. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  562. return
  563. }
  564. resplist := make([]*cygx.CygxMicroRoadshowVoiceRsep, 0)
  565. for _, voice := range list {
  566. respItem := cygx.CygxMicroRoadshowVoiceRsep{
  567. ActivityVoiceId: voice.ActivityVoiceId,
  568. ActivityId: voice.ActivityId,
  569. VoiceName: voice.VoiceName,
  570. ChartPermissionId: voice.ChartPermissionId,
  571. ChartPermissionName: voice.ChartPermissionName,
  572. IndustryId: voice.IndustryId,
  573. IndustryName: voice.IndustryName,
  574. ModifyTime: voice.ModifyTime,
  575. PublishDate: voice.PublishDate,
  576. VoicePlaySeconds: voice.VoicePlaySeconds,
  577. VoiceCounts: voice.VoiceCounts,
  578. VoiceUrl: voice.VoiceUrl,
  579. CreateTime: voice.CreateTime,
  580. Label: voice.Label,
  581. ActivityTypeId: voice.ActivityTypeId,
  582. ActivityTypeName: voice.ActivityTypeName,
  583. ActivityTime: voice.ActivityTime.Format(utils.FormatDate),
  584. ActivityTimeText: voice.ActivityTimeText,
  585. CommentNum: voice.CommentNum,
  586. }
  587. resplist = append(resplist, &respItem)
  588. }
  589. if list == nil {
  590. list = make([]*cygx.CygxMicroRoadshowVoice, 0)
  591. }
  592. resp := new(cygx.MicroRoadshowVoiceListResp)
  593. page := paging.GetPaging(currentIndex, pageSize, total)
  594. resp.List = resplist
  595. resp.Paging = page
  596. br.Ret = 200
  597. br.Success = true
  598. br.Msg = "获取成功"
  599. br.Data = resp
  600. }
  601. // @Title 音频播放详情
  602. // @Description 音频播放详情接口
  603. // @Param VoiceId query int true "视频Id"
  604. // @Success Ret=200 发布成功
  605. // @router /microRoadshow/voice/deatil [get]
  606. func (this *MicroRoadshowController) VoiceDeatil() {
  607. br := new(models.BaseResponse).Init()
  608. defer func() {
  609. this.Data["json"] = br
  610. this.ServeJSON()
  611. }()
  612. sysUser := this.SysUser
  613. if sysUser == nil {
  614. br.Msg = "请登录"
  615. br.ErrMsg = "请登录,SysUser Is Empty"
  616. br.Ret = 408
  617. return
  618. }
  619. voiceId, _ := this.GetInt("VoiceId")
  620. if voiceId <= 0 {
  621. br.Msg = "参数错误"
  622. return
  623. }
  624. var condition string
  625. var pars []interface{}
  626. condition += `AND v.activity_voice_id= ? `
  627. pars = append(pars, voiceId)
  628. list, err := cygx.GetMicroRoadshowVoiceHistoryById(condition, pars)
  629. if err != nil {
  630. br.Msg = "获取失败"
  631. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  632. return
  633. }
  634. br.Ret = 200
  635. br.Success = true
  636. br.Msg = "获取成功"
  637. br.Data = list
  638. }
  639. // @Title 留言详情excel表格下载
  640. // @Description 留言详情excel表格下载接口
  641. // @Param VideoId query int true "视频ID"
  642. // @Success 200 导出成功
  643. // @router /microRoadshow/commentListExport/video [get]
  644. func (this *MicroRoadshowController) CommentListExport() {
  645. br := new(models.BaseResponse).Init()
  646. defer func() {
  647. this.Data["json"] = br
  648. this.ServeJSON()
  649. }()
  650. sysUser := this.SysUser
  651. if sysUser == nil {
  652. br.Msg = "请登录"
  653. br.ErrMsg = "请登录,SysUser Is Empty"
  654. return
  655. }
  656. videoId, _ := this.GetInt("VideoId")
  657. videoInfo, _ := cygx.GetMicroRoadshowVideoByVideoId(videoId)
  658. if videoInfo == nil {
  659. br.Msg = "操作失败"
  660. br.ErrMsg = "视频ID错误"
  661. return
  662. }
  663. var condition string
  664. var pars []interface{}
  665. condition += ` AND activity_id = 0 AND video_id = ? `
  666. pars = append(pars, videoInfo.VideoId)
  667. list, err := cygx.GetArticleCommentListSearch(condition, pars)
  668. if err != nil {
  669. br.Msg = "获取失败"
  670. br.ErrMsg = "获取失败,Err:" + err.Error()
  671. return
  672. }
  673. //创建excel
  674. dir, err := os.Executable()
  675. exPath := filepath.Dir(dir)
  676. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  677. xlsxFile := xlsx.NewFile()
  678. if err != nil {
  679. br.Msg = "生成文件失败"
  680. br.ErrMsg = "生成文件失败"
  681. return
  682. }
  683. style := xlsx.NewStyle()
  684. alignment := xlsx.Alignment{
  685. Horizontal: "center",
  686. Vertical: "center",
  687. WrapText: true,
  688. }
  689. style.Alignment = alignment
  690. style.ApplyAlignment = true
  691. sheet, err := xlsxFile.AddSheet("名单")
  692. if err != nil {
  693. br.Msg = "新增Sheet失败"
  694. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  695. return
  696. }
  697. //标头
  698. rowTitle := sheet.AddRow()
  699. cellA := rowTitle.AddCell()
  700. cellA.Value = "姓名"
  701. cellB := rowTitle.AddCell()
  702. cellB.Value = "公司名称"
  703. cellC := rowTitle.AddCell()
  704. cellC.Value = "留言"
  705. cellD := rowTitle.AddCell()
  706. cellD.Value = "提交时间"
  707. for _, item := range list {
  708. row := sheet.AddRow()
  709. cellA := row.AddCell()
  710. cellA.Value = item.RealName
  711. cellB := row.AddCell()
  712. cellB.Value = item.CompanyName
  713. cellC := row.AddCell()
  714. cellC.Value = item.Content
  715. cellD := row.AddCell()
  716. cellD.Value = item.CreateTime
  717. }
  718. err = xlsxFile.Save(downLoadnFilePath)
  719. if err != nil {
  720. br.Msg = "保存文件失败"
  721. br.ErrMsg = "保存文件失败"
  722. return
  723. }
  724. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  725. downloadFileName := "留言列表" + randStr + ".xlsx"
  726. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  727. defer func() {
  728. os.Remove(downLoadnFilePath)
  729. }()
  730. br.Success = true
  731. br.Ret = 200
  732. br.Msg = "导出成功"
  733. }
  734. // @Title 留言详情excel表格下载
  735. // @Description 留言详情excel表格下载接口
  736. // @Param ActivityId query int true "活动Id"
  737. // @Success 200 导出成功
  738. // @router /microRoadshow/commentListExport/voice [get]
  739. func (this *MicroRoadshowController) VoiceCommentListExport() {
  740. br := new(models.BaseResponse).Init()
  741. defer func() {
  742. this.Data["json"] = br
  743. this.ServeJSON()
  744. }()
  745. sysUser := this.SysUser
  746. if sysUser == nil {
  747. br.Msg = "请登录"
  748. br.ErrMsg = "请登录,SysUser Is Empty"
  749. return
  750. }
  751. activityId, _ := this.GetInt("ActivityId")
  752. videoInfo, _ := cygx.GetMicroRoadshowVoiceById(activityId)
  753. if videoInfo == nil {
  754. br.Msg = "操作失败"
  755. br.ErrMsg = "音频ID错误"
  756. return
  757. }
  758. var condition string
  759. var pars []interface{}
  760. condition += ` AND activity_voice_id = ? `
  761. pars = append(pars, videoInfo.ActivityVoiceId)
  762. list, err := cygx.GetArticleCommentListSearch(condition, pars)
  763. if err != nil {
  764. br.Msg = "获取失败"
  765. br.ErrMsg = "获取失败,Err:" + err.Error()
  766. return
  767. }
  768. //创建excel
  769. dir, err := os.Executable()
  770. exPath := filepath.Dir(dir)
  771. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  772. xlsxFile := xlsx.NewFile()
  773. if err != nil {
  774. br.Msg = "生成文件失败"
  775. br.ErrMsg = "生成文件失败"
  776. return
  777. }
  778. style := xlsx.NewStyle()
  779. alignment := xlsx.Alignment{
  780. Horizontal: "center",
  781. Vertical: "center",
  782. WrapText: true,
  783. }
  784. style.Alignment = alignment
  785. style.ApplyAlignment = true
  786. sheet, err := xlsxFile.AddSheet("名单")
  787. if err != nil {
  788. br.Msg = "新增Sheet失败"
  789. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  790. return
  791. }
  792. //标头
  793. rowTitle := sheet.AddRow()
  794. cellA := rowTitle.AddCell()
  795. cellA.Value = "姓名"
  796. cellB := rowTitle.AddCell()
  797. cellB.Value = "公司名称"
  798. cellC := rowTitle.AddCell()
  799. cellC.Value = "留言"
  800. cellD := rowTitle.AddCell()
  801. cellD.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.CompanyName
  808. cellC := row.AddCell()
  809. cellC.Value = item.Content
  810. cellD := row.AddCell()
  811. cellD.Value = item.CreateTime
  812. }
  813. err = xlsxFile.Save(downLoadnFilePath)
  814. if err != nil {
  815. br.Msg = "保存文件失败"
  816. br.ErrMsg = "保存文件失败"
  817. return
  818. }
  819. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  820. downloadFileName := "留言列表" + randStr + ".xlsx"
  821. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  822. defer func() {
  823. os.Remove(downLoadnFilePath)
  824. }()
  825. br.Success = true
  826. br.Ret = 200
  827. br.Msg = "导出成功"
  828. }
  829. // @Title 留言列表详情
  830. // @Description 获取留言列表详情接口
  831. // @Param VideoId query int true "视频ID"
  832. // @Success 200 {object} cygx.ArticleCommentListResp
  833. // @router /microRoadshow/commentList/video [get]
  834. func (this *MicroRoadshowController) CommentList() {
  835. br := new(models.BaseResponse).Init()
  836. defer func() {
  837. this.Data["json"] = br
  838. this.ServeJSON()
  839. }()
  840. sysUser := this.SysUser
  841. if sysUser == nil {
  842. br.Msg = "请登录"
  843. br.ErrMsg = "请登录,SysUser Is Empty"
  844. return
  845. }
  846. videoId, _ := this.GetInt("VideoId")
  847. videoInfo, _ := cygx.GetMicroRoadshowVideoByVideoId(videoId)
  848. if videoInfo == nil {
  849. br.Msg = "操作失败"
  850. br.ErrMsg = "视频ID错误"
  851. return
  852. }
  853. var condition string
  854. var pars []interface{}
  855. condition += ` AND activity_id = 0 AND video_id = ? `
  856. pars = append(pars, videoInfo.VideoId)
  857. list, err := cygx.GetArticleCommentListSearch(condition, pars)
  858. if err != nil {
  859. br.Msg = "获取失败"
  860. br.ErrMsg = "获取失败,Err:" + err.Error()
  861. return
  862. }
  863. //list, err := cygx.GetArticleCommentListByVideoId(videoId)
  864. //if err != nil {
  865. // br.Msg = "获取失败"
  866. // br.ErrMsg = "获取失败,Err:" + err.Error()
  867. // return
  868. //}
  869. resp := new(cygx.ArticleCommentListResp)
  870. resp.List = list
  871. br.Ret = 200
  872. br.Success = true
  873. br.Msg = "获取成功"
  874. br.Data = resp
  875. }
  876. // @Title 留言列表详情
  877. // @Description 获取留言列表详情接口
  878. // @Param ActivityId query int true "活动Id"
  879. // @Success 200 {object} cygx.ArticleCommentListResp
  880. // @router /microRoadshow/commentList/voice [get]
  881. func (this *MicroRoadshowController) VoiceCommentList() {
  882. br := new(models.BaseResponse).Init()
  883. defer func() {
  884. this.Data["json"] = br
  885. this.ServeJSON()
  886. }()
  887. sysUser := this.SysUser
  888. if sysUser == nil {
  889. br.Msg = "请登录"
  890. br.ErrMsg = "请登录,SysUser Is Empty"
  891. return
  892. }
  893. activityId, _ := this.GetInt("ActivityId")
  894. videoInfo, _ := cygx.GetMicroRoadshowVoiceById(activityId)
  895. if videoInfo == nil {
  896. br.Msg = "操作失败"
  897. br.ErrMsg = "音频ID错误"
  898. return
  899. }
  900. var condition string
  901. var pars []interface{}
  902. condition += ` AND activity_voice_id = ? `
  903. pars = append(pars, videoInfo.ActivityVoiceId)
  904. list, err := cygx.GetArticleCommentListSearch(condition, pars)
  905. if err != nil {
  906. br.Msg = "获取失败"
  907. br.ErrMsg = "获取失败,Err:" + err.Error()
  908. return
  909. }
  910. resp := new(cygx.ArticleCommentListResp)
  911. resp.List = list
  912. br.Ret = 200
  913. br.Success = true
  914. br.Msg = "获取成功"
  915. br.Data = resp
  916. }