delete_template.go 947 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package data_import
  2. import (
  3. "adm-management/errors"
  4. v1 "adm-management/pb/v1"
  5. "context"
  6. "encoding/json"
  7. "fmt"
  8. "git.getensh.com/common/gopkgsv2/database"
  9. "git.getensh.com/common/gopkgsv2/logger"
  10. "go.uber.org/zap"
  11. "google.golang.org/grpc/status"
  12. "gorm.io/gorm"
  13. )
  14. func DeleteTemplate(ctx context.Context, req *v1.DeleteTemplateRequest) (reply *v1.DeleteTemplateReply, err error) {
  15. reply = &v1.DeleteTemplateReply{}
  16. defer func() {
  17. if r := recover(); r != nil {
  18. err = fmt.Errorf("%+v", r)
  19. e := &status.Status{}
  20. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  21. logger.Error("err",
  22. zap.String("system_err", err.Error()),
  23. zap.Stack("stacktrace"))
  24. }
  25. }
  26. }()
  27. db := database.DB()
  28. err = db.Exec("Delete FROM t_adm_data_template where id = ?", req.Id).Error
  29. if err != nil {
  30. if err == gorm.ErrRecordNotFound {
  31. return reply, nil
  32. }
  33. return reply, errors.SystemError
  34. }
  35. return reply, err
  36. }