get_sop_node_detail_logic.go 2.4 KB

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