123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- package app
- import (
- "github.com/gin-gonic/gin"
- "github.com/sirupsen/logrus"
- "lc-fangdaosha/model/app"
- "lc-fangdaosha/model/app/request"
- "lc-fangdaosha/model/common/response"
- "lc-fangdaosha/service"
- )
- type GatewayApi struct {
- }
- var gs = service.ServiceGroupApp.AppServiceGroup.GatewayService
- // List 获取网关列表
- func (api *GatewayApi) List(c *gin.Context) {
- var req request.GatewayRequest
- err := c.ShouldBindJSON(&req)
- if err != nil {
- logrus.Error("请求数据绑定错误", err)
- }
- list, err := gs.List(req)
- if err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- response.OkWithDetailed(response.PageResult{
- List: list,
- Total: int64(len(list)),
- Page: req.Page,
- PageSize: req.PageSize,
- }, "获取成功", c)
- }
- // AdminSet 管理员设置osn和给网关分配用户
- func (api *GatewayApi) AdminSet(c *gin.Context) {
- var data app.Gateway
- err := c.ShouldBindJSON(&data)
- if err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- err = gs.AdminSet(&data)
- if err != nil {
- response.FailWithDetailed(err.Error(), "设置失败", c)
- return
- }
- response.OkWithMessage("设置成功", c)
- }
- // UserSet 用户设置网关名和描述信息
- func (api *GatewayApi) UserSet(c *gin.Context) {
- var data app.Gateway
- err := c.ShouldBindJSON(&data)
- if err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- err = gs.Update(&data)
- if err != nil {
- response.FailWithDetailed(err.Error(), "设置失败", c)
- return
- }
- response.OkWithMessage("设置成功", c)
- }
- // DeleteGateways 删除网关及其关联设备
- func (api *GatewayApi) DeleteGateways(c *gin.Context) {
- var req app.Gateway
- err := c.ShouldBindJSON(&req)
- if err != nil {
- response.FailWithDetailed(err.Error(), "请求参数错误", c)
- return
- }
- err = gs.DeleteGateways(req)
- if err != nil {
- response.FailWithDetailed(err.Error(), "删除失败", c)
- return
- }
- response.OkWithMessage("删除成功", c)
- }
- // UnbindGateways 解绑网关下的设备
- func (api *GatewayApi) UnbindGateways(c *gin.Context) {
- var req app.Gateway
- err := c.ShouldBindJSON(&req)
- if err != nil {
- response.FailWithDetailed(err.Error(), "请求参数错误", c)
- return
- }
- err = gs.UnbindGateways(req)
- if err != nil {
- response.FailWithDetailed(err.Error(), "解绑失败", c)
- return
- }
- response.OkWithMessage("解绑成功", c)
- }
|