| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- package service
- import (
- "iot_manager_service/app/device/dao"
- "iot_manager_service/app/device/model"
- "iot_manager_service/util"
- )
- var IntelligentLightingService = new(intelligentLightingService)
- type intelligentLightingService struct{}
- func (s *intelligentLightingService) GetDetailByLight(id int) (model.RspIntelligentLightDetail, *util.Errors) {
- detail := model.RspIntelligentLightDetail{}
- lightControl, _ := LightControlService.GetOne(id)
- if lightControl != nil {
- lightControl.LampPoleName = lightControl.LampPoleName + "(" + lightControl.LampPoleSN + ")"
- detail.LightControlList = []dao.LightControl{*lightControl}
- detail.LampPoleName = lightControl.LampPoleName
- }
- detail.LightRelMap = s.GetLightRelation(id, model.RelationTypeLight)
- return detail, nil
- }
- func (s *intelligentLightingService) GetDetailByGroup(id int) (model.RspIntelligentLightDetailByGroup, *util.Errors) {
- detail := model.RspIntelligentLightDetailByGroup{}
- lampPoleGroup, _ := LightControlService.GetByGroupId(id)
- if len(lampPoleGroup) > 0 {
- detail.LightControlList = lampPoleGroup
- detail.LampPoleGroupName = lampPoleGroup[0].LampPoleName
- }
- detail.CountLampPole = LampPoleService.CountLampPole(id)
- detail.LightRelMap = s.GetLightRelation(id, model.RelationTypeLampPoleGroup)
- return detail, nil
- }
- func (s *intelligentLightingService) GetLightRelation(id, relationType int) model.IntelligentLightSimple {
- detail := model.IntelligentLightSimple{}
- intelligentLight := dao.IntelligentLight{Rid: id, RelationType: relationType}
- relations, _ := intelligentLight.GetByRidAndType()
- if len(relations) > 0 {
- light, _ := LightControlService.Get(relations[0].LightID)
- if light != nil {
- detail.LightName = light.Name
- detail.LightSn = light.SN
- }
- }
- return detail
- }
- func (s *intelligentLightingService) BatchGet(ids []int) []dao.IntelligentLight {
- // 创建查询实例
- intelligent := &dao.IntelligentLight{}
- conditions, err := intelligent.BatchGet(ids)
- if err != nil {
- return nil
- }
- return conditions
- }
|