123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- package http
- import (
- "context"
- "go-common/app/admin/main/search/model"
- "go-common/library/ecode"
- "go-common/library/log"
- bm "go-common/library/net/http/blademaster"
- )
- func logSearch(c *bm.Context) {
- form := c.Request.Form
- appidStr := form.Get("appid")
- switch appidStr {
- case "log_audit":
- logAudit(c)
- case "log_audit_group":
- logAuditGroupBy(c)
- case "log_user_action":
- logUserAction(c)
- default:
- c.JSON(nil, ecode.RequestErr)
- }
- }
- func bAuth(c *bm.Context, appID string, businessID int) bool {
- if business, ok := svr.Check(appID, businessID); ok && business.PermissionPoint != "" {
- authSrv.Permit(business.PermissionPoint)(c)
- return !c.IsAborted()
- }
- c.JSON(nil, ecode.AccessDenied)
- c.Abort()
- return false
- }
- func logAudit(c *bm.Context) {
- var (
- err error
- sp = &model.LogParams{
- Bsp: &model.BasicSearchParams{},
- }
- )
- if err = c.Bind(sp); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if err = c.Bind(sp.Bsp); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- business, ok := svr.Check("log_audit", sp.Business)
- if !ok {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- res, err := svr.LogAudit(c, c.Request.Form, sp, business)
- if err != nil {
- log.Error("srv.LogAudit(%v) error(%v)", sp, err)
- c.JSON(nil, err)
- return
- }
- c.JSON(res, err)
- }
- func logAuditGroupBy(c *bm.Context) {
- var (
- err error
- sp = &model.LogParams{
- Bsp: &model.BasicSearchParams{},
- }
- )
- if err = c.Bind(sp); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if err = c.Bind(sp.Bsp); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- business, ok := svr.Check("log_audit", sp.Business)
- if !ok {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- res, err := svr.LogAuditGroupBy(c, c.Request.Form, sp, business)
- if err != nil {
- log.Error("srv.LogAuditGroupBy(%v) error(%v)", sp, err)
- c.JSON(nil, err)
- return
- }
- c.JSON(res, err)
- }
- func logUserAction(c *bm.Context) {
- var (
- err error
- sp = &model.LogParams{
- Bsp: &model.BasicSearchParams{},
- }
- )
- if err = c.Bind(sp); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if err = c.Bind(sp.Bsp); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- business, ok := svr.Check("log_user_action", sp.Business)
- if !ok {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- res, err := svr.LogUserAction(c, c.Request.Form, sp, business)
- if err != nil {
- log.Error("srv.LogUserAction(%v) error(%v)", sp, err)
- c.JSON(nil, err)
- return
- }
- c.JSON(res, err)
- }
- func bMlogAudit(c *bm.Context) {
- var (
- err error
- sp = &model.LogParams{
- Bsp: &model.BasicSearchParams{},
- }
- )
- if err = c.Bind(sp); err != nil {
- return
- }
- if err = c.Bind(sp.Bsp); err != nil {
- return
- }
- if !bAuth(c, "log_audit", sp.Business) {
- return
- }
- business, ok := svr.Check("log_audit", sp.Business)
- if !ok {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if uid, ok := c.Get("uid"); ok {
- go svr.LogCount(context.Background(), "log_audit", sp.Business, uid)
- }
- res, err := svr.LogAudit(c, c.Request.Form, sp, business)
- if err != nil {
- log.Error("srv.bMlogAudit(%v) error(%v)", sp, err)
- return
- }
- c.JSON(res, err)
- }
- func bMlogAuditGroupBy(c *bm.Context) {
- var (
- err error
- sp = &model.LogParams{
- Bsp: &model.BasicSearchParams{},
- }
- )
- if err = c.Bind(sp); err != nil {
- return
- }
- if err = c.Bind(sp.Bsp); err != nil {
- return
- }
- if !bAuth(c, "log_audit", sp.Business) {
- return
- }
- business, ok := svr.Check("log_audit", sp.Business)
- if !ok {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- res, err := svr.LogAuditGroupBy(c, c.Request.Form, sp, business)
- if err != nil {
- log.Error("srv.bMlogAuditGroupBy(%v) error(%v)", sp, err)
- return
- }
- c.JSON(res, err)
- }
- func bMlogUserAction(c *bm.Context) {
- var (
- err error
- sp = &model.LogParams{
- Bsp: &model.BasicSearchParams{},
- }
- )
- if err = c.Bind(sp); err != nil {
- return
- }
- if err = c.Bind(sp.Bsp); err != nil {
- return
- }
- if !bAuth(c, "log_user_action", sp.Business) {
- return
- }
- business, ok := svr.Check("log_user_action", sp.Business)
- if !ok {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if uid, ok := c.Get("uid"); ok {
- go svr.LogCount(context.Background(), "log_user_action", sp.Business, uid)
- }
- res, err := svr.LogUserAction(c, c.Request.Form, sp, business)
- if err != nil {
- log.Error("srv.bMlogUserAction(%v) error(%v)", sp, err)
- return
- }
- c.JSON(res, err)
- }
|