common.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. package model
  2. import (
  3. "encoding/json"
  4. "net"
  5. "server/dao"
  6. "sync"
  7. )
  8. var (
  9. InductanceTCP net.Listener
  10. Mutex sync.Mutex
  11. ConnectionMap1 = &sync.Map{}
  12. )
  13. type QueueData struct {
  14. Ip string `json:"ip"`
  15. Value []byte `json:"value"`
  16. }
  17. type RegionRequest struct {
  18. RegionId int `json:"regionId"`
  19. State int `json:"state"`
  20. }
  21. type DevicesRequest struct {
  22. IDs []int `json:"ids"`
  23. State int `json:"state"`
  24. }
  25. // 蓝牙 ----------------------------------------------------------------------------------
  26. type MsgRoot struct {
  27. ID string `json:"id"`
  28. Method string `json:"method"` // 对应 /thing/event/xxx/post
  29. Params MsgParams `json:"params"`
  30. Version string `json:"version"`
  31. }
  32. // MsgParams 外层 params 节点
  33. type MsgParams struct {
  34. Time int64 `json:"time"` // 毫秒时间戳
  35. Value json.RawMessage `json:"value"` // 动态内容,RawMessage 延迟解析
  36. }
  37. // HeartbeatValue 心跳上报 value
  38. type HeartbeatValue struct {
  39. DeviceName string `json:"device_name"` // 网关名称
  40. Area string `json:"area"` // 区号
  41. Number string `json:"number"` // 灯号
  42. Cluster string `json:"cluster"` // 组号(已偏移)
  43. UUID string `json:"uuid"` // 设备唯一ID(业务主键)
  44. UpdatedTime string `json:"updated_time"` // 上报时间戳
  45. }
  46. type BeaconValue struct {
  47. Area string `json:"area"`
  48. Number string `json:"number"`
  49. Cluster string `json:"cluster"`
  50. UUID string `json:"uuid"`
  51. Version string `json:"version"`
  52. DeviceName string `json:"device_name"`
  53. Type string `json:"type"`
  54. }
  55. // TriggerValue 人体/传感器触发上报
  56. type TriggerValue struct {
  57. DeviceName string `json:"device_name"`
  58. Area string `json:"area"`
  59. Number string `json:"number"`
  60. UUID string `json:"uuid"`
  61. TrigTime int64 `json:"trig_time"` // 触发时间(毫秒)
  62. }
  63. // AlsValue 照度上报
  64. type AlsValue struct {
  65. DeviceName string `json:"device_name"`
  66. Area string `json:"area"`
  67. Number string `json:"number"`
  68. UUID string `json:"uuid"`
  69. Lux int `json:"lux"` // 照度值(lux)
  70. UpdatedTime string `json:"updated_time"`
  71. }
  72. // ConsumptionValue 能耗上报
  73. type ConsumptionValue struct {
  74. DeviceName string `json:"device_name"`
  75. Area string `json:"area"`
  76. Number string `json:"number"`
  77. UUID string `json:"uuid"`
  78. AcquisitionTime int64 `json:"acquisition_time"`
  79. TimeDur int64 `json:"time_dur"` // 通电时长(秒)
  80. SensorDur int64 `json:"sensor_dur"` // 感应时长
  81. EnergyDur int64 `json:"energy_dur"` // 等效能耗时长
  82. Power float64 `json:"power"` // 单灯功率
  83. }
  84. // CurrentValue 实时亮度、色温
  85. type CurrentValue struct {
  86. DeviceName string `json:"device_name"`
  87. Area string `json:"area"`
  88. Number string `json:"number"`
  89. UUID string `json:"uuid"`
  90. CurrentBright int `json:"current_bright"` // 当前亮度
  91. CurrentCct int `json:"current_cct"` // 当前色温
  92. UpdatedTime string `json:"updated_time"`
  93. }
  94. // SceneValue 情景模式上报
  95. type SceneValue struct {
  96. DeviceName string `json:"device_name"`
  97. Area string `json:"area"`
  98. Number string `json:"number"`
  99. UUID string `json:"uuid"`
  100. SceneNo int `json:"scene_no"` // 情景号 1~31
  101. HighBright string `json:"high_bright"` // 有人亮度
  102. StandbyBright string `json:"standby_bright"` // 无人亮度
  103. CctBright string `json:"cct_bright"` // 色温
  104. DelayTime string `json:"delay_time"` // 一段延时
  105. DelayTime2 string `json:"delay_time2"` // 二段延时
  106. LightMode string `json:"light_mode"` // 亮灯模式
  107. DelayMode string `json:"delay_mode"` // 感应模式
  108. AlsControlMode string `json:"alscontrol_mode"` // 恒照度模式
  109. SceneValidity string `json:"scene_validity"` // 情景是否有效
  110. }
  111. // TempHumValue 温湿度传感器上报
  112. type TempHumValue struct {
  113. DeviceName string `json:"device_name"`
  114. Area string `json:"area"`
  115. Number string `json:"number"`
  116. UUID string `json:"uuid"`
  117. Temperature int `json:"temperature"` // 单位 0.1℃
  118. Humidity int `json:"humidity"` // 单位 0.1%RH
  119. UpdatedTime string `json:"updated_time"`
  120. }
  121. // AcStatusValue 空调状态上报
  122. type AcStatusValue struct {
  123. DeviceName string `json:"device_name"`
  124. Area string `json:"area"`
  125. Number string `json:"number"`
  126. UUID string `json:"uuid"`
  127. AcStatus string `json:"ac_status"` // On/Off
  128. AcMode string `json:"ac_mode"` // Cold/Warm/...
  129. AcSleep string `json:"ac_sleep"` // 睡眠模式
  130. AcTemperature string `json:"ac_temperature"`
  131. AcWindSpeed string `json:"ac_wind_speed"`
  132. AcChildLock string `json:"ac_child_lock"`
  133. }
  134. // MeterCurrentValue 电表电流
  135. type MeterCurrentValue struct {
  136. DeviceName string `json:"device_name"`
  137. Area string `json:"area"`
  138. Cluster string `json:"cluster"`
  139. Number string `json:"number"`
  140. UUID string `json:"uuid"`
  141. Addr int `json:"Addr"` // 电表地址
  142. Ia float64 `json:"Ia"`
  143. Ib float64 `json:"Ic"`
  144. Ic float64 `json:"Ib"`
  145. }
  146. // MeterVoltageValue 电表电压
  147. type MeterVoltageValue struct {
  148. DeviceName string `json:"device_name"`
  149. Area string `json:"area"`
  150. Cluster string `json:"cluster"`
  151. Number string `json:"number"`
  152. UUID string `json:"uuid"`
  153. Addr int `json:"Addr"`
  154. Ua float64 `json:"Ua"`
  155. Ub float64 `json:"Ub"`
  156. Uc float64 `json:"Uc"`
  157. }
  158. // MeterPowerValue 电表功率
  159. type MeterPowerValue struct {
  160. DeviceName string `json:"device_name"`
  161. Area string `json:"area"`
  162. Cluster string `json:"cluster"`
  163. Number string `json:"number"`
  164. UUID string `json:"uuid"`
  165. Addr int `json:"addr"`
  166. Pt float64 `json:"Pt"` // 有功功率
  167. Qt float64 `json:"Qt"` // 无功功率
  168. PFt float64 `json:"PFt"` // 功率因数
  169. Freq int `json:"Freq"` // 频率
  170. }
  171. type DashboardRequest struct {
  172. GatewayID uint `json:"gatewayId" form:"gatewayId"`
  173. Year int `json:"year" form:"year"`
  174. Week int `json:"week" form:"week"`
  175. }
  176. // 趋势图数据结构
  177. type TrendData struct {
  178. Date string `json:"date"`
  179. Actual float64 `json:"actual"`
  180. Theory float64 `json:"theory"`
  181. }
  182. type AvailableWeek struct {
  183. Year int `json:"year"`
  184. Week int `json:"week"`
  185. Label string `json:"label"`
  186. }
  187. type DashboardResponse struct {
  188. Gateways []dao.Gateway `json:"gateways"`
  189. AvailableWeeks []AvailableWeek `json:"available_weeks"`
  190. CurrentGatewayID uint `json:"currentGatewayId"`
  191. TotalLuminaires int `json:"total_luminaires"`
  192. ElectricityConsumption float64 `json:"total_electricity_consumption_this_week"`
  193. CarbonReduction float64 `json:"carbon_emission_reduction"`
  194. CarbonReductionRatio float64 `json:"carbon_emission_reduction_ratio"`
  195. WarningCount int `json:"warning_count"`
  196. LoopDeviceCount int `json:"loop_device_count"`
  197. Devices []dao.Device `json:"devices"`
  198. GatewayCount int `json:"gateway_count"`
  199. Trends []TrendData `json:"trends"`
  200. YearOnYearTrends []TrendData `json:"year_on_year_trends"`
  201. }