push.go 83 KB

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