inforelatedlogic.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jyInfo/rpc/consumer/consumerclient"
  4. "app.yhyue.com/moapp/jyInfo/rpc/consumer/internal/svc"
  5. "app.yhyue.com/moapp/jyInfo/rpc/model"
  6. "app.yhyue.com/moapp/jyInfo/rpc/util"
  7. se "app.yhyue.com/moapp/jybase/encrypt"
  8. "context"
  9. "log"
  10. mc "app.yhyue.com/moapp/jybase/common"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type InfoRelatedLogic struct {
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. logx.Logger
  17. }
  18. func NewInfoRelatedLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoRelatedLogic {
  19. return &InfoRelatedLogic{
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. Logger: logx.WithContext(ctx),
  23. }
  24. }
  25. // 关联公告
  26. func (l *InfoRelatedLogic) InfoRelated(in *consumerclient.UserIdReq) (*consumerclient.InfoRelatedResp, error) {
  27. // todo: add your logic here and delete this line
  28. var (
  29. queryName string
  30. resp consumerclient.InfoRelatedResp
  31. )
  32. log.Println("关联公告接口调用", in)
  33. queryName = ` and type=` + mc.InterfaceToStr(in.MsgType)
  34. if in.AppId != "" {
  35. queryName = queryName + ` and app_id = ` + util.StrFormat(in.AppId)
  36. }
  37. if in.EntId != 0 {
  38. queryName = queryName + ` and ent_id = ` + mc.InterfaceToStr(in.EntId)
  39. }
  40. switch in.MsgId {
  41. case 0:
  42. if in.Match != "" {
  43. queryName = queryName + ` and title LIKE '%` + in.Match + `%' `
  44. }
  45. allData := model.Mysql.SelectBySql(`SELECT id,title,contact_person,contact_phone,contact_overt from information WHERE user_id="` + in.UserId + `" and published=2 and is_del=1` + queryName + ` order by create_time desc limit 50`)
  46. if allData == nil || len(*allData) == 0 {
  47. return &resp, nil
  48. }
  49. for _, v := range *allData {
  50. var data consumerclient.InfoData
  51. data.Id = se.SE.EncodeString(mc.InterfaceToStr(v["id"])) //关联信息加密
  52. data.Title = mc.InterfaceToStr(v["title"])
  53. data.Person = mc.InterfaceToStr(v["contact_person"])
  54. data.Phone = mc.InterfaceToStr(v["contact_phone"])
  55. data.Overt = mc.Int64All(v["contact_overt"])
  56. resp.Data = append(resp.Data, &data)
  57. }
  58. case 1:
  59. var allData *[]map[string]interface{}
  60. if in.MsgType == 1 || in.MsgType == 2 {
  61. allData = model.Mysql.SelectBySql(`SELECT id,title,contact_person,contact_phone,contact_overt from information WHERE user_id="` + in.UserId + `"` + queryName + ` order by create_time desc limit 1`)
  62. } else if in.MsgType == 3 {
  63. allData = model.Mysql.SelectBySql(`SELECT id,title,contact_person,contact_phone,contact_overt from supply_info WHERE user_id="` + in.UserId + `"` + queryName + ` order by create_time desc limit 1`)
  64. }
  65. if allData == nil || len(*allData) == 0 {
  66. return &resp, nil
  67. }
  68. for _, v := range *allData {
  69. var data consumerclient.InfoData
  70. data.Id = se.SE.EncodeString(mc.InterfaceToStr(v["id"])) //关联信息加密
  71. data.Title = mc.InterfaceToStr(v["title"])
  72. data.Person = mc.InterfaceToStr(v["contact_person"])
  73. data.Phone = mc.InterfaceToStr(v["contact_phone"])
  74. data.Overt = mc.Int64All(v["contact_overt"])
  75. resp.Data = append(resp.Data, &data)
  76. }
  77. }
  78. return &resp, nil
  79. }