struct.go 24 KB

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