12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package handler
- import (
- "city_chips/internal/model"
- "city_chips/internal/service"
- "city_chips/pkg/helper/resp"
- "fmt"
- "github.com/spf13/viper"
- "math/rand"
- "time"
- "github.com/gin-gonic/gin"
- )
- type IntelligentBuildingControlHandler struct {
- *Handler
- intelligentBuildingControlService service.IntelligentBuildingControlService
- conf *viper.Viper
- }
- func NewIntelligentBuildingControlHandler(
- handler *Handler,
- intelligentBuildingControlService service.IntelligentBuildingControlService,
- conf *viper.Viper,
- ) *IntelligentBuildingControlHandler {
- return &IntelligentBuildingControlHandler{
- Handler: handler,
- intelligentBuildingControlService: intelligentBuildingControlService,
- conf: conf,
- }
- }
- func (h *IntelligentBuildingControlHandler) GetIntelligentBuildingControl(ctx *gin.Context) {
- m := make(map[string]any)
- var device []model.AlarmList
- for i := 0; i < 10; i++ {
- name := fmt.Sprintf("设备%v", i+1)
- location := fmt.Sprintf("位置%v", i+1)
- alarm := fmt.Sprintf("报警时间%v", i+1)
- inspection := model.AlarmList{
- Id: i + 1,
- Name: name,
- State: rand.Intn(2),
- Date: time.Now().Format("2006-01-02 15:04:05"),
- Location: location,
- AlarmContent: alarm,
- }
- device = append(device, inspection)
- }
- m["DeviceCount"] = rand.Intn(100) //设备总数
- m["StopState"] = rand.Intn(100) //停止状态
- m["RunState"] = rand.Intn(100) //运行状态
- m["FaultState"] = rand.Intn(1000) //故障状态
- m["DeviceList"] = device //设备列表
- resp.HandleSuccess(ctx, m)
- }
|