operation_log.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package v1
  2. import (
  3. "context"
  4. "go.uber.org/zap"
  5. "property-company-gateway/pb"
  6. "property-company-gateway/pb/v1"
  7. "time"
  8. "git.getensh.com/common/gopkgs/logger"
  9. )
  10. const (
  11. ModuleGarden = "小区管理"
  12. ModuleSystemUser = "物业小区管理员"
  13. ModuleCompany = "公司信息"
  14. )
  15. //
  16. const (
  17. ActionGardenAdd = "新增小区"
  18. ActionGardenUpdate = "修改小区"
  19. ActionGardenDel = "删除小区"
  20. )
  21. //
  22. const (
  23. ActionSystemUserAdd = "新增小区管理员"
  24. ActionSystemUserDel = "删除小区管理员"
  25. ActionSystemUserUpdate = "修改小区管理员"
  26. )
  27. const (
  28. ActionCompanyUpdate = "修改公司信息"
  29. )
  30. type OperationLogRequest struct {
  31. Module string
  32. Action string
  33. UserName string
  34. Uid int64
  35. Origin interface{}
  36. Target interface{}
  37. Cid int64
  38. }
  39. func OperationLogAdd(req *OperationLogRequest) {
  40. mreq := v1.CompanyLogAddRequest{
  41. Module:req.Module,
  42. Action:req.Action,
  43. Username:req.UserName,
  44. Uid:req.Uid,
  45. Timestamp:time.Now().Unix(),
  46. Cid:req.Cid,
  47. }
  48. if req.Origin != nil {
  49. origin, _ := json.Marshal(req.Origin)
  50. mreq.Origin = string(origin)
  51. }
  52. if req.Target != nil {
  53. target, _ := json.Marshal(req.Target)
  54. mreq.Target = string(target)
  55. }
  56. _, err := pb.PropertyLog.CompanyLogAdd(context.Background(), &mreq)
  57. if err != nil {
  58. s, _ := json.Marshal(mreq)
  59. logger.Error("func",
  60. zap.String("call", "pb.PropertyLog.CompanyLogAdd"),
  61. zap.String("params", string(s)),
  62. zap.String("error", err.Error()))
  63. }
  64. }