struct.go 26 KB

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