industryinfologic.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jyInfo/rpc/common/commoninfo"
  4. "app.yhyue.com/moapp/jyInfo/rpc/common/internal/svc"
  5. md "app.yhyue.com/moapp/jyInfo/rpc/model"
  6. mc "app.yhyue.com/moapp/jybase/common"
  7. "context"
  8. "github.com/zeromicro/go-zero/core/logx"
  9. )
  10. type IndustryInfoLogic struct {
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. logx.Logger
  14. }
  15. func NewIndustryInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *IndustryInfoLogic {
  16. return &IndustryInfoLogic{
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. Logger: logx.WithContext(ctx),
  20. }
  21. }
  22. // 获取行业信息
  23. func (l *IndustryInfoLogic) IndustryInfo(in *commoninfo.ProjectReq) (*commoninfo.IndustryResp, error) {
  24. var resp commoninfo.IndustryResp
  25. data := *md.Mysql.Find("infotype", map[string]interface{}{}, "", "", -1, 0)
  26. var rData commoninfo.Idata
  27. var industrys []*commoninfo.Industry
  28. var supplys []*commoninfo.Supply
  29. var infotype []*commoninfo.Infotype
  30. infotypes := []map[string]interface{}{}
  31. for _, v := range data {
  32. if mc.Int64All(v["type"]) == 4 {
  33. var industry commoninfo.Industry
  34. industry.Name = mc.InterfaceToStr(v["name"])
  35. industrys = append(industrys, &industry)
  36. } else if mc.Int64All(v["type"]) == 3 {
  37. var supply commoninfo.Supply
  38. supply.Name = mc.InterfaceToStr(v["name"])
  39. supplys = append(supplys, &supply)
  40. } else if mc.Int64All(v["type"]) == 1 {
  41. var info commoninfo.Infotype
  42. info.Id = mc.Int64All(v["id"])
  43. info.Name = mc.InterfaceToStr(v["name"])
  44. infotype = append(infotype, &info)
  45. } else {
  46. infotypes = append(infotypes, v)
  47. }
  48. }
  49. for _, info := range infotype {
  50. var childs []*commoninfo.IndustryChildsResp
  51. for _, i := range infotypes {
  52. if i["pid"] == info.Id {
  53. var child commoninfo.IndustryChildsResp
  54. child.Name = mc.InterfaceToStr(i["name"])
  55. childs = append(childs, &child)
  56. }
  57. }
  58. info.Childs = childs
  59. }
  60. rData.Industry = industrys
  61. rData.Buyerclass = supplys
  62. rData.Infotype = infotype
  63. resp.Data = &rData
  64. return &resp, nil
  65. }