From 6091b30432804d212f6ed81900c7d9dfb5ecd5ca Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Mon, 25 Nov 2024 09:33:13 +0800 Subject: [PATCH] update --- app/hdl/comm/hdl_comm.go | 63 ++++++++++++++++++++++++++++++++++++++++ app/md/comm/hdl_comm.go | 5 ++++ app/router/router.go | 3 +- docs/docs.go | 56 +++++++++++++++++++++++++++++++++++ docs/swagger.json | 56 +++++++++++++++++++++++++++++++++++ docs/swagger.yaml | 37 +++++++++++++++++++++++ go.mod | 2 +- 7 files changed, 220 insertions(+), 2 deletions(-) create mode 100644 app/md/comm/hdl_comm.go diff --git a/app/hdl/comm/hdl_comm.go b/app/hdl/comm/hdl_comm.go index 9823915..8e1a1b8 100644 --- a/app/hdl/comm/hdl_comm.go +++ b/app/hdl/comm/hdl_comm.go @@ -3,11 +3,14 @@ package comm import ( "applet/app/db" "applet/app/e" + "applet/app/md/comm" "applet/app/utils/cache" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" + "code.fnuoos.com/EggPlanet/egg_models.git/src/model" enum2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" "github.com/aliyun/aliyun-oss-go-sdk/oss" "github.com/gin-gonic/gin" + "time" ) // GetOssUrl @@ -61,3 +64,63 @@ func GetOssUrl(c *gin.Context) { e.OutSuc(c, signedURL, nil) } + +// AccessRecords +// @Summary 通用请求-访问记录-页面记录 +// @Tags 访问记录 +// @Description 页面记录 +// @Accept json +// @Produce json +// @param Authorization header string true "验证参数Bearer和token空格拼接" +// @Param req body comm.AccessRecordsReq true "页面标识" +// @Success 200 {string} "success" +// @Success 200 {string} "data exist" +// @Failure 400 {object} md.Response "具体错误" +// @Router /api/v1/comm/accessRecords [POST] +func AccessRecords(c *gin.Context) { + var req *comm.AccessRecordsReq + if err1 := c.ShouldBindJSON(&req); err1 != nil { + e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error()) + return + } + + if req.Index == "" { + e.OutErr(c, e.ERR_INVALID_ARGS, nil) + return + } + + val, exists := c.Get("user") + if !exists { + e.OutErr(c, e.ERR_USER_CHECK_ERR, nil) + return + } + user, ok := val.(*model.User) + if !ok { + e.OutErr(c, e.ERR_USER_CHECK_ERR, nil) + return + } + + date := time.Now().Format("2006-01-02") + recordsDb := implement.NewEggAccessRecordsDb(db.Db) + exist, err := recordsDb.EggAccessRecordsExist(user.Id, date, req.Index) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, nil) + } + if exist { + e.OutSuc(c, "data exist", nil) + return + } + + m := model.EggAccessRecords{ + Uid: user.Id, + PageIndex: req.Index, + Date: date, + } + _, err = recordsDb.EggAccessRecordsInsert(&m) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, nil) + return + } + + e.OutSuc(c, "success", nil) +} diff --git a/app/md/comm/hdl_comm.go b/app/md/comm/hdl_comm.go new file mode 100644 index 0000000..291ea6f --- /dev/null +++ b/app/md/comm/hdl_comm.go @@ -0,0 +1,5 @@ +package comm + +type AccessRecordsReq struct { + Index string `json:"index,required"` // 页面标签 +} diff --git a/app/router/router.go b/app/router/router.go index 859ba28..7b4b61c 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -111,5 +111,6 @@ func route(r *gin.RouterGroup) { } func rComm(r *gin.RouterGroup) { - r.GET("/getOssUrl", comm.GetOssUrl) // 获取阿里云上传PutObject所需的签名URL + r.GET("/getOssUrl", comm.GetOssUrl) // 获取阿里云上传PutObject所需的签名URL + r.GET("/accessRecords", comm.AccessRecords) // 访问记录 } diff --git a/docs/docs.go b/docs/docs.go index 4cb1dd4..b43ce78 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -407,6 +407,53 @@ const docTemplate = `{ } } }, + "/api/v1/comm/accessRecords": { + "post": { + "description": "页面记录", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "访问记录" + ], + "summary": "通用请求-访问记录-页面记录", + "parameters": [ + { + "type": "string", + "description": "验证参数Bearer和token空格拼接", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "description": "页面标识", + "name": "req", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/comm.AccessRecordsReq" + } + } + ], + "responses": { + "200": { + "description": "data exist", + "schema": { + "type": "string" + } + }, + "400": { + "description": "具体错误", + "schema": { + "$ref": "#/definitions/md.Response" + } + } + } + } + }, "/api/v1/comm/getOssUrl": { "get": { "description": "上传许可链接(获取)", @@ -1572,6 +1619,15 @@ const docTemplate = `{ } } }, + "comm.AccessRecordsReq": { + "type": "object", + "properties": { + "index": { + "description": "页面标签", + "type": "string" + } + } + }, "md.AdvertisingBasic": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index 4231c99..41ba620 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -401,6 +401,53 @@ } } }, + "/api/v1/comm/accessRecords": { + "post": { + "description": "页面记录", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "访问记录" + ], + "summary": "通用请求-访问记录-页面记录", + "parameters": [ + { + "type": "string", + "description": "验证参数Bearer和token空格拼接", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "description": "页面标识", + "name": "req", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/comm.AccessRecordsReq" + } + } + ], + "responses": { + "200": { + "description": "data exist", + "schema": { + "type": "string" + } + }, + "400": { + "description": "具体错误", + "schema": { + "$ref": "#/definitions/md.Response" + } + } + } + } + }, "/api/v1/comm/getOssUrl": { "get": { "description": "上传许可链接(获取)", @@ -1566,6 +1613,15 @@ } } }, + "comm.AccessRecordsReq": { + "type": "object", + "properties": { + "index": { + "description": "页面标签", + "type": "string" + } + } + }, "md.AdvertisingBasic": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index bdaf652..a844b67 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -12,6 +12,12 @@ definitions: description: 总数据量 type: integer type: object + comm.AccessRecordsReq: + properties: + index: + description: 页面标签 + type: string + type: object md.AdvertisingBasic: properties: android_ad_is_open: @@ -1116,6 +1122,37 @@ paths: summary: 广告位详情 tags: - 广告位详情 + /api/v1/comm/accessRecords: + post: + consumes: + - application/json + description: 页面记录 + parameters: + - description: 验证参数Bearer和token空格拼接 + in: header + name: Authorization + required: true + type: string + - description: 页面标识 + in: body + name: req + required: true + schema: + $ref: '#/definitions/comm.AccessRecordsReq' + produces: + - application/json + responses: + "200": + description: data exist + schema: + type: string + "400": + description: 具体错误 + schema: + $ref: '#/definitions/md.Response' + summary: 通用请求-访问记录-页面记录 + tags: + - 访问记录 /api/v1/comm/getOssUrl: get: consumes: diff --git a/go.mod b/go.mod index 62e45ca..6cdc52f 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( ) require ( - code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241123093254-20bf9e0d7fc0 + code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241125012958-44d150a46684 code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241123093218-87b65e51eea3 code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5