// 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/consts" "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.DeviceTypeAddBody true " " // @Success 200 {object} v1.DeviceTypeAddResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/device/type [post] func (c *Controller) DeviceTypeAdd(ctx *gin.Context) { // 解析参数 var userName string var loginUid int64 req := ¶m_v1.DeviceTypeAddRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, nil, nil, nil, &req.DeviceTypeAddBody) 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.DeviceTypeAddResponse{} rpcReq := &v1.DeviceTypeAddRequest{ DeviceCode:req.DeviceType, ProviderId:uid, AgentPhone:req.AgentPhone, Agent:req.Agent, Appendix:req.Appendix, Comment:req.Comment, } rpcRsp, err := pb.Supplier.DeviceTypeAdd(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "DeviceTypeAdd"), 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.DeviceTypeTestingAddBody true " " // @Success 200 {object} v1.DeviceTypeTestingAddResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/device/type_testing [post] func (c *Controller) DeviceTypeTestingAdd(ctx *gin.Context) { // 解析参数 var userName string var loginUid int64 req := ¶m_v1.DeviceTypeTestingAddRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, nil, nil, nil, &req.DeviceTypeTestingAddBody) 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.DeviceTypeTestingAddResponse{} rpcReq := &v1.DeviceTypeTestingAddRequest{ DeviceCode:req.DeviceType, ProviderId:uid, AgentPhone:req.AgentPhone, Agent:req.Agent, Appendix:req.Appendix, Comment:req.Comment, } rpcRsp, err := pb.Supplier.DeviceTypeTestingAdd(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "DeviceTypeTestingAdd"), 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/dust [post] func (c *Controller) DeviceDustAdd(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 rpcReq.Type = consts.DeviceTypeDust 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.DeviceAddBody true " " // @Success 200 {object} v1.DeviceAddResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/device/attendance [post] func (c *Controller) DeviceAttendanceAdd(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 rpcReq.Type = consts.DeviceTypeAttendance 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 device_code query int32 false " " // @Param list_type query int32 true "0. 已对接的设备类型 1 设备类型申请列表 2 设备类型对接列表 3.可申请的设备类型 4 可对接的设备类型 6 平台支持的所有的设备类型" // @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, err = utils.GetTokenInfo(ctx) return nil } // 业务处理 handleServiceTask := func() error { // 响应数据 resp := param_v1.DeviceTypeListResponse{} rpcReq := &v1.DeviceTypeListRequest{} rpcReq.ProviderId = loginUid rpcReq.DeviceCode = req.DeviceCode rpcReq.ListType = req.ListType 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) } for i, _ := range resp.Data { if resp.Data[i].TypeCode == consts.DeviceTypeDust { resp.Data[i].NeedAppendix = true } } 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{} rpcReq.ListType = 5 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/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.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 = consts.DeviceTypeDust 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 "设备类型编码" // @Param filter_status query string false "状态,逗号分隔:0 待审核 1 通过 2 未通过" // @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.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 = consts.DeviceTypeAttendance 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 } _, 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.CanDel = true rpcReq.AllType = 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 } _, 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) }