struct.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  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. District map[string]interface{} //区域-区县
  73. Subtype []interface{} //信息类型-二级分类
  74. Subtypes []string //信息类型-二级分类
  75. Buyerclass []interface{} //采购单位行业
  76. Buyerclasss []string //采购单位行业
  77. IsUpgrade bool //免费用户是否订阅升级
  78. MaxPushSize int //推送最大条数
  79. MaxMailSize int //邮件最大条数
  80. }
  81. // 推送设置
  82. type PushSet struct {
  83. Email string //邮箱
  84. SubSet *PushSetChild //订阅推送设置
  85. WeekReport *PushSetChild //周报推送设置
  86. MonthReport *PushSetChild //月报推送设置
  87. NewprojectForecast *PushSetChild //潜在项目预测推送设置
  88. EntInfo *PushSetChild //企业情报监控-企业工商变动推送设置
  89. FollowProject *PushSetChild //项目进度监控推送设置
  90. FollowEnt *PushSetChild //企业情报监控-企业中标动态推送设置
  91. }
  92. func (p *PushSet) ResetSubSet() {
  93. if p.SubSet == nil {
  94. return
  95. }
  96. if p.SubSet.RateMode == 0 || p.SubSet.RateMode == 5 {
  97. p.SubSet.RateMode = 2
  98. if len(p.SubSet.Times) == 0 {
  99. p.SubSet.Times = append(p.SubSet.Times, "09:00", "14:00")
  100. }
  101. } else if p.SubSet.RateMode == 2 && len(p.SubSet.Times) == 0 {
  102. p.SubSet.Times = append(p.SubSet.Times, "09:00")
  103. }
  104. sort.Strings(p.SubSet.Times)
  105. }
  106. type PushSetChild struct {
  107. RateMode int //推送时间
  108. Times []string //自定义推送时间
  109. WxPush int //是否开启微信推送
  110. AppPush int //是否开启app推送
  111. MailPush int //是否开启邮箱推送
  112. Nomsgtip int //是否开启无消息推送提醒
  113. }
  114. // 用户基本信息
  115. type UserInfo struct {
  116. Id string //mongoid
  117. BaseUserId int64 //mysql用户id
  118. S_m_openid string //公众号openid
  119. A_m_openid string //app微信登录openid
  120. Phone string //app手机号登录
  121. Jpushid string //极光推送id
  122. Opushid string //厂商推送id
  123. AppPhoneType string //手机型号
  124. Subscribe int //是否关注
  125. VipStatus int //超级订阅 1--试用 2--正式
  126. MemberStatus int //大会员
  127. NicheStatus int //商机管理
  128. IsMainAccount bool //是否是主账号
  129. SonAccountStatus int //子账号状态 0-禁用 1-启用
  130. MemberMainid string //主账号id
  131. Entniche *Entniche
  132. WxTplMsg *WxTplMsg
  133. SubSet *SubSet
  134. PushSet *PushSet
  135. Extend *UserInfoExtend
  136. }
  137. /*
  138. *获取用户信息
  139. *temp 用户数据
  140. *tp 1-免费 2-超级订阅 3-大会员
  141. */
  142. func NewUserInfo(temp map[string]interface{}, tp int) *UserInfo {
  143. ui := &UserInfo{
  144. Id: BsonIdToSId(temp["_id"]),
  145. BaseUserId: util.Int64All(temp["base_user_id"]),
  146. S_m_openid: util.ObjToString(temp["s_m_openid"]),
  147. A_m_openid: util.ObjToString(temp["a_m_openid"]),
  148. Phone: GetPhone(temp),
  149. Jpushid: util.ObjToString(temp["s_jpushid"]),
  150. Opushid: util.ObjToString(temp["s_opushid"]),
  151. AppPhoneType: util.ObjToString(temp["s_appponetype"]),
  152. Subscribe: util.IntAllDef(temp["i_ispush"], 1),
  153. VipStatus: util.IntAll(temp["i_vip_status"]),
  154. MemberStatus: util.IntAll(temp["i_member_status"]),
  155. }
  156. if ui.MemberStatus > 0 {
  157. ui.IsMainAccount = util.IntAll(temp["i_mainaccount"]) == 1
  158. ui.SonAccountStatus = util.IntAllDef(temp["i_member_sub_status"], -1)
  159. ui.MemberMainid = util.ObjToString(temp["s_member_mainid"])
  160. }
  161. if tp == 3 {
  162. obj, _ := temp["o_member_jy"].(map[string]interface{})
  163. ui.GetSubSet(false, ui.Id, obj)
  164. } else if tp == 2 {
  165. obj, _ := temp["o_vipjy"].(map[string]interface{})
  166. ui.GetSubSet(false, ui.Id, obj)
  167. } else if tp == 1 {
  168. obj, _ := temp["o_jy"].(map[string]interface{})
  169. ui.GetSubSet(true, ui.Id, obj)
  170. }
  171. o_pushset, _ := temp["o_pushset"].(map[string]interface{})
  172. ui.GetPushSet(o_pushset)
  173. ui.PushSetFilter()
  174. return ui
  175. }
  176. // 解析用户的推送设置
  177. func (u *UserInfo) GetPushSet(obj map[string]interface{}) {
  178. subSet, _ := obj["o_subset"].(map[string]interface{})
  179. times, _ := subSet["a_times"].([]interface{})
  180. weekReport, _ := obj["o_week_report"].(map[string]interface{})
  181. monthReport, _ := obj["o_month_report"].(map[string]interface{})
  182. newprojectForecast, _ := obj["o_newproject_forecast"].(map[string]interface{})
  183. entInfo, _ := obj["o_entinfo"].(map[string]interface{})
  184. followProject, _ := obj["o_follow_project"].(map[string]interface{})
  185. followEnt, _ := obj["o_follow_ent"].(map[string]interface{})
  186. u.PushSet = &PushSet{
  187. Email: strings.TrimSpace(util.ObjToString(obj["s_email"])),
  188. SubSet: &PushSetChild{
  189. WxPush: util.IntAllDef(subSet["i_wxpush"], 1),
  190. AppPush: util.IntAllDef(subSet["i_apppush"], 0),
  191. MailPush: util.IntAll(subSet["i_mailpush"]),
  192. RateMode: util.IntAll(subSet["i_ratemode"]),
  193. Times: util.ObjArrToStringArr(times),
  194. Nomsgtip: util.IntAllDef(subSet["i_nomsgtip"], 1), //默认开启
  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. subSet.District, _ = obj["o_district"].(map[string]interface{})
  385. }
  386. for _, v := range subSet.Buyerclass {
  387. s_v, _ := v.(string)
  388. if s_v == "" {
  389. continue
  390. }
  391. subSet.Buyerclasss = append(subSet.Buyerclasss, s_v)
  392. }
  393. for _, v := range subSet.Subtype {
  394. s_v, _ := v.(string)
  395. if s_v == "" {
  396. continue
  397. }
  398. subSet.Subtypes = append(subSet.Subtypes, s_v)
  399. }
  400. for area, _ := range subSet.Area {
  401. if area == "" {
  402. continue
  403. }
  404. subSet.Areas = append(subSet.Areas, area)
  405. }
  406. ////////////////
  407. for _, vs := range keySets {
  408. if vs == nil {
  409. logger.Error(userId, "关键词设置异常")
  410. continue
  411. }
  412. var vs_keys []string
  413. for _, vs_v := range [][]string{vs.Keys, vs.AppendKeys} {
  414. for _, vs_vv := range vs_v {
  415. vs_vv = strings.TrimSpace(vs_vv)
  416. if vs_vv == "" {
  417. continue
  418. }
  419. vs_keys = append(vs_keys, vs_vv)
  420. }
  421. }
  422. if len(vs_keys) == 0 {
  423. continue
  424. }
  425. key := strings.Join(vs_keys, "+")
  426. subSet.OriginalKeys = append(subSet.OriginalKeys, key)
  427. if KeyFilterReg.MatchString(key) {
  428. continue
  429. } else if !KeyRetainReg.MatchString(key) {
  430. continue
  431. }
  432. subSet.Keys = append(subSet.Keys, key)
  433. subSet.Notkeys = append(subSet.Notkeys, vs.NotKeys...)
  434. //转大写
  435. upperKey := strings.ToUpper(key)
  436. subSet.Key_item[upperKey] = vs.Item
  437. //建立与排除词的对应关系
  438. for _, notkey := range vs.NotKeys {
  439. upperNotkey := strings.ToUpper(notkey)
  440. if subSet.Key_notkey[upperKey] == nil {
  441. subSet.Key_notkey[upperKey] = map[string]bool{}
  442. }
  443. subSet.Key_notkey[upperKey][upperNotkey] = true
  444. }
  445. //免费用户需要进行映射
  446. if isFreeUser {
  447. //建立与信息范围的对应关系
  448. for _, area := range vs.Areas {
  449. if subSet.Key_area[upperKey] == nil {
  450. subSet.Key_area[upperKey] = map[string]bool{}
  451. }
  452. subSet.Key_area[upperKey][area] = true
  453. }
  454. //建立与信息类型的对应关系
  455. for _, subtype := range vs.SubTypes {
  456. if subSet.Key_subtype[upperKey] == nil {
  457. subSet.Key_subtype[upperKey] = map[string]bool{}
  458. }
  459. subSet.Key_subtype[upperKey][subtype] = true
  460. }
  461. }
  462. }
  463. u.SubSet = subSet
  464. }
  465. // 得到用户的关键词
  466. func (u *UserInfo) GetKeySets(a_key interface{}) ([]*KeySet, error) {
  467. var keySets []*KeySet
  468. if a_key == nil {
  469. return keySets, nil
  470. }
  471. _bs, err := json.Marshal(a_key)
  472. if err == nil {
  473. err = json.Unmarshal(_bs, &keySets)
  474. }
  475. if err != nil {
  476. return keySets, err
  477. }
  478. for _, v := range keySets {
  479. if v == nil {
  480. continue
  481. }
  482. keys, appendKeys, notKeys := []string{}, []string{}, []string{}
  483. for _, vv := range v.Keys {
  484. keys = append(keys, SpaceReg.Split(strings.TrimSpace(vv), -1)...)
  485. }
  486. for _, vv := range v.AppendKeys {
  487. appendKeys = append(appendKeys, SpaceReg.Split(strings.TrimSpace(vv), -1)...)
  488. }
  489. for _, vv := range v.NotKeys {
  490. notKeys = append(notKeys, SpaceReg.Split(strings.TrimSpace(vv), -1)...)
  491. }
  492. v.Keys = keys
  493. v.AppendKeys = appendKeys
  494. v.NotKeys = notKeys
  495. }
  496. return keySets, err
  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) AddAreaCityDistrict(area, city *map[string]map[*UserInfo]bool, district *map[string]map[string]map[*UserInfo]bool) {
  587. if len(u.SubSet.Area) == 0 {
  588. u.Add("", area)
  589. } else {
  590. for k, v := range u.SubSet.Area {
  591. if k == "" {
  592. continue
  593. }
  594. vs, _ := v.([]interface{})
  595. if len(vs) == 0 {
  596. u.Add(k, area)
  597. } else {
  598. for _, vv := range vs {
  599. s_vv, _ := vv.(string)
  600. if s_vv == "" {
  601. continue
  602. }
  603. d_vv, _ := u.SubSet.District[s_vv].([]interface{})
  604. if len(d_vv) == 0 {
  605. u.Add(s_vv, city)
  606. } else {
  607. for _, vvv := range d_vv {
  608. s_vvv, _ := vvv.(string)
  609. if s_vvv == "" {
  610. continue
  611. }
  612. d_mm := (*district)[s_vv]
  613. if d_mm == nil {
  614. d_mm = map[string]map[*UserInfo]bool{}
  615. }
  616. u.Add(s_vvv, &d_mm)
  617. (*district)[s_vv] = d_mm
  618. }
  619. }
  620. }
  621. }
  622. }
  623. }
  624. }
  625. // 把用户挂在词下面
  626. func (u *UserInfo) MakeKeyUser(keys []string, key_user *map[string]*[]*UserInfo) {
  627. mp := map[string]bool{}
  628. for _, key := range keys {
  629. v := strings.ToUpper(key)
  630. if v == "" || mp[v] {
  631. continue
  632. }
  633. mp[v] = true
  634. arr := (*key_user)[v]
  635. if arr == nil {
  636. arr = &[]*UserInfo{}
  637. }
  638. *arr = append(*arr, u)
  639. (*key_user)[v] = arr
  640. }
  641. }
  642. type WxTplMsg struct {
  643. Key string
  644. Area string
  645. }
  646. type SortList []*MatchInfo
  647. func (s SortList) Len() int {
  648. return len(s)
  649. }
  650. func (s SortList) Less(i, j int) bool {
  651. return util.Int64All((*s[i].Info)["publishtime"]) > util.Int64All((*s[j].Info)["publishtime"])
  652. }
  653. func (s SortList) Swap(i, j int) {
  654. s[i], s[j] = s[j], s[i]
  655. }
  656. type CSortList []map[string]interface{}
  657. func (s CSortList) Len() int {
  658. return len(s)
  659. }
  660. func (s CSortList) Less(i, j int) bool {
  661. return util.Int64All(s[i]["publishtime"]) > util.Int64All(s[j]["publishtime"])
  662. }
  663. func (s CSortList) Swap(i, j int) {
  664. s[i], s[j] = s[j], s[i]
  665. }
  666. type MatchInfo struct {
  667. Info *map[string]interface{}
  668. Keys []string
  669. Items []string
  670. MatchWays []string
  671. DisId string
  672. HandDis bool //是否分发
  673. }
  674. type KeyDfa struct {
  675. Key *dfa.DFA
  676. NotKey *dfa.DFA
  677. Key_user *map[string]*[]*UserInfo
  678. Notkey_user *map[string]*[]*UserInfo
  679. }
  680. // 所有用户的关键词和排除词
  681. func (p *KeyDfa) CreateDaf() {
  682. //关键词
  683. p.Key = &dfa.DFA{}
  684. keys := make([]string, 0)
  685. for k, _ := range *p.Key_user {
  686. keys = append(keys, k)
  687. }
  688. p.Key.AddWord(keys...)
  689. //排除关键词
  690. p.NotKey = &dfa.DFA{}
  691. notKeys := make([]string, 0)
  692. for k, _ := range *p.Notkey_user {
  693. notKeys = append(notKeys, k)
  694. }
  695. p.NotKey.AddWord(notKeys...)
  696. }
  697. type MatchUser struct {
  698. Keys []string
  699. Items []string
  700. Item map[string]bool
  701. MatchWays []string
  702. MatchWay map[string]bool
  703. }
  704. type RelationProjectUser struct {
  705. TopTypes []string
  706. }
  707. type PushInfo struct {
  708. Ids []interface{}
  709. Info map[string]interface{}
  710. }
  711. // 推送返回结果
  712. type PushResult struct {
  713. WxStatus int
  714. AppStatus int
  715. MailStatus int
  716. PushDate int64
  717. Infos *SortList
  718. }
  719. type PushParam struct {
  720. JpushTitle string
  721. LastInfoDate int64
  722. TitleArray []string
  723. Infos *SortList
  724. InfosLength int
  725. MailHtml string
  726. PushDate int64
  727. PushCount int
  728. IsPush bool
  729. }
  730. type BiddingInfo struct {
  731. Id string
  732. Title string
  733. ClearTitle string
  734. HighlightTitle string
  735. AreaTitle string
  736. Area string
  737. Publishtime int64
  738. PublishtimeDiff string
  739. PublishtimeYMD string
  740. Buyerclass string
  741. Subscopeclass string
  742. Bidamount interface{}
  743. Budget interface{}
  744. Acount string
  745. Subtype string
  746. Toptype string
  747. Infotype string
  748. }
  749. // 身份信息
  750. type IdentityInfo struct {
  751. Name string
  752. PersonId int64
  753. UserName string
  754. AccountId int64
  755. EntAccountId int64
  756. PositionId int64
  757. PositionType int64
  758. EntId int64
  759. EntUserId int64
  760. EntUserName string
  761. UserId int64
  762. }