get_sop_node_by_id_logic.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. return &types.SopNodeInfoResp{
  39. BaseDataInfo: types.BaseDataInfo{
  40. Code: 0,
  41. Msg: errormsg.Success,
  42. },
  43. Data: types.SopNodeInfo{
  44. BaseIDInfo: types.BaseIDInfo{
  45. Id: &data.ID,
  46. CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
  47. UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
  48. },
  49. Status: &data.Status,
  50. StageId: &data.StageID,
  51. ParentId: &data.ParentID,
  52. Name: &data.Name,
  53. ConditionType: &data.ConditionType,
  54. ConditionList: data.ConditionList,
  55. NoReplyCondition: &data.NoReplyCondition,
  56. ActionMessage: actionMessage,
  57. ActionLabel: data.ActionLabel,
  58. },
  59. }, nil
  60. }