struct.go 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. package p
  2. import (
  3. "strings"
  4. util "app.yhyue.com/moapp/jybase/common"
  5. "bp.jydev.jianyu360.cn/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. IsMainAccount bool //是否是主账号
  100. SonAccountStatus int //子账号状态 0-禁用 1-启用
  101. MainId string //主账号id
  102. Entniche *Entniche
  103. MemberMainid string
  104. WxTplMsg *WxTplMsg
  105. SubSet *SubSet
  106. Extend *UserInfoExtend
  107. }
  108. //
  109. type Entniche struct {
  110. EntId int //企业id
  111. EntName string //企业名称
  112. DeptId int //部门id
  113. //DeptName string //部门名称
  114. DisId string //分发id
  115. UserId int
  116. Unique string
  117. OnlyPush int
  118. IsNew int
  119. PowerSource int //权益来源
  120. ProductType string //产品类型
  121. Mail string //邮箱
  122. IsDis int //是否是分发
  123. DisMember int //分发-超级订阅
  124. DisVip int //分发-大会员
  125. }
  126. //用户基本信息-扩展
  127. type UserInfoExtend struct {
  128. CreateTime int64 //
  129. Size int
  130. }
  131. func (u *UserInfo) Add(k string, m *map[string]map[*UserInfo]bool) {
  132. mk := (*m)[k]
  133. if mk == nil {
  134. mk = map[*UserInfo]bool{}
  135. }
  136. mk[u] = true
  137. (*m)[k] = mk
  138. }
  139. //添加信息类型映射关系
  140. func (u *UserInfo) AddSbuype(m *map[string]map[*UserInfo]bool) {
  141. if len(u.SubSet.Subtypes) == 0 {
  142. u.Add("", m)
  143. } else {
  144. for _, v := range u.SubSet.Subtypes {
  145. u.Add(v, m)
  146. }
  147. }
  148. }
  149. //添加采购单位类型映射关系
  150. func (u *UserInfo) AddBuyerclass(m *map[string]map[*UserInfo]bool) {
  151. //如果有关键词 有采购单位行业,行业加上“其它”
  152. if len(u.SubSet.Buyerclasss) == 0 {
  153. u.Add("", m)
  154. } else {
  155. if u.SubSet.Matchbuyerclass_other == 1 && len(u.SubSet.Keys) > 0 {
  156. u.Add("其它", m)
  157. }
  158. for _, v := range u.SubSet.Buyerclasss {
  159. u.Add(v, m)
  160. }
  161. }
  162. }
  163. //添加区域映射关系
  164. func (u *UserInfo) AddArea(m *map[string]map[*UserInfo]bool) {
  165. if len(u.SubSet.Areas) == 0 {
  166. u.Add("", m)
  167. } else {
  168. for _, v := range u.SubSet.Areas {
  169. u.Add(v, m)
  170. }
  171. }
  172. }
  173. //添加区域城市映射关系
  174. func (u *UserInfo) AddAreaCity(area, city *map[string]map[*UserInfo]bool) {
  175. if len(u.SubSet.Area) == 0 {
  176. u.Add("", area)
  177. } else {
  178. for k, v := range u.SubSet.Area {
  179. if k == "" {
  180. continue
  181. }
  182. vs, _ := v.([]interface{})
  183. if len(vs) == 0 {
  184. u.Add(k, area)
  185. } else {
  186. for _, vv := range vs {
  187. s_vv, _ := vv.(string)
  188. if s_vv == "" {
  189. continue
  190. }
  191. u.Add(s_vv, city)
  192. }
  193. }
  194. }
  195. }
  196. }
  197. //把用户挂在词下面
  198. func (u *UserInfo) MakeKeyUser(keys []string, key_user *map[string]*[]*UserInfo) {
  199. mp := map[string]bool{}
  200. for _, key := range keys {
  201. v := strings.ToUpper(key)
  202. if v == "" || mp[v] {
  203. continue
  204. }
  205. mp[v] = true
  206. arr := (*key_user)[v]
  207. if arr == nil {
  208. arr = &[]*UserInfo{}
  209. }
  210. *arr = append(*arr, u)
  211. (*key_user)[v] = arr
  212. }
  213. }
  214. type WxTplMsg struct {
  215. Key string
  216. Area string
  217. }
  218. type SortList []*MatchInfo
  219. func (s SortList) Len() int {
  220. return len(s)
  221. }
  222. func (s SortList) Less(i, j int) bool {
  223. return util.Int64All((*s[i].Info)["publishtime"]) > util.Int64All((*s[j].Info)["publishtime"])
  224. }
  225. func (s SortList) Swap(i, j int) {
  226. s[i], s[j] = s[j], s[i]
  227. }
  228. type CSortList []map[string]interface{}
  229. func (s CSortList) Len() int {
  230. return len(s)
  231. }
  232. func (s CSortList) Less(i, j int) bool {
  233. return util.Int64All(s[i]["publishtime"]) > util.Int64All(s[j]["publishtime"])
  234. }
  235. func (s CSortList) Swap(i, j int) {
  236. s[i], s[j] = s[j], s[i]
  237. }
  238. type MatchInfo struct {
  239. Info *map[string]interface{}
  240. Keys []string
  241. Items []string
  242. MatchWays []string
  243. DisId string
  244. }
  245. type KeyDfa struct {
  246. Key *dfa.DFA
  247. NotKey *dfa.DFA
  248. Key_user *map[string]*[]*UserInfo
  249. Notkey_user *map[string]*[]*UserInfo
  250. }
  251. //所有用户的关键词和排除词
  252. func (p *KeyDfa) CreateDaf() {
  253. //关键词
  254. p.Key = &dfa.DFA{}
  255. keys := make([]string, 0)
  256. for k, _ := range *p.Key_user {
  257. keys = append(keys, k)
  258. }
  259. p.Key.AddWord(keys...)
  260. //排除关键词
  261. p.NotKey = &dfa.DFA{}
  262. notKeys := make([]string, 0)
  263. for k, _ := range *p.Notkey_user {
  264. notKeys = append(notKeys, k)
  265. }
  266. p.NotKey.AddWord(notKeys...)
  267. }
  268. //
  269. type MatchUser struct {
  270. Keys []string
  271. MatchWays []string
  272. MatchWay map[string]bool
  273. }
  274. //
  275. type RelationProjectUser struct {
  276. TopTypes []string
  277. }
  278. //
  279. type PushInfo struct {
  280. Ids []interface{}
  281. Info map[string]interface{}
  282. }
  283. //推送返回结果
  284. type PushResult struct {
  285. WxStatus int
  286. AppStatus int
  287. MailStatus int
  288. PushDate int64
  289. Infos *SortList
  290. }
  291. //
  292. type PushWay struct {
  293. WxPush bool
  294. AppPush bool
  295. MailPush bool
  296. }
  297. //
  298. type PushParam struct {
  299. JpushTitle string
  300. LastInfoDate int64
  301. TitleArray []string
  302. Infos *SortList
  303. InfosLength int
  304. MailHtml string
  305. PushDate int64
  306. PushCount int
  307. IsPush bool
  308. }
  309. //
  310. type BiddingInfo struct {
  311. Id string
  312. Title string
  313. ClearTitle string
  314. HighlightTitle string
  315. AreaTitle string
  316. Area string
  317. Publishtime int64
  318. PublishtimeDiff string
  319. PublishtimeYMD string
  320. Buyerclass string
  321. Subscopeclass string
  322. Bidamount interface{}
  323. Budget interface{}
  324. Acount string
  325. Subtype string
  326. Toptype string
  327. Infotype string
  328. }