1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018 |
- package p
- import (
- "encoding/json"
- "sort"
- "strings"
- util "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/logger"
- . "app.yhyue.com/moapp/jybase/mongodb"
- . "app.yhyue.com/moapp/jybase/mysql"
- "bp.jydev.jianyu360.cn/BaseService/pushpkg/dfa"
- )
- type MgoConf struct {
- Address string
- Size int
- DbName string
- ReplSet string
- UserName string
- Password string
- Collection string
- ExperienceDbName string
- }
- type RedisConf struct {
- Address string
- }
- type MysqlConf struct {
- DbName string
- Address string
- UserName string
- PassWord string
- MaxOpenConns int
- MaxIdleConns int
- }
- type EsConf struct {
- Address string
- Size int
- Version string
- UserName string
- Password string
- }
- type MemberService struct {
- IsBuy bool
- Services map[int]*memberService
- }
- type memberService struct {
- Id int
- StartTime string
- }
- // 关键词
- type KeySet struct {
- Item string `json:"item"` //分类名称
- Keys []string `json:"key"` //关键词
- NotKeys []string `json:"notkey"` //排除词
- SubTypes []string `json:"infotype"` //信息类型
- Areas []string `json:"area"` //地区
- AppendKeys []string `json:"appendkey"` //附加词
- MatchWay int `json:"matchway"` //匹配模式 0:精准匹配 1:模糊匹配
- }
- // 解析订阅词
- type SubSet struct {
- Matchbuyerclass_other int //是否开启其他按钮
- ProjectMatch int //项目关联推送
- Items []string //关键词分类
- Keys []string //过滤后的关键词
- Notkeys []string //排除词
- Key_item map[string]string //关键词对应的分类名称
- Key_notkey map[string]map[string]bool //关键词所对应的排除词
- Key_area map[string]map[string]bool //关键词所对应的信息范围
- Key_subtype map[string]map[string]bool //关键词所对应的信息类型
- OriginalKeys []string //原始关键词
- Areas []string //区域-省份
- Area map[string]interface{} //区域-省份
- District map[string]interface{} //区域-区县
- Subtype []interface{} //信息类型-二级分类
- Subtypes []string //信息类型-二级分类
- Buyerclass []interface{} //采购单位行业
- Buyerclasss []string //采购单位行业
- IsUpgrade bool //免费用户是否订阅升级
- MaxPushSize int //推送最大条数
- MaxMailSize int //邮件最大条数
- Switch int //开关
- MatchMode []string //匹配方式 title detail filetext projectname/purchasing
- Amount string //金额
- StartAmount float64 //开始金额
- EndAmount float64 //结束金额
- TopBusinessType []interface{} //业务类型
- TopBusinessTypes []string //业务类型
- SubBusinessType []interface{} //业务类型
- SubBusinessTypes []string //业务类型
- AreaCityDistrict map[string]interface{} //省市区
- }
- // 推送设置
- type PushSet struct {
- Email string //邮箱
- SubSet *PushSetChild //订阅推送设置
- WeekReport *PushSetChild //周报推送设置
- MonthReport *PushSetChild //月报推送设置
- NewprojectForecast *PushSetChild //潜在项目预测推送设置
- EntInfo *PushSetChild //企业情报监控-企业工商变动推送设置
- FollowProject *PushSetChild //项目进度监控推送设置
- FollowEnt *PushSetChild //企业情报监控-企业中标动态推送设置
- OwnerMonitor *PushSetChild //业主监控推送设置
- }
- func (p *PushSet) Reset() {
- //
- if p.SubSet != nil {
- if p.SubSet.RateMode < 1 || p.SubSet.RateMode > 4 {
- p.SubSet.RateMode = 2
- if len(p.SubSet.Times) == 0 {
- p.SubSet.Times = append(p.SubSet.Times, "09:00", "14:00")
- }
- } else if p.SubSet.RateMode == 2 && len(p.SubSet.Times) == 0 {
- p.SubSet.Times = append(p.SubSet.Times, "09:00")
- }
- sort.Strings(p.SubSet.Times)
- }
- //
- if p.EntInfo != nil {
- if p.EntInfo.RateMode < 1 || p.EntInfo.RateMode > 4 {
- p.EntInfo.RateMode = 1
- if len(p.EntInfo.Times) == 0 {
- p.EntInfo.Times = append(p.EntInfo.Times, "09:00", "14:00")
- }
- } else if p.EntInfo.RateMode == 2 && len(p.EntInfo.Times) == 0 {
- p.EntInfo.Times = append(p.EntInfo.Times, "09:00")
- }
- sort.Strings(p.EntInfo.Times)
- }
- //
- if p.NewprojectForecast != nil {
- if p.NewprojectForecast.RateMode < 1 || p.NewprojectForecast.RateMode > 4 {
- p.NewprojectForecast.RateMode = 1
- if len(p.NewprojectForecast.Times) == 0 {
- p.NewprojectForecast.Times = append(p.NewprojectForecast.Times, "09:00", "14:00")
- }
- } else if p.NewprojectForecast.RateMode == 2 && len(p.NewprojectForecast.Times) == 0 {
- p.NewprojectForecast.Times = append(p.NewprojectForecast.Times, "09:00")
- }
- sort.Strings(p.NewprojectForecast.Times)
- }
- //
- if p.FollowProject != nil {
- if p.FollowProject.RateMode < 1 || p.FollowProject.RateMode > 4 {
- p.FollowProject.RateMode = 1
- if len(p.FollowProject.Times) == 0 {
- p.FollowProject.Times = append(p.FollowProject.Times, "09:00", "14:00")
- }
- } else if p.FollowProject.RateMode == 2 && len(p.FollowProject.Times) == 0 {
- p.FollowProject.Times = append(p.FollowProject.Times, "09:00")
- }
- sort.Strings(p.FollowProject.Times)
- }
- //
- if p.FollowEnt != nil {
- if p.FollowEnt.RateMode < 1 || p.FollowEnt.RateMode > 4 {
- p.FollowEnt.RateMode = 1
- if len(p.FollowEnt.Times) == 0 {
- p.FollowEnt.Times = append(p.FollowEnt.Times, "09:00", "14:00")
- }
- } else if p.FollowEnt.RateMode == 2 && len(p.FollowEnt.Times) == 0 {
- p.FollowEnt.Times = append(p.FollowEnt.Times, "09:00")
- }
- sort.Strings(p.FollowEnt.Times)
- }
- //
- if p.OwnerMonitor != nil {
- if p.OwnerMonitor.RateMode < 1 || p.OwnerMonitor.RateMode > 4 {
- p.OwnerMonitor.RateMode = 1
- if len(p.OwnerMonitor.Times) == 0 {
- p.OwnerMonitor.Times = append(p.OwnerMonitor.Times, "09:00", "14:00")
- }
- } else if p.OwnerMonitor.RateMode == 2 && len(p.OwnerMonitor.Times) == 0 {
- p.OwnerMonitor.Times = append(p.OwnerMonitor.Times, "09:00")
- }
- sort.Strings(p.OwnerMonitor.Times)
- }
- }
- type PushSetChild struct {
- RateMode int //推送时间
- Times []string //自定义推送时间
- WxPush int //是否开启微信推送
- AppPush int //是否开启app推送
- MailPush int //是否开启邮箱推送
- Nomsgtip int //是否开启无消息推送提醒
- }
- // 用户基本信息
- type UserInfo struct {
- Id string //mongoid
- PositionId int64 //职位id
- BaseUserId int64 //mysql用户id
- AccountId int64 //账户id
- S_m_openid string //公众号openid
- A_m_openid string //app微信登录openid
- Phone string //app手机号登录
- Jpushid string //极光推送id
- Opushid string //厂商推送id
- AppPhoneType string //手机型号
- Subscribe int //是否关注
- VipStatus int //超级订阅 1--试用 2--正式
- MemberStatus int //大会员
- NicheStatus int //商机管理
- IsMainAccount bool //是否是主账号
- SonAccountStatus int //子账号状态 0-禁用 1-启用
- MemberMainid string //主账号id
- SubPushInactive int //活跃状态
- Entniche *Entniche
- WxTplMsg *WxTplMsg
- SubSet *SubSet
- PushSet *PushSet
- Extend *UserInfoExtend
- }
- /*
- *获取用户信息
- *temp 用户数据
- *tp 1-免费 2-超级订阅 3-大会员
- */
- func NewUserInfo(temp map[string]interface{}, tp int) *UserInfo {
- ui := &UserInfo{
- Id: BsonIdToSId(temp["_id"]),
- BaseUserId: util.Int64All(temp["base_user_id"]),
- S_m_openid: util.ObjToString(temp["s_m_openid"]),
- A_m_openid: util.ObjToString(temp["a_m_openid"]),
- Phone: GetPhone(temp),
- Jpushid: util.ObjToString(temp["s_jpushid"]),
- Opushid: util.ObjToString(temp["s_opushid"]),
- AppPhoneType: util.ObjToString(temp["s_appponetype"]),
- Subscribe: util.IntAllDef(temp["i_ispush"], 1),
- VipStatus: util.IntAll(temp["i_vip_status"]),
- MemberStatus: util.IntAll(temp["i_member_status"]),
- SubPushInactive: util.IntAll(temp["subpush_inactive"]),
- }
- if ui.MemberStatus > 0 {
- ui.IsMainAccount = util.IntAll(temp["i_mainaccount"]) == 1
- ui.SonAccountStatus = util.IntAllDef(temp["i_member_sub_status"], -1)
- ui.MemberMainid = util.ObjToString(temp["s_member_mainid"])
- }
- if tp == 3 {
- obj, _ := temp["o_member_jy"].(map[string]interface{})
- ui.GetSubSet(false, ui.Id, obj)
- } else if tp == 2 {
- obj, _ := temp["o_vipjy"].(map[string]interface{})
- ui.GetSubSet(false, ui.Id, obj)
- } else if tp == 1 {
- obj, _ := temp["o_jy"].(map[string]interface{})
- ui.GetSubSet(true, ui.Id, obj)
- } else {
- ui.SubSet = &SubSet{}
- }
- o_pushset, _ := temp["o_pushset"].(map[string]interface{})
- ui.GetPushSet(o_pushset)
- ui.PushSetFilter()
- return ui
- }
- //
- func NewMyUserInfo(Mgo *MongodbSim, msl *Mysql, userId string) *UserInfo {
- var user *map[string]interface{}
- if IsObjectIdHex(userId) {
- user, _ = Mgo.FindById(Mgo_User, userId, UserCollFields)
- } else {
- user = GetAllByEntPositionId(Mgo, msl, util.IntAll(userId))
- }
- if user == nil || len(*user) == 0 {
- logger.Error(userId, "没有找到该用户信息")
- return nil
- }
- ui := NewUserInfo(*user, 0)
- ui.Id = userId
- return ui
- }
- //
- func NewMyUserInfoByEntUserId(Mgo *MongodbSim, Mysql *Mysql, userId string) *UserInfo {
- var user *map[string]interface{}
- if IsObjectIdHex(userId) {
- user, _ = Mgo.FindById(Mgo_User, userId, UserCollFields)
- } else {
- user = GetAllByEntUserId(Mgo, Mysql, util.IntAll(userId))
- }
- if user == nil || len(*user) == 0 {
- logger.Error(userId, "没有找到该用户信息")
- return nil
- }
- ui := NewUserInfo(*user, 0)
- ui.Id = userId
- return ui
- }
- // 解析用户的推送设置
- func (u *UserInfo) GetPushSet(obj map[string]interface{}) {
- subSet, _ := obj["o_subset"].(map[string]interface{})
- subSet_times, _ := subSet["a_times"].([]interface{})
- weekReport, _ := obj["o_week_report"].(map[string]interface{})
- monthReport, _ := obj["o_month_report"].(map[string]interface{})
- newprojectForecast, _ := obj["o_newproject_forecast"].(map[string]interface{})
- newprojectForecast_times, _ := newprojectForecast["a_times"].([]interface{})
- entInfo, _ := obj["o_entinfo"].(map[string]interface{})
- entInfo_times, _ := entInfo["a_times"].([]interface{})
- followProject, _ := obj["o_follow_project"].(map[string]interface{})
- followProject_times, _ := followProject["a_times"].([]interface{})
- followEnt, _ := obj["o_follow_ent"].(map[string]interface{})
- followEnt_times, _ := followEnt["a_times"].([]interface{})
- ownerMonitor, _ := obj["o_owner_monitor"].(map[string]interface{})
- ownerMonitor_times, _ := ownerMonitor["a_times"].([]interface{})
- u.PushSet = &PushSet{
- Email: strings.TrimSpace(util.ObjToString(obj["s_email"])),
- SubSet: &PushSetChild{
- WxPush: util.IntAllDef(subSet["i_wxpush"], 1),
- AppPush: util.IntAllDef(subSet["i_apppush"], 0),
- MailPush: util.IntAll(subSet["i_mailpush"]),
- RateMode: util.IntAll(subSet["i_ratemode"]),
- Times: util.ObjArrToStringArr(subSet_times),
- Nomsgtip: util.IntAllDef(subSet["i_nomsgtip"], 1), //默认开启
- },
- WeekReport: &PushSetChild{
- WxPush: util.IntAllDef(weekReport["i_wxpush"], 1),
- AppPush: util.IntAllDef(weekReport["i_apppush"], 1),
- MailPush: util.IntAll(weekReport["i_mailpush"]),
- },
- MonthReport: &PushSetChild{
- WxPush: util.IntAllDef(monthReport["i_wxpush"], 1),
- AppPush: util.IntAllDef(monthReport["i_apppush"], 1),
- MailPush: util.IntAll(monthReport["i_mailpush"]),
- },
- NewprojectForecast: &PushSetChild{
- WxPush: util.IntAllDef(newprojectForecast["i_wxpush"], 1),
- AppPush: util.IntAllDef(newprojectForecast["i_apppush"], 1),
- MailPush: util.IntAll(newprojectForecast["i_mailpush"]),
- RateMode: util.IntAll(newprojectForecast["i_ratemode"]),
- Times: util.ObjArrToStringArr(newprojectForecast_times),
- },
- EntInfo: &PushSetChild{
- WxPush: util.IntAllDef(entInfo["i_wxpush"], 1),
- AppPush: util.IntAllDef(entInfo["i_apppush"], 1),
- MailPush: util.IntAll(entInfo["i_mailpush"]),
- RateMode: util.IntAll(entInfo["i_ratemode"]),
- Times: util.ObjArrToStringArr(entInfo_times),
- },
- FollowProject: &PushSetChild{
- WxPush: util.IntAllDef(followProject["i_wxpush"], 1),
- AppPush: util.IntAllDef(followProject["i_apppush"], 1),
- MailPush: util.IntAll(followProject["i_mailpush"]),
- RateMode: util.IntAll(followProject["i_ratemode"]),
- Times: util.ObjArrToStringArr(followProject_times),
- },
- FollowEnt: &PushSetChild{
- WxPush: util.IntAllDef(followEnt["i_wxpush"], 1),
- AppPush: util.IntAllDef(followEnt["i_apppush"], 1),
- MailPush: util.IntAll(followEnt["i_mailpush"]),
- RateMode: util.IntAll(followEnt["i_ratemode"]),
- Times: util.ObjArrToStringArr(followEnt_times),
- },
- OwnerMonitor: &PushSetChild{
- WxPush: util.IntAllDef(ownerMonitor["i_wxpush"], 1),
- AppPush: util.IntAllDef(ownerMonitor["i_apppush"], 1),
- MailPush: util.IntAll(ownerMonitor["i_mailpush"]),
- RateMode: util.IntAll(ownerMonitor["i_ratemode"]),
- Times: util.ObjArrToStringArr(ownerMonitor_times),
- },
- }
- u.PushSet.Reset()
- }
- // 解析用户的推送设置
- func (u *UserInfo) PushSetFilter() {
- if u.Subscribe == 0 || u.S_m_openid == "" {
- if u.PushSet.SubSet != nil {
- u.PushSet.SubSet.WxPush = -1
- }
- if u.PushSet.WeekReport != nil {
- u.PushSet.WeekReport.WxPush = -1
- }
- if u.PushSet.MonthReport != nil {
- u.PushSet.MonthReport.WxPush = -1
- }
- if u.PushSet.NewprojectForecast != nil {
- u.PushSet.NewprojectForecast.WxPush = -1
- }
- if u.PushSet.EntInfo != nil {
- u.PushSet.EntInfo.WxPush = -1
- }
- if u.PushSet.FollowProject != nil {
- u.PushSet.FollowProject.WxPush = -1
- }
- if u.PushSet.FollowEnt != nil {
- u.PushSet.FollowEnt.WxPush = -1
- }
- }
- if u.Jpushid == "" && u.Opushid == "" {
- if u.PushSet.SubSet != nil {
- u.PushSet.SubSet.AppPush = -1
- }
- if u.PushSet.WeekReport != nil {
- u.PushSet.WeekReport.AppPush = -1
- }
- if u.PushSet.MonthReport != nil {
- u.PushSet.MonthReport.AppPush = -1
- }
- if u.PushSet.NewprojectForecast != nil {
- u.PushSet.NewprojectForecast.AppPush = -1
- }
- if u.PushSet.EntInfo != nil {
- u.PushSet.EntInfo.AppPush = -1
- }
- if u.PushSet.FollowProject != nil {
- u.PushSet.FollowProject.AppPush = -1
- }
- if u.PushSet.FollowEnt != nil {
- u.PushSet.FollowEnt.AppPush = -1
- }
- }
- mailPush := true
- if (u.S_m_openid == "" || (u.S_m_openid != "" && u.Subscribe == 0)) && u.Phone == "" && u.A_m_openid == "" {
- mailPush = false
- } else if (u.S_m_openid == "" || (u.S_m_openid != "" && u.Subscribe == 0)) && u.Phone == "" && u.A_m_openid != "" && u.Jpushid == "" && u.Opushid == "" {
- mailPush = false
- } else if !MailReg.MatchString(u.PushSet.Email) {
- mailPush = false
- }
- if !mailPush {
- if u.PushSet.SubSet != nil {
- u.PushSet.SubSet.MailPush = -1
- }
- if u.PushSet.WeekReport != nil {
- u.PushSet.WeekReport.MailPush = -1
- }
- if u.PushSet.MonthReport != nil {
- u.PushSet.MonthReport.MailPush = -1
- }
- if u.PushSet.NewprojectForecast != nil {
- u.PushSet.NewprojectForecast.MailPush = -1
- }
- if u.PushSet.EntInfo != nil {
- u.PushSet.EntInfo.MailPush = -1
- }
- if u.PushSet.FollowProject != nil {
- u.PushSet.FollowProject.MailPush = -1
- }
- if u.PushSet.FollowEnt != nil {
- u.PushSet.FollowEnt.MailPush = -1
- }
- }
- }
- // 解析用户的订阅设置
- func (u *UserInfo) GetSubSet(isFreeUser bool, userId string, obj map[string]interface{}) {
- subSet := &SubSet{
- Keys: []string{},
- Notkeys: []string{},
- Key_item: map[string]string{},
- Key_notkey: map[string]map[string]bool{},
- Key_area: map[string]map[string]bool{},
- Key_subtype: map[string]map[string]bool{},
- OriginalKeys: []string{},
- Areas: []string{},
- Subtypes: []string{},
- Buyerclasss: []string{},
- Matchbuyerclass_other: util.IntAllDef(obj["i_matchbuyerclass_other"], 1),
- ProjectMatch: util.IntAll(obj["i_projectmatch"]),
- MaxPushSize: util.IntAll(obj["i_maxpushsize"]),
- MaxMailSize: util.IntAll(obj["i_maxmailsize"]),
- Switch: util.IntAllDef(obj["i_switch"], 1),
- MatchMode: []string{},
- }
- matchMode, _ := obj["i_matchmode"].([]interface{})
- for _, v := range matchMode {
- vs, _ := v.(string)
- subSet.MatchMode = append(subSet.MatchMode, vs)
- }
- if len(subSet.MatchMode) == 0 {
- subSet.MatchMode = append(subSet.MatchMode, "title")
- }
- subSet.Amount = util.ObjToString(obj["amount"])
- if amount := strings.Split(subSet.Amount, "-"); len(amount) == 2 {
- subSet.StartAmount = util.Float64All(amount[0]) * 10000
- subSet.EndAmount = util.Float64All(amount[1]) * 10000
- }
- var keySets []*KeySet
- if isFreeUser {
- var err error
- keySets, err = u.GetKeySets(obj["a_key"])
- if err != nil {
- logger.Error("获取用户关键词错误!", userId, obj["a_key"], err)
- return
- }
- area := obj["o_area"]
- if ppStatus := util.IntAll(obj["i_ppstatus"]); ppStatus == 1 {
- area = obj["o_area_p"]
- }
- if newFree := util.IntAll(obj["i_newfree"]); newFree == 1 && area != nil {
- subSet.IsUpgrade = true
- subSet.Subtype, _ = obj["a_infotype"].([]interface{})
- subSet.Area, _ = area.(map[string]interface{})
- }
- } else {
- items, _ := obj["a_items"].([]interface{})
- for _, v := range items {
- item, _ := v.(map[string]interface{})
- itemName := strings.TrimSpace(util.ObjToString(item["s_item"]))
- subSet.Items = append(subSet.Items, itemName)
- kss, err := u.GetKeySets(item["a_key"])
- if err != nil {
- logger.Error("获取用户关键词错误!", userId, item["a_key"], err)
- continue
- }
- for _, vv := range kss {
- if vv == nil {
- continue
- }
- if vv.MatchWay == 1 {
- for _, vvv := range vv.Keys {
- keySets = append(keySets, &KeySet{
- Item: itemName,
- Keys: []string{vvv},
- NotKeys: vv.NotKeys,
- })
- }
- for _, vvv := range vv.AppendKeys {
- keySets = append(keySets, &KeySet{
- Item: itemName,
- Keys: []string{vvv},
- NotKeys: vv.NotKeys,
- })
- }
- } else {
- vv.Item = itemName
- keySets = append(keySets, vv)
- }
- }
- }
- subSet.Buyerclass, _ = obj["a_buyerclass"].([]interface{})
- subSet.Subtype, _ = obj["a_infotype"].([]interface{})
- subSet.Area, _ = obj["o_area"].(map[string]interface{})
- subSet.District, _ = obj["o_district"].(map[string]interface{})
- }
- subSet.TopBusinessType, _ = obj["a_topbusinesstype"].([]interface{})
- subSet.SubBusinessType, _ = obj["a_subbusinesstype"].([]interface{})
- for _, v := range subSet.Buyerclass {
- s_v, _ := v.(string)
- if s_v == "" {
- continue
- }
- subSet.Buyerclasss = append(subSet.Buyerclasss, s_v)
- }
- for _, v := range subSet.Subtype {
- s_v, _ := v.(string)
- if s_v == "" {
- continue
- }
- subSet.Subtypes = append(subSet.Subtypes, s_v)
- }
- subSet.AreaCityDistrict, _ = obj["o_area_city_district"].(map[string]interface{})
- if subSet.AreaCityDistrict != nil {
- area, district := map[string]interface{}{}, map[string]interface{}{}
- for k, v := range subSet.AreaCityDistrict {
- city := []interface{}{}
- vm, _ := v.(map[string]interface{})
- for kk, vv := range vm {
- city = append(city, kk)
- district[kk] = vv
- }
- area[k] = city
- }
- subSet.Area = area
- subSet.District = district
- }
- for area, _ := range subSet.Area {
- if area == "" {
- continue
- }
- subSet.Areas = append(subSet.Areas, area)
- }
- for _, v := range subSet.TopBusinessType {
- s_v, _ := v.(string)
- if s_v == "" {
- continue
- }
- subSet.TopBusinessTypes = append(subSet.TopBusinessTypes, s_v)
- }
- for _, v := range subSet.SubBusinessType {
- s_v, _ := v.(string)
- if s_v == "" {
- continue
- }
- subSet.SubBusinessTypes = append(subSet.SubBusinessTypes, s_v)
- }
- ////////////////
- for _, vs := range keySets {
- if vs == nil {
- logger.Error(userId, "关键词设置异常")
- continue
- }
- var vs_keys []string
- for _, vs_v := range [][]string{vs.Keys, vs.AppendKeys} {
- for _, vs_vv := range vs_v {
- vs_vv = strings.TrimSpace(vs_vv)
- if vs_vv == "" {
- continue
- }
- vs_keys = append(vs_keys, vs_vv)
- }
- }
- if len(vs_keys) == 0 {
- continue
- }
- key := strings.Join(vs_keys, "+")
- subSet.OriginalKeys = append(subSet.OriginalKeys, key)
- if KeyFilterReg.MatchString(key) {
- continue
- } else if !KeyRetainReg.MatchString(key) {
- continue
- }
- subSet.Keys = append(subSet.Keys, key)
- subSet.Notkeys = append(subSet.Notkeys, vs.NotKeys...)
- //转大写
- upperKey := strings.ToUpper(key)
- subSet.Key_item[upperKey] = vs.Item
- //建立与排除词的对应关系
- for _, notkey := range vs.NotKeys {
- upperNotkey := strings.ToUpper(notkey)
- if subSet.Key_notkey[upperKey] == nil {
- subSet.Key_notkey[upperKey] = map[string]bool{}
- }
- subSet.Key_notkey[upperKey][upperNotkey] = true
- }
- //免费用户需要进行映射
- if isFreeUser {
- //建立与信息范围的对应关系
- for _, area := range vs.Areas {
- if subSet.Key_area[upperKey] == nil {
- subSet.Key_area[upperKey] = map[string]bool{}
- }
- subSet.Key_area[upperKey][area] = true
- }
- //建立与信息类型的对应关系
- for _, subtype := range vs.SubTypes {
- if subSet.Key_subtype[upperKey] == nil {
- subSet.Key_subtype[upperKey] = map[string]bool{}
- }
- subSet.Key_subtype[upperKey][subtype] = true
- }
- }
- }
- u.SubSet = subSet
- }
- // 得到用户的关键词
- func (u *UserInfo) GetKeySets(a_key interface{}) ([]*KeySet, error) {
- var keySets []*KeySet
- if a_key == nil {
- return keySets, nil
- }
- _bs, err := json.Marshal(a_key)
- if err == nil {
- err = json.Unmarshal(_bs, &keySets)
- }
- if err != nil {
- return keySets, err
- }
- for _, v := range keySets {
- if v == nil {
- continue
- }
- keys, appendKeys, notKeys := []string{}, []string{}, []string{}
- for _, vv := range v.Keys {
- keys = append(keys, SpaceReg.Split(strings.TrimSpace(vv), -1)...)
- }
- for _, vv := range v.AppendKeys {
- appendKeys = append(appendKeys, SpaceReg.Split(strings.TrimSpace(vv), -1)...)
- }
- for _, vv := range v.NotKeys {
- notKeys = append(notKeys, SpaceReg.Split(strings.TrimSpace(vv), -1)...)
- }
- v.Keys = keys
- v.AppendKeys = appendKeys
- v.NotKeys = notKeys
- }
- return keySets, err
- }
- type Entniche struct {
- AccountId int64 //企业账户id
- EntId int //企业id
- EntName string //企业名称
- DeptId int //部门id
- DisId string //分发id
- UserId int
- Unique string
- OnlyPush int
- IsNew int
- PowerSource int //权益来源
- ProductType string //产品类型
- Mail string //邮箱
- IsDis int //是否是分发
- DisMember int //分发-超级订阅
- DisVip int //分发-大会员
- }
- // 用户基本信息-扩展
- type UserInfoExtend struct {
- Object map[string]interface{}
- CreateTime int64 //
- Size int
- }
- func (u *UserInfo) Add(k string, m *map[string]map[*UserInfo]bool) {
- mk := (*m)[k]
- if mk == nil {
- mk = map[*UserInfo]bool{}
- }
- mk[u] = true
- (*m)[k] = mk
- }
- // 添加业务类型
- func (u *UserInfo) AddTopBusinessType(m *map[string]map[*UserInfo]bool) {
- if len(u.SubSet.TopBusinessTypes) == 0 {
- u.Add("", m)
- } else {
- for _, v := range u.SubSet.TopBusinessTypes {
- u.Add(v, m)
- }
- }
- }
- //
- func (u *UserInfo) AddSubBusinessType(m *map[string]map[*UserInfo]bool) {
- if len(u.SubSet.SubBusinessTypes) == 0 {
- u.Add("", m)
- } else {
- for _, v := range u.SubSet.SubBusinessTypes {
- u.Add(v, m)
- }
- }
- }
- // 添加信息类型映射关系
- func (u *UserInfo) AddSubtype(m *map[string]map[*UserInfo]bool) {
- if len(u.SubSet.Subtypes) == 0 {
- u.Add("", m)
- } else {
- for _, v := range u.SubSet.Subtypes {
- u.Add(v, m)
- }
- }
- }
- // 添加采购单位类型映射关系
- func (u *UserInfo) AddBuyerclass(m *map[string]map[*UserInfo]bool) {
- //如果有关键词 有采购单位行业,行业加上“其它”
- if len(u.SubSet.Buyerclasss) == 0 {
- u.Add("", m)
- } else {
- if u.SubSet.Matchbuyerclass_other == 1 && len(u.SubSet.Keys) > 0 {
- u.Add("其它", m)
- }
- for _, v := range u.SubSet.Buyerclasss {
- u.Add(v, m)
- }
- }
- }
- // 添加区域映射关系
- func (u *UserInfo) AddArea(m *map[string]map[*UserInfo]bool) {
- if len(u.SubSet.Areas) == 0 {
- u.Add("", m)
- } else {
- for _, v := range u.SubSet.Areas {
- u.Add(v, m)
- }
- }
- }
- //添加省市映射关系
- func (u *UserInfo) AddAreaCity(area, city *map[string]map[*UserInfo]bool) {
- if len(u.SubSet.Area) == 0 {
- u.Add("", area)
- } else {
- for k, v := range u.SubSet.Area {
- if k == "" {
- continue
- }
- vs, _ := v.([]interface{})
- if len(vs) == 0 {
- u.Add(k, area)
- } else {
- for _, vv := range vs {
- s_vv, _ := vv.(string)
- if s_vv == "" {
- continue
- }
- u.Add(s_vv, city)
- }
- }
- }
- }
- }
- //添加省市县映射关系
- func (u *UserInfo) AddAreaCityDistrict(area, city *map[string]map[*UserInfo]bool, district *map[string]map[string]map[*UserInfo]bool) {
- if len(u.SubSet.Area) == 0 {
- u.Add("", area)
- } else {
- for k, v := range u.SubSet.Area {
- if k == "" {
- continue
- }
- vs, _ := v.([]interface{})
- if len(vs) == 0 {
- u.Add(k, area)
- } else {
- for _, vv := range vs {
- s_vv, _ := vv.(string)
- if s_vv == "" {
- continue
- }
- d_vv, _ := u.SubSet.District[s_vv].([]interface{})
- if len(d_vv) == 0 {
- u.Add(s_vv, city)
- } else {
- for _, vvv := range d_vv {
- s_vvv, _ := vvv.(string)
- if s_vvv == "" {
- continue
- }
- d_mm := (*district)[s_vv]
- if d_mm == nil {
- d_mm = map[string]map[*UserInfo]bool{}
- }
- u.Add(s_vvv, &d_mm)
- (*district)[s_vv] = d_mm
- }
- }
- }
- }
- }
- }
- }
- //
- func (u *UserInfo) MakeKeyUserByMatchMode(title_pjob, detail_pjob, filetext_pjob, pnp_pjob *KeyDfa) {
- for _, v := range u.SubSet.MatchMode {
- if v == "title" {
- u.MakeKeyUser(u.SubSet.Keys, title_pjob.Key_user)
- u.MakeKeyUser(u.SubSet.Notkeys, title_pjob.Notkey_user)
- } else if v == "detail" {
- u.MakeKeyUser(u.SubSet.Keys, detail_pjob.Key_user)
- u.MakeKeyUser(u.SubSet.Notkeys, detail_pjob.Notkey_user)
- } else if v == "filetext" {
- u.MakeKeyUser(u.SubSet.Keys, filetext_pjob.Key_user)
- u.MakeKeyUser(u.SubSet.Notkeys, filetext_pjob.Notkey_user)
- } else if v == "projectname/purchasing" {
- u.MakeKeyUser(u.SubSet.Keys, pnp_pjob.Key_user)
- u.MakeKeyUser(u.SubSet.Notkeys, pnp_pjob.Notkey_user)
- }
- }
- }
- // 把用户挂在词下面
- func (u *UserInfo) MakeKeyUser(keys []string, key_user *map[string]*[]*UserInfo) {
- mp := map[string]bool{}
- for _, key := range keys {
- v := strings.ToUpper(key)
- if v == "" || mp[v] {
- continue
- }
- mp[v] = true
- arr := (*key_user)[v]
- if arr == nil {
- arr = &[]*UserInfo{}
- }
- *arr = append(*arr, u)
- (*key_user)[v] = arr
- }
- }
- type WxTplMsg struct {
- Key string
- Area string
- Size int
- }
- type SortList []*MatchInfo
- func (s SortList) Len() int {
- return len(s)
- }
- func (s SortList) Less(i, j int) bool {
- return util.Int64All(s[i].Info["publishtime"]) > util.Int64All(s[j].Info["publishtime"])
- }
- func (s SortList) Swap(i, j int) {
- s[i], s[j] = s[j], s[i]
- }
- type CSortList []map[string]interface{}
- func (s CSortList) Len() int {
- return len(s)
- }
- func (s CSortList) Less(i, j int) bool {
- return util.Int64All(s[i]["publishtime"]) > util.Int64All(s[j]["publishtime"])
- }
- func (s CSortList) Swap(i, j int) {
- s[i], s[j] = s[j], s[i]
- }
- type MatchInfo struct {
- Info map[string]interface{}
- Keys []string
- Items []string
- MatchWays []string
- DisId string
- HandDis bool //是否分发
- Extend map[string]interface{}
- }
- type KeyDfa struct {
- Key *dfa.DFA
- NotKey *dfa.DFA
- Key_user *map[string]*[]*UserInfo
- Notkey_user *map[string]*[]*UserInfo
- }
- // 所有用户的关键词和排除词
- func (p *KeyDfa) CreateDaf() {
- //关键词
- p.Key = &dfa.DFA{}
- keys := make([]string, 0)
- for k, _ := range *p.Key_user {
- keys = append(keys, k)
- }
- p.Key.AddWord(keys...)
- //排除关键词
- p.NotKey = &dfa.DFA{}
- notKeys := make([]string, 0)
- for k, _ := range *p.Notkey_user {
- notKeys = append(notKeys, k)
- }
- p.NotKey.AddWord(notKeys...)
- }
- type MatchUser struct {
- Keys []string
- Items []string
- Item map[string]bool
- MatchWays []string
- MatchWay map[string]bool
- }
- type RelationProjectUser struct {
- TopTypes []string
- }
- type PushInfo struct {
- Ids []interface{}
- Info map[string]interface{}
- }
- // 推送返回结果
- type PushResult struct {
- WxStatus int
- AppStatus int
- MailStatus int
- PushDate int64
- Infos *SortList
- }
- type PushParam struct {
- JpushTitle string
- LastInfoDate int64
- TitleArray []string
- Infos *SortList
- InfosLength int
- MailHtml string
- PushId string
- PushDate int64
- PushCount int
- IsPush bool
- }
- type BiddingInfo struct {
- Id string
- Title string
- ClearTitle string
- HighlightTitle string
- AreaTitle string
- Area string
- Publishtime int64
- PublishtimeDiff string
- PublishtimeYMD string
- Buyerclass string
- Subscopeclass string
- Bidamount interface{}
- Budget interface{}
- Acount string
- Subtype string
- Toptype string
- Infotype string
- }
|