device.py 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. demeter web
  5. name:device.py 设备相关
  6. author:rabin
  7. """
  8. from __load__ import *
  9. class index_path(Load):
  10. """
  11. @api {get} /device 获取网关首页信息
  12. @apiVersion 1.0.0
  13. @apiName getDevice
  14. @apiGroup Device
  15. @apiParam {String} id 网关id
  16. @apiSuccess {Object[]} setting 基本信息
  17. @apiSuccess {String} setting.name 站点名
  18. @apiSuccess {Number} setting.farm 当前的农场ID
  19. @apiSuccess {Object[]} info 网关状态基本信息
  20. @apiSuccess {String} info.id 网关ID
  21. @apiSuccess {String} info.name 网关名称
  22. @apiSuccess {Bool} info.status 网关状态
  23. @apiSuccess {Number} info.power 电量
  24. @apiSuccess {Object[]} status 设备状态
  25. @apiSuccess {Number} status.id 设备ID
  26. @apiSuccess {String} status.name 设备名称
  27. @apiSuccess {String} status.show 显示的数据
  28. @apiSuccess {String} status.unit 设备的单位
  29. @apiSuccess {Number} status.max 设备的上限
  30. @apiSuccess {Number} status.min 设备的下限
  31. @apiSuccess {Bool} status.status 设备状态true在线
  32. @apiSuccess {Object[]} device 设备数据
  33. @apiSuccess {Number} device.id 设备ID
  34. @apiSuccess {String} device.name 设备名称
  35. @apiSuccess {String} device.show 显示的数据
  36. @apiSuccess {String} device.unit 设备的单位
  37. @apiSuccess {Number} device.max 设备的上限
  38. @apiSuccess {Number} device.min 设备的下限
  39. @apiSuccess {Bool} device.status 设备状态true在线
  40. @apiSuccess {Object[]} pic 图像数据
  41. @apiSuccess {Number} pic.id 图片ID
  42. @apiSuccess {String} pic.name 图片名称
  43. @apiSuccess {String} pic.show 图片地址
  44. @apiSuccess {String} pic.cdates 采集时间
  45. @apiSuccess {String} pic.cdate 采集时间戳
  46. @apiErrorExample 操作成功
  47. {"status": 1, "msg": "yes", "code": 0, "data": {"info": {"stat": "", "pic": "", "hardware_id": 10086, "farm_id": 1, "cdate": 1508815174, "state": true, "camera": "", "id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "name": "\u9ed8\u8ba4\u7f51\u5173"}, "status": [{"gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "status": true, "hardware_type": 5, "hardware_id": 10086, "cxnum": null, "name": "\u7f51\u5173\u72b6\u6001", "type_id": 0, "max": null, "farm_id": 1, "udate": 1508815174, "cdate": 1508816395, "value": "1", "operdate": null, "state": true, "cxdate": null, "min": null, "exp": null, "inorder": 0, "id": "4fabff1e-47a0-5775-9bdc-fe9ace585b82", "oper": false, "cxtype": null}, {"gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "status": false, "hardware_type": 4, "hardware_id": 10086, "cxnum": null, "name": "\u7535\u6e90\u72b6\u6001", "type_id": 8, "max": null, "farm_id": 1, "udate": 1508815174, "cdate": 1508815174, "value": "2", "operdate": null, "state": true, "cxdate": null, "min": null, "exp": null, "inorder": 0, "id": "2592b560-9c76-5849-94b0-5306d04ec120", "oper": false, "cxtype": null}], "pic": {"oper": false, "hardware_type": 6, "farm_id": 1, "type_id": 0, "operdate": null, "id": "6e78c955-e3be-5edb-b0c2-e6c5c88fd95a", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": null, "hardware_id": 222, "cdates": "2017-10-24 03:36:05", "state": true, "inorder": 1, "cxtype": null, "status": false, "max": null, "cxnum": null, "cdate": 1508816165, "name": "\u6444\u50cf\u59341\u53f7", "cxdate": null, "udate": 1508816132, "value": "http://xinnongbaohe.oss-cn-shanghai.aliyuncs.com/cp/bjbg1/1.jpg", "exp": null}, "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": {}, "device": [{"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 2, "operdate": null, "id": "cda160d2-75de-531e-aded-47687a343aed", "unit": "%RH", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100011, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816395, "name": "\u6e7f\u5ea6#100011", "cxdate": null, "udate": 1508815230, "value": "46.88", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 3, "operdate": null, "id": "98612a58-366e-545b-874c-365f907c5fab", "unit": "LUX", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100028, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816395, "name": "\u5149\u7167#100028", "cxdate": null, "udate": 1508815235, "value": "6260.9", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 1, "operdate": null, "id": "8af915ee-8ebf-5440-9884-0bd9897df4ca", "unit": "\u2103", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100005, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816395, "name": "\u6e29\u5ea6#100005", "cxdate": null, "udate": 1508815229, "value": "20.49", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 2, "operdate": null, "id": "37125978-ceb0-5fd0-9241-77e07b608dee", "unit": "%RH", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100016, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816394, "name": "\u6e7f\u5ea6#100016", "cxdate": null, "udate": 1508815226, "value": "58.57", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 3, "operdate": null, "id": "76607038-af6c-53ce-a9c8-7744ddaf3735", "unit": "LUX", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100026, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816394, "name": "\u5149\u7167#100026", "cxdate": null, "udate": 1508815227, "value": "10983.25", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 1, "operdate": null, "id": "485e905b-3163-57c4-8b98-0508e3957466", "unit": "\u2103", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100002, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816394, "name": "\u6e29\u5ea6#100002", "cxdate": null, "udate": 1508815239, "value": "24.73", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 1, "operdate": null, "id": "f759c5bf-b15d-5279-bf4c-19d4f67b1e29", "unit": "\u2103", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100007, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816393, "name": "\u6e29\u5ea6#100007", "cxdate": null, "udate": 1508815224, "value": "-18.47", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 2, "operdate": null, "id": "60965dab-9332-50f6-851b-15f39a5f41b5", "unit": "%RH", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100017, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816393, "name": "\u6e7f\u5ea6#100017", "cxdate": null, "udate": 1508815243, "value": "76.92", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 3, "operdate": null, "id": "2c9e16e4-e17f-5c8d-bdea-b259ee460574", "unit": "LUX", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100029, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816393, "name": "\u5149\u7167#100029", "cxdate": null, "udate": 1508815223, "value": "6717.61", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 3, "operdate": null, "id": "3fbbe124-152e-52a3-8bd6-bc7f90a2551e", "unit": "LUX", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100020, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816392, "name": "\u5149\u7167#100020", "cxdate": null, "udate": 1508815225, "value": "3326.56", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 2, "operdate": null, "id": "5fac900a-bc71-5418-bf27-e412230b19df", "unit": "%RH", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100019, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816392, "name": "\u6e7f\u5ea6#100019", "cxdate": null, "udate": 1508815228, "value": "54.16", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 1, "operdate": null, "id": "40470b37-8c01-57fd-9f7d-57745669a4b0", "unit": "\u2103", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100001, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816392, "name": "\u6e29\u5ea6#100001", "cxdate": null, "udate": 1508815223, "value": "13.06", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 3, "operdate": null, "id": "d995b32a-6fe1-5d63-bffa-78d78d8aec18", "unit": "LUX", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100025, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816391, "name": "\u5149\u7167#100025", "cxdate": null, "udate": 1508815236, "value": "8535.0", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 1, "operdate": null, "id": "8a04e1ad-0c05-59d1-ae14-2452c8afaf95", "unit": "\u2103", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100008, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816391, "name": "\u6e29\u5ea6#100008", "cxdate": null, "udate": 1508815225, "value": "16.36", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 1, "operdate": null, "id": "4bb9f07d-3475-56f4-86f7-9949c9084a08", "unit": "\u2103", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100009, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816390, "name": "\u6e29\u5ea6#100009", "cxdate": null, "udate": 1508815251, "value": "25.88", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 2, "operdate": null, "id": "8bbe208b-d924-523f-b993-f76a919f8945", "unit": "%RH", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100012, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816390, "name": "\u6e7f\u5ea6#100012", "cxdate": null, "udate": 1508815249, "value": "67.91", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 3, "operdate": null, "id": "15a44210-7e61-530a-b467-e60996bfea22", "unit": "LUX", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100024, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816390, "name": "\u5149\u7167#100024", "cxdate": null, "udate": 1508815228, "value": "9274.73", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 3, "operdate": null, "id": "442595ec-3cbb-5703-9d21-1a67a7aceda0", "unit": "LUX", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100027, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816388, "name": "\u5149\u7167#100027", "cxdate": null, "udate": 1508815237, "value": "7311.34", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 2, "operdate": null, "id": "f514d104-861d-5621-9286-2e2fadc56d0c", "unit": "%RH", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100018, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816387, "name": "\u6e7f\u5ea6#100018", "cxdate": null, "udate": 1508815224, "value": "56.99", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 2, "operdate": null, "id": "e55829f8-2cf0-5336-b2f8-c23cf26aa251", "unit": "%RH", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100013, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816386, "name": "\u6e7f\u5ea6#100013", "cxdate": null, "udate": 1508815232, "value": "61.32", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 3, "operdate": null, "id": "70e8637b-82f3-5798-9dd7-cea14aec4f36", "unit": "LUX", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100023, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816386, "name": "\u5149\u7167#100023", "cxdate": null, "udate": 1508815224, "value": "4280.96", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 2, "operdate": null, "id": "95e3b45d-2f4c-5756-a63a-dcd1e5dd1135", "unit": "%RH", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100015, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816384, "name": "\u6e7f\u5ea6#100015", "cxdate": null, "udate": 1508815227, "value": "31.78", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 2, "operdate": null, "id": "4ec04501-5d89-5a23-b4c9-6be73cae9abe", "unit": "%RH", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100010, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816383, "name": "\u6e7f\u5ea6#100010", "cxdate": null, "udate": 1508815225, "value": "61.0", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 3, "operdate": null, "id": "3894b1b1-270e-5436-be39-35d2bdc872f0", "unit": "LUX", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100022, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816383, "name": "\u5149\u7167#100022", "cxdate": null, "udate": 1508815233, "value": "10463.48", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 3, "operdate": null, "id": "66735d06-19a1-5973-afcb-23e70cdf5770", "unit": "LUX", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100021, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816381, "name": "\u5149\u7167#100021", "cxdate": null, "udate": 1508815231, "value": "8172.25", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 1, "operdate": null, "id": "931a710d-d8a8-510e-8074-1caf1e1f47f8", "unit": "\u2103", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100003, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816377, "name": "\u6e29\u5ea6#100003", "cxdate": null, "udate": 1508815227, "value": "28.24", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 1, "operdate": null, "id": "2a97c55b-35b3-5aea-abd7-c34d68840e3b", "unit": "\u2103", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100000, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816376, "name": "\u6e29\u5ea6#100000", "cxdate": null, "udate": 1508815228, "value": "-11.67", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 1, "operdate": null, "id": "cbbf9117-5b50-5a1a-95ca-ec42f2a02c6b", "unit": "\u2103", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100004, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816375, "name": "\u6e29\u5ea6#100004", "cxdate": null, "udate": 1508815236, "value": "-0.02", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 2, "operdate": null, "id": "2b8a4776-01cc-5016-9e61-daefe74831df", "unit": "%RH", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100014, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816375, "name": "\u6e7f\u5ea6#100014", "cxdate": null, "udate": 1508815223, "value": "62.18", "exp": null}, {"oper": false, "hardware_type": 2, "farm_id": 1, "type_id": 1, "operdate": null, "id": "ef6dad5d-f4a7-518d-8f66-629c1a5896f4", "unit": "\u2103", "gateway_id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "min": 0, "hardware_id": 100006, "state": true, "inorder": 0, "cxtype": null, "status": true, "max": 0, "cxnum": null, "cdate": 1508816374, "name": "\u6e29\u5ea6#100006", "cxdate": null, "udate": 1508815226, "value": "5.87", "exp": null}]}}
  48. @apiErrorExample 操作失败
  49. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  50. """
  51. @auth
  52. @Web.setting
  53. def get(self):
  54. id = self.input('id', None)
  55. if id:
  56. self.data['info'] = self.service('common').one('device_gateway', id=id)
  57. if not self.data['info']:
  58. self.out('no')
  59. return
  60. self.data['status'] = self.service('common').list('device_info', state=True, search={'hardware_type--ins':(4,5), 'gateway_id':id}, order='inorder asc, type_id asc,udate asc,hardware_id asc')
  61. self.data['device'] = self.service('common').list('device_info', state=True, search={'hardware_type':2, 'gateway_id':id}, order='inorder asc, type_id asc,udate asc,hardware_id asc')
  62. if self.data['device']:
  63. for key, value in enumerate(self.data['device']):
  64. type = self.service('common').one('device_type', id=value['type_id'])
  65. self.data['device'][key]['unit'] = type['unit']
  66. self.data['pic'] = []
  67. pic = self.service('common').list('device_info', state=True, search={'hardware_type':6, 'farm_id':self.data['info']['farm_id']})
  68. if pic:
  69. for key, value in enumerate(pic):
  70. pic[key]['cdates'] = Demeter.date(value['cdate'])
  71. self.data['pic'] = pic
  72. self.out('yes', self.data)
  73. else:
  74. self.out('no')
  75. class list_path(Load):
  76. """
  77. @api {get} /device/list 获取网关设备列表
  78. @apiVersion 1.0.0
  79. @apiName getDeviceList
  80. @apiGroup Device
  81. @apiSuccess {Object[]} setting 基本信息
  82. @apiSuccess {String} setting.name 站点名
  83. @apiSuccess {Number} setting.farm 当前的农场ID
  84. @apiSuccess {Object[]} list 网关信息(环境监测)
  85. @apiSuccess {String} list.name 网关名称
  86. @apiSuccess {String} list.id 网关ID
  87. @apiErrorExample 操作成功
  88. {"status": 1, "msg": "yes", "code": 0, "data": {"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/"}, "list": [{"stat": false, "pic": "", "hardware_id": 10086, "farm_id": 1, "cdate": 1508815174, "state": true, "camera": null, "id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "name": "\u9ed8\u8ba4\u7f51\u5173"}], "base": {}}}
  89. @apiErrorExample 操作失败
  90. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  91. """
  92. @auth
  93. @Web.setting
  94. def get(self):
  95. self.data['list'] = self.service('common').list('device_gateway', search={'farm_id': Demeter.config['setting']['farm']})
  96. self.out('yes', self.data)
  97. class stat_path(Load):
  98. """
  99. @api {get} /device/stat 获取数据统计
  100. @apiVersion 1.0.0
  101. @apiName getDeviceStat
  102. @apiGroup Device
  103. @apiParam {String} id 网关id
  104. @apiParam {String} device 设备id
  105. @apiParam {String} search_group 周期ID
  106. @apiParam {String} search_start 开始时间:2017-10-10 10:10:10
  107. @apiParam {String} search_end 结束时间:2017-10-10 10:10:10
  108. @apiSuccess {Object[]} setting 基本信息
  109. @apiSuccess {String} setting.name 站点名
  110. @apiSuccess {Number} setting.farm 当前的农场ID
  111. @apiSuccess {Object[]} info 网关状态基本信息
  112. @apiSuccess {String} info.id 网关ID
  113. @apiSuccess {String} info.name 网关名称
  114. @apiSuccess {Object[]} data 设备选择
  115. @apiSuccess {Number} data.id 设备ID
  116. @apiSuccess {String} data.name 设备名称
  117. @apiSuccess {Object[]} group 周期选择
  118. @apiSuccess {Number} group.id 周期ID
  119. @apiSuccess {String} group.name 周期名称
  120. @apiSuccess {Object[]} cur_device 当前选择的设备
  121. @apiSuccess {Number} cur_device.id 设备ID
  122. @apiSuccess {String} cur_device.name 设备名称
  123. @apiSuccess {Object[]} data 设备数据,两条线
  124. @apiSuccess {String} data.name 本条数据名
  125. @apiSuccess {Object[]} data.data 本条数据的具体数据
  126. @apiSuccess {String} data.data.time 数据时间
  127. @apiSuccess {String} data.data.value 数据具体的值
  128. @apiSuccess {Object[]} search 当前搜索的值
  129. @apiSuccess {String} search.group 周期的值
  130. @apiSuccess {String} search.start 开始时间
  131. @apiSuccess {String} search.end 结束时间
  132. @apiErrorExample 操作成功
  133. {"status": 1, "msg": "yes", "code": 0, "data": {"info": {"status": true, "hardware_id": 10086, "name": "\u9ed8\u8ba4\u7f51\u5173", "farm_id": 1, "cdate": 1504233947, "state": true, "power_num": "", "power_status": "", "id": "ce37636b-3ce7-5de2-9160-0f3283f7d392"}, "search": {"group": "1"}, "group": [{"id": "1", "name": "\u4e00\u5929"}, {"id": "7", "name": "\u4e00\u5468"}, {"id": "30", "name": "\u4e00\u4e2a\u6708"}, {"id": "180", "name": "\u534a\u5e74"}], "setting": {"farm": 1, "user": 0, "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "cur_device": {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": "", "hardware_type": 2, "hardware_id": 100001, "name": "\u6e7f\u5ea6#100001", "type_id": 2, "farm_id": 1, "cdate": 1504253835, "state": true, "num": 4, "status": true, "show": "4", "id": "dc24428c-eafc-5715-b7d1-f3222d28c3bb"}, "device": [{"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100009, "name": "\u6e7f\u5ea6#100009", "type_id": 2, "farm_id": 1, "cdate": 1504253837, "state": true, "num": 30, "status": true, "show": "30", "id": "6d8a4c0e-4f85-524a-87f8-382c333c44da"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100000, "name": "\u6e7f\u5ea6#100000", "type_id": 2, "farm_id": 1, "cdate": 1504253836, "state": true, "num": 5, "status": true, "show": "5", "id": "d644b079-9d4d-521c-8e65-8940c96ba9a7"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100001, "name": "\u6e7f\u5ea6#100001", "type_id": 2, "farm_id": 1, "cdate": 1504253835, "state": true, "num": 4, "status": true, "show": "4", "id": "dc24428c-eafc-5715-b7d1-f3222d28c3bb"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100004, "name": "\u6e7f\u5ea6#100004", "type_id": 2, "farm_id": 1, "cdate": 1504253834, "state": true, "num": 17, "status": true, "show": "17", "id": "62199416-cca0-5114-b900-a10f51e7e447"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100005, "name": "\u6e7f\u5ea6#100005", "type_id": 2, "farm_id": 1, "cdate": 1504253833, "state": true, "num": 7, "status": true, "show": "7", "id": "456daa98-a1f0-59e6-a337-7ca1fa7b2527"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100003, "name": "\u6e7f\u5ea6#100003", "type_id": 2, "farm_id": 1, "cdate": 1504253832, "state": true, "num": 39, "status": true, "show": "39", "id": "11bd4ad1-b4ff-5b1f-948a-935d859b408c"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100007, "name": "\u6e7f\u5ea6#100007", "type_id": 2, "farm_id": 1, "cdate": 1504253828, "state": true, "num": 43, "status": true, "show": "43", "id": "f8e3a42a-7fa3-575a-b99e-2dab4f992239"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100010, "name": "\u6e7f\u5ea6#100010", "type_id": 2, "farm_id": 1, "cdate": 1504253827, "state": true, "num": 20, "status": true, "show": "20", "id": "138876d7-1710-56fa-824b-10402cba17f8"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100002, "name": "\u6e7f\u5ea6#100002", "type_id": 2, "farm_id": 1, "cdate": 1504253826, "state": true, "num": 43, "status": true, "show": "43", "id": "eecfe61f-de83-588f-8cbd-41519d4ebef3"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100006, "name": "\u6e7f\u5ea6#100006", "type_id": 2, "farm_id": 1, "cdate": 1504253818, "state": true, "num": 4, "status": true, "show": "4", "id": "78bd90ac-6af3-5091-83e5-f3397063f743"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100008, "name": "\u6e7f\u5ea6#100008", "type_id": 2, "farm_id": 1, "cdate": 1504253815, "state": true, "num": 37, "status": true, "show": "37", "id": "5fda8633-aed8-5a3b-8175-2c61e7553d91"}], "data": [{"data": {"rows": [["2017-09-01 11:15:00", 45], ["2017-09-01 11:20:00", 50], ["2017-09-01 11:25:00", 49], ["2017-09-01 11:30:00", 49], ["2017-09-01 11:35:00", 50], ["2017-09-01 11:40:00", 48], ["2017-09-01 11:45:00", 49], ["2017-09-01 11:50:00", 47], ["2017-09-01 11:55:00", 49], ["2017-09-01 12:00:00", 49], ["2017-09-01 12:05:00", 47], ["2017-09-01 12:10:00", 50], ["2017-09-01 12:15:00", 49], ["2017-09-01 12:20:00", 50], ["2017-09-01 12:25:00", 48], ["2017-09-01 12:30:00", 50], ["2017-09-01 12:35:00", 48], ["2017-09-01 12:40:00", 50], ["2017-09-01 12:45:00", 47], ["2017-09-01 12:50:00", 50], ["2017-09-01 12:55:00", 49], ["2017-09-01 13:00:00", 46], ["2017-09-01 13:05:00", 50], ["2017-09-01 13:10:00", 50], ["2017-09-01 13:15:00", 49], ["2017-09-01 13:20:00", 50], ["2017-09-01 13:25:00", 49], ["2017-09-01 13:30:00", 50], ["2017-09-01 13:35:00", 50], ["2017-09-01 13:40:00", 48], ["2017-09-01 13:45:00", 49], ["2017-09-01 13:50:00", 49], ["2017-09-01 13:55:00", 49], ["2017-09-01 14:00:00", 49], ["2017-09-01 14:05:00", 47], ["2017-09-01 14:10:00", 49], ["2017-09-01 14:15:00", 48], ["2017-09-01 14:20:00", 45], ["2017-09-01 14:25:00", 50], ["2017-09-01 14:30:00", 50], ["2017-09-01 14:35:00", 49], ["2017-09-01 14:40:00", 49], ["2017-09-01 14:45:00", 49], ["2017-09-01 14:50:00", 49], ["2017-09-01 14:55:00", 47], ["2017-09-01 15:00:00", 49], ["2017-09-01 15:05:00", 50], ["2017-09-01 15:10:00", 49], ["2017-09-01 15:15:00", 47], ["2017-09-01 15:25:00", 50], ["2017-09-01 15:30:00", 50], ["2017-09-01 15:35:00", 49], ["2017-09-01 15:40:00", 49], ["2017-09-01 15:45:00", 49], ["2017-09-01 15:50:00", 48], ["2017-09-01 15:55:00", 47], ["2017-09-01 16:05:00", 46], ["2017-09-01 16:10:00", 49], ["2017-09-01 16:15:00", 49]], "value": "[45, 50, 49, 49, 50, 48, 49, 47, 49, 49, 47, 50, 49, 50, 48, 50, 48, 50, 47, 50, 49, 46, 50, 50, 49, 50, 49, 50, 50, 48, 49, 49, 49, 49, 47, 49, 48, 45, 50, 50, 49, 49, 49, 49, 47, 49, 50, 49, 47, 50, 50, 49, 49, 49, 48, 47, 46, 49, 49]", "time": "[\"2017-09-01 11:15:00\", \"2017-09-01 11:20:00\", \"2017-09-01 11:25:00\", \"2017-09-01 11:30:00\", \"2017-09-01 11:35:00\", \"2017-09-01 11:40:00\", \"2017-09-01 11:45:00\", \"2017-09-01 11:50:00\", \"2017-09-01 11:55:00\", \"2017-09-01 12:00:00\", \"2017-09-01 12:05:00\", \"2017-09-01 12:10:00\", \"2017-09-01 12:15:00\", \"2017-09-01 12:20:00\", \"2017-09-01 12:25:00\", \"2017-09-01 12:30:00\", \"2017-09-01 12:35:00\", \"2017-09-01 12:40:00\", \"2017-09-01 12:45:00\", \"2017-09-01 12:50:00\", \"2017-09-01 12:55:00\", \"2017-09-01 13:00:00\", \"2017-09-01 13:05:00\", \"2017-09-01 13:10:00\", \"2017-09-01 13:15:00\", \"2017-09-01 13:20:00\", \"2017-09-01 13:25:00\", \"2017-09-01 13:30:00\", \"2017-09-01 13:35:00\", \"2017-09-01 13:40:00\", \"2017-09-01 13:45:00\", \"2017-09-01 13:50:00\", \"2017-09-01 13:55:00\", \"2017-09-01 14:00:00\", \"2017-09-01 14:05:00\", \"2017-09-01 14:10:00\", \"2017-09-01 14:15:00\", \"2017-09-01 14:20:00\", \"2017-09-01 14:25:00\", \"2017-09-01 14:30:00\", \"2017-09-01 14:35:00\", \"2017-09-01 14:40:00\", \"2017-09-01 14:45:00\", \"2017-09-01 14:50:00\", \"2017-09-01 14:55:00\", \"2017-09-01 15:00:00\", \"2017-09-01 15:05:00\", \"2017-09-01 15:10:00\", \"2017-09-01 15:15:00\", \"2017-09-01 15:25:00\", \"2017-09-01 15:30:00\", \"2017-09-01 15:35:00\", \"2017-09-01 15:40:00\", \"2017-09-01 15:45:00\", \"2017-09-01 15:50:00\", \"2017-09-01 15:55:00\", \"2017-09-01 16:05:00\", \"2017-09-01 16:10:00\", \"2017-09-01 16:15:00\"]"}, "name": "\u6700\u9ad8"}, {"data": {"rows": [["2017-09-01 11:15:00", 3], ["2017-09-01 11:20:00", 3], ["2017-09-01 11:25:00", 1], ["2017-09-01 11:30:00", 1], ["2017-09-01 11:35:00", 1], ["2017-09-01 11:40:00", 2], ["2017-09-01 11:45:00", 2], ["2017-09-01 11:50:00", 1], ["2017-09-01 11:55:00", 3], ["2017-09-01 12:00:00", 3], ["2017-09-01 12:05:00", 1], ["2017-09-01 12:10:00", 1], ["2017-09-01 12:15:00", 2], ["2017-09-01 12:20:00", 1], ["2017-09-01 12:25:00", 1], ["2017-09-01 12:30:00", 2], ["2017-09-01 12:35:00", 1], ["2017-09-01 12:40:00", 3], ["2017-09-01 12:45:00", 1], ["2017-09-01 12:50:00", 4], ["2017-09-01 12:55:00", 1], ["2017-09-01 13:00:00", 3], ["2017-09-01 13:05:00", 1], ["2017-09-01 13:10:00", 1], ["2017-09-01 13:15:00", 1], ["2017-09-01 13:20:00", 7], ["2017-09-01 13:25:00", 1], ["2017-09-01 13:30:00", 1], ["2017-09-01 13:35:00", 1], ["2017-09-01 13:40:00", 1], ["2017-09-01 13:45:00", 1], ["2017-09-01 13:50:00", 4], ["2017-09-01 13:55:00", 5], ["2017-09-01 14:00:00", 2], ["2017-09-01 14:05:00", 2], ["2017-09-01 14:10:00", 3], ["2017-09-01 14:15:00", 4], ["2017-09-01 14:20:00", 1], ["2017-09-01 14:25:00", 1], ["2017-09-01 14:30:00", 1], ["2017-09-01 14:35:00", 1], ["2017-09-01 14:40:00", 2], ["2017-09-01 14:45:00", 2], ["2017-09-01 14:50:00", 2], ["2017-09-01 14:55:00", 1], ["2017-09-01 15:00:00", 1], ["2017-09-01 15:05:00", 1], ["2017-09-01 15:10:00", 1], ["2017-09-01 15:15:00", 1], ["2017-09-01 15:25:00", 3], ["2017-09-01 15:30:00", 1], ["2017-09-01 15:35:00", 1], ["2017-09-01 15:40:00", 9], ["2017-09-01 15:45:00", 2], ["2017-09-01 15:50:00", 5], ["2017-09-01 15:55:00", 8], ["2017-09-01 16:05:00", 5], ["2017-09-01 16:10:00", 1], ["2017-09-01 16:15:00", 4]], "value": "[3, 3, 1, 1, 1, 2, 2, 1, 3, 3, 1, 1, 2, 1, 1, 2, 1, 3, 1, 4, 1, 3, 1, 1, 1, 7, 1, 1, 1, 1, 1, 4, 5, 2, 2, 3, 4, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 3, 1, 1, 9, 2, 5, 8, 5, 1, 4]", "time": "[\"2017-09-01 11:15:00\", \"2017-09-01 11:20:00\", \"2017-09-01 11:25:00\", \"2017-09-01 11:30:00\", \"2017-09-01 11:35:00\", \"2017-09-01 11:40:00\", \"2017-09-01 11:45:00\", \"2017-09-01 11:50:00\", \"2017-09-01 11:55:00\", \"2017-09-01 12:00:00\", \"2017-09-01 12:05:00\", \"2017-09-01 12:10:00\", \"2017-09-01 12:15:00\", \"2017-09-01 12:20:00\", \"2017-09-01 12:25:00\", \"2017-09-01 12:30:00\", \"2017-09-01 12:35:00\", \"2017-09-01 12:40:00\", \"2017-09-01 12:45:00\", \"2017-09-01 12:50:00\", \"2017-09-01 12:55:00\", \"2017-09-01 13:00:00\", \"2017-09-01 13:05:00\", \"2017-09-01 13:10:00\", \"2017-09-01 13:15:00\", \"2017-09-01 13:20:00\", \"2017-09-01 13:25:00\", \"2017-09-01 13:30:00\", \"2017-09-01 13:35:00\", \"2017-09-01 13:40:00\", \"2017-09-01 13:45:00\", \"2017-09-01 13:50:00\", \"2017-09-01 13:55:00\", \"2017-09-01 14:00:00\", \"2017-09-01 14:05:00\", \"2017-09-01 14:10:00\", \"2017-09-01 14:15:00\", \"2017-09-01 14:20:00\", \"2017-09-01 14:25:00\", \"2017-09-01 14:30:00\", \"2017-09-01 14:35:00\", \"2017-09-01 14:40:00\", \"2017-09-01 14:45:00\", \"2017-09-01 14:50:00\", \"2017-09-01 14:55:00\", \"2017-09-01 15:00:00\", \"2017-09-01 15:05:00\", \"2017-09-01 15:10:00\", \"2017-09-01 15:15:00\", \"2017-09-01 15:25:00\", \"2017-09-01 15:30:00\", \"2017-09-01 15:35:00\", \"2017-09-01 15:40:00\", \"2017-09-01 15:45:00\", \"2017-09-01 15:50:00\", \"2017-09-01 15:55:00\", \"2017-09-01 16:05:00\", \"2017-09-01 16:10:00\", \"2017-09-01 16:15:00\"]"}, "name": "\u6700\u4f4e"}]}}
  134. @apiErrorExample 操作失败
  135. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  136. """
  137. @auth
  138. @Web.setting
  139. def get(self):
  140. id = self.input('id', None)
  141. device = self.input('device', None)
  142. if id and device:
  143. self.data['info'] = self.service('common').one('device_gateway', id=id)
  144. if not self.data['info']:
  145. self.out('no')
  146. return
  147. self.data['cur_device'] = self.service('common').one('device_info', id=device)
  148. if not self.data['cur_device']:
  149. self.out('no')
  150. return
  151. self.data['device'] = self.service('common').list('device_info', state=True, search={'hardware_type':2, 'gateway_id':id}, order='inorder asc, type_id asc,udate asc,hardware_id asc')
  152. model = Demeter.model('data', 'tsdb')
  153. self.data['group'] = model.dateConfig()
  154. search_group = self.input('search_group')
  155. search_start = self.input('search_start')
  156. search_end = self.input('search_end')
  157. search = {}
  158. if search_group:
  159. search['group'] = search_group
  160. else:
  161. search['group'] = '1'
  162. if search_start:
  163. search['start'] = search_start
  164. if search_end:
  165. search['end'] = search_end
  166. method = 'maxmin'
  167. self.data['search'] = search
  168. self.data['data'] = model.getData(method, search, self.data['cur_device'])
  169. self.out('yes', self.data)
  170. else:
  171. self.out('no')
  172. class pic_path(Load):
  173. """
  174. @api {get} /device/pic 获取图像记录
  175. @apiVersion 1.0.0
  176. @apiName getDevicePic
  177. @apiGroup Device
  178. @apiParam {String} page 页数
  179. @apiParam {String} id 网关id
  180. @apiParam {String} search_date 拍照时间:2017-10-10
  181. @apiSuccess {Object[]} setting 基本信息
  182. @apiSuccess {String} setting.name 站点名
  183. @apiSuccess {Number} setting.farm 当前的农场ID
  184. @apiSuccess {Object[]} info 网关状态基本信息
  185. @apiSuccess {String} info.id 网关ID
  186. @apiSuccess {String} info.name 网关名称
  187. @apiSuccess {Object[]} pic 图像数据
  188. @apiSuccess {Number} pic.id 图片ID
  189. @apiSuccess {String} pic.name 图片名称
  190. @apiSuccess {String} pic.show 图片地址
  191. @apiSuccess {String} pic.cdates 采集时间
  192. @apiSuccess {String} pic.cdate 采集时间戳
  193. @apiSuccess {Object[]} search 当前搜索的值
  194. @apiSuccess {String} search.date 拍照时间
  195. @apiSuccess {String} url 网站url
  196. @apiSuccess {Object[]} page 分页信息
  197. @apiSuccess {String} page.current 当前页
  198. @apiSuccess {String} page.total 总页数
  199. @apiSuccess {String} page.num 每页数据条数
  200. @apiSuccess {String} page.totalNum 总数据条数
  201. @apiErrorExample 操作成功
  202. {"status": 1, "msg": "yes", "code": 0, "data": {"info": {"status": true, "hardware_id": 10086, "name": "\u9ed8\u8ba4\u7f51\u5173", "farm_id": 1, "cdate": 1504233947, "state": true, "power_num": "", "power_status": "", "id": "ce37636b-3ce7-5de2-9160-0f3283f7d392"}, "url": "http://192.168.15.10:8088/", "pic": [{"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "pic": "/camera/2017/09/01/01c323ac0208580601252e2ce9eb3286.jpg", "farm_id": 1, "cdate": 1504262668, "cdates": "2017-09-01 10:44:28", "state": true, "id": "5ea5d688-e092-5131-a382-686298da4f94", "device_id": "2f612150-f670-54e9-9886-a044cfb18e20"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "pic": "/camera/2017/09/01/f5e1509cf0d6b1cb2f048a058dabd75b.jpg", "farm_id": 1, "cdate": 1504262666, "cdates": "2017-09-01 10:44:26", "state": true, "id": "bd36fa61-5210-57c5-b8b8-a81e5797ee85", "device_id": "2f612150-f670-54e9-9886-a044cfb18e20"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "pic": "/camera/2017/09/01/8f3a6d9d614cd280d2cb4a78f90d121a.jpg", "farm_id": 1, "cdate": 1504262665, "cdates": "2017-09-01 10:44:25", "state": true, "id": "162ac864-b2e9-5a7a-84cb-ac57e31ef99c", "device_id": "2f612150-f670-54e9-9886-a044cfb18e20"}], "search_date": null, "setting": {"farm": 1, "user": 0, "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "page": {"current": 1, "ajax": false, "total": 1.0, "num": 15, "totalNum": 3}}}
  203. @apiErrorExample 操作失败
  204. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  205. """
  206. @auth
  207. @Web.setting
  208. def get(self):
  209. id = self.input('id', None)
  210. device = self.input('device', None)
  211. if device:
  212. """
  213. self.data['info'] = self.service('common').one('device_gateway', id=id)
  214. if not self.data['info']:
  215. self.out('no')
  216. return
  217. """
  218. self.data['url'] = self.request.protocol + "://" + self.request.host + '/'
  219. self.data['search_date'] = self.input('search_date')
  220. search = {}
  221. #search['gateway_id'] = id
  222. search['device_id'] = device
  223. if self.data['search_date']:
  224. search['cdate-time-start'] = self.data['search_date'] + ' 00:00:00'
  225. search['cdate-time-end'] = self.data['search_date'] + ' 23:59:59'
  226. self.data['pic'] = self.service('common').list('device_pic', state=True, search=search, page=True)
  227. if self.data['pic']:
  228. for key, value in enumerate(self.data['pic']):
  229. self.data['pic'][key]['cdates'] = Demeter.date(value['cdate'])
  230. self.data['pic'][key]['pic'] = 'https://api.nongxiaohe.com' + value['pic']
  231. self.out('yes', self.data)
  232. else:
  233. self.out('no')
  234. class picup_path(Load):
  235. def get(self):
  236. update = {}
  237. update['gateway_id'] = '542535db-6c0b-51fc-9f73-cafb3872ce76'
  238. update['device_id'] = '6e78c955-e3be-5edb-b0c2-e6c5c88fd95a'
  239. update['pic'] = 'http://xinnongbaohe.oss-cn-shanghai.aliyuncs.com/cp/bjbg1/1.jpg'
  240. state = self.service('common').update('device_pic', False, update)
  241. self.out('yes', {'id':state})
  242. class msgup_path(Load):
  243. def get(self):
  244. update = {}
  245. update['device_id'] = '6e78c955-e3be-5edb-b0c2-e6c5c88fd95a'
  246. update['type_id'] = 1
  247. update['content'] = '错误提示打发打发'
  248. state = self.service('common').update('msg', False, update)
  249. self.out('yes', {'id':state})
  250. class msg_path(Load):
  251. """
  252. @api {get} /device/msg 获取设备日志
  253. @apiVersion 1.0.0
  254. @apiName getDeviceMsg
  255. @apiGroup Device
  256. @apiParam {String} page 页数
  257. @apiParam {String} id 网关id
  258. @apiParam {String} device 设备id
  259. @apiSuccess {Object[]} setting 基本信息
  260. @apiSuccess {String} setting.name 站点名
  261. @apiSuccess {Number} setting.farm 当前的农场ID
  262. @apiSuccess {Object[]} msg 日志列表
  263. @apiSuccess {Number} msg.id 日志ID
  264. @apiSuccess {String} msg.content 日志内容
  265. @apiSuccess {String} msg.cdates 日志时间
  266. @apiSuccess {String} msg.cdate 日志时间戳
  267. @apiSuccess {Object[]} page 分页信息
  268. @apiSuccess {String} page.current 当前页
  269. @apiSuccess {String} page.total 总页数
  270. @apiSuccess {String} page.num 每页数据条数
  271. @apiSuccess {String} page.totalNum 总数据条数
  272. @apiErrorExample 操作成功
  273. {"status": 1, "msg": "yes", "code": 0, "data": {"info": {"status": true, "hardware_id": 10086, "name": "\u9ed8\u8ba4\u7f51\u5173", "farm_id": 1, "cdate": 1504233947, "state": true, "power_num": "", "power_status": "", "id": "ce37636b-3ce7-5de2-9160-0f3283f7d392"}, "msg": [], "setting": {"farm": 1, "user": 0, "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "cur_device": {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": "", "hardware_type": 2, "hardware_id": 100001, "name": "\u6e7f\u5ea6#100001", "type_id": 2, "farm_id": 1, "cdate": 1504253835, "state": true, "num": 4, "status": true, "show": "4", "id": "dc24428c-eafc-5715-b7d1-f3222d28c3bb"}}}
  274. @apiErrorExample 操作失败
  275. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  276. """
  277. @auth
  278. @Web.setting
  279. def get(self):
  280. id = self.input('id', None)
  281. if id:
  282. self.data['info'] = self.service('common').one('device_gateway', id=id)
  283. if not self.data['info']:
  284. self.out('no')
  285. return
  286. device = self.service('common').list('device_info', search={'gateway_id':id}, order='inorder asc, type_id asc,udate asc,hardware_id asc')
  287. if not device:
  288. self.out('no')
  289. return
  290. devices = []
  291. if device:
  292. for key, value in enumerate(device):
  293. devices.append(value['id'])
  294. search = {}
  295. search['device_id--ins'] = devices
  296. self.data['msg'] = self.service('common').list('msg', state=True, search=search, page=True)
  297. if self.data['msg']:
  298. for key, value in enumerate(self.data['msg']):
  299. self.data['msg'][key]['cdates'] = Demeter.date(value['cdate'])
  300. type = self.service('common').one('msg_type', id=value['type_id'])
  301. self.data['msg'][key]['type_name'] = type['name']
  302. self.out('yes', self.data)
  303. else:
  304. self.out('no')
  305. class set_path(Load):
  306. """
  307. @api {get} /device/set 获取设备极限值信息
  308. @apiVersion 1.0.0
  309. @apiName getDeviceSet
  310. @apiGroup Device
  311. @apiParam {String} id 网关id
  312. @apiParam {String} device 设备id
  313. @apiSuccess {Object[]} setting 基本信息
  314. @apiSuccess {String} setting.name 站点名
  315. @apiSuccess {Number} setting.farm 当前的农场ID
  316. @apiSuccess {Object[]} device 设备数据
  317. @apiSuccess {Number} device.id 设备ID
  318. @apiSuccess {String} device.name 设备名称
  319. @apiSuccess {String} device.show 显示的数据
  320. @apiSuccess {String} device.unit 设备的单位
  321. @apiSuccess {Number} device.max 设备的上限
  322. @apiSuccess {Number} device.min 设备的下限
  323. @apiSuccess {Bool} device.status 设备状态
  324. @apiErrorExample 操作成功
  325. {"status": 1, "msg": "yes", "code": 0, "data": {"setting": {"farm": 1, "user": 0, "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "list": [{"pic": "http://192.168.15.10:8087/upload/2017/08/30/455f9d6c26b5c989b32eda1809e58d5f.jpg", "method_id": null, "land_id": "249be20d-5759-5af0-9859-b770d9f44e2a", "farm_id": 1, "state": true, "amount": "100ml", "workdate": 1504105397, "category_id": "9365ea66-be55-56f7-a511-059fc85a9478", "cdate": 1504076614, "id": "19e05f00-ae55-5605-be12-86dcd2866df9"}], "page": {"current": 1, "ajax": false, "total": 1.0, "num": 15, "totalNum": 1}}}
  326. @apiErrorExample 操作失败
  327. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  328. """
  329. @auth
  330. @Web.setting
  331. def get(self):
  332. id = self.input('id', None)
  333. device = self.input('device', None)
  334. if id and device:
  335. self.data['info'] = self.service('common').one('device_gateway', id=id)
  336. if not self.data['info']:
  337. self.out('no')
  338. return
  339. self.data['device'] = self.service('common').one('device_info', id=device)
  340. if not self.data['device']:
  341. self.out('no')
  342. return
  343. type = self.service('common').one('device_type', id=self.data['device']['type_id'])
  344. self.data['device']['unit'] = type['unit']
  345. self.out('yes', self.data)
  346. else:
  347. self.out('no')
  348. """
  349. @api {post} /device/set 更新极限值设置
  350. @apiVersion 1.0.0
  351. @apiName updateDeviceSet
  352. @apiGroup Device
  353. @apiParam {String} id 设备id
  354. @apiParam {String} update_max 最大上限
  355. @apiParam {String} update_min 最小下限
  356. @apiSuccess {Bool} status 状态
  357. @apiSuccess {String} msg 描述
  358. @apiSuccess {Number} code 状态码
  359. @apiErrorExample 操作成功
  360. {"status": 1, "msg": "操作成功", "code": 0, "data": {}}
  361. @apiErrorExample 操作失败
  362. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  363. """
  364. @auth
  365. @Web.setting
  366. def post(self):
  367. id = self.input('id', None)
  368. if not id:
  369. self.out('no')
  370. return
  371. device = self.service('common').one('device_info', id=id)
  372. if not device:
  373. self.out('no')
  374. return
  375. update = {}
  376. update['max'] = self.input('update_max')
  377. update['min'] = self.input('update_min')
  378. if not update['max']:
  379. self.out(u'请输入最大上限')
  380. return
  381. if not update['min']:
  382. self.out(u'请输入最小下限')
  383. return
  384. state = self.service('common').update('device_info', device['id'], update, cdate=False)
  385. self.out('yes', {'id':state})