123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package admin
- import (
- "context"
- "gd_admin/apis"
- "gd_admin/common.in/storage"
- "gd_admin/common.in/utils"
- "gd_admin/errors"
- "gd_admin/impl/dbmodel"
- "fmt"
- "github.com/astaxie/beego/orm"
- "go.uber.org/zap"
- "time"
- )
- func AdminDelete(ctx context.Context, req *apis.AdminDeleteReq, reply *apis.AdminDeleteReply) error {
- if req.AdminId == 0 {
- return errors.ArgsError
- }
- delAccessTask := func(db orm.Ormer) error {
- p := dbmodel.TGdAdminRbacAccess{}
- // where
- filter := map[string]interface{}{
- "uid": req.AdminId,
- }
- _, err := p.Del(db, filter)
- if err != nil {
- l.Error("mysql",
- zap.String("sql", fmt.Sprintf("SELECT * FROM %s", p.TableName())),
- zap.String("fields", utils.MarshalJsonString(filter)),
- zap.String("error", err.Error()))
- return errors.DataBaseError
- }
- return nil
- }
- delUserTask := func(db orm.Ormer) error {
- _, err := orm.NewOrm().Raw("update t_gd_admin set status = ?, updated_at = ? where id = ?", 1, time.Now().Format("2006-01-02 15:04:05"), req.AdminId).Exec()
- if err != nil {
- return errors.DataBaseError
- }
- return nil
- }
- //处理事务
- tasks := []storage.DbaTasker{}
- tasks = append(tasks, storage.GenerateDbaTask(delAccessTask))
- tasks = append(tasks, storage.GenerateDbaTask(delUserTask))
- storage.ExecTrans(tasks...)
- return nil
- }
|