suggestion_order_info.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. "gorm.io/gorm"
  9. "property-garden/errors"
  10. dbmodel "property-garden/model"
  11. pb_v1 "property-garden/pb/v1"
  12. "property-garden/utils"
  13. "strings"
  14. "git.getensh.com/common/gopkgs/database"
  15. "git.getensh.com/common/gopkgs/logger"
  16. "go.uber.org/zap"
  17. "google.golang.org/grpc/status"
  18. )
  19. func checkSuggestionOrderInfoParam(req *pb_v1.SuggestionOrderInfoRequest) error {
  20. switch {
  21. case req.GardenId == 0:
  22. return status.Error(10003, "小区不能为空")
  23. case req.Id == 0:
  24. return status.Error(10003, "id 不能为空")
  25. }
  26. return nil
  27. }
  28. func SuggestionOrderInfo(ctx context.Context, req *pb_v1.SuggestionOrderInfoRequest) (reply *pb_v1.SuggestionOrderInfoReply, err error) {
  29. reply = &pb_v1.SuggestionOrderInfoReply{}
  30. // 捕获各个task中的异常并返回给调用者
  31. defer func() {
  32. if r := recover(); r != nil {
  33. err = fmt.Errorf("%+v", r)
  34. e := &status.Status{}
  35. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  36. logger.Error("err",
  37. zap.String("system_err", err.Error()),
  38. zap.Stack("stacktrace"))
  39. }
  40. }
  41. }()
  42. // 参数检查
  43. err = checkSuggestionOrderInfoParam(req)
  44. if err != nil {
  45. return nil, err
  46. }
  47. dbname := utils.GetGardenDbName(req.GardenId)
  48. p := dbmodel.NewSuggestionOrder(dbname)
  49. where := map[string]interface{}{
  50. "id": req.Id,
  51. }
  52. err = p.Find(database.DB(), where)
  53. if err != nil && err != gorm.ErrRecordNotFound {
  54. return nil, errors.DataBaseError
  55. }
  56. if p.ID == 0 {
  57. return nil, errors.ErrRecordNotFound
  58. }
  59. // 处理流水线
  60. pipeline := []SuggestionOrderPipelineData{}
  61. json.Unmarshal([]byte(p.Pipeline), &pipeline)
  62. uids := []int64{}
  63. for _, v := range pipeline{
  64. if v.CurrentUid > 0 {
  65. uids = append(uids, v.CurrentUid)
  66. }
  67. if !v.LastByCompany && v.LastUid > 0 {
  68. uids = append(uids, v.LastUid)
  69. }
  70. }
  71. userInfos, err := getUserInfos(uids, req.GardenId)
  72. if err != nil {
  73. return nil, err
  74. }
  75. rspPipeline := make([]*pb_v1.SuggestionOrderPipelineData, len(pipeline))
  76. for i, v := range pipeline {
  77. item := &pb_v1.SuggestionOrderPipelineData{
  78. // 处理意见
  79. Feedback:v.Feedback,
  80. // 处理时间
  81. HandleTime:v.HandleTime,
  82. Status:SuggestionPipelineStatusM[v.Status],
  83. }
  84. switch v.Status {
  85. case SuggestionPipelineStatusCreate:
  86. item.User = p.ApplyPeople
  87. item.Feedback = p.ApplyContent
  88. item.Phone = p.ApplyPeoplePhone
  89. case SuggestionPipelineStatusSend:
  90. item.User = userInfos[v.CurrentUid].Name
  91. item.Phone = userInfos[v.CurrentUid].Phone
  92. case SuggestionPipelineStatusFinish:
  93. if !v.LastByCompany {
  94. item.User = userInfos[v.LastUid].Name
  95. item.Phone = userInfos[v.LastUid].Phone
  96. }
  97. case SuggestionPipelineStatusBack:
  98. if !v.LastByCompany {
  99. item.User = userInfos[v.LastUid].Name
  100. item.Phone = userInfos[v.LastUid].Phone
  101. }
  102. case SuggestionPipelineStatusResend:
  103. item.User = userInfos[v.CurrentUid].Name
  104. item.Phone = userInfos[v.CurrentUid].Phone
  105. }
  106. rspPipeline[i] = item
  107. }
  108. // 处理基本信息
  109. item := &pb_v1.SuggestionOrderItem{
  110. // 分类id
  111. SuggestionType: p.SuggestionType,
  112. // 报修人
  113. ApplyPeople: p.ApplyPeople,
  114. // 报修人电话
  115. ApplyPeoplePhone: p.ApplyPeoplePhone,
  116. // 处理人
  117. CurrentUser: userInfos[p.CurrentUid].Name,
  118. // 报修内容
  119. ApplyContent: p.ApplyContent,
  120. // 报修图片
  121. ApplyPic: strings.Split(p.ApplyPic, ";"),
  122. // 回访内容
  123. ReturnVisitContent: p.ReturnVisitContent,
  124. // 回访满意度
  125. ReturnVisitLevel: p.ReturnVisitLevel,
  126. // 投诉时间
  127. CreatedAt: p.CreatedAt.Format("2006-01-02 15:04:05"),
  128. Id: p.ID,
  129. Status:p.Status,
  130. }
  131. if !p.LastUidIsCompany {
  132. item.LastUser = userInfos[p.LastUid].Name
  133. }
  134. reply.List = rspPipeline
  135. reply.BaseInfo = item
  136. return reply, nil
  137. }