struct.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. package p
  2. import (
  3. "encoding/json"
  4. "sort"
  5. "strings"
  6. util "app.yhyue.com/moapp/jybase/common"
  7. "app.yhyue.com/moapp/jybase/logger"
  8. . "app.yhyue.com/moapp/jybase/mongodb"
  9. "bp.jydev.jianyu360.cn/BaseService/pushpkg/dfa"
  10. )
  11. type MgoConf struct {
  12. Address string
  13. Size int
  14. DbName string
  15. ReplSet string
  16. UserName string
  17. Password string
  18. Collection string
  19. ExperienceDbName string
  20. }
  21. type RedisConf struct {
  22. Address string
  23. }
  24. type MysqlConf struct {
  25. DbName string
  26. Address string
  27. UserName string
  28. PassWord string
  29. MaxOpenConns int
  30. MaxIdleConns int
  31. }
  32. type EsConf struct {
  33. Address string
  34. Size int
  35. Version string
  36. UserName string
  37. Password string
  38. }
  39. type MemberService struct {
  40. IsBuy bool
  41. Services map[int]*memberService
  42. }
  43. type memberService struct {
  44. Id int
  45. StartTime string
  46. }
  47. // 关键词
  48. type KeySet struct {
  49. Item string `json:"item"` //分类名称
  50. Keys []string `json:"key"` //关键词
  51. NotKeys []string `json:"notkey"` //排除词
  52. SubTypes []string `json:"infotype"` //信息类型
  53. Areas []string `json:"area"` //地区
  54. AppendKeys []string `json:"appendkey"` //附加词
  55. MatchWay int `json:"matchway"` //匹配模式 0:精准匹配 1:模糊匹配
  56. }
  57. // 解析订阅词
  58. type SubSet struct {
  59. MatchWay int //匹配方式 1-标题 2-正文
  60. Matchbuyerclass_other int //是否开启其他按钮
  61. ProjectMatch int //项目关联推送
  62. Items []string //关键词分类
  63. Keys []string //过滤后的关键词
  64. Notkeys []string //排除词
  65. Key_item map[string]string //关键词对应的分类名称
  66. Key_notkey map[string]map[string]bool //关键词所对应的排除词
  67. Key_area map[string]map[string]bool //关键词所对应的信息范围
  68. Key_subtype map[string]map[string]bool //关键词所对应的信息类型
  69. OriginalKeys []string //原始关键词
  70. Areas []string //区域-省份
  71. Area map[string]interface{} //区域-省份
  72. Subtype []interface{} //信息类型-二级分类
  73. Subtypes []string //信息类型-二级分类
  74. Buyerclass []interface{} //采购单位行业
  75. Buyerclasss []string //采购单位行业
  76. IsUpgrade bool //免费用户是否订阅升级
  77. MaxPushSize int //推送最大条数
  78. MaxMailSize int //邮件最大条数
  79. }
  80. // 推送设置
  81. type PushSet struct {
  82. Email string //邮箱
  83. SubSet *PushSetChild //订阅推送设置
  84. WeekReport *PushSetChild //周报推送设置
  85. MonthReport *PushSetChild //月报推送设置
  86. NewprojectForecast *PushSetChild //潜在项目预测推送设置
  87. EntInfo *PushSetChild //企业情报监控-企业工商变动推送设置
  88. FollowProject *PushSetChild //项目进度监控推送设置
  89. FollowEnt *PushSetChild //企业情报监控-企业中标动态推送设置
  90. }
  91. func (p *PushSet) ResetSubSet() {
  92. if p.SubSet == nil {
  93. return
  94. }
  95. if p.SubSet.RateMode == 0 || p.SubSet.RateMode == 5 {
  96. p.SubSet.RateMode = 2
  97. if len(p.SubSet.Times) == 0 {
  98. p.SubSet.Times = append(p.SubSet.Times, "09:00", "14:00")
  99. }
  100. } else if p.SubSet.RateMode == 2 && len(p.SubSet.Times) == 0 {
  101. p.SubSet.Times = append(p.SubSet.Times, "09:00")
  102. }
  103. sort.Strings(p.SubSet.Times)
  104. }
  105. type PushSetChild struct {
  106. RateMode int //推送时间
  107. Times []string //自定义推送时间
  108. WxPush int //是否开启微信推送
  109. AppPush int //是否开启app推送
  110. MailPush int //是否开启邮箱推送
  111. Nomsgtip int //是否开启无消息推送提醒
  112. }
  113. // 用户基本信息
  114. type UserInfo struct {
  115. Id string //mongoid
  116. BaseUserId int64 //mysql用户id
  117. S_m_openid string //公众号openid
  118. A_m_openid string //app微信登录openid
  119. Phone string //app手机号登录
  120. Jpushid string //极光推送id
  121. Opushid string //厂商推送id
  122. AppPhoneType string //手机型号
  123. Subscribe int //是否关注
  124. VipStatus int //超级订阅 1--试用 2--正式
  125. MemberStatus int //大会员
  126. NicheStatus int //商机管理
  127. IsMainAccount bool //是否是主账号
  128. SonAccountStatus int //子账号状态 0-禁用 1-启用
  129. MemberMainid string //主账号id
  130. Entniche *Entniche
  131. WxTplMsg *WxTplMsg
  132. SubSet *SubSet
  133. PushSet *PushSet
  134. Extend *UserInfoExtend
  135. }
  136. /*
  137. *获取用户信息
  138. *temp 用户数据
  139. *tp 1-免费 2-超级订阅 3-大会员
  140. */
  141. func NewUserInfo(temp map[string]interface{}, tp int) *UserInfo {
  142. ui := &UserInfo{
  143. Id: BsonIdToSId(temp["_id"]),
  144. BaseUserId: util.Int64All(temp["base_user_id"]),
  145. S_m_openid: util.ObjToString(temp["s_m_openid"]),
  146. A_m_openid: util.ObjToString(temp["a_m_openid"]),
  147. Phone: GetPhone(temp),
  148. Jpushid: util.ObjToString(temp["s_jpushid"]),
  149. Opushid: util.ObjToString(temp["s_opushid"]),
  150. AppPhoneType: util.ObjToString(temp["s_appponetype"]),
  151. Subscribe: util.IntAllDef(temp["i_ispush"], 1),
  152. VipStatus: util.IntAll(temp["i_vip_status"]),
  153. MemberStatus: util.IntAll(temp["i_member_status"]),
  154. }
  155. if ui.MemberStatus > 0 {
  156. ui.IsMainAccount = util.IntAll(temp["i_mainaccount"]) == 1
  157. ui.SonAccountStatus = util.IntAllDef(temp["i_member_sub_status"], -1)
  158. ui.MemberMainid = util.ObjToString(temp["s_member_mainid"])
  159. }
  160. if tp == 3 {
  161. obj, _ := temp["o_member_jy"].(map[string]interface{})
  162. ui.GetSubSet(false, ui.Id, obj)
  163. } else if tp == 2 {
  164. obj, _ := temp["o_vipjy"].(map[string]interface{})
  165. ui.GetSubSet(false, ui.Id, obj)
  166. } else if tp == 1 {
  167. obj, _ := temp["o_jy"].(map[string]interface{})
  168. ui.GetSubSet(true, ui.Id, obj)
  169. }
  170. o_pushset, _ := temp["o_pushset"].(map[string]interface{})
  171. ui.GetPushSet(o_pushset)
  172. ui.PushSetFilter()
  173. return ui
  174. }
  175. // 解析用户的推送设置
  176. func (u *UserInfo) GetPushSet(obj map[string]interface{}) {
  177. subSet, _ := obj["o_subset"].(map[string]interface{})
  178. times, _ := subSet["a_times"].([]interface{})
  179. weekReport, _ := obj["o_week_report"].(map[string]interface{})
  180. monthReport, _ := obj["o_month_report"].(map[string]interface{})
  181. newprojectForecast, _ := obj["o_newproject_forecast"].(map[string]interface{})
  182. entInfo, _ := obj["o_entinfo"].(map[string]interface{})
  183. followProject, _ := obj["o_follow_project"].(map[string]interface{})
  184. followEnt, _ := obj["o_follow_ent"].(map[string]interface{})
  185. u.PushSet = &PushSet{
  186. Email: strings.TrimSpace(util.ObjToString(obj["s_email"])),
  187. SubSet: &PushSetChild{
  188. WxPush: util.IntAllDef(subSet["i_wxpush"], 1),
  189. AppPush: util.IntAllDef(subSet["i_apppush"], 1),
  190. MailPush: util.IntAll(subSet["i_mailpush"]),
  191. RateMode: util.IntAll(subSet["i_ratemode"]),
  192. Times: util.ObjArrToStringArr(times),
  193. Nomsgtip: util.IntAllDef(obj["i_nomsgtip"], 1), //默认开启
  194. },
  195. WeekReport: &PushSetChild{
  196. WxPush: util.IntAllDef(weekReport["i_wxpush"], 1),
  197. AppPush: util.IntAllDef(weekReport["i_apppush"], 1),
  198. MailPush: util.IntAll(weekReport["i_mailpush"]),
  199. },
  200. MonthReport: &PushSetChild{
  201. WxPush: util.IntAllDef(monthReport["i_wxpush"], 1),
  202. AppPush: util.IntAllDef(monthReport["i_apppush"], 1),
  203. MailPush: util.IntAll(monthReport["i_mailpush"]),
  204. },
  205. NewprojectForecast: &PushSetChild{
  206. WxPush: util.IntAllDef(newprojectForecast["i_wxpush"], 1),
  207. AppPush: util.IntAllDef(newprojectForecast["i_apppush"], 1),
  208. MailPush: util.IntAll(newprojectForecast["i_mailpush"]),
  209. },
  210. EntInfo: &PushSetChild{
  211. WxPush: util.IntAllDef(entInfo["i_wxpush"], 1),
  212. AppPush: util.IntAllDef(entInfo["i_apppush"], 1),
  213. MailPush: util.IntAll(entInfo["i_mailpush"]),
  214. },
  215. FollowProject: &PushSetChild{
  216. WxPush: util.IntAllDef(followProject["i_wxpush"], 1),
  217. AppPush: util.IntAllDef(followProject["i_apppush"], 1),
  218. MailPush: util.IntAll(followProject["i_mailpush"]),
  219. },
  220. FollowEnt: &PushSetChild{
  221. WxPush: util.IntAllDef(followEnt["i_wxpush"], 1),
  222. AppPush: util.IntAllDef(followEnt["i_apppush"], 1),
  223. MailPush: util.IntAll(followEnt["i_mailpush"]),
  224. },
  225. }
  226. u.PushSet.ResetSubSet()
  227. }
  228. // 解析用户的推送设置
  229. func (u *UserInfo) PushSetFilter() {
  230. if u.Subscribe == 0 || u.S_m_openid == "" {
  231. if u.PushSet.SubSet != nil {
  232. u.PushSet.SubSet.WxPush = -1
  233. }
  234. if u.PushSet.WeekReport != nil {
  235. u.PushSet.WeekReport.WxPush = -1
  236. }
  237. if u.PushSet.MonthReport != nil {
  238. u.PushSet.MonthReport.WxPush = -1
  239. }
  240. if u.PushSet.NewprojectForecast != nil {
  241. u.PushSet.NewprojectForecast.WxPush = -1
  242. }
  243. if u.PushSet.EntInfo != nil {
  244. u.PushSet.EntInfo.WxPush = -1
  245. }
  246. if u.PushSet.FollowProject != nil {
  247. u.PushSet.FollowProject.WxPush = -1
  248. }
  249. if u.PushSet.FollowEnt != nil {
  250. u.PushSet.FollowEnt.WxPush = -1
  251. }
  252. }
  253. if u.Jpushid == "" && u.Opushid == "" {
  254. if u.PushSet.SubSet != nil {
  255. u.PushSet.SubSet.AppPush = -1
  256. }
  257. if u.PushSet.WeekReport != nil {
  258. u.PushSet.WeekReport.AppPush = -1
  259. }
  260. if u.PushSet.MonthReport != nil {
  261. u.PushSet.MonthReport.AppPush = -1
  262. }
  263. if u.PushSet.NewprojectForecast != nil {
  264. u.PushSet.NewprojectForecast.AppPush = -1
  265. }
  266. if u.PushSet.EntInfo != nil {
  267. u.PushSet.EntInfo.AppPush = -1
  268. }
  269. if u.PushSet.FollowProject != nil {
  270. u.PushSet.FollowProject.AppPush = -1
  271. }
  272. if u.PushSet.FollowEnt != nil {
  273. u.PushSet.FollowEnt.AppPush = -1
  274. }
  275. }
  276. mailPush := true
  277. if (u.S_m_openid == "" || (u.S_m_openid != "" && u.Subscribe == 0)) && u.Phone == "" && u.A_m_openid == "" {
  278. mailPush = false
  279. } else if (u.S_m_openid == "" || (u.S_m_openid != "" && u.Subscribe == 0)) && u.Phone == "" && u.A_m_openid != "" && u.Jpushid == "" && u.Opushid == "" {
  280. mailPush = false
  281. } else if !MailReg.MatchString(u.PushSet.Email) {
  282. mailPush = false
  283. }
  284. if !mailPush {
  285. if u.PushSet.SubSet != nil {
  286. u.PushSet.SubSet.MailPush = -1
  287. }
  288. if u.PushSet.WeekReport != nil {
  289. u.PushSet.WeekReport.MailPush = -1
  290. }
  291. if u.PushSet.MonthReport != nil {
  292. u.PushSet.MonthReport.MailPush = -1
  293. }
  294. if u.PushSet.NewprojectForecast != nil {
  295. u.PushSet.NewprojectForecast.MailPush = -1
  296. }
  297. if u.PushSet.EntInfo != nil {
  298. u.PushSet.EntInfo.MailPush = -1
  299. }
  300. if u.PushSet.FollowProject != nil {
  301. u.PushSet.FollowProject.MailPush = -1
  302. }
  303. if u.PushSet.FollowEnt != nil {
  304. u.PushSet.FollowEnt.MailPush = -1
  305. }
  306. }
  307. }
  308. // 解析用户的订阅设置
  309. func (u *UserInfo) GetSubSet(isFreeUser bool, userId string, obj map[string]interface{}) {
  310. subSet := &SubSet{
  311. Keys: []string{},
  312. Notkeys: []string{},
  313. Key_item: map[string]string{},
  314. Key_notkey: map[string]map[string]bool{},
  315. Key_area: map[string]map[string]bool{},
  316. Key_subtype: map[string]map[string]bool{},
  317. OriginalKeys: []string{},
  318. Areas: []string{},
  319. Subtypes: []string{},
  320. Buyerclasss: []string{},
  321. MatchWay: util.IntAllDef(obj["i_matchway"], 1),
  322. Matchbuyerclass_other: util.IntAllDef(obj["i_matchbuyerclass_other"], 1),
  323. ProjectMatch: util.IntAll(obj["i_projectmatch"]),
  324. MaxPushSize: util.IntAll(obj["i_maxpushsize"]),
  325. MaxMailSize: util.IntAll(obj["i_maxmailsize"]),
  326. }
  327. var keySets []*KeySet
  328. if isFreeUser {
  329. var err error
  330. keySets, err = u.GetKeySets(obj["a_key"])
  331. if err != nil {
  332. logger.Error("获取用户关键词错误!", userId, obj["a_key"], err)
  333. return
  334. }
  335. area := obj["o_area"]
  336. if ppStatus := util.IntAll(obj["i_ppstatus"]); ppStatus == 1 {
  337. area = obj["o_area_p"]
  338. }
  339. if newFree := util.IntAll(obj["i_newfree"]); newFree == 1 && area != nil {
  340. subSet.IsUpgrade = true
  341. subSet.Subtype, _ = obj["a_infotype"].([]interface{})
  342. subSet.Area, _ = area.(map[string]interface{})
  343. }
  344. } else {
  345. items, _ := obj["a_items"].([]interface{})
  346. for _, v := range items {
  347. item, _ := v.(map[string]interface{})
  348. itemName := strings.TrimSpace(util.ObjToString(item["s_item"]))
  349. subSet.Items = append(subSet.Items, itemName)
  350. kss, err := u.GetKeySets(item["a_key"])
  351. if err != nil {
  352. logger.Error("获取用户关键词错误!", userId, item["a_key"], err)
  353. continue
  354. }
  355. for _, vv := range kss {
  356. if vv == nil {
  357. continue
  358. }
  359. if vv.MatchWay == 1 {
  360. for _, vvv := range vv.Keys {
  361. keySets = append(keySets, &KeySet{
  362. Item: itemName,
  363. Keys: []string{vvv},
  364. NotKeys: vv.NotKeys,
  365. })
  366. }
  367. for _, vvv := range vv.AppendKeys {
  368. keySets = append(keySets, &KeySet{
  369. Item: itemName,
  370. Keys: []string{vvv},
  371. NotKeys: vv.NotKeys,
  372. })
  373. }
  374. } else {
  375. vv.Item = itemName
  376. keySets = append(keySets, vv)
  377. }
  378. }
  379. }
  380. subSet.Buyerclass, _ = obj["a_buyerclass"].([]interface{})
  381. subSet.Subtype, _ = obj["a_infotype"].([]interface{})
  382. subSet.Area, _ = obj["o_area"].(map[string]interface{})
  383. }
  384. for _, v := range subSet.Buyerclass {
  385. s_v, _ := v.(string)
  386. if s_v == "" {
  387. continue
  388. }
  389. subSet.Buyerclasss = append(subSet.Buyerclasss, s_v)
  390. }
  391. for _, v := range subSet.Subtype {
  392. s_v, _ := v.(string)
  393. if s_v == "" {
  394. continue
  395. }
  396. subSet.Subtypes = append(subSet.Subtypes, s_v)
  397. }
  398. for area, _ := range subSet.Area {
  399. if area == "" {
  400. continue
  401. }
  402. subSet.Areas = append(subSet.Areas, area)
  403. }
  404. ////////////////
  405. for _, vs := range keySets {
  406. if vs == nil {
  407. logger.Error(userId, "关键词设置异常")
  408. continue
  409. }
  410. var vs_keys []string
  411. for _, vs_v := range [][]string{vs.Keys, vs.AppendKeys} {
  412. for _, vs_vv := range vs_v {
  413. vs_vv = strings.TrimSpace(vs_vv)
  414. if vs_vv == "" {
  415. continue
  416. }
  417. vs_keys = append(vs_keys, vs_vv)
  418. }
  419. }
  420. if len(vs_keys) == 0 {
  421. continue
  422. }
  423. key := strings.Join(vs_keys, "+")
  424. subSet.OriginalKeys = append(subSet.OriginalKeys, key)
  425. if KeyFilterReg.MatchString(key) {
  426. continue
  427. } else if !KeyRetainReg.MatchString(key) {
  428. continue
  429. }
  430. subSet.Keys = append(subSet.Keys, key)
  431. subSet.Notkeys = append(subSet.Notkeys, vs.NotKeys...)
  432. //转大写
  433. upperKey := strings.ToUpper(key)
  434. subSet.Key_item[upperKey] = vs.Item
  435. //建立与排除词的对应关系
  436. for _, notkey := range vs.NotKeys {
  437. upperNotkey := strings.ToUpper(notkey)
  438. if subSet.Key_notkey[upperKey] == nil {
  439. subSet.Key_notkey[upperKey] = map[string]bool{}
  440. }
  441. subSet.Key_notkey[upperKey][upperNotkey] = true
  442. }
  443. //免费用户需要进行映射
  444. if isFreeUser {
  445. //建立与信息范围的对应关系
  446. for _, area := range vs.Areas {
  447. if subSet.Key_area[upperKey] == nil {
  448. subSet.Key_area[upperKey] = map[string]bool{}
  449. }
  450. subSet.Key_area[upperKey][area] = true
  451. }
  452. //建立与信息类型的对应关系
  453. for _, subtype := range vs.SubTypes {
  454. if subSet.Key_subtype[upperKey] == nil {
  455. subSet.Key_subtype[upperKey] = map[string]bool{}
  456. }
  457. subSet.Key_subtype[upperKey][subtype] = true
  458. }
  459. }
  460. }
  461. u.SubSet = subSet
  462. }
  463. // 得到用户的关键词
  464. func (u *UserInfo) GetKeySets(a_key interface{}) ([]*KeySet, error) {
  465. var keySets []*KeySet
  466. if a_key == nil {
  467. return keySets, nil
  468. }
  469. _bs, err := json.Marshal(a_key)
  470. if err == nil {
  471. err = json.Unmarshal(_bs, &keySets)
  472. }
  473. if err != nil {
  474. return keySets, err
  475. }
  476. for _, v := range keySets {
  477. if v == nil {
  478. continue
  479. }
  480. keys, appendKeys, notKeys := []string{}, []string{}, []string{}
  481. for _, vv := range v.Keys {
  482. keys = append(keys, SpaceReg.Split(strings.TrimSpace(vv), -1)...)
  483. }
  484. for _, vv := range v.AppendKeys {
  485. appendKeys = append(appendKeys, SpaceReg.Split(strings.TrimSpace(vv), -1)...)
  486. }
  487. for _, vv := range v.NotKeys {
  488. notKeys = append(notKeys, SpaceReg.Split(strings.TrimSpace(vv), -1)...)
  489. }
  490. v.Keys = keys
  491. v.AppendKeys = appendKeys
  492. v.NotKeys = notKeys
  493. }
  494. return keySets, err
  495. }
  496. type Entniche struct {
  497. EntId int //企业id
  498. EntName string //企业名称
  499. DeptId int //部门id
  500. DisId string //分发id
  501. UserId int
  502. Unique string
  503. OnlyPush int
  504. IsNew int
  505. PowerSource int //权益来源
  506. ProductType string //产品类型
  507. Mail string //邮箱
  508. IsDis int //是否是分发
  509. DisMember int //分发-超级订阅
  510. DisVip int //分发-大会员
  511. }
  512. // 用户基本信息-扩展
  513. type UserInfoExtend struct {
  514. CreateTime int64 //
  515. Size int
  516. }
  517. func (u *UserInfo) Add(k string, m *map[string]map[*UserInfo]bool) {
  518. mk := (*m)[k]
  519. if mk == nil {
  520. mk = map[*UserInfo]bool{}
  521. }
  522. mk[u] = true
  523. (*m)[k] = mk
  524. }
  525. // 添加信息类型映射关系
  526. func (u *UserInfo) AddSbuype(m *map[string]map[*UserInfo]bool) {
  527. if len(u.SubSet.Subtypes) == 0 {
  528. u.Add("", m)
  529. } else {
  530. for _, v := range u.SubSet.Subtypes {
  531. u.Add(v, m)
  532. }
  533. }
  534. }
  535. // 添加采购单位类型映射关系
  536. func (u *UserInfo) AddBuyerclass(m *map[string]map[*UserInfo]bool) {
  537. //如果有关键词 有采购单位行业,行业加上“其它”
  538. if len(u.SubSet.Buyerclasss) == 0 {
  539. u.Add("", m)
  540. } else {
  541. if u.SubSet.Matchbuyerclass_other == 1 && len(u.SubSet.Keys) > 0 {
  542. u.Add("其它", m)
  543. }
  544. for _, v := range u.SubSet.Buyerclasss {
  545. u.Add(v, m)
  546. }
  547. }
  548. }
  549. // 添加区域映射关系
  550. func (u *UserInfo) AddArea(m *map[string]map[*UserInfo]bool) {
  551. if len(u.SubSet.Areas) == 0 {
  552. u.Add("", m)
  553. } else {
  554. for _, v := range u.SubSet.Areas {
  555. u.Add(v, m)
  556. }
  557. }
  558. }
  559. // 添加区域城市映射关系
  560. func (u *UserInfo) AddAreaCity(area, city *map[string]map[*UserInfo]bool) {
  561. if len(u.SubSet.Area) == 0 {
  562. u.Add("", area)
  563. } else {
  564. for k, v := range u.SubSet.Area {
  565. if k == "" {
  566. continue
  567. }
  568. vs, _ := v.([]interface{})
  569. if len(vs) == 0 {
  570. u.Add(k, area)
  571. } else {
  572. for _, vv := range vs {
  573. s_vv, _ := vv.(string)
  574. if s_vv == "" {
  575. continue
  576. }
  577. u.Add(s_vv, city)
  578. }
  579. }
  580. }
  581. }
  582. }
  583. // 把用户挂在词下面
  584. func (u *UserInfo) MakeKeyUser(keys []string, key_user *map[string]*[]*UserInfo) {
  585. mp := map[string]bool{}
  586. for _, key := range keys {
  587. v := strings.ToUpper(key)
  588. if v == "" || mp[v] {
  589. continue
  590. }
  591. mp[v] = true
  592. arr := (*key_user)[v]
  593. if arr == nil {
  594. arr = &[]*UserInfo{}
  595. }
  596. *arr = append(*arr, u)
  597. (*key_user)[v] = arr
  598. }
  599. }
  600. type WxTplMsg struct {
  601. Key string
  602. Area string
  603. }
  604. type SortList []*MatchInfo
  605. func (s SortList) Len() int {
  606. return len(s)
  607. }
  608. func (s SortList) Less(i, j int) bool {
  609. return util.Int64All((*s[i].Info)["publishtime"]) > util.Int64All((*s[j].Info)["publishtime"])
  610. }
  611. func (s SortList) Swap(i, j int) {
  612. s[i], s[j] = s[j], s[i]
  613. }
  614. type CSortList []map[string]interface{}
  615. func (s CSortList) Len() int {
  616. return len(s)
  617. }
  618. func (s CSortList) Less(i, j int) bool {
  619. return util.Int64All(s[i]["publishtime"]) > util.Int64All(s[j]["publishtime"])
  620. }
  621. func (s CSortList) Swap(i, j int) {
  622. s[i], s[j] = s[j], s[i]
  623. }
  624. type MatchInfo struct {
  625. Info *map[string]interface{}
  626. Keys []string
  627. Items []string
  628. MatchWays []string
  629. DisId string
  630. }
  631. type KeyDfa struct {
  632. Key *dfa.DFA
  633. NotKey *dfa.DFA
  634. Key_user *map[string]*[]*UserInfo
  635. Notkey_user *map[string]*[]*UserInfo
  636. }
  637. // 所有用户的关键词和排除词
  638. func (p *KeyDfa) CreateDaf() {
  639. //关键词
  640. p.Key = &dfa.DFA{}
  641. keys := make([]string, 0)
  642. for k, _ := range *p.Key_user {
  643. keys = append(keys, k)
  644. }
  645. p.Key.AddWord(keys...)
  646. //排除关键词
  647. p.NotKey = &dfa.DFA{}
  648. notKeys := make([]string, 0)
  649. for k, _ := range *p.Notkey_user {
  650. notKeys = append(notKeys, k)
  651. }
  652. p.NotKey.AddWord(notKeys...)
  653. }
  654. type MatchUser struct {
  655. Keys []string
  656. Items []string
  657. Item map[string]bool
  658. MatchWays []string
  659. MatchWay map[string]bool
  660. }
  661. type RelationProjectUser struct {
  662. TopTypes []string
  663. }
  664. type PushInfo struct {
  665. Ids []interface{}
  666. Info map[string]interface{}
  667. }
  668. // 推送返回结果
  669. type PushResult struct {
  670. WxStatus int
  671. AppStatus int
  672. MailStatus int
  673. PushDate int64
  674. Infos *SortList
  675. }
  676. type PushParam struct {
  677. JpushTitle string
  678. LastInfoDate int64
  679. TitleArray []string
  680. Infos *SortList
  681. InfosLength int
  682. MailHtml string
  683. PushDate int64
  684. PushCount int
  685. IsPush bool
  686. }
  687. type BiddingInfo struct {
  688. Id string
  689. Title string
  690. ClearTitle string
  691. HighlightTitle string
  692. AreaTitle string
  693. Area string
  694. Publishtime int64
  695. PublishtimeDiff string
  696. PublishtimeYMD string
  697. Buyerclass string
  698. Subscopeclass string
  699. Bidamount interface{}
  700. Budget interface{}
  701. Acount string
  702. Subtype string
  703. Toptype string
  704. Infotype string
  705. }
  706. // 身份信息
  707. type IdentityInfo struct {
  708. Name string
  709. PersonId int64
  710. UserName string
  711. AccountId int64
  712. EntAccountId int64
  713. PositionId int64
  714. PositionType int64
  715. EntId int64
  716. EntUserId int64
  717. EntUserName string
  718. UserId int64
  719. }