struct.go 24 KB

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