|
@@ -1,9 +1,12 @@
|
|
|
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)
|
|
@@ -34,17 +37,47 @@ func (s *intelligentLightingService) GetDetailByGroup(id int) (model.RspIntellig
|
|
|
return detail, nil
|
|
|
}
|
|
|
|
|
|
-func (s *intelligentLightingService) GetLightRelation(id, relationType int) model.IntelligentLightSimple {
|
|
|
+func (s *intelligentLightingService) GetLightRelation(rId, relationType int) model.IntelligentLightSimple {
|
|
|
detail := model.IntelligentLightSimple{}
|
|
|
- intelligentLight := dao.IntelligentLight{Rid: id, RelationType: relationType}
|
|
|
+
|
|
|
+ // 获取照明策略关联
|
|
|
+ intelligentLight := dao.IntelligentLight{Rid: rId, 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
|
|
|
+ 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
|
|
|
}
|
|
|
|
|
@@ -57,3 +90,8 @@ func (s *intelligentLightingService) BatchGet(ids []int) []dao.IntelligentLight
|
|
|
}
|
|
|
return conditions
|
|
|
}
|
|
|
+
|
|
|
+func (s *intelligentLightingService) List(searchValue string, current, size int) ([]dao.IntelligentLight,
|
|
|
+ *util.Errors) {
|
|
|
+ return nil, nil
|
|
|
+}
|