get_sop_node_by_id_logic.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package sop_node
  2. import (
  3. "context"
  4. "wechat-api/internal/svc"
  5. "wechat-api/internal/types"
  6. "wechat-api/internal/utils/dberrorhandler"
  7. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  8. "github.com/suyuan32/simple-admin-common/utils/pointy"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type GetSopNodeByIdLogic struct {
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. logx.Logger
  15. }
  16. func NewGetSopNodeByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSopNodeByIdLogic {
  17. return &GetSopNodeByIdLogic{
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. Logger: logx.WithContext(ctx),
  21. }
  22. }
  23. func (l *GetSopNodeByIdLogic) GetSopNodeById(req *types.IDReq) (*types.SopNodeInfoResp, error) {
  24. data, err := l.svcCtx.DB.SopNode.Get(l.ctx, req.Id)
  25. if err != nil {
  26. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  27. }
  28. var actionMessage []types.Action
  29. if len(data.ActionMessage) > 0 {
  30. actionMessage = make([]types.Action, len(data.ActionMessage))
  31. for i, condition := range data.ActionMessage {
  32. actionMessage[i] = types.Action{
  33. Type: condition.Type,
  34. Content: condition.Content,
  35. }
  36. }
  37. }
  38. var actionForward *types.ActionForward
  39. if data.ActionForward != nil {
  40. actionForward = &types.ActionForward{}
  41. actionForward.Wxid = data.ActionForward.Wxid
  42. if len(data.ActionForward.Action) > 0 {
  43. forwardAction := make([]types.Action, len(data.ActionForward.Action))
  44. for i, condition := range data.ActionForward.Action {
  45. forwardAction[i] = types.Action{
  46. Type: condition.Type,
  47. Content: condition.Content,
  48. }
  49. }
  50. actionForward.Action = forwardAction
  51. }
  52. } else {
  53. actionForward = nil
  54. }
  55. return &types.SopNodeInfoResp{
  56. BaseDataInfo: types.BaseDataInfo{
  57. Code: 0,
  58. Msg: errormsg.Success,
  59. },
  60. Data: types.SopNodeInfo{
  61. BaseIDInfo: types.BaseIDInfo{
  62. Id: &data.ID,
  63. CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
  64. UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
  65. },
  66. Status: &data.Status,
  67. StageId: &data.StageID,
  68. ParentId: &data.ParentID,
  69. Name: &data.Name,
  70. ConditionType: &data.ConditionType,
  71. ConditionList: data.ConditionList,
  72. NoReplyCondition: &data.NoReplyCondition,
  73. NoReplyUnit: &data.NoReplyUnit,
  74. ActionMessage: actionMessage,
  75. ActionLabelAdd: data.ActionLabelAdd,
  76. ActionLabelDel: data.ActionLabelDel,
  77. ActionForward: actionForward,
  78. },
  79. }, nil
  80. }