struct.go 26 KB

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