log.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. package http
  2. import (
  3. "context"
  4. "go-common/app/admin/main/search/model"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. func logSearch(c *bm.Context) {
  10. form := c.Request.Form
  11. appidStr := form.Get("appid")
  12. switch appidStr {
  13. case "log_audit":
  14. logAudit(c)
  15. case "log_audit_group":
  16. logAuditGroupBy(c)
  17. case "log_user_action":
  18. logUserAction(c)
  19. default:
  20. c.JSON(nil, ecode.RequestErr)
  21. }
  22. }
  23. func bAuth(c *bm.Context, appID string, businessID int) bool {
  24. if business, ok := svr.Check(appID, businessID); ok && business.PermissionPoint != "" {
  25. authSrv.Permit(business.PermissionPoint)(c)
  26. return !c.IsAborted()
  27. }
  28. c.JSON(nil, ecode.AccessDenied)
  29. c.Abort()
  30. return false
  31. }
  32. func logAudit(c *bm.Context) {
  33. var (
  34. err error
  35. sp = &model.LogParams{
  36. Bsp: &model.BasicSearchParams{},
  37. }
  38. )
  39. if err = c.Bind(sp); err != nil {
  40. c.JSON(nil, ecode.RequestErr)
  41. return
  42. }
  43. if err = c.Bind(sp.Bsp); err != nil {
  44. c.JSON(nil, ecode.RequestErr)
  45. return
  46. }
  47. business, ok := svr.Check("log_audit", sp.Business)
  48. if !ok {
  49. c.JSON(nil, ecode.RequestErr)
  50. return
  51. }
  52. res, err := svr.LogAudit(c, c.Request.Form, sp, business)
  53. if err != nil {
  54. log.Error("srv.LogAudit(%v) error(%v)", sp, err)
  55. c.JSON(nil, err)
  56. return
  57. }
  58. c.JSON(res, err)
  59. }
  60. func logAuditGroupBy(c *bm.Context) {
  61. var (
  62. err error
  63. sp = &model.LogParams{
  64. Bsp: &model.BasicSearchParams{},
  65. }
  66. )
  67. if err = c.Bind(sp); err != nil {
  68. c.JSON(nil, ecode.RequestErr)
  69. return
  70. }
  71. if err = c.Bind(sp.Bsp); err != nil {
  72. c.JSON(nil, ecode.RequestErr)
  73. return
  74. }
  75. business, ok := svr.Check("log_audit", sp.Business)
  76. if !ok {
  77. c.JSON(nil, ecode.RequestErr)
  78. return
  79. }
  80. res, err := svr.LogAuditGroupBy(c, c.Request.Form, sp, business)
  81. if err != nil {
  82. log.Error("srv.LogAuditGroupBy(%v) error(%v)", sp, err)
  83. c.JSON(nil, err)
  84. return
  85. }
  86. c.JSON(res, err)
  87. }
  88. func logUserAction(c *bm.Context) {
  89. var (
  90. err error
  91. sp = &model.LogParams{
  92. Bsp: &model.BasicSearchParams{},
  93. }
  94. )
  95. if err = c.Bind(sp); err != nil {
  96. c.JSON(nil, ecode.RequestErr)
  97. return
  98. }
  99. if err = c.Bind(sp.Bsp); err != nil {
  100. c.JSON(nil, ecode.RequestErr)
  101. return
  102. }
  103. business, ok := svr.Check("log_user_action", sp.Business)
  104. if !ok {
  105. c.JSON(nil, ecode.RequestErr)
  106. return
  107. }
  108. res, err := svr.LogUserAction(c, c.Request.Form, sp, business)
  109. if err != nil {
  110. log.Error("srv.LogUserAction(%v) error(%v)", sp, err)
  111. c.JSON(nil, err)
  112. return
  113. }
  114. c.JSON(res, err)
  115. }
  116. func bMlogAudit(c *bm.Context) {
  117. var (
  118. err error
  119. sp = &model.LogParams{
  120. Bsp: &model.BasicSearchParams{},
  121. }
  122. )
  123. if err = c.Bind(sp); err != nil {
  124. return
  125. }
  126. if err = c.Bind(sp.Bsp); err != nil {
  127. return
  128. }
  129. if !bAuth(c, "log_audit", sp.Business) {
  130. return
  131. }
  132. business, ok := svr.Check("log_audit", sp.Business)
  133. if !ok {
  134. c.JSON(nil, ecode.RequestErr)
  135. return
  136. }
  137. if uid, ok := c.Get("uid"); ok {
  138. go svr.LogCount(context.Background(), "log_audit", sp.Business, uid)
  139. }
  140. res, err := svr.LogAudit(c, c.Request.Form, sp, business)
  141. if err != nil {
  142. log.Error("srv.bMlogAudit(%v) error(%v)", sp, err)
  143. return
  144. }
  145. c.JSON(res, err)
  146. }
  147. func bMlogAuditGroupBy(c *bm.Context) {
  148. var (
  149. err error
  150. sp = &model.LogParams{
  151. Bsp: &model.BasicSearchParams{},
  152. }
  153. )
  154. if err = c.Bind(sp); err != nil {
  155. return
  156. }
  157. if err = c.Bind(sp.Bsp); err != nil {
  158. return
  159. }
  160. if !bAuth(c, "log_audit", sp.Business) {
  161. return
  162. }
  163. business, ok := svr.Check("log_audit", sp.Business)
  164. if !ok {
  165. c.JSON(nil, ecode.RequestErr)
  166. return
  167. }
  168. res, err := svr.LogAuditGroupBy(c, c.Request.Form, sp, business)
  169. if err != nil {
  170. log.Error("srv.bMlogAuditGroupBy(%v) error(%v)", sp, err)
  171. return
  172. }
  173. c.JSON(res, err)
  174. }
  175. func bMlogUserAction(c *bm.Context) {
  176. var (
  177. err error
  178. sp = &model.LogParams{
  179. Bsp: &model.BasicSearchParams{},
  180. }
  181. )
  182. if err = c.Bind(sp); err != nil {
  183. return
  184. }
  185. if err = c.Bind(sp.Bsp); err != nil {
  186. return
  187. }
  188. if !bAuth(c, "log_user_action", sp.Business) {
  189. return
  190. }
  191. business, ok := svr.Check("log_user_action", sp.Business)
  192. if !ok {
  193. c.JSON(nil, ecode.RequestErr)
  194. return
  195. }
  196. if uid, ok := c.Get("uid"); ok {
  197. go svr.LogCount(context.Background(), "log_user_action", sp.Business, uid)
  198. }
  199. res, err := svr.LogUserAction(c, c.Request.Form, sp, business)
  200. if err != nil {
  201. log.Error("srv.bMlogUserAction(%v) error(%v)", sp, err)
  202. return
  203. }
  204. c.JSON(res, err)
  205. }