12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- package service
- import (
- "fmt"
- "iot_manager_service/app/device/dao"
- "iot_manager_service/app/device/model"
- "iot_manager_service/util"
- "strconv"
- "time"
- )
- 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(rId, relationType int) model.IntelligentLightSimple {
- detail := model.IntelligentLightSimple{}
- // 获取照明策略关联
- intelligentLight := dao.IntelligentLight{Rid: rId, RelationType: relationType}
- relations, _ := intelligentLight.GetByRidAndType()
- if len(relations) == 0 {
- return detail
- }
- lightId := relations[0].LightID
- // 获取策略详情(日期,如果是年,使用当前年起始日期)
- lightStrategy, _ := LightStrategyService.GetOne(lightId)
- if lightStrategy == nil {
- return detail
- }
- //获取灯控名称和SN
- detail.LightName = lightStrategy.LightName
- detail.LightSn = lightStrategy.LightSn
- //全年
- if lightStrategy.IsAllYear == model.IsYear {
- year := time.Now().Year()
- detail.EffectiveDate = fmt.Sprintf("%d-01-01 ~ %d-12-31", year, year)
- } else {
- detail.EffectiveDate = lightStrategy.StartTime + " ~ " + lightStrategy.EndTime
- }
- // 获取策略时间(每日的时间策略)
- timeConditions, _ := TimeConditionService.GetByLightId(lightId)
- for _, timeCondition := range timeConditions {
- if timeCondition.StartTime == "" && timeCondition.EndTime == "" {
- timeCondition.StartTime = "日落"
- timeCondition.EndTime = "日出"
- }
- detail.TimeConditionList = append(detail.TimeConditionList, model.TimeConditionSimple{
- Luminance: strconv.Itoa(timeCondition.Luminance) + "%",
- Times: timeCondition.StartTime + " ~ " + timeCondition.EndTime,
- })
- }
- 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
- }
- func (s *intelligentLightingService) List(searchValue string, current, size int) ([]dao.IntelligentLight,
- *util.Errors) {
- return nil, nil
- }
|