// 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) }