yidong.go 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389
  1. package services
  2. import (
  3. "context"
  4. "encoding/json"
  5. "errors"
  6. "fmt"
  7. "hongze/hongze_cygx/models"
  8. "hongze/hongze_cygx/models/yidong"
  9. "hongze/hongze_cygx/utils"
  10. "io/ioutil"
  11. "net/http"
  12. "strings"
  13. "time"
  14. )
  15. // GetActivityTypeIdWithYiDong 根据易董同步过来的活动类型,自动匹配行业
  16. func GetActivityTypeIdWithYiDong(industrySwName string) (chartPermissionId int) {
  17. mapIndustrySwName := map[string]int{
  18. "家用电器": utils.XIAO_FEI_ID,
  19. "纺织服饰": utils.XIAO_FEI_ID,
  20. "休闲服务": utils.XIAO_FEI_ID,
  21. "食品饮料": utils.XIAO_FEI_ID,
  22. "美容护理": utils.XIAO_FEI_ID,
  23. //消费
  24. "汽车": utils.ZHI_ZAO_ID,
  25. "机械设备": utils.ZHI_ZAO_ID,
  26. "电力设备": utils.ZHI_ZAO_ID,
  27. //智造
  28. "电子": utils.KE_JI_ID,
  29. "计算机": utils.KE_JI_ID,
  30. "通信": utils.KE_JI_ID,
  31. //科技
  32. "医药生物": utils.YI_YAO_ID,
  33. //医药
  34. "策略": utils.CE_LUE_ID,
  35. //策略
  36. "非银金融": utils.CHART_PERMISSION_ID_YANXUAN,
  37. "建筑装饰": utils.CHART_PERMISSION_ID_YANXUAN,
  38. "基础化工": utils.CHART_PERMISSION_ID_YANXUAN,
  39. "农林牧渔": utils.CHART_PERMISSION_ID_YANXUAN,
  40. "传媒": utils.CHART_PERMISSION_ID_YANXUAN,
  41. "公用事业": utils.CHART_PERMISSION_ID_YANXUAN,
  42. "建筑材料": utils.CHART_PERMISSION_ID_YANXUAN,
  43. "房地产": utils.CHART_PERMISSION_ID_YANXUAN,
  44. "采掘": utils.CHART_PERMISSION_ID_YANXUAN,
  45. "轻工制造": utils.CHART_PERMISSION_ID_YANXUAN,
  46. "钢铁": utils.CHART_PERMISSION_ID_YANXUAN,
  47. "交通运输": utils.CHART_PERMISSION_ID_YANXUAN,
  48. "国防军工": utils.CHART_PERMISSION_ID_YANXUAN,
  49. "银行": utils.CHART_PERMISSION_ID_YANXUAN,
  50. "有色金属": utils.CHART_PERMISSION_ID_YANXUAN,
  51. "综合": utils.CHART_PERMISSION_ID_YANXUAN,
  52. "商业贸易": utils.CHART_PERMISSION_ID_YANXUAN,
  53. "宏观": utils.CHART_PERMISSION_ID_YANXUAN,
  54. "金融工程": utils.CHART_PERMISSION_ID_YANXUAN,
  55. "商贸零售": utils.CHART_PERMISSION_ID_YANXUAN,
  56. "社会服务": utils.CHART_PERMISSION_ID_YANXUAN,
  57. "煤炭": utils.CHART_PERMISSION_ID_YANXUAN,
  58. "石油石化": utils.CHART_PERMISSION_ID_YANXUAN,
  59. "环保": utils.CHART_PERMISSION_ID_YANXUAN,
  60. //研选
  61. }
  62. chartPermissionId = mapIndustrySwName[industrySwName]
  63. return
  64. }
  65. // GetActivityTypeIdWithYiDong 根据易董同步过来的活动类型,自动匹配行业
  66. func GetActivityTypeNameWithYiDong(industrySwName string) (chartPermissionName string) {
  67. mapIndustrySwName := map[string]string{
  68. "家用电器": utils.XIAO_FEI_NAME,
  69. "纺织服饰": utils.XIAO_FEI_NAME,
  70. "休闲服务": utils.XIAO_FEI_NAME,
  71. "食品饮料": utils.XIAO_FEI_NAME,
  72. "美容护理": utils.XIAO_FEI_NAME,
  73. //消费
  74. "汽车": utils.ZHI_ZAO_NAME,
  75. "机械设备": utils.ZHI_ZAO_NAME,
  76. "电力设备": utils.ZHI_ZAO_NAME,
  77. //智造
  78. "电子": utils.KE_JI_NAME,
  79. "计算机": utils.KE_JI_NAME,
  80. "通信": utils.KE_JI_NAME,
  81. //科技
  82. "医药生物": utils.YI_YAO_NAME,
  83. //医药
  84. "策略": utils.CE_LUE_NAME,
  85. //策略
  86. "非银金融": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  87. "建筑装饰": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  88. "基础化工": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  89. "农林牧渔": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  90. "传媒": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  91. "公用事业": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  92. "建筑材料": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  93. "房地产": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  94. "采掘": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  95. "轻工制造": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  96. "钢铁": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  97. "交通运输": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  98. "国防军工": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  99. "银行": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  100. "有色金属": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  101. "综合": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  102. "商业贸易": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  103. "宏观": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  104. "金融工程": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  105. "商贸零售": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  106. "社会服务": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  107. "煤炭": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  108. "石油石化": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  109. "环保": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  110. //研选
  111. }
  112. chartPermissionName = mapIndustrySwName[industrySwName]
  113. return
  114. }
  115. var yidongHongzeCode = "RI0011" // 弘则在易董那边建会的公司code
  116. // 获取易董token
  117. func GetYiDongToken() (token string, err error) {
  118. defer func() {
  119. if err != nil {
  120. fmt.Println(err)
  121. utils.FileLog.Info(err.Error())
  122. }
  123. }()
  124. cacheKey := utils.YI_DONG_ZHENG_TONG_YUN_TOKEN_KEY
  125. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  126. if ttlTime > 0 {
  127. token, _ = utils.Rc.RedisString(cacheKey)
  128. }
  129. if token == "" {
  130. url := utils.YiDongZhengTongYunUrl + "oauth/token?grant_type=client_credentials&response_type=token&client_id=" + utils.YiDongZhengTongYunAppid + "&client_secret=" + utils.YiDongZhengTongYunSecret
  131. method := "GET"
  132. client := &http.Client{}
  133. req, errReq := http.NewRequest(method, url, nil)
  134. if errReq != nil {
  135. err = errReq
  136. return
  137. }
  138. res, errReq := client.Do(req)
  139. if errReq != nil {
  140. err = errReq
  141. return
  142. }
  143. defer res.Body.Close()
  144. type Ydtoklen struct {
  145. Success bool `json:"success"`
  146. ExpiresIn int `json:"expires_in"`
  147. AccessToken string `json:"access_token"`
  148. }
  149. var ydtoklen Ydtoklen
  150. body, errReq := ioutil.ReadAll(res.Body)
  151. if errReq != nil {
  152. err = errReq
  153. return
  154. }
  155. errReq = json.Unmarshal(body, &ydtoklen)
  156. if errReq != nil {
  157. err = errReq
  158. return
  159. }
  160. token = ydtoklen.AccessToken
  161. utils.Rc.Put(cacheKey, ydtoklen.AccessToken, time.Second*7000)
  162. }
  163. return
  164. }
  165. // 获取易董活动列表
  166. func GetYiDongActivity(cont context.Context) (err error) {
  167. //func GetYiDongActivity() (err error) {
  168. defer func() {
  169. if err != nil {
  170. fmt.Println(err)
  171. go utils.SendAlarmMsg("获取易董活动列表失败:"+err.Error(), 2)
  172. utils.FileLog.Info(err.Error())
  173. }
  174. }()
  175. var token string
  176. token, _ = GetYiDongToken()
  177. url := utils.YiDongZhengTongYunUrl + "interact/activityManageApi/getRoadshowList?access_token=" + token
  178. method := "POST"
  179. payload := strings.NewReader(`{
  180. "meetingStatus": "0"
  181. }`)
  182. client := &http.Client{}
  183. req, err := http.NewRequest(method, url, payload)
  184. if err != nil {
  185. fmt.Println(err)
  186. utils.FileLog.Info(err.Error())
  187. return
  188. }
  189. req.Header.Add("Content-Type", "application/json")
  190. res, err := client.Do(req)
  191. if err != nil {
  192. fmt.Println(err)
  193. utils.FileLog.Info(err.Error())
  194. return
  195. }
  196. defer res.Body.Close()
  197. var ApifoxModal *models.ApifoxModal
  198. body, err := ioutil.ReadAll(res.Body)
  199. if err != nil {
  200. fmt.Println(err)
  201. utils.FileLog.Info(err.Error())
  202. return
  203. }
  204. //添加请求日志记录
  205. itemApiLog := new(models.CygxThreeApiLog)
  206. itemApiLog.CreateTime = time.Now()
  207. itemApiLog.Source = 1
  208. itemApiLog.Url = url
  209. itemApiLog.Body = utils.ReplaceSpaceAndWrap(fmt.Sprint(payload))
  210. itemApiLog.Result = string(body)
  211. go models.AddCygxThreeApiLog(itemApiLog)
  212. err = json.Unmarshal(body, &ApifoxModal)
  213. if err != nil {
  214. fmt.Println("Getres.PublicGetDate Err:", err.Error())
  215. utils.FileLog.Info(err.Error())
  216. return
  217. }
  218. OldActYIdongList, err := models.GetActivityListByYiDong()
  219. if err != nil {
  220. fmt.Println(err)
  221. utils.FileLog.Info(string(err.Error()))
  222. return
  223. }
  224. mapOldYiDong := make(map[string]string)
  225. mapOldYiDongBody := make(map[string]string)
  226. for _, v := range OldActYIdongList {
  227. mapOldYiDong[v.YidongActivityId] = v.YidongActivityId
  228. mapOldYiDongBody[v.YidongActivityId] = fmt.Sprint(v.ActivityName, v.Label, v.ChartPermissionId, v.ActivityTime, v.YidongActivityEndTime, v.DistinguishedGuest)
  229. }
  230. // 通过查研观向观向建会的易董活动
  231. yiDongByCygxList, err := models.GetActivityListByYiDongByCygx()
  232. if err != nil {
  233. fmt.Println(err)
  234. utils.FileLog.Info(string(err.Error()))
  235. return
  236. }
  237. yiDongByCygxMap := make(map[string]string)
  238. for _, v := range yiDongByCygxList {
  239. yiDongByCygxMap[v.YidongActivityIdByCygx] = v.YidongActivityIdByCygx
  240. }
  241. var itemsAdd []*models.CygxActivity
  242. if len(ApifoxModal.Result) > 0 {
  243. actList := ApifoxModal.Result
  244. for _, v := range actList {
  245. //同步有效性 1有效,0失效
  246. if v.SyncFlag == "0" {
  247. continue
  248. }
  249. //如果是通过查研观向观向建会的易董活动,就不进行更新的操作
  250. if _, ok := yiDongByCygxMap[v.ID]; ok {
  251. continue
  252. }
  253. //fmt.Println(v.CompanyCode)
  254. if v.CompanyCode == yidongHongzeCode { //弘则在易董那边建会的公司code,如果是弘则的就不同步
  255. continue
  256. }
  257. var item = new(models.CygxActivity)
  258. item.YidongActivityId = v.ID
  259. item.ActivityTypeId = 3
  260. item.ActivityTypeName = "公司调研电话会"
  261. sliceCompanyInfo := strings.Split(v.CompanyInfo, "(")
  262. sliceActivityTitle := strings.Split(v.CompanyInfo, ")")
  263. companyInfo := sliceCompanyInfo[0]
  264. if len(sliceActivityTitle) > 1 {
  265. item.ActivityName = companyInfo + v.Title
  266. } else {
  267. item.ActivityName = v.Title
  268. }
  269. //fmt.Println(item.ActivityName)
  270. //return err
  271. item.LastUpdatedTime = time.Now()
  272. item.Label = companyInfo
  273. item.TemporaryLabel = companyInfo
  274. item.ChartPermissionId = utils.CHART_PERMISSION_ID_YANXUAN
  275. item.ChartPermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
  276. item.ChartPermissionIdDeputy = GetActivityTypeIdWithYiDong(v.IndustrySwName)
  277. item.ChartPermissionNameDeputy = GetActivityTypeNameWithYiDong(v.IndustrySwName)
  278. item.ChartPermissionNames = item.ChartPermissionName
  279. //if item.ChartPermissionId != item.ChartPermissionIdDeputy {
  280. item.IsShowHz = 1 //默认弘则活动也展示 11.0
  281. //}
  282. item.ActivityTime = v.Start
  283. item.YidongActivityEndTime = v.End
  284. item.YidongSignUpStart = v.SignUpStart
  285. item.YidongSignUpEnd = v.SignUpEnd
  286. item.YidongActivityEndTime = v.End
  287. item.ActivityTimeText = GetActivityTextTime(v.Start)
  288. item.YidongActivityUrl = v.URL
  289. item.ActivityJoinType = v.ActivityJoinType
  290. item.IsExternalLabel = 1
  291. detailYidng, err := GetYiDongActivityDetail(v.ID)
  292. if err != nil {
  293. return err
  294. }
  295. detailList := detailYidng.Resultdetail.GuestPersonList
  296. for _, vdetail := range detailList {
  297. item.DistinguishedGuest += vdetail.PersonName + " " + vdetail.JobName + ","
  298. }
  299. item.DistinguishedGuest = strings.TrimRight(item.DistinguishedGuest, ",")
  300. item.Body = "<p>" + "【" + item.ActivityName + "】" + "<p>时间:" + item.ActivityTimeText + "</p>嘉宾:" + item.DistinguishedGuest + "</p>"
  301. //fmt.Println(item.Body)
  302. //return err
  303. if mapOldYiDong[v.ID] == "" {
  304. itemsAdd = append(itemsAdd, item)
  305. newId, err := models.AddCygxActivity(item)
  306. if err != nil {
  307. fmt.Println(err)
  308. utils.FileLog.Info(string(err.Error()))
  309. return err
  310. }
  311. //把公司名称当做标的 对活动进行产业标的的关联
  312. YidongActivityGroup(companyInfo, int(newId))
  313. } else {
  314. //如果内容主体有做变更,就修改内容
  315. if mapOldYiDongBody[v.ID] != fmt.Sprint(item.ActivityName+"12", item.Label, item.ChartPermissionId, item.ActivityTime, item.YidongActivityEndTime, item.DistinguishedGuest) {
  316. updateParams := make(map[string]interface{})
  317. updateParams["ActivityName"] = item.ActivityName
  318. updateParams["Body"] = item.Body
  319. updateParams["Label"] = item.Label
  320. //updateParams["TemporaryLabel"] = item.TemporaryLabel
  321. updateParams["DistinguishedGuest"] = item.DistinguishedGuest
  322. updateParams["ChartPermissionId"] = item.ChartPermissionId
  323. updateParams["ChartPermissionName"] = item.ChartPermissionName
  324. updateParams["ChartPermissionNames"] = item.ChartPermissionNames
  325. updateParams["ActivityTime"] = item.ActivityTime
  326. updateParams["YidongActivityEndTime"] = item.YidongActivityEndTime
  327. updateParams["ActivityTimeText"] = item.ActivityTimeText
  328. updateParams["YidongActivityUrl"] = item.YidongActivityUrl
  329. updateParams["ActivityJoinType"] = item.ActivityJoinType
  330. updateParams["YidongSignUpStart"] = item.YidongSignUpStart
  331. updateParams["YidongSignUpEnd"] = item.YidongSignUpEnd
  332. updateParams["ChartPermissionIdDeputy"] = item.ChartPermissionIdDeputy
  333. updateParams["ChartPermissionNameDeputy"] = item.ChartPermissionNameDeputy
  334. updateParams["IsShowHz"] = item.IsShowHz
  335. updateParams["IsExternalLabel"] = 1
  336. updateParams["LastUpdatedTime"] = time.Now()
  337. whereParam := map[string]interface{}{"yidong_activity_id": item.YidongActivityId}
  338. err = models.UpdateByExpr(models.CygxActivity{}, whereParam, updateParams)
  339. if err != nil {
  340. return err
  341. }
  342. }
  343. }
  344. }
  345. }
  346. return
  347. }
  348. // 获取易董活动详情
  349. func GetYiDongActivityDetail(activityId string) (detail *models.ApifoxModaldetail, err error) {
  350. defer func() {
  351. if err != nil {
  352. go utils.SendAlarmMsg("获取易董活动详情失败:"+err.Error(), 2)
  353. }
  354. }()
  355. var token string
  356. token, _ = GetYiDongToken()
  357. url := utils.YiDongZhengTongYunUrl + "interact/activityManageApi/getRoadshowDetail?access_token=" + token
  358. method := "POST"
  359. payload := strings.NewReader(`{"activityId":"` + activityId + `"}`)
  360. client := &http.Client{}
  361. req, err := http.NewRequest(method, url, payload)
  362. if err != nil {
  363. fmt.Println(err)
  364. utils.FileLog.Info(err.Error())
  365. return
  366. }
  367. req.Header.Add("Content-Type", "application/json")
  368. res, err := client.Do(req)
  369. if err != nil {
  370. fmt.Println(err)
  371. utils.FileLog.Info(err.Error())
  372. return
  373. }
  374. defer res.Body.Close()
  375. var ApifoxModal *models.ApifoxModaldetail
  376. body, err := ioutil.ReadAll(res.Body)
  377. if err != nil {
  378. fmt.Println(err)
  379. utils.FileLog.Info(err.Error())
  380. return
  381. }
  382. //添加请求日志记录
  383. itemApiLog := new(models.CygxThreeApiLog)
  384. itemApiLog.CreateTime = time.Now()
  385. itemApiLog.Source = 1
  386. itemApiLog.Url = url
  387. itemApiLog.Body = utils.ReplaceSpaceAndWrap(fmt.Sprint(payload))
  388. itemApiLog.Result = string(body)
  389. go models.AddCygxThreeApiLog(itemApiLog)
  390. err = json.Unmarshal(body, &ApifoxModal)
  391. if err != nil {
  392. fmt.Println("Getres.PublicGetDate Err:", err.Error())
  393. utils.FileLog.Info(err.Error())
  394. return
  395. }
  396. detail = ApifoxModal
  397. return
  398. }
  399. // 生成用户相关信息接口 获取用户tgc
  400. func GetYiDongCreateUserInfo(user *models.WxUserItem) (userTgc string, err error) {
  401. defer func() {
  402. if err != nil {
  403. fmt.Println(err)
  404. go utils.SendAlarmMsg("生成用户相关信息接口 获取用户tgc失败:"+err.Error(), 2)
  405. utils.FileLog.Info(err.Error())
  406. }
  407. }()
  408. url := utils.YiDongHuaWeiYunUrl + "app/hz/createUserInfo"
  409. method := "POST"
  410. payload := strings.NewReader(`{
  411. "phone": "` + user.Mobile + `",
  412. "personName": "` + user.RealName + `",
  413. "companyName": "` + user.CompanyName + `",
  414. "jobName": "` + user.Position + `",
  415. "mobileCountryCode": "+` + user.CountryCode + `",
  416. "sourceFrom": "01"
  417. }`)
  418. client := &http.Client{}
  419. req, err := http.NewRequest(method, url, payload)
  420. if err != nil {
  421. fmt.Println(err)
  422. utils.FileLog.Info(err.Error())
  423. return
  424. }
  425. req.Header.Add("Content-Type", "application/json")
  426. res, err := client.Do(req)
  427. if err != nil {
  428. fmt.Println(err)
  429. utils.FileLog.Info(err.Error())
  430. return
  431. }
  432. defer res.Body.Close()
  433. var ApifoxModal *models.ApifoxModalUserTgc
  434. body, err := ioutil.ReadAll(res.Body)
  435. if err != nil {
  436. fmt.Println(err)
  437. utils.FileLog.Info(err.Error())
  438. return
  439. }
  440. err = json.Unmarshal(body, &ApifoxModal)
  441. if err != nil {
  442. fmt.Println("Getres.PublicGetDate Err:", err.Error())
  443. utils.FileLog.Info(err.Error())
  444. return
  445. }
  446. userTgc = ApifoxModal.Result.Tgc
  447. return
  448. }
  449. // GetYiDongOriginalLink 将易懂的短连接转为长链接
  450. func GetYiDongOriginalLink(item *models.ActivityDetail) (yidongLongLink string, err error) {
  451. defer func() {
  452. if err != nil {
  453. fmt.Println(err)
  454. go utils.SendAlarmMsg("将易懂的短连接转为长链接 失败:"+err.Error(), 2)
  455. utils.FileLog.Info(err.Error())
  456. }
  457. }()
  458. sliceYidongActivityUrl := strings.Split(item.YidongActivityUrl, "/")
  459. var shortLink string
  460. if len(sliceYidongActivityUrl) > 1 {
  461. shortLink = sliceYidongActivityUrl[len(sliceYidongActivityUrl)-1]
  462. }
  463. var token string
  464. token, err = GetYiDongToken()
  465. if err != nil {
  466. fmt.Println(err)
  467. return
  468. }
  469. url := utils.YiDonggetOriginalLink + shortLink + "&access_token=" + token
  470. fmt.Println(url)
  471. method := "GET"
  472. client := &http.Client{}
  473. req, err := http.NewRequest(method, url, nil)
  474. if err != nil {
  475. fmt.Println(err)
  476. return
  477. }
  478. res, err := client.Do(req)
  479. if err != nil {
  480. fmt.Println(err)
  481. return
  482. }
  483. defer res.Body.Close()
  484. var ApifoxModal *models.ApifoxgetOriginalLink
  485. body, err := ioutil.ReadAll(res.Body)
  486. if err != nil {
  487. fmt.Println(err)
  488. utils.FileLog.Info(err.Error())
  489. return
  490. }
  491. err = json.Unmarshal(body, &ApifoxModal)
  492. if err != nil {
  493. fmt.Println("Getres.PublicGetDate Err:", err.Error())
  494. utils.FileLog.Info(err.Error())
  495. return
  496. }
  497. lingLink := ApifoxModal.Result
  498. //fmt.Println(lingLink)
  499. //
  500. //slicelingLink := strings.Split(lingLink, "redirect_uri=")
  501. ////var shortLink string
  502. //if len(slicelingLink) > 1 {
  503. // lingLink = slicelingLink[len(slicelingLink)-1]
  504. //}
  505. yidongLongLink = lingLink
  506. return
  507. }
  508. // 处理易董这边过来的时间格式
  509. func GetActivityTextTime(timeYidong string) (timeText string) {
  510. strTime := timeYidong
  511. startTime := utils.StrTimeToTime(strTime)
  512. week := utils.StrDateTimeToWeek(strTime)
  513. timeStrYmd := startTime.Format(utils.FormatDate)
  514. timeStrHmm := startTime.Format(utils.FormatTime)
  515. timeYmd := utils.StrTimeToTime(timeStrYmd + " 12:00:00") //拼接当天中午12点的时间
  516. var amOrPm string
  517. if startTime.After(timeYmd) {
  518. amOrPm = " PM"
  519. } else {
  520. amOrPm = " AM"
  521. }
  522. timeText = timeStrYmd + "(" + week + ")" + timeStrHmm + amOrPm
  523. return
  524. }
  525. //func init() {
  526. // GetYiDongActivityMeeting()
  527. //}
  528. // GetYiDongActivityMeeting获取易董到会详情
  529. func GetYiDongActivityMeeting(cont context.Context) (err error) {
  530. //func GetYiDongActivityMeeting() (err error) {
  531. var condition string
  532. startDate := time.Now().AddDate(0, 0, -1).Format(utils.FormatDateTime)
  533. endDate := time.Now().Add(-time.Minute * 120).Format(utils.FormatDateTime)
  534. condition += ` AND activity_time > ` + "'" + startDate + "'"
  535. condition += ` AND activity_time < ` + "'" + endDate + "'"
  536. //fmt.Println(startDate)
  537. artivityListYidong, err := models.GetActivityListByYidong(condition)
  538. if err != nil {
  539. fmt.Println("GetActivityListByYidong Err:", err.Error())
  540. return err
  541. }
  542. //fmt.Println(artivityListYidong)
  543. //return
  544. //fmt.Println("artivityListYidong", artivityListYidong)
  545. //return err
  546. if len(artivityListYidong) == 0 {
  547. return err
  548. }
  549. var token string
  550. token, _ = GetYiDongToken()
  551. for _, v := range artivityListYidong {
  552. defer func() {
  553. if err != nil {
  554. go utils.SendAlarmMsg("获取易董到会详情失败:"+err.Error(), 2)
  555. }
  556. }()
  557. var yidongActivityId string
  558. if v.YidongActivityId != "" {
  559. yidongActivityId = v.YidongActivityId
  560. } else if v.YidongActivityIdByCygx != "" {
  561. yidongActivityId = v.YidongActivityIdByCygx
  562. }
  563. url := utils.YiDongZhengTongYunUrl + "interact/activityManageApi/getAttendPersonList?access_token=" + token
  564. method := "POST"
  565. payload := strings.NewReader(`{"activityId":"` + yidongActivityId + `"}`)
  566. client := &http.Client{}
  567. req, err := http.NewRequest(method, url, payload)
  568. if err != nil {
  569. fmt.Println(err)
  570. utils.FileLog.Info(err.Error())
  571. return err
  572. }
  573. req.Header.Add("Content-Type", "application/json")
  574. res, err := client.Do(req)
  575. if err != nil {
  576. fmt.Println(err)
  577. utils.FileLog.Info(err.Error())
  578. return err
  579. }
  580. defer res.Body.Close()
  581. var ApifoxModal *models.ApifoxModaluser
  582. body, err := ioutil.ReadAll(res.Body)
  583. if err != nil {
  584. fmt.Println(err)
  585. utils.FileLog.Info(err.Error())
  586. return err
  587. }
  588. //utils.FileLog.Info(string(body))
  589. //fmt.Println(string(body))
  590. err = json.Unmarshal(body, &ApifoxModal)
  591. if err != nil {
  592. fmt.Println("Getres.PublicGetDate Err:", err.Error())
  593. utils.FileLog.Info(err.Error())
  594. return err
  595. }
  596. //跟易董返回的用户状态修改活动以提交到会状态
  597. err = models.UpdateCygxActivitySubmitMeetingByYidong(yidongActivityId)
  598. if err != nil {
  599. fmt.Println("UpdateCygxActivitySubmitMeetingByYidong Err:", err.Error())
  600. return err
  601. }
  602. var mobiles []string
  603. var mobileStr string
  604. var mobileStrMeet string
  605. mapActivityAttendanceDetail := make(map[string]*models.CygxActivityAttendanceDetail)
  606. if len(ApifoxModal.Result) > 0 {
  607. itemlog := new(models.CygxYidongActivityMeetingApiLog)
  608. itemlog.YidongActivityId = yidongActivityId
  609. itemlog.Data = string(body)
  610. itemlog.CreateTime = time.Now()
  611. err = models.AddCygxYidongActivityMeetingApiLog(itemlog)
  612. if err != nil {
  613. fmt.Println("AddCygxYidongActivityMeetingApiLog Err:", err.Error())
  614. return err
  615. }
  616. var itemsUpdate []*models.CygxActivitySignupDetail
  617. needAddAttendanc := make([]*models.CygxActivityAttendanceDetail, 0)
  618. for _, vresult := range ApifoxModal.Result {
  619. if vresult.PersonTelephone == "" {
  620. continue
  621. }
  622. if vresult.Duration != "" || vresult.DurationReview != "" || vresult.DurationLive != "" {
  623. mobiles = append(mobiles, vresult.PersonTelephone)
  624. //err = models.UpdateCygxActivitySignupisMeet(v.ActivityId, vresult.PersonTelephone)
  625. //if err != nil {
  626. // fmt.Println("UpdateCygxActivitySignupisMeet Err:", err.Error())
  627. // return err
  628. //}
  629. var itemDetail = new(models.CygxActivitySignupDetail)
  630. if vresult.Duration != "" || vresult.DurationLive != "" {
  631. if vresult.Duration == "" {
  632. vresult.Duration = vresult.DurationLive
  633. }
  634. itemDetail.FirstMeetingTime = vresult.StartTime
  635. itemDetail.LastMeetingTime = vresult.EndTime
  636. itemDetail.Duration = vresult.Duration
  637. itemDetail.MeetingStatusStr = "直播"
  638. } else if vresult.DurationReview != "" {
  639. itemDetail.FirstMeetingTime = vresult.StartTimeReview
  640. itemDetail.LastMeetingTime = vresult.EndTimeReview
  641. itemDetail.Duration = vresult.DurationReview
  642. itemDetail.MeetingStatusStr = "回放"
  643. }
  644. itemDetail.Position = vresult.JobName
  645. itemDetail.RealName = vresult.PersonName
  646. itemDetail.Mobile = vresult.PersonTelephone
  647. itemDetail.OutboundMobile = vresult.PersonTelephone
  648. itemDetail.IsMeeting = 1
  649. itemDetail.ActivityId = v.ActivityId
  650. mapActivityAttendanceDetail[vresult.PersonTelephone] = new(models.CygxActivityAttendanceDetail)
  651. mapActivityAttendanceDetail[vresult.PersonTelephone].FirstMeetingTime = vresult.StartTime
  652. mapActivityAttendanceDetail[vresult.PersonTelephone].LastMeetingTime = vresult.EndTime
  653. mapActivityAttendanceDetail[vresult.PersonTelephone].Duration = utils.GetAttendanceDetailSecondsByYiDong(vresult.Duration)
  654. itemsUpdate = append(itemsUpdate, itemDetail)
  655. } else {
  656. continue
  657. }
  658. item := new(models.CygxActivityAttendanceDetail)
  659. item.ActivityId = v.ActivityId
  660. item.Mobile = vresult.PersonTelephone
  661. if vresult.Duration != "" {
  662. item.FirstMeetingTime = vresult.StartTime
  663. item.LastMeetingTime = vresult.EndTime
  664. item.Duration = vresult.Duration
  665. item.MeetingStatusStr = "直播"
  666. } else if vresult.DurationReview != "" {
  667. item.FirstMeetingTime = vresult.StartTimeReview
  668. item.LastMeetingTime = vresult.EndTimeReview
  669. item.Duration = vresult.DurationReview
  670. item.MeetingStatusStr = "回放"
  671. }
  672. item.Position = vresult.JobName
  673. item.RealName = vresult.PersonName
  674. item.FirstMeetingTime = vresult.StartTime
  675. item.LastMeetingTime = vresult.EndTime
  676. item.Duration = vresult.Duration
  677. item.IsMeetingStr = 1
  678. mobileStrMeet += "'" + vresult.PersonTelephone + "'" + ","
  679. item.CreateTime = time.Now()
  680. needAddAttendanc = append(needAddAttendanc, item)
  681. mobileStr += "'" + vresult.PersonTelephone + "'" + ","
  682. }
  683. lenmobiles := len(mobiles)
  684. if lenmobiles > 0 {
  685. var parsYd []interface{}
  686. var conditionYd string
  687. conditionYd = ` AND mobile IN (` + utils.GetOrmInReplace(lenmobiles) + `) AND activity_id=? `
  688. parsYd = append(parsYd, mobiles, v.ActivityId)
  689. err = models.UpdateCygxActivitySignupisMeetList(conditionYd, parsYd)
  690. if err != nil {
  691. fmt.Println("UpdateCygxActivitySignupisMeetList Err:", err.Error())
  692. return err
  693. }
  694. err = models.UpdateActivitySignupDetailMultiByYiDong(itemsUpdate)
  695. if err != nil {
  696. fmt.Println("UpdateActivitySignupDetailMultiByYiDong Err:", err.Error())
  697. return err
  698. }
  699. }
  700. mobileStr = strings.TrimRight(mobileStr, ",")
  701. if mobileStr == "" {
  702. mobileStr = "1"
  703. }
  704. mobileStrMeet = strings.TrimRight(mobileStrMeet, ",")
  705. if mobileStrMeet == "" {
  706. mobileStrMeet = "1"
  707. }
  708. listUser, err := models.GetWxUserOutboundMobile(mobileStr)
  709. if err != nil {
  710. fmt.Println("GetWxUserOutboundMobile Err:", err.Error())
  711. return err
  712. }
  713. for kAdd, vAdd := range needAddAttendanc {
  714. for _, v2 := range listUser {
  715. if v2.OutboundMobile == vAdd.Mobile || v2.Mobile == vAdd.Mobile {
  716. if needAddAttendanc[kAdd].CompanyId <= 1 {
  717. needAddAttendanc[kAdd].CompanyId = v2.CompanyId
  718. needAddAttendanc[kAdd].SellerName = v2.SellerName
  719. needAddAttendanc[kAdd].CompanyName = v2.CompanyName
  720. //needAddAttendanc[k].IsMeetingStr = 1
  721. }
  722. }
  723. }
  724. }
  725. //参会记录
  726. err = models.AddAttendancDetail(needAddAttendanc, v.ActivityId, mobileStrMeet)
  727. if err != nil {
  728. fmt.Println("AddAttendancDetail Err:", err.Error())
  729. return err
  730. }
  731. ////处理是否限制报名
  732. err = AddCygxActivityRestrictSignupByAdmin(v.ActivityId)
  733. if err != nil {
  734. fmt.Println("AddCygxActivityRestrictSignupByAdmin Err:", err.Error())
  735. return err
  736. }
  737. AddctivitySignupDetailByJmcjNew(needAddAttendanc, []int{v.ActivityId})
  738. }
  739. }
  740. return
  741. }
  742. // YidongActivityGroup 添加活动与产业标的的关联
  743. func YidongActivityGroup(subjectName string, activityId int) (err error) {
  744. subjectList, err := models.GetCygxIndustrialSubjectList(subjectName)
  745. if err != nil {
  746. fmt.Println(err)
  747. return err
  748. }
  749. if len(subjectList) == 0 {
  750. return err
  751. }
  752. fmt.Println("去掉临时标签的活动", activityId)
  753. err = models.UpdateActivityshowSubject(activityId)
  754. if err != nil {
  755. go utils.SendAlarmMsg("UpdateActivityshowSubject :根据易董推过来的匹配信息,判断临时标签是否展示失败"+err.Error(), 2)
  756. }
  757. var industrialActivityItems []*models.CygxIndustrialActivityGroupManagement
  758. var subjectActivityItems []*models.CygxIndustrialActivityGroupSubject
  759. mapSubjectName := make(map[string]string)
  760. for _, v := range subjectList {
  761. industrialActivityItem := new(models.CygxIndustrialActivityGroupManagement)
  762. subjectActivityItem := new(models.CygxIndustrialActivityGroupSubject)
  763. industrialActivityItem.ActivityId = activityId
  764. industrialActivityItem.IndustrialManagementId = v.IndustrialManagementId
  765. industrialActivityItem.Source = 1
  766. industrialActivityItem.CreateTime = time.Now()
  767. industrialActivityItems = append(industrialActivityItems, industrialActivityItem)
  768. subjectActivityItem.ActivityId = activityId
  769. subjectActivityItem.IndustrialSubjectId = v.IndustrialSubjectId
  770. subjectActivityItem.Source = 1
  771. subjectActivityItem.CreateTime = time.Now()
  772. if mapSubjectName[v.SubjectName] == "" {
  773. subjectActivityItems = append(subjectActivityItems, subjectActivityItem)
  774. mapSubjectName[v.SubjectName] = v.SubjectName
  775. }
  776. }
  777. err = models.AddCygxActiuvityGroupMulti(industrialActivityItems, subjectActivityItems)
  778. if err != nil {
  779. go utils.SendAlarmMsg("AddCygxActiuvityGroupMulti :批量添加易董活动关联的活动标签失败"+err.Error(), 2)
  780. }
  781. return
  782. }
  783. // 会前一小时将,报名信息同步到易董
  784. func YiDongSignAppointmentsForThird(cont context.Context) (err error) {
  785. //func YiDongSignAppointmentsForThird() (err error) {
  786. defer func() {
  787. if err != nil {
  788. fmt.Println(err)
  789. go utils.SendAlarmMsg("会前一小时将,报名信息同步到易董,同步失败"+err.Error(), 2)
  790. }
  791. }()
  792. var pars []interface{}
  793. var condition string
  794. startDate := time.Now().Add(+time.Minute * 45).Format(utils.FormatDateTime)
  795. endDate := time.Now().Add(+time.Minute * 60).Format(utils.FormatDateTime)
  796. condition = " AND is_yidong_sign_up = 0 AND yidong_activity_id_by_cygx != '' AND activity_time BETWEEN ? AND ? "
  797. pars = append(pars, startDate, endDate)
  798. activityList, err := models.GetActivityListByCondition(condition, pars)
  799. if err != nil {
  800. return
  801. }
  802. if len(activityList) == 0 {
  803. return
  804. }
  805. listEmail, e := models.GetAskEmail()
  806. if e != nil {
  807. err = errors.New("GetAskEmail, Err: " + e.Error())
  808. return
  809. }
  810. //获取某一个活动下面不需要推送的主讲人手机号
  811. idAndMobileNoSendMap := make(map[string]bool)
  812. for _, v := range activityList {
  813. for _, vName := range listEmail {
  814. if strings.Contains(v.Speaker, vName.Name) {
  815. idAndMobileNoSendMap[fmt.Sprint("Id_", v.ActivityId, "Mobile_", vName.Mobile)] = true
  816. }
  817. }
  818. }
  819. url := utils.YiDongHuaWeiYunUrl + "app/hz/signAppointmentsForThird"
  820. var outCallStatus string
  821. for _, v := range activityList {
  822. go UpdateIsSendYidongSignUp(v.ActivityId)
  823. var parsSignUp []interface{}
  824. var conditionSignUp string
  825. conditionSignUp += ` AND activity_id = ?`
  826. parsSignUp = append(parsSignUp, v.ActivityId)
  827. conditionSignUp += ` AND do_fail_type = 0 `
  828. listSignUp, e := models.GetActivitySignuListByUser(conditionSignUp, parsSignUp)
  829. if e != nil {
  830. err = errors.New("GetActivitySignuListByUser, Err: " + e.Error())
  831. return
  832. }
  833. if len(listSignUp) == 0 {
  834. continue
  835. }
  836. var companyIds []int
  837. for _, vS := range listSignUp {
  838. companyIds = append(companyIds, vS.CompanyId)
  839. }
  840. sellNameMap := GetSellNameMapByCompanyIds(companyIds)
  841. for _, vS := range listSignUp {
  842. if idAndMobileNoSendMap[fmt.Sprint("Id_", vS.ActivityId, "Mobile_", vS.Mobile)] {
  843. continue //如果这个活动对应的是主讲人的手机号,那么就不做推送
  844. }
  845. if vS.SignupType == 1 {
  846. outCallStatus = "1"
  847. } else {
  848. outCallStatus = "0"
  849. }
  850. params := SignAppointmentsForThirdParam{
  851. ActivityId: v.YidongActivityIdByCygx,
  852. MobileCountryCode: "+" + vS.CountryCode,
  853. PersonTelephone: vS.OutboundMobile,
  854. ThirdPartySource: "01",
  855. InvestorType: "0",
  856. PersonName: vS.RealName,
  857. JoinRole: "2",
  858. CompanyName: vS.CompanyName,
  859. Extend1: sellNameMap[vS.CompanyId],
  860. OutCallStatus: outCallStatus,
  861. }
  862. postData, e := json.Marshal(params)
  863. if e != nil {
  864. err = e
  865. fmt.Println("PostData json.Marshal Err:" + err.Error())
  866. utils.FileLog.Info("PostData json.Marshal Err:" + err.Error())
  867. return
  868. }
  869. method := "POST"
  870. client := &http.Client{}
  871. req, e := http.NewRequest(method, url, strings.NewReader(string(postData)))
  872. if e != nil {
  873. err = e
  874. fmt.Println(err)
  875. return
  876. }
  877. req.Header.Add("Content-Type", "application/json")
  878. res, e := client.Do(req)
  879. if e != nil {
  880. err = e
  881. return
  882. }
  883. defer res.Body.Close()
  884. body, e := ioutil.ReadAll(res.Body)
  885. if e != nil {
  886. err = e
  887. return
  888. }
  889. itemApiLog := new(models.CygxThreeApiLog)
  890. itemApiLog.CreateTime = time.Now()
  891. itemApiLog.Source = 1
  892. itemApiLog.Url = url
  893. itemApiLog.Body = string(postData)
  894. itemApiLog.Result = string(body)
  895. go models.AddCygxThreeApiLog(itemApiLog)
  896. var yidongResp *YiDongSignAppointmentsForThirdResp
  897. err = json.Unmarshal(body, &yidongResp)
  898. if err != nil {
  899. return
  900. }
  901. if !yidongResp.Success {
  902. err = errors.New(" 会前一小时将,报名信息同步到易董,同步失败," + yidongResp.ErrorCode + yidongResp.ErrorMsg)
  903. return
  904. }
  905. }
  906. }
  907. return
  908. }
  909. type SignAppointmentsForThirdParam struct {
  910. ActivityId string `description:"易董活动ID" json:"activityId"`
  911. MobileCountryCode string `description:"国际区号注意要带前面+号 " json:"mobileCountryCode"`
  912. PersonTelephone string `description:"手机号" json:"personTelephone"`
  913. ThirdPartySource string `description:"第三方来源;弘则固定:01" json:"thirdPartySource"`
  914. InvestorType string `description:"投资者类型 0个人1机构" json:"investorType"`
  915. PersonName string `description:"姓名" json:"personName"`
  916. CompanyName string `description:"公司名" json:"companyName"`
  917. JoinRole string `description:"1:嘉宾, 2:普通参会人员, 3:会议助理。不传默认取值2" json:"joinRole"`
  918. OutCallStatus string `description:"1:需要,0:不需要。不传取默认值0" json:"outCallStatus"`
  919. Extend1 string `description:"对口销售" json:"extend1"`
  920. }
  921. type YiDongSignAppointmentsForThirdResp struct {
  922. ErrorCode string `json:"errorCode"` // 错误码,001:活动不存在;002:该活动不支持此渠道报名;003:该手机号或邮箱已经被其他账号提交报名;004:不在报名时间;005:报名人数已满
  923. ErrorMsg string `json:"errorMsg"` // 错误信息
  924. Success bool `json:"success"` // 成功标识,true:成功;false:失败。可作为判断报名是否成功的标识
  925. Timestamp float64 `json:"timestamp"` // 时间戳
  926. }
  927. //func init() {
  928. // GroupingActivityToYiDong()
  929. //}
  930. // GroupingActivityToYiDong 建立与易董的活动关联
  931. func GroupingActivityToYiDong(cont context.Context) (err error) {
  932. //func GroupingActivityToYiDong() (err error) {
  933. defer func() {
  934. if err != nil {
  935. fmt.Println(err)
  936. go utils.SendAlarmMsg("建立与易董的活动关联失败 GroupingActivityToYiDong"+err.Error(), 2)
  937. }
  938. }()
  939. startDate := time.Now().AddDate(0, 0, -2).Format(utils.FormatDate)
  940. endDate := time.Now().AddDate(0, 0, 0).Format(utils.FormatDate)
  941. var token string
  942. token, _ = GetYiDongToken()
  943. url := utils.YiDongZhengTongYunUrl + "interact/activityManageApi/getRoadshowList?access_token=" + token
  944. method := "POST"
  945. payload := strings.NewReader(`{
  946. "meetingStatus": "2",
  947. "conveneStartStr": "` + startDate + `",
  948. "conveneEndStr": "` + endDate + `"}`)
  949. client := &http.Client{}
  950. req, err := http.NewRequest(method, url, payload)
  951. if err != nil {
  952. fmt.Println(err)
  953. utils.FileLog.Info(err.Error())
  954. return
  955. }
  956. req.Header.Add("Content-Type", "application/json")
  957. res, err := client.Do(req)
  958. if err != nil {
  959. fmt.Println(err)
  960. utils.FileLog.Info(err.Error())
  961. return
  962. }
  963. defer res.Body.Close()
  964. var ApifoxModal *models.ApifoxModal
  965. body, err := ioutil.ReadAll(res.Body)
  966. if err != nil {
  967. fmt.Println(err)
  968. utils.FileLog.Info(err.Error())
  969. return
  970. }
  971. //添加请求日志记录
  972. itemApiLog := new(models.CygxThreeApiLog)
  973. itemApiLog.CreateTime = time.Now()
  974. itemApiLog.Source = 1
  975. itemApiLog.Url = url
  976. itemApiLog.Body = utils.ReplaceSpaceAndWrap(fmt.Sprint(payload))
  977. itemApiLog.Result = string(body)
  978. go models.AddCygxThreeApiLog(itemApiLog)
  979. err = json.Unmarshal(body, &ApifoxModal)
  980. if err != nil {
  981. fmt.Println("Getres.PublicGetDate Err:", err.Error())
  982. return
  983. }
  984. //var itemsAdd []*models.CygxActivity
  985. if len(ApifoxModal.Result) > 0 {
  986. actList := ApifoxModal.Result
  987. for _, v := range actList {
  988. //同步有效性 1有效,0失效
  989. if v.SyncFlag == "0" {
  990. continue
  991. }
  992. var yidongTitle string
  993. titleSlice := strings.Split(v.Title, "】")
  994. for _, vt := range titleSlice {
  995. yidongTitle = vt
  996. }
  997. e := models.UpdateCygxActivityyidongActivityId(v.ID, v.Start, yidongTitle)
  998. if e != nil {
  999. err = errors.New("UpdateCygxActivityyidongActivityId, Err: " + e.Error())
  1000. return
  1001. }
  1002. }
  1003. }
  1004. return
  1005. }
  1006. // GetLoginAuthCodeReq 获取登录编码请求体
  1007. type GetYiDongActivityByApiReq struct {
  1008. MeetingStatus string `json:"meetingStatus" description:"会议状态必需(0未开始1进行中2已结束)多个逗号分隔"`
  1009. ConveneStartStr string `json:"conveneStartStr" description:"活动日期范围开始"`
  1010. ConveneEndStr string `json:"conveneEndStr" description:"活动日期范围结束"`
  1011. LastUpdateTime string `json:"lastUpdateTime" description:"上次同步时间(用于筛选更新时间大于同步时间的活动数据)"`
  1012. }
  1013. type GetYiDongActivityMeetByActivityIdReq struct {
  1014. ActivityId string `json:"activityId" description:"活动ID"`
  1015. }
  1016. // 根据条件获取易董建会列表信息
  1017. func GetYiDongActivityListByApi(param *GetYiDongActivityByApiReq) (yiDongResult []models.Result) {
  1018. var err error
  1019. defer func() {
  1020. if err != nil {
  1021. fmt.Println(err)
  1022. go utils.SendAlarmMsg(fmt.Sprint("根据条件获取易董建会列表信息 GetYiDongActivityListByApi"+err.Error(), param), 2)
  1023. }
  1024. }()
  1025. var token string
  1026. token, _ = GetYiDongToken()
  1027. url := utils.YiDongZhengTongYunUrl + "interact/activityManageApi/getRoadshowList?access_token=" + token
  1028. method := "POST"
  1029. data, e := json.Marshal(param)
  1030. if e != nil {
  1031. err = errors.New("data json marshal err: " + e.Error())
  1032. return
  1033. }
  1034. payload := strings.NewReader(string(data))
  1035. client := &http.Client{}
  1036. req, e := http.NewRequest(method, url, payload)
  1037. if e != nil {
  1038. err = errors.New(" http.NewRequest err: " + e.Error())
  1039. return
  1040. }
  1041. req.Header.Add("Content-Type", "application/json")
  1042. res, e := client.Do(req)
  1043. if e != nil {
  1044. err = errors.New(" client.Do err: " + e.Error())
  1045. return
  1046. }
  1047. defer res.Body.Close()
  1048. var ApifoxModal *models.ApifoxModal
  1049. body, e := ioutil.ReadAll(res.Body)
  1050. if e != nil {
  1051. err = errors.New(" ioutil.ReadAll: " + e.Error())
  1052. return
  1053. }
  1054. //添加请求日志记录
  1055. itemApiLog := new(models.CygxThreeApiLog)
  1056. itemApiLog.CreateTime = time.Now()
  1057. itemApiLog.Source = 1
  1058. itemApiLog.Url = url
  1059. itemApiLog.Body = utils.ReplaceSpaceAndWrap(fmt.Sprint(payload))
  1060. itemApiLog.Result = string(body)
  1061. go models.AddCygxThreeApiLog(itemApiLog)
  1062. err = json.Unmarshal(body, &ApifoxModal)
  1063. if err != nil {
  1064. fmt.Println("Getres.PublicGetDate Err:", err.Error())
  1065. return
  1066. }
  1067. if len(ApifoxModal.Result) > 0 {
  1068. yiDongResult = ApifoxModal.Result
  1069. } else {
  1070. yiDongResult = make([]models.Result, 0)
  1071. }
  1072. return
  1073. }
  1074. // 根据条件获取易董活动ID获取到会信息
  1075. func GetYiDongActivityMeetDataByaAtivityId(ativityId string) (yiDongResult []models.Resultuser) {
  1076. var err error
  1077. defer func() {
  1078. if err != nil {
  1079. fmt.Println(err)
  1080. go utils.SendAlarmMsg(fmt.Sprint("根据条件获取易董建会列表信息 GetYiDongActivityListByApi"+err.Error(), ativityId), 2)
  1081. }
  1082. }()
  1083. var token string
  1084. token, _ = GetYiDongToken()
  1085. url := utils.YiDongZhengTongYunUrl + "interact/activityManageApi/getAttendPersonList?access_token=" + token
  1086. method := "POST"
  1087. param := new(GetYiDongActivityMeetByActivityIdReq)
  1088. param.ActivityId = ativityId
  1089. data, e := json.Marshal(param)
  1090. if e != nil {
  1091. err = errors.New("data json marshal err: " + e.Error())
  1092. return
  1093. }
  1094. payload := strings.NewReader(string(data))
  1095. client := &http.Client{}
  1096. req, e := http.NewRequest(method, url, payload)
  1097. if e != nil {
  1098. err = errors.New(" http.NewRequest err: " + e.Error())
  1099. return
  1100. }
  1101. req.Header.Add("Content-Type", "application/json")
  1102. res, e := client.Do(req)
  1103. if e != nil {
  1104. err = errors.New(" client.Do err: " + e.Error())
  1105. return
  1106. }
  1107. defer res.Body.Close()
  1108. var ApifoxModal *models.ApifoxModaluser
  1109. body, e := ioutil.ReadAll(res.Body)
  1110. if e != nil {
  1111. err = errors.New(" ioutil.ReadAll err: " + e.Error())
  1112. return
  1113. }
  1114. e = json.Unmarshal(body, &ApifoxModal)
  1115. if e != nil {
  1116. err = errors.New(" json.Unmarshal err: " + e.Error())
  1117. return
  1118. }
  1119. //添加请求日志记录
  1120. itemApiLog := new(models.CygxThreeApiLog)
  1121. itemApiLog.CreateTime = time.Now()
  1122. itemApiLog.Source = 1
  1123. itemApiLog.Url = url
  1124. itemApiLog.Body = utils.ReplaceSpaceAndWrap(fmt.Sprint(payload))
  1125. itemApiLog.Result = string(body)
  1126. go models.AddCygxThreeApiLog(itemApiLog)
  1127. err = json.Unmarshal(body, &ApifoxModal)
  1128. if err != nil {
  1129. fmt.Println("Getres.PublicGetDate Err:", err.Error())
  1130. return
  1131. }
  1132. if len(ApifoxModal.Result) > 0 {
  1133. yiDongResult = ApifoxModal.Result
  1134. } else {
  1135. yiDongResult = make([]models.Resultuser, 0)
  1136. }
  1137. return
  1138. }
  1139. //func init() {
  1140. // UpdateYiDongActivityDataToCygx()
  1141. //}
  1142. // 更新易董活动信息,到会信息到查研观向数据库
  1143. func UpdateYiDongActivityDataToCygx(cont context.Context) (err error) {
  1144. defer func() {
  1145. if err != nil {
  1146. fmt.Println(err)
  1147. go utils.SendAlarmMsg(fmt.Sprint("更新易董活动信息,到会信息到查研观向数据库 UpdateYiDongActivityDataToCygx"+err.Error()), 2)
  1148. }
  1149. }()
  1150. startDate := time.Now().AddDate(0, 0, -3).Format(utils.FormatDate)
  1151. endDate := time.Now().AddDate(0, 0, 0).Format(utils.FormatDate)
  1152. param := new(GetYiDongActivityByApiReq)
  1153. param.MeetingStatus = "2"
  1154. param.ConveneStartStr = startDate
  1155. param.ConveneEndStr = endDate
  1156. actList := GetYiDongActivityListByApi(param)
  1157. if len(actList) == 0 {
  1158. return
  1159. }
  1160. var itmes []*yidong.CygxYidongActivity
  1161. var YidongIds []string
  1162. for _, v := range actList {
  1163. YidongIds = append(YidongIds, v.ID)
  1164. }
  1165. listCygx, e := yidong.GetCygxYidongActivityListByYidongIds(YidongIds)
  1166. if e != nil {
  1167. err = errors.New("GetCygxYidongActivityListByYidongIds, Err: " + e.Error())
  1168. return
  1169. }
  1170. mapYidongId := make(map[string]bool)
  1171. for _, v := range listCygx {
  1172. mapYidongId[v.YidongId] = true
  1173. }
  1174. listMeetDataCygx, e := yidong.GetCygxYidongActivityMeetDataListByYidongIds(YidongIds)
  1175. if e != nil {
  1176. err = errors.New("GetCygxYidongActivityListByYidongIds, Err: " + e.Error())
  1177. return
  1178. }
  1179. mapMeetData := make(map[string]bool)
  1180. for _, v := range listMeetDataCygx {
  1181. mapMeetData[fmt.Sprint("AID_", v.YidongId, "M_", v.PersonTelephone)] = true
  1182. }
  1183. for _, v := range actList {
  1184. if mapYidongId[v.ID] {
  1185. continue
  1186. }
  1187. item := new(yidong.CygxYidongActivity)
  1188. item.YidongId = v.ID
  1189. item.CompanyInfo = v.CompanyInfo
  1190. item.Type = v.Type
  1191. item.IndustrySwName = v.IndustrySwName
  1192. item.Start = v.Start
  1193. item.End = v.End
  1194. item.SignUpStart = v.SignUpStart
  1195. item.SignUpEnd = v.SignUpEnd
  1196. item.ActivityJoinType = v.ActivityJoinType
  1197. item.Banner = v.Banner
  1198. item.Url = v.URL
  1199. item.SyncFlag = v.SyncFlag
  1200. item.BusinessCardOpen = v.BusinessCardOpen
  1201. item.BusinessCardRequired = v.BusinessCardRequired
  1202. item.PersonNameOpen = v.PersonNameOpen
  1203. item.PersonNameRequired = v.PersonNameRequired
  1204. item.PersonTelephoneOpen = v.PersonTelephoneOpen
  1205. item.PersonTelephoneRequired = v.PersonTelephoneRequired
  1206. item.MailOpen = v.MailOpen
  1207. item.MailRequired = v.MailRequired
  1208. item.CompanyShortNameOpen = v.CompanyShortNameOpen
  1209. item.CompanyShortNameRequired = v.CompanyShortNameRequired
  1210. item.CompanyCodeOpen = v.CompanyCodeOpen
  1211. item.CompanyCodeRequired = v.CompanyCodeRequired
  1212. item.JobNameOpen = v.JobNameOpen
  1213. item.JobNameRequired = v.JobNameRequired
  1214. item.CertificateInformationOpen = v.CertificateInformationOpen
  1215. item.CertificateInformationRequired = v.CertificateInformationRequired
  1216. item.InviteeOpen = v.InviteeOpen
  1217. item.InviteeRequired = v.InviteeRequired
  1218. item.CreateTime = time.Now()
  1219. itmes = append(itmes, item)
  1220. }
  1221. //新增记录
  1222. if len(itmes) > 0 {
  1223. e = yidong.AddCygxYidongActivityMulti(itmes)
  1224. if e != nil {
  1225. err = errors.New("AddCygxYidongActivityMulti, Err: " + e.Error())
  1226. return
  1227. }
  1228. }
  1229. var itmesMdata []*yidong.CygxYidongActivityMeetData
  1230. for _, v := range actList {
  1231. meetDataList := GetYiDongActivityMeetDataByaAtivityId(v.ID)
  1232. for _, mdata := range meetDataList {
  1233. if mapMeetData[fmt.Sprint("AID_", v.ID, "M_", mdata.PersonTelephone)] || mdata.PersonTelephone == "" {
  1234. continue
  1235. }
  1236. itmemdata := new(yidong.CygxYidongActivityMeetData)
  1237. itmemdata.YidongMeetDataId = mdata.ID
  1238. itmemdata.Title = v.Title
  1239. itmemdata.YidongId = v.ID
  1240. itmemdata.UserId = mdata.UserID
  1241. itmemdata.PersonTelephone = mdata.PersonTelephone
  1242. itmemdata.Duration = mdata.Duration
  1243. itmemdata.StartTime = mdata.StartTime
  1244. itmemdata.EndTime = mdata.EndTime
  1245. itmemdata.DeviceType = mdata.DeviceType
  1246. itmemdata.Status = mdata.Status
  1247. itmemdata.PersonName = mdata.PersonName
  1248. itmemdata.JobName = mdata.JobName
  1249. itmemdata.Mail = mdata.Mail
  1250. itmemdata.CompanyName = mdata.CompanyName
  1251. itmemdata.MobileCountryCode = mdata.MobileCountryCode
  1252. itmemdata.SignUpStatus = mdata.SignUpStatus
  1253. itmemdata.DurationLive = mdata.DurationLive
  1254. itmemdata.StartTimeLive = mdata.StartTimeLive
  1255. itmemdata.EndTimeLive = mdata.EndTimeLive
  1256. itmemdata.DurationReview = mdata.DurationReview
  1257. itmemdata.StartTimeInteract = mdata.StartTimeInteract
  1258. itmemdata.EndTimeInteract = mdata.EndTimeInteract
  1259. itmemdata.CreateTime = time.Now()
  1260. itmesMdata = append(itmesMdata, itmemdata)
  1261. }
  1262. }
  1263. // 写入到会信息
  1264. if len(itmesMdata) > 0 {
  1265. e = yidong.AddCygxYidongActivityMeetDataMulti(itmesMdata)
  1266. if e != nil {
  1267. err = errors.New("AddCygxYidongActivityMeetDataMulti, Err: " + e.Error())
  1268. return
  1269. }
  1270. }
  1271. //fmt.Println("end")
  1272. return
  1273. }
  1274. //func init() {
  1275. // //param := new(GetYiDongActivityByApiReq)
  1276. // //param.MeetingStatus = "2"
  1277. // //param.ConveneStartStr = "2024-10-28"
  1278. // //param.ConveneEndStr = "2024-10-30"
  1279. // actList := GetYiDongActivityMeetDataByaAtivityId("1180584155007237390")
  1280. //
  1281. // for _, v := range actList {
  1282. // //同步有效性 1有效,0失效
  1283. // //if v.SyncFlag == "0" {
  1284. // // continue
  1285. // //}
  1286. // //var yidongTitle string
  1287. // //titleSlice := strings.Split(v.Title, "】")
  1288. // //
  1289. // //for _, vt := range titleSlice {
  1290. // // yidongTitle = vt
  1291. // //}
  1292. //
  1293. // fmt.Println(v.PersonTelephone)
  1294. // fmt.Println(v.PersonName)
  1295. // }
  1296. //}