12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274 |
- // 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-site-management-gateway/errors"
- param_v1 "smart-site-management-gateway/param/v1"
- "smart-site-management-gateway/pb"
- "smart-site-management-gateway/pb/v1"
- "smart-site-management-gateway/utils"
- )
- // 设备列表
- // @Summary 设备列表
- // @Description 设备列表
- // @Tags 设备后台设置
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param page query int false " "
- // @Param page_size query int false " "
- // @Param filter query string false " "
- // @Param status query int false " 审核状态 -1 不过滤, 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
- }
- loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- if req.Page < 1 {
- req.Page = 1
- }
- resp := param_v1.DeviceListResponse{}
- rpcReq := &v1.DeviceListRequest{
- Page: req.Page,
- Filter: req.Filter,
- PageSize:req.PageSize,
- }
- //req.FilterStatus = "1"
- if req.Status > -1 {
- rpcReq.StatusFilters = append(rpcReq.StatusFilters, int32(req.Status))
- }
- rpcReq.ProjectId = projectId
- reply, err := pb.Project.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, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.VedioListResponse{}
- rpcReq := &v1.VedioListRequest{}
- rpcReq.Page = req.Page
- rpcReq.ProjectId = projectId
- 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.Project.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 sn query string false " "
- // @Param page query int false " "
- // @Param page_size query int false " "
- // @Param channel_no query string 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
- }
- loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.ChannelListResponse{}
- rpcReq := &v1.ChannelListRequest{}
- rpcReq.Page = req.Page
- rpcReq.Sn = req.Sn
- rpcReq.ChannelNo = req.ChannelNo
- rpcReq.PageSise = req.PageSize
- rpcReq.ProjectId = projectId
- /*
- 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.Project.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)
- }
- // 未绑定设备的通道列表
- // @Summary 未绑定设备的通道列表
- // @Description 未绑定设备的通道列表
- // @Tags device
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Success 200 {object} v1.ChannelListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/device/vedio_channel_unbind [get]
- func (c *Controller) DeviceVedioChannelUnbindList(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
- }
- loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.ChannelListUnbindResponse{}
- rpcReq := &v1.ChannelListRequest{}
- rpcReq.ProjectId = projectId
- rpcReq.IsUnbind = true
- reply, err := pb.Project.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.List = reply.List
- if resp.Data.List == nil {
- resp.Data.List = make([]*v1.ChannelItem, 0)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // 申请的设备列表
- // @Summary 申请的设备列表
- // @Description 申请的设备列表
- // @Tags 设备后台设置
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param page query int false " "
- // @Param filter query string false " "
- // @Success 200 {object} v1.DeviceListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/device/apply_list [get]
- func (c *Controller) DeviceApplyList(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, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- if req.Page < 1 {
- req.Page = 1
- }
- resp := param_v1.DeviceListResponse{}
- rpcReq := &v1.DeviceListRequest{
- Page: req.Page,
- Filter: req.Filter,
- }
- rpcReq.StatusFilters = append(rpcReq.StatusFilters, 0)
- rpcReq.StatusFilters = append(rpcReq.StatusFilters, 2)
- rpcReq.ProjectId = projectId
- reply, err := pb.Project.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 项目后台设置
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param body body v1.ProjectChangeBody true " "
- // @Success 200 {object} v1.DeviceListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/project [put]
- func (c *Controller) ProjectChange(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ProjectChangeRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ProjectChangeBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- var pid int64
- handleServiceTask := func() error {
- // 响应数据
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- pid = projectId
- resp := param_v1.ProjectChangeResponse{}
- rpcReq := &v1.ProjectChangeRequest{
- Id: projectId,
- }
- rpcReq.List = make([]*v1.ProjectInfoItem, len(req.List))
- for i, v := range req.List {
- rpcReq.List[i] = &v1.ProjectInfoItem{}
- rpcReq.List[i].Name = v.Name
- rpcReq.List[i].Value = v.Value
- }
- _, err = pb.Project.ProjectChange(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "ProjectChange"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- s, _ := json.MarshalToString(req)
- utils.LogWrite("项目变更申请", loginUid, userName, s, err, pid)
- }
- // 项目变更申请前获取当前项目字段信息
- // @Summary 项目变更申请前获取当前项目字段信息
- // @Description 项目变更申请前获取当前项目字段信息
- // @Tags 项目后台设置
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Success 200 {object} v1.ProjectInfoForChangeResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/project/fields [get]
- func (c *Controller) ProjectInfoForChange(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ProjectInfoForChangeRequest{}
- 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
- }
- loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.ProjectInfoForChangeResponse{}
- rpcReq := &v1.ProjectInfoForChangeRequest{
- Id: projectId,
- }
- reply, err := pb.Project.ProjectInfoForChange(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "ProjectChange"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // 项目变更申请列表
- // @Summary 项目变更申请列表
- // @Description 项目变更申请列表
- // @Tags 项目后台设置
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param page query int false " "
- // @Success 200 {object} v1.ProjectChangeInfoListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/project/change_job_list [get]
- func (c *Controller) ProjectChangeInfoList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ProjectChangeInfoListRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.ProjectChangeInfoListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- if req.Page < 1 {
- req.Page = 1
- }
- resp := param_v1.ProjectChangeInfoListResponse{}
- rpcReq := &v1.ProjectChangeInfoListRequest{
- Id: projectId,
- Page: req.Page,
- }
- reply, err := pb.Project.ProjectChangeInfoList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "ProjectChangeInfoList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // 设备入库审批
- // @Summary 设备入库审批
- // @Description 设备入库审批
- // @Tags 设备后台设置
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param body body v1.DeviceApproveBody true " "
- // @Success 200 {object} v1.DeviceApproveResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/project/device_approve [put]
- func (c *Controller) DeviceApprove(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.DeviceApproveRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.DeviceApproveBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- var pid int64
- handleServiceTask := func() error {
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- pid = projectId
- // 响应数据
- resp := param_v1.DeviceApproveResponse{}
- rpcReq := &v1.DeviceApproveRequest{
- Id: req.Id,
- Status: req.Status,
- Feedback: req.Feedback,
- }
- _, err = pb.Project.DeviceApprove(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "DeviceApprove"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- s, _ := json.MarshalToString(req)
- utils.LogWrite("设备入库审批", loginUid, userName, s, err, pid)
- }
- /*
- //
- // @Summary 设备下的摄像头
- // @Description 设备下的摄像头
- // @Tags device
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param device_id query int64 true " "
- // @Success 200 {object} v1.DeviceCameraResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/device/camera [get]
- func (c *Controller) DeviceCamera(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.DeviceCameraRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.DeviceCameraQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- // 响应数据
- resp := param_v1.DeviceCameraResponse{}
- rpcReq := &v1.CameraListRequest{
- DeviceId:req.DeviceId,
- ProjectId:projectId,
- }
- rpcRsp, err := pb.Project.CameraList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Project.CameraList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if len(rpcRsp.List) > 0 {
- resp.Data = *rpcRsp.List[0]
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- */
- // 项目信息
- // @Summary 项目信息
- // @Description 项目信息
- // @Tags project
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Success 200 {object} v1.ProjectInfoResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/project/info [get]
- func (c *Controller) ProjectInfo(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ProjectInfoRequest{}
- 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
- }
- loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.ProjectInfoResponse{}
- rpcReq := &v1.ProjectInfoRequest{
- ProjectId:projectId,
- }
- reply, err := pb.Project.ProjectInfo(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "ProjectInfo"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // 项目设备统计
- // @Summary 项目设备统计
- // @Description 项目设备统计
- // @Tags project
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Success 200 {object} v1.ProjectDeviceStatisticsResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/project/device_statistics [get]
- func (c *Controller) ProjectDeviceStatistics(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ProjectDeviceStatisticsRequest{}
- 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
- }
- loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.ProjectDeviceStatisticsResponse{}
- rpcReq := &v1.ProjectDeviceStatisticsRequest{
- ProjectId:projectId,
- }
- reply, err := pb.Project.ProjectDeviceStatistics(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "ProjectDeviceStatistics"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *reply
- if resp.Data.List == nil {
- resp.Data.List = []*v1.ProjectDeviceStatistics{}
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // 项目进度列表
- // @Summary 项目进度列表
- // @Description 项目进度列表
- // @Tags project
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Success 200 {object} v1.ProjectProgressResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/project/progress_list [get]
- func (c *Controller) ProjectProgress(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ProjectProgressRequest{}
- 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
- }
- loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.ProjectProgressResponse{}
- rpcReq := &v1.ProjectProgressRequest{
- ProjectId:projectId,
- }
- reply, err := pb.Project.ProjectProgress(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "ProjectProgress"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *reply
- if resp.Data.List == nil {
- resp.Data.List = []*v1.ProjectProgress{}
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // 添加项目进度
- // @Summary 添加项目进度
- // @Description 添加项目进度
- // @Tags project
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param body body v1.ProjectProgressAddBody true " "
- // @Success 200 {object} v1.ProjectProgressAddResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/project/progress [post]
- func (c *Controller) ProjectProgressAdd(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ProjectProgressAddRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ProjectProgressAddBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- var pid int64
- handleServiceTask := func() error {
- // 响应数据
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- pid = projectId
- resp := param_v1.ProjectProgressAddResponse{}
- rpcReq := &v1.ProjectProgressAddRequest{
- ProjectId:projectId,
- Name:req.Name,
- ExpectEndTime:req.ExpectEndTime,
- ExpectStartTime:req.ExpectStartTime,
- }
- reply, err := pb.Project.ProjectProgressAdd(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "ProjectProgressAdd"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- s, _ := json.MarshalToString(req)
- utils.LogWrite("添加项目进度", loginUid, userName, s, err, pid)
- }
- //
- // @Summary 项目进度完成或开工
- // @Description 项目进度完成或开工
- // @Tags project
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param body body v1.ProjectProgressSetBody true " "
- // @Success 200 {object} v1.ProjectProgressSetResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/project/progress [put]
- func (c *Controller) ProjectProgressSet(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ProjectProgressSetRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ProjectProgressSetBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- if (req.RealityStartTime <= 0 && req.RealityEndTime <= 0) ||
- (req.RealityStartTime > 0 && req.RealityEndTime > 0) {
- return errors.ParamsError
- }
- loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- var pid int64
- handleServiceTask := func() error {
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- pid = projectId
- // 响应数据
- resp := param_v1.ProjectProgressSetResponse{}
- rpcReq := &v1.ProjectProgressSetRequest{
- Id:req.Id,
- Image:req.Image,
- Start:req.RealityStartTime,
- End:req.RealityEndTime,
- }
- _, err = pb.Project.ProjectProgressSet(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "ProjectProgressSet"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- s, _ := json.MarshalToString(req)
- utils.LogWrite("项目进度完成", loginUid, userName, s, err, pid)
- }
- // 删除项目进度
- // @Summary 删除项目进度
- // @Description 删除项目进度
- // @Tags project
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param id path int64 true " "
- // @Success 200 {object} v1.ProjectProgressDelResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/project/progress/{id} [delete]
- func (c *Controller) ProjectProgressDel(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ProjectProgressDelRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, &req.ProjectProgressDelPath, nil, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- var pid int64
- handleServiceTask := func() error {
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- pid = projectId
- // 响应数据
- resp := param_v1.ProjectProgressDelResponse{}
- rpcReq := &v1.ProjectProgressDelRequest{
- Id:req.Id,
- }
- _, err = pb.Project.ProjectProgressDel(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "ProjectProgressDel"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- s, _ := json.MarshalToString(req)
- utils.LogWrite("删除项目进度", loginUid, userName, s, err, pid)
- }
- // 设备绑定的摄像头
- // @Summary 设备绑定的摄像头
- // @Description 设备绑定的摄像头
- // @Tags device
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param sn query string false " "
- // @Success 200 {object} v1.DeviceVideoChannelResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/device/vedio_channel [get]
- func (c *Controller) DeviceVideoChannel(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.DeviceVideoChannelRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.DeviceVideoChannelQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.DeviceVideoChannelResponse{}
- rpcReq := &v1.DeviceVideoChannelRequest{}
- rpcReq.Sn = req.Sn
- rpcReq.ProjectId = projectId
- /*
- 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.Project.DeviceVideoChannel(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "DeviceVideoChannel"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // 设置项目平面图或效果图
- // @Summary 设置项目平面图或效果图
- // @Description 设置项目平面图或效果图
- // @Tags 项目后台设置
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param body body v1.ProjectSetPicBody true " "
- // @Success 200 {object} v1.ProjectSetPicResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/project/pic [put]
- func (c *Controller) ProjectSetPic(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ProjectSetPicRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ProjectSetPicBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- var pid int64
- handleServiceTask := func() error {
- // 响应数据
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- pid = projectId
- resp := param_v1.ProjectSetPicResponse{}
- rpcReq := &v1.ProjectSetPicRequest{
- ProjectId: projectId,
- PicUrl:req.PicUrl,
- PicType:req.PicType,
- }
- _, err = pb.Project.ProjectSetPic(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "ProjectSetPic"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- s, _ := json.MarshalToString(req)
- utils.LogWrite("设置项目平面图或效果图", loginUid, userName, s, err, pid)
- }
- // 修改项目名称或地址
- // @Summary 修改项目名称或地址
- // @Description 修改项目名称或地址
- // @Tags 项目后台设置
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param body body v1.ProjectUpdateBody true " "
- // @Success 200 {object} v1.ProjectUpdateResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/project/name_location [put]
- func (c *Controller) ProjectUpdate(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ProjectUpdateRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ProjectUpdateBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- var pid int64
- handleServiceTask := func() error {
- // 响应数据
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- pid = projectId
- resp := param_v1.ProjectUpdateResponse{}
- rpcReq := &v1.ProjectUpdateRequest{
- ProjectId: projectId,
- Name:req.Name,
- ShortName:req.ShortName,
- Location:req.Location,
- }
- _, err = pb.Project.ProjectUpdate(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "ProjectUpdate"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- s, _ := json.MarshalToString(req)
- utils.LogWrite("修改项目名称或地址", loginUid, userName, s, err, pid)
- }
|