newestbiddinglogic.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. package logic
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. IC "jyBXBase/rpc/init"
  7. "jyBXBase/rpc/model"
  8. "log"
  9. "sort"
  10. "time"
  11. MC "app.yhyue.com/moapp/jybase/common"
  12. "app.yhyue.com/moapp/jybase/redis"
  13. "jyBXBase/rpc/internal/svc"
  14. "jyBXBase/rpc/type/bxbase"
  15. "github.com/zeromicro/go-zero/core/logx"
  16. )
  17. type NewestBiddingLogic struct {
  18. ctx context.Context
  19. svcCtx *svc.ServiceContext
  20. logx.Logger
  21. }
  22. func NewNewestBiddingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NewestBiddingLogic {
  23. return &NewestBiddingLogic{
  24. ctx: ctx,
  25. svcCtx: svcCtx,
  26. Logger: logx.WithContext(ctx),
  27. }
  28. }
  29. // 首页最新招标信息
  30. func (l *NewestBiddingLogic) NewestBidding(in *bxbase.NewestBiddingReq) (*bxbase.NewsetBiddingResp, error) {
  31. t := time.Now()
  32. userType := ""
  33. // status : 0 -不存缓存 1-存到未登录用户 2-存到用户自己的key 3-存到登录用户最新标讯
  34. r, status := func(in *bxbase.NewestBiddingReq) (*bxbase.NewsetBiddingResp, int) {
  35. var res = &bxbase.NewsetBiddingResp{
  36. Data: &bxbase.NewsetBidding{
  37. List: []*bxbase.NewestList{},
  38. },
  39. }
  40. // 1. 未登录用户 查未登录缓存 返回 没有缓存 查最新标讯存未登录返回
  41. // 2. 登录用户 查count count=1 查用户缓存 缓存没数据查用户推送
  42. // count =0 查最新标讯缓存 缓存没数据查最新标讯存登录缓存 显示引导用户设置关键词
  43. if in.UserId == "" {
  44. redisKey := "p1_indexMessage_new_noLogin_%d_%d_%d"
  45. redisKey = fmt.Sprintf(redisKey, time.Now().Year(), time.Now().Month(), time.Now().Day())
  46. redisByte, err := redis.GetBytes("other", redisKey)
  47. if err == nil && redisByte != nil && len(*redisByte) > 0 {
  48. err = json.Unmarshal(*redisByte, res.Data)
  49. if err != nil {
  50. logx.Info(fmt.Sprintf("读取缓存 序列化异常,err:%s", err.Error()))
  51. }
  52. }
  53. if len(res.Data.List) > 0 { // 缓存有数据直接返回
  54. return res, 0
  55. }
  56. // todo 没数据查最新数据返回
  57. //未登录用户访问全部信息类型 需要过滤掉 拟建和采购意向
  58. //subtype = `"预告","公告","结果","其它"`
  59. //
  60. return res, 1
  61. }
  62. // 登录根据用户身份构造 roleNewestInfo 用于后边查询数据
  63. var roleNewestInfo *model.NewestInfo
  64. flag := ""
  65. powerCheck := IC.Middleground.PowerCheckCenter.Check(in.AppId, in.MgoUserId, in.NewUserId, in.AccountId, in.EntId, in.PositionType, in.PositionId)
  66. if powerCheck.Member.Status > 0 {
  67. // 大会员
  68. flag = "m"
  69. if in.PositionType == int64(1) {
  70. roleNewestInfo = model.GetNewestInfo(MC.InterfaceToStr(in.EntUserId), "e", in.EntUserId)
  71. } else {
  72. roleNewestInfo = model.GetNewestInfo(MC.InterfaceToStr(in.NewUserId), "m", in.NewUserId)
  73. }
  74. } else if powerCheck.Entniche.Status > 0 && powerCheck.Entniche.PowerSource != 1 && powerCheck.Entniche.IsEntPower == 1 {
  75. // 商机管理
  76. flag = "e"
  77. roleNewestInfo = model.GetNewestInfo(MC.InterfaceToStr(in.EntUserId), "e", in.EntUserId)
  78. } else if powerCheck.Vip.Status > 0 {
  79. // 超级订阅
  80. flag = "v"
  81. if in.PositionType == int64(1) {
  82. roleNewestInfo = model.GetNewestInfo(MC.InterfaceToStr(in.EntUserId), "e", in.EntUserId)
  83. } else {
  84. roleNewestInfo = model.GetNewestInfo(MC.InterfaceToStr(in.NewUserId), "v", in.NewUserId)
  85. }
  86. } else {
  87. // 普通用户
  88. flag = "f"
  89. if in.PositionType == int64(1) {
  90. roleNewestInfo = model.GetNewestInfo(MC.InterfaceToStr(in.EntUserId), "e", in.EntUserId)
  91. } else {
  92. roleNewestInfo = model.GetNewestInfo(MC.InterfaceToStr(in.NewUserId), "f", in.NewUserId)
  93. }
  94. }
  95. res.Data.SubFlag = flag
  96. existData := roleNewestInfo.GetPushHistoryCount()
  97. if existData > 0 { // 存在推送 查推送缓存 缓存没有数据则查 推送数据
  98. res.Data.ShowTip = 1 // 不显示
  99. // todo 查缓存
  100. return res, 0
  101. // 查推送
  102. return res, 2
  103. } else { // 等0则说明推送里面没有数据 所以去查最新标讯信息缓存 返回 缓存没有则查最新标讯信息 存到缓存里面
  104. res.Data.ShowTip = 2 // 不显示
  105. // 查缓存
  106. return res, 0
  107. // todo 查最新标讯
  108. // 显示引导设置
  109. return res, 3
  110. }
  111. return res, 0
  112. }(in)
  113. //if r.Data.Count > 0 {
  114. // //排序
  115. // sort.Slice(r.Data.List, func(i, j int) bool {
  116. // return r.Data.List[i].PublishTime > r.Data.List[j].PublishTime
  117. // })
  118. // //-1:程序异常 0 不存在缓存数据 1 存在缓存数据 新数据 存入缓存
  119. // if i == 0 {
  120. // rks := ""
  121. // if userType == "e" {
  122. // rks = MC.If(in.UserId != "", in.EntUserId, in.City).(string)
  123. // } else {
  124. // rks = MC.If(in.UserId != "", in.UserId, in.City).(string)
  125. // }
  126. // //rks := MC.If(in.UserId != "", in.UserId, in.City).(string)
  127. // b, err := json.Marshal(r.Data)
  128. // if err != nil {
  129. // r.ErrCode = -1
  130. // r.ErrMsg = fmt.Sprintf("保存缓存 序列化异常,err:%s", err.Error())
  131. // } else {
  132. // redisKey := "p1_indexMessage_new_" + rks
  133. // timeOut := 2 * 60 * 60
  134. // if in.UserId == "" {
  135. // //未登录用户缓存一天
  136. // timeOut = 24 * 60 * 60
  137. // redisKey = fmt.Sprintf("%s_%d_%d_%d", redisKey, time.Now().Year(), time.Now().Month(), time.Now().Day())
  138. // }
  139. // if err = redis.PutBytes("other", redisKey, &b, timeOut); err != nil {
  140. // r.ErrCode = -1
  141. // r.ErrMsg = fmt.Sprintf("保存缓存 redis 异常,err:%s", err.Error())
  142. // }
  143. // }
  144. // }
  145. //}
  146. model.MakeCollection(in.UserId, r.Data.List)
  147. log.Println("接口耗时:", time.Since(t).Seconds())
  148. return r, nil
  149. }
  150. //func (l *NewestBiddingLogic) NewestBidding(in *bxbase.NewestBiddingReq) (*bxbase.NewsetBiddingResp, error) {
  151. // t := time.Now()
  152. // userType := ""
  153. // r, i := func(in *bxbase.NewestBiddingReq) (*bxbase.NewsetBiddingResp, int) {
  154. // var res = &bxbase.NewsetBiddingResp{
  155. // Data: &bxbase.NewsetBidding{
  156. // List: []*bxbase.NewestList{},
  157. // },
  158. // }
  159. // entUserId, _ := strconv.ParseInt(in.EntUserId, 10, 64)
  160. // //主体处理(fType:普通用户;vType:超级订阅用户;mType:大会员用户;eType:商机管理用户)
  161. // if in.PositionType == 1 {
  162. // //主体等于企业的
  163. // userType = "e"
  164. // }
  165. // rks := ""
  166. // if userType == "e" {
  167. // rks = MC.If(in.UserId != "", in.EntUserId, in.City).(string)
  168. // } else {
  169. // rks = MC.If(in.UserId != "", in.UserId, in.City).(string)
  170. // }
  171. // redisKey := "p1_indexMessage_new_" + rks
  172. // if in.UserId == "" {
  173. // //未登录用户查询当天缓存
  174. // redisKey = fmt.Sprintf("%s_%d_%d_%d", redisKey, time.Now().Year(), time.Now().Month(), time.Now().Day())
  175. // }
  176. // redisByte, err := redis.GetBytes("other", redisKey)
  177. // if err == nil && redisByte != nil && len(*redisByte) > 0 {
  178. // err = json.Unmarshal(*redisByte, res.Data)
  179. // if err != nil {
  180. // logx.Info(fmt.Sprintf("读取缓存 序列化异常,err:%s", err.Error()))
  181. // }
  182. // if len(res.Data.List) > 0 {
  183. // return res, 1
  184. // }
  185. // }
  186. // var subtype string
  187. // //登录用户
  188. // if in.UserId != "" {
  189. // //优先级 由测试确认 大会员 》 商机管理 》 VIP 》 普通用户 》 搜索历史
  190. // //获取订阅信息
  191. // userMap := IC.Compatible.Select(in.UserId, `{"o_jy":1,"o_vipjy":1,"i_vip_status":1,"o_member_jy":1,"i_member_status":1,"s_m_phone":1,"s_phone":1}`)
  192. // if userMap == nil || len(*userMap) == 0 {
  193. // //查询出错
  194. // res.ErrCode = -1
  195. // res.ErrMsg = fmt.Errorf("未查询到用户信息").Error()
  196. // return res, -1
  197. // }
  198. // //var isPayUser bool = false
  199. // //付费用户如果没有数据 直接返回 需求来源:测试
  200. // //vip用户
  201. // vipStatus := MC.IntAll((*userMap)["i_vip_status"])
  202. // //大会员用户
  203. // bigStatus := MC.Int64All((*userMap)["i_member_status"])
  204. // if bigStatus > 0 {
  205. // o_msgset := MC.ObjToMap((*userMap)["o_member_jy"])
  206. // big_items, ok := (*o_msgset)["a_items"].([]interface{})
  207. // //大会员推送历史
  208. // result := []*bxbase.NewestList{}
  209. // if userType == "e" {
  210. // result = model.GetNewestInfo(rks, "e", entUserId).GetPushHistory()
  211. // } else {
  212. // result = model.GetNewestInfo(rks, "m", in.NewUserId).GetPushHistory()
  213. // }
  214. // res.Data.Count = int64(len(result))
  215. // if res.Data.Count > 0 {
  216. // res.Data.HasSubKeys = ok && len(big_items) > 0
  217. // res.Data.List = result
  218. // res.Data.SubFlag = "m"
  219. // }
  220. // return res, 0
  221. // }
  222. // if phone := MC.If((*userMap)["s_phone"] != nil, MC.ObjToString((*userMap)["s_phone"]), MC.ObjToString((*userMap)["s_m_phone"])).(string); phone != "" && in.EntUserId != "" && in.EntId != "" {
  223. // //商机管理
  224. // entNicheInfos := IC.MainMysql.SelectBySql(`SELECT i.power_source,u.power FROM entniche_user u LEFT JOIN entniche_info i ON u.ent_id=i.id WHERE u.phone=? and i.status=1 AND i.id = ?`, phone, in.EntId)
  225. // if entNicheInfos != nil && len(*entNicheInfos) > 0 {
  226. // entNicheInfo := (*entNicheInfos)[0]
  227. // //排除商机管理服务
  228. // if MC.IntAll(entNicheInfo["power_source"]) != 1 {
  229. // // 已分发权限
  230. // if MC.IntAll(entNicheInfo["power"]) > 0 {
  231. // //商机管理推送历史
  232. // result := model.GetNewestInfo(in.EntUserId, "e", entUserId).GetPushHistory()
  233. // res.Data.Count = int64(len(result))
  234. // if res.Data.Count > 0 {
  235. // res.Data.List = result
  236. // res.Data.SubFlag = "e"
  237. // }
  238. // return res, 0
  239. // }
  240. // }
  241. // }
  242. // }
  243. // if vipStatus > 0 {
  244. // o_msgset := MC.ObjToMap((*userMap)["o_vipjy"])
  245. // vip_items, ok := (*o_msgset)["a_items"].([]interface{})
  246. // //vip查询推送历史
  247. // result := []*bxbase.NewestList{}
  248. // if userType == "e" {
  249. // result = model.GetNewestInfo(rks, "e", entUserId).GetPushHistory()
  250. // } else {
  251. // result = model.GetNewestInfo(rks, "v", in.NewUserId).GetPushHistory()
  252. // }
  253. // res.Data.IsVip = true
  254. // res.Data.HasSubKeys = ok && len(vip_items) > 0
  255. // res.Data.Count = int64(len(result))
  256. // res.Data.List = result
  257. // res.Data.SubFlag = "v"
  258. // return res, 0
  259. // }
  260. //
  261. // //普通用户用户- 有关键词
  262. // o_msgset := MC.ObjToMap((*userMap)["o_jy"])
  263. // items, ok := (*o_msgset)["a_key"].([]interface{})
  264. // if ok && len(items) > 0 {
  265. // //普通用户查询推送历史
  266. // result := []*bxbase.NewestList{}
  267. // if userType == "e" {
  268. // result = model.GetNewestInfo(rks, "e", entUserId).GetPushHistory()
  269. // } else {
  270. // result = model.GetNewestInfo(rks, "f", in.NewUserId).GetPushHistory()
  271. // }
  272. // res.Data.IsVip = false
  273. // res.Data.HasSubKeys = ok && len(items) > 0
  274. // res.Data.Count = int64(len(result))
  275. // res.Data.List = result
  276. // res.Data.SubFlag = "f"
  277. // return res, 0
  278. // }
  279. // //搜索历史-关键词
  280. // hKeys := redis.GetStr("other", fmt.Sprintf("s_%s", in.UserId))
  281. // if hKeys != "" && len(strings.Split(hKeys, ",")) > 0 {
  282. // //历史搜索
  283. // res.Data.History = strings.Split(hKeys, ",")
  284. // //根据订阅词获取查询语句
  285. // query := model.NewestQuery("", hKeys, subtype)
  286. // result := model.NewestES(query)
  287. // res.Data.IsVip = false
  288. // res.Data.HasSubKeys = false
  289. // res.Data.Count = int64(len(result))
  290. // res.Data.List = result
  291. // return res, 0
  292. // }
  293. // } else {
  294. // //未登录用户访问全部信息类型 需要过滤掉 拟建和采购意向
  295. // subtype = `"预告","公告","结果","其它"`
  296. // }
  297. // if in.IsSearch == 2 { //定位查询(默认全国)
  298. // query := model.NewestQuery(rks, "", subtype)
  299. // result := model.NewestES(query)
  300. // res.Data.IsVip = false
  301. // res.Data.HasSubKeys = false
  302. // res.Data.Count = int64(len(result))
  303. // res.Data.List = result
  304. // return res, 0
  305. // }
  306. // return res, 0
  307. // }(in)
  308. // if r.Data.Count > 0 {
  309. // //排序
  310. // sort.Slice(r.Data.List, func(i, j int) bool {
  311. // return r.Data.List[i].PublishTime > r.Data.List[j].PublishTime
  312. // })
  313. // //-1:程序异常 0 不存在缓存数据 1 存在缓存数据 新数据 存入缓存
  314. // if i == 0 {
  315. // rks := ""
  316. // if userType == "e" {
  317. // rks = MC.If(in.UserId != "", in.EntUserId, in.City).(string)
  318. // } else {
  319. // rks = MC.If(in.UserId != "", in.UserId, in.City).(string)
  320. // }
  321. // //rks := MC.If(in.UserId != "", in.UserId, in.City).(string)
  322. // b, err := json.Marshal(r.Data)
  323. // if err != nil {
  324. // r.ErrCode = -1
  325. // r.ErrMsg = fmt.Sprintf("保存缓存 序列化异常,err:%s", err.Error())
  326. // } else {
  327. // redisKey := "p1_indexMessage_new_" + rks
  328. // timeOut := 2 * 60 * 60
  329. // if in.UserId == "" {
  330. // //未登录用户缓存一天
  331. // timeOut = 24 * 60 * 60
  332. // redisKey = fmt.Sprintf("%s_%d_%d_%d", redisKey, time.Now().Year(), time.Now().Month(), time.Now().Day())
  333. // }
  334. // if err = redis.PutBytes("other", redisKey, &b, timeOut); err != nil {
  335. // r.ErrCode = -1
  336. // r.ErrMsg = fmt.Sprintf("保存缓存 redis 异常,err:%s", err.Error())
  337. // }
  338. // }
  339. // }
  340. // }
  341. // model.MakeCollection(in.UserId, r.Data.List)
  342. // log.Println("接口耗时:", time.Since(t).Seconds())
  343. // return r, nil
  344. //}