1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package admin
- import (
- "server/dao"
- "server/model/common/request"
- "server/model/common/response"
- )
- type DeviceService struct{}
- func (ds *DeviceService) QueryAllDevices() ([]dao.Device, error) {
- return dao.QueryAllDevices()
- }
- func (ds *DeviceService) QueryDeviceList(info request.DeviceSearch) ([]dao.Device, int64, error) {
- limit := info.PageInfo.PageSize
- offset := info.PageInfo.PageSize * (info.PageInfo.Page - 1)
- return dao.QueryDeviceList(info.Sn, info.Name, info.Genre, limit, offset)
- }
- func (ds *DeviceService) GenerateDeviceFile(id int) (data response.DeviceFileData, err error) {
- devices, err := dao.QueryDeviceByTunnelId(id)
- if err != nil {
- return data, err
- }
- for _, d := range devices {
- if d.DeviceGenre.Type == "环境设备" {
- envDev := response.EnvDev{
- Sn: d.Sn,
- Name: d.Name,
- Address: d.Address,
- TaskTime: d.TaskTime,
- WaitTime: d.WaitTime,
- SerialId: d.SerialId,
- }
- data.EnvDev = append(data.EnvDev, envDev)
- } else if d.DeviceGenre.Type == "开关设备" {
- lampDev := response.LampDev{
- Sn: d.Sn,
- Name: d.Name,
- Address: d.Address,
- RadarId: d.RadarId,
- SerialId: d.SerialId,
- }
- data.LampDev = append(data.LampDev, lampDev)
- }
- }
- return data, nil
- }
- func (ds *DeviceService) CreateDevice(device dao.Device) error {
- return device.CreateDevice()
- }
- func (ds *DeviceService) UpdateDevice(device dao.Device) error {
- return device.UpdateDevice()
- }
- func (ds *DeviceService) DeleteDevice(id int) error {
- return dao.DeleteDevice(id)
- }
|