Quellcode durchsuchen

增加“通知公告设置已读请求”接口

Simon Zhou vor 5 Jahren
Ursprung
Commit
0be9f195fb
8 geänderte Dateien mit 205 neuen und 3 gelöschten Zeilen
  1. 3 1
      config/cfg.j2
  2. 77 2
      controllers/common/notice.go
  3. 46 0
      docs/docs.go
  4. 46 0
      docs/swagger.json
  5. 29 0
      docs/swagger.yaml
  6. 1 0
      global/e/code.go
  7. 1 0
      global/e/msg.go
  8. 2 0
      routers/router.go

+ 3 - 1
config/cfg.j2

@@ -5,6 +5,8 @@
         "uploadUrl": "{{openonline_url}}/upload",
         "commSearchUrl": "{{search_url}}",
         "goCommonSearchUrl": "http://{{ws2tcp_internet_addr}}:{{go_queryservice_listen_port}}/api",
-        "openApiUrl":"{{openonline_url}}"
+        "openApiUrl":"{{openonline_url}}",
+        "mobileOpenUrl": "{{mobileopen_url}",
+        "mobileAuthUrl": "{{mobileauth_url}"
         }
 }

+ 77 - 2
controllers/common/notice.go

@@ -64,9 +64,9 @@ func QueryNotice(c *gin.Context) {
 		return
 	}
 
-	// 获取登录账号已读公告ID
+	// 获取登录账号已读公告ID, 这里要使用的是个人的UserID来查询
 	var msgReceivers []int
-	engine.Table("MSGRECEIVER").Select("AUTOID").Where("RECEIVERTYPE = 2 and MANAGERID = ?", userAccount.Memberuserid).Find(&msgReceivers)
+	engine.Table("MSGRECEIVER").Select("AUTOID").Where("RECEIVERTYPE = 2 and MANAGERID = ?", userAccount.Userid).Find(&msgReceivers)
 
 	// 查询SENDTYPE = 1的数据
 	datas1 := make([]QueryNoticeRsp, 0)
@@ -165,5 +165,80 @@ func QueryNotice(c *gin.Context) {
 		logger.GetLogger().Infof("QueryNotice successed: %v", rst)
 		appG.Response(http.StatusOK, e.SUCCESS, rst)
 	}
