push.go 68 KB

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