main.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. demeter web
  5. name:main.py 主界面相关api
  6. author:rabin
  7. """
  8. from __load__ import *
  9. class index_path(Load):
  10. """
  11. @api {get} / 获取首页信息
  12. @apiVersion 1.0.0
  13. @apiName getIndex
  14. @apiGroup Common
  15. @apiSuccess {Object[]} setting 基本信息
  16. @apiSuccess {String} setting.name 站点名
  17. @apiSuccess {Number} setting.farm 当前的农场ID
  18. @apiSuccess {Object[]} farm 农场基本信息
  19. @apiSuccess {String} farm.name 农场名
  20. @apiSuccess {Object[]} gateway 网关信息(环境监测)
  21. @apiSuccess {String} gateway.name 网关名称
  22. @apiSuccess {String} gateway.id 网关ID
  23. @apiErrorExample 操作成功
  24. {"status": 1, "msg": "yes", "code": 0, "data": {"farm": {"info": "3123fdf", "master_name": "31232", "tel": "323", "name": "\u9ed8\u8ba4\u56ed\u533a", "pic": "http://192.168.15.10:8087/upload/2017/09/27/5c3d27b95a0375cd5c0eab03c61a494a.jpg", "cdate": 1506496822, "gateway": "", "master_pic": "", "state": true, "location": "", "address": "312", "id": 1}, "gateway": [{"stat": false, "pic": null, "hardware_id": 10086, "farm_id": 1, "cdate": 1506496123, "state": true, "camera": null, "id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "name": "\u9ed8\u8ba4\u7f51\u5173"}], "setting": {"farm": 1, "user": "229cfd36-9399-5599-b2b5-c53174c3de19", "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "base": {}, "msg": 0}}
  25. @apiErrorExample 操作失败
  26. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  27. """
  28. @auth
  29. @Web.setting
  30. def get(self):
  31. # 获取网关
  32. self.data['gateway'] = self.service('common').list('device_gateway', search={'farm_id': Demeter.config['setting']['farm']})
  33. # 获取农场信息
  34. self.data['farm'] = self.service('common').one('farm', id=Demeter.config['setting']['farm'])
  35. # 获取消息数量
  36. self.data['msg'] = len(self.service('common').list('msg', search={'status':False, "farm_id":self.data['setting']['farm']}, limit='0,100'))
  37. if self.data['msg'] > 99:
  38. self.data['msg'] = str(99) + '+'
  39. self.data['pic'] = []
  40. pic = self.service('common').list('device_info', state=True, search={'hardware_type':6, 'farm_id':Demeter.config['setting']['farm']})
  41. if pic:
  42. for key, value in enumerate(pic):
  43. pic[key]['cdates'] = Demeter.date(value['cdate'])
  44. self.data['pic'] = pic
  45. self.out('yes', self.data)