123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940 |
- // 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-supplier-management-gateway/errors"
- param_v1 "smart-supplier-management-gateway/param/v1"
- "smart-supplier-management-gateway/pb"
- "smart-supplier-management-gateway/pb/v1"
- "smart-supplier-management-gateway/utils"
- "strconv"
- "strings"
- )
- // 设备对接
- // @Summary 设备对接
- // @Description 设备对接
- // @Tags device
- // @Accept json
- // @Produce json
- // @Param token header string true "设备类型"
- // @Param body body v1.DeviceDockingBody true "设备类型"
- // @Success 200 {object} v1.DeviceDockingResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/device/docking [post]
- func (c *Controller) DeviceDocking(ctx *gin.Context) {
- // 解析参数
- var userName string
- var loginUid int64
- req := ¶m_v1.DeviceDockingRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, nil, &req.DeviceDockingBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- userName, loginUid, err = utils.GetTokenInfo(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- uid, err := utils.GetJwtIdFromCtx(ctx)
- if err != nil {
- return err
- }
- // 响应数据
- resp := param_v1.DeviceDockingResponse{}
- rpcReq := &v1.DeviceDockingRequest{
- DeviceType:req.DeviceType,
- Uid:uid,
- }
- rpcRsp, err := pb.Supplier.DeviceDocking(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "DeviceDocking"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return err
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- s, _ := json.MarshalToString(req)
- utils.LogWrite("设备对接申请", loginUid, userName, s, err, 0)
- }
- // 添加设备
- // @Summary 添加设备
- // @Description 添加设备
- // @Tags device
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param body body v1.DeviceAddBody true " "
- // @Success 200 {object} v1.DeviceAddResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/device [post]
- func (c *Controller) DeviceAdd(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.DeviceAddRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.DeviceAddBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- userName, loginUid, _ = utils.GetTokenInfo(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.DeviceAddResponse{}
- rpcReq := &v1.DeviceAddRequest{}
- utils.StructCopy(rpcReq, &req.DeviceAddBody, "")
- rpcReq.ProviderId = loginUid
- rpcRsp, err := pb.Supplier.DeviceAdd(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "DeviceAdd"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- s, _ := json.MarshalToString(req)
- utils.LogWrite("设备入库申请", loginUid, userName, s, err, req.ProjectId)
- }
- // 拆机申请
- // @Summary 拆机申请
- // @Description 拆机申请
- // @Tags device
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param body body v1.DeviceDelBody true " "
- // @Success 200 {object} v1.DeviceDelResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/device [delete]
- func (c *Controller) DeviceDel(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.DeviceDelRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.DeviceDelBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- userName, loginUid, err = utils.GetTokenInfo(ctx)
- return nil
- }
- // 业务处理
- projectId := int64(0)
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.DeviceDelResponse{}
- rpcReq := &v1.DeviceDelRequest{
- DeviceId:req.Id,
- Reason:req.Reason,
- }
- reply, err := pb.Supplier.DeviceDel(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "DeviceDel"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- projectId = reply.ProjectId
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- s, _ := json.MarshalToString(req)
- utils.LogWrite("设备拆机申请", loginUid, userName, s, err, projectId)
- }
- // 设备类型列表
- // @Summary 设备类型列表
- // @Description 设备类型列表
- // @Tags device
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Success 200 {object} v1.DeviceTypeListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/device/default_type_list [get]
- func (c *Controller) DeviceDefaultTypeList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.DeviceTypeListRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- userName, loginUid, err = utils.GetTokenInfo(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.DeviceTypeListResponse{}
- rpcReq := &v1.DeviceTypeListRequest{}
- rpcReq.ProviderId = 0
- reply, err := pb.Supplier.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.List
- if resp.Data == nil {
- resp.Data = 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 include_vedio query bool false "是否包含视屏设备"
- // @Param status_filters query string false "状态,逗号分隔:0 待对接测试 1 测试通过 2对接测试未通过 3. 审核通过 3 审核未通过"
- // @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
- }
- userName, loginUid, err = utils.GetTokenInfo(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.DeviceTypeListResponse{}
- rpcReq := &v1.DeviceTypeListRequest{}
- rpcReq.ProviderId = loginUid
- if req.StatusFilters != "" {
- array := strings.Split(req.StatusFilters, ",")
- for _, v := range array {
- value, _ := strconv.Atoi(v)
- rpcReq.StatusFilters = append(rpcReq.StatusFilters, int32(value))
- }
- }
- rpcReq.IncludeVedio = req.IncludeVedio
- reply, err := pb.Supplier.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.List
- if resp.Data == nil {
- resp.Data = make([]*v1.DeviceTypeItem, 0)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // 设备类型总列表
- // @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.DeviceTypeListRequest{}
- reply, err := pb.Supplier.DeviceTypeList(ctx, rpcReq)
- if err != nil {
- logger.Error("func",
- zap.String("call", "DeviceTypeAll"),
- 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, handleServiceTask)
- }
- // 设备列表
- // @Summary 设备列表
- // @Description 设备列表
- // @Tags device
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param filter query string false "过滤字段"
- // @Param page query int false " "
- // @Param type_code query int false "设备类型编码"
- // @Param filter_status query string false "状态,逗号分隔:0 待审核 1 通过 2 未通过"
- // @Success 200 {object} v1.DeviceListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/device/list [get]
- func (c *Controller) DeviceList(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
- }
- userName, loginUid, err = utils.GetTokenInfo(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.DeviceListResponse{}
- rpcReq := &v1.DeviceListRequest{}
- rpcReq.ProjectId = req.ProjectId
- rpcReq.Page = req.Page
- rpcReq.ProviderId = loginUid
- rpcReq.Filter = req.Filter
- rpcReq.TypeCode = int32(req.TypeCode)
- rpcReq.CanDel = req.CanDel
- 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.Supplier.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 page query int false " "
- // @Param type_code query int false "设备类型编码"
- // @Success 200 {object} v1.DeviceListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/device/can_del_list [get]
- func (c *Controller) DeviceCanDelList(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
- }
- userName, loginUid, err = utils.GetTokenInfo(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.DeviceListResponse{}
- rpcReq := &v1.DeviceListRequest{}
- rpcReq.ProjectId = req.ProjectId
- rpcReq.Page = req.Page
- rpcReq.ProviderId = loginUid
- rpcReq.Filter = req.Filter
- rpcReq.TypeCode = int32(req.TypeCode)
- rpcReq.CanDel = true
- reply, err := pb.Supplier.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 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
- }
- userName, loginUid, err = utils.GetTokenInfo(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.VedioListResponse{}
- rpcReq := &v1.VedioListRequest{}
- rpcReq.Page = req.Page
- rpcReq.ProviderId = loginUid
- rpcReq.Filter = req.Filter
- /*
- 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.Supplier.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 page query int false " "
- // @Param filter_status query string false "状态,逗号分隔:0 待审核 1 通过 2 未通过"
- // @Param filter query string false " "
- // @Success 200 {object} v1.DeviceDelJobListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/device/del_job_list [get]
- func (c *Controller) DeviceDelJobList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.DeviceDelJobListRequest{}
- var loginUid int64
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.DeviceDelJobListQuery, 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.DeviceDelJobListResponse{}
- rpcReq := &v1.DeviceDelJobListRequest{
- Page:req.Page,
- }
- if req.FilterStatus != "" {
- array := strings.Split(req.FilterStatus, ",")
- for _, v := range array {
- value, _ := strconv.Atoi(v)
- rpcReq.StatusFilters = append(rpcReq.StatusFilters, int32(value))
- }
- }
- rpcReq.ProviderId = loginUid
- rpcReq.Filter = req.Filter
- reply, err := pb.Supplier.DeviceDelJobList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "DeviceDelJobList"),
- 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.DeviceDelJobItem, 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 " "
- // @Success 200 {object} v1.ProjectListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/project/list [get]
- func (c *Controller) ProjectList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ProjectListRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- userName, loginUid, err = utils.GetTokenInfo(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.ProjectListResponse{}
- rpcReq := &v1.ProjectListRequest{}
- reply, err := pb.Supplier.ProjectList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "ProjectList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = reply.List
- if resp.Data == nil {
- resp.Data = make([]*v1.ProjectItem, 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 body body v1.VedioAddBody true " "
- // @Success 200 {object} v1.VedioAddResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/device/vedio [post]
- func (c *Controller) VedioAdd(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.VedioAddRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.VedioAddBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- userName, loginUid, _ = utils.GetTokenInfo(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.VedioAddResponse{}
- rpcReq := &v1.VedioAddRequest{
- ProviderId:loginUid,
- ProjectId:req.ProjectId,
- VedioType:req.VedioType,
- Name:req.Name,
- ChannelCount:req.ChannelCount,
- }
- rpcRsp, err := pb.Supplier.VedioAdd(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "VedioAdd"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- s, _ := json.MarshalToString(req)
- utils.LogWrite("视频设备入库申请", loginUid, userName, s, err, req.ProjectId)
- }
- // 添加通道
- // @Summary 添加通道
- // @Description 添加通道
- // @Tags device
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param body body v1.ChannelAddBody true " "
- // @Success 200 {object} v1.ChannelAddResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/device/vedio_channel [post]
- func (c *Controller) ChannelAdd(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ChannelAddRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ChannelAddBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- userName, loginUid, _ = utils.GetTokenInfo(ctx)
- return nil
- }
- // 业务处理
- var projectId int64
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.ChannelAddResponse{}
- rpcReq := &v1.ChannelAddRequest{
- Sn:req.Sn,
- ChannelCount:req.ChannelCount,
- }
- rpcRsp, err := pb.Supplier.ChannelAdd(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "ChannelAdd"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- projectId = rpcRsp.ProjectId
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- s, _ := json.MarshalToString(req)
- utils.LogWrite("添加通道", loginUid, userName, s, err, projectId)
- }
- // 编辑通道
- // @Summary 编辑通道
- // @Description 编辑通道
- // @Tags device
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param body body v1.ChannelUpdateBody true " "
- // @Success 200 {object} v1.ChannelUpdateResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/device/vedio_channel [put]
- func (c *Controller) ChannelUpdate(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ChannelUpdateRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ChannelUpdateBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- userName, loginUid, _ = utils.GetTokenInfo(ctx)
- return nil
- }
- // 业务处理
- var projectId int64
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.ChannelUpdateResponse{}
- rpcReq := &v1.ChannelUpdateRequest{
- Id:req.Id,
- Name:req.Name,
- }
- rpcRsp, err := pb.Supplier.ChannelUpdate(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "ChannelUpdate"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- projectId = rpcRsp.ProjectId
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- s, _ := json.MarshalToString(req)
- utils.LogWrite("编辑通道", loginUid, userName, s, err, projectId)
- }
- // 通道列表
- // @Summary 通道列表
- // @Description 通道列表
- // @Tags device
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param sn query string true " "
- // @Param channel_no query string false " "
- // @Param page query int 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
- }
- userName, loginUid, err = utils.GetTokenInfo(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.Supplier.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)
- }
|