update_sop_node_logic.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. // 根据 id 关联查询处 task 信息,并判断 status 是否为 1
  27. data, err := l.svcCtx.DB.SopNode.Query().
  28. Where(sopnode.ID(*req.Id)).
  29. WithSopStage(func(query *ent.SopStageQuery) {
  30. query.WithSopTask()
  31. }).
  32. Only(l.ctx)
  33. if err != nil {
  34. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  35. }
  36. task := data.Edges.SopStage.Edges.SopTask
  37. if task.Status != 1 {
  38. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  39. }
  40. actionMessage := make([]custom_types.Action, len(req.ActionMessage))
  41. for i, condition := range req.ActionMessage {
  42. actionMessage[i] = custom_types.Action{
  43. Type: condition.Type,
  44. Content: condition.Content,
  45. }
  46. }
  47. err = l.svcCtx.DB.SopNode.UpdateOneID(*req.Id).
  48. SetNotNilStatus(req.Status).
  49. SetNotNilStageID(req.StageId).
  50. SetNotNilParentID(req.ParentId).
  51. SetNotNilName(req.Name).
  52. SetNotNilConditionType(req.ConditionType).
  53. SetNotNilConditionList(req.ConditionList).
  54. SetNotNilActionMessage(actionMessage).
  55. SetNotNilActionLabel(req.ActionLabel).
  56. Exec(l.ctx)
  57. if err != nil {
  58. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  59. }
  60. return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
  61. }