Browse Source

chat question & answer

zzf 1 year ago
parent
commit
7a90d7c943

+ 12 - 0
.idea/dataSources.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="DataSourceManagerImpl" format="xml" multifile-model="true">
+    <data-source source="LOCAL" name="confrontation-training.db" uuid="6a98ad0a-90e9-4a4a-b3c3-85c6f388ce1c">
+      <driver-ref>sqlite.xerial</driver-ref>
+      <synchronize>true</synchronize>
+      <jdbc-driver>org.sqlite.JDBC</jdbc-driver>
+      <jdbc-url>jdbc:sqlite:$PROJECT_DIR$/db/confrontation-training.db</jdbc-url>
+      <working-dir>$ProjectFileDir$</working-dir>
+    </data-source>
+  </component>
+</project>

+ 1 - 1
api/gateway.go → api/gateway/gateway.go

@@ -1,4 +1,4 @@
-package api
+package gateway
 
 import (
 	"confrontation-training/common"

+ 1 - 1
api/sse.go → api/gateway/sse.go

@@ -1,4 +1,4 @@
-package api
+package gateway
 
 import (
 	"confrontation-training/constant"

+ 1 - 1
api/user.go → api/gateway/user.go

@@ -1,4 +1,4 @@
-package api
+package gateway
 
 import (
 	"confrontation-training/common"

+ 64 - 0
api/question/answer.go

@@ -0,0 +1,64 @@
+package question
+
+import (
+	errmsg "confrontation-training/err"
+	"confrontation-training/models"
+	"confrontation-training/response"
+	"confrontation-training/service"
+	"github.com/gin-gonic/gin"
+)
+
+type AnswerService struct {
+	service.AnswerService
+}
+
+func GteAnswerService() *AnswerService {
+	return &AnswerService{}
+}
+
+// CreateAnswer
+// PingExample confrontation-training
+// @Summary 录入答案
+// @Schemes
+// @Description 录入答案
+// @Tags 问答管理
+// @Param q body string true "questionNo:问题编号;NextQuestionNo:下一个问题编号;answer:答案"
+// @Accept json
+// @Produce json
+// @Success 200 {string} string "ok"
+// @Router /v1/chat/create/answer [post]
+func (a *AnswerService) CreateAnswer(c *gin.Context) {
+	var param models.CreateAnswer
+	err := c.ShouldBindJSON(&param)
+	if err != nil {
+		panic(err)
+		return
+	}
+	answer, count := a.CreateNewAnswer(param)
+	if count == 0 {
+		response.Failed(errmsg.AnswerCreateFailed, c)
+	} else {
+		response.Success(errmsg.CreateSuccess, answer, c)
+	}
+	return
+}
+
+//GetAnswer
+// PingExample confrontation-training
+// @Summary 查询答案
+// @Schemes
+// @Description 查询答案
+// @Tags 问答管理
+// @Param id query uint8 false "id:问题主键"
+// @Accept json
+// @Produce json
+// @Success 200 {string} string "ok"
+// @Router /v1/chat/get/question [get]
+func (a *AnswerService) GetAnswer(c *gin.Context) {
+
+	var id uint8
+	err := c.ShouldBind(&id)
+	if err != nil {
+		return
+	}
+}

+ 76 - 0
api/question/question.go

@@ -0,0 +1,76 @@
+package question
+
+import (
+	errmsg "confrontation-training/err"
+	"confrontation-training/models"
+	"confrontation-training/response"
+	"confrontation-training/service"
+	"fmt"
+	"github.com/gin-gonic/gin"
+)
+
+type QuestionService struct {
+	service.QuestionService
+}
+
+func GetQuestionService() *QuestionService {
+	return &QuestionService{}
+}
+
+// GetQuestion
+// PingExample confrontation-training
+// @Summary 查询问题
+// @Schemes
+// @Description 查询问题
+// @Tags 问答管理
+// @Param id query uint8 false "id:问题主键"
+// @Accept json
+// @Produce json
+// @Success 200 {string} string "ok"
+// @Router /v1/chat/get/question [get]
+func (q *QuestionService) GetQuestion(c *gin.Context) {
+	var id uint8
+	if err := c.ShouldBind(&id); err != nil {
+		fmt.Printf("参数绑定异常:%s", err.Error())
+		response.Failed(errmsg.ParamInvalid, c)
+		return
+	}
+	if id == 0 {
+		id = 1
+	}
+	question, count := q.FindQuestionById(id)
+	if count == 0 {
+		response.Failed(errmsg.QuestionNotFound, c)
+	} else {
+		response.Success(errmsg.FindSuccess, question, c)
+	}
+	return
+}
+
+// CreateQuestion
+// PingExample confrontation-training
+// @Summary 录入问题
+// @Schemes
+// @Description 录入问题
+// @Tags 问答管理
+// @Param q body string true "question:问题;nextQuestionNo:下一个问题编号:如果此编号不为空,则说明此问题为陈述,没有答案信息;questionType:题目类型:0选择题;1填空题"
+// @Accept json
+// @Produce json
+// @Success 200 {string} string "ok"
+// @Router /v1/chat/create/question [post]
+func (q *QuestionService) CreateQuestion(c *gin.Context) {
+	var param models.CreateQuestion
+	if err := c.ShouldBindJSON(&param); err != nil {
+		fmt.Printf("参数绑定异常:%s", err.Error())
+		response.Failed(errmsg.ParamInvalid, c)
+		return
+	}
+
+	question, count := q.CreateNewQuestion(param)
+	if count == 0 {
+		response.Failed(errmsg.QuestionCreateFailed, c)
+	} else {
+		response.Success(errmsg.FindSuccess, question, c)
+	}
+	return
+}

+ 0 - 1
config/application.yaml

@@ -21,7 +21,6 @@ jwt:
 # 定时任务
 cron:
   enable: true
-
 #蓝牙网关地址
 gateway:
   baseUrl: http://192.168.2.254

BIN
db/confrontation-training.db


+ 412 - 0
docs/docs.go

@@ -0,0 +1,412 @@
+// Code generated by swaggo/swag. DO NOT EDIT.
+
+package docs
+
+import "github.com/swaggo/swag"
+
+const docTemplate = `{
+    "schemes": {{ marshal .Schemes }},
+    "swagger": "2.0",
+    "info": {
+        "description": "{{escape .Description}}",
+        "title": "{{.Title}}",
+        "contact": {
+            "name": "Develoven"
+        },
+        "version": "{{.Version}}"
+    },
+    "host": "{{.Host}}",
+    "basePath": "{{.BasePath}}",
+    "paths": {
+        "/v1/chat/getQuestion": {
+            "get": {
+                "description": "查询问题",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "问答管理"
+                ],
+                "summary": "查询问题",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "id:问题主键",
+                        "name": "id",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/device/:mac/stop/collect": {
+            "get": {
+                "description": "停止采集",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "设备管理"
+                ],
+                "summary": "停止采集",
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/device/:mac/stop/trans": {
+            "get": {
+                "description": "停止传输",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "设备管理"
+                ],
+                "summary": "停止传输",
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/device/connection": {
+            "get": {
+                "description": "连接设备",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "设备管理"
+                ],
+                "summary": "连接设备",
+                "parameters": [
+                    {
+                        "description": "chip:芯片编号,0或1;mac:Mac地址;addrType:地址类型 public/random ",
+                        "name": "device",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/device/open/notify/": {
+            "get": {
+                "description": "开启数据通知",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "设备管理"
+                ],
+                "summary": "开启数据通知",
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/device/scan": {
+            "get": {
+                "description": "扫描设备",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "设备管理"
+                ],
+                "summary": "扫描设备",
+                "parameters": [
+                    {
+                        "description": "chip:芯片编号,1或1;filterName:0 脑电 1 心电;filterRssi:信号强度,小于0的整数,字符串格式传输;filterMac:过滤Mac地址,以",
+                        "name": "device",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/device/write/data/": {
+            "post": {
+                "description": "写入数据——发送指令 ,ECG设备开启测试功能",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "设备管理"
+                ],
+                "summary": "写入数据——发送指令",
+                "parameters": [
+                    {
+                        "description": "mac:设备MAC地址 userName:用户姓名 gender:性别 age:年龄 height:身高 weight:体重",
+                        "name": "mac",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/user/change/password": {
+            "post": {
+                "description": "用户修改密码",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户管理"
+                ],
+                "summary": "用户修改密码",
+                "parameters": [
+                    {
+                        "description": "userName:用户名 password:密码 newPassword:新密码",
+                        "name": "user",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/user/find": {
+            "post": {
+                "description": "用户列表查询",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户管理"
+                ],
+                "summary": "用户列表查询",
+                "parameters": [
+                    {
+                        "description": "role:角色;userName:用户名;pageNum:页数;pageSize:每页记录数",
+                        "name": "user",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/user/login": {
+            "post": {
+                "description": "用户登录",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户管理"
+                ],
+                "summary": "用户登录",
+                "parameters": [
+                    {
+                        "description": "username:编号;password:密码;role:角色;",
+                        "name": "user",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/user/register": {
+            "post": {
+                "description": "用户注册",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户管理"
+                ],
+                "summary": "用户注册",
+                "parameters": [
+                    {
+                        "description": "userName:用户名;password:密码;role:角色",
+                        "name": "user",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/user/reset": {
+            "post": {
+                "description": "管理员重置普通用户密码",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户管理"
+                ],
+                "summary": "管理员重置普通用户密码",
+                "parameters": [
+                    {
+                        "description": "username:管理员编号;usernameInit:被重置用户编号",
+                        "name": "user",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        }
+    }
+}`
+
+// SwaggerInfo holds exported Swagger Info so clients can modify it
+var SwaggerInfo = &swag.Spec{
+	Version:          "1.0",
+	Host:             "",
+	BasePath:         "",
+	Schemes:          []string{},
+	Title:            "对抗训练",
+	Description:      "对抗训练",
+	InfoInstanceName: "swagger",
+	SwaggerTemplate:  docTemplate,
+	LeftDelim:        "{{",
+	RightDelim:       "}}",
+}
+
+func init() {
+	swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
+}

+ 385 - 0
docs/swagger.json

@@ -0,0 +1,385 @@
+{
+    "swagger": "2.0",
+    "info": {
+        "description": "对抗训练",
+        "title": "对抗训练",
+        "contact": {
+            "name": "Develoven"
+        },
+        "version": "1.0"
+    },
+    "paths": {
+        "/v1/chat/getQuestion": {
+            "get": {
+                "description": "查询问题",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "问答管理"
+                ],
+                "summary": "查询问题",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "id:问题主键",
+                        "name": "id",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/device/:mac/stop/collect": {
+            "get": {
+                "description": "停止采集",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "设备管理"
+                ],
+                "summary": "停止采集",
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/device/:mac/stop/trans": {
+            "get": {
+                "description": "停止传输",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "设备管理"
+                ],
+                "summary": "停止传输",
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/device/connection": {
+            "get": {
+                "description": "连接设备",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "设备管理"
+                ],
+                "summary": "连接设备",
+                "parameters": [
+                    {
+                        "description": "chip:芯片编号,0或1;mac:Mac地址;addrType:地址类型 public/random ",
+                        "name": "device",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/device/open/notify/": {
+            "get": {
+                "description": "开启数据通知",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "设备管理"
+                ],
+                "summary": "开启数据通知",
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/device/scan": {
+            "get": {
+                "description": "扫描设备",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "设备管理"
+                ],
+                "summary": "扫描设备",
+                "parameters": [
+                    {
+                        "description": "chip:芯片编号,1或1;filterName:0 脑电 1 心电;filterRssi:信号强度,小于0的整数,字符串格式传输;filterMac:过滤Mac地址,以",
+                        "name": "device",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/device/write/data/": {
+            "post": {
+                "description": "写入数据——发送指令 ,ECG设备开启测试功能",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "设备管理"
+                ],
+                "summary": "写入数据——发送指令",
+                "parameters": [
+                    {
+                        "description": "mac:设备MAC地址 userName:用户姓名 gender:性别 age:年龄 height:身高 weight:体重",
+                        "name": "mac",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/user/change/password": {
+            "post": {
+                "description": "用户修改密码",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户管理"
+                ],
+                "summary": "用户修改密码",
+                "parameters": [
+                    {
+                        "description": "userName:用户名 password:密码 newPassword:新密码",
+                        "name": "user",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/user/find": {
+            "post": {
+                "description": "用户列表查询",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户管理"
+                ],
+                "summary": "用户列表查询",
+                "parameters": [
+                    {
+                        "description": "role:角色;userName:用户名;pageNum:页数;pageSize:每页记录数",
+                        "name": "user",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/user/login": {
+            "post": {
+                "description": "用户登录",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户管理"
+                ],
+                "summary": "用户登录",
+                "parameters": [
+                    {
+                        "description": "username:编号;password:密码;role:角色;",
+                        "name": "user",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/user/register": {
+            "post": {
+                "description": "用户注册",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户管理"
+                ],
+                "summary": "用户注册",
+                "parameters": [
+                    {
+                        "description": "userName:用户名;password:密码;role:角色",
+                        "name": "user",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/user/reset": {
+            "post": {
+                "description": "管理员重置普通用户密码",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户管理"
+                ],
+                "summary": "管理员重置普通用户密码",
+                "parameters": [
+                    {
+                        "description": "username:管理员编号;usernameInit:被重置用户编号",
+                        "name": "user",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        }
+    }
+}

+ 249 - 0
docs/swagger.yaml

@@ -0,0 +1,249 @@
+info:
+  contact:
+    name: Develoven
+  description: 对抗训练
+  title: 对抗训练
+  version: "1.0"
+paths:
+  /v1/chat/getQuestion:
+    get:
+      consumes:
+      - application/json
+      description: 查询问题
+      parameters:
+      - description: id:问题主键
+        in: query
+        name: id
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: ok
+          schema:
+            type: string
+      summary: 查询问题
+      tags:
+      - 问答管理
+  /v1/device/:mac/stop/collect:
+    get:
+      consumes:
+      - application/json
+      description: 停止采集
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: ok
+          schema:
+            type: string
+      summary: 停止采集
+      tags:
+      - 设备管理
+  /v1/device/:mac/stop/trans:
+    get:
+      consumes:
+      - application/json
+      description: 停止传输
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: ok
+          schema:
+            type: string
+      summary: 停止传输
+      tags:
+      - 设备管理
+  /v1/device/connection:
+    get:
+      consumes:
+      - application/json
+      description: 连接设备
+      parameters:
+      - description: 'chip:芯片编号,0或1;mac:Mac地址;addrType:地址类型 public/random '
+        in: body
+        name: device
+        required: true
+        schema:
+          type: string
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: ok
+          schema:
+            type: string
+      summary: 连接设备
+      tags:
+      - 设备管理
+  /v1/device/open/notify/:
+    get:
+      consumes:
+      - application/json
+      description: 开启数据通知
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: ok
+          schema:
+            type: string
+      summary: 开启数据通知
+      tags:
+      - 设备管理
+  /v1/device/scan:
+    get:
+      consumes:
+      - application/json
+      description: 扫描设备
+      parameters:
+      - description: chip:芯片编号,1或1;filterName:0 脑电 1 心电;filterRssi:信号强度,小于0的整数,字符串格式传输;filterMac:过滤Mac地址,以
+        in: body
+        name: device
+        required: true
+        schema:
+          type: string
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: ok
+          schema:
+            type: string
+      summary: 扫描设备
+      tags:
+      - 设备管理
+  /v1/device/write/data/:
+    post:
+      consumes:
+      - application/json
+      description: 写入数据——发送指令 ,ECG设备开启测试功能
+      parameters:
+      - description: mac:设备MAC地址 userName:用户姓名 gender:性别 age:年龄 height:身高 weight:体重
+        in: body
+        name: mac
+        required: true
+        schema:
+          type: string
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: ok
+          schema:
+            type: string
+      summary: 写入数据——发送指令
+      tags:
+      - 设备管理
+  /v1/user/change/password:
+    post:
+      consumes:
+      - application/json
+      description: 用户修改密码
+      parameters:
+      - description: userName:用户名 password:密码 newPassword:新密码
+        in: body
+        name: user
+        required: true
+        schema:
+          type: string
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: ok
+          schema:
+            type: string
+      summary: 用户修改密码
+      tags:
+      - 用户管理
+  /v1/user/find:
+    post:
+      consumes:
+      - application/json
+      description: 用户列表查询
+      parameters:
+      - description: role:角色;userName:用户名;pageNum:页数;pageSize:每页记录数
+        in: body
+        name: user
+        required: true
+        schema:
+          type: string
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: ok
+          schema:
+            type: string
+      summary: 用户列表查询
+      tags:
+      - 用户管理
+  /v1/user/login:
+    post:
+      consumes:
+      - application/json
+      description: 用户登录
+      parameters:
+      - description: username:编号;password:密码;role:角色;
+        in: body
+        name: user
+        required: true
+        schema:
+          type: string
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: ok
+          schema:
+            type: string
+      summary: 用户登录
+      tags:
+      - 用户管理
+  /v1/user/register:
+    post:
+      consumes:
+      - application/json
+      description: 用户注册
+      parameters:
+      - description: userName:用户名;password:密码;role:角色
+        in: body
+        name: user
+        required: true
+        schema:
+          type: string
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: ok
+          schema:
+            type: string
+      summary: 用户注册
+      tags:
+      - 用户管理
+  /v1/user/reset:
+    post:
+      consumes:
+      - application/json
+      description: 管理员重置普通用户密码
+      parameters:
+      - description: username:管理员编号;usernameInit:被重置用户编号
+        in: body
+        name: user
+        required: true
+        schema:
+          type: string
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: ok
+          schema:
+            type: string
+      summary: 管理员重置普通用户密码
+      tags:
+      - 用户管理
+swagger: "2.0"

+ 4 - 0
err/errMsg.go

@@ -3,6 +3,7 @@ package err
 const (
 	ParamInvalid              = "请求参数无效"
 	FindSuccess               = "查询成功"
+	CreateSuccess             = "创建成功"
 	UserAlreadyExists         = "用户已存在"
 	UserRegisterSuccess       = "用户注册成功"
 	UserRegisterFailed        = "用户注册失败"
@@ -24,4 +25,7 @@ const (
 	BindUserFailed            = "绑定用户指令发送失败"
 	StartCollocateFailed      = "开始收集指令发送失败"
 	StartTransFailed          = "开始传送指令发送失败"
+	QuestionNotFound          = "问答问题不存在"
+	QuestionCreateFailed      = "创建问题失败"
+	AnswerCreateFailed        = "创建答案失败"
 )

+ 4 - 1
initialize/gorm.go

@@ -13,7 +13,10 @@ func SQLite() {
 	sqliteConfig := global.Config.SQLite
 
 	db, err := gorm.Open(sqlite.Open(sqliteConfig.Url), &gorm.Config{
-		NamingStrategy: schema.NamingStrategy{SingularTable: false},
+		NamingStrategy: schema.NamingStrategy{
+			TablePrefix:   "ct_",
+			SingularTable: false,
+		},
 	})
 	if err != nil {
 		fmt.Printf("mysql error :%s", err.Error())

+ 27 - 13
initialize/router.go

@@ -1,10 +1,12 @@
 package initialize
 
 import (
-	"confrontation-training/api"
+	"confrontation-training/api/gateway"
+	"confrontation-training/api/question"
 	"confrontation-training/global"
 	_ "confrontation-training/global"
 	"confrontation-training/middleware"
+	"confrontation-training/models"
 	"fmt"
 	"github.com/gin-gonic/gin"
 	swaggerFiles "github.com/swaggo/files"
@@ -13,6 +15,13 @@ import (
 )
 
 func Router() {
+
+	//初始化表格
+	initTableErr := global.Db.AutoMigrate(&models.User{}, &models.Question{})
+	if initTableErr != nil {
+		fmt.Printf("初始化表格异常:%s", initTableErr.Error())
+		return
+	}
 	gin.SetMode(gin.ReleaseMode)
 	engine := gin.Default()
 	//解决跨域
@@ -31,21 +40,26 @@ func Router() {
 	//group
 	v1 := engine.Group("/v1")
 	user := v1.Group("/user")
-	user.POST("/login", api.GetUser().UserLogin)
+	user.POST("/login", gateway.GetUser().UserLogin)
 
 	//user.Use(middleware.JwtAuth())
-	user.POST("/register", api.GetUser().UseRegister)
-	user.POST("/reset", api.GetUser().ResetPassword)
-	user.POST("/find", api.GetUser().UserList)
-	user.POST("/change/password", api.GetUser().ModePass)
+	user.POST("/register", gateway.GetUser().UseRegister)
+	user.POST("/reset", gateway.GetUser().ResetPassword)
+	user.POST("/find", gateway.GetUser().UserList)
+	user.POST("/change/password", gateway.GetUser().ModePass)
 	device := v1.Group("/device")
-	device.GET("/scan", api.ScanDevice)
-	device.GET("/connection", api.ConnectDevice)
-	device.POST("/write/data/", api.WriteData)
-	device.GET("/open/notify/", api.OpenNotify)
-	device.GET("/:mac/stop/trans/", api.StopTrans)
-	device.GET("/:mac/stop/collect/", api.StopCollect)
-	device.GET("/:mac/disconnect/", api.Disconnect)
+	device.GET("/scan", gateway.ScanDevice)
+	device.GET("/connection", gateway.ConnectDevice)
+	device.POST("/write/data/", gateway.WriteData)
+	device.GET("/open/notify/", gateway.OpenNotify)
+	device.GET("/:mac/stop/trans/", gateway.StopTrans)
+	device.GET("/:mac/stop/collect/", gateway.StopCollect)
+	device.GET("/:mac/disconnect/", gateway.Disconnect)
+	chat := v1.Group("/chat")
+	chat.GET("/get/question/", question.GetQuestionService().GetQuestion)
+	chat.POST("/create/question/", question.GetQuestionService().CreateQuestion)
+	chat.GET("/get/answer/", question.GteAnswerService().CreateAnswer)
+
 	//
 	//record := v1.Group("/record")
 	//record.POST("/create", api.GetRecord().SaveRecord)

+ 16 - 0
models/answer.go

@@ -0,0 +1,16 @@
+package models
+
+import "gorm.io/gorm"
+
+type Answer struct {
+	gorm.Model
+	QuestionId     *uint8 `gorm:"question_id type:integer not null comment '问题编号'"`
+	NextQuestionId *uint8 `gorm:"next_question_id type:integer comment '下一个问题编号'"`
+	Answer         string `gorm:"answer type:varchar(200) not null comment '答案信息'"`
+}
+
+type CreateAnswer struct {
+	QuestionId     *uint8 `json:"questionId" binding:"required,gt=0" `
+	NextQuestionId *uint8 `json:"nextQuestionId" binding:"gt=0"`
+	Answer         string `json:"answer" binding:"required"`
+}

+ 16 - 0
models/question.go

@@ -0,0 +1,16 @@
+package models
+
+import "gorm.io/gorm"
+
+type Question struct {
+	gorm.Model
+	Question       string `gorm:"question type:varchar(100) not null comment '问题'"`
+	NextQuestionId *uint8 `gorm:"next_question_id comment '下一个问题编号:如果此编号不为空,则说明此问题为陈述,没有答案信息'"`
+	QuestionType   *uint8 `gorm:"question_type not null default '0' comment '题目类型:0选择题;1填空题'"`
+}
+
+type CreateQuestion struct {
+	Question       string `json:"question" binding:"required"`
+	NextQuestionId *uint8 `json:"nextQuestionId"`
+	QuestionType   *uint8 `json:"questionType" binding:"required,gte=0" `
+}

+ 19 - 0
service/answerService.go

@@ -0,0 +1,19 @@
+package service
+
+import (
+	"confrontation-training/global"
+	"confrontation-training/models"
+)
+
+type AnswerService struct {
+}
+
+func (a *AnswerService) CreateNewAnswer(param models.CreateAnswer) (models.Answer, int64) {
+	answer := models.Answer{
+		Answer:         param.Answer,
+		QuestionId:     param.QuestionId,
+		NextQuestionId: param.NextQuestionId,
+	}
+	count := global.Db.Create(&answer).RowsAffected
+	return answer, count
+}

+ 26 - 0
service/questionService.go

@@ -0,0 +1,26 @@
+package service
+
+import (
+	"confrontation-training/global"
+	"confrontation-training/models"
+)
+
+type QuestionService struct {
+}
+
+// FindQuestionById  查询问题
+func (q *QuestionService) FindQuestionById(id uint8) (models.Question, int64) {
+	var question models.Question
+	count := global.Db.Where(" id = ?", id).First(&question).RowsAffected
+	return question, count
+}
+
+func (q *QuestionService) CreateNewQuestion(param models.CreateQuestion) (models.Question, int64) {
+	question := models.Question{
+		NextQuestionId: param.NextQuestionId,
+		QuestionType:   param.QuestionType,
+		Question:       param.Question,
+	}
+	affected := global.Db.Create(&question).RowsAffected
+	return question, affected
+}