activity_ocr.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. package cygx
  2. import (
  3. "errors"
  4. "hongze/hz_crm_api/models/cygx"
  5. "hongze/hz_crm_api/utils"
  6. "strconv"
  7. "strings"
  8. "time"
  9. )
  10. //处理OCR识别图片建会的逻辑
  11. //星期日 Sunday=Sun. 读音:英[ˈsʌndeɪ]美[ˈsʌnˌdeɪ]
  12. //
  13. //星期一 Monday=Mon. 读音:英[ˈmʌndeɪ]美[ˈmʌndeɪ]
  14. //
  15. //星期二 Tuesday=Tues. 读音:英[ˈtju:zdeɪ]美[ˈtu:zdeɪ]
  16. //
  17. //星期三 Wednesday=Wed. 读音:英[ˈwenzdeɪ]美[ˈwɛnzdi, -ˌde]
  18. //
  19. //星期四 Thursday=Thur./Thurs. 读音:英[ˈθɜ:zdeɪ]美[ˈθɜ:rzdeɪ]
  20. //
  21. //星期五 Friday=Fri. 读音:英[ˈfraɪdeɪ]美[ˈfraɪˌdeɪ]
  22. //
  23. //星期六 Saturday=Sat. 读音: 英[ˈsætədeɪ]美[ˈsætərdeɪ]
  24. // 处理年月日格式
  25. func ConvertActivityTitmeYMD(TitmeYMD string) (titmeYMDNew string) {
  26. titmeYMDNew = TitmeYMD
  27. titmeYMDNew = strings.Replace(titmeYMDNew, "/", "月", -1)
  28. //titmeYMDNew = strings.Replace(titmeYMDNew, "SUN", "日(周日)", -1)
  29. //titmeYMDNew = strings.Replace(titmeYMDNew, "MON", "日(周一)", -1)
  30. //titmeYMDNew = strings.Replace(titmeYMDNew, "TUE", "日(周二)", -1)
  31. //titmeYMDNew = strings.Replace(titmeYMDNew, "WED", "日(周三)", -1)
  32. //titmeYMDNew = strings.Replace(titmeYMDNew, "THU", "日(周四)", -1)
  33. //titmeYMDNew = strings.Replace(titmeYMDNew, "FRI", "日(周五)", -1)
  34. //titmeYMDNew = strings.Replace(titmeYMDNew, "SAT", "日(周六)", -1)
  35. titmeYMDNew = strings.Replace(titmeYMDNew, "SUN", "日", -1)
  36. titmeYMDNew = strings.Replace(titmeYMDNew, "MON", "日", -1)
  37. titmeYMDNew = strings.Replace(titmeYMDNew, "TUE", "日", -1)
  38. titmeYMDNew = strings.Replace(titmeYMDNew, "WED", "日", -1)
  39. titmeYMDNew = strings.Replace(titmeYMDNew, "THU", "日", -1)
  40. titmeYMDNew = strings.Replace(titmeYMDNew, "FRI", "日", -1)
  41. titmeYMDNew = strings.Replace(titmeYMDNew, "SAT", "日", -1)
  42. titmeYMDNew = strconv.Itoa(time.Now().Year()) + "年" + titmeYMDNew
  43. return
  44. }
  45. // 处理时分PM格式
  46. func ConvertActivityTitmeHM(titmeHM string) (titmeHMNew string) {
  47. titmeHMNew = titmeHM
  48. //var hNum int
  49. var amOrPm string
  50. if strings.Contains(titmeHM, "PM") {
  51. //hNum = 12
  52. amOrPm = "PM"
  53. } else {
  54. amOrPm = "AM"
  55. }
  56. titmeHM = strings.Replace(titmeHM, "AM", "", -1)
  57. titmeHM = strings.Replace(titmeHM, "PM", "", -1)
  58. sliceHm := strings.Split(titmeHM, ":")
  59. if len(sliceHm) != 2 {
  60. return
  61. }
  62. hourNum, _ := strconv.Atoi(sliceHm[0])
  63. minute := sliceHm[1]
  64. titmeHMNew = strconv.Itoa(hourNum) + ":" + minute + " " + amOrPm
  65. return
  66. }
  67. // 活动内容模版
  68. var ActivityOcrTemplate = "<p>【小范围公司线上交流】{{COMPANY}}</p><p>时间:{{TIME}}</p><p>嘉宾:IR</p><p>主持人:IR</p><p>链接参会:(会前一天下午更新)</p><p>备注:</p><p>1、请先报名,我们将于会议前一天提供【Webex】入会链接(可电话拨入or网络端参会);</p><p>2、会议语言:{{LANGUAGE}};</p><p>3、本场会议报名截止时间为会议开始前一天下午3点半;</p><p>4、本次会议扣0.5次研选服务点。</p>"
  69. func MakeActivityReqText(list []*cygx.AliyunOcrTextActivityResp) (req cygx.ActivityRep, err error, errMsg string) {
  70. for _, v := range list {
  71. ActivityOcrTmp := ActivityOcrTemplate
  72. sliceCompany := strings.Split(v.Company, "(")
  73. company := sliceCompany[0]
  74. //company := v.Company
  75. ActivityOcrTmp = strings.Replace(ActivityOcrTmp, "{{COMPANY}}", v.Company, -1)
  76. v.TitmeYMD = strings.Replace(v.TitmeYMD, "年", "-", -1)
  77. v.TitmeYMD = strings.Replace(v.TitmeYMD, "月", "-", -1)
  78. v.TitmeYMD = strings.Replace(v.TitmeYMD, "日", "", -1)
  79. weeknum := utils.StrDateTimeToWeek(v.TitmeYMD + " 00:00:00")
  80. havePm := strings.Contains(v.TitmeHM, "PM")
  81. var activityTime string
  82. activityTime = strings.Replace(v.TitmeHM, " ", "", -1)
  83. activityTime = strings.Replace(activityTime, "AM", "", -1)
  84. activityTime = strings.Replace(activityTime, "PM", "", -1)
  85. activityTime = v.TitmeYMD + " " + activityTime + ":00"
  86. resultTime := utils.StrTimeToTime(activityTime)
  87. var amOrPm string
  88. if havePm {
  89. //前端传过来的是 2:00PM 这里转成 14:00 PM
  90. slicePm := strings.Split(v.TitmeHM, ":")
  91. for sk, sv := range slicePm {
  92. // 如果是中午 12:30 PM 就不做任何处理
  93. if sk == 0 && sv != "12" {
  94. resultTime = resultTime.Add(12 * time.Hour)
  95. activityTime = resultTime.Format(utils.FormatDateTime)
  96. }
  97. }
  98. amOrPm = "PM"
  99. } else {
  100. amOrPm = "AM"
  101. }
  102. var condition string
  103. var pars []interface{}
  104. condition = " AND activity_type_id = 3 AND activity_time = ? AND temporary_label = ? "
  105. pars = append(pars, activityTime, company)
  106. total, e := cygx.GetActivityCount(condition, pars)
  107. if e != nil {
  108. err = errors.New("GetActivityCount,Err" + e.Error())
  109. return
  110. }
  111. if total > 0 {
  112. errMsg = "相同时段已存在对应活动"
  113. return
  114. }
  115. ActivityOcrTmp = strings.Replace(ActivityOcrTmp, "{{TIME}}", v.TitmeYMD+"("+weeknum+")"+resultTime.Format(utils.FormatTimeHm)+amOrPm, -1)
  116. if !utils.CheckStrHaveLetter(company) {
  117. ActivityOcrTmp = strings.Replace(ActivityOcrTmp, "{{LANGUAGE}}", "中文", -1)
  118. } else {
  119. ActivityOcrTmp = strings.Replace(ActivityOcrTmp, "{{LANGUAGE}}", "英文", -1)
  120. }
  121. req.Body += ActivityOcrTmp + "<hr>" //分隔符标签
  122. label := new(cygx.ActivityGroupIndustrialRep)
  123. label.TemporaryLabel = company
  124. req.List = append(req.List, label)
  125. }
  126. //初始化相关活动参数信息
  127. req.Body = strings.TrimRight(req.Body, "<hr>")
  128. req.DoType = 1
  129. req.ActivityTypeId = 3
  130. req.PermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
  131. req.CustomerTypeIds = "1,2,8,10,3,9,5,6,7"
  132. req.IsAllCustomerType = 1
  133. req.LimitPeopleNum = 10
  134. req.LabelType = 1
  135. req.VisibleRange = 2
  136. req.IsResearchPoints = 1
  137. req.IsNeedEmail = 1
  138. req.IsShowHz = 1 //是否同时在弘则展示 1是,0否
  139. // 研选点数
  140. pointsSet := new(cygx.CygxActivityPointsSetRsq)
  141. pointsSet.PointsObject = "1"
  142. pointsSet.UserPointsNum = "0.5"
  143. pointsSet.PointsType = "1"
  144. pointsSet.CompanyPointsNum = "0"
  145. pointsSet.CancelDeadlineType = "1"
  146. req.PointsSet = pointsSet
  147. return
  148. }
  149. // 代码冲突了先放这里
  150. func UpdateActivityVideoAndVoice(activityInfo *cygx.ActivityDetail, itemVoice *cygx.CygxActivityVoice, itemVideo *cygx.CygxActivityVideo) (err error) {
  151. if activityInfo.ActiveState != 3 {
  152. return // 没有结束的活动不会上传音视频
  153. }
  154. activityId := activityInfo.ActivityId
  155. var condition string
  156. var pars []interface{}
  157. //处理音频
  158. if itemVoice.ActivityId > 0 {
  159. condition = " AND activity_id = ? "
  160. pars = append(pars, activityId)
  161. total, e := cygx.GetCygxActivityVoiceCount(condition, pars)
  162. if e != nil {
  163. err = errors.New("GetCygxActivityVoiceCount" + e.Error())
  164. return
  165. }
  166. //activityId := itemVoice.ActivityId
  167. ////获取活动详情
  168. //activityInfo, e := cygx.GetAddActivityInfoById(activityId)
  169. //if e != nil {
  170. // err = errors.New("GetAddActivityInfoById, Err: " + e.Error())
  171. // return
  172. //}
  173. //易董办会的分析师电话会,为路演回放
  174. if (activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 7) && activityInfo.IsYidongConduct == 1 {
  175. itemVoice.FileType = 1
  176. } else {
  177. itemVoice.FileType = 2
  178. }
  179. shareImg, _ := MakeCygxMp3HtmlImg(itemVoice.VoicePlaySeconds, activityInfo.ChartPermissionId) //生成分享图片
  180. itemVoice.ShareImg = shareImg
  181. itemVoice.VoiceName = utils.RemoveFileSuffixName(itemVoice.VoiceName) //去掉后缀名称
  182. //如果等于0就新增,反之就修改
  183. if total == 0 {
  184. newId, e := cygx.AddCygxActivityVoice(itemVoice)
  185. if e != nil {
  186. err = errors.New("GetCygxActivityVoiceCount" + e.Error())
  187. return
  188. }
  189. go UpdateActivityVoiceResourceData(int(newId)) //写入首页最新 cygx_resource_data 表
  190. go SendWxMsgWithUpdateActivityVideoAndVoice(activityId, itemVoice.VoiceName) // 已结束的活动上传音频或视频后给已关注这个活动关联的产业的正式、试用 客户发送模板信息
  191. } else {
  192. //获取音频详情
  193. voiceDetail, e := cygx.GetCygxActivityVoiceReqDetailByActivityId(activityId)
  194. if e != nil {
  195. err = errors.New("GetCygxActivityVoiceReqDetail" + e.Error())
  196. return
  197. }
  198. //手动修改过的,二次编辑,文件类型不变
  199. if voiceDetail.IsByHand == 1 {
  200. itemVoice.FileType = voiceDetail.FileType
  201. }
  202. e = cygx.UpdateCygxActivityVoice(itemVoice)
  203. if e != nil {
  204. err = errors.New("UpdateCygxActivityVoice" + e.Error())
  205. return
  206. }
  207. go UpdateActivityVoiceResourceData(voiceDetail.ActivityVoiceId) //写入首页最新 cygx_resource_data 表
  208. }
  209. } else {
  210. voiceDetail, e := cygx.GetCygxActivityVoiceReqDetail(activityId)
  211. if e != nil && e.Error() != utils.ErrNoRow() {
  212. err = errors.New("GetCygxActivityVoiceReqDetail" + e.Error())
  213. return
  214. }
  215. if voiceDetail != nil {
  216. e = cygx.DeleteCygxActivityVoice(activityId)
  217. if e != nil {
  218. err = errors.New("DeleteCygxActivityVoice" + e.Error())
  219. return
  220. }
  221. go UpdateActivityVoiceResourceData(voiceDetail.ActivityVoiceId) //写入首页最新 cygx_resource_data 表
  222. }
  223. }
  224. //处理视频
  225. if itemVideo.ActivityId > 0 {
  226. condition = " AND art.activity_id = ? "
  227. pars = append(pars, activityId)
  228. total, e := cygx.GetActivityVideoCount(condition, pars)
  229. if e != nil {
  230. err = errors.New("GetActivityVideoCount" + e.Error())
  231. return
  232. }
  233. //activityId := itemVideo.ActivityId
  234. ////获取活动详情
  235. //activityInfo, e := cygx.GetAddActivityInfoById(activityId)
  236. //if e != nil {
  237. // err = errors.New("GetAddActivityInfoById, Err: " + e.Error())
  238. // return
  239. //}
  240. //易董办会的分析师电话会,为路演回放
  241. if (activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 7) && activityInfo.IsYidongConduct == 1 {
  242. itemVideo.FileType = 1
  243. } else {
  244. itemVideo.FileType = 2
  245. }
  246. shareImg, _ := MakeCygxMp4HtmlImg(itemVideo.VideoDuration, activityInfo.ChartPermissionId) //生成分享图片
  247. itemVideo.ShareImg = shareImg
  248. itemVideo.VideoName = utils.RemoveFileSuffixName(itemVideo.VideoName) //去掉后缀名称
  249. //视频文件更换阿里云oss地址 避免卡顿
  250. var newOssUrl string
  251. newOssUrl = strings.Replace(itemVideo.VideoUrl, "https://hzstatic.hzinsights.com", "https://hzchart.oss-accelerate.aliyuncs.com", -1)
  252. itemVideo.VideoUrl = newOssUrl
  253. //如果等于0就新增,反之就修改
  254. if total == 0 {
  255. newId, e := cygx.AddCygxActivityVideo(itemVideo)
  256. if e != nil {
  257. err = errors.New("AddCygxActivityVideo" + e.Error())
  258. return
  259. }
  260. go UpdateActivityVideoResourceData(int(newId)) //写入首页最新 cygx_resource_data 表
  261. go SendWxMsgWithUpdateActivityVideoAndVoice(activityId, itemVideo.VideoName) // 已结束的活动上传音频或视频后给已关注这个活动关联的产业的正式、试用 客户发送模板信息
  262. } else {
  263. //获取视频详情
  264. videoDetail, e := cygx.GetCygxActivityVideoReqDetail(activityId)
  265. if e != nil {
  266. err = errors.New("GetCygxActivityVideoReqDetail" + e.Error())
  267. return
  268. }
  269. //手动修改过的,二次编辑,文件类型不变
  270. if videoDetail.IsByHand == 1 {
  271. itemVideo.FileType = videoDetail.FileType
  272. }
  273. e = cygx.UpdateCygxActivityVideo(itemVideo)
  274. if e != nil {
  275. err = errors.New("UpdateCygxActivityVideo" + e.Error())
  276. return
  277. }
  278. go UpdateActivityVideoResourceData(videoDetail.VideoId) //写入首页最新 cygx_resource_data 表
  279. }
  280. } else {
  281. //删除原有的视频数据
  282. videoDetail, e := cygx.GetCygxActivityVideoReqDetail(activityId)
  283. if e != nil && e.Error() != utils.ErrNoRow() {
  284. err = errors.New("GetCygxActivityVideoReqDetail" + e.Error())
  285. return
  286. }
  287. if videoDetail != nil {
  288. e = cygx.DeleteCygxActivityVideo(activityId)
  289. if e != nil {
  290. err = errors.New("DeleteCygxActivityVideo" + e.Error())
  291. return
  292. }
  293. go UpdateActivityVideoResourceData(videoDetail.VideoId) //写入首页最新 cygx_resource_data 表
  294. }
  295. }
  296. return
  297. }