get_sop_node_by_id_logic.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. actionMessage := make([]types.Action, len(data.ActionMessage))
  29. for i, condition := range data.ActionMessage {
  30. actionMessage[i] = types.Action{
  31. Type: condition.Type,
  32. Content: condition.Content,
  33. }
  34. }
  35. return &types.SopNodeInfoResp{
  36. BaseDataInfo: types.BaseDataInfo{
  37. Code: 0,
  38. Msg: errormsg.Success,
  39. },
  40. Data: types.SopNodeInfo{
  41. BaseIDInfo: types.BaseIDInfo{
  42. Id: &data.ID,
  43. CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
  44. UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
  45. },
  46. Status: &data.Status,
  47. StageId: &data.StageID,
  48. ParentId: &data.ParentID,
  49. Name: &data.Name,
  50. ConditionType: &data.ConditionType,
  51. ConditionList: data.ConditionList,
  52. ActionMessage: actionMessage,
  53. ActionLabel: data.ActionLabel,
  54. },
  55. }, nil
  56. }