struct.go 21 KB

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