timeConditionService.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package service
  2. import (
  3. "iot_manager_service/app/device/dao"
  4. "iot_manager_service/util/common"
  5. "iot_manager_service/util/logger"
  6. )
  7. // 灯控策略-时间策略服务
  8. var TimeConditionService = new(timeConditionService)
  9. type timeConditionService struct{}
  10. func (s *timeConditionService) Get(id int) (*dao.TimeCondition, *common.Errors) {
  11. // 创建查询实例
  12. condition := &dao.TimeCondition{
  13. ID: id,
  14. }
  15. err := condition.Get()
  16. if err != nil {
  17. return nil, common.FailResponse(err.Error(), nil)
  18. }
  19. return condition, nil
  20. }
  21. func (s *timeConditionService) Save(conditions []dao.TimeCondition) error {
  22. for _, condition := range conditions {
  23. if condition.ID == 0 {
  24. condition.Save()
  25. } else {
  26. condition.Update()
  27. }
  28. }
  29. return nil
  30. }
  31. func (s *timeConditionService) GetByLightId(id int) []dao.TimeCondition {
  32. // 创建查询实例
  33. condition := &dao.TimeCondition{
  34. LightId: id,
  35. }
  36. conditions, err := condition.GetByLightId()
  37. if err != nil {
  38. logger.Logger.Errorf("GetByLightIds err = %v \n", err)
  39. return nil
  40. }
  41. return conditions
  42. }
  43. func (s *timeConditionService) GetAll() ([]dao.TimeCondition, *common.Errors) {
  44. // 创建查询实例
  45. condition := &dao.TimeCondition{}
  46. conditions, err := condition.GetAll()
  47. if err != nil {
  48. return nil, common.FailResponse(err.Error(), nil)
  49. }
  50. return conditions, nil
  51. }