Browse Source

温控面板

huangyan 2 weeks ago
parent
commit
b379bfe59f

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

@@ -57,7 +57,7 @@ func NewWire(viperViper *viper.Viper, logger *log.Logger) (*gin.Engine, func(),
 	energyService := service.NewEnergyService(serviceService, energyRepository, viperViper, client)
 	energyHandler := handler.NewEnergyHandler(handlerHandler, energyService, viperViper)
 	intelligentBuildingControlRepository := repository.NewIntelligentBuildingControlRepository(repositoryRepository)
-	intelligentBuildingControlService := service.NewIntelligentBuildingControlService(serviceService, intelligentBuildingControlRepository)
+	intelligentBuildingControlService := service.NewIntelligentBuildingControlService(serviceService, intelligentBuildingControlRepository, viperViper)
 	intelligentBuildingControlHandler := handler.NewIntelligentBuildingControlHandler(handlerHandler, intelligentBuildingControlService, viperViper)
 	temperatureRepository := repository.NewTemperatureRepository(repositoryRepository)
 	temperatureService := service.NewTemperatureService(serviceService, temperatureRepository, viperViper, client)

+ 2 - 1
config/local.yml

@@ -52,6 +52,7 @@ hikvision:
     doorStates: "/artemis/api/nms/v1/online/acs_device/get" #查询门禁设备状态接口
     acsdoorstates: "/artemis/api/acs/v1/door/states" #门禁点状态查询
     eventLogs: "/artemis/api/scpms/v2/eventLogs/searches" #入侵报警事件日志查询
+    iasDeviceSearch: "/api/resource/v2/iasDevice/search" #查询入侵报警主机列表v2
     regionsRoot: "/artemis/api/resource/v1/regions/root" #获取区域树接口
     regionsSubRegions: "/artemis/api/resource/v2/regions/subRegions" #根据区域编号获取下一级区域列表v2
     vqdList: "/artemis/api/nms/v1/vqd/list" #根据监控点列表查询视频质量诊断结果
@@ -94,7 +95,7 @@ Modbus:
   url: "tcp://"
 #楼控系统
 obix:
-  baseUrl: "https://10.1.201.253/obix/config"
+  baseUrl: "https://182.43.247.65:8098/obix/config"
   username: "obix"
   password: "Obix123456"
 #照明 系统

+ 35 - 13
internal/handler/hikvision.go

@@ -320,19 +320,28 @@ func (h *HikvisionHandler) GetAccess(ctx *gin.Context) {
 		devices = append(devices, inspection)
 		alarmList = append(alarmList, alarm)
 	}
-
-	m["DeviceCount"] = rand.Intn(500) //设备总数
-	m["Online"] = rand.Intn(100)      //在线
-	m["Abnormal"] = rand.Intn(100)    //异常
-	m["Fault"] = rand.Intn(100)       //故障
-	m["Offline"] = rand.Intn(100)     //离线
-	m["Attendance"] = rand.Intn(100)  //出勤率
-	m["Invasio1"] = invasio1          //入侵事件1
-	m["Invasio2"] = invasio2          //入侵事件2
-	m["DailyTotal"] = DailyTotal      //每日统计
-	m["Cumulative"] = Cumulative      //累计统计
-	m["AlarmList"] = alarmList        //实时告警与通知
-	m["devices"] = devices            //设备列表
+	err, result := h.hikvisionService.GetAcsDeviceSearch("1", "1000", "")
+	if err != nil {
+		resp.HandleError(ctx, 1201, "获取设备列表失败", err)
+		return
+	}
+	err, resource := h.hikvisionService.DeviceResource("door")
+	if err != nil {
+		resp.HandleError(ctx, 1201, "获取设备资源失败", err)
+		return
+	}
+	m["DeviceCount"] = resource.Data.Total //设备总数
+	m["Online"] = rand.Intn(100)           //在线
+	m["Abnormal"] = rand.Intn(100)         //异常
+	m["Fault"] = rand.Intn(100)            //故障
+	m["Offline"] = rand.Intn(100)          //离线
+	m["Attendance"] = rand.Intn(100)       //出勤率
+	m["Invasio1"] = invasio1               //入侵事件1
+	m["Invasio2"] = invasio2               //入侵事件2
+	m["DailyTotal"] = DailyTotal           //每日统计
+	m["Cumulative"] = Cumulative           //累计统计
+	m["AlarmList"] = alarmList             //实时告警与通知
+	m["devices"] = result.Data             //设备列表
 	resp.HandleSuccess(ctx, m)
 }
 
