package cygx import ( "github.com/beego/beego/v2/client/orm" "hongze/hz_crm_api/utils" "time" ) type WxUserRaiLabel struct { RaiLabelId int `orm:"column(rai_label_id);pk"` UserId int `description:"用户ID"` RealName string `description:"用户实际名称"` Mobile string `description:"手机号"` Email string `description:"邮箱"` CompanyId int `description:"公司id"` CompanyName string `description:"公司名称"` Label string `description:"标签内容"` SourceId int `description:"来源ID"` SourceType int `description:"来源1:搜索关键字标签、2:产业/个股标签(线下活动)、3:产业/个股标签(线下路演)、4:产业/个股标签(线上活动)、5:产业/个股标签(线上路演)、6:销售输入标签、7:产业/个股标签(报告)、8:报告类型标签"` SysUserId int `description:"创建人id"` SysUserRealName string `description:"创建人名称"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` TableName string `description:"数据来源的表名"` } type WxUserRaiLabelList struct { List []*WxUserRaiLabelListResp } type WxUserRaiLabelListResp struct { UserId int `description:"用户ID"` RaiLabelId int `description:"ID"` Label string `description:"标签内容"` SourceType int `description:"来源1:搜索关键字标签、2:产业/个股标签(线下活动)、3:产业/个股标签(线下路演)、4:产业/个股标签(线上活动)、5:产业/个股标签(线上路演)、6:销售输入标签、7:产业/个股标签(报告)、8:报告类型标签"` } type WxUserRaiLabelAddReq struct { UserId int `description:"用户ID"` Label string `description:"标签内容"` } type WxUserRaiLabelIdReq struct { RaiLabelId int `description:"ID"` } // 添加 func AddWxUserRaiLabel(item *WxUserRaiLabel) (err error) { o := orm.NewOrmUsingDB("hz_cygx") _, err = o.Insert(item) return } // DeleteWxUserRaiLabel 根据主键ID删除数据 func DeleteWxUserRaiLabel(raiLabelId int) (err error) { o := orm.NewOrmUsingDB("hz_cygx") sql := ` DELETE FROM wx_user_rai_label WHERE rai_label_id = ? ` _, err = o.Raw(sql, raiLabelId).Exec() return } // GetWxUserRaiLabelListByUserIds 根据多个userId 获取每个UserId最新的十条数据 func GetWxUserRaiLabelListByUserIds(userIdArr []int) (list []*WxUserRaiLabelListResp, err error) { lenArr := len(userIdArr) if lenArr == 0 { return } o := orm.NewOrmUsingDB("hz_cygx") sql := `SELECT t.rai_label_id, t.user_id, t.label, t.source_type FROM ( SELECT rai_label_id, user_id, label, source_type, create_time, @row_number := IF ( @prev_user_id = user_id, @row_number + 1, 1 ) AS rank, @prev_user_id := user_id FROM wx_user_rai_label, ( SELECT @row_number := 0, @prev_user_id := NULL ) AS vars WHERE user_id IN ( ` + utils.GetOrmInReplace(lenArr) + ` ) ORDER BY create_time DESC ) AS t WHERE t.rank <= 10 ORDER BY t.create_time DESC ` _, err = o.Raw(sql, userIdArr).QueryRows(&list) return } // GetWxUserRaiLabelListByUserId 根据用户ID,获取最近四个月的数据信息 func GetWxUserRaiLabelListByUserId(userId int) (list []*WxUserRaiLabelListResp, err error) { o := orm.NewOrmUsingDB("hz_cygx") sql := `SELECT rai_label_id, user_id, label, source_type FROM wx_user_rai_label WHERE user_id = ? AND create_time >= ? ORDER BY create_time DESC LIMIT 1000 ` _, err = o.Raw(sql, userId, time.Now().AddDate(0, -4, 0).Format(utils.FormatDate)).QueryRows(&list) return } // 通过纪要ID获取详情 func GetWxUserRaiLabelDetailById(raiLabelId int) (item *WxUserRaiLabel, err error) { o := orm.NewOrmUsingDB("hz_cygx") sql := `SELECT * FROM wx_user_rai_label WHERE rai_label_id =? ` err = o.Raw(sql, raiLabelId).QueryRow(&item) return } type WxUserRaiLabelDetailResp struct { SourceType int `description:"来源1:搜索关键字标签、2:产业/个股标签(线下活动)、3:产业/个股标签(线下路演)、4:产业/个股标签(线上活动)、5:产业/个股标签(线上路演)、6:销售输入标签、7:产业/个股标签(报告)、8:报告类型标签"` KeyWord *WxUserRaiLabelKeyWordResp Activity *WxUserRaiLabelActivityResp RoadShow *WxUserRaiLabelRoadShowResp Seller *WxUserRaiLabelSellerResp Article *WxUserRaiLabelArticleResp } type WxUserRaiLabelKeyWordResp struct { Label string `description:"标签内容"` CreateTime string `description:"创建时间"` } type WxUserRaiLabelActivityResp struct { ActivityName string `description:"活动名称"` ActivityTypeName string `description:"活动类型名称"` ActivityTime string `description:"活动时间"` Duration string `description:"参会时长"` Label string `description:"标签内容"` } type WxUserRaiLabelRoadShowResp struct { Theme string `description:"会议主题"` ResearcherName string `description:"研究员名称"` RoadShowTime string `description:"开始时间"` Label string `description:"标签内容"` } type WxUserRaiLabelSellerResp struct { Label string `description:"标签内容"` SysUserRealName string `description:"创建人名称"` CreateTime string `description:"创建时间"` } type WxUserRaiLabelArticleResp struct { Title string `description:"标题"` PublishDate string `description:"发布时间"` CreateTime string `description:"创建时间"` SourceText string `description:"阅读来源"` StopTime string `description:"阅读停留时间"` Label string `description:"标签内容"` } type WxUserRaiLabelRedis struct { UserId int `description:"用户ID"` SourceId int `description:"资源ID"` Label string `description:"标签内容"` SourceType int `description:"来源1:搜索关键字标签、2:产业/个股标签(线下活动)、3:产业/个股标签(线下路演)、4:产业/个股标签(线上活动)、5:产业/个股标签(线上路演)、6:销售输入标签、7:产业/个股标签(报告)、8:报告类型标签"` CreateTime time.Time `description:"创建时间"` RegisterPlatform int `description:"来源 1小程序,2:网页"` TableName string `description:"数据来源的表名"` }