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