struct.go 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. package p
  2. import (
  3. "strings"
  4. util "app.yhyue.com/moapp/jybase/common"
  5. "bp.jydev.jianyu360.cn/BaseService/pushpkg/dfa"
  6. )
  7. //
  8. type MgoConf struct {
  9. Address string
  10. Size int
  11. DbName string
  12. ReplSet string
  13. UserName string
  14. Password string
  15. Collection string
  16. ExperienceDbName string
  17. }
  18. //
  19. type RedisConf struct {
  20. Address string
  21. }
  22. //
  23. type MysqlConf struct {
  24. DbName string
  25. Address string
  26. UserName string
  27. PassWord string
  28. MaxOpenConns int
  29. MaxIdleConns int
  30. }
  31. //
  32. type EsConf struct {
  33. Address string
  34. Size int
  35. }
  36. //
  37. type MemberService struct {
  38. IsBuy bool
  39. Services map[int]*memberService
  40. }
  41. //
  42. type memberService struct {
  43. Id int
  44. StartTime string
  45. }
  46. //关键词
  47. type KeySet struct {
  48. Item string `json:"item"` //分类名称
  49. Keys []string `json:"key"` //关键词
  50. NotKeys []string `json:"notkey"` //排除词
  51. SubTypes []string `json:"infotype"` //信息类型
  52. Areas []string `json:"area"` //地区
  53. AppendKeys []string `json:"appendkey"` //附加词
  54. MatchWay int `json:"matchway"` //匹配模式 0:精准匹配 1:模糊匹配
  55. }
  56. //解析订阅词
  57. type SubSet struct {
  58. WxPush int //是否开启微信推送
  59. AppPush int //是否开启app推送
  60. MailPush int //是否开启邮箱推送
  61. RateMode int //推送时间
  62. Email string //邮箱
  63. MatchWay int //匹配方式 1-标题 2-正文
  64. Matchbuyerclass_other int //是否开启其他按钮
  65. ProjectMatch int //项目关联推送
  66. Items []string //关键词分类
  67. Keys []string //过滤后的关键词
  68. Notkeys []string //排除词
  69. Key_item map[string]string //关键词对应的分类名称
  70. Key_notkey map[string]map[string]bool //关键词所对应的排除词
  71. Key_area map[string]map[string]bool //关键词所对应的信息范围
  72. Key_subtype map[string]map[string]bool //关键词所对应的信息类型
  73. OriginalKeys []string //原始关键词
  74. Areas []string //区域-省份
  75. Area map[string]interface{} //区域-省份
  76. Subtype []interface{} //信息类型-二级分类
  77. Subtypes []string //信息类型-二级分类
  78. Buyerclass []interface{} //采购单位行业
  79. Buyerclasss []string //采购单位行业
  80. IsUpgrade bool //免费用户是否订阅升级
  81. MaxPushSize int //推送最大条数
  82. MaxMailSize int //邮件最大条数
  83. }
  84. //用户基本信息
  85. type UserInfo struct {
  86. Id string //mongoid
  87. BaseUserId int64 //mysql用户id
  88. S_m_openid string //公众号openid
  89. A_m_openid string //app微信登录openid
  90. Phone string //app手机号登录
  91. Jpushid string //极光推送id
  92. Opushid string //厂商推送id
  93. AppPhoneType string //手机型号
  94. ApplyStatus int //是否申请打开订阅推送
  95. Subscribe int //是否关注
  96. UserType int //用户类型
  97. VipStatus int //超级订阅 1--试用 2--正式
  98. MemberStatus int //大会员
  99. NicheStatus int //商机管理
  100. IsMainAccount bool //是否是主账号
  101. SonAccountStatus int //子账号状态 0-禁用 1-启用
  102. MainId string //主账号id
  103. Entniche *Entniche
  104. MemberMainid string
  105. WxTplMsg *WxTplMsg
  106. SubSet *SubSet
  107. Extend *UserInfoExtend
  108. }
  109. //
  110. type Entniche struct {
  111. EntId int //企业id
  112. EntName string //企业名称
  113. DeptId int //部门id
  114. //DeptName string //部门名称
  115. DisId string //分发id
  116. UserId int
  117. Unique string
  118. OnlyPush int
  119. IsNew int
  120. PowerSource int //权益来源
  121. ProductType string //产品类型
  122. Mail string //邮箱
  123. IsDis int //是否是分发
  124. DisMember int //分发-超级订阅
  125. DisVip int //分发-大会员
  126. }
  127. //用户基本信息-扩展
  128. type UserInfoExtend struct {
  129. CreateTime int64 //
  130. Size int
  131. }
  132. func (u *UserInfo) Add(k string, m *map[string]map[*UserInfo]bool) {
  133. mk := (*m)[k]
  134. if mk == nil {
  135. mk = map[*UserInfo]bool{}
  136. }
  137. mk[u] = true
  138. (*m)[k] = mk
  139. }
  140. //添加信息类型映射关系
  141. func (u *UserInfo) AddSbuype(m *map[string]map[*UserInfo]bool) {
  142. if len(u.SubSet.Subtypes) == 0 {
  143. u.Add("", m)
  144. } else {
  145. for _, v := range u.SubSet.Subtypes {
  146. u.Add(v, m)
  147. }
  148. }
  149. }
  150. //添加采购单位类型映射关系
  151. func (u *UserInfo) AddBuyerclass(m *map[string]map[*UserInfo]bool) {
  152. //如果有关键词 有采购单位行业,行业加上“其它”
  153. if len(u.SubSet.Buyerclasss) == 0 {
  154. u.Add("", m)
  155. } else {
  156. if u.SubSet.Matchbuyerclass_other == 1 && len(u.SubSet.Keys) > 0 {
  157. u.Add("其它", m)
  158. }
  159. for _, v := range u.SubSet.Buyerclasss {
  160. u.Add(v, m)
  161. }
  162. }
  163. }
  164. //添加区域映射关系
  165. func (u *UserInfo) AddArea(m *map[string]map[*UserInfo]bool) {
  166. if len(u.SubSet.Areas) == 0 {
  167. u.Add("", m)
  168. } else {
  169. for _, v := range u.SubSet.Areas {
  170. u.Add(v, m)
  171. }
  172. }
  173. }
  174. //添加区域城市映射关系
  175. func (u *UserInfo) AddAreaCity(area, city *map[string]map[*UserInfo]bool) {
  176. if len(u.SubSet.Area) == 0 {
  177. u.Add("", area)
  178. } else {
  179. for k, v := range u.SubSet.Area {
  180. if k == "" {
  181. continue
  182. }
  183. vs, _ := v.([]interface{})
  184. if len(vs) == 0 {
  185. u.Add(k, area)
  186. } else {
  187. for _, vv := range vs {
  188. s_vv, _ := vv.(string)
  189. if s_vv == "" {
  190. continue
  191. }
  192. u.Add(s_vv, city)
  193. }
  194. }
  195. }
  196. }
  197. }
  198. //把用户挂在词下面
  199. func (u *UserInfo) MakeKeyUser(keys []string, key_user *map[string]*[]*UserInfo) {
  200. mp := map[string]bool{}
  201. for _, key := range keys {
  202. v := strings.ToUpper(key)
  203. if v == "" || mp[v] {
  204. continue
  205. }
  206. mp[v] = true
  207. arr := (*key_user)[v]
  208. if arr == nil {
  209. arr = &[]*UserInfo{}
  210. }
  211. *arr = append(*arr, u)
  212. (*key_user)[v] = arr
  213. }
  214. }
  215. type WxTplMsg struct {
  216. Key string
  217. Area string
  218. }
  219. type SortList []*MatchInfo
  220. func (s SortList) Len() int {
  221. return len(s)
  222. }
  223. func (s SortList) Less(i, j int) bool {
  224. return util.Int64All((*s[i].Info)["publishtime"]) > util.Int64All((*s[j].Info)["publishtime"])
  225. }
  226. func (s SortList) Swap(i, j int) {
  227. s[i], s[j] = s[j], s[i]
  228. }
  229. type CSortList []map[string]interface{}
  230. func (s CSortList) Len() int {
  231. return len(s)
  232. }
  233. func (s CSortList) Less(i, j int) bool {
  234. return util.Int64All(s[i]["publishtime"]) > util.Int64All(s[j]["publishtime"])
  235. }
  236. func (s CSortList) Swap(i, j int) {
  237. s[i], s[j] = s[j], s[i]
  238. }
  239. type MatchInfo struct {
  240. Info *map[string]interface{}
  241. Keys []string
  242. Items []string
  243. MatchWays []string
  244. DisId string
  245. }
  246. type KeyDfa struct {
  247. Key *dfa.DFA
  248. NotKey *dfa.DFA
  249. Key_user *map[string]*[]*UserInfo
  250. Notkey_user *map[string]*[]*UserInfo
  251. }
  252. //所有用户的关键词和排除词
  253. func (p *KeyDfa) CreateDaf() {
  254. //关键词
  255. p.Key = &dfa.DFA{}
  256. keys := make([]string, 0)
  257. for k, _ := range *p.Key_user {
  258. keys = append(keys, k)
  259. }
  260. p.Key.AddWord(keys...)
  261. //排除关键词
  262. p.NotKey = &dfa.DFA{}
  263. notKeys := make([]string, 0)
  264. for k, _ := range *p.Notkey_user {
  265. notKeys = append(notKeys, k)
  266. }
  267. p.NotKey.AddWord(notKeys...)
  268. }
  269. //
  270. type MatchUser struct {
  271. Keys []string
  272. MatchWays []string
  273. MatchWay map[string]bool
  274. }
  275. //
  276. type RelationProjectUser struct {
  277. TopTypes []string
  278. }
  279. //
  280. type PushInfo struct {
  281. Ids []interface{}
  282. Info map[string]interface{}
  283. }
  284. //推送返回结果
  285. type PushResult struct {
  286. WxStatus int
  287. AppStatus int
  288. MailStatus int
  289. PushDate int64
  290. Infos *SortList
  291. }
  292. //
  293. type PushWay struct {
  294. WxPush bool
  295. AppPush bool
  296. MailPush bool
  297. }
  298. //
  299. type PushParam struct {
  300. JpushTitle string
  301. LastInfoDate int64
  302. TitleArray []string
  303. Infos *SortList
  304. InfosLength int
  305. MailHtml string
  306. PushDate int64
  307. PushCount int
  308. IsPush bool
  309. }
  310. //
  311. type BiddingInfo struct {
  312. Id string
  313. Title string
  314. ClearTitle string
  315. HighlightTitle string
  316. AreaTitle string
  317. Area string
  318. Publishtime int64
  319. PublishtimeDiff string
  320. PublishtimeYMD string
  321. Buyerclass string
  322. Subscopeclass string
  323. Bidamount interface{}
  324. Budget interface{}
  325. Acount string
  326. Subtype string
  327. Toptype string
  328. Infotype string
  329. }