micro_roadshow.go 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  1. package services
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "hongze/hongze_cygx/models"
  7. "hongze/hongze_cygx/utils"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. // GetMicroRoadShowDefaultImgConfig 获取微路演默认图/分享图配置
  13. func GetMicroRoadShowDefaultImgConfig() (audioMap, videoMap, audioShareMap, videoShareMap map[int]string, err error) {
  14. audioMap = make(map[int]string, 0)
  15. videoMap = make(map[int]string, 0)
  16. audioShareMap = make(map[int]string, 0)
  17. videoShareMap = make(map[int]string, 0)
  18. key := models.MicroRoadshowDefaultImgKey
  19. conf, e := models.GetConfigByCode(key)
  20. if e != nil {
  21. err = errors.New("获取微路演默认图配置失败, Err: " + e.Error())
  22. return
  23. }
  24. if conf.ConfigValue == "" {
  25. err = errors.New("获取微路演默认图配置有误")
  26. return
  27. }
  28. list := new(models.MicroRoadShowDefaultImgList)
  29. if e = json.Unmarshal([]byte(conf.ConfigValue), &list); e != nil {
  30. err = errors.New("微路演默认图配置配置值解析失败, Err: " + e.Error())
  31. return
  32. }
  33. audioList := list.Audio
  34. for i := range audioList {
  35. audioMap[audioList[i].ChartPermissionId] = audioList[i].ImgUrl
  36. audioShareMap[audioList[i].ChartPermissionId] = audioList[i].ShareImg
  37. }
  38. videoList := list.Video
  39. for i := range videoList {
  40. videoMap[videoList[i].ChartPermissionId] = videoList[i].ImgUrl
  41. videoShareMap[videoList[i].ChartPermissionId] = videoList[i].ShareImg
  42. }
  43. return
  44. }
  45. // GetHomeNewestList 获取首页最新列表
  46. func GetHomeNewestList(userId, companyId, startSize, pageSize int, condition string, pars []interface{}) (resp []*models.HomeArticle, total int, err error) {
  47. resp = make([]*models.HomeArticle, 0)
  48. unionList, e := models.GetHomeNewestListUnionList(condition, pars, startSize, pageSize)
  49. if e != nil {
  50. err = errors.New("获取首页最新列表失败")
  51. return
  52. }
  53. unionTotal, e := models.GetHomeNewestListUnionCount(condition, pars)
  54. if e != nil {
  55. err = errors.New("获取首页最新列表总数失败")
  56. return
  57. }
  58. total = unionTotal
  59. // 用户权限
  60. authInfo, permissionArr, e := GetUserRaiPermissionInfo(userId, companyId)
  61. if e != nil {
  62. err = errors.New("获取用户权限失败, Err: " + e.Error())
  63. return
  64. }
  65. // 获取默认图配置
  66. audioMap, videoMap, audioShareMap, videoShareMap, e := GetMicroRoadShowDefaultImgConfig()
  67. if e != nil {
  68. err = errors.New("获取微路演默认图配置失败, Err: " + e.Error())
  69. return
  70. }
  71. // 此处没有直接使用HomeArticle结构体而是多加了一层, 纯粹是为了方便前端区分纪要和微路演音频=_=!
  72. for _, v := range unionList {
  73. item := new(models.HomeArticle)
  74. item.HomeType = v.HomeType
  75. // 纪要
  76. if item.HomeType == 0 {
  77. item.ArticleId = v.ArticleId
  78. item.Title = v.Title
  79. item.TitleEn = v.TitleEn
  80. item.UpdateFrequency = v.UpdateFrequency
  81. item.CreateDate = v.CreateDate
  82. item.PublishDate = v.PublishDate
  83. item.Body = v.Body
  84. item.BodyHtml = v.BodyHtml
  85. item.Abstract = v.Abstract
  86. item.CategoryName = v.CategoryName
  87. item.SubCategoryName = v.SubCategoryName
  88. item.ExpertBackground = v.ExpertBackground
  89. item.IsResearch = v.IsResearch
  90. item.Pv = v.Pv
  91. item.ImgUrlPc = v.ImgUrlPc
  92. item.CategoryId = v.CategoryId
  93. item.HttpUrl = v.HttpUrl
  94. item.IsNeedJump = v.IsNeedJump
  95. item.Source = v.Source
  96. item.Annotation = v.Annotation
  97. }
  98. // 音频
  99. if v.HomeType == 1 {
  100. ad := new(models.MicroAudioUnionList)
  101. ad.Id = v.Id
  102. ad.AudioTitle = v.AudioTitle
  103. ad.AudioResourceUrl = v.AudioResourceUrl
  104. ad.AudioType = v.AudioType
  105. ad.AudioPublishTime = utils.StrTimeToTime(v.AudioPublishTime).Format(utils.FormatDate)
  106. ad.AudioImgUrl = v.AudioImgUrl
  107. ad.AudioChartPermissionId = v.AudioChartPermissionId
  108. ad.AudioChartPermissionName = v.AudioChartPermissionName
  109. ad.AudioPlaySeconds = v.AudioPlaySeconds
  110. ad.AudioPlaySeconds = v.AudioPlaySeconds
  111. ad.AudioActivityId = v.AudioActivityId
  112. item.MicroAudio = ad
  113. // 默认图
  114. if ad.AudioImgUrl == "" {
  115. if ad.AudioType == 1 {
  116. ad.AudioImgUrl = audioMap[ad.AudioChartPermissionId]
  117. } else {
  118. ad.AudioImgUrl = videoMap[ad.AudioChartPermissionId]
  119. }
  120. }
  121. // 分享图
  122. if ad.AudioType == 1 {
  123. ad.AudioShareImg = audioShareMap[ad.AudioChartPermissionId]
  124. } else {
  125. ad.AudioShareImg = videoShareMap[ad.AudioChartPermissionId]
  126. }
  127. // 权限
  128. au := new(models.UserPermissionAuthInfo)
  129. au.SellerName = authInfo.SellerName
  130. au.SellerMobile = authInfo.SellerMobile
  131. au.HasPermission = authInfo.HasPermission
  132. au.OperationMode = authInfo.OperationMode
  133. if au.HasPermission == 1 {
  134. // 非宏观权限进一步判断是否有权限
  135. if ad.AudioChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, ad.AudioChartPermissionName) {
  136. au.HasPermission = 2
  137. }
  138. }
  139. // 无权限的弹框提示
  140. if au.HasPermission != 1 {
  141. if au.OperationMode == UserPermissionOperationModeCall {
  142. if ad.AudioType == 1 {
  143. au.PopupMsg = UserPermissionPopupMsgCallActivity
  144. } else {
  145. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  146. }
  147. } else {
  148. if ad.AudioType == 1 {
  149. au.PopupMsg = UserPermissionPopupMsgApplyActivity
  150. } else {
  151. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  152. }
  153. }
  154. }
  155. ad.AuthInfo = au
  156. }
  157. resp = append(resp, item)
  158. }
  159. return
  160. }
  161. // GetMicroRoadShowPageList 获取微路演列表添加活动视频 更新与8.1版本
  162. func GetMicroRoadShowPageListV8(pageSize, currentIndex, audioId, videoId, activityVideoId int, filter, keywords, audioIds, videoIds, activityVideoIds, chartPermissionIds string) (respList []*models.MicroRoadShowPageList, total int, err error) {
  163. var e error
  164. // 根据每页数据量获取音视频配比
  165. startSize := utils.StartIndex(currentIndex, pageSize)
  166. videoList := make([]*models.MicroRoadShowPageList, 0)
  167. if keywords != "" {
  168. keywords = "%" + keywords + "%"
  169. }
  170. //音频的查询
  171. var audioCond string
  172. var audioPars []interface{}
  173. // 如果筛选条件为指定视频ID或只看视频则不做音频查询
  174. //if videoId > 0 || activityVideoId > 0 || filter == 1 {
  175. // audioCond = ""
  176. //} else {
  177. // 活动已发布且已结束
  178. audioCond += ` AND b.publish_status = 1 AND b.active_state = 3`
  179. //活动音频,设置有效时间为30天,失效后该活动就不再支持音频回放。有效期起始时间为活动的开始时间
  180. //endTime := time.Now().AddDate(0, 0, -30).Format("2006-01-02 15:04:05")
  181. //audioCond += ` AND b.activity_time > ? `
  182. //audioPars = append(audioPars, endTime)
  183. if keywords != "" {
  184. audioCond += ` AND ( a.voice_name LIKE ? OR b.label LIKE ? )`
  185. audioPars = append(audioPars, keywords, keywords)
  186. }
  187. if audioId > 0 {
  188. audioCond += ` AND a.activity_voice_id = ?`
  189. audioPars = append(audioPars, audioId)
  190. }
  191. if audioIds != "" {
  192. sliceId := strings.Split(audioIds, ",")
  193. var idSqlStr string
  194. for _, v := range sliceId {
  195. idSqlStr += "'" + v + "',"
  196. }
  197. idSqlStr = strings.TrimRight(idSqlStr, ",")
  198. audioCond += ` AND a.activity_voice_id IN (` + idSqlStr + `)`
  199. }
  200. //}
  201. //视频的处理
  202. var videoCond string
  203. var videoCondAct string
  204. var videoPars []interface{}
  205. var videoParsAct []interface{}
  206. //if audioId > 0 || filter == 2 {
  207. // videoCond = ""
  208. //} else {
  209. if keywords != "" {
  210. videoCond += ` AND video_name LIKE ?`
  211. videoPars = append(videoPars, keywords)
  212. videoCondAct += ` AND (video_name LIKE ? OR art.label LIKE ?)`
  213. videoParsAct = append(videoParsAct, keywords, keywords)
  214. }
  215. if videoId > 0 {
  216. videoCond += ` AND video_id = ?`
  217. videoPars = append(videoPars, videoId)
  218. }
  219. if activityVideoId > 0 {
  220. videoCondAct += ` AND video_id = ?`
  221. videoParsAct = append(videoParsAct, activityVideoId)
  222. }
  223. if activityVideoIds != "" {
  224. sliceId := strings.Split(activityVideoIds, ",")
  225. var idSqlStr string
  226. for _, v := range sliceId {
  227. idSqlStr += "'" + v + "',"
  228. }
  229. idSqlStr = strings.TrimRight(idSqlStr, ",")
  230. videoCondAct += ` AND v.video_id IN (` + idSqlStr + `)`
  231. }
  232. //如果传了路演的或者活动的视频ID只查询一个
  233. if videoId > 0 {
  234. videoCondAct += ` AND video_id = 0 `
  235. audioCond += ` AND a.activity_voice_id = 0 `
  236. }
  237. if activityVideoId > 0 {
  238. videoCond += ` AND video_id = 0 `
  239. audioCond += ` AND a.activity_voice_id = 0 `
  240. }
  241. if audioId > 0 {
  242. videoCondAct += ` AND video_id = 0 `
  243. videoCond += ` AND video_id = 0 `
  244. }
  245. if strings.Contains(filter, "1") && !strings.Contains(filter, "2") {
  246. audioCond += ` AND a.activity_voice_id = 0 `
  247. } else if !strings.Contains(filter, "1") && strings.Contains(filter, "2") {
  248. videoCondAct += ` AND video_id = 0 `
  249. videoCond += ` AND video_id = 0 `
  250. }
  251. if strings.Contains(filter, "3") && !strings.Contains(filter, "4") {
  252. audioCond += ` AND a.activity_voice_id = 0 `
  253. videoCondAct += ` AND video_id = 0 `
  254. } else if strings.Contains(filter, "3") && !strings.Contains(filter, "4") {
  255. videoCond += ` AND video_id = 0 `
  256. }
  257. if videoIds != "" {
  258. sliceId := strings.Split(videoIds, ",")
  259. var idSqlStr string
  260. for _, v := range sliceId {
  261. idSqlStr += "'" + v + "',"
  262. }
  263. idSqlStr = strings.TrimRight(idSqlStr, ",")
  264. videoCond += ` AND video_id IN (` + idSqlStr + `)`
  265. }
  266. videoCond += ` AND publish_status = 1`
  267. if chartPermissionIds != "" {
  268. videoCond += ` AND chart_permission_id IN (` + chartPermissionIds + `)`
  269. audioCond += ` AND b.chart_permission_id IN (` + chartPermissionIds + `)`
  270. videoCondAct += ` AND art.chart_permission_id IN (` + chartPermissionIds + `)`
  271. }
  272. //}
  273. total, videoList, e = models.GetMicroRoadShowVideoPageListV8(startSize, pageSize, videoCond, videoPars, videoCondAct, videoParsAct, audioCond, audioPars)
  274. if e != nil {
  275. err = errors.New("获取微路演音视频列表失败, Err: " + e.Error())
  276. return
  277. }
  278. respList = videoList
  279. return
  280. }
  281. // GetMicroRoadShowPageList 获取微路演列表添加活动视频 更新与8.1版本
  282. func GetMicroRoadShowPageListV12(pageSize, currentIndex, sourceId, tableType int, filter, keywords, searchType, chartPermissionIds string) (respList []*models.MicroRoadShowPageList, total int, err error) {
  283. //Type int `description:"类型: 1-活动音频; 2-活动视频; 3-产业视频; 4-系列问答"`
  284. var e error
  285. // 根据每页数据量获取音视频配比
  286. startSize := utils.StartIndex(currentIndex, pageSize)
  287. videoList := make([]*models.MicroRoadShowPageList, 0)
  288. var audioAct string // 活动音频 1
  289. var audioActPars []interface{}
  290. var videoAct string // 活动视频 2
  291. var videoActPars []interface{}
  292. //视频的处理
  293. var videoMico string //产业视频 3
  294. var videoMicoPars []interface{}
  295. var conditionAskserie string // 系列问答 4
  296. var askseriePars []interface{}
  297. if sourceId > 0 && tableType > 0 {
  298. //先给不相干的表查询ID = 0
  299. audioAct += ` AND b.chart_permission_id = 0 `
  300. videoAct += ` AND b.chart_permission_id = 0`
  301. videoMico += ` AND a.chart_permission_id = 0 `
  302. conditionAskserie += ` AND a.chart_permission_id = 0 `
  303. switch tableType {
  304. case 1:
  305. audioAct += ` OR a.activity_id = ` + strconv.Itoa(sourceId)
  306. case 2:
  307. videoAct += ` OR a.activity_id = ` + strconv.Itoa(sourceId)
  308. case 3:
  309. videoMico += ` OR a.id = ` + strconv.Itoa(sourceId)
  310. case 4:
  311. conditionAskserie += ` OR a.askserie_video_id = ` + strconv.Itoa(sourceId)
  312. }
  313. }
  314. if filter == "1" {
  315. audioAct += ` AND b.chart_permission_id = 0 `
  316. } else if filter == "2" {
  317. videoAct += ` AND b.chart_permission_id = 0`
  318. videoMico += ` AND a.chart_permission_id = 0 `
  319. conditionAskserie += ` AND a.chart_permission_id = 0 `
  320. }
  321. if searchType != "" {
  322. // @Param SearchType string int true "搜索类型: 1-路演回放; 2-问答系列; 3-调研反馈 多个用 , 隔开"
  323. videoMico += ` AND a.chart_permission_id = 0 ` // 产业视频不在搜索范围内
  324. if strings.Contains(searchType, "1") && !strings.Contains(searchType, "3") {
  325. audioAct += ` AND b.activity_type_id IN (2,7) AND b.is_yidong_conduct = 1 `
  326. videoAct += ` AND b.activity_type_id IN (2,7) AND b.is_yidong_conduct = 1 `
  327. }
  328. if !strings.Contains(searchType, "1") && strings.Contains(searchType, "3") {
  329. audioAct += ` AND ( b.is_yidong_conduct = 0 OR b.activity_type_id NOT IN (2,7) ) `
  330. videoAct += ` AND ( b.is_yidong_conduct = 0 OR b.activity_type_id NOT IN (2,7) ) `
  331. }
  332. if !strings.Contains(searchType, "2") {
  333. conditionAskserie += ` AND a.chart_permission_id = 0 `
  334. }
  335. if !strings.Contains(searchType, "3") && !strings.Contains(searchType, "1") {
  336. audioAct += ` AND b.chart_permission_id = 0 `
  337. videoAct += ` AND b.chart_permission_id = 0 `
  338. }
  339. }
  340. if keywords != "" {
  341. keywords = "%" + keywords + "%"
  342. audioAct += ` AND a.voice_name LIKE ? `
  343. videoAct += ` AND a.video_name LIKE ? `
  344. videoMico += ` AND a.video_name LIKE ? `
  345. conditionAskserie += ` AND a.video_name LIKE ? `
  346. audioActPars = append(audioActPars, keywords)
  347. videoActPars = append(videoActPars, keywords)
  348. videoMicoPars = append(videoMicoPars, keywords)
  349. askseriePars = append(askseriePars, keywords)
  350. }
  351. //行业筛选
  352. if chartPermissionIds != "" {
  353. audioAct += ` AND b.chart_permission_id IN (` + chartPermissionIds + `)`
  354. videoAct += ` AND b.chart_permission_id IN (` + chartPermissionIds + `)`
  355. videoMico += ` AND a.chart_permission_id IN (` + chartPermissionIds + `)`
  356. conditionAskserie += ` AND a.chart_permission_id IN (` + chartPermissionIds + `)`
  357. }
  358. //发布状态
  359. audioAct += ` AND b.publish_status = 1 `
  360. videoAct += ` AND b.publish_status = 1 `
  361. videoMico += ` AND a.publish_status = 1 `
  362. conditionAskserie += ` AND a.publish_status = 1 `
  363. total, videoList, e = models.GetMicroRoadShowVideoPageListV12(startSize, pageSize, audioAct, audioActPars, videoAct, videoActPars, videoMico, videoMicoPars, conditionAskserie, askseriePars)
  364. if e != nil {
  365. err = errors.New("获取微路演音视频列表失败, Err: " + e.Error())
  366. return
  367. }
  368. respList = videoList
  369. return
  370. }
  371. // GetMicroRoadShowPageListIkWord 添加IK分词联想词 获取微路演列表添加活动视频 更新与8.1版本
  372. func CountMicroRoadShowPageListIkWord(audioId, videoId, activityVideoId int, keywordArr []string, filter, audioIds, videoIds, activityVideoIds string) (total int, err error) {
  373. var e error
  374. var keywords string
  375. if len(keywordArr) > 0 {
  376. keywords = KeyWordArrSqlRegexpAll(keywordArr)
  377. }
  378. //if keywords == "" {
  379. // return
  380. //}
  381. //音频的查询
  382. var audioCond string
  383. var audioPars []interface{}
  384. // 如果筛选条件为指定视频ID或只看视频则不做音频查询
  385. //if videoId > 0 || activityVideoId > 0 || filter == 1 {
  386. // audioCond += ` AND a.activity_voice_id = 0 `
  387. //} else {
  388. // 活动已发布且已结束
  389. audioCond += ` AND b.publish_status = 1 AND b.active_state = 3`
  390. if keywords != "" {
  391. audioCond += ` AND (a.voice_name REGEXP ? OR b.label REGEXP ? ) `
  392. audioPars = append(audioPars, keywords, keywords)
  393. }
  394. if audioId > 0 {
  395. audioCond += ` AND a.activity_voice_id = ?`
  396. audioPars = append(audioPars, audioId)
  397. }
  398. if audioIds != "" {
  399. sliceId := strings.Split(audioIds, ",")
  400. var idSqlStr string
  401. for _, v := range sliceId {
  402. idSqlStr += "'" + v + "',"
  403. }
  404. idSqlStr = strings.TrimRight(idSqlStr, ",")
  405. audioCond += ` AND a.activity_voice_id IN (` + idSqlStr + `)`
  406. }
  407. //}
  408. //视频的处理
  409. var videoCond string
  410. var videoCondAct string
  411. var videoPars []interface{}
  412. var videoParsAct []interface{}
  413. //if audioId > 0 || filter == 2 {
  414. // videoCond = ""
  415. //} else {
  416. if keywords != "" {
  417. videoCond += ` AND video_name REGEXP ? `
  418. videoPars = append(videoPars, keywords)
  419. videoCondAct += ` AND (video_name REGEXP ? OR art.label REGEXP ? )`
  420. videoParsAct = append(videoParsAct, keywords, keywords)
  421. }
  422. if videoId > 0 {
  423. videoCond += ` AND video_id = ? `
  424. videoPars = append(videoPars, videoId)
  425. }
  426. if activityVideoId > 0 {
  427. videoCondAct += ` AND video_id = ?`
  428. videoParsAct = append(videoParsAct, activityVideoId)
  429. }
  430. if activityVideoIds != "" {
  431. sliceId := strings.Split(activityVideoIds, ",")
  432. var idSqlStr string
  433. for _, v := range sliceId {
  434. idSqlStr += "'" + v + "',"
  435. }
  436. idSqlStr = strings.TrimRight(idSqlStr, ",")
  437. videoCondAct += ` AND v.video_id IN (` + idSqlStr + `)`
  438. }
  439. //如果传了路演的或者活动的视频ID只查询一个
  440. if videoId > 0 {
  441. videoCondAct += ` AND video_id = 0 `
  442. audioCond += ` AND a.activity_voice_id = 0 `
  443. }
  444. if activityVideoId > 0 {
  445. videoCond += ` AND video_id = 0 `
  446. audioCond += ` AND a.activity_voice_id = 0 `
  447. }
  448. if audioId > 0 {
  449. videoCondAct += ` AND video_id = 0 `
  450. videoCond += ` AND video_id = 0 `
  451. }
  452. if strings.Contains(filter, "1") && !strings.Contains(filter, "2") {
  453. audioCond += ` AND a.activity_voice_id = 0 `
  454. } else if !strings.Contains(filter, "1") && strings.Contains(filter, "2") {
  455. videoCondAct += ` AND video_id = 0 `
  456. videoCond += ` AND video_id = 0 `
  457. }
  458. if strings.Contains(filter, "3") && !strings.Contains(filter, "4") {
  459. audioCond += ` AND a.activity_voice_id = 0 `
  460. videoCondAct += ` AND video_id = 0 `
  461. } else if strings.Contains(filter, "3") && !strings.Contains(filter, "4") {
  462. videoCond += ` AND video_id = 0 `
  463. }
  464. if videoIds != "" {
  465. sliceId := strings.Split(videoIds, ",")
  466. var idSqlStr string
  467. for _, v := range sliceId {
  468. idSqlStr += "'" + v + "',"
  469. }
  470. idSqlStr = strings.TrimRight(idSqlStr, ",")
  471. videoCond += ` AND video_id IN (` + idSqlStr + `)`
  472. }
  473. videoCond += ` AND publish_status = 1`
  474. //}
  475. total, e = models.CountMicroRoadShowVideoPageList(videoCond, videoPars, videoCondAct, videoParsAct, audioCond, audioPars)
  476. if e != nil {
  477. err = errors.New("获取微路演音视频列表失败, Err: " + e.Error())
  478. return
  479. }
  480. return
  481. }
  482. // GetMicroRoadShowPageListIkWord 添加IK分词联想词 获取微路演列表添加活动视频 更新与8.1版本
  483. func GetMicroRoadShowPageListIkWord(startSize, pageSize, audioId, videoId, activityVideoId int, keywordArr []string, filter, audioIds, videoIds, activityVideoIds, keywords string) (respList []*models.MicroRoadShowPageList, err error) {
  484. videoList := make([]*models.MicroRoadShowPageList, 0)
  485. var e error
  486. var keywordsIk string
  487. if len(keywordArr) > 1 {
  488. keywordsIk = KeyWordArrSqlRegexp(keywordArr)
  489. }
  490. if keywords != "" {
  491. keywords = "%" + keywords + "%"
  492. }
  493. //音频的查询
  494. var audioCond string
  495. var audioPars []interface{}
  496. // 如果筛选条件为指定视频ID或只看视频则不做音频查询
  497. //if videoId > 0 || activityVideoId > 0 || filter == 1 {
  498. // audioCond += ` AND a.activity_voice_id = 0 `
  499. //} else {
  500. // 活动已发布且已结束
  501. audioCond += ` AND b.publish_status = 1 AND b.active_state = 3`
  502. if keywordsIk != "" {
  503. audioCond += ` AND ( a.voice_name REGEXP ? OR b.label REGEXP ? )`
  504. audioCond += ` AND ( a.voice_name NOT LIKE ? AND b.label NOT LIKE ? )`
  505. audioPars = append(audioPars, keywordsIk, keywordsIk, keywords, keywords)
  506. }
  507. if audioId > 0 {
  508. audioCond += ` AND a.activity_voice_id = ?`
  509. audioPars = append(audioPars, audioId)
  510. }
  511. if audioIds != "" {
  512. sliceId := strings.Split(audioIds, ",")
  513. var idSqlStr string
  514. for _, v := range sliceId {
  515. idSqlStr += "'" + v + "',"
  516. }
  517. idSqlStr = strings.TrimRight(idSqlStr, ",")
  518. audioCond += ` AND a.activity_voice_id IN (` + idSqlStr + `)`
  519. }
  520. //}
  521. //视频的处理
  522. var videoCond string
  523. var videoCondAct string
  524. var videoPars []interface{}
  525. var videoParsAct []interface{}
  526. //if audioId > 0 || filter == 2 {
  527. // videoCond = ""
  528. //} else {
  529. if keywordsIk != "" {
  530. videoCond += ` AND video_name REGEXP ?`
  531. videoPars = append(videoPars, keywordsIk)
  532. videoCondAct += ` AND ( v.video_name REGEXP ? OR art.label REGEXP ? )`
  533. videoCondAct += ` AND ( v.video_name NOT LIKE ? AND art.label NOT LIKE ? )`
  534. //videoCondAct += ` AND video_name REGEXP ?`
  535. videoParsAct = append(videoParsAct, keywordsIk, keywordsIk, keywords, keywords)
  536. }
  537. if videoId > 0 {
  538. videoCond += ` AND video_id = ?`
  539. videoPars = append(videoPars, videoId)
  540. }
  541. if activityVideoId > 0 {
  542. videoCondAct += ` AND video_id = ?`
  543. videoParsAct = append(videoParsAct, activityVideoId)
  544. }
  545. if activityVideoIds != "" {
  546. sliceId := strings.Split(activityVideoIds, ",")
  547. var idSqlStr string
  548. for _, v := range sliceId {
  549. idSqlStr += "'" + v + "',"
  550. }
  551. idSqlStr = strings.TrimRight(idSqlStr, ",")
  552. videoCondAct += ` AND v.video_id IN (` + idSqlStr + `)`
  553. }
  554. //如果传了路演的或者活动的视频ID只查询一个
  555. if videoId > 0 {
  556. videoCondAct += ` AND video_id = 0 `
  557. audioCond += ` AND a.activity_voice_id = 0 `
  558. }
  559. if activityVideoId > 0 {
  560. videoCond += ` AND video_id = 0 `
  561. audioCond += ` AND a.activity_voice_id = 0 `
  562. }
  563. if audioId > 0 {
  564. videoCondAct += ` AND video_id = 0 `
  565. videoCond += ` AND video_id = 0 `
  566. }
  567. if strings.Contains(filter, "1") && !strings.Contains(filter, "2") {
  568. audioCond += ` AND a.activity_voice_id = 0 `
  569. } else if !strings.Contains(filter, "1") && strings.Contains(filter, "2") {
  570. videoCondAct += ` AND video_id = 0 `
  571. videoCond += ` AND video_id = 0 `
  572. }
  573. if strings.Contains(filter, "3") && !strings.Contains(filter, "4") {
  574. audioCond += ` AND a.activity_voice_id = 0 `
  575. videoCondAct += ` AND video_id = 0 `
  576. } else if strings.Contains(filter, "3") && !strings.Contains(filter, "4") {
  577. videoCond += ` AND video_id = 0 `
  578. }
  579. if videoIds != "" {
  580. sliceId := strings.Split(videoIds, ",")
  581. var idSqlStr string
  582. for _, v := range sliceId {
  583. idSqlStr += "'" + v + "',"
  584. }
  585. idSqlStr = strings.TrimRight(idSqlStr, ",")
  586. videoCond += ` AND video_id IN (` + idSqlStr + `)`
  587. }
  588. videoCond += ` AND publish_status = 1`
  589. //}
  590. videoList, e = models.GetMicroRoadShowVideoPageListIkWord(startSize, pageSize, videoCond, videoPars, videoCondAct, videoParsAct, audioCond, audioPars)
  591. if e != nil {
  592. err = errors.New("获取微路演音视频列表失败分词, Err: " + e.Error())
  593. return
  594. }
  595. respList = videoList
  596. return
  597. }
  598. // 我的收藏
  599. func GetMicroRoadShowMycollect(pageSize, currentIndex int, audioIds, videoIds, activityVideoIds string) (respList []*models.MicroRoadShowPageList, total int, err error) {
  600. var e error
  601. // 根据每页数据量获取音视频配比
  602. startSize := utils.StartIndex(currentIndex, pageSize)
  603. videoList := make([]*models.MicroRoadShowPageList, 0)
  604. //音频的查询
  605. var audioCond string
  606. var audioPars []interface{}
  607. // 如果筛选条件为指定视频ID或只看视频则不做音频查询
  608. // 活动已发布且已结束
  609. audioCond += ` AND b.publish_status = 1 AND b.active_state = 3`
  610. if audioIds != "" {
  611. sliceId := strings.Split(audioIds, ",")
  612. var idSqlStr string
  613. for _, v := range sliceId {
  614. idSqlStr += "'" + v + "',"
  615. }
  616. idSqlStr = strings.TrimRight(idSqlStr, ",")
  617. audioCond += ` AND a.activity_voice_id IN (` + idSqlStr + `)`
  618. } else {
  619. audioCond += ` AND a.activity_voice_id = 0 `
  620. }
  621. //视频的处理
  622. var videoCond string
  623. var videoCondAct string
  624. if activityVideoIds != "" {
  625. sliceId := strings.Split(activityVideoIds, ",")
  626. var idSqlStr string
  627. for _, v := range sliceId {
  628. idSqlStr += "'" + v + "',"
  629. }
  630. idSqlStr = strings.TrimRight(idSqlStr, ",")
  631. videoCondAct += ` AND v.video_id IN (` + idSqlStr + `)`
  632. } else {
  633. videoCondAct += ` AND v.video_id = 0 `
  634. }
  635. var videoPars []interface{}
  636. var videoParsAct []interface{}
  637. if videoIds != "" {
  638. sliceId := strings.Split(videoIds, ",")
  639. var idSqlStr string
  640. for _, v := range sliceId {
  641. idSqlStr += "'" + v + "',"
  642. }
  643. idSqlStr = strings.TrimRight(idSqlStr, ",")
  644. videoCond += ` AND video_id IN (` + idSqlStr + `)`
  645. } else {
  646. videoCond += ` AND video_id = 0 `
  647. }
  648. videoCond += ` AND publish_status = 1`
  649. total, videoList, e = models.GetMicroRoadShowVideoPageListV8(startSize, pageSize, videoCond, videoPars, videoCondAct, videoParsAct, audioCond, audioPars)
  650. if e != nil {
  651. err = errors.New("获取微路演音视频列表失败, Err: " + e.Error())
  652. return
  653. }
  654. respList = videoList
  655. return
  656. }
  657. // 我的收藏
  658. func GetMicroRoadShowMycollectV12(pageSize, currentIndex int, audioIds, activityVideoIds, roadshowIdsStr, askserieVideoIds string, user *models.WxUserItem) (respList []*models.MicroRoadShowPageList, total int, err error) {
  659. //Type int `description:"类型: 1-活动音频; 2-活动视频; 3-产业视频; 4-系列问答"`
  660. var e error
  661. // 根据每页数据量获取音视频配比
  662. startSize := utils.StartIndex(currentIndex, pageSize)
  663. videoList := make([]*models.MicroRoadShowPageList, 0)
  664. var audioAct string // 活动音频 1
  665. var audioActPars []interface{}
  666. var videoAct string // 活动视频 2
  667. var videoActPars []interface{}
  668. //视频的处理
  669. var videoMico string //产业视频 3
  670. var videoMicoPars []interface{}
  671. var conditionAskserie string // 系列问答 4
  672. var askseriePars []interface{}
  673. if audioIds != "" {
  674. sliceId := strings.Split(audioIds, ",")
  675. audioAct += ` AND a.activity_voice_id IN (` + strings.Join(sliceId, ",") + `)`
  676. } else {
  677. audioAct += ` AND a.activity_voice_id = 0 `
  678. }
  679. if activityVideoIds != "" {
  680. sliceId := strings.Split(activityVideoIds, ",")
  681. videoAct += ` AND a.video_id IN (` + strings.Join(sliceId, ",") + `)`
  682. } else {
  683. videoAct += ` AND a.video_id = 0 `
  684. }
  685. if roadshowIdsStr != "" {
  686. sliceId := strings.Split(roadshowIdsStr, ",")
  687. videoMico += ` AND a.video_id IN (` + strings.Join(sliceId, ",") + `)`
  688. } else {
  689. videoMico += ` AND a.video_id = 0 `
  690. }
  691. if askserieVideoIds != "" {
  692. sliceId := strings.Split(askserieVideoIds, ",")
  693. conditionAskserie += ` AND a.askserie_video_id IN (` + strings.Join(sliceId, ",") + `)`
  694. } else {
  695. conditionAskserie += ` AND a.askserie_video_id = 0 `
  696. }
  697. //发布状态
  698. audioAct += ` AND b.publish_status = 1 `
  699. videoAct += ` AND b.publish_status = 1 `
  700. videoMico += ` AND a.publish_status = 1 `
  701. conditionAskserie += ` AND a.publish_status = 1 `
  702. total, videoList, e = models.GetMicroRoadShowVideoPageListV12(startSize, pageSize, audioAct, audioActPars, videoAct, videoActPars, videoMico, videoMicoPars, conditionAskserie, askseriePars)
  703. if e != nil {
  704. err = errors.New("获取微路演音视频列表失败, Err: " + e.Error())
  705. return
  706. }
  707. userId := user.UserId
  708. listMycollect, e := models.GetUserMicroRoadshowCollectList(userId)
  709. if e != nil {
  710. err = errors.New("GetUserMicroRoadshowCollectList, Err: " + e.Error())
  711. return
  712. }
  713. mapaudioIds := make(map[int]int) //活动音频
  714. mapvideoIds := make(map[int]int) // 微路演视频
  715. mapactivityVideoIds := make(map[int]int) // 活动视频
  716. mapAskserieVideoIds := make(map[int]int) // 活动视频
  717. for _, item := range listMycollect {
  718. if item.ActivityVoiceId > 0 {
  719. mapaudioIds[item.ActivityVoiceId] = item.ActivityVoiceId
  720. } else if item.VideoId > 0 {
  721. mapvideoIds[item.VideoId] = item.VideoId
  722. } else if item.ActivityVideoId > 0 {
  723. mapactivityVideoIds[item.ActivityVoiceId] = item.ActivityVoiceId
  724. }
  725. }
  726. listAskserieVideoCollect, e := models.GetUserCygxAskserieVideoCollectList(userId)
  727. if e != nil {
  728. err = errors.New("GetUserCygxAskserieVideoCollectList, Err: " + e.Error())
  729. return
  730. }
  731. for _, v := range listAskserieVideoCollect {
  732. if v.AskserieVideoId > 0 {
  733. mapAskserieVideoIds[v.AskserieVideoId] = v.AskserieVideoId
  734. }
  735. }
  736. for _, item := range videoList {
  737. if item.Type == 1 {
  738. //音频
  739. if mapaudioIds[item.Id] > 0 {
  740. item.IsCollect = true
  741. }
  742. } else if item.Type == 2 {
  743. //活动视频
  744. if mapactivityVideoIds[item.Id] > 0 {
  745. item.IsCollect = true
  746. }
  747. } else if item.Type == 3 {
  748. //微路演视频
  749. if mapvideoIds[item.Id] > 0 {
  750. item.IsCollect = true
  751. }
  752. } else if item.Type == 4 {
  753. //系列问答视频
  754. if mapAskserieVideoIds[item.SourceId] > 0 {
  755. item.IsCollect = true
  756. }
  757. }
  758. }
  759. respList = videoList
  760. return
  761. }
  762. // GetMicroRoadshowVideoMap 获取已经发布的微路演的产业ID
  763. func GetMicroRoadshowVideoMap() (items map[int]int, err error) {
  764. list, e := models.GetMicroRoadshowVideoList()
  765. if e != nil && e.Error() != utils.ErrNoRow() {
  766. err = errors.New("获取已经发布的微路演的产业失败,GetMicroRoadshowVideoList " + e.Error())
  767. return
  768. }
  769. mapindustrialId := make(map[int]int)
  770. for _, v := range list {
  771. mapindustrialId[v.IndustryId] = v.IndustryId
  772. }
  773. items = mapindustrialId
  774. return
  775. }
  776. func GetindustryVideo(user *models.WxUserItem, industrialManagementId int) (industryVideo *models.MicroVideoSimpleInfo, AuthInfo *models.UserPermissionAuthInfo, err error) {
  777. total, e := models.GetMicroRoadshowVideoByIndustryIdCount(industrialManagementId)
  778. if e != nil {
  779. err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryIdCount " + e.Error())
  780. return
  781. }
  782. if total == 0 {
  783. return
  784. }
  785. // 用户权限
  786. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  787. if e != nil {
  788. err = errors.New("获取用户权限失败,GetUserRaiPermissionInfo " + e.Error())
  789. return
  790. }
  791. videoSimple := new(models.MicroVideoSimpleInfo)
  792. // 权限
  793. var au *models.UserPermissionAuthInfo
  794. video, e := models.GetMicroRoadshowVideoByIndustryId(industrialManagementId)
  795. if e != nil {
  796. err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  797. return
  798. } else {
  799. videoSimple.Id = video.VideoId
  800. videoSimple.Title = "5min【" + video.IndustryName + "】逻辑解析"
  801. videoSimple.BackgroundImg = video.ImgUrl
  802. videoSimple.DetailImgUrl = video.DetailImgUrl
  803. if videoSimple.BackgroundImg == "" {
  804. // 获取默认图配置
  805. _, videoMap, _, _, e := GetMicroRoadShowDefaultImgConfig()
  806. if e != nil {
  807. err = errors.New("获取视频默认配置图失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  808. return
  809. }
  810. videoSimple.BackgroundImg = videoMap[video.ChartPermissionId]
  811. }
  812. videoSimple.PlaySeconds = video.VideoDuration
  813. videoSimple.ResourceUrl = video.VideoUrl
  814. au = new(models.UserPermissionAuthInfo)
  815. au.SellerName = authInfo.SellerName
  816. au.SellerMobile = authInfo.SellerMobile
  817. au.HasPermission = authInfo.HasPermission
  818. au.OperationMode = authInfo.OperationMode
  819. if au.HasPermission == 1 {
  820. // 非宏观权限进一步判断是否有权限
  821. if video.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, video.ChartPermissionName) {
  822. au.HasPermission = 2
  823. }
  824. }
  825. // 无权限的弹框提示
  826. if au.HasPermission != 1 {
  827. if au.OperationMode == UserPermissionOperationModeCall {
  828. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  829. } else {
  830. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  831. }
  832. videoSimple.ResourceUrl = ""
  833. }
  834. }
  835. industryVideo = videoSimple
  836. AuthInfo = au
  837. return
  838. }
  839. // 用户微路演视频回放操作操作行为,模板消息推送
  840. func MicroRoadshowVideoUserRmind(user *models.WxUserItem, videoId int) (err error) {
  841. defer func() {
  842. if err != nil {
  843. go utils.SendAlarmMsg("用户音视频回放操作操作行为,模板消息推送失败"+err.Error(), 2)
  844. }
  845. }()
  846. countUser, err := models.GetUserRemind(user.UserId)
  847. if err != nil {
  848. return err
  849. }
  850. if countUser == 0 {
  851. return err
  852. }
  853. var first string
  854. var keyword1 string
  855. var keyword2 string
  856. var keyword3 string
  857. var keyword4 string
  858. var remark string
  859. //获取销售手机号
  860. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  861. if err != nil && err.Error() != utils.ErrNoRow() {
  862. return err
  863. }
  864. if sellerItemQy != nil {
  865. openIdList, e := models.GetWxOpenIdByMobileList(sellerItemQy.Mobile)
  866. if e != nil {
  867. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  868. return
  869. }
  870. videoInfo, e := models.GetMicroRoadshowVideoByVideoId(videoId)
  871. if e != nil {
  872. err = errors.New("GetCygxActivitySpecialDetailById, Err: " + e.Error())
  873. return
  874. }
  875. if videoInfo == nil {
  876. return
  877. }
  878. first = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:播放微路演详视频")
  879. keyword1 = videoInfo.VideoName
  880. keyword2 = fmt.Sprint("互动:播放微路演详视频,", user.RealName, "--", user.CompanyName)
  881. remark = "点击查看微路演详情"
  882. openIdArr := make([]string, 0)
  883. for _, v := range openIdList {
  884. openIdArr = append(openIdArr, v.OpenId)
  885. }
  886. redirectUrl := utils.WX_MSG_PATH_ACTIVITY_INDUSTRYR_EPORT + strconv.Itoa(videoInfo.IndustryId)
  887. sendInfo := new(SendWxTemplate)
  888. sendInfo.First = first
  889. sendInfo.Keyword1 = keyword1
  890. sendInfo.Keyword2 = keyword2
  891. sendInfo.Keyword3 = keyword3
  892. sendInfo.Keyword4 = keyword4
  893. sendInfo.Remark = remark
  894. sendInfo.TemplateId = utils.WxMsgTemplateIdArticleUserRemind
  895. sendInfo.RedirectUrl = redirectUrl
  896. sendInfo.RedirectTarget = 3
  897. sendInfo.Resource = strconv.Itoa(videoId)
  898. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  899. sendInfo.OpenIdArr = openIdArr
  900. err = PublicSendTemplateMsg(sendInfo)
  901. if err != nil {
  902. return
  903. }
  904. }
  905. return
  906. }
  907. // 记录产业视频播放记录
  908. func AddMicroRoadshowVideoRecord(user *models.WxUserItem, videoId, playSeconds int) {
  909. var err error
  910. defer func() {
  911. if err != nil {
  912. go utils.SendAlarmMsg(fmt.Sprint("记录用户活动音频播放记录失败 AddMicroRoadshowVideoRecord Err:", err.Error(), "videoId:", videoId, "UserId:", user.UserId), 2)
  913. }
  914. }()
  915. item := new(models.CygxMicroRoadshowVideoHistory)
  916. item.UserId = user.UserId
  917. item.RealName = user.RealName
  918. item.VideoId = videoId
  919. item.PlaySeconds = strconv.Itoa(playSeconds)
  920. item.Mobile = user.Mobile
  921. item.Email = user.Email
  922. item.CompanyId = user.CompanyId
  923. item.CompanyName = user.CompanyName
  924. item.CreateTime = time.Now()
  925. item.ModifyTime = time.Now()
  926. item.RegisterPlatform = utils.REGISTER_PLATFORM
  927. sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  928. if e != nil && e.Error() != utils.ErrNoRow() {
  929. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  930. return
  931. }
  932. if sellerItem != nil {
  933. item.SellerName = sellerItem.RealName
  934. }
  935. if playSeconds != 0 {
  936. lastItem, e := models.GetLastCygxMicroRoadshowVideoHistory(videoId, user.UserId)
  937. if e != nil {
  938. err = errors.New("GetLastCygxMicroRoadshowVideoHistory, Err: " + e.Error())
  939. return
  940. }
  941. e = models.UpdateLastCygxActivityVideoHistory(strconv.Itoa(playSeconds), lastItem.Id)
  942. if e != nil {
  943. err = errors.New("UpdateLastCygxActivityVideoHistory, Err: " + e.Error())
  944. return
  945. }
  946. } else {
  947. e = models.AddCygxMicroRoadshowVideoHistory(item)
  948. if e != nil {
  949. err = errors.New("AddCygxMicroRoadshowVideoHistory, Err: " + e.Error())
  950. return
  951. }
  952. e = models.UpdateCygxMicroRoadshowVideo(videoId)
  953. if e != nil {
  954. err = errors.New("UpdateCygxActivityVideoCounts, Err: " + e.Error())
  955. return
  956. }
  957. go MicroRoadshowVideoUserRmind(user, videoId)
  958. }
  959. return
  960. }