device.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package service
  2. import (
  3. "cold-delivery/app/admin/model"
  4. "cold-delivery/app/admin/service/dto"
  5. "cold-delivery/common/actions"
  6. "cold-delivery/common/nats/nats_server"
  7. "fmt"
  8. "gogs.baozhida.cn/zoie/OAuth-core/service"
  9. "strings"
  10. )
  11. type Device struct {
  12. service.Service
  13. }
  14. // GetPage 获取Device列表
  15. func (e *Device) GetDeviceSensorList(c *dto.DeviceSensorGetPageReq, p *actions.DataPermission) (list []nats_server.DeviceSensor_R, count int64, err error) {
  16. if len(c.Sn) == 0 {
  17. return list, count, nil
  18. }
  19. company, err := model.GetCompanyById(p.DeptId)
  20. if err != nil {
  21. e.Log.Errorf("db error: %s", err)
  22. return list, count, model.GetCompanyKeyErr
  23. }
  24. list, count, err = nats_server.Cold_CompanyDeviceSensor_List_ByKey(c.Sn, company.ColdKey)
  25. if err != nil {
  26. e.Log.Errorf("db error: %s", err)
  27. return list, count, err
  28. }
  29. return list, count, nil
  30. }
  31. func (e *Device) GetData(c *dto.DeviceSensorGetDataReq, p *actions.DataPermission) (list []nats_server.DeviceData_R, count int64, err error) {
  32. T_snid := ""
  33. ids := strings.Split(strings.Trim(c.T_ids, ","), ",")
  34. for _, id := range ids {
  35. T_snid += fmt.Sprintf("%s,%s|", c.T_sn, id)
  36. }
  37. list, count, err = nats_server.Cold_ReadDeviceDataListBy_T_snid(T_snid, c.StartTime, c.EndTime, c.GetPageIndex(), c.GetPageSize())
  38. if err != nil {
  39. e.Log.Errorf("db error: %s", err)
  40. return list, count, err
  41. }
  42. return list, count, nil
  43. }