12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- package service
- import (
- "cold-logistics/app/admin/model"
- "cold-logistics/app/admin/service/dto"
- "cold-logistics/common/actions"
- "cold-logistics/common/global"
- "cold-logistics/common/nats/nats_server"
- "fmt"
- "gogs.baozhida.cn/zoie/OAuth-core/service"
- )
- type Device struct {
- service.Service
- }
- // GetPage 获取Device列表
- func (e *Device) GetSensorList(p *actions.DataPermission) (list []nats_server.DeviceSensor_R, count int64, err error) {
- var userObj model.SysUser
- err = e.Orm.Model(&userObj).First(&userObj, p.UserId).Error
- if err != nil {
- e.Log.Errorf("db error: %s", err)
- return list, count, global.GetFailedErr
- }
- var sn string
- // 仓管2 司机3
- if userObj.Type == 2 {
- err = e.Orm.Model(&model.Warehouse{}).Select("sn").Where("user_id = ?", userObj.Id).Scan(&sn).Error
- }
- if userObj.Type == 3 {
- err = e.Orm.Model(&model.Car{}).Select("sn").Where("user_id = ?", userObj.Id).Scan(&sn).Error
- }
- if err != nil {
- e.Log.Errorf("db error: %s", err)
- return list, count, global.GetFailedErr
- }
- if len(sn) == 0 {
- return list, count, nil
- }
- company, err := model.GetCompanyById(p.DeptId)
- if err != nil {
- e.Log.Errorf("db error: %s", err)
- return list, count, model.GetCompanyKeyErr
- }
- list, count, err = nats_server.Cold_CompanyDeviceSensor_List_ByKey(sn, company.ColdKey)
- if err != nil {
- e.Log.Errorf("db error: %s", err)
- return list, count, err
- }
- return list, count, nil
- }
- func (e *Device) GetData(c dto.DeviceGetDataReq, p *actions.DataPermission) (list []nats_server.DeviceData_R, count int64, err error) {
- T_snid := fmt.Sprintf("%s,%d|", c.T_sn, c.T_id)
- list, count, err = nats_server.Cold_ReadDeviceDataListBy_T_snid(T_snid, c.StartTime, c.EndTime, c.Page, c.PageSize)
- if err != nil {
- e.Log.Errorf("db error: %s", err)
- return list, count, err
- }
- return list, count, nil
- }
|