1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- 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:"更新时间"`
- }
- 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
- user_id DESC
- ) AS t
- WHERE
- t.rank <= 10
- ORDER BY
- t.create_time DESC `
- _, err = o.Raw(sql, userIdArr).QueryRows(&list)
- return
- }
|