push.go 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975
  1. package model
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. IC "jyBXSubscribe/rpc/init"
  6. ms "jyBXSubscribe/rpc/model/service"
  7. "jyBXSubscribe/rpc/type/bxsubscribe"
  8. "jyBXSubscribe/rpc/util"
  9. "log"
  10. "strconv"
  11. "strings"
  12. "sync"
  13. "time"
  14. "github.com/gogf/gf/v2/util/gconv"
  15. "app.yhyue.com/moapp/jybase/common"
  16. "app.yhyue.com/moapp/jybase/date"
  17. "app.yhyue.com/moapp/jybase/encrypt"
  18. elastic "app.yhyue.com/moapp/jybase/es"
  19. P "app.yhyue.com/moapp/jybase/mapping"
  20. "app.yhyue.com/moapp/jybase/mongodb"
  21. "app.yhyue.com/moapp/jybase/mysql"
  22. "app.yhyue.com/moapp/jybase/redis"
  23. "github.com/zeromicro/go-zero/core/logx"
  24. "go.mongodb.org/mongo-driver/bson/primitive"
  25. )
  26. const (
  27. pageSize = 100
  28. AllSubPushCacheSize = 200
  29. query = `{"query":{"terms":{"_id":["%s"]}},"_source":["_id","area","city", "publishtime", "s_subscopeclass", "subtype", "title", "toptype", "type", "buyerclass","bidamount","budget","projectname","buyer","bidopentime","s_winner","filetext","spidercode","site","buyertel","buyerperson","agency","agencyperson","agencytel","winnerperson","winnertel","signendtime","bidendtime","entidlist","isValidFile"],"from":0,"size":%d}`
  30. mongodb_fields = `{"_id":1,"area":1,"publishtime":1,"s_subscopeclass":1,"subtype":1,"title":1,"toptype":1,"type":1, "city":1,"buyerclass":1,"budget":1,"bidamount":1,"s_winner":1,"bidopentime":1,"buyer":1,"projectname":1,"filetext":1,"spidercode":1,"site":1,"buyertel":1,"buyerperson":1,"agency":1,"agencyperson":1,"agencytel":1,"winnerperson":1,"winnertel":1,"signendtime":1,"bidendtime":1,"entidlist":1,"isValidFile":1}`
  31. SubFreeFlag = "fType"
  32. SubVipFlag = "vType"
  33. MemberFlag = "mType"
  34. EntnicheFlag = "eType"
  35. oneDay = 24 * 60 * 60
  36. )
  37. var (
  38. ennicheInsertCollKey = []string{"infoid", "matchkeys", "date", "area", "city", "district", "buyerclass", "toptype", "subtype", "subscopeclass", "budget", "bidamount", "attachment_count", "userid", "entid", "deptid", "source", "product"}
  39. subscribeInsertCollKey = []string{"infoid", "matchkeys", "date", "area", "city", "district", "buyerclass", "toptype", "subtype", "subscopeclass", "budget", "bidamount", "attachment_count", "userid", "isvip"}
  40. memberInsertCollKey = []string{"infoid", "matchkeys", "date", "area", "city", "district", "buyerclass", "toptype", "subtype", "subscopeclass", "budget", "bidamount", "attachment_count", "userid"}
  41. )
  42. var aboutDbMsg map[string]*AboutDbMsg = map[string]*AboutDbMsg{
  43. SubFreeFlag: &AboutDbMsg{"push.pushsubscribe", "subpush"},
  44. SubVipFlag: &AboutDbMsg{"push.pushsubscribe", "subpush"},
  45. MemberFlag: &AboutDbMsg{"push.pushmember", "memberpush"},
  46. EntnicheFlag: &AboutDbMsg{"push.pushentniche", "entnichepush"},
  47. }
  48. type AboutDbMsg struct {
  49. MysqlTable string
  50. RedisKeyFlag string
  51. }
  52. type SubPush struct {
  53. Date string
  54. Datas []*bxsubscribe.SubscribeInfo
  55. Count int64
  56. }
  57. type PushCa struct {
  58. Date int64
  59. InfoId string
  60. Visit int
  61. Index int64
  62. Keys []string
  63. Type int
  64. Isvip int
  65. FileExists bool
  66. Source int64
  67. Title string
  68. SourceAll string
  69. }
  70. // 查询参数
  71. type SubPushQueryParam struct {
  72. Mgo_bidding mongodb.MongodbSim //
  73. Bidding string //
  74. Bidding_back string //
  75. UserId string //用户id
  76. PageNum int //页面
  77. PageSize int //每页数量
  78. SelectTime string //时间
  79. Area string //区域
  80. City string //城市
  81. Buyerclass string //采购单位行业
  82. Subtype string //信息类型 二级分类
  83. Subscopeclass string //信息行业
  84. Key string //订阅词
  85. Export bool //导出
  86. EntId string //企业id
  87. Price string //价格
  88. FileExists string //是否有附件;默认全部;1:有附件;-1:无附件
  89. EntUserId string //商机管理用户id
  90. DeptId string //商机管理用户部门id
  91. IsRead string //是否已读
  92. Source string //信息来源
  93. Staffs []string //分发人员
  94. BaseServiceMysql *mysql.Mysql
  95. NewUserId int64
  96. IsEnt bool
  97. SelectInfoIds []string
  98. BuySubject int64
  99. UserType string
  100. PositionType int64
  101. IsPayUser bool // 是否是付费用户
  102. NotReturnCount int64
  103. Item string
  104. SelectKeys []string //关键词
  105. District string
  106. SubPushInactive string // 订阅活跃标记
  107. }
  108. // 关键词参数
  109. type KeyParam struct {
  110. UserId string //用户id
  111. EntUserId string //商机管理用户id
  112. DeptId string //商机管理用户部门id
  113. NewUserId int64
  114. IsEnt bool
  115. VipPower int64
  116. EntId string //企业id
  117. MemberPower int64
  118. PowerSource int64
  119. UserPower int64
  120. PositionType int64
  121. }
  122. func (spqp *SubPushQueryParam) IsEmpty() bool {
  123. return (spqp.SelectTime == "" || spqp.SelectTime == "all") && spqp.Area == "" && spqp.District == "" && spqp.City == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == "" && spqp.Item == "" && spqp.Price == "" && spqp.FileExists == "" && len(spqp.Staffs) == 0 && spqp.Source == "" && spqp.IsRead == ""
  124. }
  125. type subscribePush struct {
  126. ModuleFlag string
  127. }
  128. func NewSubscribePush(module ...string) *subscribePush {
  129. m := ""
  130. if len(module) > 0 {
  131. m = module[0]
  132. }
  133. return &subscribePush{m}
  134. }
  135. // 从pushcache_2_a中取
  136. func (s *subscribePush) GetTodayCache(userId, userType string) (*SubPush, error) {
  137. pc_a, err := redis.GetNewBytes("pushcache_2_b", s.todayKey(userId, userType))
  138. if err != nil {
  139. return nil, err
  140. }
  141. if pc_a == nil {
  142. return nil, nil
  143. }
  144. var p *SubPush
  145. if err := json.Unmarshal(*pc_a, &p); err != nil {
  146. return nil, err
  147. }
  148. return p, nil
  149. }
  150. // 往pushcache_2_a中放
  151. func (s *subscribePush) PutTodayCache(userId, userType string, pc_a *SubPush) {
  152. redis.Put("pushcache_2_b", s.todayKey(userId, userType), pc_a, oneDay)
  153. }
  154. // 获取redis key
  155. func (s *subscribePush) todayKey(userId, userType string) string {
  156. if s.ModuleFlag == EntnicheFlag {
  157. switch userType {
  158. case SubVipFlag:
  159. return fmt.Sprintf("%s_%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, "vip", userId)
  160. case MemberFlag:
  161. return fmt.Sprintf("%s_%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, "member", userId)
  162. case SubFreeFlag:
  163. return fmt.Sprintf("%s_%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, "free", userId)
  164. }
  165. }
  166. return fmt.Sprintf("%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, userId)
  167. }
  168. func (s *subscribePush) allKey(userId, userType string) string {
  169. if s.ModuleFlag == EntnicheFlag {
  170. switch userType {
  171. case SubVipFlag:
  172. return fmt.Sprintf("all_%s_%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, "vip", userId)
  173. case MemberFlag:
  174. return fmt.Sprintf("all_%s_%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, "member", userId)
  175. case SubFreeFlag:
  176. return fmt.Sprintf("all_%s_%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, "free", userId)
  177. }
  178. }
  179. return fmt.Sprintf("all_%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, userId)
  180. }
  181. // 历史推送记录中单条信息格式化
  182. func (s *subscribePush) InfoFormat(p *PushCa, info *map[string]interface{}, isPay bool) *bxsubscribe.SubscribeInfo {
  183. area := common.ObjToString((*info)["area"])
  184. if area == "A" {
  185. area = "全国"
  186. }
  187. industry := common.ObjToString((*info)["s_subscopeclass"])
  188. scs := strings.Split(industry, ",")
  189. if len(scs) > 0 {
  190. industry = scs[0]
  191. if industry != "" {
  192. iss := strings.Split(industry, "_")
  193. if len(iss) > 0 {
  194. industry = iss[0]
  195. }
  196. }
  197. }
  198. infotype := common.ObjToString((*info)["subtype"])
  199. if infotype == "" {
  200. infotype = common.ObjToString((*info)["toptype"])
  201. }
  202. _id := p.InfoId
  203. if _id == "" {
  204. _id = common.ObjToString((*info)["_id"])
  205. }
  206. isValidFile, _ := (*info)["isValidFile"].(bool)
  207. formatInfo := &bxsubscribe.SubscribeInfo{
  208. XId: encrypt.EncodeArticleId2ByCheck(_id),
  209. Title: common.InterfaceToStr((*info)["title"]),
  210. Area: area,
  211. City: common.InterfaceToStr((*info)["city"]),
  212. BuyerClass: common.InterfaceToStr((*info)["buyerclass"]),
  213. Subtype: infotype,
  214. Industry: industry,
  215. PublishTime: common.Int64All((*info)["publishtime"]),
  216. CaIndex: p.Index,
  217. CaDate: p.Date,
  218. CaIsvisit: int64(p.Visit),
  219. CaIsvip: int64(p.Isvip),
  220. CaType: int64(p.Type),
  221. MatchKeys: p.Keys,
  222. Budget: common.Float64All((*info)["budget"]),
  223. BidAmount: common.Float64All((*info)["bidamount"]),
  224. Buyer: common.InterfaceToStr((*info)["buyer"]),
  225. ProjectName: common.InterfaceToStr((*info)["projectname"]),
  226. Winner: common.InterfaceToStr((*info)["s_winner"]),
  227. BidOpenTime: common.Int64All((*info)["bidopentime"]),
  228. CaFileExists: p.FileExists,
  229. Source: p.Source,
  230. Site: common.InterfaceToStr((*info)["site"]),
  231. SpiderCode: common.InterfaceToStr((*info)["spidercode"]),
  232. Toptype: common.InterfaceToStr((*info)["toptype"]),
  233. IsValidFile: isValidFile,
  234. SourceAll: p.SourceAll,
  235. }
  236. // 免费用户返回精简列表字段
  237. if !isPay {
  238. return formatInfo
  239. }
  240. winnerList := common.InterfaceToStr((*info)["s_winner"]) //中标企业名称集合
  241. if winnerList != "" && len(strings.Split(winnerList, ",")) > 0 {
  242. for wk, wv := range strings.Split(winnerList, ",") {
  243. var (
  244. winnerId = ""
  245. )
  246. if (*info)["entidlist"] != nil {
  247. if entIdList := common.ObjArrToStringArr((*info)["entidlist"].([]interface{})); len(entIdList) > wk { //中标企业id集合
  248. winnerId = entIdList[wk]
  249. }
  250. }
  251. formatInfo.WinnerInfo = append(formatInfo.WinnerInfo, &bxsubscribe.WinnerInfo{
  252. Winner: wv, //中标企业 需要单独处理
  253. WinnerTel: common.ObjToString((*info)["winnertel"]), //中标企业联系电话
  254. WinnerPerson: common.ObjToString((*info)["winnerperson"]), //中标企业联系人
  255. WinnerId: common.If(winnerId != "" && len([]rune(winnerId)) > 12, encrypt.EncodeArticleId2ByCheck(winnerId), "").(string), //中标企业加密id 存在winnerId 异常的情况
  256. })
  257. }
  258. }
  259. // 付费用户返回详细列表字段
  260. formatInfo.BuyerTel = common.ObjToString((*info)["buyertel"])
  261. formatInfo.BuyerPerson = common.ObjToString((*info)["buyerperson"])
  262. formatInfo.Agency = common.ObjToString((*info)["agency"])
  263. formatInfo.AgencyPerson = common.ObjToString((*info)["agencyperson"])
  264. formatInfo.AgencyTel = common.ObjToString((*info)["agencytel"])
  265. formatInfo.SignendTime = common.Int64All((*info)["signendtime"])
  266. formatInfo.BidendTime = common.Int64All((*info)["bidendtime"])
  267. return formatInfo
  268. }
  269. func (s *subscribePush) Datas(spqp *SubPushQueryParam, bsp *ViewCondition) (hasNextPage bool, total int64, result []*bxsubscribe.SubscribeInfo) {
  270. logx.Info(spqp.UserId, spqp.NewUserId, s.ModuleFlag, "subscribePush query param:", "SelectTime:", spqp.SelectTime, "Area:", spqp.Area, "District:", spqp.District, "City:", spqp.City, "Subtype:", spqp.Subtype, "Subscopeclass:", spqp.Subscopeclass, "Buyerclass:", spqp.Buyerclass, "Key:", spqp.Key, "PageNum:", spqp.PageNum, "Price:", spqp.Price, "FileExists:", spqp.FileExists)
  271. if spqp.UserId == "" {
  272. return
  273. }
  274. //不活跃用户处理
  275. if spqp.UserType == "" && spqp.PositionType == 0 {
  276. }
  277. if spqp.PageNum < 1 {
  278. spqp.PageNum = 1
  279. }
  280. if spqp.PageSize < 1 || spqp.PageSize > pageSize {
  281. if !spqp.Export {
  282. spqp.PageSize = pageSize
  283. } else { //数据导出查询20000条限制
  284. if spqp.PageSize < 1 || spqp.PageSize > 20000 {
  285. spqp.PageSize = 20000
  286. }
  287. }
  288. }
  289. starttime, endtime := int64(0), int64(0)
  290. if len(strings.Split(spqp.SelectTime, "_")) == 2 {
  291. st := strings.Split(spqp.SelectTime, "_")[0]
  292. et := strings.Split(spqp.SelectTime, "_")[1]
  293. if st != "" && et != "" {
  294. starttime, _ = strconv.ParseInt(st, 0, 64)
  295. endtime, _ = strconv.ParseInt(et, 0, 64)
  296. if endtime > 0 {
  297. etTime := time.Unix(endtime, 0)
  298. endtime = time.Date(etTime.Year(), etTime.Month(), etTime.Day(), 23, 59, 59, 0, time.Local).Unix()
  299. }
  300. }
  301. }
  302. nowFormat := date.NowFormat(date.Date_Short_Layout)
  303. start := (spqp.PageNum - 1) * spqp.PageSize
  304. end := start + spqp.PageSize
  305. //时间是今天,没有别的过滤条件--首先读取当前推送缓存数据 其次查询数据库
  306. if nowFormat == date.FormatDateByInt64(&starttime, date.Date_Short_Layout) && spqp.Area == "" && spqp.City == "" && spqp.District == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == "" && spqp.Item == "" && spqp.Price == "" && spqp.FileExists == "" && len(spqp.Staffs) == 0 && spqp.Source == "" && spqp.IsRead == "" && len(spqp.SelectInfoIds) == 0 {
  307. subPush := &SubPush{}
  308. var err error
  309. if spqp.IsEnt == false {
  310. subPush, err = s.GetTodayCache(spqp.UserId, spqp.UserType)
  311. }
  312. if err != nil {
  313. logx.Info(spqp.UserId, "GetTodayCache Error", err)
  314. }
  315. if err != nil || subPush == nil || subPush.Date != nowFormat || len(subPush.Datas) == 0 {
  316. list, countSearch := s.getDatasFromMysql(spqp, starttime, endtime, spqp.PageSize, false)
  317. subPush = &SubPush{
  318. Date: nowFormat,
  319. Datas: list,
  320. Count: countSearch,
  321. }
  322. if spqp.IsEnt == false && spqp.NotReturnCount == 0 {
  323. s.PutTodayCache(spqp.UserId, spqp.UserType, subPush)
  324. }
  325. }
  326. length := len(subPush.Datas)
  327. if end > length {
  328. end = length
  329. }
  330. if start < length {
  331. result = subPush.Datas[start:end]
  332. } else {
  333. result = subPush.Datas
  334. }
  335. total = int64(length)
  336. //全部,没有过滤条件 之前缓存500
  337. } else if spqp.IsEmpty() && (spqp.PageNum-1)*spqp.PageSize < 200 && len(spqp.SelectInfoIds) == 0 && !spqp.Export { //全部,没有过滤条件 之前缓存5页*50条=250 非数据导出
  338. allCache := &SubPush{}
  339. var err error
  340. if !spqp.IsEnt {
  341. allCache, err = s.GetAllCache(spqp.UserId, spqp.UserType)
  342. }
  343. if err != nil {
  344. logx.Info(spqp.UserId, "GetAllCache Error", err)
  345. }
  346. if err != nil || allCache == nil || allCache.Date != nowFormat || len(allCache.Datas) == 0 {
  347. list, countSearch := []*bxsubscribe.SubscribeInfo{}, int64(0)
  348. if spqp.IsEnt {
  349. list, countSearch = s.getDatasFromMysql(spqp, starttime, endtime, spqp.PageSize, true)
  350. } else {
  351. spqp.PageNum = 1
  352. list, countSearch = s.getDatasFromMysql(spqp, starttime, endtime, AllSubPushCacheSize, true)
  353. }
  354. allCache = &SubPush{
  355. Date: nowFormat,
  356. Datas: list,
  357. Count: countSearch,
  358. }
  359. if spqp.IsEnt == false && spqp.NotReturnCount == 0 {
  360. s.PutAllCache(spqp.UserId, spqp.UserType, allCache)
  361. }
  362. }
  363. length := len(allCache.Datas)
  364. if end > length {
  365. end = length
  366. }
  367. if start < length {
  368. result = allCache.Datas[start:end]
  369. } else {
  370. result = allCache.Datas
  371. }
  372. total = allCache.Count
  373. } else {
  374. result, total = s.getDatasFromMysql(spqp, starttime, endtime, spqp.PageSize, true)
  375. }
  376. if result == nil {
  377. result = []*bxsubscribe.SubscribeInfo{}
  378. }
  379. hasNextPage = len(result) >= spqp.PageSize
  380. return
  381. }
  382. func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, endtime int64, size int, isLimit bool) (result []*bxsubscribe.SubscribeInfo, count int64) {
  383. start := time.Now().Unix()
  384. querys := []string{}
  385. userStr := " 1=1 "
  386. var (
  387. countSql, findSql string
  388. list []map[string]interface{}
  389. )
  390. querys = append(querys, " ")
  391. if spqp.SelectInfoIds != nil && len(spqp.SelectInfoIds) > 0 {
  392. var (
  393. selectInfoIds []string
  394. )
  395. for _, sId := range spqp.SelectInfoIds {
  396. selectInfoIds = append(selectInfoIds, sId)
  397. if len(selectInfoIds) == 50 {
  398. findSelectSql := fmt.Sprintf("select a.id,a.date,a.infoid,a.isvisit,REPLACE(a.matchkeys,'+',' ') as matchkeys,a.type,a.attachment_count from %s a where %s order by a.date desc,a.id desc", aboutDbMsg[s.ModuleFlag].MysqlTable, fmt.Sprintf("a.id in ('%s')", strings.Join(selectInfoIds, "','")))
  399. logx.Info(spqp.NewUserId, "subscribePush info ids query sql:", findSelectSql)
  400. list = append(list, *spqp.BaseServiceMysql.SelectBySql(findSelectSql)...)
  401. selectInfoIds = []string{}
  402. }
  403. }
  404. if len(selectInfoIds) > 0 {
  405. findSelectSql := fmt.Sprintf("select a.id,a.date,a.infoid,a.isvisit,REPLACE(a.matchkeys,'+',' ') as matchkeys,a.type,a.attachment_count from %s a where %s order by a.date desc,a.id desc", aboutDbMsg[s.ModuleFlag].MysqlTable, fmt.Sprintf("a.id in ('%s')", strings.Join(selectInfoIds, "','")))
  406. logx.Info(spqp.NewUserId, "subscribePush info ids query sql:", findSelectSql)
  407. list = append(list, *spqp.BaseServiceMysql.SelectBySql(findSelectSql)...)
  408. selectInfoIds = []string{}
  409. }
  410. //countSql = fmt.Sprintf("select count(1) as count from %s a where %s", aboutDbMsg[s.ModuleFlag].MysqlTable, fmt.Sprintf("a.id in ('%s')", strings.Join(spqp.SelectInfoIds, "','")))
  411. //logx.Info("countSql", countSql)
  412. //findSql = fmt.Sprintf("select a.id,a.date,a.infoid,a.isvisit,REPLACE(a.matchkeys,'+',' ') as matchkeys,a.type,a.attachment_count from %s a where %s order by a.date desc,a.id desc", aboutDbMsg[s.ModuleFlag].MysqlTable, fmt.Sprintf("a.id in ('%s')", strings.Join(spqp.SelectInfoIds, "','")))
  413. ////查询总数
  414. //count = spqp.BaseServiceMysql.CountBySql(countSql)
  415. } else {
  416. //公共查询条件
  417. //时间
  418. if starttime > 0 && endtime > 0 {
  419. querys = append(querys, fmt.Sprintf(" a.date>=%d and a.date<=%d", starttime, endtime))
  420. } else if starttime > 0 && endtime == 0 {
  421. querys = append(querys, fmt.Sprintf(" a.date>=%d", starttime))
  422. } else if starttime == 0 && endtime > 0 {
  423. querys = append(querys, fmt.Sprintf(" a.date<=%d", endtime))
  424. } else {
  425. querys = append(querys, " a.date>0")
  426. }
  427. var regionArr = []string{}
  428. if spqp.Area != "" || spqp.City != "" || spqp.District != "" {
  429. //城市
  430. city := []string{}
  431. for _, v := range strings.Split(spqp.City, ",") {
  432. if P.BidCodeMapping.City[v] != "" {
  433. city = append(city, fmt.Sprint(P.BidCodeMapping.City[v]))
  434. }
  435. }
  436. if len(city) > 0 {
  437. regionArr = append(regionArr, fmt.Sprintf(" a.city in (%s) ", strings.Join(city, ",")))
  438. }
  439. //区域
  440. area := []string{}
  441. for _, v := range strings.Split(spqp.Area, ",") {
  442. if P.BidCodeMapping.Area[v] != "" {
  443. area = append(area, fmt.Sprint(P.BidCodeMapping.Area[v]))
  444. }
  445. }
  446. if len(area) > 0 {
  447. regionArr = append(regionArr, fmt.Sprintf(" a.area in (%s) ", strings.Join(area, ",")))
  448. }
  449. //区域
  450. district := []string{}
  451. if spqp.District != "" {
  452. for _, v := range strings.Split(spqp.District, ",") {
  453. cityName := strings.Split(v, "_")[0]
  454. districtName := strings.Split(v, "_")[1]
  455. if P.BidCodeMapping.District[cityName][districtName] != "" {
  456. district = append(district, fmt.Sprint(P.BidCodeMapping.District[cityName][districtName]))
  457. }
  458. }
  459. }
  460. if len(district) > 0 {
  461. regionArr = append(regionArr, fmt.Sprintf(" a.district in (%s) ", strings.Join(district, ",")))
  462. }
  463. if len(regionArr) > 0 {
  464. querys = append(querys, fmt.Sprintf("(%s)", strings.Join(regionArr, "or")))
  465. }
  466. }
  467. //采购单位行业
  468. if spqp.Buyerclass != "" {
  469. buyerclass := []string{}
  470. for _, v := range strings.Split(spqp.Buyerclass, ",") {
  471. if fmt.Sprint(P.BidCodeMapping.Buyerclass[v]) != "" {
  472. buyerclass = append(buyerclass, fmt.Sprint(P.BidCodeMapping.Buyerclass[v]))
  473. }
  474. }
  475. if len(buyerclass) == 1 {
  476. buyerclass = append(buyerclass, "9999")
  477. }
  478. if len(buyerclass) > 0 {
  479. querys = append(querys, fmt.Sprintf("a.buyerclass in (%s)", strings.Join(buyerclass, ",")))
  480. }
  481. }
  482. //信息类型
  483. if spqp.Subtype != "" {
  484. subtype := []string{}
  485. for _, v := range strings.Split(spqp.Subtype, ",") {
  486. subtype = append(subtype, P.BidCodeMapping.Subtype[v])
  487. }
  488. if len(subtype) == 1 {
  489. subtype = append(subtype, "9999")
  490. }
  491. if len(subtype) > 0 {
  492. querys = append(querys, fmt.Sprintf("subtype in (%s)", strings.Join(subtype, ",")))
  493. }
  494. }
  495. //信息行业
  496. if spqp.Subscopeclass != "" {
  497. find_in_set := []string{}
  498. for _, v := range strings.Split(spqp.Subscopeclass, ",") {
  499. find_in_set = append(find_in_set, fmt.Sprintf("find_in_set('%s',a.subscopeclass)", P.BidCodeMapping.Subscopeclass[v]))
  500. }
  501. if len(find_in_set) == 1 {
  502. querys = append(querys, find_in_set[0])
  503. } else if len(find_in_set) > 1 {
  504. querys = append(querys, fmt.Sprintf("(%s)", strings.Join(find_in_set, " or ")))
  505. }
  506. }
  507. //关键词
  508. find_in_set := []string{}
  509. if spqp.IsEnt {
  510. if spqp.Key != "" {
  511. for _, v := range strings.Split(spqp.Key, ",") {
  512. find_in_set = append(find_in_set, fmt.Sprintf("find_in_set('%s',replace(a.matchkeys,' ',','))", v))
  513. }
  514. }
  515. if spqp.Item != "" {
  516. for _, v := range strings.Split(spqp.Item, ",") {
  517. find_in_set = append(find_in_set, fmt.Sprintf("find_in_set('%s',replace(a.matchitems,' ',','))", v))
  518. }
  519. }
  520. } else {
  521. if spqp.Key != "" {
  522. for _, v := range strings.Split(spqp.Key, ",") {
  523. find_in_set = append(find_in_set, fmt.Sprintf("find_in_set('%s',replace(a.matchkeys,' ',','))", v))
  524. }
  525. }
  526. if spqp.Item != "" {
  527. //通过分类名搜索
  528. keyArr := s.ItemToKey(spqp)
  529. for _, v := range strings.Split(keyArr, ",") {
  530. find_in_set = append(find_in_set, fmt.Sprintf("find_in_set('%s',replace(a.matchkeys,' ',','))", v))
  531. }
  532. }
  533. }
  534. if len(find_in_set) == 1 {
  535. querys = append(querys, find_in_set[0])
  536. } else if len(find_in_set) > 1 {
  537. querys = append(querys, fmt.Sprintf("(%s)", strings.Join(find_in_set, " or ")))
  538. }
  539. //价格- 预算和中标金额
  540. if spqp.Price != "" && strings.Contains(spqp.Price, "-") {
  541. minPriceStr, maxPriceStr := strings.Split(spqp.Price, "-")[0], strings.Split(spqp.Price, "-")[1]
  542. minPrice := common.Int64All(common.Float64All(minPriceStr) * 10000) //换成元
  543. maxPrice := common.Int64All(common.Float64All(maxPriceStr) * 10000) //换成元
  544. if minPriceStr != "" && maxPriceStr != "" {
  545. querys = append(querys, fmt.Sprintf("((a.bidamount>=%d and a.bidamount<=%d) or (a.budget>=%d and a.budget<=%d and a.bidamount is null))", minPrice, maxPrice, minPrice, maxPrice))
  546. } else if minPriceStr != "" {
  547. querys = append(querys, fmt.Sprintf("(a.bidamount>=%d or (a.budget>=%d and a.bidamount is null))", minPrice, minPrice))
  548. } else if maxPriceStr != "" {
  549. querys = append(querys, fmt.Sprintf("(a.bidamount<=%d or (a.budget<=%d and a.bidamount is null))", maxPrice, maxPrice))
  550. }
  551. }
  552. //附件
  553. if spqp.FileExists != "" {
  554. if spqp.FileExists == "1" {
  555. querys = append(querys, fmt.Sprintf("a.attachment_count is not null"))
  556. } else if spqp.FileExists == "-1" {
  557. querys = append(querys, fmt.Sprintf("a.attachment_count is null"))
  558. }
  559. }
  560. // 是否已读
  561. if spqp.IsRead != "" {
  562. if spqp.IsRead == "0" {
  563. querys = append(querys, " a.isvisit IS NULL")
  564. } else if spqp.IsRead == "1" {
  565. querys = append(querys, " a.isvisit=1")
  566. }
  567. }
  568. // 信息来源
  569. if spqp.Source == "1" || spqp.Source == "2" || spqp.Source == "3" {
  570. querys = append(querys, " a.source="+spqp.Source)
  571. }
  572. if spqp.IsEnt {
  573. var staffs []string
  574. userStr += fmt.Sprintf(" and a.entid='%s' ", spqp.EntId)
  575. //判断是企业管理员还是部门管理员 部门管理员获取所有子部门
  576. userEnt := EntInfo(common.IntAll(spqp.EntId), common.IntAll(spqp.EntUserId))
  577. if !(userEnt.Role_admin_system || userEnt.Role_admin_department) {
  578. result = []*bxsubscribe.SubscribeInfo{}
  579. return
  580. }
  581. if userEnt.Role_admin_department { //
  582. // 部门管理员 获取所有部门和子部门员工
  583. users := GetDisUsers(common.IntAll(spqp.EntId), userEnt.Dept.Id)
  584. if users != nil && len(*users) > 0 {
  585. for _, v := range *users {
  586. if len(spqp.Staffs) > 0 {
  587. for _, vv := range spqp.Staffs {
  588. if fmt.Sprintf("%d", v.Id) == vv {
  589. staffs = append(staffs, common.InterfaceToStr(v.Id))
  590. }
  591. }
  592. } else {
  593. staffs = append(staffs, common.InterfaceToStr(v.Id))
  594. }
  595. }
  596. } else {
  597. log.Printf("部门管理员为获取到部门员工:%s", spqp.EntUserId)
  598. result = []*bxsubscribe.SubscribeInfo{}
  599. return
  600. }
  601. } else if len(spqp.Staffs) > 0 {
  602. staffs = spqp.Staffs
  603. }
  604. // 无查询分配人员、是否已读
  605. if spqp.IsRead == "" && len(staffs) == 0 {
  606. //查询数量(需要去重)
  607. countSql = fmt.Sprintf("select count(1) from %s a where %s %s ", aboutDbMsg[s.ModuleFlag].MysqlTable, userStr, strings.Join(querys, " and "))
  608. //列表查询
  609. findSql = fmt.Sprintf("select a.id,a.infoid,REPLACE(a.matchkeys,'+',' ') as matchkeys,a.attachment_count, IF(a.source is NULL,1,a.source) as source from %s a where %s %s order by a.date desc,a.id desc",
  610. aboutDbMsg[s.ModuleFlag].MysqlTable, userStr, strings.Join(querys, " and "))
  611. } else {
  612. //查询分配人员或是否已读
  613. staffQuery := " and 1=1 "
  614. if len(spqp.Staffs) > 0 {
  615. staffQuery += fmt.Sprintf(" and a.userid in ('%s') ", strings.Join(staffs, "','"))
  616. } else if len(staffs) > 0 {
  617. staffQuery += fmt.Sprintf(" and a.userid in (0,'%s') ", strings.Join(staffs, "','"))
  618. }
  619. countSql = fmt.Sprintf("select count(1) from %s a where %s %s %s ", aboutDbMsg[s.ModuleFlag].MysqlTable, userStr, strings.Join(querys, " and "), staffQuery)
  620. //列表查询
  621. findSql = fmt.Sprintf("select a.id,a.infoid,REPLACE(a.matchkeys,'+',' ') as matchkeys,a.attachment_count,IF(a.source is NULL,1,a.source) as source from %s a where %s %s %s order by a.date desc,a.id desc ", aboutDbMsg[s.ModuleFlag].MysqlTable, userStr, strings.Join(querys, " and "), staffQuery)
  622. }
  623. } else {
  624. // 是否已读
  625. if spqp.IsRead != "" {
  626. if spqp.IsRead == "0" {
  627. querys = append(querys, " a.isvisit IS NULL")
  628. } else if spqp.IsRead == "1" {
  629. querys = append(querys, " a.isvisit=1")
  630. }
  631. }
  632. // 信息来源
  633. if spqp.Source == "1" || spqp.Source == "2" || spqp.Source == "3" {
  634. querys = append(querys, " a.source="+spqp.Source)
  635. }
  636. if spqp.PositionType == 1 {
  637. //企业主体是企业的个人查询
  638. if spqp.UserType == SubVipFlag {
  639. userStr += fmt.Sprintf(" and a.userid='%s' and ( a.product=1 or a.product=3 or a.source>1 ) ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
  640. } else if spqp.UserType == MemberFlag {
  641. userStr += fmt.Sprintf(" and a.userid='%s' and ( a.product=2 or a.product=3 or a.source>1 ) ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
  642. } else if spqp.UserType == EntnicheFlag {
  643. userStr += fmt.Sprintf(" and a.userid='%s' and ( a.product is null or a.product=3 or a.source>1 ) ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
  644. } else {
  645. userStr += fmt.Sprintf(" and a.userid='%s' ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
  646. }
  647. } else {
  648. if s.ModuleFlag == EntnicheFlag {
  649. //老商机管理个人订阅查询
  650. userStr += fmt.Sprintf(" and a.userid='%s' and a.product is null", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
  651. } else {
  652. //个人订阅查询
  653. userStr += fmt.Sprintf(" and a.userid='%s'", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
  654. }
  655. }
  656. //查询数量
  657. countSql = fmt.Sprintf("select count(1) as count from %s a where %s %s", aboutDbMsg[s.ModuleFlag].MysqlTable, userStr, strings.Join(querys, " and "))
  658. //列表查询语句
  659. findSql = "select a.id,a.date,a.infoid,a.isvisit,REPLACE(a.matchkeys,'+',' ') as matchkeys,a.type,a.attachment_count"
  660. if s.ModuleFlag == EntnicheFlag {
  661. findSql += ", IF(a.source is NULL,1,a.source) as source "
  662. }
  663. if s.ModuleFlag != MemberFlag && s.ModuleFlag != EntnicheFlag {
  664. findSql += ",a.isvip"
  665. }
  666. findSql = fmt.Sprintf("%s from %s a where %s %s "+
  667. " order by a.date desc,a.id desc", findSql, aboutDbMsg[s.ModuleFlag].MysqlTable, userStr, strings.Join(querys, " and "))
  668. }
  669. //查询总数
  670. logx.Info("countSql", countSql)
  671. if spqp.NotReturnCount == 0 {
  672. count = spqp.BaseServiceMysql.CountBySql(countSql)
  673. }
  674. log.Println("数据总数查询", count)
  675. if isLimit {
  676. findSql += fmt.Sprintf(" limit %d,%d", (spqp.PageNum-1)*size, size)
  677. }
  678. list = *spqp.BaseServiceMysql.SelectBySql(findSql)
  679. logx.Info(spqp.NewUserId, "subscribePush query sql:", findSql)
  680. }
  681. end1 := time.Now().Unix()
  682. log.Println("mysql查询用时:", end1-start)
  683. if list != nil && len(list) > 0 {
  684. pushCas := s.GetJyPushs(list)
  685. if !spqp.Export {
  686. result = s.GetInfoByIds(spqp.Mgo_bidding, spqp.Bidding, spqp.Bidding_back, pushCas, spqp.IsPayUser)
  687. } else {
  688. result = s.GetOnlyExportInfo(pushCas)
  689. }
  690. } else {
  691. result = []*bxsubscribe.SubscribeInfo{}
  692. }
  693. end2 := time.Now().Unix()
  694. log.Println("处理数据用时:", end2-end1)
  695. log.Println("总用时用时:", end2-start)
  696. return
  697. }
  698. // GetOnlyInfoId 获取信息id
  699. func (s *subscribePush) GetOnlyExportInfo(pushCas []*PushCa) []*bxsubscribe.SubscribeInfo {
  700. array := make([]*bxsubscribe.SubscribeInfo, len(pushCas))
  701. for k, v := range pushCas {
  702. array[k] = &bxsubscribe.SubscribeInfo{XId: encrypt.EncodeArticleId2ByCheck(v.InfoId), MatchKeys: v.Keys}
  703. }
  704. return array
  705. }
  706. // 根据id取内容
  707. func (s *subscribePush) GetInfoByIds(Mgo_bidding mongodb.MongodbSim, bidding, bidding_back string, pushCas []*PushCa, isPay bool) []*bxsubscribe.SubscribeInfo {
  708. array := make([]*bxsubscribe.SubscribeInfo, len(pushCas))
  709. if len(pushCas) == 0 {
  710. return array
  711. }
  712. m := map[string]bool{}
  713. ids := []string{}
  714. for _, v := range pushCas {
  715. if m[v.InfoId] {
  716. continue
  717. }
  718. m[v.InfoId] = true
  719. ids = append(ids, v.InfoId)
  720. }
  721. infos := map[string]map[string]interface{}{}
  722. //redis
  723. pool := make(chan bool, 3)
  724. wait := &sync.WaitGroup{}
  725. lock := &sync.Mutex{}
  726. es_ids := []string{}
  727. for _, vv := range ids {
  728. pool <- true
  729. wait.Add(1)
  730. go func(v string) {
  731. defer func() {
  732. <-pool
  733. wait.Done()
  734. }()
  735. //剑鱼程序未找到赋值 位置;猜测在推送程序中
  736. info_i := redis.Get("pushcache_1", fmt.Sprintf("info_%s", v))
  737. lock.Lock()
  738. defer lock.Unlock()
  739. if info_i != nil {
  740. info_m, _ := info_i.(map[string]interface{})
  741. info_m["_id"] = v
  742. infos[v] = info_m
  743. } else {
  744. es_ids = append(es_ids, v)
  745. }
  746. }(vv)
  747. }
  748. wait.Wait()
  749. log.Println("ESSSS")
  750. //elasticsearch
  751. if len(es_ids) > 0 {
  752. list := elastic.Get("bidding", "bidding", fmt.Sprintf(query, strings.Join(es_ids, `","`), len(es_ids)))
  753. if list != nil {
  754. for _, v := range *list {
  755. _id := common.ObjToString(v["_id"])
  756. infos[_id] = v
  757. }
  758. }
  759. }
  760. log.Println("mongodb")
  761. //mongodb bidding
  762. mgo_ids := []primitive.ObjectID{}
  763. for _, v := range es_ids {
  764. if infos[v] == nil {
  765. _id, _ := primitive.ObjectIDFromHex(v)
  766. mgo_ids = append(mgo_ids, _id)
  767. }
  768. }
  769. if len(mgo_ids) > 0 {
  770. list, ok := Mgo_bidding.Find(bidding, map[string]interface{}{"_id": map[string]interface{}{"$in": mgo_ids}}, nil, mongodb_fields, false, -1, -1)
  771. if ok && *list != nil {
  772. for _, v := range *list {
  773. _id := mongodb.BsonIdToSId(v["_id"])
  774. v["_id"] = _id
  775. infos[_id] = v
  776. }
  777. }
  778. }
  779. log.Println("bidding_back")
  780. //mongodb bidding_back
  781. mgo_back_ids := []primitive.ObjectID{}
  782. for _, v := range mgo_ids {
  783. if infos[mongodb.BsonIdToSId(v)] == nil {
  784. mgo_back_ids = append(mgo_back_ids, v)
  785. }
  786. }
  787. if len(mgo_back_ids) > 0 {
  788. list, ok := Mgo_bidding.Find(bidding_back, map[string]interface{}{"_id": map[string]interface{}{"$in": mgo_back_ids}}, nil, mongodb_fields, false, -1, -1)
  789. if ok && *list != nil {
  790. for _, v := range *list {
  791. _id := mongodb.BsonIdToSId(v["_id"])
  792. v["_id"] = _id
  793. infos[_id] = v
  794. }
  795. }
  796. }
  797. for k, v := range pushCas {
  798. info := infos[v.InfoId]
  799. if info == nil {
  800. info = map[string]interface{}{}
  801. }
  802. array[k] = s.InfoFormat(v, &info, isPay)
  803. }
  804. return array
  805. }
  806. // 获取历史推送
  807. func (s *subscribePush) GetJyPushs(datas []map[string]interface{}) (pushCas []*PushCa) {
  808. pushCas = []*PushCa{}
  809. for _, v := range datas {
  810. keys := []string{}
  811. if matchkeys := common.ObjToString(v["matchkeys"]); matchkeys != "" {
  812. keys = strings.Split(matchkeys, " ")
  813. }
  814. pushCas = append(pushCas, &PushCa{
  815. Date: common.Int64All(v["date"]),
  816. InfoId: common.ObjToString(v["infoid"]),
  817. Visit: common.IntAll(v["isvisit"]),
  818. Index: common.Int64All(v["id"]),
  819. Keys: keys,
  820. Type: common.IntAll(v["type"]),
  821. Isvip: common.IntAll(v["isvip"]),
  822. FileExists: common.IntAll(v["attachment_count"]) > 0,
  823. Source: common.Int64All(v["source"]),
  824. SourceAll: common.ObjToString(v["sourceAll"]),
  825. })
  826. }
  827. return
  828. }
  829. // 查看全部列表缓存
  830. func (s *subscribePush) PutAllCache(userId, userType string, datas *SubPush) {
  831. log.Println("pushcache_2_a", s.allKey(userId, userType), datas, oneDay)
  832. redis.Put("pushcache_2_a", s.allKey(userId, userType), datas, oneDay)
  833. }
  834. func (s *subscribePush) GetAllCache(userId, userType string) (*SubPush, error) {
  835. return s.GetCache("pushcache_2_a", s.allKey(userId, userType))
  836. }
  837. func (s *subscribePush) GetCache(code, key string) (*SubPush, error) {
  838. pc_a, err := redis.GetNewBytes(code, key)
  839. if err != nil {
  840. return nil, err
  841. }
  842. if pc_a == nil {
  843. return nil, nil
  844. }
  845. var p *SubPush
  846. if err := json.Unmarshal(*pc_a, &p); err != nil {
  847. return nil, err
  848. }
  849. return p, nil
  850. }
  851. // 是否收藏
  852. func (s *subscribePush) MakeCollection(userId string, list []*bxsubscribe.SubscribeInfo) {
  853. if list == nil || len(list) == 0 {
  854. return
  855. }
  856. param := []interface{}{userId}
  857. wh := []string{}
  858. for _, v := range list {
  859. array := encrypt.DecodeArticleId2ByCheck(v.XId)
  860. if len(array) == 1 && array[0] != "" {
  861. param = append(param, array[0])
  862. wh = append(wh, "?")
  863. }
  864. }
  865. if len(wh) > 0 {
  866. result := IC.MainMysql.SelectBySql(`select bid from bdcollection where userid=? and bid in (`+strings.Join(wh, ",")+`)`, param...)
  867. bid_map := map[string]bool{}
  868. if result != nil {
  869. for _, v := range *result {
  870. bid_map[encrypt.EncodeArticleId2ByCheck(common.ObjToString(v["bid"]))] = true
  871. }
  872. }
  873. for _, v := range list {
  874. if bid_map[v.XId] {
  875. v.Collection = 1
  876. }
  877. }
  878. }
  879. }
  880. // 仅移动端首页使用,历史推送7天信息
  881. func (s *subscribePush) sevenDayKey(userId string) string {
  882. return fmt.Sprintf("7day_subpush_%s", userId)
  883. }
  884. func (s *subscribePush) PutSevenDayCache(userId string, datas []*bxsubscribe.SubscribeInfo) {
  885. redis.Put("pushcache_2_a", s.sevenDayKey(userId), SubPush{Datas: datas}, 7*24*60*60)
  886. }
  887. // 从pushcache_2_a中取
  888. func (s *subscribePush) GetSevenDayCache(userId string) ([]*bxsubscribe.SubscribeInfo, error) {
  889. allPush, _ := s.GetCache("pushcache_2_a", s.sevenDayKey(userId))
  890. if allPush != nil && allPush.Datas != nil && len(allPush.Datas) > 0 {
  891. return allPush.Datas, nil
  892. }
  893. return nil, nil
  894. }
  895. // 历史推送记录中单条信息格式化
  896. func InfoFormats(info map[string]interface{}, tmp map[string]interface{}) map[string]interface{} {
  897. area := common.ObjToString(info["area"])
  898. if area == "A" {
  899. area = "全国"
  900. }
  901. industry := common.ObjToString(info["s_subscopeclass"])
  902. scs := strings.Split(industry, ",")
  903. if len(scs) > 0 {
  904. industry = scs[0]
  905. if industry != "" {
  906. iss := strings.Split(industry, "_")
  907. if len(iss) > 0 {
  908. industry = iss[0]
  909. }
  910. }
  911. }
  912. infotype := common.ObjToString(info["subtype"])
  913. if infotype == "" {
  914. infotype = common.ObjToString(info["toptype"])
  915. }
  916. if infotype == "" {
  917. infotype = common.ObjToString(info["type"])
  918. if infotype == "tender" {
  919. infotype = "招标"
  920. } else if infotype == "bid" {
  921. infotype = "中标"
  922. }
  923. }
  924. info["type"] = infotype
  925. return info
  926. }
  927. // UpdateUserPushUnread 更新app未读标识为已读
  928. func UpdateUserPushUnread(userid string, vt string) {
  929. if vt == MemberFlag {
  930. IC.Mgo.UpdateById("user", userid, map[string]interface{}{"$set": map[string]interface{}{"i_member_apppushunread": 0}})
  931. } else if vt == EntnicheFlag {
  932. IC.Mgo.UpdateById("user", userid, map[string]interface{}{"$set": map[string]interface{}{"i_entniche_apppushunread": 0}})
  933. } else {
  934. IC.Mgo.UpdateById("user", userid, map[string]interface{}{"$set": map[string]interface{}{"i_apppushunread": 0}})
  935. }
  936. }
  937. func (s *subscribePush) SetRead(newUserId, id int64, userId, entUserId, entId string, isEnt bool, userType string) error {
  938. if id <= 0 && newUserId == 0 {
  939. return nil
  940. }
  941. if newUserId == 0 {
  942. return nil
  943. }
  944. IC.BaseServiceMysql.UpdateOrDeleteBySql(fmt.Sprintf("update %s set isvisit=1,visittime=now() where userid=? and id=?", aboutDbMsg[s.ModuleFlag].MysqlTable), common.If(s.ModuleFlag == EntnicheFlag, entUserId, newUserId), id)
  945. if s.ModuleFlag == EntnicheFlag {
  946. userId = entUserId
  947. }
  948. todaySubPush, err := s.GetTodayCache(userId, userType)
  949. //当天数据处理
  950. if err == nil && todaySubPush != nil {
  951. for _, v := range todaySubPush.Datas {
  952. if v.CaIndex == id {
  953. v.CaIsvisit = 1
  954. break
  955. }
  956. }
  957. s.PutTodayCache(userId, userType, todaySubPush)
  958. }
  959. //全部数据处理
  960. allSubPush, err := s.GetAllCache(userId, userType)
  961. if err == nil && allSubPush != nil {
  962. for _, v := range allSubPush.Datas {
  963. if v.CaIndex == id {
  964. v.CaIsvisit = 1
  965. break
  966. }
  967. }
  968. s.PutAllCache(userId, userType, allSubPush)
  969. }
  970. return nil
  971. }
  972. // UserInfo 获取用户信息
  973. func (s *subscribePush) UserInfo(baseUserId int64) (*map[string]interface{}, int64) {
  974. user, ok := IC.Mgo.FindOneByField("user", map[string]interface{}{"base_user_id": baseUserId}, `{"i_ts_guide":1,"s_m_openid":1,"a_m_openid":1,"s_phone":1,"a_mergeorder":1,"o_jy":1,"l_firstpushtime":1,"i_vip_status":1,"l_vip_endtime":1,"o_vipjy":1,"i_member_status":1,"o_member_jy":1}`)
  975. if !ok || user == nil {
  976. return nil, 0
  977. }
  978. return user, common.Int64All((*user)["l_firstpushtime"])
  979. }
  980. // GetKeySet 是否有订阅词
  981. func GetKeySet(t string, u *map[string]interface{}, data []string) (bool, []string) {
  982. var industry_ = []string{}
  983. if u != nil {
  984. if t == SubFreeFlag {
  985. o_jy, _ := (*u)["o_jy"].(map[string]interface{})
  986. a_key, _ := o_jy["a_key"].([]interface{})
  987. return len(a_key) > 0, industry_
  988. } else {
  989. var obj map[string]interface{}
  990. if t == SubVipFlag {
  991. obj, _ = (*u)["o_vipjy"].(map[string]interface{})
  992. } else if t == MemberFlag {
  993. obj, _ = (*u)["o_member_jy"].(map[string]interface{})
  994. } else if t == EntnicheFlag {
  995. if len(data) > 0 {
  996. return true, data
  997. } else {
  998. return false, data
  999. }
  1000. }
  1001. if obj != nil {
  1002. if buyerclassObj, ok := obj["a_buyerclass"].([]interface{}); ok {
  1003. industry_ = common.ObjArrToStringArr(buyerclassObj)
  1004. }
  1005. itmes, _ := obj["a_items"].([]interface{})
  1006. for _, v := range itmes {
  1007. item, _ := v.(map[string]interface{})
  1008. keys, _ := item["a_key"].([]interface{})
  1009. if len(keys) > 0 {
  1010. return true, industry_
  1011. }
  1012. }
  1013. }
  1014. }
  1015. }
  1016. return false, industry_
  1017. }
  1018. const (
  1019. INDEX = "bidding"
  1020. TYPE = "bidding"
  1021. bidField = `"_id","title","publishtime","toptype","subtype","type","area","city","s_subscopeclass","buyerclass","budget","bidamount","filetext","spidercode","site","buyer","bidopentime","buyertel","buyerperson","agency","agencyperson","agencytel","s_winner","winnerperson","winnertel","signendtime","bidendtime","entidlist"`
  1022. bidTime = `{"range":{"publishtime":{"gt":%d}}}`
  1023. bidSort = `{"publishtime":"desc"}`
  1024. findfields = `"title"`
  1025. )
  1026. // 首次访问推送页面 默认生成推送数据
  1027. // 默认匹配es 7天内数据
  1028. func (s *subscribePush) DefaultDatas(spqp *SubPushQueryParam, bsp *ViewCondition) (hasNextPage bool, total int64, result []*bxsubscribe.SubscribeInfo) {
  1029. if spqp.UserId == "" {
  1030. return false, 0, nil
  1031. }
  1032. logx.Info("userId:", spqp.UserId, "newUserId:", spqp.NewUserId)
  1033. t1 := time.Now()
  1034. if len(bsp.Keyword) > 0 {
  1035. logx.Info("--bsp:", bsp)
  1036. //获取查询语句
  1037. qstr := s.getDefaultDatasSQL(bsp)
  1038. list := elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSort, bidField, 0, bsp.Size, 0, false)
  1039. //logx.Info(time.Since(t1), "count:", len(*list))
  1040. if list != nil && len(*list) > 0 {
  1041. total = int64(len(*list))
  1042. result = s.listManager(spqp, *list, bsp.Keyword)
  1043. if len(result) > pageSize {
  1044. result = result[:pageSize]
  1045. hasNextPage = true
  1046. }
  1047. }
  1048. }
  1049. logx.Info("请求耗时:", time.Since(t1))
  1050. return
  1051. }
  1052. // 保存推送表
  1053. func (s *subscribePush) listManager(spqp *SubPushQueryParam, list []map[string]interface{}, keyword []ViewKeyWord) (resultList []*bxsubscribe.SubscribeInfo) {
  1054. now := time.Now().Unix()
  1055. length := len(list)
  1056. resultList = make([]*bxsubscribe.SubscribeInfo, length)
  1057. pushInsert := []interface{}{}
  1058. var product interface{}
  1059. if spqp.UserType == SubVipFlag {
  1060. product = 1
  1061. } else if spqp.UserType == MemberFlag {
  1062. product = 2
  1063. }
  1064. for i := length - 1; i >= 0; i-- {
  1065. v := list[i]
  1066. title := strings.Replace(common.ObjToString(v["title"]), " ", "", -1)
  1067. infoid := common.InterfaceToStr(v["_id"])
  1068. matchkeys := getKeys(title, keyword)
  1069. matchkey := strings.Join(matchkeys, " ")
  1070. subscopeclassStr := ""
  1071. area := common.If(v["area"] == nil, nil, common.If(common.ObjToString(v["area"]) == "A", 0, common.If(P.BidCodeMapping.Area[common.ObjToString(v["area"])] != "", P.BidCodeMapping.Area[common.ObjToString(v["area"])], 0)))
  1072. city := common.If(P.BidCodeMapping.City[common.ObjToString(v["city"])] == "", nil, P.BidCodeMapping.City[common.ObjToString(v["city"])])
  1073. cityName := common.ObjToString(v["city"])
  1074. district := ""
  1075. districtName := common.ObjToString(v["city"])
  1076. if cityName != "" && districtName != "" {
  1077. district = gconv.String(common.If(P.BidCodeMapping.District[cityName][districtName] == "", nil, P.BidCodeMapping.District[cityName][districtName]))
  1078. }
  1079. subtype := common.If(P.BidCodeMapping.Subtype[common.ObjToString(v["subtype"])] == "", nil, P.BidCodeMapping.Subtype[common.ObjToString(v["subtype"])])
  1080. toptype := common.If(P.BidCodeMapping.Toptype[common.ObjToString(v["toptype"])] == "", nil, P.BidCodeMapping.Toptype[common.ObjToString(v["toptype"])])
  1081. buyerclass := common.If(P.BidCodeMapping.Buyerclass[common.ObjToString(v["buyerclass"])] == "", nil, P.BidCodeMapping.Buyerclass[common.ObjToString(v["buyerclass"])])
  1082. attachment_count := 0
  1083. if v["isValidFile"] != nil {
  1084. isValidFile, _ := v["isValidFile"].(bool)
  1085. attachment_count = common.If(isValidFile, 1, 0).(int)
  1086. }
  1087. bidamount := common.If(v["bidamount"] == nil, nil, v["bidamount"])
  1088. budget := common.If(v["budget"] == nil, nil, v["budget"])
  1089. if s_subscopeclass := common.ObjToString(v["s_subscopeclass"]); s_subscopeclass != "" {
  1090. subscopeclass := []string{}
  1091. for _, v := range strings.Split(s_subscopeclass, ",") {
  1092. if subscopeclass_mapping, ok := P.BidCodeMapping.Subscopeclass[v]; ok {
  1093. subscopeclass = append(subscopeclass, fmt.Sprint(subscopeclass_mapping))
  1094. }
  1095. }
  1096. if len(subscopeclass) > 0 {
  1097. subscopeclassStr = strings.Join(subscopeclass, ",")
  1098. }
  1099. }
  1100. redisKey := fmt.Sprintf("pushinfo_%s_%s", spqp.UserId, common.ObjToString(v["_id"]))
  1101. entid := spqp.EntId
  1102. entUserId := spqp.EntUserId
  1103. deptid := spqp.DeptId
  1104. //公共字段处理
  1105. pushInsert = append(pushInsert, common.InterfaceToStr(infoid), matchkey, now, area, city, district, buyerclass, toptype, subtype, subscopeclassStr, budget, bidamount, attachment_count)
  1106. switch s.ModuleFlag {
  1107. case EntnicheFlag:
  1108. pushInsert = append(pushInsert, entUserId, entid, deptid, 1, product)
  1109. case MemberFlag:
  1110. pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId))
  1111. case SubVipFlag:
  1112. pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId), 1)
  1113. case SubFreeFlag:
  1114. pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId), 0)
  1115. }
  1116. redis.Put("pushcache_2_a", redisKey, 1, 86400)
  1117. resultList[i] = s.InfoFormat(&PushCa{
  1118. InfoId: infoid,
  1119. Date: time.Now().Unix(),
  1120. Keys: matchkeys,
  1121. FileExists: v["filetext"] != nil,
  1122. }, &v, spqp.IsPayUser)
  1123. }
  1124. id := int64(0)
  1125. switch s.ModuleFlag {
  1126. case EntnicheFlag:
  1127. _, id = spqp.BaseServiceMysql.InsertIgnoreBatch(aboutDbMsg[s.ModuleFlag].MysqlTable, ennicheInsertCollKey, pushInsert)
  1128. case MemberFlag:
  1129. _, id = spqp.BaseServiceMysql.InsertIgnoreBatch(aboutDbMsg[s.ModuleFlag].MysqlTable, memberInsertCollKey, pushInsert)
  1130. default:
  1131. _, id = spqp.BaseServiceMysql.InsertIgnoreBatch(aboutDbMsg[s.ModuleFlag].MysqlTable, subscribeInsertCollKey, pushInsert)
  1132. }
  1133. for i := length - 1; i >= 0; i-- {
  1134. resultList[i].CaIndex = id
  1135. id++
  1136. }
  1137. return
  1138. }
  1139. // 获取匹配得关键词
  1140. func getKeys(title string, keywords []ViewKeyWord) (str []string) {
  1141. if len(keywords) > 0 {
  1142. L:
  1143. for _, v := range keywords {
  1144. for _, vk := range v.Keyword {
  1145. if strings.Contains(title, vk) {
  1146. str = append(str, v.Keyword...)
  1147. break L
  1148. }
  1149. }
  1150. for _, va := range v.Appended {
  1151. if strings.Contains(title, va) {
  1152. str = append(str, v.Appended...)
  1153. break L
  1154. }
  1155. }
  1156. }
  1157. }
  1158. return
  1159. }
  1160. // 获取查询语句
  1161. func (s *subscribePush) getDefaultDatasSQL(bsp *ViewCondition) (str string) {
  1162. query := `{"query":{"bool":{"must":[%s],"should":[%s],"minimum_should_match": %d}}, "size": 500}`
  1163. query_bool_should := `{"bool":{"should":[%s],"minimum_should_match": 1}}`
  1164. multi_match := `{"multi_match": {"query": %s,"type": "phrase", "fields": [%s]}}`
  1165. query_bool_must_and := `{"bool":{"must":[%s]%s}}`
  1166. query_bool_must_and_district := `{"bool":{"must":[{"terms":{"city":["%s"]}},{"terms":{"district":["%s"]}}]}}`
  1167. bools := []string{}
  1168. musts := []string{}
  1169. //发布时间最新7天(正式环境需要修改)
  1170. musts = append(musts, fmt.Sprintf(bidTime, time.Now().AddDate(0, 0, -15).Unix()))
  1171. //省份
  1172. areaCity := []string{}
  1173. if len(bsp.Area) > 0 {
  1174. areaquery := `{"terms":{"area":[`
  1175. for k, v := range bsp.Area {
  1176. if k > 0 {
  1177. areaquery += `,`
  1178. }
  1179. areaquery += `"` + v + `"`
  1180. }
  1181. areaquery += `]}}`
  1182. areaCity = append(areaCity, areaquery)
  1183. }
  1184. //城市
  1185. if len(bsp.City) > 0 {
  1186. areaquery := `{"terms":{"city":[`
  1187. for k, v := range bsp.City {
  1188. if k > 0 {
  1189. areaquery += `,`
  1190. }
  1191. areaquery += `"` + v + `"`
  1192. }
  1193. areaquery += `]}}`
  1194. areaCity = append(areaCity, areaquery)
  1195. }
  1196. //区域处理
  1197. if len(bsp.District) > 0 {
  1198. for _, v := range bsp.District {
  1199. cityName := strings.Split(v, "_")[0]
  1200. districtName := strings.Split(v, "_")[1]
  1201. areaCity = append(areaCity, fmt.Sprintf(query_bool_must_and_district, cityName, districtName))
  1202. }
  1203. }
  1204. if len(areaCity) > 0 {
  1205. musts = append(musts, fmt.Sprintf(query_bool_should, strings.Join(areaCity, ",")))
  1206. }
  1207. if len(bsp.Subtype) > 0 {
  1208. subquery := `{"terms":{"subtype":[`
  1209. for k, v := range bsp.Subtype {
  1210. if k > 0 {
  1211. subquery += `,`
  1212. }
  1213. subquery += `"` + v + `"`
  1214. }
  1215. subquery += `]}}`
  1216. musts = append(musts, subquery)
  1217. }
  1218. if len(bsp.Buyerclass) > 0 {
  1219. Buyerclass := `{"terms":{"buyerclass":[`
  1220. for k, v := range bsp.Buyerclass {
  1221. if k > 0 {
  1222. Buyerclass += `,`
  1223. }
  1224. Buyerclass += `"` + v + `"`
  1225. }
  1226. Buyerclass += `]}}`
  1227. musts = append(musts, Buyerclass)
  1228. }
  1229. boolsNum := 0 //should
  1230. if len(bsp.Keyword) > 0 {
  1231. boolsNum = 1
  1232. if bsp.SelectType == "" || bsp.SelectType == "2" {
  1233. bsp.SelectType = "detail\", \"title"
  1234. } else {
  1235. bsp.SelectType = "title"
  1236. }
  1237. multi_match = fmt.Sprintf(multi_match, "%s", "\""+bsp.SelectType+"\"")
  1238. for _, v := range bsp.Keyword {
  1239. shoulds := []string{}
  1240. must_not := []string{}
  1241. //附加词
  1242. for _, vv := range v.Keyword {
  1243. vv = strings.TrimSpace(vv)
  1244. if vv == "" {
  1245. continue
  1246. }
  1247. shoulds = append(shoulds, fmt.Sprintf(multi_match, "\""+vv+"\""))
  1248. }
  1249. for _, vv := range v.Appended {
  1250. vv = strings.TrimSpace(vv)
  1251. if vv == "" {
  1252. continue
  1253. }
  1254. shoulds = append(shoulds, fmt.Sprintf(multi_match, "\""+vv+"\""))
  1255. }
  1256. //排除词
  1257. for _, vv := range v.Exclude {
  1258. vv = strings.TrimSpace(vv)
  1259. if vv == "" {
  1260. continue
  1261. }
  1262. must_not = append(must_not, fmt.Sprintf(multi_match, "\""+vv+"\""))
  1263. }
  1264. //添加
  1265. if len(shoulds) > 0 {
  1266. notStr := ""
  1267. if len(must_not) > 0 {
  1268. notStr = fmt.Sprintf(`,"must_not":[%s]`, strings.Join(must_not, ","))
  1269. }
  1270. bools = append(bools, fmt.Sprintf(query_bool_must_and, strings.Join(shoulds, ","), notStr))
  1271. }
  1272. }
  1273. }
  1274. qstr := fmt.Sprintf(query, strings.Join(musts, ","), strings.Join(bools, ","), boolsNum)
  1275. logx.Info("----", qstr)
  1276. return qstr
  1277. }
  1278. /*已选条件--关键词*/
  1279. type ViewKeyWord struct {
  1280. Keyword []string `json:"key"` //关键词
  1281. Appended []string `json:"appendkey"` //附加词
  1282. Exclude []string `json:"notkey"` //排除词
  1283. MatchWay int `json:"matchway"` //匹配模式
  1284. }
  1285. /*已选条件*/
  1286. type ViewCondition struct {
  1287. Area []string //地区-省份
  1288. City []string //地区-城市
  1289. District []string //区县
  1290. Buyerclass []string //采购行业
  1291. Keyword []ViewKeyWord //关键词
  1292. SelectType string //筛选(正文 or 标题)
  1293. Subtype []string //信息类型
  1294. Size int //数量
  1295. }
  1296. // 获取用户信息
  1297. func (s *subscribePush) GetUserInfo(spqp *SubPushQueryParam) (vc *ViewCondition) {
  1298. var isPayBool = false
  1299. var tmpInfo = struct {
  1300. Items []interface{}
  1301. BuyerClass []interface{}
  1302. SubType []interface{}
  1303. Area map[string]interface{}
  1304. District map[string]interface{}
  1305. SelectType string
  1306. }{}
  1307. switch s.ModuleFlag {
  1308. case MemberFlag:
  1309. userMap, ok := IC.Mgo.FindById("user", spqp.UserId, `{"o_member_jy":1,"i_member_status":1,"subpush_inactive":1}`)
  1310. spqp.SubPushInactive = common.ObjToString((*userMap)["subpush_inactive"])
  1311. if !ok || userMap == nil || len(*userMap) == 0 {
  1312. return &ViewCondition{}
  1313. }
  1314. //大会员
  1315. if common.IntAll((*userMap)["i_member_status"]) > 0 {
  1316. isPayBool = true
  1317. o_member_jy, _ := (*userMap)["o_member_jy"].(map[string]interface{})
  1318. tmpInfo.Items, _ = o_member_jy["a_items"].([]interface{})
  1319. tmpInfo.BuyerClass, _ = o_member_jy["a_buyerclass"].([]interface{})
  1320. tmpInfo.SubType, _ = o_member_jy["a_infotype"].([]interface{})
  1321. tmpInfo.Area, _ = o_member_jy["o_area"].(map[string]interface{})
  1322. tmpInfo.District, _ = o_member_jy["o_district"].(map[string]interface{})
  1323. }
  1324. case SubVipFlag:
  1325. userMap, ok := IC.Mgo.FindById("user", spqp.UserId, `{"o_vipjy":1,"i_vip_status":1,"subpush_inactive":1}`)
  1326. spqp.SubPushInactive = common.ObjToString((*userMap)["subpush_inactive"])
  1327. if !ok || userMap == nil || len(*userMap) == 0 {
  1328. return &ViewCondition{}
  1329. }
  1330. if common.IntAll((*userMap)["i_vip_status"]) > 0 {
  1331. isPayBool = true
  1332. o_vipjy, _ := (*userMap)["o_vipjy"].(map[string]interface{})
  1333. tmpInfo.Items, _ = o_vipjy["a_items"].([]interface{})
  1334. tmpInfo.BuyerClass, _ = o_vipjy["a_buyerclass"].([]interface{})
  1335. tmpInfo.SubType, _ = o_vipjy["a_infotype"].([]interface{})
  1336. tmpInfo.Area, _ = o_vipjy["o_area"].(map[string]interface{})
  1337. tmpInfo.District, _ = o_vipjy["o_district"].(map[string]interface{})
  1338. }
  1339. case EntnicheFlag:
  1340. //商机管理
  1341. entUserId, _ := strconv.Atoi(spqp.EntUserId)
  1342. entId, _ := strconv.Atoi(spqp.EntId)
  1343. entInfo, deptId := (&ms.MatchJob{}).Start(entId, entUserId)
  1344. if entInfo != nil && len(entInfo) > 0 {
  1345. spqp.DeptId = strconv.Itoa(deptId)
  1346. if common.IntAll(entInfo["i_type"]) == 2 {
  1347. if entInfo["a_key"] != nil {
  1348. tmpInfo.Items, _ = entInfo["a_key"].([]interface{})
  1349. //信息类型
  1350. tmpInfo.SubType, _ = entInfo["a_infotype"].([]interface{})
  1351. //省份
  1352. tmpInfo.Area, _ = entInfo["o_area"].(map[string]interface{})
  1353. tmpInfo.District, _ = entInfo["o_district"].(map[string]interface{})
  1354. if common.IntAllDef(entInfo["i_ppstatus"], 0) == 1 && entInfo["o_area_p"] != nil {
  1355. tmpInfo.Area, _ = entInfo["o_area_p"].(map[string]interface{})
  1356. }
  1357. }
  1358. } else {
  1359. isPayBool = true
  1360. tmpInfo.Items, _ = entInfo["a_items"].([]interface{})
  1361. tmpInfo.BuyerClass, _ = entInfo["a_buyerclass"].([]interface{})
  1362. tmpInfo.SubType, _ = entInfo["a_infotype"].([]interface{})
  1363. tmpInfo.Area, _ = entInfo["o_area"].(map[string]interface{})
  1364. tmpInfo.District, _ = entInfo["o_district"].(map[string]interface{})
  1365. }
  1366. }
  1367. default:
  1368. userMap, ok := IC.Mgo.FindById("user", spqp.UserId, `{"o_jy":1}`)
  1369. if !ok || userMap == nil || len(*userMap) == 0 {
  1370. return &ViewCondition{}
  1371. }
  1372. o_jy, _ := (*userMap)["o_jy"].(map[string]interface{})
  1373. if o_jy["a_key"] != nil {
  1374. tmpInfo.Items, _ = o_jy["a_key"].([]interface{})
  1375. //信息类型
  1376. tmpInfo.SubType, _ = o_jy["a_infotype"].([]interface{})
  1377. //省份
  1378. tmpInfo.Area, _ = o_jy["o_area"].(map[string]interface{})
  1379. tmpInfo.District, _ = o_jy["o_district"].(map[string]interface{})
  1380. if common.IntAllDef(o_jy["i_ppstatus"], 0) == 1 && o_jy["o_area_p"] != nil {
  1381. tmpInfo.Area, _ = o_jy["o_area_p"].(map[string]interface{})
  1382. }
  1383. }
  1384. }
  1385. vc = &ViewCondition{
  1386. Buyerclass: common.ObjArrToStringArr(tmpInfo.BuyerClass),
  1387. Subtype: common.ObjArrToStringArr(tmpInfo.SubType),
  1388. Area: getStringArrFromDbResult(tmpInfo.Area, 1),
  1389. City: getStringArrFromDbResult(tmpInfo.Area, 2),
  1390. District: districtHandle(tmpInfo.District),
  1391. SelectType: "1",
  1392. }
  1393. //付费用户
  1394. if isPayBool {
  1395. vc.Size = IC.C.DefaulCount.Pay
  1396. vc.Keyword = getKeyWordArrFromDbResult(tmpInfo.Items, "", -1)
  1397. } else {
  1398. vc.Size = IC.C.DefaulCount.Free
  1399. vc.Keyword = getKeyWordArrFromDbResultByFree(tmpInfo.Items, "", -1)
  1400. //vc.Keyword = getKeyWordArrFromDbResult(tmpInfo.Items, "", -1)
  1401. }
  1402. return
  1403. }
  1404. // 区县处理
  1405. func districtHandle(data map[string]interface{}) []string {
  1406. arr := []string{}
  1407. for k, v := range data {
  1408. for _, v1 := range gconv.SliceAny(v) {
  1409. arr = append(arr, fmt.Sprintf("%s_%s", k, v1))
  1410. }
  1411. }
  1412. return arr
  1413. } // 关键词 附加词 排除词
  1414. func getKeyWordArrFromDbResult(a_items []interface{}, item string, index int) (arr []ViewKeyWord) {
  1415. if a_items == nil {
  1416. return
  1417. }
  1418. for _, v := range a_items {
  1419. vm, _ := v.(map[string]interface{})
  1420. if item != "" && index >= 0 && item != common.ObjToString(vm["s_item"]) {
  1421. continue
  1422. }
  1423. kwsArr := vm["a_key"]
  1424. for i, k := range kwsArr.([]interface{}) {
  1425. if item != "" && index >= 0 && i != index {
  1426. continue
  1427. }
  1428. kw := ViewKeyWord{}
  1429. b, e := json.Marshal(k)
  1430. if e != nil {
  1431. log.Println(e.Error())
  1432. }
  1433. json.Unmarshal(b, &kw)
  1434. if kw.MatchWay == 1 {
  1435. for _, kk := range kw.Keyword {
  1436. arr = append(arr, ViewKeyWord{
  1437. Keyword: []string{kk},
  1438. Exclude: kw.Exclude,
  1439. })
  1440. }
  1441. for _, kk := range kw.Appended {
  1442. arr = append(arr, ViewKeyWord{
  1443. Keyword: []string{kk},
  1444. Exclude: kw.Exclude,
  1445. })
  1446. }
  1447. } else {
  1448. arr = append(arr, kw)
  1449. }
  1450. }
  1451. }
  1452. return
  1453. }
  1454. // //关键词 附加词 排除词 省份订阅包 - 普通用户
  1455. func getKeyWordArrFromDbResultByFree(a_items []interface{}, item string, index int) (arr []ViewKeyWord) {
  1456. if a_items == nil {
  1457. return
  1458. }
  1459. for _, v := range a_items {
  1460. kw := ViewKeyWord{}
  1461. b, e := json.Marshal(v)
  1462. if e != nil {
  1463. log.Println(e.Error())
  1464. }
  1465. json.Unmarshal(b, &kw)
  1466. if kw.MatchWay == 1 {
  1467. for _, kk := range kw.Keyword {
  1468. arr = append(arr, ViewKeyWord{
  1469. Keyword: []string{kk},
  1470. Exclude: kw.Exclude,
  1471. })
  1472. }
  1473. for _, kk := range kw.Appended {
  1474. arr = append(arr, ViewKeyWord{
  1475. Keyword: []string{kk},
  1476. Exclude: kw.Exclude,
  1477. })
  1478. }
  1479. } else {
  1480. arr = append(arr, kw)
  1481. }
  1482. }
  1483. return
  1484. }
  1485. // 地区格式化
  1486. func getStringArrFromDbResult(area map[string]interface{}, i int) (arr []string) {
  1487. if area == nil {
  1488. return
  1489. }
  1490. var eareArr []string
  1491. var cityArr []string
  1492. for k, v := range area {
  1493. if len(v.([]interface{})) > 0 {
  1494. cityArr = append(cityArr, common.ObjArrToStringArr(v.([]interface{}))...)
  1495. } else {
  1496. eareArr = append(eareArr, k)
  1497. }
  1498. }
  1499. if i == 1 {
  1500. arr = eareArr
  1501. } else {
  1502. arr = cityArr
  1503. }
  1504. return
  1505. }
  1506. // IsInTsGuide 是否进入向导
  1507. func (s *subscribePush) IsInTsGuide(userid string) bool {
  1508. if userid == "" {
  1509. return false
  1510. }
  1511. data, ok := IC.Mgo.FindById("user", userid, `{"o_jy":1,"i_ts_guide":1,"":1,"i_member_status":1,"i_vip_status":1}`)
  1512. if ok {
  1513. //付费用户无免费订阅,不进入订阅向导页面
  1514. if common.IntAll((*data)["i_member_status"]) > 0 || common.IntAll((*data)["i_vip_status"]) > 0 {
  1515. return false
  1516. }
  1517. o_jy, _ := (*data)["o_jy"].(map[string]interface{})
  1518. i_ts_guide := common.IntAll((*data)["i_ts_guide"])
  1519. if i_ts_guide == 2 || (i_ts_guide == 0 && len(o_jy) == 0) {
  1520. return true
  1521. }
  1522. }
  1523. return false
  1524. }
  1525. func (s *subscribePush) Keys(spqp *KeyParam) (result []*bxsubscribe.KeyItems) {
  1526. keyData := map[string][]interface{}{}
  1527. if spqp.IsEnt {
  1528. //企业关键词查找
  1529. res_, _ := IC.Mgo.Find("entniche_rule", map[string]interface{}{
  1530. "i_userid": map[string]interface{}{
  1531. "$exists": false,
  1532. },
  1533. "i_entid": common.Int64All(spqp.EntId),
  1534. }, "", `{"o_entniche":1}`, false, -1, -1)
  1535. o_entniche := map[string]interface{}{}
  1536. if res_ == nil || len(*res_) == 0 {
  1537. return MapToarr(keyData)
  1538. }
  1539. for _, ruleV := range *res_ {
  1540. o_entniche = common.StructToMapMore(ruleV["o_entniche"])
  1541. if o_entniche["a_items"] != nil {
  1542. a_item := common.ObjArrToMapArr(o_entniche["a_items"].([]interface{}))
  1543. for _, v := range a_item {
  1544. if v["a_key"] != nil {
  1545. a_key_arr := v["a_key"].([]interface{})
  1546. s_item := common.InterfaceToStr(v["s_item"])
  1547. if keyData[s_item] != nil {
  1548. //第一次搜索存在
  1549. //去重
  1550. keyData[s_item] = MergeArray(a_key_arr, keyData[s_item])
  1551. } else {
  1552. //第一次搜索不存在
  1553. keyData[s_item] = a_key_arr
  1554. }
  1555. }
  1556. }
  1557. }
  1558. }
  1559. } else {
  1560. //个人关键词查找
  1561. //fType:普通用户;vType:超级订阅用户;mType:大会员用户;eType:商机管理用户
  1562. types := 2
  1563. typeKey := ""
  1564. switch s.ModuleFlag {
  1565. case SubVipFlag:
  1566. types = 1
  1567. typeKey = "o_vipjy"
  1568. case MemberFlag:
  1569. types = 1
  1570. typeKey = "o_member_jy"
  1571. case EntnicheFlag:
  1572. types = 0
  1573. typeKey = "o_entniche"
  1574. case SubFreeFlag:
  1575. types = 2
  1576. typeKey = "o_jy"
  1577. }
  1578. if spqp.PositionType == 1 {
  1579. typeKey = "o_entniche"
  1580. }
  1581. o_entniche := &map[string]interface{}{}
  1582. if spqp.PositionType == 0 {
  1583. mData, ok := IC.Mgo.FindById("user", spqp.UserId, `{"o_jy":1,"o_vipjy":1,"o_member_jy":1,""i_member_sub_status":1,"s_member_mainid":1}`)
  1584. if mData == nil || len(*mData) == 0 || !ok {
  1585. return nil
  1586. }
  1587. if s.ModuleFlag == MemberFlag {
  1588. sub_status := common.Int64All((*mData)["i_member_sub_status"])
  1589. if sub_status == 1 {
  1590. //大会员子账号处理
  1591. mData, ok = IC.Mgo.FindById("user", common.InterfaceToStr((*mData)["s_member_mainid"]), `{"o_jy":1,"o_vipjy":1,"o_member_jy":1,""i_member_sub_status":1,"s_member_mainid":1}`)
  1592. if mData == nil || len(*mData) == 0 || !ok {
  1593. return nil
  1594. }
  1595. }
  1596. }
  1597. o_entniche = common.ObjToMap((*mData)[typeKey])
  1598. } else {
  1599. res_, _ := IC.Mgo.FindOneByField("entniche_rule", map[string]interface{}{
  1600. "i_userid": common.Int64All(spqp.EntUserId),
  1601. "i_entid": common.Int64All(spqp.EntId),
  1602. "i_type": types,
  1603. }, `{"o_entniche":1}`)
  1604. if res_ != nil {
  1605. o_entniche = common.ObjToMap((*res_)["o_entniche"])
  1606. }
  1607. }
  1608. if s.ModuleFlag == SubVipFlag {
  1609. //从user表中取 o_vipjy.a_items
  1610. if (*o_entniche)["a_items"] != nil {
  1611. a_items := common.ObjArrToMapArr((*o_entniche)["a_items"].([]interface{}))
  1612. for _, v := range a_items {
  1613. if v["a_key"] != nil {
  1614. a_key_arr := v["a_key"].([]interface{})
  1615. keyData[common.InterfaceToStr(v["s_item"])] = a_key_arr
  1616. }
  1617. }
  1618. }
  1619. } else if s.ModuleFlag == MemberFlag {
  1620. //从user表中取 o_member_jy.a_items
  1621. //o_memeberjy := common.ObjToMap((*mData)["o_member_jy"])
  1622. if (*o_entniche)["a_items"] != nil {
  1623. a_items := common.ObjArrToMapArr((*o_entniche)["a_items"].([]interface{}))
  1624. for _, v := range a_items {
  1625. if v["a_key"] != nil {
  1626. a_key_arr := v["a_key"].([]interface{})
  1627. keyData[common.InterfaceToStr(v["s_item"])] = a_key_arr
  1628. }
  1629. }
  1630. }
  1631. } else if s.ModuleFlag == EntnicheFlag {
  1632. res_, _ := IC.Mgo.FindOneByField("entniche_rule", map[string]interface{}{
  1633. "i_userid": common.Int64All(spqp.EntUserId),
  1634. "i_entid": common.Int64All(spqp.EntId),
  1635. "i_type": types,
  1636. }, `{"o_entniche":1}`)
  1637. o_entniche := &map[string]interface{}{}
  1638. if res_ != nil {
  1639. o_entniche = common.ObjToMap((*res_)["o_entniche"])
  1640. }
  1641. if (*o_entniche)["a_items"] != nil {
  1642. a_item := common.ObjArrToMapArr((*o_entniche)["a_items"].([]interface{}))
  1643. for _, v := range a_item {
  1644. if v["a_key"] != nil {
  1645. a_key_arr := v["a_key"].([]interface{})
  1646. keyData[common.InterfaceToStr(v["s_item"])] = a_key_arr
  1647. }
  1648. }
  1649. }
  1650. } else {
  1651. //免费用户
  1652. a_key, _ := (*o_entniche)["a_key"].([]interface{})
  1653. if len(a_key) > 0 {
  1654. for _, v := range a_key {
  1655. if keyData["未分类"] != nil {
  1656. keyData["未分类"] = append(keyData["未分类"], v)
  1657. } else {
  1658. keyData["未分类"] = []interface{}{v}
  1659. }
  1660. }
  1661. }
  1662. }
  1663. if spqp.PositionType == 1 && s.ModuleFlag != SubFreeFlag {
  1664. //1、mysql entniche_user_rule表中获取自己的分发规则id
  1665. data := IC.MainMysql.SelectBySql(`SELECT rule_id FROM entniche_user_rule a
  1666. INNER JOIN entniche_department b ON a.dept_id = b.id AND a.user_id =?
  1667. ORDER BY b.pid
  1668. LIMIT 1 `, spqp.EntUserId)
  1669. if data == nil || len(*data) == 0 {
  1670. return MapToarr(keyData)
  1671. }
  1672. ruleId := common.ObjToString((*data)[0]["rule_id"])
  1673. //3、entniche_distribute表,查询条件:{_id:ObjectId(1结果中的分发规则id),i_status:0},取 o_entniche.a_items,这个查到的是分类名称,然后到上面1的结果中获取这个分类下的词
  1674. res, _ := IC.Mgo.FindById("entniche_distribute", ruleId, nil)
  1675. if res == nil || len(*res) == 0 {
  1676. return MapToarr(keyData)
  1677. }
  1678. entItem := (*res)["a_items"].([]interface{})
  1679. if (*res)["a_items"] == nil {
  1680. return MapToarr(keyData)
  1681. }
  1682. //2、entniche_rule表, 企业订阅关键词查询条件: {i_entid:123,i_deptid:0},取 o_entniche.a_items
  1683. deptid := common.Int64All((*res)["i_deptid"])
  1684. ruleMap := map[string]interface{}{
  1685. "i_entid": common.Int64All(spqp.EntId),
  1686. }
  1687. if deptid == 0 {
  1688. ruleMap["i_deptid"] = map[string]interface{}{"$exists": false}
  1689. ruleMap["i_userid"] = map[string]interface{}{"$exists": false}
  1690. } else {
  1691. ruleMap["i_deptid"] = deptid
  1692. }
  1693. res_, _ := IC.Mgo.FindOneByField("entniche_rule", ruleMap, `{"o_entniche":1}`)
  1694. o_entniche := &map[string]interface{}{}
  1695. if res_ != nil {
  1696. o_entniche = common.ObjToMap((*res_)["o_entniche"])
  1697. }
  1698. entnicheRule := map[string][]interface{}{}
  1699. if (*o_entniche)["a_items"] != nil {
  1700. a_item := common.ObjArrToMapArr((*o_entniche)["a_items"].([]interface{}))
  1701. for _, v := range a_item {
  1702. if v["a_key"] != nil {
  1703. a_key_arr := v["a_key"].([]interface{})
  1704. entnicheRule[common.InterfaceToStr(v["s_item"])] = a_key_arr
  1705. }
  1706. }
  1707. }
  1708. for _, value := range entItem {
  1709. v := common.InterfaceToStr(value)
  1710. if entnicheRule[v] != nil {
  1711. if keyData[v] != nil {
  1712. //第一次搜索存在
  1713. //去重
  1714. keyData[v] = MergeArray(keyData[v], entnicheRule[v])
  1715. } else {
  1716. //第一次搜索不存在
  1717. keyData[v] = entnicheRule[v]
  1718. }
  1719. }
  1720. }
  1721. }
  1722. }
  1723. return MapToarr(keyData)
  1724. }
  1725. // 关键词处理
  1726. func KeyHandle(a_items map[string]interface{}) []interface{} {
  1727. keyArr := []interface{}{}
  1728. if a_items["a_key"] != nil {
  1729. a_key_arr := common.ObjArrToMapArr(a_items["a_key"].([]interface{}))
  1730. for _, vv := range a_key_arr {
  1731. for _, v := range vv["key"].([]interface{}) {
  1732. keyArr = append(keyArr, v)
  1733. }
  1734. }
  1735. }
  1736. return keyArr
  1737. }
  1738. func MapToarr(data map[string][]interface{}) []*bxsubscribe.KeyItems {
  1739. result := []*bxsubscribe.KeyItems{}
  1740. for k, v := range data {
  1741. keyArr := []*bxsubscribe.Key{}
  1742. for _, m := range common.ObjArrToMapArr(v) {
  1743. keys := &bxsubscribe.Key{}
  1744. if m["notkey"] != nil {
  1745. keys.Notkey = common.ObjArrToStringArr(m["notkey"].([]interface{}))
  1746. }
  1747. if m["key"] != nil {
  1748. keys.Key = common.ObjArrToStringArr(m["key"].([]interface{}))
  1749. }
  1750. if m["matchway"] != nil {
  1751. keys.Matchway = common.Int64All(m["matchway"])
  1752. }
  1753. if m["appendkey"] != nil {
  1754. keys.Appendkey = common.ObjArrToStringArr(m["appendkey"].([]interface{}))
  1755. }
  1756. keyArr = append(keyArr, keys)
  1757. }
  1758. result = append(result, &bxsubscribe.KeyItems{
  1759. AKey: keyArr,
  1760. SItem: k,
  1761. })
  1762. }
  1763. return result
  1764. }
  1765. func MergeArray(dest []interface{}, src []interface{}) (result []interface{}) {
  1766. data := map[string]interface{}{}
  1767. for _, v := range common.ObjArrToMapArr(dest) {
  1768. notkey := ""
  1769. key := ""
  1770. matchway := ""
  1771. appendkey := ""
  1772. if v["notkey"] != nil {
  1773. otkeyArr := common.ObjArrToStringArr(v["notkey"].([]interface{}))
  1774. for _, keyV := range otkeyArr {
  1775. if common.InterfaceToStr(keyV) != "" {
  1776. notkey += fmt.Sprintf(",%s", common.InterfaceToStr(keyV))
  1777. }
  1778. }
  1779. }
  1780. if v["key"] != nil {
  1781. keyArr := common.ObjArrToStringArr(v["key"].([]interface{}))
  1782. for _, keyV := range keyArr {
  1783. if common.InterfaceToStr(keyV) != "" {
  1784. key += fmt.Sprintf(",%s", common.InterfaceToStr(keyV))
  1785. }
  1786. }
  1787. }
  1788. if v["matchway"] != nil {
  1789. matchway = common.InterfaceToStr(v["matchway"])
  1790. }
  1791. if v["appendkey"] != nil {
  1792. appendkeyArr := common.ObjArrToStringArr(v["appendkey"].([]interface{}))
  1793. for _, keyV := range appendkeyArr {
  1794. if common.InterfaceToStr(keyV) != "" {
  1795. appendkey += fmt.Sprintf(",%s", common.InterfaceToStr(keyV))
  1796. }
  1797. }
  1798. }
  1799. k := fmt.Sprintf("%s_____%s_____%s_____%s", notkey, key, matchway, appendkey)
  1800. data[k] = v
  1801. }
  1802. for _, v := range common.ObjArrToMapArr(src) {
  1803. notkey := ""
  1804. key := ""
  1805. matchway := ""
  1806. appendkey := ""
  1807. if v["notkey"] != nil {
  1808. otkeyArr := common.ObjArrToStringArr(v["notkey"].([]interface{}))
  1809. for _, keyV := range otkeyArr {
  1810. if common.InterfaceToStr(keyV) != "" {
  1811. notkey += fmt.Sprintf(",%s", common.InterfaceToStr(keyV))
  1812. }
  1813. }
  1814. }
  1815. if v["key"] != nil {
  1816. keyArr := common.ObjArrToStringArr(v["key"].([]interface{}))
  1817. for _, keyV := range keyArr {
  1818. if common.InterfaceToStr(keyV) != "" {
  1819. key += fmt.Sprintf(",%s", common.InterfaceToStr(keyV))
  1820. }
  1821. }
  1822. }
  1823. if v["matchway"] != nil {
  1824. matchway = common.InterfaceToStr(v["matchway"])
  1825. }
  1826. if v["appendkey"] != nil {
  1827. appendkeyArr := common.ObjArrToStringArr(v["appendkey"].([]interface{}))
  1828. for _, keyV := range appendkeyArr {
  1829. if common.InterfaceToStr(keyV) != "" {
  1830. appendkey += fmt.Sprintf(",%s", common.InterfaceToStr(keyV))
  1831. }
  1832. }
  1833. }
  1834. k := fmt.Sprintf("%s_____%s_____%s_____%s", notkey, key, matchway, appendkey)
  1835. data[k] = v
  1836. }
  1837. for _, v := range data {
  1838. result = append(result, v)
  1839. }
  1840. return
  1841. }
  1842. func (s *subscribePush) ItemToKey(in *SubPushQueryParam) string {
  1843. moduleFlag := s.ModuleFlag
  1844. s.ModuleFlag = in.UserType
  1845. spqp := KeyParam{
  1846. UserId: in.UserId,
  1847. EntUserId: in.EntUserId,
  1848. DeptId: in.DeptId,
  1849. NewUserId: in.NewUserId,
  1850. IsEnt: in.IsEnt,
  1851. EntId: in.EntId,
  1852. PositionType: in.PositionType,
  1853. }
  1854. //所有关键词获取
  1855. keyItemsArr := s.Keys(&spqp)
  1856. s.ModuleFlag = moduleFlag
  1857. keyArr := []string{}
  1858. if len(keyItemsArr) > 0 {
  1859. for _, k1 := range keyItemsArr {
  1860. for _, k2 := range strings.Split(in.Item, ",") {
  1861. if k1.SItem == k2 {
  1862. if len(k1.AKey) > 0 {
  1863. for _, k3 := range k1.AKey {
  1864. key := ""
  1865. if len(k3.Key) > 0 {
  1866. key = strings.Join(k3.Key, " ")
  1867. }
  1868. if len(k3.Appendkey) > 0 {
  1869. if key != "" {
  1870. key += " " + strings.Join(k3.Appendkey, " ")
  1871. } else {
  1872. key = strings.Join(k3.Appendkey, " ")
  1873. }
  1874. }
  1875. if k3.Matchway == 1 {
  1876. //模糊处理
  1877. key = strings.ReplaceAll(key, " ", ",")
  1878. } else {
  1879. //精准处理
  1880. key = strings.ReplaceAll(key, " ", "+")
  1881. }
  1882. keyArr = append(keyArr, key)
  1883. }
  1884. }
  1885. }
  1886. }
  1887. }
  1888. }
  1889. return strings.Join(keyArr, ",")
  1890. }
  1891. func (s *SubPushQueryParam) ExportPushFormat() (ids, keyWords []string) {
  1892. if len(s.SelectInfoIds) > 0 {
  1893. for ik, id := range s.SelectInfoIds {
  1894. if xid := util.DecodeId(id); len(xid) > 0 {
  1895. ids = append(ids, xid)
  1896. if len(s.SelectKeys) > ik {
  1897. keyWords = append(keyWords, strings.ReplaceAll(s.SelectKeys[ik], " ", ","))
  1898. } else {
  1899. keyWords = append(keyWords, "")
  1900. }
  1901. }
  1902. }
  1903. }
  1904. return
  1905. }