123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389 |
- 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 = "<p>" + "【" + item.ActivityName + "】" + "<p>时间:" + item.ActivityTimeText + "</p>嘉宾:" + item.DistinguishedGuest + "</p>"
- //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
- 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)
- // }
- //}
|