struct.go 21 KB

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