del.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package operation_log
  4. import (
  5. "context"
  6. "encoding/json"
  7. "fmt"
  8. "git.getensh.com/common/gopkgs/database"
  9. "git.getensh.com/common/gopkgs/logger"
  10. "go.uber.org/zap"
  11. "google.golang.org/grpc/status"
  12. "xingjia-management-gateway/apis"
  13. "xingjia-management-gateway/errors"
  14. dbmodel "xingjia-management-gateway/model"
  15. )
  16. func checkOperationLogDelParam(req *apis.OperationLogDelRequest) error {
  17. switch {
  18. case req.SelfId == 0:
  19. return status.Error(10003, "未知操作者")
  20. case len(req.Ids) == 0:
  21. return status.Error(10003, "目标不能为空")
  22. }
  23. return nil
  24. }
  25. //
  26. func OperationLogDel(ctx context.Context, req *apis.OperationLogDelRequest) (reply *apis.OperationLogDelReply, err error) {
  27. reply = &apis.OperationLogDelReply{}
  28. // 捕获各个task中的异常并返回给调用者
  29. defer func() {
  30. if r := recover(); r != nil {
  31. err = fmt.Errorf("%+v", r)
  32. e := &status.Status{}
  33. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  34. logger.Error("err",
  35. zap.String("system_err", err.Error()),
  36. zap.Stack("stacktrace"))
  37. }
  38. }
  39. }()
  40. if err = checkOperationLogDelParam(req); err != nil {
  41. return nil, err
  42. }
  43. if err = checkAdmin(req.SelfId); err != nil {
  44. return nil, err
  45. }
  46. where := map[string]interface{}{
  47. "id in": req.Ids,
  48. }
  49. p := &dbmodel.TOperationLog{}
  50. err = p.Delete(database.DB(), where)
  51. if err != nil {
  52. return nil, errors.DataBaseError
  53. }
  54. return reply, err
  55. }