device.py 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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.data['pic'] = []
  97. pic = self.service('common').list('device_info', state=True, search={'hardware_type':6, 'farm_id':Demeter.config['setting']['farm']})
  98. if pic:
  99. self.data['pic'] = pic
  100. self.out('yes', self.data)
  101. class stat_path(Load):
  102. """
  103. @api {get} /device/stat 获取数据统计
  104. @apiVersion 1.0.0
  105. @apiName getDeviceStat
  106. @apiGroup Device
  107. @apiParam {String} id 网关id
  108. @apiParam {String} device 设备id
  109. @apiParam {String} search_group 周期ID
  110. @apiParam {String} search_start 开始时间:2017-10-10 10:10:10
  111. @apiParam {String} search_end 结束时间:2017-10-10 10:10:10
  112. @apiSuccess {Object[]} setting 基本信息
  113. @apiSuccess {String} setting.name 站点名
  114. @apiSuccess {Number} setting.farm 当前的农场ID
  115. @apiSuccess {Object[]} info 网关状态基本信息
  116. @apiSuccess {String} info.id 网关ID
  117. @apiSuccess {String} info.name 网关名称
  118. @apiSuccess {Object[]} data 设备选择
  119. @apiSuccess {Number} data.id 设备ID
  120. @apiSuccess {String} data.name 设备名称
  121. @apiSuccess {Object[]} group 周期选择
  122. @apiSuccess {Number} group.id 周期ID
  123. @apiSuccess {String} group.name 周期名称
  124. @apiSuccess {Object[]} cur_device 当前选择的设备
  125. @apiSuccess {Number} cur_device.id 设备ID
  126. @apiSuccess {String} cur_device.name 设备名称
  127. @apiSuccess {Object[]} data 设备数据,两条线
  128. @apiSuccess {String} data.name 本条数据名
  129. @apiSuccess {Object[]} data.data 本条数据的具体数据
  130. @apiSuccess {String} data.data.time 数据时间
  131. @apiSuccess {String} data.data.value 数据具体的值
  132. @apiSuccess {Object[]} search 当前搜索的值
  133. @apiSuccess {String} search.group 周期的值
  134. @apiSuccess {String} search.start 开始时间
  135. @apiSuccess {String} search.end 结束时间
  136. @apiErrorExample 操作成功
  137. {"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"}]}}
  138. @apiErrorExample 操作失败
  139. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  140. """
  141. @auth
  142. @Web.setting
  143. def get(self):
  144. id = self.input('id', None)
  145. device = self.input('device', None)
  146. if id and device:
  147. self.data['info'] = self.service('common').one('device_gateway', id=id)
  148. if not self.data['info']:
  149. self.out('no')
  150. return
  151. self.data['cur_device'] = self.service('common').one('device_info', id=device)
  152. if not self.data['cur_device']:
  153. self.out('no')
  154. return
  155. 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')
  156. model = Demeter.model('data', 'tsdb')
  157. self.data['group'] = model.dateConfig()
  158. search_group = self.input('search_group')
  159. search_start = self.input('search_start')
  160. search_end = self.input('search_end')
  161. search = {}
  162. if search_group:
  163. search['group'] = search_group
  164. else:
  165. search['group'] = '1'
  166. if search_start:
  167. search['start'] = search_start
  168. if search_end:
  169. search['end'] = search_end
  170. method = 'maxmin'
  171. self.data['search'] = search
  172. self.data['data'] = model.getData(method, search, self.data['cur_device'])
  173. self.out('yes', self.data)
  174. else:
  175. self.out('no')
  176. class pic_path(Load):
  177. """
  178. @api {get} /device/pic 获取图像记录
  179. @apiVersion 1.0.0
  180. @apiName getDevicePic
  181. @apiGroup Device
  182. @apiParam {String} page 页数
  183. @apiParam {String} id 网关id
  184. @apiParam {String} search_date 拍照时间:2017-10-10
  185. @apiSuccess {Object[]} setting 基本信息
  186. @apiSuccess {String} setting.name 站点名
  187. @apiSuccess {Number} setting.farm 当前的农场ID
  188. @apiSuccess {Object[]} info 网关状态基本信息
  189. @apiSuccess {String} info.id 网关ID
  190. @apiSuccess {String} info.name 网关名称
  191. @apiSuccess {Object[]} pic 图像数据
  192. @apiSuccess {Number} pic.id 图片ID
  193. @apiSuccess {String} pic.name 图片名称
  194. @apiSuccess {String} pic.show 图片地址
  195. @apiSuccess {String} pic.cdates 采集时间
  196. @apiSuccess {String} pic.cdate 采集时间戳
  197. @apiSuccess {Object[]} search 当前搜索的值
  198. @apiSuccess {String} search.date 拍照时间
  199. @apiSuccess {String} url 网站url
  200. @apiSuccess {Object[]} page 分页信息
  201. @apiSuccess {String} page.current 当前页
  202. @apiSuccess {String} page.total 总页数
  203. @apiSuccess {String} page.num 每页数据条数
  204. @apiSuccess {String} page.totalNum 总数据条数
  205. @apiErrorExample 操作成功
  206. {"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}}}
  207. @apiErrorExample 操作失败
  208. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  209. """
  210. @auth
  211. @Web.setting
  212. def get(self):
  213. id = self.input('id', None)
  214. device = self.input('device', None)
  215. if device:
  216. """
  217. self.data['info'] = self.service('common').one('device_gateway', id=id)
  218. if not self.data['info']:
  219. self.out('no')
  220. return
  221. """
  222. self.data['url'] = self.request.protocol + "://" + self.request.host + '/'
  223. self.data['search_date'] = self.input('search_date')
  224. search = {}
  225. #search['gateway_id'] = id
  226. search['device_id'] = device
  227. if self.data['search_date']:
  228. search['cdate-time-start'] = self.data['search_date'] + ' 00:00:00'
  229. search['cdate-time-end'] = self.data['search_date'] + ' 23:59:59'
  230. self.data['pic'] = self.service('common').list('device_pic', state=True, search=search, page=True)
  231. if self.data['pic']:
  232. for key, value in enumerate(self.data['pic']):
  233. self.data['pic'][key]['cdates'] = Demeter.date(value['cdate'])
  234. self.data['pic'][key]['pic'] = 'https://api.nongxiaohe.com' + value['pic']
  235. self.out('yes', self.data)
  236. else:
  237. self.out('no')
  238. class picup_path(Load):
  239. def get(self):
  240. update = {}
  241. update['gateway_id'] = '542535db-6c0b-51fc-9f73-cafb3872ce76'
  242. update['device_id'] = '6e78c955-e3be-5edb-b0c2-e6c5c88fd95a'
  243. update['pic'] = 'http://xinnongbaohe.oss-cn-shanghai.aliyuncs.com/cp/bjbg1/1.jpg'
  244. state = self.service('common').update('device_pic', False, update)
  245. self.out('yes', {'id':state})
  246. class msgup_path(Load):
  247. def get(self):
  248. update = {}
  249. update['device_id'] = '6e78c955-e3be-5edb-b0c2-e6c5c88fd95a'
  250. update['type_id'] = 1
  251. update['content'] = '错误提示打发打发'
  252. state = self.service('common').update('msg', False, update)
  253. self.out('yes', {'id':state})
  254. class msg_path(Load):
  255. """
  256. @api {get} /device/msg 获取设备日志
  257. @apiVersion 1.0.0
  258. @apiName getDeviceMsg
  259. @apiGroup Device
  260. @apiParam {String} page 页数
  261. @apiParam {String} id 网关id
  262. @apiParam {String} device 设备id
  263. @apiSuccess {Object[]} setting 基本信息
  264. @apiSuccess {String} setting.name 站点名
  265. @apiSuccess {Number} setting.farm 当前的农场ID
  266. @apiSuccess {Object[]} msg 日志列表
  267. @apiSuccess {Number} msg.id 日志ID
  268. @apiSuccess {String} msg.content 日志内容
  269. @apiSuccess {String} msg.cdates 日志时间
  270. @apiSuccess {String} msg.cdate 日志时间戳
  271. @apiSuccess {Object[]} page 分页信息
  272. @apiSuccess {String} page.current 当前页
  273. @apiSuccess {String} page.total 总页数
  274. @apiSuccess {String} page.num 每页数据条数
  275. @apiSuccess {String} page.totalNum 总数据条数
  276. @apiErrorExample 操作成功
  277. {"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"}}}
  278. @apiErrorExample 操作失败
  279. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  280. """
  281. @auth
  282. @Web.setting
  283. def get(self):
  284. id = self.input('id', None)
  285. if id:
  286. self.data['info'] = self.service('common').one('device_gateway', id=id)
  287. if not self.data['info']:
  288. self.out('no')
  289. return
  290. device = self.service('common').list('device_info', search={'gateway_id':id}, order='inorder asc, type_id asc,udate asc,hardware_id asc')
  291. if not device:
  292. self.out('no')
  293. return
  294. devices = []
  295. if device:
  296. for key, value in enumerate(device):
  297. devices.append(value['id'])
  298. search = {}
  299. search['device_id--ins'] = devices
  300. self.data['msg'] = self.service('common').list('msg', state=True, search=search, page=True)
  301. if self.data['msg']:
  302. for key, value in enumerate(self.data['msg']):
  303. self.data['msg'][key]['cdates'] = Demeter.date(value['cdate'])
  304. type = self.service('common').one('msg_type', id=value['type_id'])
  305. self.data['msg'][key]['type_name'] = type['name']
  306. self.out('yes', self.data)
  307. else:
  308. self.out('no')
  309. class set_path(Load):
  310. """
  311. @api {get} /device/set 获取设备极限值信息
  312. @apiVersion 1.0.0
  313. @apiName getDeviceSet
  314. @apiGroup Device
  315. @apiParam {String} id 网关id
  316. @apiParam {String} device 设备id
  317. @apiSuccess {Object[]} setting 基本信息
  318. @apiSuccess {String} setting.name 站点名
  319. @apiSuccess {Number} setting.farm 当前的农场ID
  320. @apiSuccess {Object[]} device 设备数据
  321. @apiSuccess {Number} device.id 设备ID
  322. @apiSuccess {String} device.name 设备名称
  323. @apiSuccess {String} device.show 显示的数据
  324. @apiSuccess {String} device.unit 设备的单位
  325. @apiSuccess {Number} device.max 设备的上限
  326. @apiSuccess {Number} device.min 设备的下限
  327. @apiSuccess {Bool} device.status 设备状态
  328. @apiErrorExample 操作成功
  329. {"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}}}
  330. @apiErrorExample 操作失败
  331. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  332. """
  333. @auth
  334. @Web.setting
  335. def get(self):
  336. id = self.input('id', None)
  337. device = self.input('device', None)
  338. if id and device:
  339. self.data['info'] = self.service('common').one('device_gateway', id=id)
  340. if not self.data['info']:
  341. self.out('no')
  342. return
  343. self.data['device'] = self.service('common').one('device_info', id=device)
  344. if not self.data['device']:
  345. self.out('no')
  346. return
  347. type = self.service('common').one('device_type', id=self.data['device']['type_id'])
  348. self.data['device']['unit'] = type['unit']
  349. self.out('yes', self.data)
  350. else:
  351. self.out('no')
  352. """
  353. @api {post} /device/set 更新极限值设置
  354. @apiVersion 1.0.0
  355. @apiName updateDeviceSet
  356. @apiGroup Device
  357. @apiParam {String} id 设备id
  358. @apiParam {String} update_max 最大上限
  359. @apiParam {String} update_min 最小下限
  360. @apiSuccess {Bool} status 状态
  361. @apiSuccess {String} msg 描述
  362. @apiSuccess {Number} code 状态码
  363. @apiErrorExample 操作成功
  364. {"status": 1, "msg": "操作成功", "code": 0, "data": {}}
  365. @apiErrorExample 操作失败
  366. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  367. """
  368. @auth
  369. @Web.setting
  370. def post(self):
  371. id = self.input('id', None)
  372. if not id:
  373. self.out('no')
  374. return
  375. device = self.service('common').one('device_info', id=id)
  376. if not device:
  377. self.out('no')
  378. return
  379. update = {}
  380. update['max'] = self.input('update_max')
  381. update['min'] = self.input('update_min')
  382. if not update['max']:
  383. self.out(u'请输入最大上限')
  384. return
  385. if not update['min']:
  386. self.out(u'请输入最小下限')
  387. return
  388. state = self.service('common').update('device_info', device['id'], update, cdate=False)
  389. self.out('yes', {'id':state})