huangyan 1 місяць тому
батько
коміт
868b0c269d

+ 5 - 1
cmd/server/wire/wire.go

@@ -9,10 +9,10 @@ import (
 	"city_chips/internal/server"
 	"city_chips/internal/service"
 	"city_chips/pkg/log"
-
 	"github.com/gin-gonic/gin"
 	"github.com/google/wire"
 	"github.com/spf13/viper"
+	"net/http"
 )
 
 var ServerSet = wire.NewSet(server.NewServerHTTP)
@@ -48,6 +48,7 @@ var ServiceSet = wire.NewSet(
 	service.NewIlluminatingService,
 	service.NewEnergyService,
 	service.NewIntelligentBuildingControlService,
+	provideHTTPClient,
 )
 
 var HandlerSet = wire.NewSet(
@@ -66,6 +67,9 @@ var HandlerSet = wire.NewSet(
 	handler.NewIntelligentBuildingControlHandler,
 )
 
+func provideHTTPClient() *http.Client {
+	return http.DefaultClient // 或者你可以自定义 client
+}
 func NewWire(*viper.Viper, *log.Logger) (*gin.Engine, func(), error) {
 	panic(wire.Build(
 		ServerSet,

+ 8 - 2
cmd/server/wire/wire_gen.go

@@ -15,6 +15,7 @@ import (
 	"github.com/gin-gonic/gin"
 	"github.com/google/wire"
 	"github.com/spf13/viper"
+	"net/http"
 )
 
 // Injectors from wire.go:
@@ -49,7 +50,8 @@ func NewWire(viperViper *viper.Viper, logger *log.Logger) (*gin.Engine, func(),
 	informationService := service.NewInformationService(serviceService, informationRepository)
 	informationHandler := handler.NewInformationHandler(handlerHandler, informationService, viperViper)
 	illuminatingRepository := repository.NewIlluminatingRepository(repositoryRepository)
-	illuminatingService := service.NewIlluminatingService(serviceService, illuminatingRepository)
+	client := provideHTTPClient()
+	illuminatingService := service.NewIlluminatingService(serviceService, illuminatingRepository, viperViper, client)
 	illuminatingHandler := handler.NewIlluminatingHandler(handlerHandler, illuminatingService, viperViper)
 	energyRepository := repository.NewEnergyRepository(repositoryRepository)
 	energyService := service.NewEnergyService(serviceService, energyRepository)
@@ -68,6 +70,10 @@ var ServerSet = wire.NewSet(server.NewServerHTTP)
 
 var RepositorySet = wire.NewSet(repository.NewDb, repository.NewRepository, repository.NewUserRepository, repository.NewAccessControlRepository, repository.NewHikvisionRepository, repository.NewConferenceRepository, repository.NewHomeRepository, repository.NewElevatorRepository, repository.NewBroadcastRepository, repository.NewPropertyRepository, repository.NewInformationRepository, repository.NewIlluminatingRepository, repository.NewEnergyRepository, repository.NewIntelligentBuildingControlRepository)
 
-var ServiceSet = wire.NewSet(service.NewService, service.NewUserService, service.NewAccessControlService, service.NewHikvisionService, service.NewConferenceService, service.NewHomeService, service.NewElevatorService, service.NewBroadcastService, service.NewPropertyService, service.NewInformationService, service.NewIlluminatingService, service.NewEnergyService, service.NewIntelligentBuildingControlService)
+var ServiceSet = wire.NewSet(service.NewService, service.NewUserService, service.NewAccessControlService, service.NewHikvisionService, service.NewConferenceService, service.NewHomeService, service.NewElevatorService, service.NewBroadcastService, service.NewPropertyService, service.NewInformationService, service.NewIlluminatingService, service.NewEnergyService, service.NewIntelligentBuildingControlService, provideHTTPClient)
 
 var HandlerSet = wire.NewSet(handler.NewHandler, handler.NewUserHandler, handler.NewAccessControlHandler, handler.NewHikvisionHandler, handler.NewConferenceHandler, handler.NewHomeHandler, handler.NewElevatorHandler, handler.NewBroadcastHandler, handler.NewPropertyHandler, handler.NewInformationHandler, handler.NewIlluminatingHandler, handler.NewEnergyHandler, handler.NewIntelligentBuildingControlHandler)
+
+func provideHTTPClient() *http.Client {
+	return http.DefaultClient
+}

+ 10 - 0
config/local.yml

@@ -97,3 +97,13 @@ obix:
   baseUrl: "https://10.1.201.253/obix/config"
   username: "obix"
   password: "Obix123456"
+illuminating:
+  authorization: "Basic ZWNpYzo1MzZmN2VkNGE1MTNiODMzMTI3N2IwMzVkZDE2ODExZg=="
+  clientId: 3
+  mobile: "admin"
+  password: "123456"
+  baseUrl: "http://10.1.204.253"
+  api:
+    login: "/user/v1/user/user/login"
+    statistics: "/baseecic/v1/baseecic/all/statistics"
+    baseecic: "/baseecic/v2/device/all"

+ 106 - 1
internal/handler/hikvision.go

@@ -450,8 +450,9 @@ func (h *HikvisionHandler) GetDoorSearch(ctx *gin.Context) {
 	name := ctx.Query("name")
 	pageNo := ctx.Query("pageNo")
 	pageSize := ctx.Query("pageSize")
+	doorIndexCodes := ctx.Query("doorIndexCodes")
 
-	err, result := h.hikvisionService.GetDoorSearch(pageNo, pageSize, name)
+	err, result := h.hikvisionService.GetDoorSearch(pageNo, pageSize, name, []string{doorIndexCodes})
 	if err != nil {
 		h.logger.Error("获取门禁设备列表失败")
 		resp.HandleError(ctx, 1201, "获取门禁设备列表失败", err)
@@ -719,3 +720,107 @@ func (h *HikvisionHandler) GetDoorDoControl(ctx *gin.Context) {
 	}
 	resp.HandleSuccess(ctx, search.Data)
 }
+
+// GetAcsDoorStates GetDoorDoControl 门禁点状态
+func (h *HikvisionHandler) GetAcsDoorStates(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()
+	var response model.Response
+	var Acs model.DoorSearch
+	var AcsDevice model.AcsDoorStates
+	var acsDoor model.AcsDoor
+	doorIndexCodes := ctx.Query("doorIndexCodes")
+	if doorIndexCodes == "" {
+		resp.HandleError(ctx, 1203, "参数错误", nil)
+		return
+	}
+	for conn {
+		select {
+		case <-notify:
+			conn = false
+			fmt.Println("断开连接")
+			return
+		default:
+			err, search := h.hikvisionService.GetAcsDoorStates([]string{doorIndexCodes})
+			if err != nil {
+				h.logger.Error("获取门禁设备在线状态失败")
+				resp.HandleError(ctx, 1201, "获取门禁设备在线状态失败", err)
+				return
+			}
+			bytes, err := json.Marshal(search)
+			if err != nil {
+				h.logger.Error("json序列化失败")
+				resp.HandleError(ctx, 1202, "json序列化失败", nil)
+				return
+			}
+			err = json.Unmarshal(bytes, &AcsDevice)
+			if err != nil {
+				h.logger.Error("json反序列化失败")
+				resp.HandleError(ctx, 1203, "json反序列化失败", nil)
+				return
+			}
+			err, result := h.hikvisionService.GetDoorSearch("1", "1", "", []string{AcsDevice.Data.AuthDoorList[0].DoorIndexCode})
+			if err != nil {
+				h.logger.Error("获取门禁点信息失败")
+				resp.HandleError(ctx, 1201, "获取门禁点信息失败", err)
+				return
+			}
+			bytes, err = json.Marshal(result)
+			if err != nil {
+				h.logger.Error("json序列化失败")
+				resp.HandleError(ctx, 1202, "json序列化失败", nil)
+				return
+			}
+			err = json.Unmarshal(bytes, &Acs)
+			if err != nil {
+				h.logger.Error("json反序列化失败")
+				resp.HandleError(ctx, 1203, "json反序列化失败", nil)
+				return
+			}
+			for i, _ := range Acs.Data.List {
+				Acs.Data.List[i].State = AcsDevice.Data.AuthDoorList[0].DoorState
+				acsDoor.DoorNo = Acs.Data.List[i].DoorNo
+				acsDoor.DoorSerial = Acs.Data.List[i].DoorSerial
+				acsDoor.IndexCode = Acs.Data.List[i].IndexCode
+				acsDoor.State = AcsDevice.Data.AuthDoorList[0].DoorState
+				if AcsDevice.Data.AuthDoorList[0].DoorState > 3 {
+					acsDoor.StateName = "故障"
+					acsDoor.Color = 16711680
+				} else {
+					acsDoor.StateName = model.StateName[AcsDevice.Data.AuthDoorList[0].DoorState]
+					acsDoor.Color = model.Color[AcsDevice.Data.AuthDoorList[0].DoorState]
+				}
+				acsDoor.CreateTime = Acs.Data.List[i].CreateTime
+				acsDoor.UpdateTime = Acs.Data.List[i].UpdateTime
+				acsDoor.Name = Acs.Data.List[i].Name
+				acsDoor.RegionIndexCode = Acs.Data.List[i].RegionIndexCode
+				acsDoor.RegionName = Acs.Data.List[i].RegionName
+				acsDoor.RegionPath = Acs.Data.List[i].RegionPath
+				acsDoor.RegionPathName = Acs.Data.List[i].RegionPathName
+				acsDoor.ResourceType = Acs.Data.List[i].ResourceType
+				acsDoor.TreatyType = Acs.Data.List[i].TreatyType
+				acsDoor.Description = Acs.Data.List[i].Description
+				acsDoor.InstallLocation = Acs.Data.List[i].InstallLocation
+				acsDoor.ParentIndexCode = Acs.Data.List[i].ParentIndexCode
+				acsDoor.ReaderInId = Acs.Data.List[i].ReaderInId
+				acsDoor.ReaderOutId = Acs.Data.List[i].ReaderOutId
+				acsDoor.ChannelNo = Acs.Data.List[i].ChannelNo
+				acsDoor.ControlOneId = Acs.Data.List[i].ControlOneId
+				acsDoor.ControlTwoId = Acs.Data.List[i].ControlTwoId
+				acsDoor.ChannelType = Acs.Data.List[i].ChannelType
+			}
+			response.Code = 200
+			response.Msg = "获取门禁点列表成功"
+			response.Data = acsDoor
+			res, _ := json.Marshal(&response)
+			fmt.Fprintf(ctx.Writer, "data: %s\n\n", string(res))
+			ctx.Writer.Flush()
+			time.Sleep(10 * time.Second)
+		}
+	}
+}

+ 44 - 0
internal/handler/illuminating.go

@@ -6,6 +6,7 @@ import (
 	"city_chips/pkg/helper/resp"
 	"encoding/json"
 	"fmt"
+	"go.uber.org/zap"
 	"math/rand"
 	"strconv"
 	"time"
@@ -127,3 +128,46 @@ func (h *IlluminatingHandler) UpdataLightingStatus(ctx *gin.Context) {
 	}
 	resp.HandleSuccess(ctx, id)
 }
+
+// GetStatistics 获取灯光统计数据
+func (h *IlluminatingHandler) GetStatistics(ctx *gin.Context) {
+	var statis model.IlluminatingStatistics
+	statistics, err := h.illuminatingService.GetStatistics()
+	if err != nil {
+		h.logger.Error("获取统计信息失败", zap.Any("err", err))
+		resp.HandleError(ctx, 1201, "获取统计信息失败", nil)
+		return
+	}
+	err = json.Unmarshal(statistics, &statis)
+	if err != nil {
+		h.logger.Error("json反序列化失败")
+		resp.HandleError(ctx, 1202, "json反序列化失败", nil)
+		return
+	}
+	resp.HandleSuccess(ctx, statis)
+}
+func (h *IlluminatingHandler) GetBaseecic(ctx *gin.Context) {
+	currentPageStr := ctx.PostForm("currentPage")
+	currentPage, err := strconv.Atoi(currentPageStr)
+	device_type_idStr := ctx.PostForm("device_type_id")
+	device_type_id, err := strconv.Atoi(device_type_idStr)
+
+	devices_enabledStr := ctx.PostForm("devices_enabled")
+	devices_enabled, err := strconv.Atoi(devices_enabledStr)
+	pageSizeStr := ctx.PostForm("pageSize")
+	pageSize, err := strconv.Atoi(pageSizeStr)
+	if err != nil {
+		resp.HandleError(ctx, 1203, "参数错误", err)
+		return
+	}
+	query := ctx.PostForm("query")
+
+	baseecic, err := h.illuminatingService.GetBaseecic(currentPage, device_type_id, devices_enabled, pageSize, query)
+	if err != nil {
+		h.logger.Error("获取统计信息失败", zap.Any("err", err))
+		resp.HandleError(ctx, 1201, "获取统计信息失败", nil)
+		return
+	}
+
+	resp.HandleSuccess(ctx, baseecic)
+}

+ 38 - 0
internal/model/hikvision.go

@@ -681,7 +681,45 @@ type DoorSearch struct {
 		} `json:"list"`
 	} `json:"data"`
 }
+type AcsDoor struct {
+	IndexCode       string `json:"indexCode"`
+	ResourceType    string `json:"resourceType"`
+	Name            string `json:"name"`
+	DoorNo          string `json:"doorNo"`
+	ChannelNo       string `json:"channelNo"`
+	ParentIndexCode string `json:"parentIndexCode"`
+	ControlOneId    string `json:"controlOneId"`
+	ControlTwoId    string `json:"controlTwoId"`
+	ReaderInId      string `json:"readerInId"`
+	ReaderOutId     string `json:"readerOutId"`
+	DoorSerial      int    `json:"doorSerial"`
+	TreatyType      string `json:"treatyType"`
+	RegionIndexCode string `json:"regionIndexCode"`
+	RegionPath      string `json:"regionPath"`
+	CreateTime      string `json:"createTime"`
+	UpdateTime      string `json:"updateTime"`
+	Description     string `json:"description"`
+	ChannelType     string `json:"channelType"`
+	RegionName      string `json:"regionName"`
+	RegionPathName  string `json:"regionPathName"`
+	InstallLocation string `json:"installLocation"`
+	State           int    `json:"state"`
+	Color           int    `json:"color"`
+	StateName       string `json:"statename"`
+}
 
+var Color = map[int]int{
+	0: 0,
+	1: 255,
+	2: 65344,
+	3: 16711680,
+}
+var StateName = map[int]string{
+	0: "初始状态",
+	1: "开门",
+	2: "关门",
+	3: "离线",
+}
 var ResourceType = map[string]string{
 	"region":                "区域",
 	"acsDevice":             "门禁控制器",

+ 107 - 1
internal/model/illuminating.go

@@ -1,6 +1,9 @@
 package model
 
-import "gorm.io/gorm"
+import (
+	"gorm.io/gorm"
+	"time"
+)
 
 type Illuminating struct {
 	gorm.Model
@@ -22,6 +25,109 @@ type EventList struct {
 	DeviceStatus int    `json:"DeviceStatus"` //设备状态
 	EventDate    string `json:"EventDate"`    //事件时间
 }
+type Login struct {
+	AccessToken string `json:"access_token"`
+	SysUser     struct {
+		SysUsersId        int    `json:"sys_users_id"`
+		UserName          string `json:"user_name"`
+		Password          string `json:"password"`
+		DisplayName       string `json:"display_name"`
+		Mobile            string `json:"mobile"`
+		Email             string `json:"email"`
+		HeadImage         string `json:"head_image"`
+		Valid             int    `json:"valid"`
+		LockStatus        int    `json:"lock_status"`
+		VerificationCode  string `json:"verification_code"`
+		CreatedDatetime   string `json:"created_datetime"`
+		LastLoginDatetime string `json:"last_login_datetime"`
+		LastLoginInfo     string `json:"last_login_info"`
+		Additional        string `json:"additional"`
+		Sex               int    `json:"sex"`
+		OrgId             int    `json:"org_id"`
+	} `json:"sys_user"`
+	RefreshToken string `json:"refresh_token"`
+	ExpiresIn    string `json:"expires_in"`
+	TokenType    string `json:"token_type"`
+	IsNew        bool   `json:"is_new"`
+	RoleType     int    `json:"role_type"`
+}
+type LoginRequst struct {
+	Authorization string `json:"authorization"`
+	ClientId      int    `json:"clientId"`
+	Mobile        string `json:"mobile"`
+	Password      string `json:"password"`
+}
+type IlluminatingStatistics struct {
+	BuildingCount   int `json:"building_count"`
+	RoomCount       int `json:"room_count"`
+	GatewayCount    int `json:"gateway_count"`
+	DeviceCount     int `json:"device_count"`
+	AlarmCount      int `json:"alarm_count"`
+	StrategyCount   int `json:"strategy_count"`
+	UserCount       int `json:"user_count"`
+	DdcCount        int `json:"ddc_count"`
+	ThermostatCount int `json:"thermostat_count"`
+}
+type IlluminatingBaseecic struct {
+	Devices []struct {
+		DevicesId                 int           `json:"devices_id"`
+		DevicesUdid               string        `json:"devices_udid"`
+		DevicesTypeId             int           `json:"devices_type_id"`
+		DevicesName               string        `json:"devices_name"`
+		DevicesReqInterval        int           `json:"devices_req_interval"`
+		DevicesLastRequestTime    time.Time     `json:"devices_last_request_time"`
+		DevicesJsonObject         string        `json:"devices_json_object"`
+		DevicesEnabled            int           `json:"devices_enabled"`
+		DevicesCreated            time.Time     `json:"devices_created"`
+		DevicesSource             string        `json:"devices_source"`
+		DevicesDescription        string        `json:"devices_description"`
+		DevicesTypeCode           string        `json:"devices_type_code"`
+		DevicesTypeName           string        `json:"devices_type_name"`
+		DevicesTypeWiredWireless  int           `json:"devices_type_wired_wireless"`
+		DevicesTypeCategoryId     int           `json:"devices_type_category_id"`
+		DevicesTypeSort           int           `json:"devices_type_sort"`
+		DevicesTypeCharging       int           `json:"devices_type_charging"`
+		CategoryId                int           `json:"category_id"`
+		CategoryClassification    string        `json:"category_classification"`
+		CategoryName              string        `json:"category_name"`
+		CategorySystematic        int           `json:"category_systematic"`
+		CategorySort              int           `json:"category_sort"`
+		GatewayId                 int           `json:"gateway_id"`
+		GatewayCode               string        `json:"gateway_code"`
+		GatewayName               string        `json:"gateway_name"`
+		GatewayDescription        string        `json:"gateway_description"`
+		GatewayOrgId              int           `json:"gateway_org_id"`
+		GatewayStatus             int           `json:"gateway_status"`
+		GatewayLastRequestTime    time.Time     `json:"gateway_last_request_time"`
+		DevicesGatewayId          int           `json:"devices_gateway_id"`
+		RoomId                    int           `json:"room_id"`
+		RoomRegionId              int           `json:"room_region_id"`
+		RoomName                  string        `json:"room_name"`
+		RoomUserId                int           `json:"room_user_id"`
+		RoomCheckinDate           string        `json:"room_checkin_date"`
+		RoomCheckoutDate          string        `json:"room_checkout_date"`
+		RoomArea                  string        `json:"room_area"`
+		RegionId                  int           `json:"region_id"`
+		RegionBuildingId          int           `json:"region_building_id"`
+		RegionName                string        `json:"region_name"`
+		RegionParentId            int           `json:"region_parent_id"`
+		OnLine                    int           `json:"on_line"`
+		RealDeviceName            string        `json:"real_device_name"`
+		DeviceDataStatus          int           `json:"device_data_status"`
+		BuildingId                int           `json:"building_id"`
+		BuildingName              string        `json:"building_name"`
+		DataFrom                  string        `json:"data_from"`
+		GatewayType               int           `json:"gateway_type"`
+		FullRegionName            string        `json:"full_region_name"`
+		DevicesReplaceStatus      int           `json:"devices_replace_status"`
+		DevicesReplaceApplyStatus int           `json:"devices_replace_apply_status"`
+		Bacnet                    []interface{} `json:"bacnet"`
+		RatioId                   int           `json:"ratio_id"`
+		Sort                      int           `json:"sort"`
+		DevicesTypeFanRatio       int           `json:"devices_type_fan_ratio"`
+	} `json:"devices"`
+	Count int `json:"count"`
+}
 
 func (m *Illuminating) TableName() string {
 	return "illuminating"

+ 3 - 0
internal/server/http.go

@@ -60,6 +60,7 @@ func NewServerHTTP(
 		Hikvision.GET("/getAcsDeviceSearch", hikvision.GetAcsDeviceSearch)
 		Hikvision.GET("/getDoorStates", hikvision.GetDoorStates)
 		Hikvision.GET("/getDoorDoControl", hikvision.GetDoorDoControl)
+		Hikvision.GET("/getAcsDoorStates", hikvision.GetAcsDoorStates)
 	}
 	//会议系统
 	Conference := r.Group("/Conference")
@@ -105,6 +106,8 @@ func NewServerHTTP(
 		ill.GET("/count", illuminating.GetIlluminating)
 		ill.GET("/getLightingstatus", illuminating.GetLightingstatus)
 		ill.POST("/updateLightingStatus", illuminating.UpdataLightingStatus)
+		ill.GET("/getStatistics", illuminating.GetStatistics)
+		ill.POST("/getBaseecic", illuminating.GetBaseecic)
 	}
 	//能源系统
 	ener := r.Group("/energy")

+ 5 - 2
internal/service/hikvision.go

@@ -27,7 +27,7 @@ type HikvisionService interface {
 	GetVisitorTypeList() (error, model.VisitorTypeList)
 	GetTurnoverSearch(pageNo, pageSize string) (error, model.TurnoverSearch)
 	GetcameraSearch(pageNo, pageSize, name string) (error, hikvisionOpenAPIGo.Result)
-	GetDoorSearch(pageNo, pageSize, name string) (error, hikvisionOpenAPIGo.Result)
+	GetDoorSearch(pageNo, pageSize, name string, doorIndexCodes []string) (error, hikvisionOpenAPIGo.Result)
 	GetDoorStates(pageNo, pageSize string, indexCodes []string) (error, hikvisionOpenAPIGo.Result)
 	GetAcsDeviceSearch(pageNo, pageSize, name string) (error, hikvisionOpenAPIGo.Result)
 	GetManualCapture(cameraIndexCode string) (error, hikvisionOpenAPIGo.Result)
@@ -516,7 +516,7 @@ func (s *hikvisionService) GetcameraSearch(pageNo, pageSize, name string) (error
 }
 
 // GetDoorSearch 获取门禁列表
-func (s *hikvisionService) GetDoorSearch(pageNo, pageSize, name string) (error, hikvisionOpenAPIGo.Result) {
+func (s *hikvisionService) GetDoorSearch(pageNo, pageSize, name string, doorIndexCodes []string) (error, hikvisionOpenAPIGo.Result) {
 	//var cameraSearch model.CameraSearch
 	m := make(map[string]any)
 	if pageNo != "" {
@@ -532,6 +532,9 @@ func (s *hikvisionService) GetDoorSearch(pageNo, pageSize, name string) (error,
 	if name != "" {
 		m["name"] = name
 	}
+	if len(doorIndexCodes) != 0 {
+		m["doorIndexCodes"] = doorIndexCodes
+	}
 	// 获取门禁状态
 	hikvision, err := s.Hikvision(s.conf.GetString("hikvision.api.doorSearch"), m, 15)
 	if err != nil {

+ 274 - 0
internal/service/illuminating.go

@@ -1,30 +1,304 @@
 package service
 
 import (
+	"bytes"
 	"city_chips/internal/model"
 	"city_chips/internal/repository"
 	"context"
+	"encoding/json"
+	"errors"
+	"fmt"
+	"github.com/spf13/viper"
+	"io"
+	"net/http"
+	"net/url"
+	"reflect"
 )
 
 type IlluminatingService interface {
 	GetIlluminating(ctx context.Context, id int64) (*model.Illuminating, error)
+	Illuminating(method, url string, body any) ([]byte, error)
+	GetStatistics() ([]byte, error)
+	GetBaseecic(currentPage, device_type_id, devices_enabled, pageSize int, query string) (model.IlluminatingBaseecic, error)
 }
 
 func NewIlluminatingService(
 	service *Service,
 	illuminatingRepository repository.IlluminatingRepository,
+	viperViper *viper.Viper,
+	client *http.Client,
 ) IlluminatingService {
+	if client == nil {
+		client = http.DefaultClient
+	}
 	return &illuminatingService{
 		Service:                service,
 		illuminatingRepository: illuminatingRepository,
+		conf:                   viperViper,
+		client:                 client,
 	}
 }
 
 type illuminatingService struct {
 	*Service
 	illuminatingRepository repository.IlluminatingRepository
+	conf                   *viper.Viper
+	client                 *http.Client
 }
 
 func (s *illuminatingService) GetIlluminating(ctx context.Context, id int64) (*model.Illuminating, error) {
 	return s.illuminatingRepository.GetIlluminating(ctx, id)
 }
+
+//	func (s *illuminatingService) Illuminating(methond, url string, body any) ([]byte, error) {
+//		urls := s.conf.GetString("illuminating.baseUrl") + s.conf.GetString("illuminating.api.login")
+//		authorization := s.conf.GetString("illuminating.authorization")
+//		clientId := s.conf.GetInt("illuminating.clientId")
+//		mobile := s.conf.GetString("illuminating.mobile")
+//		password := s.conf.GetString("illuminating.password")
+//		requst := model.LoginRequst{
+//			Authorization: authorization,
+//			ClientId:      clientId,
+//			Mobile:        mobile,
+//			Password:      password,
+//		}
+//		var login model.Login
+//		var reqBody io.Reader
+//		bodyBytes, err := json.Marshal(requst)
+//		if err != nil {
+//			return nil, err
+//		}
+//		reqBody = bytes.NewBuffer(bodyBytes)
+//		request, err := http.NewRequest("POST", urls, reqBody)
+//		if err != nil {
+//			return nil, err
+//		}
+//		client := &http.Client{}
+//		response, err := client.Do(request)
+//		defer response.Body.Close()
+//		if err != nil {
+//			return nil, err
+//		}
+//		responseBody, err := io.ReadAll(response.Body)
+//		if err != nil {
+//			return nil, err
+//		}
+//		err = json.Unmarshal(responseBody, &login)
+//		if err != nil {
+//			return nil, err
+//		}
+//		if body != nil {
+//			bodyBytes, err := json.Marshal(requst)
+//			if err != nil {
+//				return nil, err
+//			}
+//			reqBody = bytes.NewBuffer(bodyBytes)
+//		}
+//		var Bodys io.Reader
+//		if body != nil {
+//			Bytes, err := json.Marshal(body)
+//			if err != nil {
+//				return nil, err
+//			}
+//			Bodys = bytes.NewBuffer(Bytes)
+//		}
+//		newRequest, err := http.NewRequest(methond, url, Bodys)
+//		if err != nil {
+//			return nil, err
+//		}
+//		newRequest.Header.Set("Authorization", login.AccessToken)
+//		newResponse, err := client.Do(newRequest)
+//		defer newResponse.Body.Close()
+//		if err != nil {
+//			return nil, err
+//		}
+//		respBody, err := io.ReadAll(newResponse.Body)
+//		if err != nil {
+//			return nil, err
+//		}
+//		return respBody, nil
+//	}
+func (s *illuminatingService) Illuminating(method, url string, body any) ([]byte, error) {
+	login, err := s.login()
+	if err != nil {
+		return nil, err
+	}
+
+	var reqBody io.Reader
+	var finalURL = url
+
+	// 如果是 GET 请求,把 body 当作 query 参数处理
+	if method == http.MethodGet || method == "" {
+		vals, err := buildQueryParams(body)
+		if err != nil {
+			return nil, err
+		}
+		finalURL = addQueryParams(url, vals)
+	} else {
+		// 非 GET 请求才构造 body
+		reqBody, err = buildRequestBody(body)
+		if err != nil {
+			return nil, err
+		}
+	}
+
+	request, err := http.NewRequest(method, finalURL, reqBody)
+	if err != nil {
+		return nil, err
+	}
+	request.Header.Set("Authorization", login.AccessToken)
+
+	response, err := s.client.Do(request)
+	if err != nil {
+		return nil, err
+	}
+	defer response.Body.Close()
+
+	respBody, err := io.ReadAll(response.Body)
+	if err != nil {
+		return nil, err
+	}
+	return respBody, nil
+}
+
+// login 封装登录逻辑
+func (s *illuminatingService) login() (*model.Login, error) {
+	auth := s.conf.GetString("illuminating.authorization")
+	clientId := s.conf.GetInt("illuminating.clientId")
+	mobile := s.conf.GetString("illuminating.mobile")
+	password := s.conf.GetString("illuminating.password")
+
+	loginReq := model.LoginRequst{
+		Authorization: auth,
+		ClientId:      clientId,
+		Mobile:        mobile,
+		Password:      password,
+	}
+
+	bodyBytes, err := json.Marshal(loginReq)
+	if err != nil {
+		return nil, err
+	}
+
+	url := s.conf.GetString("illuminating.baseUrl") + s.conf.GetString("illuminating.api.login")
+	request, err := http.NewRequest("POST", url, bytes.NewBuffer(bodyBytes))
+	if err != nil {
+		return nil, err
+	}
+
+	response, err := s.client.Do(request)
+	if err != nil {
+		return nil, err
+	}
+	defer response.Body.Close()
+
+	respBody, err := io.ReadAll(response.Body)
+	if err != nil {
+		return nil, err
+	}
+
+	var login model.Login
+	if err := json.Unmarshal(respBody, &login); err != nil {
+		return nil, err
+	}
+
+	return &login, nil
+}
+
+// 构建请求体工具函数
+func buildRequestBody(body any) (io.Reader, error) {
+	if body == nil {
+		return nil, nil
+	}
+	bodyBytes, err := json.Marshal(body)
+	if err != nil {
+		return nil, err
+	}
+	return bytes.NewBuffer(bodyBytes), nil
+}
+func buildQueryParams(params any) (url.Values, error) {
+	vals := make(url.Values)
+
+	switch p := params.(type) {
+	case nil:
+		return vals, nil
+	case url.Values:
+		return p, nil
+	case map[string]string:
+		for k, v := range p {
+			vals.Add(k, v)
+		}
+	case map[string][]string:
+		for k, v := range p {
+			for _, vv := range v {
+				vals.Add(k, vv)
+			}
+		}
+	default:
+		// 使用反射解析结构体字段
+		t := reflect.TypeOf(p)
+		v := reflect.ValueOf(p)
+		for i := 0; i < t.NumField(); i++ {
+			field := t.Field(i)
+			value := v.Field(i).Interface()
+
+			tag := field.Tag.Get("json")
+			if tag == "" {
+				tag = field.Name
+			}
+
+			vals.Add(tag, fmt.Sprintf("%v", value))
+		}
+	}
+
+	return vals, nil
+}
+func addQueryParams(baseURL string, values url.Values) string {
+	if len(values) == 0 {
+		return baseURL
+	}
+	u, err := url.Parse(baseURL)
+	if err != nil {
+		return baseURL // 忽略错误直接返回原值
+	}
+	q := u.Query()
+	for k, vs := range values {
+		for _, v := range vs {
+			q.Add(k, v)
+		}
+	}
+	u.RawQuery = q.Encode()
+	return u.String()
+}
+
+// GetStatistics 获取统计信息
+func (s *illuminatingService) GetStatistics() ([]byte, error) {
+	urls := s.conf.GetString("illuminating.baseUrl") + s.conf.GetString("illuminating.api.statistics")
+	illuminating, err := s.Illuminating("GET", urls, nil)
+	if err != nil {
+		return nil, errors.New("获取统计信息失败")
+	}
+	return illuminating, nil
+}
+
+// GetBaseecic 获取照明监控列表
+func (s *illuminatingService) GetBaseecic(currentPage, device_type_id, devices_enabled, pageSize int, query string) (model.IlluminatingBaseecic, error) {
+	var baseecic model.IlluminatingBaseecic
+	urls := s.conf.GetString("illuminating.baseUrl") + s.conf.GetString("illuminating.api.baseecic")
+	m := make(map[string]any)
+	m["currentPage"] = currentPage
+	m["device_type_id"] = device_type_id
+	m["devices_enabled"] = devices_enabled
+	m["pageSize"] = pageSize
+	m["query"] = query
+
+	illuminating, err := s.Illuminating("POST", urls, m)
+	if err != nil {
+		return model.IlluminatingBaseecic{}, errors.New("获取统计信息失败")
+	}
+	err = json.Unmarshal(illuminating, &baseecic)
+	if err != nil {
+		return model.IlluminatingBaseecic{}, errors.New("json反序列化失败")
+	}
+	return baseecic, nil
+}

+ 5 - 0
pkg/helper/illuminating/illuminating.go

@@ -0,0 +1,5 @@
+package illuminating
+
+func Illuminating() {
+
+}