device.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package admin
  2. import (
  3. "server/dao"
  4. "server/model/common/request"
  5. "server/model/common/response"
  6. )
  7. type DeviceService struct{}
  8. func (ds *DeviceService) QueryAllDevices() ([]dao.Device, error) {
  9. return dao.QueryAllDevices()
  10. }
  11. func (ds *DeviceService) QueryDeviceList(info request.DeviceSearch) ([]dao.Device, int64, error) {
  12. limit := info.PageInfo.PageSize
  13. offset := info.PageInfo.PageSize * (info.PageInfo.Page - 1)
  14. return dao.QueryDeviceList(info.Sn, info.Name, info.Genre, limit, offset)
  15. }
  16. func (ds *DeviceService) GenerateDeviceFile(id int) (data response.DeviceFileData, err error) {
  17. devices, err := dao.QueryDeviceByTunnelId(id)
  18. if err != nil {
  19. return data, err
  20. }
  21. for _, d := range devices {
  22. if d.DeviceGenre.Type == "环境设备" {
  23. envDev := response.EnvDev{
  24. Sn: d.Sn,
  25. Name: d.Name,
  26. Address: d.Address,
  27. TaskTime: d.TaskTime,
  28. WaitTime: d.WaitTime,
  29. SerialId: d.SerialId,
  30. }
  31. data.EnvDev = append(data.EnvDev, envDev)
  32. } else if d.DeviceGenre.Type == "开关设备" {
  33. lampDev := response.LampDev{
  34. Sn: d.Sn,
  35. Name: d.Name,
  36. Address: d.Address,
  37. RadarId: d.RadarId,
  38. SerialId: d.SerialId,
  39. }
  40. data.LampDev = append(data.LampDev, lampDev)
  41. }
  42. }
  43. return data, nil
  44. }
  45. func (ds *DeviceService) CreateDevice(device dao.Device) error {
  46. return device.CreateDevice()
  47. }
  48. func (ds *DeviceService) UpdateDevice(device dao.Device) error {
  49. return device.UpdateDevice()
  50. }
  51. func (ds *DeviceService) DeleteDevice(id int) error {
  52. return dao.DeleteDevice(id)
  53. }