suggestion_order_list.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package suggestion
  4. import (
  5. "context"
  6. "encoding/json"
  7. "fmt"
  8. "property-garden/errors"
  9. dbmodel "property-garden/model"
  10. pb_v1 "property-garden/pb/v1"
  11. "property-garden/utils"
  12. "strings"
  13. "git.getensh.com/common/gopkgs/database"
  14. "git.getensh.com/common/gopkgs/logger"
  15. "go.uber.org/zap"
  16. "google.golang.org/grpc/status"
  17. )
  18. func checkSuggestionOrderListParam(req *pb_v1.SuggestionOrderListRequest) error {
  19. switch {
  20. case req.GardenId == 0:
  21. return status.Error(10003, "小区不能为空")
  22. }
  23. if req.PageSize == 0 {
  24. req.PageSize = 10
  25. }
  26. if req.Page == 0 {
  27. req.Page = 1
  28. }
  29. return nil
  30. }
  31. func SuggestionOrderList(ctx context.Context, req *pb_v1.SuggestionOrderListRequest) (reply *pb_v1.SuggestionOrderListReply, err error) {
  32. reply = &pb_v1.SuggestionOrderListReply{}
  33. // 捕获各个task中的异常并返回给调用者
  34. defer func() {
  35. if r := recover(); r != nil {
  36. err = fmt.Errorf("%+v", r)
  37. e := &status.Status{}
  38. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  39. logger.Error("err",
  40. zap.String("system_err", err.Error()),
  41. zap.Stack("stacktrace"))
  42. }
  43. }
  44. }()
  45. // 参数检查
  46. err = checkSuggestionOrderListParam(req)
  47. if err != nil {
  48. return nil, err
  49. }
  50. dbname := utils.GetGardenDbName(req.GardenId)
  51. p := dbmodel.NewSuggestionOrder(dbname)
  52. where := map[string]interface{}{}
  53. if req.CurrentUid > 0 {
  54. where["current_uid"] = req.CurrentUid
  55. }
  56. if req.Status > 0 {
  57. where["status"] = req.Status
  58. }
  59. if req.ApplyPeople != "" {
  60. where["apply_people"] = req.ApplyPeople
  61. }
  62. if req.ApplyPeoplePhone != "" {
  63. where["apply_people_phone"] = req.ApplyPeoplePhone
  64. }
  65. if req.SuggestionType > 0 {
  66. where["suggestion_type"] = req.SuggestionType
  67. }
  68. if req.HouseholdUid > 0 {
  69. where["household_uid"] = req.HouseholdUid
  70. }
  71. reply.Page = req.Page
  72. reply.Total, err = p.Count(database.DB(), where, nil)
  73. if err != nil {
  74. return nil, errors.DataBaseError
  75. }
  76. if reply.Total == 0 {
  77. return reply, nil
  78. }
  79. list, err := p.List(database.DB(), where, nil, int(req.Page), int(req.PageSize))
  80. if err != nil {
  81. return nil, errors.DataBaseError
  82. }
  83. reply.List = make([]*pb_v1.SuggestionOrderItem, len(list))
  84. uids := []int64{}
  85. for _, v := range list {
  86. if v.CurrentUid > 0 {
  87. uids = append(uids, v.CurrentUid)
  88. }
  89. if !v.LastUidIsCompany && v.LastUid > 0 {
  90. uids = append(uids, v.LastUid)
  91. }
  92. }
  93. userInfos, err := getUserInfos(uids, req.GardenId)
  94. if err != nil {
  95. return nil, err
  96. }
  97. for i, v := range list {
  98. item := &pb_v1.SuggestionOrderItem{
  99. // 分类id
  100. SuggestionType:v.SuggestionType,
  101. // 投诉人
  102. ApplyPeople:v.ApplyPeople,
  103. // 投诉人电话
  104. ApplyPeoplePhone:v.ApplyPeoplePhone,
  105. // 处理人
  106. CurrentUser:userInfos[v.CurrentUid].Name,
  107. // 报修内容
  108. ApplyContent:v.ApplyContent,
  109. // 报修图片
  110. ApplyPic:strings.Split(v.ApplyPic, ";"),
  111. // 回访内容
  112. ReturnVisitContent: v.ReturnVisitContent,
  113. // 回访满意度
  114. ReturnVisitLevel: v.ReturnVisitLevel,
  115. // 报修时间
  116. CreatedAt:v.CreatedAt.Format("2006-01-02 15:04:05"),
  117. Id:v.ID,
  118. Status:v.Status,
  119. }
  120. if !v.LastUidIsCompany {
  121. item.LastUser = userInfos[v.LastUid].Name
  122. }
  123. reply.List[i] = item
  124. }
  125. return reply, nil
  126. }