123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- package v1
- import (
- "errors"
- "github.com/gin-gonic/gin"
- "github.com/go-playground/validator"
- "lot_interlligentControl/app/e"
- "lot_interlligentControl/app/services"
- "lot_interlligentControl/app/services/imp"
- "lot_interlligentControl/models"
- "lot_interlligentControl/unity"
- "lot_interlligentControl/utils"
- "strconv"
- )
- var serviceNode services.ServiceNodes = &imp.ServiceNodes{}
- // GetServiceNodesById
- // @Tags 节点管理
- // @Summary 查询自己的所有节点
- // @Success 200 {object} e.R
- // @Fail 400 {object} e.R
- // @Param req body unity.PageParams true "分页数据"
- // @Accept application/json
- // @Router /serviceNode [get]
- func GetServiceNodesById(c *gin.Context) {
- var pages unity.PageParams
- uId := utils.GetUId(c)
- err := c.ShouldBindJSON(&pages)
- if err != nil {
- e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
- return
- }
- result, total, err := unity.PaginateByID(uId, pages, models.ServiceNodes{})
- if err != nil {
- e.ResponseWithMsg(c, e.PaginationFailed, e.PaginationFailed.GetMsg())
- return
- }
- e.ResPonsePage(c, result, total, pages)
- }
- // DeleteServiceNodesById
- // @Tags 节点管理
- // @Summary 根据Id删除节点
- // @Success 200 {object} e.R
- // @Fail 400 {object} e.R
- // @Param id query string true "id"
- // @Accept application/json
- // @Router /serviceNode [delete]
- func DeleteServiceNodesById(c *gin.Context) {
- id := c.Query("id")
- validate := validator.New()
- err := validate.Var(id, "required,numeric")
- if err != nil {
- e.ResponseWithMsg(c, e.TheParameterCannotBeEmpty, e.TheParameterCannotBeEmpty.GetMsg())
- return
- }
- atoi, _ := strconv.Atoi(id)
- _, rescode := unity.DeleteById(atoi, models.ServiceNodes{})
- if rescode != nil {
- e.ResponseWithMsg(c, e.DeleteFail, e.DeleteFail.GetMsg())
- return
- }
- e.ResponseSuccess(c, "删除成功")
- }
- // AddServiceNode
- // @Tags 节点管理
- // @Summary 添加节点
- // @Success 200 {object} e.R
- // @Fail 400 {object} e.R
- // @Param req body models.ServiceNodesDto true "节点数据"
- // @Accept application/json
- // @Router /serviceNode [post]
- func AddServiceNode(c *gin.Context) {
- var nodes models.ServiceNodesDto
- err := c.ShouldBindJSON(&nodes)
- if err != nil {
- e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
- return
- }
- uid := utils.GetUId(c)
- rescode := serviceNode.AddServiceNodes(uid, nodes)
- if errors.Is(rescode, e.SUCCESS) {
- e.ResponseSuccess(c, "添加成功")
- return
- }
- e.ResponseError(c, rescode)
- }
- // UpdateServiceNode
- // @Tags 节点管理
- // @Summary 修改节点
- // @Success 200 {object} e.R
- // @Fail 400 {object} e.R
- // @Param id query string true "id"
- // @Param req body models.ServiceNodesDto true "节点数据"
- // @Accept application/json
- // @Router /serviceNode [put]
- func UpdateServiceNode(c *gin.Context) {
- id := c.Query("id")
- var nodes models.ServiceNodesDto
- validate := validator.New()
- atoi, _ := strconv.Atoi(id)
- err := c.ShouldBindJSON(&nodes)
- err = validate.Var(id, "required,numeric")
- if err != nil {
- e.ResponseWithMsg(c, e.TheParameterCannotBeEmpty, e.TheParameterCannotBeEmpty.GetMsg())
- return
- }
- if err != nil {
- e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
- return
- }
- uId := utils.GetUId(c)
- rescode := serviceNode.UpdateServiceNodes(uId, atoi, nodes)
- if errors.Is(rescode, e.SUCCESS) {
- e.ResponseSuccess(c, "修改成功")
- return
- }
- e.ResponseError(c, rescode)
- }
- // GetNode
- // @Tags 节点管理
- // @Summary 获取自己节点以及公开节点
- // @Success 200 {object} []models.ServiceNodes
- // @Fail 400 {object} e.R
- // @Accept application/json
- // @Router /getNode [get]
- func GetNode(c *gin.Context) {
- uid := utils.GetUId(c)
- node, rescode := serviceNode.GetNode(uid)
- if errors.Is(rescode, e.SUCCESS) {
- e.ResponseSuccess(c, node)
- return
- }
- e.ResponseError(c, rescode)
- }
|