123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package v1
- import (
- "github.com/gin-gonic/gin"
- "github.com/jaryhe/gopkgs/logger"
- "github.com/jaryhe/gopkgs/tasker/httptasker"
- "github.com/jaryhe/gopkgs/util"
- "go.uber.org/zap"
- "net/http"
- "smart-enterprise-management-gateway/consts"
- "smart-enterprise-management-gateway/errors"
- param_v1 "smart-enterprise-management-gateway/param/v1"
- "smart-enterprise-management-gateway/pb"
- "smart-enterprise-management-gateway/pb/v1"
- "smart-enterprise-management-gateway/utils"
- "strconv"
- "strings"
- )
- // 设备类型总列表
- // @Summary 设备类型总列表
- // @Description 设备类型总列表
- // @Tags device
- // @Accept json
- // @Produce json
- // @Success 200 {object} v1.DeviceAllTypeListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/device_type_all [get]
- func (c *Controller) DeviceTypeAll(ctx *gin.Context) {
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.DeviceAllTypeListResponse{}
- rpcReq := &v1.DeviceAllTypeListRequest{}
- reply, err := pb.Enterprise.DeviceAllTypeList(ctx, rpcReq)
- if err != nil {
- logger.Error("func",
- zap.String("call", "DeviceAllTypeList"),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *reply
- if resp.Data.List == nil {
- resp.Data.List= make([]*v1.DeviceAllTypeItem, 0)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, handleServiceTask)
- }
- // 已通过审核的设备类型列表
- // @Summary 已通过审核的设备类型列表
- // @Description 已通过审核的设备类型列表
- // @Tags device
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param filter query string false " "
- // @Param page query int true " "
- // @Success 200 {object} v1.DeviceTypeListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/device/type_list [get]
- func (c *Controller) DeviceTypeList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.DeviceTypeListRequest{}
- //var loginUid int64
- //var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.DeviceTypeListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- //loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.DeviceTypeListResponse{}
- rpcReq := &v1.DeviceTypeListRequest{}
- rpcReq.Page = req.Page
- if rpcReq.Page < 1 {
- rpcReq.Page = 1
- }
- rpcReq.Filter = req.Filter
- req.StatusFilters = "3"
- if req.StatusFilters != "" {
- array := strings.Split(req.StatusFilters, ",")
- for _, v := range array {
- value, _ := strconv.Atoi(v)
- rpcReq.FilterStatus = append(rpcReq.FilterStatus, int32(value))
- }
- }
- reply, err := pb.Enterprise.DeviceTypeList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "DeviceTypeList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *reply
- if resp.Data.List == nil {
- resp.Data.List = make([]*v1.DeviceTypeItem, 0)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // 扬尘设备列表
- // @Summary 扬尘设备列表
- // @Description 扬尘设备列表
- // @Tags device
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param page query int false " "
- // @Param filter query string false " "
- // @Param project_id query int64 false " "
- // @Param state query int32 false " -1 0 1"
- // @Success 200 {object} v1.DeviceListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/device/dust_list [get]
- func (c *Controller) DeviceDustList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.DeviceListRequest{}
- var loginUid int64
- //var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.DeviceListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- loginUid, _, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.DeviceListResponse{}
- rpcReq := &v1.DeviceListRequest{}
- rpcReq.Page = req.Page
- if rpcReq.Page < 1 {
- rpcReq.Page = 1
- }
- rpcReq.Cid = loginUid
- rpcReq.Filter = req.Filter
- rpcReq.TypeCode = consts.DeviceTypeDust
- req.FilterStatus = "1"
- rpcReq.State = req.State
- rpcReq.ProjectId = req.ProjectId
- if req.FilterStatus != "" {
- array := strings.Split(req.FilterStatus, ",")
- for _, v := range array {
- value, _ := strconv.Atoi(v)
- rpcReq.StatusFilters = append(rpcReq.StatusFilters, int32(value))
- }
- }
- reply, err := pb.Enterprise.DeviceList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "DeviceList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *reply
- if resp.Data.List == nil {
- resp.Data.List = make([]*v1.DeviceItem, 0)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // 塔机设备列表
- // @Summary 塔机设备列表
- // @Description 塔机设备列表
- // @Tags device
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param page query int false " "
- // @Param filter query string false " "
- // @Param project_id query int64 false " "
- // @Param state query int32 false " -1 0 1"
- // @Success 200 {object} v1.DeviceListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/device/tower_list [get]
- func (c *Controller) DeviceTowerList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.DeviceListRequest{}
- var loginUid int64
- //var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.DeviceListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- loginUid, _, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.DeviceListResponse{}
- rpcReq := &v1.DeviceListRequest{}
- rpcReq.Page = req.Page
- if rpcReq.Page < 1 {
- rpcReq.Page = 1
- }
- rpcReq.Cid = loginUid
- rpcReq.Filter = req.Filter
- rpcReq.TypeCode = consts.DeviceTypeTower
- req.FilterStatus = "1"
- rpcReq.State = req.State
- rpcReq.ProjectId = req.ProjectId
- if req.FilterStatus != "" {
- array := strings.Split(req.FilterStatus, ",")
- for _, v := range array {
- value, _ := strconv.Atoi(v)
- rpcReq.StatusFilters = append(rpcReq.StatusFilters, int32(value))
- }
- }
- reply, err := pb.Enterprise.DeviceList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "DeviceList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *reply
- if resp.Data.List == nil {
- resp.Data.List = make([]*v1.DeviceItem, 0)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // 升降机设备列表
- // @Summary 升降机设备列表
- // @Description 升降机设备列表
- // @Tags device
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param page query int false " "
- // @Param filter query string false " "
- // @Param project_id query int64 false " "
- // @Param state query int32 false " -1 0 1"
- // @Success 200 {object} v1.DeviceListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/device/lift_list [get]
- func (c *Controller) DeviceLiftList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.DeviceListRequest{}
- var loginUid int64
- //var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.DeviceListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- loginUid, _, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.DeviceListResponse{}
- rpcReq := &v1.DeviceListRequest{}
- rpcReq.Page = req.Page
- if rpcReq.Page < 1 {
- rpcReq.Page = 1
- }
- rpcReq.Cid = loginUid
- rpcReq.Filter = req.Filter
- rpcReq.TypeCode = consts.DeviceTypeLift
- req.FilterStatus = "1"
- rpcReq.State = req.State
- rpcReq.ProjectId = req.ProjectId
- if req.FilterStatus != "" {
- array := strings.Split(req.FilterStatus, ",")
- for _, v := range array {
- value, _ := strconv.Atoi(v)
- rpcReq.StatusFilters = append(rpcReq.StatusFilters, int32(value))
- }
- }
- reply, err := pb.Enterprise.DeviceList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "DeviceList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *reply
- if resp.Data.List == nil {
- resp.Data.List = make([]*v1.DeviceItem, 0)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // 实名制设备列表
- // @Summary 实名制设备列表
- // @Description 实名制设备列表
- // @Tags device
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param page query int false " "
- // @Param filter query string false " "
- // @Param project_id query int64 false " "
- // @Param state query int32 false " -1 0 1"
- // @Success 200 {object} v1.DeviceListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/device/attendance_list [get]
- func (c *Controller) DeviceAttendanceList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.DeviceListRequest{}
- var loginUid int64
- //var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.DeviceListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- loginUid, _, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.DeviceListResponse{}
- rpcReq := &v1.DeviceListRequest{}
- rpcReq.Page = req.Page
- if rpcReq.Page < 1 {
- rpcReq.Page = 1
- }
- rpcReq.Cid = loginUid
- rpcReq.Filter = req.Filter
- rpcReq.TypeCode = consts.DeviceTypeAttendance
- req.FilterStatus = "1"
- rpcReq.State = req.State
- rpcReq.ProjectId = req.ProjectId
- if req.FilterStatus != "" {
- array := strings.Split(req.FilterStatus, ",")
- for _, v := range array {
- value, _ := strconv.Atoi(v)
- rpcReq.StatusFilters = append(rpcReq.StatusFilters, int32(value))
- }
- }
- reply, err := pb.Enterprise.DeviceList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "DeviceList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *reply
- if resp.Data.List == nil {
- resp.Data.List = make([]*v1.DeviceItem, 0)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // 视频设备列表
- // @Summary 视频设备列表
- // @Description 视频设备列表
- // @Tags device
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param filter query string false "过滤字段"
- // @Param project_id query int64 false " "
- // @Param state query int32 false "-1,0,1"
- // @Param page query int false " "
- // @Success 200 {object} v1.VedioListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/device/vedio_list [get]
- func (c *Controller) DeviceVedioList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.VedioListRequest{}
- var loginUid int64
- //var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.VedioListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- loginUid, _, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.VedioListResponse{}
- rpcReq := &v1.VedioListRequest{}
- rpcReq.Page = req.Page
- rpcReq.Cid = loginUid
- rpcReq.Filter = req.Filter
- rpcReq.Cid = loginUid
- rpcReq.ProjectId = req.ProjectId
- rpcReq.State = req.State
- rpcReq.StatusFilters = append(rpcReq.StatusFilters, 1)
- /*
- if req.FilterStatus != "" {
- array := strings.Split(req.FilterStatus, ",")
- for _, v := range array {
- value, _ := strconv.Atoi(v)
- rpcReq.StatusFilters = append(rpcReq.StatusFilters, int32(value))
- }
- }*/
- reply, err := pb.Enterprise.VedioList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "VedioList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *reply
- if resp.Data.List == nil {
- resp.Data.List = make([]*v1.VedioItem, 0)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // 通道列表
- // @Summary 通道列表
- // @Description 通道列表
- // @Tags device
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param sn query string true " "
- // @Param page query int false " "
- // @Param channel_no query string false " "
- // @Success 200 {object} v1.ChannelListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/device/vedio_channel_list [get]
- func (c *Controller) DeviceVedioChannelList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ChannelListRequest{}
- //var loginUid int64
- //var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.ChannelListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- //loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.ChannelListResponse{}
- rpcReq := &v1.ChannelListRequest{}
- rpcReq.Page = req.Page
- rpcReq.Sn = req.Sn
- rpcReq.ChannelNo = req.ChannelNo
- /*
- if req.FilterStatus != "" {
- array := strings.Split(req.FilterStatus, ",")
- for _, v := range array {
- value, _ := strconv.Atoi(v)
- rpcReq.StatusFilters = append(rpcReq.StatusFilters, int32(value))
- }
- }*/
- reply, err := pb.Enterprise.ChannelList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "ChannelList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *reply
- if resp.Data.List == nil {
- resp.Data.List = make([]*v1.ChannelItem, 0)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|