123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package v1
- import (
- "net/http"
- "smart-site-management-gateway/errors"
- param_v1 "smart-site-management-gateway/param/v1"
- "smart-site-management-gateway/parser"
- "smart-site-management-gateway/pb"
- "smart-site-management-gateway/pb/v1"
- "smart-site-management-gateway/utils"
- "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"
- )
- //
- // @Summary 塔机历史
- // @Description 塔机历史
- // @Tags 塔吊监控前台展示
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param page query int false " "
- // @Param page_size query int false " "
- // @Param start query int64 false " "
- // @Param end query int64 false " "
- // @Param sn query string true " "
- // @Success 200 {object} v1.TowerMonitorHistoryResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/iot/tower_history [get]
- func (c *Controller) TowerMonitorHistory(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.TowerMonitorHistoryRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.TowerMonitorHistoryQuery, 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.TowerMonitorHistoryResponse{}
- rpcReq := &v1.TowerMonitorHistoryRequest{
- Sn: req.Sn,
- Start:req.Start,
- End:req.End,
- PageSize:req.PageSize,
- Page:req.Page,
- }
- rpcRsp, err := pb.Project.TowerMonitorHistory(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Project.TowerMonitorHistory"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 塔吊最近数据
- // @Description 塔吊最近数据
- // @Tags 塔吊监控前台展示
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param sn query string false " "
- // @Success 200 {object} v1.LatestTowerMonitorDataResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/iot/tower_last [get]
- func (c *Controller) LatestTowerMonitorData(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.LatestTowerMonitorDataRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.LatestTowerMonitorQuery, 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 {
- // 响应数据
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.LatestTowerMonitorDataResponse{}
- rpcReq := &v1.LatestTowerMonitorDataRequest{
- Sn: req.Sn,
- ProjectId:projectId,
- }
- rpcRsp, err := pb.Project.LatestTowerMonitorData(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Project.LatestTowerMonitorData"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *rpcRsp.Data
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary iot设备列表
- // @Description iot设备列表
- // @Tags 塔吊监控前台展示
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param page query int false " "
- // @Param page_size query int false " "
- // @Param device_code query int true " "
- // @Success 200 {object} v1.IotListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/iot/list [get]
- func (c *Controller) IotList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.IotListRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.IotListQuery, 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 {
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- // 响应数据
- resp := param_v1.IotListResponse{}
- rpcReq := &v1.IotListRequest{
- PageSize:req.PageSize,
- Page:req.Page,
- ProjectId:projectId,
- DeviceCode:req.DeviceCode,
- }
- rpcRsp, err := pb.Project.IotList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Project.IotList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *rpcRsp
- if resp.Data.List == nil {
- resp.Data.List = []*v1.IotListItem{}
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary iot设备类型列表
- // @Description iot设备类型列表
- // @Tags 塔吊监控前台展示
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Success 200 {object} v1.IotTypeListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/iot/type_list [get]
- func (c *Controller) IotTypeList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.IotTypeListRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, nil, 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 {
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- // 响应数据
- resp := param_v1.IotTypeListResponse{}
- rpcReq := &v1.IotTypeListRequest{
- ProjectId:projectId,
- }
- rpcRsp, err := pb.Project.IotTypeList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Project.IotList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *rpcRsp
- if resp.Data.List == nil {
- resp.Data.List = []*v1.IotTypeListItem{}
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary iot最近数据
- // @Description iot最近数据
- // @Tags 塔吊监控前台展示
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param sn query string true " "
- // @Param device_code query int true " "
- // @Success 200 {object} v1.IotLastResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/iot/last [get]
- func (c *Controller) IotLast(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.IotLastRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.IotLastQuery, 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 {
- // 响应数据
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.IotLastResponse{}
- rpcReq := &v1.IotLastRequest{
- Sn: req.Sn,
- ProjectId:projectId,
- DeviceCode:req.DeviceCode,
- }
- rpcRsp, err := pb.Project.IotLast(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Project.IotLast"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *rpcRsp
- resp.Data.Pic = parser.Conf.TowerPicUrl
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|