device.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. package dto
  2. import (
  3. "IotAdmin/app/iot/models"
  4. "IotAdmin/common/dto"
  5. comModels "IotAdmin/common/models"
  6. "IotAdmin/iot/constant"
  7. iotStruct "IotAdmin/iot/struct"
  8. "time"
  9. )
  10. type IotDeviceGetPageReq struct {
  11. dto.Pagination `search:"-"`
  12. Type int `form:"type" search:"type:exact;column:type;table:iot_device" comment:"设备类型"`
  13. BeginTime string `form:"beginTime" search:"type:gte;column:created_at;table:iot_device" comment:"创建时间"`
  14. EndTime string `form:"endTime" search:"type:lte;column:created_at;table:iot_device" comment:"创建时间"`
  15. IotDeviceOrder
  16. }
  17. type IotDeviceOrder struct {
  18. GroupId string `form:"groupIdOrder" search:"type:order;column:group_id;table:iot_device"`
  19. Sn string `form:"snOrder" search:"type:order;column:sn;table:iot_device"`
  20. Name string `form:"nameOrder" search:"type:order;column:name;table:iot_device"`
  21. Type int `form:"typeOrder" search:"type:order;column:type;table:iot_device"`
  22. }
  23. func (m *IotDeviceGetPageReq) GetNeedSearch() interface{} {
  24. return *m
  25. }
  26. // IotDeviceInsertReq 添加设备请求参数
  27. type IotDeviceInsertReq struct {
  28. Id int `json:"-" comment:"Id"` // Id
  29. ParentId int `json:"parentId" comment:"父ID"`
  30. GroupId int `json:"groupId" comment:"分组ID"`
  31. Sn string `json:"sn" comment:"设备编码"`
  32. Name string `json:"name" comment:"设备名称"`
  33. Type int `json:"type" comment:"设备类型 1:网关 2:表计"`
  34. Mode int `json:"mode" comment:"设备模式 1:下发指令查询 2:表计主动上报"`
  35. Cycle int `json:"cycle" comment:"上报周期"`
  36. Description string `json:"description" comment:"设备描述"`
  37. Protocol string `json:"protocol" comment:"表计协议"`
  38. Address int `json:"address" comment:"表计地址"`
  39. ReportConfig *[]iotStruct.ReportConfig `json:"reportConfigs" comment:"上报配置"`
  40. comModels.ControlBy
  41. }
  42. func (s *IotDeviceInsertReq) Generate(model *models.IotDevice) {
  43. if s.Id == 0 {
  44. model.Model = comModels.Model{Id: s.Id}
  45. }
  46. model.ParentId = s.ParentId
  47. model.GroupId = s.GroupId
  48. model.Sn = s.Sn
  49. model.Name = s.Name
  50. model.Type = s.Type
  51. model.Mode = s.Mode
  52. model.Cycle = s.Cycle
  53. model.Description = s.Description
  54. model.Protocol = s.Protocol
  55. model.Address = s.Address
  56. model.CreateBy = s.CreateBy // 添加这而,需要记录是被谁创建的
  57. model.Dsn = ""
  58. if model.Type == constant.IotDeviceTypeMeter {
  59. model.Dsn = BuildDsnString(s.ReportConfig)
  60. }
  61. }
  62. func (s *IotDeviceInsertReq) GetId() interface{} {
  63. return s.Id
  64. }
  65. // IotDeviceUpdateReq 修改设备请求参数
  66. type IotDeviceUpdateReq struct {
  67. Id int `uri:"id" comment:"Id"` // Id
  68. ParentId int `json:"parentId" comment:"父ID"`
  69. GroupId int `json:"groupId" comment:"分组ID"`
  70. Sn string `json:"sn" comment:"设备编码"`
  71. Name string `json:"name" comment:"设备名称"`
  72. Type int `json:"type" comment:"设备类型 1:网关 2:表计"`
  73. Mode int `json:"mode" comment:"设备模式 1:下发指令查询 2:表计主动上报"`
  74. Cycle int `json:"cycle" comment:"上报周期"`
  75. Description string `json:"description" comment:"设备描述"`
  76. Protocol string `json:"protocol" comment:"表计协议"`
  77. Address int `json:"address" comment:"表计地址"`
  78. ReportConfig *[]iotStruct.ReportConfig `json:"reportConfigs" comment:"上报配置"`
  79. comModels.ControlBy
  80. }
  81. func (s *IotDeviceUpdateReq) Generate(model *models.IotDevice) {
  82. if s.Id == 0 {
  83. model.Model = comModels.Model{Id: s.Id}
  84. }
  85. model.ParentId = s.ParentId
  86. model.GroupId = s.GroupId
  87. model.Sn = s.Sn
  88. model.Name = s.Name
  89. model.Type = s.Type
  90. model.Mode = s.Mode
  91. model.Cycle = s.Cycle
  92. model.Description = s.Description
  93. model.Protocol = s.Protocol
  94. model.Address = s.Address
  95. model.UpdateBy = s.UpdateBy // 添加这而,需要记录是被谁更新的
  96. model.Dsn = ""
  97. if model.Type == constant.IotDeviceTypeMeter {
  98. model.Dsn = BuildDsnString(s.ReportConfig)
  99. }
  100. }
  101. func (s *IotDeviceUpdateReq) GetId() interface{} {
  102. return s.Id
  103. }
  104. func BuildDsnString(configs *[]iotStruct.ReportConfig) string {
  105. str := ""
  106. for i, cfg := range *configs {
  107. if i > 0 {
  108. str += constant.DsnSplitString
  109. }
  110. str += cfg.Host + constant.DsnChildSplitString + cfg.Protocol + constant.DsnChildSplitString + cfg.ST + constant.DsnChildSplitString + cfg.MN
  111. if cfg.User != "" {
  112. str += constant.DsnChildSplitString + cfg.User + constant.DsnChildSplitString + cfg.Pwd
  113. }
  114. }
  115. return str
  116. }
  117. // IotDeviceGetReq 获取设备请求参数
  118. type IotDeviceGetReq struct {
  119. Id int `uri:"id"`
  120. }
  121. func (s *IotDeviceGetReq) GetId() interface{} {
  122. return s.Id
  123. }
  124. // IotDeviceDeleteReq 删除设备请求参数
  125. type IotDeviceDeleteReq struct {
  126. Ids []int `json:"ids"`
  127. }
  128. func (s *IotDeviceDeleteReq) GetId() interface{} {
  129. return s.Ids
  130. }
  131. // IotDeviceResp 获取设备响应参数
  132. type IotDeviceResp struct {
  133. Id int `uri:"id" comment:"Id"` // Id
  134. ParentId int `json:"parentId" comment:"父ID"`
  135. GroupId int `json:"groupId" comment:"分组ID"`
  136. Sn string `json:"sn" comment:"设备编码"`
  137. Name string `json:"name" comment:"设备名称"`
  138. Type int `json:"type" comment:"设备类型 1:网关 2:表计"`
  139. Mode int `json:"mode" comment:"设备模式 1:下发指令查询 2:表计主动上报"`
  140. Cycle int `json:"cycle" comment:"上报周期"`
  141. Description string `json:"description" comment:"设备描述"`
  142. Protocol string `json:"protocol" comment:"表计协议"`
  143. Address int `json:"address" comment:"表计地址"`
  144. CreateBy int `json:"createBy" comment:"创建者"`
  145. CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
  146. }
  147. func (s *IotDeviceResp) Generate(model *models.IotDevice) {
  148. s.Id = model.Id
  149. s.ParentId = model.ParentId
  150. s.GroupId = model.GroupId
  151. s.Sn = model.Sn
  152. s.Name = model.Name
  153. s.Type = model.Type
  154. s.Mode = model.Mode
  155. s.Cycle = model.Cycle
  156. s.Description = model.Description
  157. s.Protocol = model.Protocol
  158. s.Address = model.Address
  159. s.CreateBy = model.CreateBy
  160. s.CreatedAt = model.CreatedAt
  161. }