yidong.go 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386
  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 != "" {
  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 != "" {
  631. itemDetail.FirstMeetingTime = vresult.StartTime
  632. itemDetail.LastMeetingTime = vresult.EndTime
  633. itemDetail.Duration = vresult.Duration
  634. itemDetail.MeetingStatusStr = "直播"
  635. } else if vresult.DurationReview != "" {
  636. itemDetail.FirstMeetingTime = vresult.StartTimeReview
  637. itemDetail.LastMeetingTime = vresult.EndTimeReview
  638. itemDetail.Duration = vresult.DurationReview
  639. itemDetail.MeetingStatusStr = "回放"
  640. }
  641. itemDetail.Position = vresult.JobName
  642. itemDetail.RealName = vresult.PersonName
  643. itemDetail.Mobile = vresult.PersonTelephone
  644. itemDetail.OutboundMobile = vresult.PersonTelephone
  645. itemDetail.IsMeeting = 1
  646. itemDetail.ActivityId = v.ActivityId
  647. mapActivityAttendanceDetail[vresult.PersonTelephone] = new(models.CygxActivityAttendanceDetail)
  648. mapActivityAttendanceDetail[vresult.PersonTelephone].FirstMeetingTime = vresult.StartTime
  649. mapActivityAttendanceDetail[vresult.PersonTelephone].LastMeetingTime = vresult.EndTime
  650. mapActivityAttendanceDetail[vresult.PersonTelephone].Duration = utils.GetAttendanceDetailSecondsByYiDong(vresult.Duration)
  651. itemsUpdate = append(itemsUpdate, itemDetail)
  652. }
  653. item := new(models.CygxActivityAttendanceDetail)
  654. item.ActivityId = v.ActivityId
  655. item.Mobile = vresult.PersonTelephone
  656. if vresult.Duration != "" {
  657. if vresult.Duration != "" {
  658. item.FirstMeetingTime = vresult.StartTime
  659. item.LastMeetingTime = vresult.EndTime
  660. item.Duration = vresult.Duration
  661. item.MeetingStatusStr = "直播"
  662. } else if vresult.DurationReview != "" {
  663. item.FirstMeetingTime = vresult.StartTimeReview
  664. item.LastMeetingTime = vresult.EndTimeReview
  665. item.Duration = vresult.DurationReview
  666. item.MeetingStatusStr = "回放"
  667. }
  668. item.Position = vresult.JobName
  669. item.RealName = vresult.PersonName
  670. item.FirstMeetingTime = vresult.StartTime
  671. item.LastMeetingTime = vresult.EndTime
  672. item.Duration = vresult.Duration
  673. item.IsMeetingStr = 1
  674. mobileStrMeet += "'" + vresult.PersonTelephone + "'" + ","
  675. item.CreateTime = time.Now()
  676. needAddAttendanc = append(needAddAttendanc, item)
  677. }
  678. mobileStr += "'" + vresult.PersonTelephone + "'" + ","
  679. }
  680. lenmobiles := len(mobiles)
  681. if lenmobiles > 0 {
  682. var parsYd []interface{}
  683. var conditionYd string
  684. conditionYd = ` AND mobile IN (` + utils.GetOrmInReplace(lenmobiles) + `) AND activity_id=? `
  685. parsYd = append(parsYd, mobiles, v.ActivityId)
  686. err = models.UpdateCygxActivitySignupisMeetList(conditionYd, parsYd)
  687. if err != nil {
  688. fmt.Println("UpdateCygxActivitySignupisMeetList Err:", err.Error())
  689. return err
  690. }
  691. err = models.UpdateActivitySignupDetailMultiByYiDong(itemsUpdate)
  692. if err != nil {
  693. fmt.Println("UpdateActivitySignupDetailMultiByYiDong Err:", err.Error())
  694. return err
  695. }
  696. }
  697. mobileStr = strings.TrimRight(mobileStr, ",")
  698. if mobileStr == "" {
  699. mobileStr = "1"
  700. }
  701. mobileStrMeet = strings.TrimRight(mobileStrMeet, ",")
  702. if mobileStrMeet == "" {
  703. mobileStrMeet = "1"
  704. }
  705. listUser, err := models.GetWxUserOutboundMobile(mobileStr)
  706. if err != nil {
  707. fmt.Println("GetWxUserOutboundMobile Err:", err.Error())
  708. return err
  709. }
  710. for kAdd, vAdd := range needAddAttendanc {
  711. for _, v2 := range listUser {
  712. if v2.OutboundMobile == vAdd.Mobile || v2.Mobile == vAdd.Mobile {
  713. if needAddAttendanc[kAdd].CompanyId <= 1 {
  714. needAddAttendanc[kAdd].CompanyId = v2.CompanyId
  715. needAddAttendanc[kAdd].SellerName = v2.SellerName
  716. needAddAttendanc[kAdd].CompanyName = v2.CompanyName
  717. //needAddAttendanc[k].IsMeetingStr = 1
  718. }
  719. }
  720. }
  721. }
  722. //参会记录
  723. err = models.AddAttendancDetail(needAddAttendanc, v.ActivityId, mobileStrMeet)
  724. if err != nil {
  725. fmt.Println("AddAttendancDetail Err:", err.Error())
  726. return err
  727. }
  728. ////处理是否限制报名
  729. err = AddCygxActivityRestrictSignupByAdmin(v.ActivityId)
  730. if err != nil {
  731. fmt.Println("AddCygxActivityRestrictSignupByAdmin Err:", err.Error())
  732. return err
  733. }
  734. AddctivitySignupDetailByJmcjNew(needAddAttendanc, []int{v.ActivityId})
  735. }
  736. }
  737. return
  738. }
  739. // YidongActivityGroup 添加活动与产业标的的关联
  740. func YidongActivityGroup(subjectName string, activityId int) (err error) {
  741. subjectList, err := models.GetCygxIndustrialSubjectList(subjectName)
  742. if err != nil {
  743. fmt.Println(err)
  744. return err
  745. }
  746. if len(subjectList) == 0 {
  747. return err
  748. }
  749. fmt.Println("去掉临时标签的活动", activityId)
  750. err = models.UpdateActivityshowSubject(activityId)
  751. if err != nil {
  752. go utils.SendAlarmMsg("UpdateActivityshowSubject :根据易董推过来的匹配信息,判断临时标签是否展示失败"+err.Error(), 2)
  753. }
  754. var industrialActivityItems []*models.CygxIndustrialActivityGroupManagement
  755. var subjectActivityItems []*models.CygxIndustrialActivityGroupSubject
  756. mapSubjectName := make(map[string]string)
  757. for _, v := range subjectList {
  758. industrialActivityItem := new(models.CygxIndustrialActivityGroupManagement)
  759. subjectActivityItem := new(models.CygxIndustrialActivityGroupSubject)
  760. industrialActivityItem.ActivityId = activityId
  761. industrialActivityItem.IndustrialManagementId = v.IndustrialManagementId
  762. industrialActivityItem.Source = 1
  763. industrialActivityItem.CreateTime = time.Now()
  764. industrialActivityItems = append(industrialActivityItems, industrialActivityItem)
  765. subjectActivityItem.ActivityId = activityId
  766. subjectActivityItem.IndustrialSubjectId = v.IndustrialSubjectId
  767. subjectActivityItem.Source = 1
  768. subjectActivityItem.CreateTime = time.Now()
  769. if mapSubjectName[v.SubjectName] == "" {
  770. subjectActivityItems = append(subjectActivityItems, subjectActivityItem)
  771. mapSubjectName[v.SubjectName] = v.SubjectName
  772. }
  773. }
  774. err = models.AddCygxActiuvityGroupMulti(industrialActivityItems, subjectActivityItems)
  775. if err != nil {
  776. go utils.SendAlarmMsg("AddCygxActiuvityGroupMulti :批量添加易董活动关联的活动标签失败"+err.Error(), 2)
  777. }
  778. return
  779. }
  780. // 会前一小时将,报名信息同步到易董
  781. func YiDongSignAppointmentsForThird(cont context.Context) (err error) {
  782. //func YiDongSignAppointmentsForThird() (err error) {
  783. defer func() {
  784. if err != nil {
  785. fmt.Println(err)
  786. go utils.SendAlarmMsg("会前一小时将,报名信息同步到易董,同步失败"+err.Error(), 2)
  787. }
  788. }()
  789. var pars []interface{}
  790. var condition string
  791. startDate := time.Now().Add(+time.Minute * 45).Format(utils.FormatDateTime)
  792. endDate := time.Now().Add(+time.Minute * 60).Format(utils.FormatDateTime)
  793. condition = " AND is_yidong_sign_up = 0 AND yidong_activity_id_by_cygx != '' AND activity_time BETWEEN ? AND ? "
  794. pars = append(pars, startDate, endDate)
  795. activityList, err := models.GetActivityListByCondition(condition, pars)
  796. if err != nil {
  797. return
  798. }
  799. if len(activityList) == 0 {
  800. return
  801. }
  802. listEmail, e := models.GetAskEmail()
  803. if e != nil {
  804. err = errors.New("GetAskEmail, Err: " + e.Error())
  805. return
  806. }
  807. //获取某一个活动下面不需要推送的主讲人手机号
  808. idAndMobileNoSendMap := make(map[string]bool)
  809. for _, v := range activityList {
  810. for _, vName := range listEmail {
  811. if strings.Contains(v.Speaker, vName.Name) {
  812. idAndMobileNoSendMap[fmt.Sprint("Id_", v.ActivityId, "Mobile_", vName.Mobile)] = true
  813. }
  814. }
  815. }
  816. url := utils.YiDongHuaWeiYunUrl + "app/hz/signAppointmentsForThird"
  817. var outCallStatus string
  818. for _, v := range activityList {
  819. go UpdateIsSendYidongSignUp(v.ActivityId)
  820. var parsSignUp []interface{}
  821. var conditionSignUp string
  822. conditionSignUp += ` AND activity_id = ?`
  823. parsSignUp = append(parsSignUp, v.ActivityId)
  824. conditionSignUp += ` AND do_fail_type = 0 `
  825. listSignUp, e := models.GetActivitySignuListByUser(conditionSignUp, parsSignUp)
  826. if e != nil {
  827. err = errors.New("GetActivitySignuListByUser, Err: " + e.Error())
  828. return
  829. }
  830. if len(listSignUp) == 0 {
  831. continue
  832. }
  833. var companyIds []int
  834. for _, vS := range listSignUp {
  835. companyIds = append(companyIds, vS.CompanyId)
  836. }
  837. sellNameMap := GetSellNameMapByCompanyIds(companyIds)
  838. for _, vS := range listSignUp {
  839. if idAndMobileNoSendMap[fmt.Sprint("Id_", vS.ActivityId, "Mobile_", vS.Mobile)] {
  840. continue //如果这个活动对应的是主讲人的手机号,那么就不做推送
  841. }
  842. if vS.SignupType == 1 {
  843. outCallStatus = "1"
  844. } else {
  845. outCallStatus = "0"
  846. }
  847. params := SignAppointmentsForThirdParam{
  848. ActivityId: v.YidongActivityIdByCygx,
  849. MobileCountryCode: "+" + vS.CountryCode,
  850. PersonTelephone: vS.OutboundMobile,
  851. ThirdPartySource: "01",
  852. InvestorType: "0",
  853. PersonName: vS.RealName,
  854. JoinRole: "2",
  855. CompanyName: vS.CompanyName,
  856. Extend1: sellNameMap[vS.CompanyId],
  857. OutCallStatus: outCallStatus,
  858. }
  859. postData, e := json.Marshal(params)
  860. if e != nil {
  861. err = e
  862. fmt.Println("PostData json.Marshal Err:" + err.Error())
  863. utils.FileLog.Info("PostData json.Marshal Err:" + err.Error())
  864. return
  865. }
  866. method := "POST"
  867. client := &http.Client{}
  868. req, e := http.NewRequest(method, url, strings.NewReader(string(postData)))
  869. if e != nil {
  870. err = e
  871. fmt.Println(err)
  872. return
  873. }
  874. req.Header.Add("Content-Type", "application/json")
  875. res, e := client.Do(req)
  876. if e != nil {
  877. err = e
  878. return
  879. }
  880. defer res.Body.Close()
  881. body, e := ioutil.ReadAll(res.Body)
  882. if e != nil {
  883. err = e
  884. return
  885. }
  886. itemApiLog := new(models.CygxThreeApiLog)
  887. itemApiLog.CreateTime = time.Now()
  888. itemApiLog.Source = 1
  889. itemApiLog.Url = url
  890. itemApiLog.Body = string(postData)
  891. itemApiLog.Result = string(body)
  892. go models.AddCygxThreeApiLog(itemApiLog)
  893. var yidongResp *YiDongSignAppointmentsForThirdResp
  894. err = json.Unmarshal(body, &yidongResp)
  895. if err != nil {
  896. return
  897. }
  898. if !yidongResp.Success {
  899. err = errors.New(" 会前一小时将,报名信息同步到易董,同步失败," + yidongResp.ErrorCode + yidongResp.ErrorMsg)
  900. return
  901. }
  902. }
  903. }
  904. return
  905. }
  906. type SignAppointmentsForThirdParam struct {
  907. ActivityId string `description:"易董活动ID" json:"activityId"`
  908. MobileCountryCode string `description:"国际区号注意要带前面+号 " json:"mobileCountryCode"`
  909. PersonTelephone string `description:"手机号" json:"personTelephone"`
  910. ThirdPartySource string `description:"第三方来源;弘则固定:01" json:"thirdPartySource"`
  911. InvestorType string `description:"投资者类型 0个人1机构" json:"investorType"`
  912. PersonName string `description:"姓名" json:"personName"`
  913. CompanyName string `description:"公司名" json:"companyName"`
  914. JoinRole string `description:"1:嘉宾, 2:普通参会人员, 3:会议助理。不传默认取值2" json:"joinRole"`
  915. OutCallStatus string `description:"1:需要,0:不需要。不传取默认值0" json:"outCallStatus"`
  916. Extend1 string `description:"对口销售" json:"extend1"`
  917. }
  918. type YiDongSignAppointmentsForThirdResp struct {
  919. ErrorCode string `json:"errorCode"` // 错误码,001:活动不存在;002:该活动不支持此渠道报名;003:该手机号或邮箱已经被其他账号提交报名;004:不在报名时间;005:报名人数已满
  920. ErrorMsg string `json:"errorMsg"` // 错误信息
  921. Success bool `json:"success"` // 成功标识,true:成功;false:失败。可作为判断报名是否成功的标识
  922. Timestamp float64 `json:"timestamp"` // 时间戳
  923. }
  924. //func init() {
  925. // GroupingActivityToYiDong()
  926. //}
  927. // GroupingActivityToYiDong 建立与易董的活动关联
  928. func GroupingActivityToYiDong(cont context.Context) (err error) {
  929. //func GroupingActivityToYiDong() (err error) {
  930. defer func() {
  931. if err != nil {
  932. fmt.Println(err)
  933. go utils.SendAlarmMsg("建立与易董的活动关联失败 GroupingActivityToYiDong"+err.Error(), 2)
  934. }
  935. }()
  936. startDate := time.Now().AddDate(0, 0, -2).Format(utils.FormatDate)
  937. endDate := time.Now().AddDate(0, 0, 0).Format(utils.FormatDate)
  938. var token string
  939. token, _ = GetYiDongToken()
  940. url := utils.YiDongZhengTongYunUrl + "interact/activityManageApi/getRoadshowList?access_token=" + token
  941. method := "POST"
  942. payload := strings.NewReader(`{
  943. "meetingStatus": "2",
  944. "conveneStartStr": "` + startDate + `",
  945. "conveneEndStr": "` + endDate + `"}`)
  946. client := &http.Client{}
  947. req, err := http.NewRequest(method, url, payload)
  948. if err != nil {
  949. fmt.Println(err)
  950. utils.FileLog.Info(err.Error())
  951. return
  952. }
  953. req.Header.Add("Content-Type", "application/json")
  954. res, err := client.Do(req)
  955. if err != nil {
  956. fmt.Println(err)
  957. utils.FileLog.Info(err.Error())
  958. return
  959. }
  960. defer res.Body.Close()
  961. var ApifoxModal *models.ApifoxModal
  962. body, err := ioutil.ReadAll(res.Body)
  963. if err != nil {
  964. fmt.Println(err)
  965. utils.FileLog.Info(err.Error())
  966. return
  967. }
  968. //添加请求日志记录
  969. itemApiLog := new(models.CygxThreeApiLog)
  970. itemApiLog.CreateTime = time.Now()
  971. itemApiLog.Source = 1
  972. itemApiLog.Url = url
  973. itemApiLog.Body = utils.ReplaceSpaceAndWrap(fmt.Sprint(payload))
  974. itemApiLog.Result = string(body)
  975. go models.AddCygxThreeApiLog(itemApiLog)
  976. err = json.Unmarshal(body, &ApifoxModal)
  977. if err != nil {
  978. fmt.Println("Getres.PublicGetDate Err:", err.Error())
  979. return
  980. }
  981. //var itemsAdd []*models.CygxActivity
  982. if len(ApifoxModal.Result) > 0 {
  983. actList := ApifoxModal.Result
  984. for _, v := range actList {
  985. //同步有效性 1有效,0失效
  986. if v.SyncFlag == "0" {
  987. continue
  988. }
  989. var yidongTitle string
  990. titleSlice := strings.Split(v.Title, "】")
  991. for _, vt := range titleSlice {
  992. yidongTitle = vt
  993. }
  994. e := models.UpdateCygxActivityyidongActivityId(v.ID, v.Start, yidongTitle)
  995. if e != nil {
  996. err = errors.New("UpdateCygxActivityyidongActivityId, Err: " + e.Error())
  997. return
  998. }
  999. }
  1000. }
  1001. return
  1002. }
  1003. // GetLoginAuthCodeReq 获取登录编码请求体
  1004. type GetYiDongActivityByApiReq struct {
  1005. MeetingStatus string `json:"meetingStatus" description:"会议状态必需(0未开始1进行中2已结束)多个逗号分隔"`
  1006. ConveneStartStr string `json:"conveneStartStr" description:"活动日期范围开始"`
  1007. ConveneEndStr string `json:"conveneEndStr" description:"活动日期范围结束"`
  1008. LastUpdateTime string `json:"lastUpdateTime" description:"上次同步时间(用于筛选更新时间大于同步时间的活动数据)"`
  1009. }
  1010. type GetYiDongActivityMeetByActivityIdReq struct {
  1011. ActivityId string `json:"activityId" description:"活动ID"`
  1012. }
  1013. // 根据条件获取易董建会列表信息
  1014. func GetYiDongActivityListByApi(param *GetYiDongActivityByApiReq) (yiDongResult []models.Result) {
  1015. var err error
  1016. defer func() {
  1017. if err != nil {
  1018. fmt.Println(err)
  1019. go utils.SendAlarmMsg(fmt.Sprint("根据条件获取易董建会列表信息 GetYiDongActivityListByApi"+err.Error(), param), 2)
  1020. }
  1021. }()
  1022. var token string
  1023. token, _ = GetYiDongToken()
  1024. url := utils.YiDongZhengTongYunUrl + "interact/activityManageApi/getRoadshowList?access_token=" + token
  1025. method := "POST"
  1026. data, e := json.Marshal(param)
  1027. if e != nil {
  1028. err = errors.New("data json marshal err: " + e.Error())
  1029. return
  1030. }
  1031. payload := strings.NewReader(string(data))
  1032. client := &http.Client{}
  1033. req, e := http.NewRequest(method, url, payload)
  1034. if e != nil {
  1035. err = errors.New(" http.NewRequest err: " + e.Error())
  1036. return
  1037. }
  1038. req.Header.Add("Content-Type", "application/json")
  1039. res, e := client.Do(req)
  1040. if e != nil {
  1041. err = errors.New(" client.Do err: " + e.Error())
  1042. return
  1043. }
  1044. defer res.Body.Close()
  1045. var ApifoxModal *models.ApifoxModal
  1046. body, e := ioutil.ReadAll(res.Body)
  1047. if e != nil {
  1048. err = errors.New(" ioutil.ReadAll: " + e.Error())
  1049. return
  1050. }
  1051. //添加请求日志记录
  1052. itemApiLog := new(models.CygxThreeApiLog)
  1053. itemApiLog.CreateTime = time.Now()
  1054. itemApiLog.Source = 1
  1055. itemApiLog.Url = url
  1056. itemApiLog.Body = utils.ReplaceSpaceAndWrap(fmt.Sprint(payload))
  1057. itemApiLog.Result = string(body)
  1058. go models.AddCygxThreeApiLog(itemApiLog)
  1059. err = json.Unmarshal(body, &ApifoxModal)
  1060. if err != nil {
  1061. fmt.Println("Getres.PublicGetDate Err:", err.Error())
  1062. return
  1063. }
  1064. if len(ApifoxModal.Result) > 0 {
  1065. yiDongResult = ApifoxModal.Result
  1066. } else {
  1067. yiDongResult = make([]models.Result, 0)
  1068. }
  1069. return
  1070. }
  1071. // 根据条件获取易董活动ID获取到会信息
  1072. func GetYiDongActivityMeetDataByaAtivityId(ativityId string) (yiDongResult []models.Resultuser) {
  1073. var err error
  1074. defer func() {
  1075. if err != nil {
  1076. fmt.Println(err)
  1077. go utils.SendAlarmMsg(fmt.Sprint("根据条件获取易董建会列表信息 GetYiDongActivityListByApi"+err.Error(), ativityId), 2)
  1078. }
  1079. }()
  1080. var token string
  1081. token, _ = GetYiDongToken()
  1082. url := utils.YiDongZhengTongYunUrl + "interact/activityManageApi/getAttendPersonList?access_token=" + token
  1083. method := "POST"
  1084. param := new(GetYiDongActivityMeetByActivityIdReq)
  1085. param.ActivityId = ativityId
  1086. data, e := json.Marshal(param)
  1087. if e != nil {
  1088. err = errors.New("data json marshal err: " + e.Error())
  1089. return
  1090. }
  1091. payload := strings.NewReader(string(data))
  1092. client := &http.Client{}
  1093. req, e := http.NewRequest(method, url, payload)
  1094. if e != nil {
  1095. err = errors.New(" http.NewRequest err: " + e.Error())
  1096. return
  1097. }
  1098. req.Header.Add("Content-Type", "application/json")
  1099. res, e := client.Do(req)
  1100. if e != nil {
  1101. err = errors.New(" client.Do err: " + e.Error())
  1102. return
  1103. }
  1104. defer res.Body.Close()
  1105. var ApifoxModal *models.ApifoxModaluser
  1106. body, e := ioutil.ReadAll(res.Body)
  1107. if e != nil {
  1108. err = errors.New(" ioutil.ReadAll err: " + e.Error())
  1109. return
  1110. }
  1111. e = json.Unmarshal(body, &ApifoxModal)
  1112. if e != nil {
  1113. err = errors.New(" json.Unmarshal err: " + e.Error())
  1114. return
  1115. }
  1116. //添加请求日志记录
  1117. itemApiLog := new(models.CygxThreeApiLog)
  1118. itemApiLog.CreateTime = time.Now()
  1119. itemApiLog.Source = 1
  1120. itemApiLog.Url = url
  1121. itemApiLog.Body = utils.ReplaceSpaceAndWrap(fmt.Sprint(payload))
  1122. itemApiLog.Result = string(body)
  1123. go models.AddCygxThreeApiLog(itemApiLog)
  1124. err = json.Unmarshal(body, &ApifoxModal)
  1125. if err != nil {
  1126. fmt.Println("Getres.PublicGetDate Err:", err.Error())
  1127. return
  1128. }
  1129. if len(ApifoxModal.Result) > 0 {
  1130. yiDongResult = ApifoxModal.Result
  1131. } else {
  1132. yiDongResult = make([]models.Resultuser, 0)
  1133. }
  1134. return
  1135. }
  1136. //func init() {
  1137. // UpdateYiDongActivityDataToCygx()
  1138. //}
  1139. // 更新易董活动信息,到会信息到查研观向数据库
  1140. func UpdateYiDongActivityDataToCygx(cont context.Context) (err error) {
  1141. defer func() {
  1142. if err != nil {
  1143. fmt.Println(err)
  1144. go utils.SendAlarmMsg(fmt.Sprint("更新易董活动信息,到会信息到查研观向数据库 UpdateYiDongActivityDataToCygx"+err.Error()), 2)
  1145. }
  1146. }()
  1147. startDate := time.Now().AddDate(0, 0, -3).Format(utils.FormatDate)
  1148. endDate := time.Now().AddDate(0, 0, 0).Format(utils.FormatDate)
  1149. param := new(GetYiDongActivityByApiReq)
  1150. param.MeetingStatus = "2"
  1151. param.ConveneStartStr = startDate
  1152. param.ConveneEndStr = endDate
  1153. actList := GetYiDongActivityListByApi(param)
  1154. if len(actList) == 0 {
  1155. return
  1156. }
  1157. var itmes []*yidong.CygxYidongActivity
  1158. var YidongIds []string
  1159. for _, v := range actList {
  1160. YidongIds = append(YidongIds, v.ID)
  1161. }
  1162. listCygx, e := yidong.GetCygxYidongActivityListByYidongIds(YidongIds)
  1163. if e != nil {
  1164. err = errors.New("GetCygxYidongActivityListByYidongIds, Err: " + e.Error())
  1165. return
  1166. }
  1167. mapYidongId := make(map[string]bool)
  1168. for _, v := range listCygx {
  1169. mapYidongId[v.YidongId] = true
  1170. }
  1171. listMeetDataCygx, e := yidong.GetCygxYidongActivityMeetDataListByYidongIds(YidongIds)
  1172. if e != nil {
  1173. err = errors.New("GetCygxYidongActivityListByYidongIds, Err: " + e.Error())
  1174. return
  1175. }
  1176. mapMeetData := make(map[string]bool)
  1177. for _, v := range listMeetDataCygx {
  1178. mapMeetData[fmt.Sprint("AID_", v.YidongId, "M_", v.PersonTelephone)] = true
  1179. }
  1180. for _, v := range actList {
  1181. if mapYidongId[v.ID] {
  1182. continue
  1183. }
  1184. item := new(yidong.CygxYidongActivity)
  1185. item.YidongId = v.ID
  1186. item.CompanyInfo = v.CompanyInfo
  1187. item.Type = v.Type
  1188. item.IndustrySwName = v.IndustrySwName
  1189. item.Start = v.Start
  1190. item.End = v.End
  1191. item.SignUpStart = v.SignUpStart
  1192. item.SignUpEnd = v.SignUpEnd
  1193. item.ActivityJoinType = v.ActivityJoinType
  1194. item.Banner = v.Banner
  1195. item.Url = v.URL
  1196. item.SyncFlag = v.SyncFlag
  1197. item.BusinessCardOpen = v.BusinessCardOpen
  1198. item.BusinessCardRequired = v.BusinessCardRequired
  1199. item.PersonNameOpen = v.PersonNameOpen
  1200. item.PersonNameRequired = v.PersonNameRequired
  1201. item.PersonTelephoneOpen = v.PersonTelephoneOpen
  1202. item.PersonTelephoneRequired = v.PersonTelephoneRequired
  1203. item.MailOpen = v.MailOpen
  1204. item.MailRequired = v.MailRequired
  1205. item.CompanyShortNameOpen = v.CompanyShortNameOpen
  1206. item.CompanyShortNameRequired = v.CompanyShortNameRequired
  1207. item.CompanyCodeOpen = v.CompanyCodeOpen
  1208. item.CompanyCodeRequired = v.CompanyCodeRequired
  1209. item.JobNameOpen = v.JobNameOpen
  1210. item.JobNameRequired = v.JobNameRequired
  1211. item.CertificateInformationOpen = v.CertificateInformationOpen
  1212. item.CertificateInformationRequired = v.CertificateInformationRequired
  1213. item.InviteeOpen = v.InviteeOpen
  1214. item.InviteeRequired = v.InviteeRequired
  1215. item.CreateTime = time.Now()
  1216. itmes = append(itmes, item)
  1217. }
  1218. //新增记录
  1219. if len(itmes) > 0 {
  1220. e = yidong.AddCygxYidongActivityMulti(itmes)
  1221. if e != nil {
  1222. err = errors.New("AddCygxYidongActivityMulti, Err: " + e.Error())
  1223. return
  1224. }
  1225. }
  1226. var itmesMdata []*yidong.CygxYidongActivityMeetData
  1227. for _, v := range actList {
  1228. meetDataList := GetYiDongActivityMeetDataByaAtivityId(v.ID)
  1229. for _, mdata := range meetDataList {
  1230. if mapMeetData[fmt.Sprint("AID_", v.ID, "M_", mdata.PersonTelephone)] || mdata.PersonTelephone == "" {
  1231. continue
  1232. }
  1233. itmemdata := new(yidong.CygxYidongActivityMeetData)
  1234. itmemdata.YidongMeetDataId = mdata.ID
  1235. itmemdata.Title = v.Title
  1236. itmemdata.YidongId = v.ID
  1237. itmemdata.UserId = mdata.UserID
  1238. itmemdata.PersonTelephone = mdata.PersonTelephone
  1239. itmemdata.Duration = mdata.Duration
  1240. itmemdata.StartTime = mdata.StartTime
  1241. itmemdata.EndTime = mdata.EndTime
  1242. itmemdata.DeviceType = mdata.DeviceType
  1243. itmemdata.Status = mdata.Status
  1244. itmemdata.PersonName = mdata.PersonName
  1245. itmemdata.JobName = mdata.JobName
  1246. itmemdata.Mail = mdata.Mail
  1247. itmemdata.CompanyName = mdata.CompanyName
  1248. itmemdata.MobileCountryCode = mdata.MobileCountryCode
  1249. itmemdata.SignUpStatus = mdata.SignUpStatus
  1250. itmemdata.DurationLive = mdata.DurationLive
  1251. itmemdata.StartTimeLive = mdata.StartTimeLive
  1252. itmemdata.EndTimeLive = mdata.EndTimeLive
  1253. itmemdata.DurationReview = mdata.DurationReview
  1254. itmemdata.StartTimeInteract = mdata.StartTimeInteract
  1255. itmemdata.EndTimeInteract = mdata.EndTimeInteract
  1256. itmemdata.CreateTime = time.Now()
  1257. itmesMdata = append(itmesMdata, itmemdata)
  1258. }
  1259. }
  1260. // 写入到会信息
  1261. if len(itmesMdata) > 0 {
  1262. e = yidong.AddCygxYidongActivityMeetDataMulti(itmesMdata)
  1263. if e != nil {
  1264. err = errors.New("AddCygxYidongActivityMeetDataMulti, Err: " + e.Error())
  1265. return
  1266. }
  1267. }
  1268. //fmt.Println("end")
  1269. return
  1270. }
  1271. //func init() {
  1272. // //param := new(GetYiDongActivityByApiReq)
  1273. // //param.MeetingStatus = "2"
  1274. // //param.ConveneStartStr = "2024-10-28"
  1275. // //param.ConveneEndStr = "2024-10-30"
  1276. // actList := GetYiDongActivityMeetDataByaAtivityId("1180584155007237390")
  1277. //
  1278. // for _, v := range actList {
  1279. // //同步有效性 1有效,0失效
  1280. // //if v.SyncFlag == "0" {
  1281. // // continue
  1282. // //}
  1283. // //var yidongTitle string
  1284. // //titleSlice := strings.Split(v.Title, "】")
  1285. // //
  1286. // //for _, vt := range titleSlice {
  1287. // // yidongTitle = vt
  1288. // //}
  1289. //
  1290. // fmt.Println(v.PersonTelephone)
  1291. // fmt.Println(v.PersonName)
  1292. // }
  1293. //}