update_sop_node_logic.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package sop_node
  2. import (
  3. "context"
  4. "wechat-api/ent"
  5. "wechat-api/ent/custom_types"
  6. "wechat-api/ent/sopnode"
  7. "wechat-api/internal/svc"
  8. "wechat-api/internal/types"
  9. "wechat-api/internal/utils/dberrorhandler"
  10. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type UpdateSopNodeLogic struct {
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. logx.Logger
  17. }
  18. func NewUpdateSopNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateSopNodeLogic {
  19. return &UpdateSopNodeLogic{
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. Logger: logx.WithContext(ctx),
  23. }
  24. }
  25. func (l *UpdateSopNodeLogic) UpdateSopNode(req *types.SopNodeInfo) (*types.BaseMsgResp, error) {
  26. organizationId := l.ctx.Value("organizationId").(uint64)
  27. // 根据 id 关联查询处 task 信息,并判断 status 是否为 1
  28. data, err := l.svcCtx.DB.SopNode.Query().
  29. Where(sopnode.ID(*req.Id)).
  30. WithSopStage(func(query *ent.SopStageQuery) {
  31. query.WithSopTask()
  32. }).
  33. Only(l.ctx)
  34. if err != nil {
  35. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  36. }
  37. task := data.Edges.SopStage.Edges.SopTask
  38. if task.Status != 1 || task.OrganizationID != organizationId {
  39. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  40. }
  41. var actionMessage []custom_types.Action
  42. if len(req.ActionMessage) > 0 {
  43. actionMessage = make([]custom_types.Action, len(req.ActionMessage))
  44. for i, condition := range req.ActionMessage {
  45. if condition.Type == 1 {
  46. actionMessage[i] = custom_types.Action{
  47. Type: condition.Type,
  48. Content: condition.Content,
  49. }
  50. } else {
  51. actionMessage[i] = custom_types.Action{
  52. Type: condition.Type,
  53. Content: condition.Content,
  54. Meta: &custom_types.Meta{
  55. Filename: condition.Meta.Filename,
  56. },
  57. }
  58. }
  59. }
  60. }
  61. err = l.svcCtx.DB.SopNode.UpdateOneID(*req.Id).
  62. SetNotNilStatus(req.Status).
  63. SetNotNilStageID(req.StageId).
  64. SetNotNilParentID(req.ParentId).
  65. SetNotNilName(req.Name).
  66. SetNotNilConditionType(req.ConditionType).
  67. SetNotNilConditionList(req.ConditionList).
  68. SetNotNilNoReplyCondition(req.NoReplyCondition).
  69. SetNotNilActionMessage(actionMessage).
  70. SetNotNilActionLabel(req.ActionLabel).
  71. Exec(l.ctx)
  72. if err != nil {
  73. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  74. }
  75. return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
  76. }