@@ -829,3 +838,16 @@ func (h *HikvisionHandler) GetAcsDoorStates(ctx *gin.Context) {
 		}
 	}
 }
+
+// GetIasDeviceSearch 查询入侵报警主机列表v2
+func (h *HikvisionHandler) GetIasDeviceSearch(ctx *gin.Context) {
+	pageNo := ctx.Query("pageNo")
+	pageSize := ctx.Query("pageSize")
+	name := ctx.Query("name")
+	err, search := h.hikvisionService.GetIasDeviceSearch(pageNo, pageSize, name)
+	if err != nil {
+		resp.HandleError(ctx, 1203, "控制门禁失败", err.Error())
+		return
+	}
+	resp.HandleSuccess(ctx, search.Data)
+}

+ 136 - 62
internal/handler/intelligentbuildingcontrol.go

@@ -10,7 +10,7 @@ import (
 	"go.uber.org/zap"
 	"math/rand"
 	"regexp"
-	"sync"
+	"strconv"
 	"time"
 
 	"github.com/spf13/viper"
@@ -76,8 +76,10 @@ func (h *IntelligentBuildingControlHandler) GetPoint(ctx *gin.Context) {
 	floor := ctx.PostForm("floor")
 	section := ctx.PostForm("section")
 	device_name := ctx.PostForm("deviceName")
+	pageNum, err := strconv.Atoi(ctx.PostForm("pageNum"))
+	pageSize, err := strconv.Atoi(ctx.PostForm("pageSize"))
 	conds := make(map[string]any)
-	var pointType []model.PointType
+	//var pointType []model.PointType
 	if pointName != "" {
 		conds["point_name"] = pointName
 	}
@@ -97,55 +99,124 @@ func (h *IntelligentBuildingControlHandler) GetPoint(ctx *gin.Context) {
 		conds["device_name"] = device_name
 	}
 
-	baseUrl := h.conf.GetString("obix.baseUrl")
-	points, err := h.intelligentBuildingControlService.GetPoint(conds)
+	//baseUrl := h.conf.GetString("obix.baseUrl")
+	point, total, err := h.intelligentBuildingControlService.GetPoint(conds, pageNum, pageSize)
 	if err != nil {
 		resp.HandleError(ctx, 1201, "查询点位失败", nil)
 		return
 	}
+	//
+	//var wg sync.WaitGroup
+	//var mutex sync.Mutex // 保护切片并发写入
+	//m := make(map[string]string)
+	//sem := make(chan struct{}, 10) // 最大并发数为10
+	//
+	//for _, v := range *points {
+	//	url := baseUrl + v.FullPath
+	//	wg.Add(1)
+	//	sem <- struct{}{}
+	//	go func(url string, pointName string) {
+	//		defer func() {
+	//			<-sem
+	//			wg.Done()
+	//		}()
+	//
+	//		request, err := obix.SendSecureRequest(url, h.conf.GetString("obix.username"), h.conf.GetString("obix.password"))
+	//		if err != nil {
+	//			h.logger.Error("发送请求失败", zap.Error(err))
+	//			return
+	//		}
+	//
+	//		re := regexp.MustCompile(`val="([^"]+)"`)
+	//		matches := re.FindStringSubmatch(request)
+	//
+	//		mutex.Lock()
+	//		defer mutex.Unlock()
+	//
+	//		if len(matches) > 1 {
+	//			s := model.PointName[pointName]
+	//			m[s] = matches[1]
+	//			pointType = append(pointType, model.PointType{Type: m})
+	//		} else {
+	//			h.logger.Warn("未找到 val 值", zap.String("url", url))
+	//		}
+	//	}(url, v.PointName)
+	//}
+	//
+	//// 等待所有协程完成
+	//wg.Wait()
 
-	var wg sync.WaitGroup
-	var mutex sync.Mutex // 保护切片并发写入
-	m := make(map[string]string)
-	sem := make(chan struct{}, 10) // 最大并发数为10
+	// 统一返回结果
+	resp.PageHandleSuccess(ctx, point, total, pageNum, pageSize)
+}
 
+// GetGetPoint 获取点位设备数据
+func (h *IntelligentBuildingControlHandler) GetGetPoint(ctx *gin.Context) {
+	pointName := ctx.Query("pointName")
+	deviceType := ctx.Query("deviceType")
+	building := ctx.Query("building")
+	floor := ctx.Query("floor")
+	section := ctx.Query("section")
+	device_name := ctx.Query("deviceName")
+	conds := make(map[string]any)
+	if pointName != "" {
+		conds["point_name"] = pointName
+	}
+	if deviceType != "" {
+		conds["device_type"] = deviceType
+	}
+	if building != "" {
+		conds["building"] = building
+	}
+	if floor != "" {
+		conds["floor"] = floor
+	}
+	if section != "" {
+		conds["section"] = section
+	}
+	if device_name != "" {
+		conds["device_name"] = device_name
+	}
+	baseUrl := h.conf.GetString("obix.baseUrl")
+	m := make(map[string]any)
+	points, _, err := h.intelligentBuildingControlService.GetPoint(conds, 1, 100)
+	if err != nil {
+		resp.HandleError(ctx, 1201, "查询点位失败", nil)
+	}
 	for _, v := range *points {
 		url := baseUrl + v.FullPath
-		wg.Add(1)
-		sem <- struct{}{}
-		go func(url string, pointName string) {
-			defer func() {
-				<-sem
-				wg.Done()
-			}()
-
-			request, err := obix.SendSecureRequest(url, h.conf.GetString("obix.username"), h.conf.GetString("obix.password"))
-			if err != nil {
-				h.logger.Error("发送请求失败", zap.Error(err))
-				return
-			}
-
-			re := regexp.MustCompile(`val="([^"]+)"`)
-			matches := re.FindStringSubmatch(request)
-
-			mutex.Lock()
-			defer mutex.Unlock()
-
-			if len(matches) > 1 {
-				s := model.PointName[pointName]
-				m[s] = matches[1]
-				pointType = append(pointType, model.PointType{Type: m})
-			} else {
-				h.logger.Warn("未找到 val 值", zap.String("url", url))
+		request, err := obix.SendSecureRequest(url, h.conf.GetString("obix.username"), h.conf.GetString("obix.password"))
+		if err != nil {
+			h.logger.Error("发送请求失败", zap.Error(err))
+			return
+		}
+		re := regexp.MustCompile(`val="([^"]+)"`)
+		matches := re.FindStringSubmatch(request)
+		if len(matches) > 1 {
+			s := model.PointName[v.PointName]
+			if s != "" {
+				value := matches[1]
+				switch val := obix.DetectType(value).(type) {
+				case int:
+					m[s] = val
+				case float64:
+					m[s] = fmt.Sprintf("%.2f", val) // 保留两位小数输出
+				case bool:
+					if val {
+						m[s] = "是"
+					} else {
+						m[s] = "否"
+					}
+				default:
+					m[s] = value // 原样输出字符串
+				}
 			}
-		}(url, v.PointName)
+		} else {
+			h.logger.Warn("未找到 val 值", zap.String("url", url))
+		}
 	}
+	resp.HandleSuccess(ctx, m)
 
-	// 等待所有协程完成
-	wg.Wait()
-
-	// 统一返回结果
-	resp.HandleSuccess(ctx, pointType)
 }
 func (h *IntelligentBuildingControlHandler) GetGetPointSSE(ctx *gin.Context) {
 	// 设置响应头
@@ -198,7 +269,7 @@ func (h *IntelligentBuildingControlHandler) GetGetPointSSE(ctx *gin.Context) {
 			return
 		default:
 			m := make(map[string]any)
-			points, err := h.intelligentBuildingControlService.GetPoint(conds)
+			points, _, err := h.intelligentBuildingControlService.GetPoint(conds, 1, 100)
 			if err != nil {
 				resp.HandleError(ctx, 1201, "查询点位失败", nil)
 				conn = false
@@ -251,27 +322,6 @@ func (h *IntelligentBuildingControlHandler) GetGetPointSSE(ctx *gin.Context) {
 
 // GetPointType 获取点位类型
 func (h *IntelligentBuildingControlHandler) GetPointType(ctx *gin.Context) {
-	var tempS1 model.NumericPoint
-	//	var xmlData = `<?xml version="1.0" encoding="UTF-8"?>
-	//<real val="27.49811553955078" display="27.50 °C {ok}" unit="obix:units/celsius">
-	//	<str name="facets" val="units=u:celsius;°C;(K);+273.15;" display="units=°C"/>
-	//	<ref name="proxyExt" display="analogInput:1:Present Value:-1:REAL"/>
-	//	<real name="out" val="27.49811553955078" display="27.50 °C {ok}"/>
-	//	<ref name="tag" display="Point Tag"/>
-	//</real>`
-	//err2 := ctx.ShouldBindXML(&tempS1)
-	//err2 := xml.Unmarshal([]byte(xmlData), &tempS1)
-	//if err2 != nil {
-	//	resp.HandleError(ctx, 1201, "绑定XML失败", nil)
-	//	return
-	//}
-	request, err2 := obix.SendSecureRequest("https://10.1.201.253/obix/config/Drivers/BacnetNetwork/DDC_9B_1F_1a/points/PAU/PAU_9B_1F_1/PAUAlr1", h.conf.GetString("obix.username"), h.conf.GetString("obix.password"))
-	if err2 != nil {
-		resp.HandleError(ctx, 1201, "发送请求失败", nil)
-		return
-	}
-	fmt.Println(request, "===========")
-	fmt.Println(tempS1)
 	points, err := h.intelligentBuildingControlService.GetPointType()
 	if err != nil {
 		resp.HandleError(ctx, 1201, "查询点位类型失败", nil)
@@ -279,6 +329,8 @@ func (h *IntelligentBuildingControlHandler) GetPointType(ctx *gin.Context) {
 	}
 	resp.HandleSuccess(ctx, points)
 }
+
+// GetDeviceType 获取设备类型
 func (h *IntelligentBuildingControlHandler) GetDeviceType(ctx *gin.Context) {
 	points, err := h.intelligentBuildingControlService.DeviceType()
 	if err != nil {
@@ -291,3 +343,25 @@ func (h *IntelligentBuildingControlHandler) GetDeviceType(ctx *gin.Context) {
 	}
 	resp.HandleSuccess(ctx, m)
 }
+
+// GetDevices 获取设备列表
+func (h *IntelligentBuildingControlHandler) GetDevices(ctx *gin.Context) {
+	conds := make(map[string]any)
+	pageNum, err := strconv.Atoi(ctx.Query("pageNum"))
+	pageSize, err := strconv.Atoi(ctx.Query("pageSize"))
+	device_type := ctx.Query("device_type")
+	if len(device_type) == 0 || device_type == "" {
+		resp.HandleError(ctx, 1201, "设备类型不能为空", nil)
+	}
+	conds["device_type"] = device_type
+	if err != nil {
+		resp.HandleError(ctx, 1201, "获取分页参数失败", nil)
+		return
+	}
+	devices, total, err := h.intelligentBuildingControlService.GetDevices(conds, pageNum, pageSize)
+	if err != nil {
+		resp.HandleError(ctx, 1201, "查询设备类型失败", nil)
+		return
+	}
+	resp.PageHandleSuccess(ctx, devices, total, pageNum, pageSize)
+}

+ 57 - 3
internal/repository/intelligentbuildingcontrol.go

@@ -8,10 +8,12 @@ import (
 
 type IntelligentBuildingControlRepository interface {
 	GetIntelligentBuildingControl(ctx context.Context, id int64) (*model.IntelligentBuildingControl, error)
-	GetPoint(conds map[string]any) (*[]model.Point, error)
+	GetPoint(conds map[string]any, pageNum, pageSize int) (*[]model.Point, int64, error)
 	GetPointType() ([]string, error)
 	DeviceType() ([]string, error)
 	DeviceCount() (int64, error)
+	GetPopintList(conds map[string]any, pageNum, pageSize int) ([]string, int64, error)
+	GetPointAll(conds map[string]any) (*[]model.Point, error)
 }
 
 func NewIntelligentBuildingControlRepository(
@@ -62,9 +64,61 @@ func (r *intelligentBuildingControlRepository) GetIntelligentBuildingControl(ctx
 }
 
 // GetPoint 根据点位数据获取点位信息
-func (r *intelligentBuildingControlRepository) GetPoint(conds map[string]any) (*[]model.Point, error) {
+func (r *intelligentBuildingControlRepository) GetPoint(conds map[string]any, pageNum, pageSize int) (*[]model.Point, int64, error) {
 	var points []model.Point
-	points, err := helper.QueryByConditions[model.Point](r.db, conds)
+	points, total, err := helper.QueryByConditions[model.Point](r.db, conds, pageNum, pageSize)
+	if err != nil {
+		return &points, 0, err
+	}
+	return &points, total, nil
+}
+
+//	func (r *intelligentBuildingControlRepository) GetPopintList() ([]string, error) {
+//		var names []string
+//		err := r.db.Model(&model.Point{}).Select("device_name").Group("device_name").Find(&names).Error
+//		if err != nil {
+//			return nil, err
+//		}
+//		return names, nil
+//	}
+func (r *intelligentBuildingControlRepository) GetPopintList(conds map[string]any, pageNum, pageSize int) ([]string, int64, error) {
+	var names []string
+	var total int64
+
+	db := r.db.Model(&model.Point{})
+
+	// 应用查询条件
+	for k, v := range conds {
+		if v != nil {
+			db = db.Where(k+" = ?", v)
+		}
+	}
+
+	// 查询总数(去重后的)
+	err := db.Select("device_name").Group("device_name").Count(&total).Error
+	if err != nil {
+		return nil, 0, err
+	}
+
+	// 分页查询
+	err = db.Select("device_name").
+		Group("device_name").
+		Order("device_name ASC").
+		Offset((pageNum - 1) * pageSize).
+		Limit(pageSize).
+		Find(&names).Error
+
+	if err != nil {
+		return nil, 0, err
+	}
+
+	return names, total, nil
+}
+
+// GetPointAll 获取所有点位表
+func (r *intelligentBuildingControlRepository) GetPointAll(conds map[string]any) (*[]model.Point, error) {
+	var points []model.Point
+	points, err := helper.QueryByCondition[model.Point](r.db, conds)
 	if err != nil {
 		return &points, err
 	}

+ 2 - 0
internal/server/http.go

@@ -141,6 +141,8 @@ func NewServerHTTP(
 		inte.GET("/pointSSE", intell.GetGetPointSSE)
 		inte.GET("/pointType", intell.GetPointType)
 		inte.GET("/deviceType", intell.GetDeviceType)
+		inte.GET("/getPoint", intell.GetGetPoint)
+		inte.GET("/getDevices", intell.GetDevices)
 	}
 	//温控
 	temper := r.Group("/temperature")

+ 29 - 0
internal/service/hikvision.go

@@ -34,6 +34,7 @@ type HikvisionService interface {
 	GetAcsDoorStates(indexCodes []string) (error, hikvisionOpenAPIGo.Result)
 	GetDoorDoControl(doorIndexCodes []string, controlType int) (error, hikvisionOpenAPIGo.Result)
 	GetEventLogs(pageNo, pageSize, srcType, startTime, endTime, srcName string, eventType int) (error, hikvisionOpenAPIGo.Result)
+	GetIasDeviceSearch(pageNo, pageSize, name string) (error, hikvisionOpenAPIGo.Result)
 }
 
 func NewHikvisionService(service *Service, hikvisionRepository repository.HikvisionRepository, conf *viper.Viper) HikvisionService {
@@ -698,3 +699,31 @@ func (s *hikvisionService) GetEventLogs(pageNo, pageSize, srcType, startTime, en
 	}
 	return nil, hikvision
 }
+
+// GetIasDeviceSearch 查询入侵报警主机列表v2
+func (s *hikvisionService) GetIasDeviceSearch(pageNo, pageSize, name string) (error, hikvisionOpenAPIGo.Result) {
+	//var cameraSearch model.CameraSearch
+	m := make(map[string]any)
+	if pageNo != "" {
+		m["pageNo"] = pageNo
+	} else {
+		m["pageNo"] = "1"
+	}
+	if pageSize != "" {
+		m["pageSize"] = pageSize
+	} else {
+		m["pageSize"] = s.conf.GetString("hikvision.pageSize")
+	}
+	if name != "" {
+		m["name"] = name
+	}
+	// 获取门禁状态
+	hikvision, err := s.Hikvision(s.conf.GetString("hikvision.api.iasDeviceSearch"), m, 15)
+	if err != nil {
+		return errors.New("获取入侵报警主机列表失败"), hikvisionOpenAPIGo.Result{}
+	}
+	if hikvision.Code != "0" {
+		return errors.New("获取入侵报警主机列表失败"), hikvisionOpenAPIGo.Result{}
+	}
+	return nil, hikvision
+}

+ 103 - 5
internal/service/intelligentbuildingcontrol.go

@@ -3,30 +3,41 @@ package service
 import (
 	"city_chips/internal/model"
 	"city_chips/internal/repository"
+	"city_chips/pkg/helper/obix"
 	"context"
+	"fmt"
+	"github.com/pkg/errors"
+	"github.com/spf13/viper"
+	"go.uber.org/zap"
+	"regexp"
+	"sync"
 )
 
 type IntelligentBuildingControlService interface {
 	GetIntelligentBuildingControl(ctx context.Context, id int64) (*model.IntelligentBuildingControl, error)
-	GetPoint(conds map[string]any) (*[]model.Point, error)
+	GetPoint(conds map[string]any, pageNum, pageSize int) (*[]model.Point, int64, error)
 	GetPointType() ([]string, error)
 	DeviceType() ([]string, error)
 	DeviceCount() (int64, error)
+	GetDevices(conds map[string]any, pageNum, pageSize int) (map[string]any, int64, error)
 }
 
 func NewIntelligentBuildingControlService(
 	service *Service,
 	intelligentBuildingControlRepository repository.IntelligentBuildingControlRepository,
+	conf *viper.Viper,
 ) IntelligentBuildingControlService {
 	return &intelligentBuildingControlService{
 		Service:                              service,
 		intelligentBuildingControlRepository: intelligentBuildingControlRepository,
+		conf:                                 conf,
 	}
 }
 
 type intelligentBuildingControlService struct {
 	*Service
 	intelligentBuildingControlRepository repository.IntelligentBuildingControlRepository
+	conf                                 *viper.Viper
 }
 
 // DeviceCount 获取设备总数
@@ -59,14 +70,101 @@ func (s *intelligentBuildingControlService) GetPointType() ([]string, error) {
 }
 
 // GetPoint 获取点位列表
-func (s *intelligentBuildingControlService) GetPoint(conds map[string]any) (*[]model.Point, error) {
-	points, err := s.intelligentBuildingControlRepository.GetPoint(conds)
+func (s *intelligentBuildingControlService) GetPoint(conds map[string]any, pageNum, pageSize int) (*[]model.Point, int64, error) {
+	points, total, err := s.intelligentBuildingControlRepository.GetPoint(conds, pageNum, pageSize)
 	if err != nil {
-		return &[]model.Point{}, err
+		return &[]model.Point{}, 0, err
 	}
-	return points, err
+	return points, total, err
 }
 
 func (s *intelligentBuildingControlService) GetIntelligentBuildingControl(ctx context.Context, id int64) (*model.IntelligentBuildingControl, error) {
 	return s.intelligentBuildingControlRepository.GetIntelligentBuildingControl(ctx, id)
 }
+
+// GetDevices 获取设备列表(支持设备 & 点位双重并发)
+func (s *intelligentBuildingControlService) GetDevices(conds map[string]any, pageNum, pageSize int) (map[string]any, int64, error) {
+	var total int64
+	baseUrl := s.conf.GetString("obix.baseUrl")
+	device := make(map[string]any)
+	list, total, err := s.intelligentBuildingControlRepository.GetPopintList(conds, pageNum, pageSize)
+	if err != nil {
+		return nil, 0, errors.New("获取设备列表失败")
+	}
+
+	var wg sync.WaitGroup
+	var mu sync.Mutex // 保护 device 的写入
+	var all *[]model.Point
+	for _, v := range list {
+		wg.Add(1)
+		go func(deviceName string) {
+			defer wg.Done()
+
+			all, err = s.intelligentBuildingControlRepository.GetPointAll(map[string]any{"device_name": deviceName})
+			if err != nil {
+				s.logger.Error("获取设备点位列表失败", zap.String("device", deviceName), zap.Error(err))
+				return
+			}
+
+			m := make(map[string]any)
+			var innerWg sync.WaitGroup
+			var innerMu sync.Mutex // 保护 m 的写入
+
+			for _, vl := range *all {
+				innerWg.Add(1)
+				go func(vl model.Point) {
+					defer innerWg.Done()
+
+					url := baseUrl + vl.FullPath
+					request, err := obix.SendSecureRequest(url, s.conf.GetString("obix.username"), s.conf.GetString("obix.password"))
+					if err != nil {
+						s.logger.Error("发送请求失败", zap.String("url", url), zap.Error(err))
+						return
+					}
+
+					re := regexp.MustCompile(`val="([^"]+)"`)
+					matches := re.FindStringSubmatch(request)
+					if len(matches) > 1 {
+						key := model.PointName[vl.PointName]
+						if key != "" {
+							value := matches[1]
+							switch val := obix.DetectType(value).(type) {
+							case int:
+								innerMu.Lock()
+								m[key] = val
+								innerMu.Unlock()
+							case float64:
+								innerMu.Lock()
+								m[key] = fmt.Sprintf("%.2f", val)
+								innerMu.Unlock()
+							case bool:
+								innerMu.Lock()
+								if val {
+									m[key] = "是"
+								} else {
+									m[key] = "否"
+								}
+								innerMu.Unlock()
+							default:
+								innerMu.Lock()
+								m[key] = value
+								innerMu.Unlock()
+							}
+						}
+					} else {
+						s.logger.Warn("未找到 val 值", zap.String("url", url))
+					}
+				}(vl)
+			}
+
+			innerWg.Wait()
+
+			mu.Lock()
+			device[deviceName] = m
+			mu.Unlock()
+		}(v)
+	}
+
+	wg.Wait()
+	return device, total, nil
+}

+ 16 - 2
pkg/helper/dbutils/dbutils.go

@@ -2,9 +2,23 @@ package helper
 
 import "gorm.io/gorm"
 
-//通用多条查询
-func QueryByConditions[T any](db *gorm.DB, conditions map[string]interface{}) ([]T, error) {
+// QueryByConditions 通用多条查询
+func QueryByCondition[T any](db *gorm.DB, conditions map[string]interface{}) ([]T, error) {
 	var results []T
 	tx := db.Where(conditions).Find(&results)
 	return results, tx.Error
 }
+
+// QueryByConditions 分页查询
+func QueryByConditions[T any](db *gorm.DB, conditions map[string]interface{}, pageNum, pageSize int) ([]T, int64, error) {
+	var results []T
+	var total int64
+
+	tx := db.Where(conditions).Model(&results).Count(&total)
+	if tx.Error != nil {
+		return nil, 0, tx.Error
+	}
+
+	tx = db.Where(conditions).Offset((pageNum - 1) * pageSize).Limit(pageSize).Find(&results)
+	return results, total, tx.Error
+}

+ 15 - 0
pkg/helper/resp/resp.go

@@ -10,6 +10,14 @@ type response struct {
 	Message string      `json:"message"`
 	Data    interface{} `json:"data"`
 }
+type pageResponse struct {
+	Code     int         `json:"code"`
+	Message  string      `json:"message"`
+	PageNum  int         `json:"pageNum"`
+	PageSize int         `json:"pageSize"`
+	Total    int64       `json:"total"`
+	Data     interface{} `json:"data"`
+}
 
 func HandleSuccess(ctx *gin.Context, data interface{}) {
 	if data == nil {
@@ -18,6 +26,13 @@ func HandleSuccess(ctx *gin.Context, data interface{}) {
 	resp := response{Code: 200, Message: "success", Data: data}
 	ctx.JSON(http.StatusOK, resp)
 }
+func PageHandleSuccess(ctx *gin.Context, data interface{}, total int64, pageNum, pageSize int) {
+	if data == nil {
+		data = map[string]string{}
+	}
+	resp := pageResponse{Code: 200, Message: "success", Data: data, PageNum: pageNum, PageSize: pageSize, Total: total}
+	ctx.JSON(http.StatusOK, resp)
+}
 
 func HandleError(ctx *gin.Context, code int, message string, data interface{}) {
 	if data == nil {