123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- // 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/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 type query int true " "
- // @Param time query int64 true " "
- // @Param sn query string true " "
- // @Success 200 {object} v1.DustMonitorHistoryResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/dust/history [get]
- func (c *Controller) DustMonitorHistory(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.DustMonitorHistoryRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.DustMonitorHistoryQuery, 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.DustMonitorHistoryResponse{}
- rpcReq := &v1.DustMonitorHistoryRequest{
- Sn: req.Sn,
- Type: req.Type,
- Time:req.Time,
- }
- rpcRsp, err := pb.Project.DustMonitorHistory(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Project.DustMonitorHistory"),
- 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 type query int false " "
- // @Param sn query string false " "
- // @Success 200 {object} v1.LatestDustMonitorDataResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/dust/last [get]
- func (c *Controller) LatestDustMonitorData(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.LatestDustMonitorDataRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.LatestDustMonitorQuery, 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.LatestDustMonitorDataResponse{}
- rpcReq := &v1.LatestDustMonitorDataRequest{
- Sn: req.Sn,
- Type: req.Type,
- ProjectId:projectId,
- }
- rpcRsp, err := pb.Project.LatestDustMonitorData(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Project.LatestDustMonitorData"),
- 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 扬尘设备列表
- // @Description 扬尘历史
- // @Tags 扬尘监控前台展示
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param page query int true " "
- // @Param page_size query int true " "
- // @Success 200 {object} v1.DustListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/dust/list [get]
- func (c *Controller) DustList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.DustListRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.DustListQuery, 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.DustListResponse{}
- rpcReq := &v1.DustListRequest{
- PageSize:req.PageSize,
- Page:req.Page,
- ProjectId:projectId,
- }
- rpcRsp, err := pb.Project.DustList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Project.DustList"),
- 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.DustListItem{}
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 扬尘aqi
- // @Description 扬尘aqi
- // @Tags 扬尘监控前台展示
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param sn query string true " "
- // @Success 200 {object} v1.DustAqiResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/dust/aqi [get]
- func (c *Controller) DustAqi(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.DustAqiRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.DustAqiQuery, 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.DustAqiResponse{}
- rpcReq := &v1.DustAqiRequest{
- Sn:req.Sn,
- }
- rpcRsp, err := pb.Project.DustAqi(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Project.DustAqi"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data.Aqi = int(rpcRsp.Aqi)
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|