|
|
package ControllerData
|
|
|
|
|
|
import (
|
|
|
"dsData/Model"
|
|
|
"dsData/Service"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"net/http"
|
|
|
)
|
|
|
|
|
|
//模块的路由配置
|
|
|
func Routers(r *gin.RouterGroup) {
|
|
|
rr := r.Group("")
|
|
|
//获取授权token
|
|
|
rr.POST("/token", token)
|
|
|
//数据下行,数据分发
|
|
|
rr.GET("/share", share)
|
|
|
//数据上行,数据汇集
|
|
|
r.POST("/collect", collect)
|
|
|
//数据类型获取
|
|
|
r.GET("/datatype", datatype)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// @Summary 获取授权票据
|
|
|
// @Description 获取授权票据
|
|
|
// @Tags 统一数据类
|
|
|
// @Accept application/x-www-form-urlencoded
|
|
|
// @Produce json
|
|
|
// @Param id formData string true "第三方系统的访问id"
|
|
|
// @Param secret formData string true "第三方系统的访问密码"
|
|
|
// @Success 200 {object} Model.Res
|
|
|
// @Router /data/token [post]
|
|
|
// @X-LengthLimit [{"id":"20,20"},{"secret":"26,26"}]
|
|
|
func token(c *gin.Context) {
|
|
|
id := c.PostForm("id")
|
|
|
secret := c.PostForm("secret")
|
|
|
success, token, expireTime := Service.Token(id, secret)
|
|
|
if success {
|
|
|
c.JSON(http.StatusOK, Model.Res{
|
|
|
Code: http.StatusOK,
|
|
|
Token: token,
|
|
|
ExpireTime: expireTime,
|
|
|
Msg: "获取成功",
|
|
|
})
|
|
|
return
|
|
|
} else {
|
|
|
c.JSON(http.StatusOK, Model.Res{
|
|
|
Code: http.StatusNotImplemented,
|
|
|
Msg: "用户名或密码不正确!",
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// @Summary 共享的数据类型有哪些
|
|
|
// @Description 共享的数据类型有哪些
|
|
|
// @Tags 统一数据类
|
|
|
// @Accept application/x-www-form-urlencoded
|
|
|
// @Produce json
|
|
|
// @Param token query string true "访问票据"
|
|
|
// @Success 200 {object} Model.Res
|
|
|
// @Router /data/datatype [get]
|
|
|
// @X-LengthLimit [{"token":"26,26"}]
|
|
|
func datatype(c *gin.Context) {
|
|
|
//1、token是不是正确,如果正确并且没有过期,那么这个系统是谁?
|
|
|
token := c.Query("token")
|
|
|
success, clientId := Service.CheckToken(token)
|
|
|
if !success {
|
|
|
c.JSON(http.StatusOK, Model.Res{
|
|
|
Code: http.StatusNotImplemented,
|
|
|
Msg: "票据无效!",
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
//2、获取数据列表
|
|
|
list := Service.Datatype(clientId)
|
|
|
c.JSON(http.StatusOK, Model.Res{
|
|
|
Code: http.StatusOK,
|
|
|
Data: list,
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// @Summary 数据分发
|
|
|
// @Description 数据分发
|
|
|
// @Tags 统一数据类
|
|
|
// @Accept application/x-www-form-urlencoded
|
|
|
// @Produce json
|
|
|
// @Param token query string true "访问票据"
|
|
|
// @Param data_type query string true "获取哪一类数据"
|
|
|
// @Param start_time query string true "开始时间"
|
|
|
// @Param pk query string true "主键值,如果不清楚第一次可以传0,以后按返回的数据再次传入即可"
|
|
|
// @Success 200 {object} Model.Res
|
|
|
// @Router /data/share [get]
|
|
|
// @X-LengthLimit [{"token":"26,26"},{"data_type":"2,20"},{"start_time":"19,19"},{"pk":"1,10"}]
|
|
|
// @X-DateTime ["start_time"]
|
|
|
func share(c *gin.Context) {
|
|
|
//1、token是不是正确,如果正确并且没有过期,那么这个系统是谁?
|
|
|
token := c.Query("token")
|
|
|
success, clientId := Service.CheckToken(token)
|
|
|
if !success {
|
|
|
c.JSON(http.StatusOK, Model.Res{
|
|
|
Code: http.StatusNotImplemented,
|
|
|
Msg: "票据无效!",
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
//2、判断获取的数据类型是否有效
|
|
|
dataType := c.Query("data_type")
|
|
|
exists := Service.DataTypeIsExists(dataType, clientId)
|
|
|
if !exists {
|
|
|
c.JSON(http.StatusOK, Model.Res{
|
|
|
Code: http.StatusNotImplemented,
|
|
|
Msg: "查询的数据类型无效!",
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
//3、检查当前系统,是否有此数据类型的访问权(待扩展,接入系统,有哪些数据类型+数据范围的访问权)
|
|
|
//TODO
|
|
|
|
|
|
//4、返回数据
|
|
|
startTime := c.Query("start_time")
|
|
|
pk := c.Query("pk")
|
|
|
success, msg, vStartTime, vPk, list := Service.Share(clientId, dataType, startTime, pk)
|
|
|
if success {
|
|
|
c.JSON(http.StatusOK, Model.Res{
|
|
|
Code: http.StatusOK,
|
|
|
StartTime: vStartTime,
|
|
|
Count: len(list),
|
|
|
Pk: vPk,
|
|
|
Data: list,
|
|
|
})
|
|
|
return
|
|
|
} else {
|
|
|
c.JSON(http.StatusOK, Model.Res{
|
|
|
Code: http.StatusNotImplemented,
|
|
|
Msg: "获取数据失败:" + msg,
|
|
|
Count: 0,
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// @Summary 数据上报
|
|
|
// @Description 数据上报
|
|
|
// @Tags 统一数据类
|
|
|
// @Accept application/x-www-form-urlencoded
|
|
|
// @Produce json
|
|
|
// @Param access_token formData string true "访问票据"
|
|
|
// @Success 200 {object} Model.Res
|
|
|
// @Router /oauth2/authorize [post]
|
|
|
func collect(c *gin.Context) {
|
|
|
//TODO
|
|
|
//一期暂无此内容
|
|
|
|
|
|
}
|