update_contact_field_template_logic.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package contact_field_template
  2. import (
  3. "context"
  4. "errors"
  5. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  6. "wechat-api/ent/contactfieldtemplate"
  7. "wechat-api/internal/utils/dberrorhandler"
  8. "wechat-api/internal/svc"
  9. "wechat-api/internal/types"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type UpdateContactFieldTemplateLogic struct {
  13. logx.Logger
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. }
  17. func NewUpdateContactFieldTemplateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateContactFieldTemplateLogic {
  18. return &UpdateContactFieldTemplateLogic{
  19. Logger: logx.WithContext(ctx),
  20. ctx: ctx,
  21. svcCtx: svcCtx}
  22. }
  23. func (l *UpdateContactFieldTemplateLogic) UpdateContactFieldTemplate(req *types.ContactFieldTemplateInfo) (resp *types.BaseMsgResp, err error) {
  24. organizationId := l.ctx.Value("organizationId").(uint64)
  25. if *req.Id <= 0 {
  26. l.Error("记录ID不存在")
  27. return nil, errors.New("记录ID不存在")
  28. }
  29. template := ConvertContactFieldTemplates(req.Template)
  30. err = l.svcCtx.DB.ContactFieldTemplate.
  31. Update().
  32. Where(contactfieldtemplate.IDEQ(*req.Id), contactfieldtemplate.OrganizationID(organizationId)).
  33. SetTemplate(template).
  34. Exec(l.ctx)
  35. if err != nil {
  36. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  37. }
  38. return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
  39. }