package services import ( "context" "encoding/json" "errors" "fmt" "hongze/hongze_cygx/models" "hongze/hongze_cygx/models/yidong" "hongze/hongze_cygx/utils" "io/ioutil" "net/http" "strings" "time" ) // GetActivityTypeIdWithYiDong 根据易董同步过来的活动类型,自动匹配行业 func GetActivityTypeIdWithYiDong(industrySwName string) (chartPermissionId int) { mapIndustrySwName := map[string]int{ "家用电器": utils.XIAO_FEI_ID, "纺织服饰": utils.XIAO_FEI_ID, "休闲服务": utils.XIAO_FEI_ID, "食品饮料": utils.XIAO_FEI_ID, "美容护理": utils.XIAO_FEI_ID, //消费 "汽车": utils.ZHI_ZAO_ID, "机械设备": utils.ZHI_ZAO_ID, "电力设备": utils.ZHI_ZAO_ID, //智造 "电子": utils.KE_JI_ID, "计算机": utils.KE_JI_ID, "通信": utils.KE_JI_ID, //科技 "医药生物": utils.YI_YAO_ID, //医药 "策略": utils.CE_LUE_ID, //策略 "非银金融": utils.CHART_PERMISSION_ID_YANXUAN, "建筑装饰": utils.CHART_PERMISSION_ID_YANXUAN, "基础化工": utils.CHART_PERMISSION_ID_YANXUAN, "农林牧渔": utils.CHART_PERMISSION_ID_YANXUAN, "传媒": utils.CHART_PERMISSION_ID_YANXUAN, "公用事业": utils.CHART_PERMISSION_ID_YANXUAN, "建筑材料": utils.CHART_PERMISSION_ID_YANXUAN, "房地产": utils.CHART_PERMISSION_ID_YANXUAN, "采掘": utils.CHART_PERMISSION_ID_YANXUAN, "轻工制造": utils.CHART_PERMISSION_ID_YANXUAN, "钢铁": utils.CHART_PERMISSION_ID_YANXUAN, "交通运输": utils.CHART_PERMISSION_ID_YANXUAN, "国防军工": utils.CHART_PERMISSION_ID_YANXUAN, "银行": utils.CHART_PERMISSION_ID_YANXUAN, "有色金属": utils.CHART_PERMISSION_ID_YANXUAN, "综合": utils.CHART_PERMISSION_ID_YANXUAN, "商业贸易": utils.CHART_PERMISSION_ID_YANXUAN, "宏观": utils.CHART_PERMISSION_ID_YANXUAN, "金融工程": utils.CHART_PERMISSION_ID_YANXUAN, "商贸零售": utils.CHART_PERMISSION_ID_YANXUAN, "社会服务": utils.CHART_PERMISSION_ID_YANXUAN, "煤炭": utils.CHART_PERMISSION_ID_YANXUAN, "石油石化": utils.CHART_PERMISSION_ID_YANXUAN, "环保": utils.CHART_PERMISSION_ID_YANXUAN, //研选 } chartPermissionId = mapIndustrySwName[industrySwName] return } // GetActivityTypeIdWithYiDong 根据易董同步过来的活动类型,自动匹配行业 func GetActivityTypeNameWithYiDong(industrySwName string) (chartPermissionName string) { mapIndustrySwName := map[string]string{ "家用电器": utils.XIAO_FEI_NAME, "纺织服饰": utils.XIAO_FEI_NAME, "休闲服务": utils.XIAO_FEI_NAME, "食品饮料": utils.XIAO_FEI_NAME, "美容护理": utils.XIAO_FEI_NAME, //消费 "汽车": utils.ZHI_ZAO_NAME, "机械设备": utils.ZHI_ZAO_NAME, "电力设备": utils.ZHI_ZAO_NAME, //智造 "电子": utils.KE_JI_NAME, "计算机": utils.KE_JI_NAME, "通信": utils.KE_JI_NAME, //科技 "医药生物": utils.YI_YAO_NAME, //医药 "策略": utils.CE_LUE_NAME, //策略 "非银金融": utils.CHART_PERMISSION_NAME_MF_YANXUAN, "建筑装饰": utils.CHART_PERMISSION_NAME_MF_YANXUAN, "基础化工": utils.CHART_PERMISSION_NAME_MF_YANXUAN, "农林牧渔": utils.CHART_PERMISSION_NAME_MF_YANXUAN, "传媒": utils.CHART_PERMISSION_NAME_MF_YANXUAN, "公用事业": utils.CHART_PERMISSION_NAME_MF_YANXUAN, "建筑材料": utils.CHART_PERMISSION_NAME_MF_YANXUAN, "房地产": utils.CHART_PERMISSION_NAME_MF_YANXUAN, "采掘": utils.CHART_PERMISSION_NAME_MF_YANXUAN, "轻工制造": utils.CHART_PERMISSION_NAME_MF_YANXUAN, "钢铁": utils.CHART_PERMISSION_NAME_MF_YANXUAN, "交通运输": utils.CHART_PERMISSION_NAME_MF_YANXUAN, "国防军工": utils.CHART_PERMISSION_NAME_MF_YANXUAN, "银行": utils.CHART_PERMISSION_NAME_MF_YANXUAN, "有色金属": utils.CHART_PERMISSION_NAME_MF_YANXUAN, "综合": utils.CHART_PERMISSION_NAME_MF_YANXUAN, "商业贸易": utils.CHART_PERMISSION_NAME_MF_YANXUAN, "宏观": utils.CHART_PERMISSION_NAME_MF_YANXUAN, "金融工程": utils.CHART_PERMISSION_NAME_MF_YANXUAN, "商贸零售": utils.CHART_PERMISSION_NAME_MF_YANXUAN, "社会服务": utils.CHART_PERMISSION_NAME_MF_YANXUAN, "煤炭": utils.CHART_PERMISSION_NAME_MF_YANXUAN, "石油石化": utils.CHART_PERMISSION_NAME_MF_YANXUAN, "环保": utils.CHART_PERMISSION_NAME_MF_YANXUAN, //研选 } chartPermissionName = mapIndustrySwName[industrySwName] return } var yidongHongzeCode = "RI0011" // 弘则在易董那边建会的公司code // 获取易董token func GetYiDongToken() (token string, err error) { defer func() { if err != nil { fmt.Println(err) utils.FileLog.Info(err.Error()) } }() cacheKey := utils.YI_DONG_ZHENG_TONG_YUN_TOKEN_KEY ttlTime := utils.Rc.GetRedisTTL(cacheKey) if ttlTime > 0 { token, _ = utils.Rc.RedisString(cacheKey) } if token == "" { url := utils.YiDongZhengTongYunUrl + "oauth/token?grant_type=client_credentials&response_type=token&client_id=" + utils.YiDongZhengTongYunAppid + "&client_secret=" + utils.YiDongZhengTongYunSecret method := "GET" client := &http.Client{} req, errReq := http.NewRequest(method, url, nil) if errReq != nil { err = errReq return } res, errReq := client.Do(req) if errReq != nil { err = errReq return } defer res.Body.Close() type Ydtoklen struct { Success bool `json:"success"` ExpiresIn int `json:"expires_in"` AccessToken string `json:"access_token"` } var ydtoklen Ydtoklen body, errReq := ioutil.ReadAll(res.Body) if errReq != nil { err = errReq return } errReq = json.Unmarshal(body, &ydtoklen) if errReq != nil { err = errReq return } token = ydtoklen.AccessToken utils.Rc.Put(cacheKey, ydtoklen.AccessToken, time.Second*7000) } return } // 获取易董活动列表 func GetYiDongActivity(cont context.Context) (err error) { //func GetYiDongActivity() (err error) { defer func() { if err != nil { fmt.Println(err) go utils.SendAlarmMsg("获取易董活动列表失败:"+err.Error(), 2) utils.FileLog.Info(err.Error()) } }() var token string token, _ = GetYiDongToken() url := utils.YiDongZhengTongYunUrl + "interact/activityManageApi/getRoadshowList?access_token=" + token method := "POST" payload := strings.NewReader(`{ "meetingStatus": "0" }`) client := &http.Client{} req, err := http.NewRequest(method, url, payload) if err != nil { fmt.Println(err) utils.FileLog.Info(err.Error()) return } req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err != nil { fmt.Println(err) utils.FileLog.Info(err.Error()) return } defer res.Body.Close() var ApifoxModal *models.ApifoxModal body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) utils.FileLog.Info(err.Error()) return } //添加请求日志记录 itemApiLog := new(models.CygxThreeApiLog) itemApiLog.CreateTime = time.Now() itemApiLog.Source = 1 itemApiLog.Url = url itemApiLog.Body = utils.ReplaceSpaceAndWrap(fmt.Sprint(payload)) itemApiLog.Result = string(body) go models.AddCygxThreeApiLog(itemApiLog) err = json.Unmarshal(body, &ApifoxModal) if err != nil { fmt.Println("Getres.PublicGetDate Err:", err.Error()) utils.FileLog.Info(err.Error()) return } OldActYIdongList, err := models.GetActivityListByYiDong() if err != nil { fmt.Println(err) utils.FileLog.Info(string(err.Error())) return } mapOldYiDong := make(map[string]string) mapOldYiDongBody := make(map[string]string) for _, v := range OldActYIdongList { mapOldYiDong[v.YidongActivityId] = v.YidongActivityId mapOldYiDongBody[v.YidongActivityId] = fmt.Sprint(v.ActivityName, v.Label, v.ChartPermissionId, v.ActivityTime, v.YidongActivityEndTime, v.DistinguishedGuest) } // 通过查研观向观向建会的易董活动 yiDongByCygxList, err := models.GetActivityListByYiDongByCygx() if err != nil { fmt.Println(err) utils.FileLog.Info(string(err.Error())) return } yiDongByCygxMap := make(map[string]string) for _, v := range yiDongByCygxList { yiDongByCygxMap[v.YidongActivityIdByCygx] = v.YidongActivityIdByCygx } var itemsAdd []*models.CygxActivity if len(ApifoxModal.Result) > 0 { actList := ApifoxModal.Result for _, v := range actList { //同步有效性 1有效,0失效 if v.SyncFlag == "0" { continue } //如果是通过查研观向观向建会的易董活动,就不进行更新的操作 if _, ok := yiDongByCygxMap[v.ID]; ok { continue } //fmt.Println(v.CompanyCode) if v.CompanyCode == yidongHongzeCode { //弘则在易董那边建会的公司code,如果是弘则的就不同步 continue } var item = new(models.CygxActivity) item.YidongActivityId = v.ID item.ActivityTypeId = 3 item.ActivityTypeName = "公司调研电话会" sliceCompanyInfo := strings.Split(v.CompanyInfo, "(") sliceActivityTitle := strings.Split(v.CompanyInfo, ")") companyInfo := sliceCompanyInfo[0] if len(sliceActivityTitle) > 1 { item.ActivityName = companyInfo + v.Title } else { item.ActivityName = v.Title } //fmt.Println(item.ActivityName) //return err item.LastUpdatedTime = time.Now() item.Label = companyInfo item.TemporaryLabel = companyInfo item.ChartPermissionId = utils.CHART_PERMISSION_ID_YANXUAN item.ChartPermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN item.ChartPermissionIdDeputy = GetActivityTypeIdWithYiDong(v.IndustrySwName) item.ChartPermissionNameDeputy = GetActivityTypeNameWithYiDong(v.IndustrySwName) item.ChartPermissionNames = item.ChartPermissionName //if item.ChartPermissionId != item.ChartPermissionIdDeputy { item.IsShowHz = 1 //默认弘则活动也展示 11.0 //} item.ActivityTime = v.Start item.YidongActivityEndTime = v.End item.YidongSignUpStart = v.SignUpStart item.YidongSignUpEnd = v.SignUpEnd item.YidongActivityEndTime = v.End item.ActivityTimeText = GetActivityTextTime(v.Start) item.YidongActivityUrl = v.URL item.ActivityJoinType = v.ActivityJoinType item.IsExternalLabel = 1 detailYidng, err := GetYiDongActivityDetail(v.ID) if err != nil { return err } detailList := detailYidng.Resultdetail.GuestPersonList for _, vdetail := range detailList { item.DistinguishedGuest += vdetail.PersonName + " " + vdetail.JobName + "," } item.DistinguishedGuest = strings.TrimRight(item.DistinguishedGuest, ",") item.Body = "
" + "【" + item.ActivityName + "】" + "
时间:" + item.ActivityTimeText + "
嘉宾:" + item.DistinguishedGuest + "" //fmt.Println(item.Body) //return err if mapOldYiDong[v.ID] == "" { itemsAdd = append(itemsAdd, item) newId, err := models.AddCygxActivity(item) if err != nil { fmt.Println(err) utils.FileLog.Info(string(err.Error())) return err } //把公司名称当做标的 对活动进行产业标的的关联 YidongActivityGroup(companyInfo, int(newId)) } else { //如果内容主体有做变更,就修改内容 if mapOldYiDongBody[v.ID] != fmt.Sprint(item.ActivityName+"12", item.Label, item.ChartPermissionId, item.ActivityTime, item.YidongActivityEndTime, item.DistinguishedGuest) { updateParams := make(map[string]interface{}) updateParams["ActivityName"] = item.ActivityName updateParams["Body"] = item.Body updateParams["Label"] = item.Label //updateParams["TemporaryLabel"] = item.TemporaryLabel updateParams["DistinguishedGuest"] = item.DistinguishedGuest updateParams["ChartPermissionId"] = item.ChartPermissionId updateParams["ChartPermissionName"] = item.ChartPermissionName updateParams["ChartPermissionNames"] = item.ChartPermissionNames updateParams["ActivityTime"] = item.ActivityTime updateParams["YidongActivityEndTime"] = item.YidongActivityEndTime updateParams["ActivityTimeText"] = item.ActivityTimeText updateParams["YidongActivityUrl"] = item.YidongActivityUrl updateParams["ActivityJoinType"] = item.ActivityJoinType updateParams["YidongSignUpStart"] = item.YidongSignUpStart updateParams["YidongSignUpEnd"] = item.YidongSignUpEnd updateParams["ChartPermissionIdDeputy"] = item.ChartPermissionIdDeputy updateParams["ChartPermissionNameDeputy"] = item.ChartPermissionNameDeputy updateParams["IsShowHz"] = item.IsShowHz updateParams["IsExternalLabel"] = 1 updateParams["LastUpdatedTime"] = time.Now() whereParam := map[string]interface{}{"yidong_activity_id": item.YidongActivityId} err = models.UpdateByExpr(models.CygxActivity{}, whereParam, updateParams) if err != nil { return err } } } } } return } // 获取易董活动详情 func GetYiDongActivityDetail(activityId string) (detail *models.ApifoxModaldetail, err error) { defer func() { if err != nil { go utils.SendAlarmMsg("获取易董活动详情失败:"+err.Error(), 2) } }() var token string token, _ = GetYiDongToken() url := utils.YiDongZhengTongYunUrl + "interact/activityManageApi/getRoadshowDetail?access_token=" + token method := "POST" payload := strings.NewReader(`{"activityId":"` + activityId + `"}`) client := &http.Client{} req, err := http.NewRequest(method, url, payload) if err != nil { fmt.Println(err) utils.FileLog.Info(err.Error()) return } req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err != nil { fmt.Println(err) utils.FileLog.Info(err.Error()) return } defer res.Body.Close() var ApifoxModal *models.ApifoxModaldetail body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) utils.FileLog.Info(err.Error()) return } //添加请求日志记录 itemApiLog := new(models.CygxThreeApiLog) itemApiLog.CreateTime = time.Now() itemApiLog.Source = 1 itemApiLog.Url = url itemApiLog.Body = utils.ReplaceSpaceAndWrap(fmt.Sprint(payload)) itemApiLog.Result = string(body) go models.AddCygxThreeApiLog(itemApiLog) err = json.Unmarshal(body, &ApifoxModal) if err != nil { fmt.Println("Getres.PublicGetDate Err:", err.Error()) utils.FileLog.Info(err.Error()) return } detail = ApifoxModal return } // 生成用户相关信息接口 获取用户tgc func GetYiDongCreateUserInfo(user *models.WxUserItem) (userTgc string, err error) { defer func() { if err != nil { fmt.Println(err) go utils.SendAlarmMsg("生成用户相关信息接口 获取用户tgc失败:"+err.Error(), 2) utils.FileLog.Info(err.Error()) } }() url := utils.YiDongHuaWeiYunUrl + "app/hz/createUserInfo" method := "POST" payload := strings.NewReader(`{ "phone": "` + user.Mobile + `", "personName": "` + user.RealName + `", "companyName": "` + user.CompanyName + `", "jobName": "` + user.Position + `", "mobileCountryCode": "+` + user.CountryCode + `", "sourceFrom": "01" }`) client := &http.Client{} req, err := http.NewRequest(method, url, payload) if err != nil { fmt.Println(err) utils.FileLog.Info(err.Error()) return } req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err != nil { fmt.Println(err) utils.FileLog.Info(err.Error()) return } defer res.Body.Close() var ApifoxModal *models.ApifoxModalUserTgc body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) utils.FileLog.Info(err.Error()) return } err = json.Unmarshal(body, &ApifoxModal) if err != nil { fmt.Println("Getres.PublicGetDate Err:", err.Error()) utils.FileLog.Info(err.Error()) return } userTgc = ApifoxModal.Result.Tgc return } // GetYiDongOriginalLink 将易懂的短连接转为长链接 func GetYiDongOriginalLink(item *models.ActivityDetail) (yidongLongLink string, err error) { defer func() { if err != nil { fmt.Println(err) go utils.SendAlarmMsg("将易懂的短连接转为长链接 失败:"+err.Error(), 2) utils.FileLog.Info(err.Error()) } }() sliceYidongActivityUrl := strings.Split(item.YidongActivityUrl, "/") var shortLink string if len(sliceYidongActivityUrl) > 1 { shortLink = sliceYidongActivityUrl[len(sliceYidongActivityUrl)-1] } var token string token, err = GetYiDongToken() if err != nil { fmt.Println(err) return } url := utils.YiDonggetOriginalLink + shortLink + "&access_token=" + token fmt.Println(url) method := "GET" client := &http.Client{} req, err := http.NewRequest(method, url, nil) if err != nil { fmt.Println(err) return } res, err := client.Do(req) if err != nil { fmt.Println(err) return } defer res.Body.Close() var ApifoxModal *models.ApifoxgetOriginalLink body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) utils.FileLog.Info(err.Error()) return } err = json.Unmarshal(body, &ApifoxModal) if err != nil { fmt.Println("Getres.PublicGetDate Err:", err.Error()) utils.FileLog.Info(err.Error()) return } lingLink := ApifoxModal.Result //fmt.Println(lingLink) // //slicelingLink := strings.Split(lingLink, "redirect_uri=") ////var shortLink string //if len(slicelingLink) > 1 { // lingLink = slicelingLink[len(slicelingLink)-1] //} yidongLongLink = lingLink return } // 处理易董这边过来的时间格式 func GetActivityTextTime(timeYidong string) (timeText string) { strTime := timeYidong startTime := utils.StrTimeToTime(strTime) week := utils.StrDateTimeToWeek(strTime) timeStrYmd := startTime.Format(utils.FormatDate) timeStrHmm := startTime.Format(utils.FormatTime) timeYmd := utils.StrTimeToTime(timeStrYmd + " 12:00:00") //拼接当天中午12点的时间 var amOrPm string if startTime.After(timeYmd) { amOrPm = " PM" } else { amOrPm = " AM" } timeText = timeStrYmd + "(" + week + ")" + timeStrHmm + amOrPm return } //func init() { // GetYiDongActivityMeeting() //} // GetYiDongActivityMeeting获取易董到会详情 func GetYiDongActivityMeeting(cont context.Context) (err error) { //func GetYiDongActivityMeeting() (err error) { var condition string startDate := time.Now().AddDate(0, 0, -1).Format(utils.FormatDateTime) endDate := time.Now().Add(-time.Minute * 120).Format(utils.FormatDateTime) condition += ` AND activity_time > ` + "'" + startDate + "'" condition += ` AND activity_time < ` + "'" + endDate + "'" //fmt.Println(startDate) artivityListYidong, err := models.GetActivityListByYidong(condition) if err != nil { fmt.Println("GetActivityListByYidong Err:", err.Error()) return err } //fmt.Println(artivityListYidong) //return //fmt.Println("artivityListYidong", artivityListYidong) //return err if len(artivityListYidong) == 0 { return err } var token string token, _ = GetYiDongToken() for _, v := range artivityListYidong { defer func() { if err != nil { go utils.SendAlarmMsg("获取易董到会详情失败:"+err.Error(), 2) } }() var yidongActivityId string if v.YidongActivityId != "" { yidongActivityId = v.YidongActivityId } else if v.YidongActivityIdByCygx != "" { yidongActivityId = v.YidongActivityIdByCygx } url := utils.YiDongZhengTongYunUrl + "interact/activityManageApi/getAttendPersonList?access_token=" + token method := "POST" payload := strings.NewReader(`{"activityId":"` + yidongActivityId + `"}`) client := &http.Client{} req, err := http.NewRequest(method, url, payload) if err != nil { fmt.Println(err) utils.FileLog.Info(err.Error()) return err } req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err != nil { fmt.Println(err) utils.FileLog.Info(err.Error()) return err } defer res.Body.Close() var ApifoxModal *models.ApifoxModaluser body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) utils.FileLog.Info(err.Error()) return err } //utils.FileLog.Info(string(body)) //fmt.Println(string(body)) err = json.Unmarshal(body, &ApifoxModal) if err != nil { fmt.Println("Getres.PublicGetDate Err:", err.Error()) utils.FileLog.Info(err.Error()) return err } //跟易董返回的用户状态修改活动以提交到会状态 err = models.UpdateCygxActivitySubmitMeetingByYidong(yidongActivityId) if err != nil { fmt.Println("UpdateCygxActivitySubmitMeetingByYidong Err:", err.Error()) return err } var mobiles []string var mobileStr string var mobileStrMeet string mapActivityAttendanceDetail := make(map[string]*models.CygxActivityAttendanceDetail) if len(ApifoxModal.Result) > 0 { itemlog := new(models.CygxYidongActivityMeetingApiLog) itemlog.YidongActivityId = yidongActivityId itemlog.Data = string(body) itemlog.CreateTime = time.Now() err = models.AddCygxYidongActivityMeetingApiLog(itemlog) if err != nil { fmt.Println("AddCygxYidongActivityMeetingApiLog Err:", err.Error()) return err } var itemsUpdate []*models.CygxActivitySignupDetail needAddAttendanc := make([]*models.CygxActivityAttendanceDetail, 0) for _, vresult := range ApifoxModal.Result { if vresult.PersonTelephone == "" { continue } if vresult.Duration != "" || vresult.DurationReview != "" || vresult.DurationLive != "" { mobiles = append(mobiles, vresult.PersonTelephone) //err = models.UpdateCygxActivitySignupisMeet(v.ActivityId, vresult.PersonTelephone) //if err != nil { // fmt.Println("UpdateCygxActivitySignupisMeet Err:", err.Error()) // return err //} var itemDetail = new(models.CygxActivitySignupDetail) if vresult.Duration != "" || vresult.DurationLive != "" { if vresult.Duration == "" { vresult.Duration = vresult.DurationLive } itemDetail.FirstMeetingTime = vresult.StartTime itemDetail.LastMeetingTime = vresult.EndTime itemDetail.Duration = vresult.Duration itemDetail.MeetingStatusStr = "直播" } else if vresult.DurationReview != "" { itemDetail.FirstMeetingTime = vresult.StartTimeReview itemDetail.LastMeetingTime = vresult.EndTimeReview itemDetail.Duration = vresult.DurationReview itemDetail.MeetingStatusStr = "回放" } itemDetail.Position = vresult.JobName itemDetail.RealName = vresult.PersonName itemDetail.Mobile = vresult.PersonTelephone itemDetail.OutboundMobile = vresult.PersonTelephone itemDetail.IsMeeting = 1 itemDetail.ActivityId = v.ActivityId mapActivityAttendanceDetail[vresult.PersonTelephone] = new(models.CygxActivityAttendanceDetail) mapActivityAttendanceDetail[vresult.PersonTelephone].FirstMeetingTime = vresult.StartTime mapActivityAttendanceDetail[vresult.PersonTelephone].LastMeetingTime = vresult.EndTime mapActivityAttendanceDetail[vresult.PersonTelephone].Duration = utils.GetAttendanceDetailSecondsByYiDong(vresult.Duration) itemsUpdate = append(itemsUpdate, itemDetail) } else { continue } item := new(models.CygxActivityAttendanceDetail) item.ActivityId = v.ActivityId item.Mobile = vresult.PersonTelephone if vresult.Duration != "" { item.FirstMeetingTime = vresult.StartTime item.LastMeetingTime = vresult.EndTime item.Duration = vresult.Duration item.MeetingStatusStr = "直播" } else if vresult.DurationReview != "" { item.FirstMeetingTime = vresult.StartTimeReview item.LastMeetingTime = vresult.EndTimeReview item.Duration = vresult.DurationReview item.MeetingStatusStr = "回放" } item.Position = vresult.JobName item.RealName = vresult.PersonName item.FirstMeetingTime = vresult.StartTime item.LastMeetingTime = vresult.EndTime item.Duration = vresult.Duration item.IsMeetingStr = 1 mobileStrMeet += "'" + vresult.PersonTelephone + "'" + "," item.CreateTime = time.Now() needAddAttendanc = append(needAddAttendanc, item) mobileStr += "'" + vresult.PersonTelephone + "'" + "," } lenmobiles := len(mobiles) if lenmobiles > 0 { var parsYd []interface{} var conditionYd string conditionYd = ` AND mobile IN (` + utils.GetOrmInReplace(lenmobiles) + `) AND activity_id=? ` parsYd = append(parsYd, mobiles, v.ActivityId) err = models.UpdateCygxActivitySignupisMeetList(conditionYd, parsYd) if err != nil { fmt.Println("UpdateCygxActivitySignupisMeetList Err:", err.Error()) return err } err = models.UpdateActivitySignupDetailMultiByYiDong(itemsUpdate) if err != nil { fmt.Println("UpdateActivitySignupDetailMultiByYiDong Err:", err.Error()) return err } } mobileStr = strings.TrimRight(mobileStr, ",") if mobileStr == "" { mobileStr = "1" } mobileStrMeet = strings.TrimRight(mobileStrMeet, ",") if mobileStrMeet == "" { mobileStrMeet = "1" } listUser, err := models.GetWxUserOutboundMobile(mobileStr) if err != nil { fmt.Println("GetWxUserOutboundMobile Err:", err.Error()) return err } for kAdd, vAdd := range needAddAttendanc { for _, v2 := range listUser { if v2.OutboundMobile == vAdd.Mobile || v2.Mobile == vAdd.Mobile { if needAddAttendanc[kAdd].CompanyId <= 1 { needAddAttendanc[kAdd].CompanyId = v2.CompanyId needAddAttendanc[kAdd].SellerName = v2.SellerName needAddAttendanc[kAdd].CompanyName = v2.CompanyName //needAddAttendanc[k].IsMeetingStr = 1 } } } } //参会记录 err = models.AddAttendancDetail(needAddAttendanc, v.ActivityId, mobileStrMeet) if err != nil { fmt.Println("AddAttendancDetail Err:", err.Error()) return err } ////处理是否限制报名 err = AddCygxActivityRestrictSignupByAdmin(v.ActivityId) if err != nil { fmt.Println("AddCygxActivityRestrictSignupByAdmin Err:", err.Error()) return err } AddctivitySignupDetailByJmcjNew(needAddAttendanc, []int{v.ActivityId}) } } return } // YidongActivityGroup 添加活动与产业标的的关联 func YidongActivityGroup(subjectName string, activityId int) (err error) { subjectList, err := models.GetCygxIndustrialSubjectList(subjectName) if err != nil { fmt.Println(err) return err } if len(subjectList) == 0 { return err } fmt.Println("去掉临时标签的活动", activityId) err = models.UpdateActivityshowSubject(activityId) if err != nil { go utils.SendAlarmMsg("UpdateActivityshowSubject :根据易董推过来的匹配信息,判断临时标签是否展示失败"+err.Error(), 2) } var industrialActivityItems []*models.CygxIndustrialActivityGroupManagement var subjectActivityItems []*models.CygxIndustrialActivityGroupSubject mapSubjectName := make(map[string]string) for _, v := range subjectList { industrialActivityItem := new(models.CygxIndustrialActivityGroupManagement) subjectActivityItem := new(models.CygxIndustrialActivityGroupSubject) industrialActivityItem.ActivityId = activityId industrialActivityItem.IndustrialManagementId = v.IndustrialManagementId industrialActivityItem.Source = 1 industrialActivityItem.CreateTime = time.Now() industrialActivityItems = append(industrialActivityItems, industrialActivityItem) subjectActivityItem.ActivityId = activityId subjectActivityItem.IndustrialSubjectId = v.IndustrialSubjectId subjectActivityItem.Source = 1 subjectActivityItem.CreateTime = time.Now() if mapSubjectName[v.SubjectName] == "" { subjectActivityItems = append(subjectActivityItems, subjectActivityItem) mapSubjectName[v.SubjectName] = v.SubjectName } } err = models.AddCygxActiuvityGroupMulti(industrialActivityItems, subjectActivityItems) if err != nil { go utils.SendAlarmMsg("AddCygxActiuvityGroupMulti :批量添加易董活动关联的活动标签失败"+err.Error(), 2) } return } // 会前一小时将,报名信息同步到易董 func YiDongSignAppointmentsForThird(cont context.Context) (err error) { //func YiDongSignAppointmentsForThird() (err error) { defer func() { if err != nil { fmt.Println(err) go utils.SendAlarmMsg("会前一小时将,报名信息同步到易董,同步失败"+err.Error(), 2) } }() var pars []interface{} var condition string startDate := time.Now().Add(+time.Minute * 45).Format(utils.FormatDateTime) endDate := time.Now().Add(+time.Minute * 60).Format(utils.FormatDateTime) condition = " AND is_yidong_sign_up = 0 AND yidong_activity_id_by_cygx != '' AND activity_time BETWEEN ? AND ? " pars = append(pars, startDate, endDate) activityList, err := models.GetActivityListByCondition(condition, pars) if err != nil { return } if len(activityList) == 0 { return } listEmail, e := models.GetAskEmail() if e != nil { err = errors.New("GetAskEmail, Err: " + e.Error()) return } //获取某一个活动下面不需要推送的主讲人手机号 idAndMobileNoSendMap := make(map[string]bool) for _, v := range activityList { for _, vName := range listEmail { if strings.Contains(v.Speaker, vName.Name) { idAndMobileNoSendMap[fmt.Sprint("Id_", v.ActivityId, "Mobile_", vName.Mobile)] = true } } } url := utils.YiDongHuaWeiYunUrl + "app/hz/signAppointmentsForThird" var outCallStatus string for _, v := range activityList { go UpdateIsSendYidongSignUp(v.ActivityId) var parsSignUp []interface{} var conditionSignUp string conditionSignUp += ` AND activity_id = ?` parsSignUp = append(parsSignUp, v.ActivityId) conditionSignUp += ` AND do_fail_type = 0 ` listSignUp, e := models.GetActivitySignuListByUser(conditionSignUp, parsSignUp) if e != nil { err = errors.New("GetActivitySignuListByUser, Err: " + e.Error()) return } if len(listSignUp) == 0 { continue } var companyIds []int for _, vS := range listSignUp { companyIds = append(companyIds, vS.CompanyId) } sellNameMap := GetSellNameMapByCompanyIds(companyIds) for _, vS := range listSignUp { if idAndMobileNoSendMap[fmt.Sprint("Id_", vS.ActivityId, "Mobile_", vS.Mobile)] { continue //如果这个活动对应的是主讲人的手机号,那么就不做推送 } if vS.SignupType == 1 { outCallStatus = "1" } else { outCallStatus = "0" } params := SignAppointmentsForThirdParam{ ActivityId: v.YidongActivityIdByCygx, MobileCountryCode: "+" + vS.CountryCode, PersonTelephone: vS.OutboundMobile, ThirdPartySource: "01", InvestorType: "0", PersonName: vS.RealName, JoinRole: "2", CompanyName: vS.CompanyName, Extend1: sellNameMap[vS.CompanyId], OutCallStatus: outCallStatus, } postData, e := json.Marshal(params) if e != nil { err = e fmt.Println("PostData json.Marshal Err:" + err.Error()) utils.FileLog.Info("PostData json.Marshal Err:" + err.Error()) return } method := "POST" client := &http.Client{} req, e := http.NewRequest(method, url, strings.NewReader(string(postData))) if e != nil { err = e fmt.Println(err) return } req.Header.Add("Content-Type", "application/json") res, e := client.Do(req) if e != nil { err = e return } defer res.Body.Close() body, e := ioutil.ReadAll(res.Body) if e != nil { err = e return } itemApiLog := new(models.CygxThreeApiLog) itemApiLog.CreateTime = time.Now() itemApiLog.Source = 1 itemApiLog.Url = url itemApiLog.Body = string(postData) itemApiLog.Result = string(body) go models.AddCygxThreeApiLog(itemApiLog) var yidongResp *YiDongSignAppointmentsForThirdResp err = json.Unmarshal(body, &yidongResp) if err != nil { return } if !yidongResp.Success { err = errors.New(" 会前一小时将,报名信息同步到易董,同步失败," + yidongResp.ErrorCode + yidongResp.ErrorMsg) return } } } return } type SignAppointmentsForThirdParam struct { ActivityId string `description:"易董活动ID" json:"activityId"` MobileCountryCode string `description:"国际区号注意要带前面+号 " json:"mobileCountryCode"` PersonTelephone string `description:"手机号" json:"personTelephone"` ThirdPartySource string `description:"第三方来源;弘则固定:01" json:"thirdPartySource"` InvestorType string `description:"投资者类型 0个人1机构" json:"investorType"` PersonName string `description:"姓名" json:"personName"` CompanyName string `description:"公司名" json:"companyName"` JoinRole string `description:"1:嘉宾, 2:普通参会人员, 3:会议助理。不传默认取值2" json:"joinRole"` OutCallStatus string `description:"1:需要,0:不需要。不传取默认值0" json:"outCallStatus"` Extend1 string `description:"对口销售" json:"extend1"` } type YiDongSignAppointmentsForThirdResp struct { ErrorCode string `json:"errorCode"` // 错误码,001:活动不存在;002:该活动不支持此渠道报名;003:该手机号或邮箱已经被其他账号提交报名;004:不在报名时间;005:报名人数已满 ErrorMsg string `json:"errorMsg"` // 错误信息 Success bool `json:"success"` // 成功标识,true:成功;false:失败。可作为判断报名是否成功的标识 Timestamp float64 `json:"timestamp"` // 时间戳 } //func init() { // GroupingActivityToYiDong() //} // GroupingActivityToYiDong 建立与易董的活动关联 func GroupingActivityToYiDong(cont context.Context) (err error) { //func GroupingActivityToYiDong() (err error) { defer func() { if err != nil { fmt.Println(err) go utils.SendAlarmMsg("建立与易董的活动关联失败 GroupingActivityToYiDong"+err.Error(), 2) } }() startDate := time.Now().AddDate(0, 0, -2).Format(utils.FormatDate) endDate := time.Now().AddDate(0, 0, 0).Format(utils.FormatDate) var token string token, _ = GetYiDongToken() url := utils.YiDongZhengTongYunUrl + "interact/activityManageApi/getRoadshowList?access_token=" + token method := "POST" payload := strings.NewReader(`{ "meetingStatus": "2", "conveneStartStr": "` + startDate + `", "conveneEndStr": "` + endDate + `"}`) client := &http.Client{} req, err := http.NewRequest(method, url, payload) if err != nil { fmt.Println(err) utils.FileLog.Info(err.Error()) return } req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err != nil { fmt.Println(err) utils.FileLog.Info(err.Error()) return } defer res.Body.Close() var ApifoxModal *models.ApifoxModal body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) utils.FileLog.Info(err.Error()) return } //添加请求日志记录 itemApiLog := new(models.CygxThreeApiLog) itemApiLog.CreateTime = time.Now() itemApiLog.Source = 1 itemApiLog.Url = url itemApiLog.Body = utils.ReplaceSpaceAndWrap(fmt.Sprint(payload)) itemApiLog.Result = string(body) go models.AddCygxThreeApiLog(itemApiLog) err = json.Unmarshal(body, &ApifoxModal) if err != nil { fmt.Println("Getres.PublicGetDate Err:", err.Error()) return } //var itemsAdd []*models.CygxActivity if len(ApifoxModal.Result) > 0 { actList := ApifoxModal.Result for _, v := range actList { //同步有效性 1有效,0失效 if v.SyncFlag == "0" { continue } var yidongTitle string titleSlice := strings.Split(v.Title, "】") for _, vt := range titleSlice { yidongTitle = vt } e := models.UpdateCygxActivityyidongActivityId(v.ID, v.Start, yidongTitle) if e != nil { err = errors.New("UpdateCygxActivityyidongActivityId, Err: " + e.Error()) return } } } return } // GetLoginAuthCodeReq 获取登录编码请求体 type GetYiDongActivityByApiReq struct { MeetingStatus string `json:"meetingStatus" description:"会议状态必需(0未开始1进行中2已结束)多个逗号分隔"` ConveneStartStr string `json:"conveneStartStr" description:"活动日期范围开始"` ConveneEndStr string `json:"conveneEndStr" description:"活动日期范围结束"` LastUpdateTime string `json:"lastUpdateTime" description:"上次同步时间(用于筛选更新时间大于同步时间的活动数据)"` } type GetYiDongActivityMeetByActivityIdReq struct { ActivityId string `json:"activityId" description:"活动ID"` } // 根据条件获取易董建会列表信息 func GetYiDongActivityListByApi(param *GetYiDongActivityByApiReq) (yiDongResult []models.Result) { var err error defer func() { if err != nil { fmt.Println(err) go utils.SendAlarmMsg(fmt.Sprint("根据条件获取易董建会列表信息 GetYiDongActivityListByApi"+err.Error(), param), 2) } }() var token string token, _ = GetYiDongToken() url := utils.YiDongZhengTongYunUrl + "interact/activityManageApi/getRoadshowList?access_token=" + token method := "POST" data, e := json.Marshal(param) if e != nil { err = errors.New("data json marshal err: " + e.Error()) return } payload := strings.NewReader(string(data)) client := &http.Client{} req, e := http.NewRequest(method, url, payload) if e != nil { err = errors.New(" http.NewRequest err: " + e.Error()) return } req.Header.Add("Content-Type", "application/json") res, e := client.Do(req) if e != nil { err = errors.New(" client.Do err: " + e.Error()) return } defer res.Body.Close() var ApifoxModal *models.ApifoxModal body, e := ioutil.ReadAll(res.Body) if e != nil { err = errors.New(" ioutil.ReadAll: " + e.Error()) return } //添加请求日志记录 itemApiLog := new(models.CygxThreeApiLog) itemApiLog.CreateTime = time.Now() itemApiLog.Source = 1 itemApiLog.Url = url itemApiLog.Body = utils.ReplaceSpaceAndWrap(fmt.Sprint(payload)) itemApiLog.Result = string(body) go models.AddCygxThreeApiLog(itemApiLog) err = json.Unmarshal(body, &ApifoxModal) if err != nil { fmt.Println("Getres.PublicGetDate Err:", err.Error()) return } if len(ApifoxModal.Result) > 0 { yiDongResult = ApifoxModal.Result } else { yiDongResult = make([]models.Result, 0) } return } // 根据条件获取易董活动ID获取到会信息 func GetYiDongActivityMeetDataByaAtivityId(ativityId string) (yiDongResult []models.Resultuser) { var err error defer func() { if err != nil { fmt.Println(err) go utils.SendAlarmMsg(fmt.Sprint("根据条件获取易董建会列表信息 GetYiDongActivityListByApi"+err.Error(), ativityId), 2) } }() var token string token, _ = GetYiDongToken() url := utils.YiDongZhengTongYunUrl + "interact/activityManageApi/getAttendPersonList?access_token=" + token method := "POST" param := new(GetYiDongActivityMeetByActivityIdReq) param.ActivityId = ativityId data, e := json.Marshal(param) if e != nil { err = errors.New("data json marshal err: " + e.Error()) return } payload := strings.NewReader(string(data)) client := &http.Client{} req, e := http.NewRequest(method, url, payload) if e != nil { err = errors.New(" http.NewRequest err: " + e.Error()) return } req.Header.Add("Content-Type", "application/json") res, e := client.Do(req) if e != nil { err = errors.New(" client.Do err: " + e.Error()) return } defer res.Body.Close() var ApifoxModal *models.ApifoxModaluser body, e := ioutil.ReadAll(res.Body) if e != nil { err = errors.New(" ioutil.ReadAll err: " + e.Error()) return } e = json.Unmarshal(body, &ApifoxModal) if e != nil { err = errors.New(" json.Unmarshal err: " + e.Error()) return } //添加请求日志记录 itemApiLog := new(models.CygxThreeApiLog) itemApiLog.CreateTime = time.Now() itemApiLog.Source = 1 itemApiLog.Url = url itemApiLog.Body = utils.ReplaceSpaceAndWrap(fmt.Sprint(payload)) itemApiLog.Result = string(body) go models.AddCygxThreeApiLog(itemApiLog) err = json.Unmarshal(body, &ApifoxModal) if err != nil { fmt.Println("Getres.PublicGetDate Err:", err.Error()) return } if len(ApifoxModal.Result) > 0 { yiDongResult = ApifoxModal.Result } else { yiDongResult = make([]models.Resultuser, 0) } return } //func init() { // UpdateYiDongActivityDataToCygx() //} // 更新易董活动信息,到会信息到查研观向数据库 func UpdateYiDongActivityDataToCygx(cont context.Context) (err error) { defer func() { if err != nil { fmt.Println(err) go utils.SendAlarmMsg(fmt.Sprint("更新易董活动信息,到会信息到查研观向数据库 UpdateYiDongActivityDataToCygx"+err.Error()), 2) } }() startDate := time.Now().AddDate(0, 0, -3).Format(utils.FormatDate) endDate := time.Now().AddDate(0, 0, 0).Format(utils.FormatDate) param := new(GetYiDongActivityByApiReq) param.MeetingStatus = "2" param.ConveneStartStr = startDate param.ConveneEndStr = endDate actList := GetYiDongActivityListByApi(param) if len(actList) == 0 { return } var itmes []*yidong.CygxYidongActivity var YidongIds []string for _, v := range actList { YidongIds = append(YidongIds, v.ID) } listCygx, e := yidong.GetCygxYidongActivityListByYidongIds(YidongIds) if e != nil { err = errors.New("GetCygxYidongActivityListByYidongIds, Err: " + e.Error()) return } mapYidongId := make(map[string]bool) for _, v := range listCygx { mapYidongId[v.YidongId] = true } listMeetDataCygx, e := yidong.GetCygxYidongActivityMeetDataListByYidongIds(YidongIds) if e != nil { err = errors.New("GetCygxYidongActivityListByYidongIds, Err: " + e.Error()) return } mapMeetData := make(map[string]bool) for _, v := range listMeetDataCygx { mapMeetData[fmt.Sprint("AID_", v.YidongId, "M_", v.PersonTelephone)] = true } for _, v := range actList { if mapYidongId[v.ID] { continue } item := new(yidong.CygxYidongActivity) item.YidongId = v.ID item.CompanyInfo = v.CompanyInfo item.Type = v.Type item.IndustrySwName = v.IndustrySwName item.Start = v.Start item.End = v.End item.SignUpStart = v.SignUpStart item.SignUpEnd = v.SignUpEnd item.ActivityJoinType = v.ActivityJoinType item.Banner = v.Banner item.Url = v.URL item.SyncFlag = v.SyncFlag item.BusinessCardOpen = v.BusinessCardOpen item.BusinessCardRequired = v.BusinessCardRequired item.PersonNameOpen = v.PersonNameOpen item.PersonNameRequired = v.PersonNameRequired item.PersonTelephoneOpen = v.PersonTelephoneOpen item.PersonTelephoneRequired = v.PersonTelephoneRequired item.MailOpen = v.MailOpen item.MailRequired = v.MailRequired item.CompanyShortNameOpen = v.CompanyShortNameOpen item.CompanyShortNameRequired = v.CompanyShortNameRequired item.CompanyCodeOpen = v.CompanyCodeOpen item.CompanyCodeRequired = v.CompanyCodeRequired item.JobNameOpen = v.JobNameOpen item.JobNameRequired = v.JobNameRequired item.CertificateInformationOpen = v.CertificateInformationOpen item.CertificateInformationRequired = v.CertificateInformationRequired item.InviteeOpen = v.InviteeOpen item.InviteeRequired = v.InviteeRequired item.CreateTime = time.Now() itmes = append(itmes, item) } //新增记录 if len(itmes) > 0 { e = yidong.AddCygxYidongActivityMulti(itmes) if e != nil { err = errors.New("AddCygxYidongActivityMulti, Err: " + e.Error()) return } } var itmesMdata []*yidong.CygxYidongActivityMeetData for _, v := range actList { meetDataList := GetYiDongActivityMeetDataByaAtivityId(v.ID) for _, mdata := range meetDataList { if mapMeetData[fmt.Sprint("AID_", v.ID, "M_", mdata.PersonTelephone)] || mdata.PersonTelephone == "" { continue } itmemdata := new(yidong.CygxYidongActivityMeetData) itmemdata.YidongMeetDataId = mdata.ID itmemdata.Title = v.Title itmemdata.YidongId = v.ID itmemdata.UserId = mdata.UserID itmemdata.PersonTelephone = mdata.PersonTelephone itmemdata.Duration = mdata.Duration itmemdata.StartTime = mdata.StartTime itmemdata.EndTime = mdata.EndTime itmemdata.DeviceType = mdata.DeviceType itmemdata.Status = mdata.Status itmemdata.PersonName = mdata.PersonName itmemdata.JobName = mdata.JobName itmemdata.Mail = mdata.Mail itmemdata.CompanyName = mdata.CompanyName itmemdata.MobileCountryCode = mdata.MobileCountryCode itmemdata.SignUpStatus = mdata.SignUpStatus itmemdata.DurationLive = mdata.DurationLive itmemdata.StartTimeLive = mdata.StartTimeLive itmemdata.EndTimeLive = mdata.EndTimeLive itmemdata.DurationReview = mdata.DurationReview itmemdata.StartTimeInteract = mdata.StartTimeInteract itmemdata.EndTimeInteract = mdata.EndTimeInteract itmemdata.CreateTime = time.Now() itmesMdata = append(itmesMdata, itmemdata) } } // 写入到会信息 if len(itmesMdata) > 0 { e = yidong.AddCygxYidongActivityMeetDataMulti(itmesMdata) if e != nil { err = errors.New("AddCygxYidongActivityMeetDataMulti, Err: " + e.Error()) return } } //fmt.Println("end") return } //func init() { // //param := new(GetYiDongActivityByApiReq) // //param.MeetingStatus = "2" // //param.ConveneStartStr = "2024-10-28" // //param.ConveneEndStr = "2024-10-30" // actList := GetYiDongActivityMeetDataByaAtivityId("1180584155007237390") // // for _, v := range actList { // //同步有效性 1有效,0失效 // //if v.SyncFlag == "0" { // // continue // //} // //var yidongTitle string // //titleSlice := strings.Split(v.Title, "】") // // // //for _, vt := range titleSlice { // // yidongTitle = vt // //} // // fmt.Println(v.PersonTelephone) // fmt.Println(v.PersonName) // } //}