intelligentLightingService.go 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package service
  2. import (
  3. "fmt"
  4. "iot_manager_service/app/device/dao"
  5. "iot_manager_service/app/device/model"
  6. "iot_manager_service/util"
  7. "strconv"
  8. "time"
  9. )
  10. var IntelligentLightingService = new(intelligentLightingService)
  11. type intelligentLightingService struct{}
  12. func (s *intelligentLightingService) GetDetailByLight(id int) (model.RspIntelligentLightDetail, *util.Errors) {
  13. detail := model.RspIntelligentLightDetail{}
  14. lightControl, _ := LightControlService.GetOne(id)
  15. if lightControl != nil {
  16. lightControl.LampPoleName = lightControl.LampPoleName + "(" + lightControl.LampPoleSN + ")"
  17. detail.LightControlList = []dao.LightControl{*lightControl}
  18. detail.LampPoleName = lightControl.LampPoleName
  19. }
  20. detail.LightRelMap = s.GetLightRelation(id, model.RelationTypeLight)
  21. return detail, nil
  22. }
  23. func (s *intelligentLightingService) GetDetailByGroup(id int) (model.RspIntelligentLightDetailByGroup, *util.Errors) {
  24. detail := model.RspIntelligentLightDetailByGroup{}
  25. lampPoleGroup, _ := LightControlService.GetByGroupId(id)
  26. if len(lampPoleGroup) > 0 {
  27. detail.LightControlList = lampPoleGroup
  28. detail.LampPoleGroupName = lampPoleGroup[0].LampPoleName
  29. }
  30. detail.CountLampPole = LampPoleService.CountLampPole(id)
  31. detail.LightRelMap = s.GetLightRelation(id, model.RelationTypeLampPoleGroup)
  32. return detail, nil
  33. }
  34. func (s *intelligentLightingService) GetLightRelation(rId, relationType int) model.IntelligentLightSimple {
  35. detail := model.IntelligentLightSimple{}
  36. // 获取照明策略关联
  37. intelligentLight := dao.IntelligentLight{Rid: rId, RelationType: relationType}
  38. relations, _ := intelligentLight.GetByRidAndType()
  39. if len(relations) == 0 {
  40. return detail
  41. }
  42. lightId := relations[0].LightID
  43. // 获取策略详情(日期,如果是年,使用当前年起始日期)
  44. lightStrategy, _ := LightStrategyService.GetOne(lightId)
  45. if lightStrategy == nil {
  46. return detail
  47. }
  48. //获取灯控名称和SN
  49. detail.LightName = lightStrategy.LightName
  50. detail.LightSn = lightStrategy.LightSn
  51. //全年
  52. if lightStrategy.IsAllYear == model.IsYear {
  53. year := time.Now().Year()
  54. detail.EffectiveDate = fmt.Sprintf("%d-01-01 ~ %d-12-31", year, year)
  55. } else {
  56. detail.EffectiveDate = lightStrategy.StartTime + " ~ " + lightStrategy.EndTime
  57. }
  58. // 获取策略时间(每日的时间策略)
  59. timeConditions, _ := TimeConditionService.GetByLightId(lightId)
  60. for _, timeCondition := range timeConditions {
  61. if timeCondition.StartTime == "" && timeCondition.EndTime == "" {
  62. timeCondition.StartTime = "日落"
  63. timeCondition.EndTime = "日出"
  64. }
  65. detail.TimeConditionList = append(detail.TimeConditionList, model.TimeConditionSimple{
  66. Luminance: strconv.Itoa(timeCondition.Luminance) + "%",
  67. Times: timeCondition.StartTime + " ~ " + timeCondition.EndTime,
  68. })
  69. }
  70. return detail
  71. }
  72. func (s *intelligentLightingService) BatchGet(ids []int) []dao.IntelligentLight {
  73. // 创建查询实例
  74. intelligent := &dao.IntelligentLight{}
  75. conditions, err := intelligent.BatchGet(ids)
  76. if err != nil {
  77. return nil
  78. }
  79. return conditions
  80. }
  81. func (s *intelligentLightingService) List(searchValue string, current, size int) ([]dao.IntelligentLight,
  82. *util.Errors) {
  83. return nil, nil
  84. }