lightConditionService.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package service
  2. import (
  3. "iot_manager_service/app/device/dao"
  4. "iot_manager_service/util"
  5. "time"
  6. )
  7. // 灯控策略服务
  8. var LightConditionService = new(lightConditionService)
  9. type lightConditionService struct{}
  10. func (s *lightConditionService) Get(id int) (*dao.LightCondition, *util.Errors) {
  11. // 创建查询实例
  12. condition := &dao.LightCondition{
  13. ID: id,
  14. }
  15. err := condition.Get()
  16. if err != nil {
  17. return nil, util.FailResponse(err.Error(), nil)
  18. }
  19. return condition, nil
  20. }
  21. func (s *lightConditionService) BatchGet(ids []int) []dao.LightCondition {
  22. // 创建查询实例
  23. condition := &dao.LightCondition{}
  24. conditions, err := condition.BatchGet(ids)
  25. if err != nil {
  26. return nil
  27. }
  28. return conditions
  29. }
  30. func (s *lightConditionService) CreateOrUpdate(req dao.LightCondition) *util.Errors {
  31. return nil
  32. }
  33. func (s *lightConditionService) Remove(userId int64, id int) *util.Errors {
  34. // 创建查询实例
  35. device := &dao.Gateway{
  36. ID: id,
  37. IsDeleted: 1,
  38. UpdateUser: userId,
  39. UpdateTime: time.Now(),
  40. }
  41. //todo
  42. // service.gatewayService.CountRelation()
  43. //todo operation record
  44. err := device.Delete()
  45. if err != nil {
  46. return util.FailResponse(err.Error(), nil)
  47. }
  48. return nil
  49. }
  50. func (s *lightConditionService) Save(conditions []dao.LightCondition) error {
  51. condition := &dao.LightCondition{}
  52. return condition.Save(conditions)
  53. }