1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- package data_import
- import (
- "adm-management/errors"
- v1 "adm-management/pb/v1"
- "context"
- "encoding/json"
- "fmt"
- "git.getensh.com/common/gopkgsv2/database"
- "git.getensh.com/common/gopkgsv2/logger"
- "go.uber.org/zap"
- "google.golang.org/grpc/status"
- "gorm.io/gorm"
- )
- func DeleteTemplate(ctx context.Context, req *v1.DeleteTemplateRequest) (reply *v1.DeleteTemplateReply, err error) {
- reply = &v1.DeleteTemplateReply{}
- defer func() {
- if r := recover(); r != nil {
- err = fmt.Errorf("%+v", r)
- e := &status.Status{}
- if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
- logger.Error("err",
- zap.String("system_err", err.Error()),
- zap.Stack("stacktrace"))
- }
- }
- }()
- db := database.DB()
- err = db.Exec("Delete FROM t_adm_data_template where id = ?", req.Id).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return reply, nil
- }
- return reply, errors.SystemError
- }
- return reply, err
- }
|