device.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package service
  2. import (
  3. "cold-logistics/app/admin/model"
  4. "cold-logistics/app/admin/service/dto"
  5. "cold-logistics/common/actions"
  6. "cold-logistics/common/global"
  7. "cold-logistics/common/nats/nats_server"
  8. "fmt"
  9. "gogs.baozhida.cn/zoie/OAuth-core/service"
  10. )
  11. type Device struct {
  12. service.Service
  13. }
  14. // GetPage 获取Device列表
  15. func (e *Device) GetSensorList(p *actions.DataPermission) (list []nats_server.DeviceSensor_R, count int64, err error) {
  16. var userObj model.SysUser
  17. err = e.Orm.Model(&userObj).First(&userObj, p.UserId).Error
  18. if err != nil {
  19. e.Log.Errorf("db error: %s", err)
  20. return list, count, global.GetFailedErr
  21. }
  22. var sn string
  23. // 仓管2 司机3
  24. if userObj.Type == 2 {
  25. err = e.Orm.Model(&model.Warehouse{}).Select("sn").Where("user_id = ?", userObj.Id).Scan(&sn).Error
  26. }
  27. if userObj.Type == 3 {
  28. err = e.Orm.Model(&model.Car{}).Select("sn").Where("user_id = ?", userObj.Id).Scan(&sn).Error
  29. }
  30. if err != nil {
  31. e.Log.Errorf("db error: %s", err)
  32. return list, count, global.GetFailedErr
  33. }
  34. if len(sn) == 0 {
  35. return list, count, nil
  36. }
  37. company, err := model.GetCompanyById(p.DeptId)
  38. if err != nil {
  39. e.Log.Errorf("db error: %s", err)
  40. return list, count, model.GetCompanyKeyErr
  41. }
  42. list, count, err = nats_server.Cold_CompanyDeviceSensor_List_ByKey(sn, company.ColdKey)
  43. if err != nil {
  44. e.Log.Errorf("db error: %s", err)
  45. return list, count, err
  46. }
  47. return list, count, nil
  48. }
  49. func (e *Device) GetData(c dto.DeviceGetDataReq, p *actions.DataPermission) (list []nats_server.DeviceData_R, count int64, err error) {
  50. T_snid := fmt.Sprintf("%s,%d|", c.T_sn, c.T_id)
  51. list, count, err = nats_server.Cold_ReadDeviceDataListBy_T_snid(T_snid, c.StartTime, c.EndTime, c.Page, c.PageSize)
  52. if err != nil {
  53. e.Log.Errorf("db error: %s", err)
  54. return list, count, err
  55. }
  56. return list, count, nil
  57. }