+}
+
+// NoticeReadedReq 通知公告设置已读请求参数
+type NoticeReadedReq struct {
+	LoginID  int `form:"loginID" binding:"requried"`  // 登录账号
+	NoticeID int `form:"noticeID" binding:"requried"` // 通知公告ID
+}
+
+// NoticeReaded 通知公告设置已读请求
+// @Summary 通知公告设置已读请求
+// @Produce json
+// @Security ApiKeyAuth
+// @Param loginID query int true "登录账号"
+// @Param noticeID query int true "通知公告ID"
+// @Success 200 {object} app.Response
+// @Failure 500 {object} app.Response
+// @Router /Common/NoticeReaded [post]
+// @Tags 通用服务
+func NoticeReaded(c *gin.Context) {
+	appG := app.Gin{C: c}
+
+	// 获取请求参数
+	var req NoticeReadedReq
+	if err := appG.C.ShouldBindQuery(&req); err != nil {
+		logger.GetLogger().Errorf("NoticeReaded failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	engine := db.GetEngine()
+	// 获取登录账号所属会员信息
+	var userAccount models.Useraccount
+	if has, _ := engine.Join("LEFT", "LOGINACCOUNT", "LOGINACCOUNT.USERID = USERACCOUNT.USERID").
+		Where("LOGINACCOUNT.LOGINID = ?", req.LoginID).Get(&userAccount); !has {
+		// 查询失败
+		logger.GetLogger().Errorf("NoticeReaded failed: %s", "获取登录账号所属会员ID失败")
+		appG.Response(http.StatusBadRequest, e.ERROR_OPERATION_FAILED, nil)
+		return
+	}
+
+	// 尝试获取指定已读数据
+	msgReceiver := &models.Msgreceiver{Autoid: int32(req.NoticeID), Managerid: userAccount.Userid, Receivertype: 2}
+	has, err := engine.Get(msgReceiver)
+	if err != nil {
+		// 执行失败
+		logger.GetLogger().Errorf("NoticeReaded failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.ERROR_OPERATION_FAILED, nil)
+		return
+	}
+	if has {
+		// 找到记录则更新已读状态
+		msgReceiver.Readstatus = 2
+		if _, err := engine.Update(msgReceiver); err != nil {
+			// 执行失败
+			logger.GetLogger().Errorf("NoticeReaded failed: %s", err.Error())
+			appG.Response(http.StatusBadRequest, e.ERROR_OPERATION_FAILED, nil)
+			return
+		}
+	} else {
+		// 找不到记录则新建一条
+		m := new(models.Msgreceiver)
+		m.Autoid = int32(req.NoticeID)
+		m.Managerid = userAccount.Userid
+		m.Readstatus = 2
+		m.Receivertype = 2
+		if _, err := engine.Insert(m); err != nil {
+			// 执行失败
+			logger.GetLogger().Errorf("NoticeReaded failed: %s", err.Error())
+			appG.Response(http.StatusBadRequest, e.ERROR_OPERATION_FAILED, nil)
+			return
+		}
+	}
 
+	// 执行成功
+	logger.GetLogger().Infof("NoticeReaded successed: %v", "ok")
+	appG.Response(http.StatusOK, e.SUCCESS, "")
 }

+ 46 - 0
docs/docs.go

@@ -369,6 +369,52 @@ var doc = `{
                 }
             }
         },
+        "/Common/NoticeReaded": {
+            "post": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "通用服务"
+                ],
+                "summary": "通知公告设置已读请求",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "登录账号",
+                        "name": "loginID",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "通知公告ID",
+                        "name": "noticeID",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Common/QueryNotice": {
             "get": {
                 "security": [

+ 46 - 0
docs/swagger.json

@@ -353,6 +353,52 @@
                 }
             }
         },
+        "/Common/NoticeReaded": {
+            "post": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "通用服务"
+                ],
+                "summary": "通知公告设置已读请求",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "登录账号",
+                        "name": "loginID",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "通知公告ID",
+                        "name": "noticeID",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Common/QueryNotice": {
             "get": {
                 "security": [

+ 29 - 0
docs/swagger.yaml

@@ -2881,6 +2881,35 @@ paths:
       summary: 查询远期订单信息
       tags:
       - 产能预售
+  /Common/NoticeReaded:
+    post:
+      parameters:
+      - description: 登录账号
+        in: query
+        name: loginID
+        required: true
+        type: integer
+      - description: 通知公告ID
+        in: query
+        name: noticeID
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/app.Response'
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 通知公告设置已读请求
+      tags:
+      - 通用服务
   /Common/QueryNotice:
     get:
       parameters:

+ 1 - 0
global/e/code.go

@@ -11,6 +11,7 @@ const (
 	ERROR_QUERY_FAIL               = 30001
 	ERROR_QUERY_QUOTEMENU_FAIL     = 30002
 	ERROR_QUERY_OPERATIONMENU_FAIL = 30003
+	ERROR_OPERATION_FAILED         = 30010
 
 	ERROR_UPLOAD_SAVE_IMAGE_FAIL    = 40001
 	ERROR_UPLOAD_CHECK_IMAGE_FAIL   = 40002

+ 1 - 0
global/e/msg.go

@@ -11,6 +11,7 @@ var MsgFlags = map[int]string{
 	ERROR_QUERY_FAIL:               "查询失败",
 	ERROR_QUERY_QUOTEMENU_FAIL:     "查询交易端行情报价牌分类菜单失败",
 	ERROR_QUERY_OPERATIONMENU_FAIL: "查询交易端功能菜单失败",
+	ERROR_OPERATION_FAILED:         "执行失败",
 
 	ERROR_UPLOAD_SAVE_IMAGE_FAIL:    "保存图片失败",
 	ERROR_UPLOAD_CHECK_IMAGE_FAIL:   "检查图片失败",

+ 2 - 0
routers/router.go

@@ -72,6 +72,8 @@ func InitRouter() *gin.Engine {
 		commonR.GET("/QueryTableDefine", common.QueryTableDefine)
 		// 通知公告系统消息查询
 		commonR.Use(token.Auth()).GET("/QueryNotice", common.QueryNotice)
+		// 通知公告设置已读请求
+		commonR.Use(token.Auth()).POST("/NoticeReaded", common.NoticeReaded)
 	}
 	// ************************ 通用单据 ************************
 	orderR := apiR.Group("Order")