#!/usr/bin/env python # -*- coding: utf-8 -*- """ demeter web name:device.py 设备相关 author:rabin """ from __load__ import * class index_path(Load): """ @api {get} /device 获取网关首页信息 @apiVersion 1.0.0 @apiName getDevice @apiGroup Device @apiParam {String} id 网关id @apiSuccess {Object[]} setting 基本信息 @apiSuccess {String} setting.name 站点名 @apiSuccess {Number} setting.farm 当前的农场ID @apiSuccess {Object[]} info 网关状态基本信息 @apiSuccess {String} info.id 网关ID @apiSuccess {String} info.name 网关名称 @apiSuccess {Bool} info.status 网关状态 @apiSuccess {Number} info.power 电量 @apiSuccess {Object[]} status 设备状态 @apiSuccess {Number} status.id 设备ID @apiSuccess {String} status.name 设备名称 @apiSuccess {String} status.show 显示的数据 @apiSuccess {String} status.unit 设备的单位 @apiSuccess {Number} status.max 设备的上限 @apiSuccess {Number} status.min 设备的下限 @apiSuccess {Bool} status.status 设备状态true在线 @apiSuccess {Object[]} device 设备数据 @apiSuccess {Number} device.id 设备ID @apiSuccess {String} device.name 设备名称 @apiSuccess {String} device.show 显示的数据 @apiSuccess {String} device.unit 设备的单位 @apiSuccess {Number} device.max 设备的上限 @apiSuccess {Number} device.min 设备的下限 @apiSuccess {Bool} device.status 设备状态true在线 @apiSuccess {Object[]} pic 图像数据 @apiSuccess {Number} pic.id 图片ID @apiSuccess {String} pic.name 图片名称 @apiSuccess {String} pic.show 图片地址 @apiSuccess {String} pic.cdates 采集时间 @apiSuccess {String} pic.cdate 采集时间戳 @apiErrorExample 操作成功 {"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}]}} @apiErrorExample 操作失败 {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}} """ @auth @Web.setting def get(self): id = self.input('id', None) if id: self.data['info'] = self.service('common').one('device_gateway', id=id) if not self.data['info']: self.out('no') return 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') 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') if self.data['device']: for key, value in enumerate(self.data['device']): type = self.service('common').one('device_type', id=value['type_id']) self.data['device'][key]['unit'] = type['unit'] self.data['pic'] = [] pic = self.service('common').list('device_info', state=True, search={'hardware_type':6, 'farm_id':self.data['info']['farm_id']}) if pic: for key, value in enumerate(pic): pic[key]['cdates'] = Demeter.date(value['cdate']) self.data['pic'] = pic self.out('yes', self.data) else: self.out('no') class list_path(Load): """ @api {get} /device/list 获取网关设备列表 @apiVersion 1.0.0 @apiName getDeviceList @apiGroup Device @apiSuccess {Object[]} setting 基本信息 @apiSuccess {String} setting.name 站点名 @apiSuccess {Number} setting.farm 当前的农场ID @apiSuccess {Object[]} list 网关信息(环境监测) @apiSuccess {String} list.name 网关名称 @apiSuccess {String} list.id 网关ID @apiErrorExample 操作成功 {"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": {}}} @apiErrorExample 操作失败 {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}} """ @auth @Web.setting def get(self): self.data['list'] = self.service('common').list('device_gateway', search={'farm_id': Demeter.config['setting']['farm']}) self.out('yes', self.data) class stat_path(Load): """ @api {get} /device/stat 获取数据统计 @apiVersion 1.0.0 @apiName getDeviceStat @apiGroup Device @apiParam {String} id 网关id @apiParam {String} device 设备id @apiParam {String} search_group 周期ID @apiParam {String} search_start 开始时间:2017-10-10 10:10:10 @apiParam {String} search_end 结束时间:2017-10-10 10:10:10 @apiSuccess {Object[]} setting 基本信息 @apiSuccess {String} setting.name 站点名 @apiSuccess {Number} setting.farm 当前的农场ID @apiSuccess {Object[]} info 网关状态基本信息 @apiSuccess {String} info.id 网关ID @apiSuccess {String} info.name 网关名称 @apiSuccess {Object[]} data 设备选择 @apiSuccess {Number} data.id 设备ID @apiSuccess {String} data.name 设备名称 @apiSuccess {Object[]} group 周期选择 @apiSuccess {Number} group.id 周期ID @apiSuccess {String} group.name 周期名称 @apiSuccess {Object[]} cur_device 当前选择的设备 @apiSuccess {Number} cur_device.id 设备ID @apiSuccess {String} cur_device.name 设备名称 @apiSuccess {Object[]} data 设备数据,两条线 @apiSuccess {String} data.name 本条数据名 @apiSuccess {Object[]} data.data 本条数据的具体数据 @apiSuccess {String} data.data.time 数据时间 @apiSuccess {String} data.data.value 数据具体的值 @apiSuccess {Object[]} search 当前搜索的值 @apiSuccess {String} search.group 周期的值 @apiSuccess {String} search.start 开始时间 @apiSuccess {String} search.end 结束时间 @apiErrorExample 操作成功 {"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"}]}} @apiErrorExample 操作失败 {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}} """ @auth @Web.setting def get(self): id = self.input('id', None) device = self.input('device', None) if id and device: self.data['info'] = self.service('common').one('device_gateway', id=id) if not self.data['info']: self.out('no') return self.data['cur_device'] = self.service('common').one('device_info', id=device) if not self.data['cur_device']: self.out('no') return 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') model = Demeter.model('data', 'tsdb') self.data['group'] = model.dateConfig() search_group = self.input('search_group') search_start = self.input('search_start') search_end = self.input('search_end') search = {} if search_group: search['group'] = search_group else: search['group'] = '1' if search_start: search['start'] = search_start if search_end: search['end'] = search_end method = 'maxmin' self.data['search'] = search self.data['data'] = model.getData(method, search, self.data['cur_device']) self.out('yes', self.data) else: self.out('no') class pic_path(Load): """ @api {get} /device/pic 获取图像记录 @apiVersion 1.0.0 @apiName getDevicePic @apiGroup Device @apiParam {String} page 页数 @apiParam {String} id 网关id @apiParam {String} search_date 拍照时间:2017-10-10 @apiSuccess {Object[]} setting 基本信息 @apiSuccess {String} setting.name 站点名 @apiSuccess {Number} setting.farm 当前的农场ID @apiSuccess {Object[]} info 网关状态基本信息 @apiSuccess {String} info.id 网关ID @apiSuccess {String} info.name 网关名称 @apiSuccess {Object[]} pic 图像数据 @apiSuccess {Number} pic.id 图片ID @apiSuccess {String} pic.name 图片名称 @apiSuccess {String} pic.show 图片地址 @apiSuccess {String} pic.cdates 采集时间 @apiSuccess {String} pic.cdate 采集时间戳 @apiSuccess {Object[]} search 当前搜索的值 @apiSuccess {String} search.date 拍照时间 @apiSuccess {String} url 网站url @apiSuccess {Object[]} page 分页信息 @apiSuccess {String} page.current 当前页 @apiSuccess {String} page.total 总页数 @apiSuccess {String} page.num 每页数据条数 @apiSuccess {String} page.totalNum 总数据条数 @apiErrorExample 操作成功 {"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}}} @apiErrorExample 操作失败 {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}} """ @auth @Web.setting def get(self): id = self.input('id', None) device = self.input('device', None) if device: """ self.data['info'] = self.service('common').one('device_gateway', id=id) if not self.data['info']: self.out('no') return """ self.data['url'] = self.request.protocol + "://" + self.request.host + '/' self.data['search_date'] = self.input('search_date') search = {} #search['gateway_id'] = id search['device_id'] = device if self.data['search_date']: search['cdate-time-start'] = self.data['search_date'] + ' 00:00:00' search['cdate-time-end'] = self.data['search_date'] + ' 23:59:59' self.data['pic'] = self.service('common').list('device_pic', state=True, search=search, page=True) if self.data['pic']: for key, value in enumerate(self.data['pic']): self.data['pic'][key]['cdates'] = Demeter.date(value['cdate']) self.data['pic'][key]['pic'] = 'https://api.nongxiaohe.com' + value['pic'] self.out('yes', self.data) else: self.out('no') class picup_path(Load): def get(self): update = {} update['gateway_id'] = '542535db-6c0b-51fc-9f73-cafb3872ce76' update['device_id'] = '6e78c955-e3be-5edb-b0c2-e6c5c88fd95a' update['pic'] = 'http://xinnongbaohe.oss-cn-shanghai.aliyuncs.com/cp/bjbg1/1.jpg' state = self.service('common').update('device_pic', False, update) self.out('yes', {'id':state}) class msgup_path(Load): def get(self): update = {} update['device_id'] = '6e78c955-e3be-5edb-b0c2-e6c5c88fd95a' update['type_id'] = 1 update['content'] = '错误提示打发打发' state = self.service('common').update('msg', False, update) self.out('yes', {'id':state}) class msg_path(Load): """ @api {get} /device/msg 获取设备日志 @apiVersion 1.0.0 @apiName getDeviceMsg @apiGroup Device @apiParam {String} page 页数 @apiParam {String} id 网关id @apiParam {String} device 设备id @apiSuccess {Object[]} setting 基本信息 @apiSuccess {String} setting.name 站点名 @apiSuccess {Number} setting.farm 当前的农场ID @apiSuccess {Object[]} msg 日志列表 @apiSuccess {Number} msg.id 日志ID @apiSuccess {String} msg.content 日志内容 @apiSuccess {String} msg.cdates 日志时间 @apiSuccess {String} msg.cdate 日志时间戳 @apiSuccess {Object[]} page 分页信息 @apiSuccess {String} page.current 当前页 @apiSuccess {String} page.total 总页数 @apiSuccess {String} page.num 每页数据条数 @apiSuccess {String} page.totalNum 总数据条数 @apiErrorExample 操作成功 {"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"}}} @apiErrorExample 操作失败 {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}} """ @auth @Web.setting def get(self): id = self.input('id', None) if id: self.data['info'] = self.service('common').one('device_gateway', id=id) if not self.data['info']: self.out('no') return device = self.service('common').list('device_info', search={'gateway_id':id}, order='inorder asc, type_id asc,udate asc,hardware_id asc') if not device: self.out('no') return devices = [] if device: for key, value in enumerate(device): devices.append(value['id']) search = {} search['device_id--ins'] = devices self.data['msg'] = self.service('common').list('msg', state=True, search=search, page=True) if self.data['msg']: for key, value in enumerate(self.data['msg']): self.data['msg'][key]['cdates'] = Demeter.date(value['cdate']) type = self.service('common').one('msg_type', id=value['type_id']) self.data['msg'][key]['type_name'] = type['name'] self.out('yes', self.data) else: self.out('no') class set_path(Load): """ @api {get} /device/set 获取设备极限值信息 @apiVersion 1.0.0 @apiName getDeviceSet @apiGroup Device @apiParam {String} id 网关id @apiParam {String} device 设备id @apiSuccess {Object[]} setting 基本信息 @apiSuccess {String} setting.name 站点名 @apiSuccess {Number} setting.farm 当前的农场ID @apiSuccess {Object[]} device 设备数据 @apiSuccess {Number} device.id 设备ID @apiSuccess {String} device.name 设备名称 @apiSuccess {String} device.show 显示的数据 @apiSuccess {String} device.unit 设备的单位 @apiSuccess {Number} device.max 设备的上限 @apiSuccess {Number} device.min 设备的下限 @apiSuccess {Bool} device.status 设备状态 @apiErrorExample 操作成功 {"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}}} @apiErrorExample 操作失败 {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}} """ @auth @Web.setting def get(self): id = self.input('id', None) device = self.input('device', None) if id and device: self.data['info'] = self.service('common').one('device_gateway', id=id) if not self.data['info']: self.out('no') return self.data['device'] = self.service('common').one('device_info', id=device) if not self.data['device']: self.out('no') return type = self.service('common').one('device_type', id=self.data['device']['type_id']) self.data['device']['unit'] = type['unit'] self.out('yes', self.data) else: self.out('no') """ @api {post} /device/set 更新极限值设置 @apiVersion 1.0.0 @apiName updateDeviceSet @apiGroup Device @apiParam {String} id 设备id @apiParam {String} update_max 最大上限 @apiParam {String} update_min 最小下限 @apiSuccess {Bool} status 状态 @apiSuccess {String} msg 描述 @apiSuccess {Number} code 状态码 @apiErrorExample 操作成功 {"status": 1, "msg": "操作成功", "code": 0, "data": {}} @apiErrorExample 操作失败 {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}} """ @auth @Web.setting def post(self): id = self.input('id', None) if not id: self.out('no') return device = self.service('common').one('device_info', id=id) if not device: self.out('no') return update = {} update['max'] = self.input('update_max') update['min'] = self.input('update_min') if not update['max']: self.out(u'请输入最大上限') return if not update['min']: self.out(u'请输入最小下限') return state = self.service('common').update('device_info', device['id'], update, cdate=False) self.out('yes', {'id':state})