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