123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560 |
- package services
- import (
- "encoding/json"
- "errors"
- "fmt"
- "hongze/hongze_cygx/models"
- "hongze/hongze_cygx/models/roadshow"
- "hongze/hongze_cygx/utils"
- "strconv"
- "time"
- )
- // 添加用户搜索标签到Redis
- func KeyWordsWxUserRaiLabelRedisAdd(sourceId, uid int, label string) (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- msg := fmt.Sprint("sourceId:", sourceId, "userId:", uid)
- go utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
- }
- }()
- log := &models.WxUserRaiLabelRedis{UserId: uid, SourceId: sourceId, SourceType: 1, Label: label, CreateTime: time.Now(), RegisterPlatform: utils.REGISTER_PLATFORM}
- if utils.Re == nil {
- err := utils.Rc.LPush(utils.WX_USER_RAI_LABEL_KEY, log)
- if err != nil {
- fmt.Println("WxUserRaiLabelRedis LPush Err:" + err.Error())
- }
- }
- return
- }
- // 添加用户阅读文章标签到Redis
- func ArticleWxUserRaiLabelRedisAdd(sourceId, uid int, createTime time.Time) (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- msg := fmt.Sprint("sourceId:", sourceId, "userId:", uid)
- go utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
- }
- }()
- log := &models.WxUserRaiLabelRedis{UserId: uid, SourceId: sourceId, SourceType: 1, TableName: utils.CYGX_OBJ_ARTICLE, CreateTime: createTime, RegisterPlatform: utils.REGISTER_PLATFORM}
- if utils.Re == nil {
- err := utils.Rc.LPush(utils.WX_USER_RAI_LABEL_KEY, log)
- if err != nil {
- fmt.Println("WxUserRaiLabelRedis LPush Err:" + err.Error())
- }
- }
- return
- }
- // 添加用户阅读本周研究汇总,与重点公司标签到Redis
- func ReportSelectionWxUserRaiLabelRedisAdd(sourceId, uid int, createTime time.Time, tableName, label string) (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- msg := fmt.Sprint("sourceId:", sourceId, "userId:", uid)
- go utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
- }
- }()
- log := &models.WxUserRaiLabelRedis{UserId: uid, SourceId: sourceId, SourceType: 1, TableName: tableName, Label: label, CreateTime: createTime, RegisterPlatform: utils.REGISTER_PLATFORM}
- if utils.Re == nil {
- err := utils.Rc.LPush(utils.WX_USER_RAI_LABEL_KEY, log)
- if err != nil {
- fmt.Println("ReportSelectionWxUserRaiLabelRedisAdd LPush Err:" + err.Error())
- }
- }
- return
- }
- // 添加用户参加活动标签到Redis
- func ActivityWxUserRaiLabelRedisAdd(sourceId, uid int, createTime time.Time) (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- msg := fmt.Sprint("sourceId:", sourceId, "userId:", uid)
- go utils.SendAlarmMsg("添加用户参加活动标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
- }
- }()
- log := &models.WxUserRaiLabelRedis{UserId: uid, SourceId: sourceId, SourceType: 2, CreateTime: createTime, RegisterPlatform: utils.REGISTER_PLATFORM}
- if utils.Re == nil {
- err := utils.Rc.LPush(utils.WX_USER_RAI_LABEL_KEY, log)
- if err != nil {
- fmt.Println("ActivityWxUserRaiLabelRedisAdd LPush Err:" + err.Error())
- }
- }
- return
- }
- func UpdateWxUserRaiLabelRedis() (err error) {
- for {
- // SourceType int `description:"来源1:搜索关键字标签、2:产业/个股标签(线下活动)、3:产业/个股标签(线下路演)、4:产业/个股标签(线上活动)、5:产业/个股标签(线上路演)、6:销售输入标签、7:产业/个股标签(报告)、8:报告类型标签"`
- utils.Rc.Brpop(utils.WX_USER_RAI_LABEL_KEY, func(b []byte) {
- var log models.WxUserRaiLabelRedis
- if err := json.Unmarshal(b, &log); err != nil {
- fmt.Println("json unmarshal wrong!")
- go utils.SendAlarmMsg("用户更新相关标签处理Redis队列消息失败:"+err.Error()+string(b), 2)
- }
- if log.TableName == "" {
- switch log.SourceType {
- case 1:
- go KeyWordsWxUserRaiLabelRedisAddReduce(log)
- fmt.Println("搜索关键词")
- break
- case 2, 4:
- go ActivityWxUserRaiLabelRedisAddReduce(log)
- fmt.Println("活动到会")
- break
- case 3, 5:
- go RoadshowWxUserRaiLabelRedisAddReduce(log)
- fmt.Println("活动到会")
- break
- default:
- fmt.Println(string(b))
- go utils.SendAlarmMsg("用户更新相关标签处理Redis队列消息失败:"+string(b), 2)
- }
- } else {
- switch log.TableName {
- case utils.CYGX_OBJ_ARTICLE:
- go ArticleWxUserRaiLabelRedisAddReduce(log)
- fmt.Println("阅读文章")
- case "cygx_research_summary":
- go ReportSelectionWxUserRaiLabelRedisAddReduce(log)
- fmt.Println("阅读本周研究汇总")
- case "cygx_report_selection":
- go ReportSelectionWxUserRaiLabelRedisAddReduce(log)
- fmt.Println("阅读报告精选(重点公司)")
- }
- }
- })
- }
- }
- // 1:搜索关键词
- func KeyWordsWxUserRaiLabelRedisAddReduce(log models.WxUserRaiLabelRedis) (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg("用户文章阅读更新相关标签,处理Redis队列消息失败:"+err.Error()+fmt.Sprint("articleId", log.SourceId, "userId", log.UserId), 2)
- }
- }()
- userId := log.UserId
- label := log.Label
- if userId == 0 {
- return
- }
- wxUser, e := models.GetWxUserItemByUserId(userId)
- if e != nil {
- err = errors.New("GetWxUserItemByUserId" + e.Error())
- return
- }
- item := new(models.WxUserRaiLabel)
- item.UserId = wxUser.UserId
- item.RealName = wxUser.RealName
- item.Mobile = wxUser.Mobile
- item.Email = wxUser.Email
- item.CompanyId = wxUser.CompanyId
- item.CompanyName = wxUser.CompanyName
- item.Label = label
- item.SourceType = log.SourceType
- item.CreateTime = log.CreateTime
- item.ModifyTime = time.Now()
- item.RegisterPlatform = log.RegisterPlatform
- err = models.AddWxUserRaiLabel(item)
- if e != nil {
- err = errors.New("AddWxUserRaiLabel" + e.Error())
- return
- }
- return
- }
- //func init() {
- // log := models.WxUserRaiLabelRedis{UserId: 53840, SourceId: 1753, SourceType: 3, TableName: "", Label: "", CreateTime: time.Now(), RegisterPlatform: utils.REGISTER_PLATFORM}
- // RoadshowWxUserRaiLabelRedisAddReduce(log)
- //}
- // 2:产业/个股标签(线下活动)、 4:产业/个股标签(线上活动)
- // 用户参加活动,相关标签
- func ActivityWxUserRaiLabelRedisAddReduce(log models.WxUserRaiLabelRedis) (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg("用户参加活动,相关标签,处理Redis队列消息失败:ActivityWxUserRaiLabelRedisAddReduce"+err.Error()+fmt.Sprint("SourceId", log.SourceId, "userId", log.UserId), 2)
- }
- }()
- userId := log.UserId
- sourceId := log.SourceId
- wxUser, e := models.GetWxUserItemByUserId(userId)
- if e != nil {
- err = errors.New("GetWxUserItemByUserId" + e.Error())
- return
- }
- activityDetail, e := models.GetAddActivityDetailByActivityId(sourceId)
- if e != nil {
- err = errors.New("GetArticleDetailTestById" + e.Error())
- return
- }
- var sourceType int
- if activityDetail.ActivityType == 1 {
- sourceType = 4
- } else {
- sourceType = 2
- }
- //正常的有产业报告
- var labelArr []string
- //建立首页资源表,与产业的关系
- industrialList, e := models.GetIndustrialActivityGroupManagementListByArticleId(sourceId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetIndustrialArticleGroupManagementListByArticleId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
- return
- }
- var items []*models.WxUserRaiLabel
- for _, v := range industrialList {
- item := new(models.WxUserRaiLabel)
- item.UserId = wxUser.UserId
- item.RealName = wxUser.RealName
- item.Mobile = wxUser.Mobile
- item.Email = wxUser.Email
- item.CompanyId = wxUser.CompanyId
- item.CompanyName = wxUser.CompanyName
- item.Label = v.IndustryName
- item.SourceType = sourceType
- item.SourceId = sourceId
- item.CreateTime = log.CreateTime
- item.ModifyTime = time.Now()
- item.RegisterPlatform = log.RegisterPlatform
- item.TableName = ""
- items = append(items, item)
- labelArr = append(labelArr, v.IndustryName)
- }
- //建立首页资源表,与标的 的关系
- subjectList, e := models.GetSubjectActivityGroupManagementListByActivityId(sourceId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetSubjectArticleGroupManagementListByArtcileId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
- return
- }
- //fmt.Println("subjectList", subjectList)
- for _, v := range subjectList {
- item := new(models.WxUserRaiLabel)
- item.UserId = wxUser.UserId
- item.RealName = wxUser.RealName
- item.Mobile = wxUser.Mobile
- item.Email = wxUser.Email
- item.CompanyId = wxUser.CompanyId
- item.CompanyName = wxUser.CompanyName
- item.Label = v.SubjectName
- item.SourceType = sourceType
- item.SourceId = sourceId
- item.CreateTime = log.CreateTime
- item.ModifyTime = time.Now()
- item.RegisterPlatform = log.RegisterPlatform
- item.TableName = ""
- items = append(items, item)
- labelArr = append(labelArr, v.SubjectName)
- }
- //如果两个标签都没有,就添加临时标签
- if len(labelArr) == 0 {
- item := new(models.WxUserRaiLabel)
- item.UserId = wxUser.UserId
- item.RealName = wxUser.RealName
- item.Mobile = wxUser.Mobile
- item.Email = wxUser.Email
- item.CompanyId = wxUser.CompanyId
- item.CompanyName = wxUser.CompanyName
- item.Label = activityDetail.Label
- item.SourceType = sourceType
- item.SourceId = sourceId
- item.CreateTime = log.CreateTime
- item.ModifyTime = time.Now()
- item.RegisterPlatform = log.RegisterPlatform
- item.TableName = ""
- items = append(items, item)
- labelArr = append(labelArr, activityDetail.Label)
- }
- e = models.AddWxUserRaiLabelMulti(items, labelArr, userId)
- if e != nil {
- err = errors.New("AddWxUserRaiLabelMulti" + e.Error())
- return
- }
- return
- }
- // 3:产业/个股标签(路演线下活动)、 5:产业/个股标签(路演线上活动)
- // 用户参加路演,相关标签
- func RoadshowWxUserRaiLabelRedisAddReduce(log models.WxUserRaiLabelRedis) (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg("用户参加路演,相关标签,处理Redis队列消息失败:RoadshowWxUserRaiLabelRedisAddReduce"+err.Error()+fmt.Sprint("SourceId", log.SourceId, "userId", log.UserId), 2)
- }
- }()
- userId := log.UserId
- sourceId := log.SourceId
- wxUser, e := models.GetWxUserItemByUserId(userId)
- if e != nil {
- err = errors.New("GetWxUserItemByUserId" + e.Error())
- return
- }
- rsCalendar, e := roadshow.GetRsCalendarById(sourceId)
- if e != nil {
- err = errors.New("GetRsCalendarById" + e.Error())
- return
- }
- var sourceType int
- if rsCalendar.RoadshowType == "线下" {
- sourceType = 3
- } else {
- sourceType = 5
- }
- totalGroup, e := roadshow.GetRsCalendarMeetingLabelGroupByRsCalendarId(sourceId)
- if e != nil {
- err = errors.New("GetRsCalendarMeetingLabelGroupByRsCalendarId" + e.Error())
- return
- }
- //var lebelDetail []*cygx.RaiServeTagResp
- var label string
- var labelArr []string
- var items []*models.WxUserRaiLabel
- if totalGroup > 0 {
- listGroup, e := roadshow.GetRsCalendarMeetingLabelGroupListByRsCalendarId(sourceId)
- if e != nil {
- err = errors.New("GetRsCalendarMeetingLabelGroupByRsCalendarId" + e.Error())
- return
- }
- var industrialManagementIds []int
- var industrialSubjectIds []int
- mapindustrialManagementName := make(map[int]string)
- mapindustrialSubjectName := make(map[int]string)
- mapCelueName := make(map[int]string)
- for _, v := range listGroup {
- switch v.TagType {
- case 1:
- industrialManagementIds = append(industrialManagementIds, v.TagId)
- case 2:
- industrialSubjectIds = append(industrialSubjectIds, v.TagId)
- case 3:
- mapCelueName[v.TagId] = "策略"
- }
- }
- if len(industrialManagementIds) > 0 {
- IndustryList, e := models.GetIndustryListByConditionByIds(industrialManagementIds)
- if e != nil {
- err = errors.New("GetRsCalendarMeetingLabelGroupByRsCalendarId" + e.Error())
- return
- }
- for _, v := range IndustryList {
- mapindustrialManagementName[v.IndustrialManagementId] = v.IndustryName
- }
- }
- if len(industrialSubjectIds) > 0 {
- SubjectList, e := models.GetIndustrialSubjectDetailByIds(industrialSubjectIds)
- if e != nil {
- err = errors.New("GetIndustrialSubjectDetailByIds" + e.Error())
- return
- }
- for _, v := range SubjectList {
- mapindustrialSubjectName[v.IndustrialSubjectId] = v.SubjectName
- }
- }
- for _, v := range listGroup {
- switch v.TagType {
- case 1:
- label = mapindustrialManagementName[v.TagId]
- case 2:
- label = mapindustrialSubjectName[v.TagId]
- case 3:
- label = mapCelueName[v.TagId]
- }
- item := new(models.WxUserRaiLabel)
- item.UserId = wxUser.UserId
- item.RealName = wxUser.RealName
- item.Mobile = wxUser.Mobile
- item.Email = wxUser.Email
- item.CompanyId = wxUser.CompanyId
- item.CompanyName = wxUser.CompanyName
- item.Label = label
- item.SourceType = sourceType
- item.SourceId = sourceId
- item.CreateTime = log.CreateTime
- item.ModifyTime = time.Now()
- item.RegisterPlatform = log.RegisterPlatform
- item.TableName = ""
- items = append(items, item)
- labelArr = append(labelArr, label)
- }
- }
- e = models.AddWxUserRaiLabelMulti(items, labelArr, userId)
- if e != nil {
- err = errors.New("AddWxUserRaiLabelMulti" + e.Error())
- return
- }
- return
- }
- // 7:产业/个股标签(报告)、8:报告类型标签
- func ArticleWxUserRaiLabelRedisAddReduce(log models.WxUserRaiLabelRedis) (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg("用户文章阅读更新相关标签,处理Redis队列消息失败:"+err.Error()+fmt.Sprint("articleId", log.SourceId, "userId", log.UserId), 2)
- }
- }()
- userId := log.UserId
- sourceId := log.SourceId
- wxUser, e := models.GetWxUserItemByUserId(userId)
- if e != nil {
- err = errors.New("GetWxUserItemByUserId" + e.Error())
- return
- }
- //articleDetail, e := models.GetArticleDetailTestById(sourceId)
- //if e != nil {
- // err = errors.New("GetArticleDetailTestById" + e.Error())
- // return
- //}
- labelArr, sourceType := GetArticlelabelArrByArticleId(sourceId)
- if len(labelArr) == 0 {
- return
- }
- var items []*models.WxUserRaiLabel
- for _, v := range labelArr {
- item := new(models.WxUserRaiLabel)
- item.UserId = wxUser.UserId
- item.RealName = wxUser.RealName
- item.Mobile = wxUser.Mobile
- item.Email = wxUser.Email
- item.CompanyId = wxUser.CompanyId
- item.CompanyName = wxUser.CompanyName
- item.Label = v
- item.SourceType = sourceType
- item.SourceId = sourceId
- item.CreateTime = log.CreateTime
- item.ModifyTime = time.Now()
- item.RegisterPlatform = log.RegisterPlatform
- item.TableName = "cygx_article"
- items = append(items, item)
- //labelArr = append(labelArr, v.IndustryName)
- }
- //articlePermission, e := models.GetArticlePermission(articleDetail.CategoryId)
- //if e != nil {
- // err = errors.New("GetArticlePermission" + e.Error())
- // return
- //}
- //if articlePermission == nil {
- // err = errors.New("报告权限不存在" + e.Error())
- // return
- //}
- //articlePermissionName := articlePermission.PermissionName
- //matchTypeName := articlePermission.MatchTypeName
- //matchTypeNameArr := []string{"季度策略", "科技前沿(周报)", "本周荟", "智造精粹"}
- //
- ////1;四大行业汇总类报告:季度策略、科技前沿(周报)、本周荟、智造精粹以报告类型做标签
- ////2:策略、固收的所有报告,以报告类型做标签
- //if articlePermissionName == utils.CE_LUE_NAME || articlePermissionName == utils.GU_SHOU_NAME || utils.InArrayByStr(matchTypeNameArr, matchTypeName) { // 策略、固收的所有报告,以报告类型做标签
- // if matchTypeName == "季度策略" {
- // matchTypeName = articlePermissionName + matchTypeName //其中季度策略以:xx行业季度策略 呈现
- // }
- // item := new(models.WxUserRaiLabel)
- // item.UserId = wxUser.UserId
- // item.RealName = wxUser.RealName
- // item.Mobile = wxUser.Mobile
- // item.Email = wxUser.Email
- // item.CompanyId = wxUser.CompanyId
- // item.CompanyName = wxUser.CompanyName
- // item.Label = matchTypeName
- // item.SourceType = 8
- // item.SourceId = sourceId
- // item.CreateTime = log.CreateTime
- // item.ModifyTime = time.Now()
- // item.RegisterPlatform = log.RegisterPlatform
- // item.TableName = "cygx_article"
- // err = models.AddWxUserRaiLabel(item)
- // if e != nil {
- // err = errors.New("AddWxUserRaiLabel" + e.Error())
- // return
- // }
- //} else if articlePermissionName == utils.ZHOU_QI_NAME {
- // //周期的行业深度、调研纪要、产业跟踪这些系列的报告用领域做标签,其余的周期报告,都用报告类型(也就是ficc定义的类型)做标签
- // //其中周期的周度观点,以 周期周度观点 呈现
- // matchTypeNameArrZhouqi := []string{"行业深度", "调研纪要", "产业跟踪"}
- // if utils.InArrayByStr(matchTypeNameArrZhouqi, matchTypeName) {
- // matchTypeName = articleDetail.FieldName
- // }
- // item := new(models.WxUserRaiLabel)
- // item.UserId = wxUser.UserId
- // item.RealName = wxUser.RealName
- // item.Mobile = wxUser.Mobile
- // item.Email = wxUser.Email
- // item.CompanyId = wxUser.CompanyId
- // item.CompanyName = wxUser.CompanyName
- // item.Label = matchTypeName
- // item.SourceType = 8
- // item.SourceId = sourceId
- // item.CreateTime = log.CreateTime
- // item.ModifyTime = time.Now()
- // item.RegisterPlatform = log.RegisterPlatform
- // item.TableName = "cygx_article"
- // e = models.AddWxUserRaiLabel(item)
- // if e != nil {
- // err = errors.New("AddWxUserRaiLabel" + e.Error())
- // return
- // }
- //} else {
- // //正常的有产业报告
- // var labelArr []string
- // //建立首页资源表,与产业的关系
- // industrialList, e := models.GetIndustrialArticleGroupManagementListByArticleId(sourceId)
- // if e != nil && e.Error() != utils.ErrNoRow() {
- // err = errors.New("GetIndustrialArticleGroupManagementListByArticleId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
- // return
- // }
- //
- // var items []*models.WxUserRaiLabel
- // for _, v := range industrialList {
- // item := new(models.WxUserRaiLabel)
- // item.UserId = wxUser.UserId
- // item.RealName = wxUser.RealName
- // item.Mobile = wxUser.Mobile
- // item.Email = wxUser.Email
- // item.CompanyId = wxUser.CompanyId
- // item.CompanyName = wxUser.CompanyName
- // item.Label = v.IndustryName
- // item.SourceType = 7
- // item.SourceId = sourceId
- // item.CreateTime = log.CreateTime
- // item.ModifyTime = time.Now()
- // item.RegisterPlatform = log.RegisterPlatform
- // item.TableName = "cygx_article"
- // items = append(items, item)
- // labelArr = append(labelArr, v.IndustryName)
- // }
- //
- // //建立首页资源表,与标的 的关系
- // subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(sourceId)
- // if e != nil && e.Error() != utils.ErrNoRow() {
- // err = errors.New("GetSubjectArticleGroupManagementListByArtcileId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
- // return
- // }
- //
- // for _, v := range subjectList {
- // item := new(models.WxUserRaiLabel)
- // item.UserId = wxUser.UserId
- // item.RealName = wxUser.RealName
- // item.Mobile = wxUser.Mobile
- // item.Email = wxUser.Email
- // item.CompanyId = wxUser.CompanyId
- // item.CompanyName = wxUser.CompanyName
- // item.Label = v.SubjectName
- // item.SourceType = 7
- // item.SourceId = sourceId
- // item.CreateTime = log.CreateTime
- // item.ModifyTime = time.Now()
- // item.RegisterPlatform = log.RegisterPlatform
- // item.TableName = "cygx_article"
- // items = append(items, item)
- // labelArr = append(labelArr, v.SubjectName)
- // }
- // e = models.AddWxUserRaiLabelMulti(items, labelArr, userId)
- // if e != nil {
- // err = errors.New("AddWxUserRaiLabelMulti" + e.Error())
- // return
- // }
- //}
- e = models.AddWxUserRaiLabelMulti(items, labelArr, userId)
- if e != nil {
- err = errors.New("AddWxUserRaiLabelMulti" + e.Error())
- return
- }
- return
- }
- // 8:报告类型标签 (本周研究汇总,与重点公司)
- func ReportSelectionWxUserRaiLabelRedisAddReduce(log models.WxUserRaiLabelRedis) (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg("报告类型标签 (本周研究汇总,与重点公司),处理Redis队列消息失败:ReportSelectionWxUserRaiLabelRedisAddReduce"+err.Error()+fmt.Sprint("SourceId", log.SourceId, "userId", log.UserId), 2)
- }
- }()
- userId := log.UserId
- sourceId := log.SourceId
- wxUser, e := models.GetWxUserItemByUserId(userId)
- if e != nil {
- err = errors.New("GetWxUserItemByUserId" + e.Error())
- return
- }
- item := new(models.WxUserRaiLabel)
- item.UserId = wxUser.UserId
- item.RealName = wxUser.RealName
- item.Mobile = wxUser.Mobile
- item.Email = wxUser.Email
- item.CompanyId = wxUser.CompanyId
- item.CompanyName = wxUser.CompanyName
- item.Label = log.Label
- item.SourceType = 8
- item.SourceId = sourceId
- item.CreateTime = log.CreateTime
- item.ModifyTime = time.Now()
- item.RegisterPlatform = log.RegisterPlatform
- item.TableName = log.TableName
- err = models.AddWxUserRaiLabel(item)
- if e != nil {
- err = errors.New("AddWxUserRaiLabel" + e.Error())
- return
- }
- return
- }
- //func init() {
- // GetArticlelabelArrByArticleId(11796)
- //}
- func GetArticlelabelArrByArticleId(articleId int) (labelArr []string, sourceType int) {
- articleDetail, e := models.GetArticleDetailTestById(articleId)
- if e != nil {
- fmt.Println(e)
- return
- }
- if articleDetail.ArticleTypeId > 0 {
- //正常的有产业报告
- //建立首页资源表,与产业的关系
- industrialList, e := models.GetIndustrialArticleGroupManagementListByArticleId(articleId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- fmt.Println(e)
- return
- }
- for _, v := range industrialList {
- labelArr = append(labelArr, v.IndustryName)
- }
- //建立首页资源表,与标的 的关系
- subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(articleId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- fmt.Println(e)
- return
- }
- for _, v := range subjectList {
- labelArr = append(labelArr, v.SubjectName)
- }
- sourceType = 7
- return
- }
- articlePermission, e := models.GetArticlePermission(articleDetail.CategoryId)
- if e != nil {
- fmt.Println(e)
- return
- }
- if articlePermission == nil {
- fmt.Println(e)
- return
- }
- articlePermissionName := articlePermission.PermissionName
- subCategoryName := articleDetail.SubCategoryName
- matchTypeNameArr := []string{"季度策略", "科技前沿(周报)", "本周荟", "智造精粹"}
- //1;四大行业汇总类报告:季度策略、科技前沿(周报)、本周荟、智造精粹以报告类型做标签
- //2:策略、固收的所有报告,以报告类型做标签
- //var labelArr []string
- if articlePermissionName == utils.CE_LUE_NAME || articlePermissionName == utils.GU_SHOU_NAME || utils.InArrayByStr(matchTypeNameArr, subCategoryName) { // 策略、固收的所有报告,以报告类型做标签
- if subCategoryName == "季度策略" {
- subCategoryName = articlePermissionName + subCategoryName //其中季度策略以:xx行业季度策略 呈现
- }
- labelArr = append(labelArr, subCategoryName)
- sourceType = 8
- } else if articlePermissionName == utils.ZHOU_QI_NAME {
- //周期的行业深度、调研纪要、产业跟踪这些系列的报告用领域做标签,其余的周期报告,都用报告类型(也就是ficc定义的类型)做标签
- //其中周期的周度观点,以 周期周度观点 呈现
- matchTypeNameArrZhouqi := []string{"行业深度", "调研纪要", "产业跟踪"}
- if utils.InArrayByStr(matchTypeNameArrZhouqi, subCategoryName) {
- subCategoryName = articleDetail.FieldName
- }
- labelArr = append(labelArr, subCategoryName)
- sourceType = 8
- } else {
- //正常的有产业报告
- //建立首页资源表,与产业的关系
- industrialList, e := models.GetIndustrialArticleGroupManagementListByArticleId(articleId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- fmt.Println(e)
- return
- }
- for _, v := range industrialList {
- labelArr = append(labelArr, v.IndustryName)
- }
- //建立首页资源表,与标的 的关系
- subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(articleId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- fmt.Println(e)
- return
- }
- for _, v := range subjectList {
- labelArr = append(labelArr, v.SubjectName)
- }
- sourceType = 7
- }
- return
- }
- //func init() {
- // //fmt.Println(GetArticlelabelArrByArticleId(11037))
- // //initCrm16_5Article2()
- //}
- func initCrm16_5keyWord() {
- listKeyWords, err := models.GetSearchKeyWordinitCrm16_5()
- if err != nil {
- fmt.Println(err)
- return
- }
- var mobiles []string
- mapMobile := make(map[string]bool)
- for _, v := range listKeyWords {
- if mapMobile[v.Mobile] || v.Mobile == "" {
- continue
- }
- mapMobile[v.Mobile] = true
- mobiles = append(mobiles, v.Mobile)
- }
- listUser, err := models.GetWxUserListByMobileArr(mobiles)
- if err != nil {
- fmt.Println(err)
- return
- }
- mapUser := make(map[string]*models.WxUserItem)
- for _, v := range listUser {
- mapUser[v.Mobile] = v
- }
- var items []*models.WxUserRaiLabelLog
- for _, v := range listKeyWords {
- if mapUser[v.Mobile] == nil || v.Mobile == "" {
- continue
- }
- wxUser := mapUser[v.Mobile]
- item := new(models.WxUserRaiLabelLog)
- item.UserId = wxUser.UserId
- item.RealName = wxUser.RealName
- item.Mobile = wxUser.Mobile
- item.Email = wxUser.Email
- item.CompanyId = wxUser.CompanyId
- item.CompanyName = wxUser.CompanyName
- item.Label = v.KeyWord
- item.SourceType = 1
- item.CreateTime = v.CreateTime
- item.ModifyTime = time.Now()
- item.RegisterPlatform = v.RegisterPlatform
- items = append(items, item)
- }
- fmt.Println(len(items))
- var itemsAdd []*models.WxUserRaiLabelLog
- if len(items) > 0 {
- for _, v := range items {
- itemsAdd = append(itemsAdd, v)
- if len(items)%2000 == 0 {
- err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
- if err != nil {
- return
- }
- itemsAdd = make([]*models.WxUserRaiLabelLog, 0)
- }
- }
- }
- if len(itemsAdd) > 0 {
- err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
- if err != nil {
- return
- }
- }
- fmt.Println("endAddWxUserRaiLabelLogMultiInit")
- }
- func initCrm16_5Activity() {
- var condition string
- var pars []interface{}
- condition += ` AND create_time > '2024-09-01' AND (is_meeting =1 OR duration != '') `
- pars = append(pars)
- //获取提交到会的人员信息
- signUpDetailList, err := models.GetSignupDetailList(condition, pars)
- if err != nil {
- fmt.Println(err)
- return
- }
- var mobiles []string
- mapMobile := make(map[string]bool)
- for _, v := range signUpDetailList {
- if mapMobile[v.Mobile] || v.Mobile == "" {
- continue
- }
- mapMobile[v.Mobile] = true
- mobiles = append(mobiles, v.Mobile)
- }
- var activityIds []int
- mapactivityId := make(map[int]bool)
- for _, v := range signUpDetailList {
- if mapactivityId[v.ActivityId] {
- continue
- }
- mapactivityId[v.ActivityId] = true
- activityIds = append(activityIds, v.ActivityId)
- }
- listUser, err := models.GetWxUserListByMobileArr(mobiles)
- if err != nil {
- fmt.Println(err)
- return
- }
- mapUser := make(map[string]*models.WxUserItem)
- for _, v := range listUser {
- mapUser[v.Mobile] = v
- }
- activityDetailList, e := models.GetAddActivityDetailByActivityIdinitCrm16_5(activityIds)
- if e != nil {
- fmt.Println(e)
- return
- }
- sourceTypemap := make(map[int]int)
- mapLabel := make(map[int]string)
- for _, v := range activityDetailList {
- if v.ActivityType == 1 {
- sourceTypemap[v.ActivityId] = 4
- } else {
- sourceTypemap[v.ActivityId] = 2
- }
- mapLabel[v.ActivityId] = v.Label
- }
- //正常的有产业报告
- //建立首页资源表,与产业的关系
- industrialList, e := models.GetIndustrialActivityGroupManagementListByArticleIds(activityIds)
- if e != nil && e.Error() != utils.ErrNoRow() {
- fmt.Println(e)
- return
- }
- //建立首页资源表,与标的 的关系
- subjectList, e := models.GetSubjectActivityGroupManagementListByActivityIds(activityIds)
- if e != nil && e.Error() != utils.ErrNoRow() {
- fmt.Println(e)
- return
- }
- var items []*models.WxUserRaiLabelLog
- for _, v := range signUpDetailList {
- if mapUser[v.Mobile] == nil || v.Mobile == "" {
- continue
- }
- var haseName bool
- wxUser := mapUser[v.Mobile]
- for _, vI := range industrialList {
- if vI.ActivityId != v.ActivityId {
- continue
- }
- haseName = true
- item := new(models.WxUserRaiLabelLog)
- item.UserId = wxUser.UserId
- item.RealName = wxUser.RealName
- item.Mobile = wxUser.Mobile
- item.Email = wxUser.Email
- item.CompanyId = wxUser.CompanyId
- item.CompanyName = wxUser.CompanyName
- item.Label = vI.IndustryName
- item.SourceType = sourceTypemap[v.ActivityId]
- item.SourceId = v.ActivityId
- item.CreateTime = v.CreateTime
- item.ModifyTime = time.Now()
- item.TableName = ""
- //item.RegisterPlatform = v.RegisterPlatform
- items = append(items, item)
- }
- for _, vs := range subjectList {
- if vs.ActivityId != v.ActivityId {
- continue
- }
- haseName = true
- item := new(models.WxUserRaiLabelLog)
- item.UserId = wxUser.UserId
- item.RealName = wxUser.RealName
- item.Mobile = wxUser.Mobile
- item.Email = wxUser.Email
- item.CompanyId = wxUser.CompanyId
- item.CompanyName = wxUser.CompanyName
- item.Label = vs.SubjectName
- item.SourceType = sourceTypemap[v.ActivityId]
- item.SourceId = v.ActivityId
- item.CreateTime = v.CreateTime
- item.ModifyTime = time.Now()
- //item.RegisterPlatform = v.RegisterPlatform
- items = append(items, item)
- }
- //如果两个标签都没有,就添加临时标签
- if !haseName {
- item := new(models.WxUserRaiLabelLog)
- item.UserId = wxUser.UserId
- item.RealName = wxUser.RealName
- item.Mobile = wxUser.Mobile
- item.Email = wxUser.Email
- item.CompanyId = wxUser.CompanyId
- item.CompanyName = wxUser.CompanyName
- item.Label = mapLabel[v.ActivityId]
- item.SourceType = sourceTypemap[v.ActivityId]
- item.SourceId = v.ActivityId
- item.CreateTime = v.CreateTime
- item.ModifyTime = time.Now()
- //item.RegisterPlatform = v.RegisterPlatform
- item.TableName = ""
- items = append(items, item)
- }
- }
- //fmt.Println("initCrm16_5Activity", len(items))
- //return
- var itemsAdd []*models.WxUserRaiLabelLog
- if len(items) > 0 {
- for _, v := range items {
- itemsAdd = append(itemsAdd, v)
- if len(itemsAdd)%2000 == 0 {
- err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
- if err != nil {
- return
- }
- itemsAdd = make([]*models.WxUserRaiLabelLog, 0)
- }
- }
- }
- if len(itemsAdd) > 0 {
- err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
- if err != nil {
- return
- }
- }
- fmt.Println("endAddWxUserRaiLabelLogMultiInit")
- }
- func initCrm16_5Article() {
- var condition string
- var pars []interface{}
- condition += ` `
- pars = append(pars)
- listArticleIds, err := models.GetCygxArticleHistoryRecordAllListArticleIdCrm16_5()
- if err != nil {
- fmt.Println(err)
- return
- }
- fmt.Println("listArticleIds", len(listArticleIds))
- listHave, err := models.GetWxUserRaiArticleLabelCrm16_5()
- if err != nil {
- fmt.Println(err)
- return
- }
- mapArticleId := make(map[int]bool)
- for _, v := range listHave {
- mapArticleId[v.ArticleId] = true
- }
- for k, v := range listArticleIds {
- fmt.Println(k)
- labelArr, sourceType := GetArticlelabelArrByArticleId(v.ArticleId)
- if len(labelArr) == 0 {
- continue
- }
- var items []*models.WxUserRaiArticleLabel
- for _, v2 := range labelArr {
- item := new(models.WxUserRaiArticleLabel)
- item.ArticleId = v.ArticleId
- item.Label = v2
- item.SourceType = sourceType
- item.CreateTime = time.Now()
- items = append(items, item)
- }
- err = models.AddWxUserRaiArticleLabelMultiInit(items)
- time.Sleep(time.Millisecond * 100)
- fmt.Println(err)
- }
- }
- func initCrm16_5Article2() {
- var condition string
- var pars []interface{}
- condition += ` `
- pars = append(pars)
- //获取提交到会的人员信息
- listArticleIds, err := models.GetCygxArticleHistoryRecordAllListUserIdCrm16_5()
- if err != nil {
- fmt.Println(err)
- return
- }
- fmt.Println("listArticleIds", len(listArticleIds))
- mapUserId := make(map[string]bool)
- var mobiles []string
- for _, v := range listArticleIds {
- if mapUserId[v.Mobile] {
- continue
- }
- mobiles = append(mobiles, v.Mobile)
- mapUserId[v.Mobile] = true
- }
- listUser, err := models.GetWxUserListByMobileArr(mobiles)
- if err != nil {
- fmt.Println(err)
- return
- }
- mapUser := make(map[string]*models.WxUserItem)
- for _, v := range listUser {
- mapUser[v.Mobile] = v
- }
- listArticleLabel, err := models.GetWxUserRaiArticleLabelAllCrm16_5()
- if err != nil {
- fmt.Println(err)
- return
- }
- mapArticleLabel := make(map[int][]string)
- mapArticleType := make(map[int]int)
- for _, v := range listArticleLabel {
- mapArticleLabel[v.ArticleId] = append(mapArticleLabel[v.ArticleId], v.Label)
- mapArticleType[v.ArticleId] = v.SourceType
- }
- var items []*models.WxUserRaiLabelLog
- for _, v := range listArticleIds {
- if mapUser[v.Mobile] == nil || v.Mobile == "" {
- continue
- }
- if len(mapArticleLabel[v.ArticleId]) == 0 {
- continue
- }
- wxUser := mapUser[v.Mobile]
- for _, vI := range mapArticleLabel[v.ArticleId] {
- item := new(models.WxUserRaiLabelLog)
- item.UserId = wxUser.UserId
- item.RealName = wxUser.RealName
- item.Mobile = wxUser.Mobile
- item.Email = wxUser.Email
- item.CompanyId = wxUser.CompanyId
- item.CompanyName = wxUser.CompanyName
- item.Label = vI
- item.SourceType = mapArticleType[v.ArticleId]
- item.SourceId = v.ArticleId
- item.CreateTime = utils.StrTimeToTime(v.CreateTime)
- item.ModifyTime = time.Now()
- item.TableName = "cygx_article"
- //item.RegisterPlatform = v.RegisterPlatform
- items = append(items, item)
- }
- }
- fmt.Println("items", len(items))
- var itemsAdd []*models.WxUserRaiLabelLog
- if len(items) > 0 {
- for _, v := range items {
- itemsAdd = append(itemsAdd, v)
- if len(itemsAdd)%2000 == 0 {
- err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
- if err != nil {
- fmt.Println(err)
- return
- }
- itemsAdd = make([]*models.WxUserRaiLabelLog, 0)
- }
- }
- }
- if len(itemsAdd) > 0 {
- err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
- if err != nil {
- fmt.Println(err)
- return
- }
- }
- fmt.Println("endAddWxUserRaiLabelLogMultiInit")
- }
- ////func init() {
- // //initCrm16_5keyWord()
- // //initCrm16_5Activity()
- // //initCrm16_5Article2()
- // //initCrm16_5ReportHistory()
- // //initCrm16_5ReportHistory_2()
- // //initCrm16_5Roadshow()
- //
- // fmt.Println("end RO")
- //
- // initCrm16_5wx_user_rai_label()
- //
- // fmt.Println("end RO2")
- //}
- // 记录用户在重点公司单独点了某一个标签
- func initCrm16_5ReportHistory_0() {
- var err error
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("SendCygxReportSelectionLogApplyTemplateMsg Err"+err.Error(), 2)
- }
- }()
- var condition string
- var pars []interface{}
- listhistory, err := models.GetCygxReportSelectionSubjectHistory()
- if err != nil {
- fmt.Println(err)
- return
- }
- for kH, vH := range listhistory {
- fmt.Println(kH)
- pars = make([]interface{}, 0)
- condition = ` AND article_id = ? AND industrial_subject_id = ? AND industrial_management_id = ? AND third_id = ? `
- pars = append(pars, vH.ArticleId, vH.IndustrialSubjectId, vH.IndustrialManagementId, vH.ThirdId)
- listLog, e := models.GetCygxReportSelectionLog(condition, pars, 0, 9999)
- if e != nil {
- err = errors.New("GetCygxReportSelectionLog, Err: " + e.Error())
- fmt.Println(err)
- return
- }
- var labelName string
- for _, v2 := range listLog {
- if v2.ThirdId > 0 {
- labelName = v2.ThirdName
- } else if v2.IndustrialSubjectId == 0 && v2.IndustrialManagementId != "" {
- labelName = v2.IndustrialManagementNames
- } else {
- labelName = v2.SubjectName
- }
- }
- err = models.UpdateCygxReportSelectionSubjectHistoryName(labelName, vH.Id)
- if err != nil {
- fmt.Println(err)
- return
- }
- }
- fmt.Println("end")
- return
- }
- func initCrm16_5ReportHistory() {
- listReportHistory, err := models.GetWxUserRaiCygxReportHistoryRecordCrm16_5()
- if err != nil {
- fmt.Println(err)
- return
- }
- var mobiles []string
- mapMobile := make(map[string]bool)
- for _, v := range listReportHistory {
- if mapMobile[v.Mobile] || v.Mobile == "" {
- continue
- }
- mapMobile[v.Mobile] = true
- mobiles = append(mobiles, v.Mobile)
- }
- listUser, err := models.GetWxUserListByMobileArr(mobiles)
- if err != nil {
- fmt.Println(err)
- return
- }
- mapUser := make(map[string]*models.WxUserItem)
- for _, v := range listUser {
- mapUser[v.Mobile] = v
- }
- var items []*models.WxUserRaiLabelLog
- for _, v := range listReportHistory {
- if mapUser[v.Mobile] == nil || v.Mobile == "" {
- continue
- }
- wxUser := mapUser[v.Mobile]
- item := new(models.WxUserRaiLabelLog)
- item.UserId = wxUser.UserId
- item.RealName = wxUser.RealName
- item.Mobile = wxUser.Mobile
- item.Email = wxUser.Email
- item.CompanyId = wxUser.CompanyId
- item.CompanyName = wxUser.CompanyName
- if v.ReportType == "bgjx" {
- item.Label = "重点推荐"
- item.TableName = "cygx_report_selection"
- } else {
- item.Label = "本周研究汇总"
- item.TableName = "cygx_research_summary"
- }
- item.SourceId = v.ArticleId
- item.SourceType = 8
- item.CreateTime = v.CreateTime
- item.ModifyTime = time.Now()
- item.RegisterPlatform = v.RegisterPlatform
- items = append(items, item)
- }
- fmt.Println("items", len(items))
- var itemsAdd []*models.WxUserRaiLabelLog
- if len(items) > 0 {
- for _, v := range items {
- itemsAdd = append(itemsAdd, v)
- if len(items)%2000 == 0 {
- err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
- if err != nil {
- return
- }
- itemsAdd = make([]*models.WxUserRaiLabelLog, 0)
- }
- }
- }
- if len(itemsAdd) > 0 {
- err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
- if err != nil {
- return
- }
- }
- fmt.Println("endAddWxUserRaiLabelLogMultiInit")
- }
- func initCrm16_5ReportHistory_2() {
- listReportHistory, err := models.GetCygxReportSelectionSubjectHistory()
- if err != nil {
- fmt.Println(err)
- return
- }
- var mobiles []string
- mapMobile := make(map[string]bool)
- for _, v := range listReportHistory {
- if mapMobile[v.Mobile] || v.Mobile == "" {
- continue
- }
- mapMobile[v.Mobile] = true
- mobiles = append(mobiles, v.Mobile)
- }
- listUser, err := models.GetWxUserListByMobileArr(mobiles)
- if err != nil {
- fmt.Println(err)
- return
- }
- mapUser := make(map[string]*models.WxUserItem)
- for _, v := range listUser {
- mapUser[v.Mobile] = v
- }
- var items []*models.WxUserRaiLabelLog
- for _, v := range listReportHistory {
- if mapUser[v.Mobile] == nil || v.Mobile == "" || v.LableName == "" {
- continue
- }
- wxUser := mapUser[v.Mobile]
- item := new(models.WxUserRaiLabelLog)
- item.UserId = wxUser.UserId
- item.RealName = wxUser.RealName
- item.Mobile = wxUser.Mobile
- item.Email = wxUser.Email
- item.CompanyId = wxUser.CompanyId
- item.CompanyName = wxUser.CompanyName
- item.Label = v.LableName
- item.SourceType = 8
- item.CreateTime = v.CreateTime
- item.ModifyTime = time.Now()
- item.RegisterPlatform = v.RegisterPlatform
- items = append(items, item)
- }
- fmt.Println("items", len(items))
- var itemsAdd []*models.WxUserRaiLabelLog
- if len(items) > 0 {
- for _, v := range items {
- itemsAdd = append(itemsAdd, v)
- if len(items)%2000 == 0 {
- err = models.AddWxUserRaiLabelLogMultiInit(items)
- if err != nil {
- return
- }
- itemsAdd = make([]*models.WxUserRaiLabelLog, 0)
- }
- }
- }
- if len(itemsAdd) > 0 {
- err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
- if err != nil {
- return
- }
- }
- fmt.Println("endAddWxUserRaiLabelLogMultiInit")
- }
- func initCrm16_5Roadshow() {
- var condition string
- var pars []interface{}
- condition = " "
- calendarMeetingUserList, e := roadshow.GetRsCalendarMeetingUserList(condition+" ORDER BY rs.start_date ASC ", pars)
- if e != nil {
- fmt.Println(e)
- return
- }
- var rsCalendarIds []int
- for _, v := range calendarMeetingUserList {
- rsCalendarIds = append(rsCalendarIds, v.RsCalendarId)
- }
- var mobiles []string
- mapMobile := make(map[string]bool)
- for _, v := range calendarMeetingUserList {
- if mapMobile[v.Mobile] || v.Mobile == "" {
- continue
- }
- mapMobile[v.Mobile] = true
- mobiles = append(mobiles, v.Mobile)
- }
- RsCalendarListInit, e := roadshow.GetRsCalendarListInit(rsCalendarIds)
- if e != nil {
- fmt.Println(e)
- return
- }
- mapRoadshowType := make(map[int]int)
- for _, v := range RsCalendarListInit {
- if v.RoadshowType == "线下" {
- mapRoadshowType[v.RsCalendarId] = 3
- } else {
- mapRoadshowType[v.RsCalendarId] = 5
- }
- }
- listUser, err := models.GetWxUserListByMobileArr(mobiles)
- if err != nil {
- fmt.Println(err)
- return
- }
- mapUser := make(map[string]*models.WxUserItem)
- for _, v := range listUser {
- mapUser[v.Mobile] = v
- }
- var items []*models.WxUserRaiLabelLog
- for _, v := range calendarMeetingUserList {
- if mapUser[v.Mobile] == nil || v.Mobile == "" {
- continue
- }
- wxUser := mapUser[v.Mobile]
- var sourceType int
- sourceType = mapRoadshowType[v.RsCalendarId]
- totalGroup, e := roadshow.GetRsCalendarMeetingLabelGroupByRsCalendarId(v.RsCalendarId)
- if e != nil {
- err = errors.New("GetRsCalendarMeetingLabelGroupByRsCalendarId" + e.Error())
- return
- }
- //var lebelDetail []*cygx.RaiServeTagResp
- var label string
- var labelArr []string
- if totalGroup > 0 {
- listGroup, e := roadshow.GetRsCalendarMeetingLabelGroupListByRsCalendarId(v.RsCalendarId)
- if e != nil {
- err = errors.New("GetRsCalendarMeetingLabelGroupByRsCalendarId" + e.Error())
- return
- }
- var industrialManagementIds []int
- var industrialSubjectIds []int
- mapindustrialManagementName := make(map[int]string)
- mapindustrialSubjectName := make(map[int]string)
- mapCelueName := make(map[int]string)
- for _, vG := range listGroup {
- switch vG.TagType {
- case 1:
- industrialManagementIds = append(industrialManagementIds, vG.TagId)
- case 2:
- industrialSubjectIds = append(industrialSubjectIds, vG.TagId)
- case 3:
- mapCelueName[vG.TagId] = "策略"
- }
- }
- if len(industrialManagementIds) > 0 {
- IndustryList, e := models.GetIndustryListByConditionByIds(industrialManagementIds)
- if e != nil {
- err = errors.New("GetRsCalendarMeetingLabelGroupByRsCalendarId" + e.Error())
- return
- }
- for _, vI := range IndustryList {
- mapindustrialManagementName[vI.IndustrialManagementId] = vI.IndustryName
- }
- }
- if len(industrialSubjectIds) > 0 {
- SubjectList, e := models.GetIndustrialSubjectDetailByIds(industrialSubjectIds)
- if e != nil {
- err = errors.New("GetIndustrialSubjectDetailByIds" + e.Error())
- return
- }
- for _, vS := range SubjectList {
- mapindustrialSubjectName[vS.IndustrialSubjectId] = vS.SubjectName
- }
- }
- for _, vG := range listGroup {
- switch vG.TagType {
- case 1:
- label = mapindustrialManagementName[vG.TagId]
- case 2:
- label = mapindustrialSubjectName[vG.TagId]
- case 3:
- label = mapCelueName[vG.TagId]
- }
- item := new(models.WxUserRaiLabelLog)
- item.UserId = wxUser.UserId
- item.RealName = wxUser.RealName
- item.Mobile = wxUser.Mobile
- item.Email = wxUser.Email
- item.CompanyId = wxUser.CompanyId
- item.CompanyName = wxUser.CompanyName
- item.Label = label
- item.SourceType = sourceType
- item.SourceId = v.RsCalendarId
- item.CreateTime = v.CreateTime
- item.ModifyTime = time.Now()
- //item.RegisterPlatform = log.RegisterPlatform
- item.TableName = ""
- items = append(items, item)
- labelArr = append(labelArr, label)
- }
- }
- }
- fmt.Println("items", len(items))
- var itemsAdd []*models.WxUserRaiLabelLog
- if len(items) > 0 {
- for _, v := range items {
- itemsAdd = append(itemsAdd, v)
- if len(items)%2000 == 0 {
- err = models.AddWxUserRaiLabelLogMultiInit(items)
- if err != nil {
- return
- }
- itemsAdd = make([]*models.WxUserRaiLabelLog, 0)
- }
- }
- }
- if len(itemsAdd) > 0 {
- err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
- if err != nil {
- return
- }
- }
- fmt.Println("endAddWxUserRaiLabelLogMultiInit")
- }
- func initCrm16_5wx_user_rai_label() {
- listAll, err := models.GetWxUserRaiLabelLogAll()
- if err != nil {
- fmt.Println(err)
- return
- }
- mapMobileLabel := make(map[string]bool)
- var items []*models.WxUserRaiLabel
- for _, v := range listAll {
- if mapMobileLabel[fmt.Sprint(v.Mobile, "__", v.Label)] {
- continue
- }
- item := new(models.WxUserRaiLabel)
- item.UserId = v.UserId
- item.RealName = v.RealName
- item.Mobile = v.Mobile
- item.Email = v.Email
- item.CompanyId = v.CompanyId
- item.CompanyName = v.CompanyName
- item.Label = v.Label
- item.SourceId = v.SourceId
- item.SourceType = v.SourceType
- item.CreateTime = v.CreateTime
- item.ModifyTime = v.ModifyTime
- item.RegisterPlatform = v.RegisterPlatform
- item.TableName = v.TableName
- items = append(items, item)
- mapMobileLabel[fmt.Sprint(v.Mobile, "__", v.Label)] = true
- }
- var itemsAdd []*models.WxUserRaiLabel
- if len(items) > 0 {
- for _, v := range items {
- itemsAdd = append(itemsAdd, v)
- if len(items)%2000 == 0 {
- err = models.AddWxUserRaiLabelMultiInit(items)
- if err != nil {
- return
- }
- itemsAdd = make([]*models.WxUserRaiLabel, 0)
- }
- }
- }
- if len(itemsAdd) > 0 {
- err = models.AddWxUserRaiLabelMultiInit(itemsAdd)
- if err != nil {
- return
- }
- }
- fmt.Println("endAddWxUserRaiLabelLogMultiInit")
- }
|