12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package service
- import (
- "fmt"
- "iot_manager_service/app/device/dao"
- "iot_manager_service/util"
- )
- // 灯控策略-时间策略服务
- var TimeConditionService = new(timeConditionService)
- type timeConditionService struct{}
- func (s *timeConditionService) Get(id int) (*dao.TimeCondition, *util.Errors) {
- // 创建查询实例
- condition := &dao.TimeCondition{
- ID: id,
- }
- err := condition.Get()
- if err != nil {
- return nil, util.FailResponse(err.Error(), nil)
- }
- return condition, nil
- }
- func (s *timeConditionService) Save(conditions []dao.TimeCondition) error {
- for _, condition := range conditions {
- if condition.ID == 0 {
- condition.Save()
- } else {
- condition.Update()
- }
- }
- return nil
- }
- func (s *timeConditionService) GetByLightId(id int) []dao.TimeCondition {
- // 创建查询实例
- condition := &dao.TimeCondition{
- LightId: id,
- }
- conditions, err := condition.GetByLightId()
- if err != nil {
- fmt.Printf("GetByLightIds err = %v \n", err)
- return nil
- }
- return conditions
- }
- func (s *timeConditionService) GetAll() ([]dao.TimeCondition, *util.Errors) {
- // 创建查询实例
- condition := &dao.TimeCondition{}
- conditions, err := condition.GetAll()
- if err != nil {
- return nil, util.FailResponse(err.Error(), nil)
- }
- return conditions, nil
- }
|