Procházet zdrojové kódy

获取会议室详情,地点详情,会议室列表

huangyan před 2 měsíci
rodič
revize
1cc39300a4

+ 1 - 0
config/local.yml

@@ -59,3 +59,4 @@ conference:
   getRoomsByLocationId: "/meetingRoom/getRoomsByLocationId" #获取会议室数据
   meetingRoom: "/meetingRoom" #会议室详情
   location: "/location" #地点详情
+  meetingRoomStatus: "/meetingRoomStatus/home" #会议室状态

+ 112 - 38
internal/handler/conference.go

@@ -5,6 +5,7 @@ import (
 	"city_chips/internal/service"
 	"city_chips/pkg/helper/resp"
 	"encoding/json"
+	"fmt"
 	"github.com/gin-gonic/gin"
 	"github.com/spf13/viper"
 	"github.com/tidwall/gjson"
@@ -45,14 +46,29 @@ func (h *ConferenceHandler) RoomOps(ctx *gin.Context) {
 // DataAnalysis 数据大屏
 func (h *ConferenceHandler) DataAnalysis(ctx *gin.Context) {
 	dataAnalysisurl := h.conf.GetString("conference.baseurl") + h.conf.GetString("conference.dataAnalysis")
+	meetingRoomStatus := h.conf.GetString("conference.baseurl") + h.conf.GetString("conference.meetingRoomStatus")
+
 	request, err := h.conferenceService.SendRequest(http.DefaultClient, "GET", dataAnalysisurl, nil)
+	meetingRoomrequest, err := h.conferenceService.SendRequest(http.DefaultClient, "GET", meetingRoomStatus, nil)
 	if err != nil {
 		resp.HandleError(ctx, 1203, "获取数据大屏信息失败", nil)
 		return
 	}
-	if gjson.Get(string(request), "code").Int() == 0 {
-		s := gjson.Get(string(request), "data").Value()
-		resp.HandleSuccess(ctx, s)
+	var bigdata model.BigData
+	if gjson.Get(string(request), "code").Int() == 0 && gjson.Get(string(meetingRoomrequest), "code").Int() == 0 {
+		err = json.Unmarshal(request, &bigdata)
+		if err != nil {
+			h.logger.Error("json序列化失败")
+			resp.HandleError(ctx, 1203, "json序列化失败", nil)
+			return
+		}
+		meetingRoomFreeCount := gjson.Get(string(meetingRoomrequest), "data.meetingRoomFreeCount").Int()
+		meetingRoomOccupiedCount := gjson.Get(string(meetingRoomrequest), "data.meetingRoomOccupiedCount").Int()
+		meetingRoomForbiddenCount := gjson.Get(string(meetingRoomrequest), "data.meetingRoomForbiddenCount").Int()
+		bigdata.Data.MeetingRoomFreeCount = meetingRoomFreeCount
+		bigdata.Data.MeetingRoomForbiddenCount = meetingRoomForbiddenCount
+		bigdata.Data.MeetingRoomOccupiedCount = meetingRoomOccupiedCount
+		resp.HandleSuccess(ctx, bigdata.Data)
 		return
 	}
 	resp.HandleError(ctx, 1203, "获取数据大屏信息失败", nil)
@@ -60,6 +76,19 @@ func (h *ConferenceHandler) DataAnalysis(ctx *gin.Context) {
 
 // GetRoomsByLocationId  获取会议室数据
 func (h *ConferenceHandler) GetRoomsByLocationId(ctx *gin.Context) {
+	// 设置响应头
+	ctx.Header("Content-Type", "text/event-stream")
+	ctx.Header("Cache-Control", "no-cache")
+	ctx.Header("Connection", "keep-alive")
+	// 监听客户端断开连接
+	conn := true
+	notify := ctx.Writer.CloseNotify()
+	type Response struct {
+		RequestId string `protobuf:"bytes,1,opt,name=requestId,proto3" json:"requestId,omitempty"`
+		Code      int32  `protobuf:"varint,2,opt,name=code,proto3" json:"code,omitempty"`
+		Msg       string `protobuf:"bytes,3,opt,name=msg,proto3" json:"msg,omitempty"`
+		Data      any    `json:"data"`
+	}
 	getRoomsByLocationId := h.conf.GetString("conference.baseurl") + h.conf.GetString("conference.getRoomsByLocationId")
 	now := time.Now().Format("2006-01-02")
 	m := make(map[string]any)
@@ -73,45 +102,63 @@ func (h *ConferenceHandler) GetRoomsByLocationId(ctx *gin.Context) {
 	m["status"] = ""
 	m["page"] = 1
 	m["page_size"] = h.conf.GetInt("conference.pageSize")
-	request, err := h.conferenceService.SendRequest(http.DefaultClient, "POST", getRoomsByLocationId, m)
-	if err != nil {
-		resp.HandleError(ctx, 1203, "获取会议室数据失败", err)
-		return
-	}
-	var rooms model.Room
-	var meetingRoomDetail []model.MeetingRoomDetail
-	if gjson.Get(string(request), "code").Int() == 0 {
-		//s := gjson.Get(string(request), "data").Value()
-		err = json.Unmarshal(request, &rooms)
-		if err != nil {
-			h.logger.Error("json序列化失败")
-			resp.HandleError(ctx, 1203, "json序列化失败", nil)
+	var response Response
+	for conn {
+		select {
+		case <-notify:
+			conn = false
+			fmt.Println("断开连接")
 			return
-		}
-		for _, v := range rooms.Data.List {
-			//log.Println("会议室id:", v.Id)
-			//log.Println("地点id:", v.LocationId)
-			//log.Println("地点名称:", v.LocationName)
-			//log.Println("企业id:", v.CompanyId)
-			//log.Println("状态:", v.Status)
-			//log.Println("使用:", v.Usage)
-			//log.Println("会议室名称:", v.Name)
-			detail := model.MeetingRoomDetail{
-				Id:           v.Id,
-				LocationId:   v.LocationId,
-				LocationName: v.LocationName,
-				CompanyId:    v.CompanyId,
-				Status:       v.Status,
-				Usage:        v.Usage,
-				Name:         v.Name,
+		default:
+			request, err := h.conferenceService.SendRequest(http.DefaultClient, "POST", getRoomsByLocationId, m)
+			if err != nil {
+				resp.HandleError(ctx, 1203, "获取会议室数据失败", err)
+				return
 			}
-			meetingRoomDetail = append(meetingRoomDetail, detail)
+			var rooms model.Room
+			var meetingRoomDetail []model.MeetingRoomDetail
+			if gjson.Get(string(request), "code").Int() == 0 {
+				err = json.Unmarshal(request, &rooms)
+				if err != nil {
+					h.logger.Error("json序列化失败")
+					response.Code = 1203
+					response.Msg = "获取会议室数据失败"
+					response.Data = nil
+					res, _ := json.Marshal(&response)
+					fmt.Fprintf(ctx.Writer, "data: %s\n\n", string(res))
+					ctx.Writer.Flush()
+					return
+				}
+				for _, v := range rooms.Data.List {
+					detail := model.MeetingRoomDetail{
+						Id:           v.Id,
+						LocationId:   v.LocationId,
+						LocationName: v.LocationName,
+						CompanyId:    v.CompanyId,
+						Status:       v.Status,
+						Usage:        v.Usage,
+						Name:         v.Name,
+					}
+					meetingRoomDetail = append(meetingRoomDetail, detail)
+				}
+			} else {
+				response.Code = 1203
+				response.Msg = "获取会议室数据失败"
+				response.Data = string(request)
+				res, _ := json.Marshal(&response)
+				fmt.Fprintf(ctx.Writer, "data: %s\n\n", string(res))
+				ctx.Writer.Flush()
+				return
+			}
+			response.Code = 200
+			response.Msg = "查询成功"
+			response.Data = meetingRoomDetail
+			res, _ := json.Marshal(&response)
+			fmt.Fprintf(ctx.Writer, "data: %s\n\n", string(res))
+			ctx.Writer.Flush()
+			time.Sleep(10 * time.Second)
 		}
-	} else {
-		resp.HandleError(ctx, 1203, "获取会议室数据失败", string(request))
-		return
 	}
-	resp.HandleSuccess(ctx, meetingRoomDetail)
 }
 
 // MeetingRoomById 会议室详情
@@ -155,3 +202,30 @@ func (h *ConferenceHandler) Location(ctx *gin.Context) {
 	}
 	resp.HandleError(ctx, 1203, "获取地点详情失败", string(request))
 }
+
+// GetRoomsByLocation 查询会议室数据
+func (h *ConferenceHandler) GetRoomsByLocation(ctx *gin.Context) {
+	getRoomsByLocation := h.conf.GetString("conference.baseurl") + h.conf.GetString("conference.getRoomsByLocationId")
+	var respGetRooms model.RespGetRooms
+	err := ctx.ShouldBindJSON(&respGetRooms)
+	if err != nil {
+		resp.HandleError(ctx, 1203, "json序列化失败", nil)
+		return
+	}
+	_, err = time.Parse("2006-01-02", respGetRooms.Date)
+	if err != nil {
+		resp.HandleError(ctx, 1203, "时间格式错误", nil)
+		return
+	}
+	request, err := h.conferenceService.SendRequest(http.DefaultClient, "POST", getRoomsByLocation, respGetRooms)
+	if err != nil {
+		resp.HandleError(ctx, 1203, "获取会议室列表失败", err)
+		return
+	}
+	if gjson.Get(string(request), "code").Int() == 0 {
+		s := gjson.Get(string(request), "data").Value()
+		resp.HandleSuccess(ctx, s)
+		return
+	}
+	resp.HandleError(ctx, 1203, "获取会议室列表失败", string(request))
+}

+ 103 - 0
internal/model/conference.go

@@ -224,6 +224,109 @@ type MeetingRoomDetail struct {
 	Usage        Usage  `json:"usage"`         //使用时间段
 	Name         string `json:"name"`          //会议室名称
 }
+type BigData struct {
+	Code    int    `json:"code"`
+	Message string `json:"message"`
+	Data    struct {
+		DepartmentMeetingYearCount []struct {
+			Count          int    `json:"count"`
+			DepartmentName string `json:"department_name"`
+		} `json:"departmentMeetingYearCount"`
+		MeetingAppointIntervalYear struct {
+			Field1  int `json:"00:00-08:00"`
+			Field2  int `json:"08:00-09:00"`
+			Field3  int `json:"09:00-10:00"`
+			Field4  int `json:"10:00-11:00"`
+			Field5  int `json:"11:00-12:00"`
+			Field6  int `json:"12:00-13:00"`
+			Field7  int `json:"13:00-14:00"`
+			Field8  int `json:"14:00-15:00"`
+			Field9  int `json:"15:00-16:00"`
+			Field10 int `json:"16:00-17:00"`
+			Field11 int `json:"17:00-18:00"`
+			Field12 int `json:"18:00-19:00"`
+			Field13 int `json:"19:00-20:00"`
+			Field14 int `json:"20:00-21:00"`
+			Field15 int `json:"21:00-22:00"`
+			Field16 int `json:"22:00-24:00"`
+		} `json:"meetingAppointIntervalYear"`
+		MeetingAvgDayCount   float64 `json:"meetingAvgDayCount"`
+		MeetingAvgTimes      string  `json:"meetingAvgTimes"`
+		MeetingMonthHM       string  `json:"meetingMonthHM"`
+		MeetingMonthManCount int     `json:"meetingMonthManCount"`
+		MeetingMonthSum      int     `json:"meetingMonthSum"`
+		MeetingPeopleMonth   struct {
+			Field1 int `json:"1-5"`
+			Field2 int `json:"100-500"`
+			Field3 int `json:"15-50"`
+			Field4 int `json:"5-15"`
+			Field5 int `json:"50-100"`
+			Field6 int `json:"500"`
+		} `json:"meetingPeopleMonth"`
+		MeetingPeopleYear struct {
+			Field1 int `json:"1-5"`
+			Field2 int `json:"100-500"`
+			Field3 int `json:"15-50"`
+			Field4 int `json:"5-15"`
+			Field5 int `json:"50-100"`
+			Field6 int `json:"500"`
+		} `json:"meetingPeopleYear"`
+		MeetingProlongYearCount int `json:"meetingProlongYearCount"`
+		MeetingRoomMonthTimes   []struct {
+			Hours  string `json:"hours"`
+			Images string `json:"images"`
+			Name   string `json:"name"`
+		} `json:"meetingRoomMonthTimes"`
+		MeetingRoomMonthUseCount []struct {
+			Count int    `json:"count"`
+			Name  string `json:"name"`
+		} `json:"meetingRoomMonthUseCount"`
+		MeetingRoomYearTimes []struct {
+			Hours  string `json:"hours"`
+			Images string `json:"images"`
+			Name   string `json:"name"`
+		} `json:"meetingRoomYearTimes"`
+		MeetingRoomYearUseCount []struct {
+			Count int    `json:"count"`
+			Name  string `json:"name"`
+		} `json:"meetingRoomYearUseCount"`
+		MeetingStopYearCount int `json:"meetingStopYearCount"`
+		MeetingTimeMonth     struct {
+			Field1 int `json:"0-15"`
+			Field2 int `json:"15-30"`
+			Field3 int `json:"30-45"`
+			Field4 int `json:"45-60"`
+			Field5 int `json:"60-90"`
+			Field6 int `json:"90"`
+		} `json:"meetingTimeMonth"`
+		MeetingTimeYear struct {
+			Field1 int `json:"0-15"`
+			Field2 int `json:"15-30"`
+			Field3 int `json:"30-45"`
+			Field4 int `json:"45-60"`
+			Field5 int `json:"60-90"`
+			Field6 int `json:"90"`
+		} `json:"meetingTimeYear"`
+		MeetingYearHM             string `json:"meetingYearHM"`
+		MeetingYearManCount       int    `json:"meetingYearManCount"`
+		MeetingYearSum            int    `json:"meetingYearSum"`
+		MeetingRoomFreeCount      int64  `json:"meetingRoomFreeCount"`      //空闲会议室
+		MeetingRoomOccupiedCount  int64  `json:"meetingRoomOccupiedCount"`  //使用中会议室
+		MeetingRoomForbiddenCount int64  `json:"meetingRoomForbiddenCount"` //禁用中会议室
+	} `json:"data"`
+}
+type RespGetRooms struct {
+	Date        string   `json:"date"`
+	Search      string   `json:"search"`
+	LocationId  []int    `json:"locationId"`
+	Capacity    []string `json:"capacity"`
+	DeviceType  []string `json:"deviceType"`
+	RoomType    []int    `json:"roomType"`
+	AppointTime string   `json:"appoint_time"`
+	Status      int      `json:"status"`
+	Page        int      `json:"page"`
+	PageSize    int      `json:"page_size"`
+}
 
 func (m *Conference) TableName() string {
 	return "conference"

+ 1 - 0
internal/server/http.go

@@ -31,6 +31,7 @@ func NewServerHTTP(logger *log.Logger, accessHandler *handler.AccessControlHandl
 		Conference.GET("/roomOps", conference.RoomOps)
 		Conference.GET("/dataAnalysis", conference.DataAnalysis)
 		Conference.GET("/getRoomsByLocationId", conference.GetRoomsByLocationId)
+		Conference.POST("/getRoomsByLocation", conference.GetRoomsByLocation)
 		Conference.GET("/meetingRoomById", conference.MeetingRoomById)
 		Conference.GET("/location", conference.Location)
 	}