rabin 7 years ago
parent
commit
bf8301a2f0

+ 3 - 1
admin/page/__load__.py

@@ -53,10 +53,12 @@ class Load(Base):
 		self.data['setting']['farmList'] = self.service('common').list('farm')
 
 	def menu(self):
+		#parent = [['农场与设备管理', '网站管理', '基础设置', '版本发布'],['', '', '', '']]
 		parent = [['农场与设备管理', '网站管理', '基础设置'],['', '', '']]
 		child = [
-			[['/farm/farm','/farm/product','/device/gateway','/device/info','/device/info?search_status-hidden-=1','/work/work','/work/category','/work/method','/work/land','/origin/batch','/farm/user','/device/printer','/msg/msg'],['农场列表', '农场产品管理', '网关管理', '设备管理', '离线设备列表', '农场农事管理', '农场农事分类', '农场劳作方式', '农场地块管理', '溯源批次管理','农场用户管理','打印机管理', '消息提醒']]
+			[['/farm/farm','/farm/product','/device/gateway','/device/info','/device/info?search_status-hidden-=1','/work/work','/work/category','/work/method','/work/land','/origin/batch','/farm/user','/device/printer','/msg/msg','/device/log'],['农场列表', '农场产品管理', '网关管理', '设备管理', '离线设备列表', '农场农事管理', '农场农事分类', '农场劳作方式', '农场地块管理', '溯源批次管理','农场用户管理','打印机管理', '消息提醒', '网关日志']]
 			,[['/web/set','/web/help_category','/web/help','/web/category','/web/article','/web/menu'],['网站资料设置', '帮助分类', '发布帮助内容', '文章分类', '发布内容文章', '菜单管理']]
 			,[['/device/type','/hardware/type','/device/notice_type','/msg/type','/admin/admin','/admin/role','/hardware/hardware', '/admin/log'],['设备类型管理','硬件类型管理', '设备错误码设置', '消息类型设置', '管理员设置', '管理权限设置','硬件设备记录', '系统日志']]
+			#,[['/package/package','/package/version'],['Package管理', '版本管理']]
 			]
 		return (parent,child)

+ 27 - 33
admin/page/device.py

@@ -10,7 +10,6 @@ from __load__ import *
 class gateway_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		self.common(
 			name = u'网关'
@@ -48,7 +47,6 @@ class gateway_path(Load):
 class gateway_update_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		id = self.input('id')
 		if id:
@@ -65,20 +63,17 @@ class gateway_update_path(Load):
 		self.commonView('update')
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def post(self):
 		id = self.commonUpdate('device_gateway')
 		self.device(id)
 
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def delete(self):
 		self.commonDelete('device_gateway')
 
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def device(self, id):
 		info = self.service('common').one('device_gateway', id=id)
 		hardware_id = info['hardware_id']
@@ -87,7 +82,6 @@ class gateway_update_path(Load):
 class info_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		self.common(
 			name = u'设备'
@@ -165,7 +159,6 @@ class info_path(Load):
 
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def post(self):
 		id = self.input('id')
 		value = self.input('value')
@@ -178,7 +171,6 @@ class info_path(Load):
 class info_update_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		self.commonOne('device_info')
 		if self.data['info']['hardware_type'] == 7:
@@ -217,12 +209,10 @@ class info_update_path(Load):
 		self.commonView('update')
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def post(self):
 		self.commonUpdate('device_info')
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def delete(self):
 		self.commonDelete('device_info')
 		"""
@@ -237,14 +227,12 @@ class info_update_path(Load):
 class camera_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		self.redirect('/device/info?search_hardware_type=7')
 
 class camera_update_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		self.common(
 			path = 'camera'
@@ -257,28 +245,24 @@ class camera_update_path(Load):
 		self.commonView('update')
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def post(self):
 		self.data['update']['hardware_type'] = 7
 		self.data['update']['type_id'] = 0
 		self.commonUpdate('device_info')
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def delete(self):
 		self.commonDelete('device_info')
 
 class camera_pic_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		self.redirect('/device/info?search_hardware_type=6')
 
 class camera_pic_update_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		self.common(
 			path = 'camera_pic'
@@ -291,21 +275,18 @@ class camera_pic_update_path(Load):
 		self.commonView('update')
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def post(self):
 		self.data['update']['hardware_type'] = 6
 		self.data['update']['type_id'] = 0
 		self.commonUpdate('device_info')
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def delete(self):
 		self.commonDelete('device_info')
 
 class pic_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		self.common(
 			name = u'摄像头图片'
@@ -329,7 +310,6 @@ class pic_path(Load):
 class stat_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		method = self.input('method', 'avg')
 		id = self.input('id')
@@ -363,7 +343,6 @@ class stat_path(Load):
 class type_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		self.common(
 			name = u'类型'
@@ -381,7 +360,6 @@ class type_path(Load):
 class type_update_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		self.common(
 			path = 'type'
@@ -394,12 +372,10 @@ class type_update_path(Load):
 		self.commonView('update')
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def post(self):
 		self.commonUpdate('device_type')
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def delete(self):
 		self.commonDelete('device_type')
 
@@ -407,7 +383,6 @@ class type_update_path(Load):
 class printer_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		self.common(
 			name = u'打印机'
@@ -430,7 +405,6 @@ class printer_path(Load):
 class printer_update_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		self.common(
 			path = 'printer'
@@ -442,12 +416,10 @@ class printer_update_path(Load):
 		self.commonView('update')
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def post(self):
 		self.commonUpdate('device_printer')
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def delete(self):
 		self.commonDelete('device_printer')
 
@@ -455,7 +427,6 @@ class printer_update_path(Load):
 class notice_type_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		self.common(
 			name = u'错误码设置'
@@ -473,7 +444,6 @@ class notice_type_path(Load):
 class notice_type_update_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		self.common(
 			path = '/device/notice_type'
@@ -484,11 +454,35 @@ class notice_type_update_path(Load):
 		self.commonView('update')
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def post(self):
 		self.commonUpdate('notice_type')
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def delete(self):
-		self.commonDelete('notice_type')
+		self.commonDelete('notice_type')
+
+class log_path(Load):
+	@Web.auth
+	@Web.setting
+	def get(self):
+		self.common(
+			name = u'网关日志'
+			,path = '/device/log'
+			,width = '600'
+			,height = '600'
+			,add = False
+			,edit = False
+			,search = (('farm_id-select-','content-input-mlike'), (u'选择农场', u'内容'))
+			,thead = (u'所属农场', u'所属网关', u'日志内容',u'发送时间')
+			,tbody = ('farm','gateway', 'content', 'cdate')
+			,state = False
+		)
+		self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
+		self.commonList('log')
+		if self.data['list']:
+			for key, value in enumerate(self.data['list']):
+				farm = self.service('common').one('farm', id=value['farm_id'])
+				self.data['list'][key]['farm'] = farm['name']
+				gateway = self.service('common').one('device_gateway', id=value['gateway_id'])
+				self.data['list'][key]['gateway'] = gateway['name']
+		self.commonView('list')

+ 3 - 2
admin/page/farm.py

@@ -18,8 +18,8 @@ class farm_path(Load):
 			,height = '600' # 新增页面的高度
 			,edit = False
 			,search = (('label-1','cdate-time-start','cdate-time-end','name-input-mlike'), (u'日期范围',u'开始时间',u'截止时间',u'农场名称')) #搜索
-			,thead = (u'农场名称', u'功能列表') #表头
-			,tbody = ('name', 'func') #表内容
+			,thead = (u'ID', u'农场名称', u'功能列表') #表头
+			,tbody = ('id','name', 'func') #表内容
 			,state = False #启用回收站
 		)
 		menu = (
@@ -35,6 +35,7 @@ class farm_path(Load):
 			,{'name':'用户管理', 'url':'/farm/user'}
 			,{'name':'打印机管理', 'url':'/device/printer'}
 			,{'name':'消息提醒', 'url':'/msg/msg'}
+			,{'name':'网关日志', 'url':'/device/log'}
 			)
 		self.commonList('farm')
 		if self.data['list']:

+ 4 - 2
admin/page/msg.py

@@ -96,8 +96,10 @@ class type_update_path(Load):
 	def get(self):
 		self.common(
 			path = '/msg/type'
-			,label = (u'类型名称', u'类型key',u'推送')
-			,update = ('name-input-required', 'key-input-required','push-checkbox-')
+			#,label = (u'类型名称', u'类型key',u'推送')
+			#,update = ('name-input-required', 'key-input-required','push-checkbox-')
+			,label = (u'类型名称', u'类型key')
+			,update = ('name-input-required', 'key-input-required')
 			,update_push = push
 		)
 		self.commonOne('msg_type')

+ 88 - 0
admin/page/package.py

@@ -0,0 +1,88 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+    demeter web page
+    name:package.py 版本相关
+    author:rabin
+"""
+from __load__ import *
+
+class version_path(Load):
+	@Web.auth
+	@Web.setting
+	def get(self):
+		self.common(
+			name = u'版本'
+			,path = '/package/version'
+			,width = '600'
+			,height = '600'
+			,search = (('package_id-select-','name-input-mlike','version-input-mlike'), (u'选择Package', u'版本名称', u'版本号'))
+			,thead = (u'所属Package', u'版本名称', u'版本号', u'创建时间')
+			,tbody = ('package','name', 'version', 'cdate')
+			,state = False
+		)
+		self.data['common']['search_package-select-'] = self.service('common').list('package')
+		self.commonList('package_version')
+		if self.data['list']:
+			for key, value in enumerate(self.data['list']):
+				package = self.service('common').one('package', id=value['package_id'])
+				self.data['list'][key]['package'] = package['name']
+		self.commonView('list')
+
+class version_update_path(Load):
+	@Web.auth
+	@Web.setting
+	def get(self):
+		self.common(
+			path = '/package/version'
+			,label = (u'所属Package',u'版本名称',u'版本号')
+			,update = ('package_id-select','name-input-required','name-input-required')
+			,update_package_id = self.service('common').list('package')
+		)
+		self.commonOne('package_version')
+		self.commonView('update')
+	@Web.auth
+	@Web.setting
+	def post(self):
+		self.commonUpdate('package_version')
+	@Web.auth
+	@Web.setting
+	def delete(self):
+		self.commonDelete('package_version')
+
+class package_path(Load):
+	@Web.auth
+	@Web.setting
+	def get(self):
+		self.common(
+			name = u'Package'
+			,path = '/package/package'
+			,width = '600'
+			,height = '300'
+			,search = (('name-input-mlike','url-input-mlike'), (u'名称',u'地址'))
+			,thead = (u'ID', u'名称',u'地址', u'更新时间')
+			,tbody = ('id', 'name', 'url', 'cdate')
+			,state = False
+		)
+		self.commonList('package')
+		self.commonView('list')
+
+class package_update_path(Load):
+	@Web.auth
+	@Web.setting
+	def get(self):
+		self.common(
+			path = '/package/package'
+			,label = (u'名称', u'地址')
+			,update = ('name-input-required', 'url-input-required')
+		)
+		self.commonOne('package')
+		self.commonView('update')
+	@Web.auth
+	@Web.setting
+	def post(self):
+		self.commonUpdate('package')
+	@Web.auth
+	@Web.setting
+	def delete(self):
+		self.commonDelete('package')

+ 1 - 1
conf/env.conf

@@ -19,7 +19,7 @@ password			= public
 timeout				= 60
 ;topic定义
 topic				= method/type/gateway/device
-sub					= pic,sensor,control,power,status
+sub					= pic,sensor,control,power,status,log
 
 [postgresql]
 host				= iot-pgsql

+ 51 - 9
cron.py

@@ -10,6 +10,7 @@ from demeter.core import *
 from gevent import monkey; monkey.patch_socket()
 import gevent
 from pic import pic
+from demeter.mqtt import *
 # 处理定时命令、周期命令、条件控制、消息、设备状态等
 timeSleep = 10
 
@@ -41,22 +42,51 @@ def control():
 		type_model = Demeter.model('device_type')
 		cur = Demeter.time() - 10
 		model.cdate.assgin(cur, '<=')
+		model.oper = True
 		model.hardware_type = 3
 		service = Demeter.service('device')
 		data = model.select()
-		for v in data:
-			model.id = v['id']
-			if v['exp'] == '-1':
-				msg = service.notice('timeout')
-				service.mul(v['id'], v['type_id'], v['name'], v['cxnum'], '失败:' + msg, False)
-			else:
-				msg = '1'
-				service.mul(v['id'], v['type_id'], v['name'], v['cxnum'], '', True)
-			model.update(exp=msg)
+		if data:
+			for v in data:
+				model.id = v['id']
+				if v['exp'] == '-1':
+					msg = service.notice('timeout')
+					service.mul(v['id'], v['type_id'], v['name'], v['cxnum'], '失败:' + msg, False)
+					model.update(exp=msg)
+				else:
+					msg = '1'
+					service.mul(v['id'], v['type_id'], v['name'], v['cxnum'], '', True)
+					model.update(exp=msg, oper=False)
 
 		gevent.sleep(timeSleep)
 		
 
+# 批量控制的队列
+def mulQueue():
+	while 1:
+		model = Demeter.model('device_mul_queue')
+		model.status = 1
+		data = model.select(type='fetchone', order='device_id asc')
+		service = Demeter.service('device')
+		if data and not data['oper']:
+			model.id = data['id']
+			service.switch(data['device_id'], switch=data['value'])
+			model.update(oper=True)
+
+		gevent.sleep(1)
+
+# 批量控制的队列清理,10小时清理一次24小时之前完成的数据
+def mulQueueDrop():
+	while 1:
+		num = 3600*24
+		model = Demeter.model('device_mul_queue')
+		model.status.ins((2,3))
+		cur = Demeter.time() - num
+		model.cdate.assgin(cur, '<=')
+		model.delete()
+
+		gevent.sleep(36000)
+
 def timing():
 	while 1:
 		model = Demeter.model('device_set_timing')
@@ -102,6 +132,15 @@ def savePic():
 		pic()
 		gevent.sleep(1800)
 
+# 同步时间,24小时同步一次
+def timeSync():
+	while 1:
+		pub = Pub()
+		key = 'time/bh'
+		value = Demeter.date(Demeter.time())
+		pub.push(key, value)
+		gevent.sleep(3600*24)
+
 def handle():
 	gevent.joinall([
 		gevent.spawn(timing),
@@ -109,6 +148,9 @@ def handle():
 		gevent.spawn(device),
 		gevent.spawn(savePic),
 		gevent.spawn(control),
+		gevent.spawn(timeSync),
+		gevent.spawn(mulQueue),
+		gevent.spawn(mulQueueDrop),
 	])
 
 handle()

+ 11 - 37
front/page/device.py

@@ -6,11 +6,11 @@
     author:rabin
 """
 from __load__ import *
+from demeter.mqtt import *
 # 首页
 class index_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		# 获取网关列表
 		self.data['gateway'] = self.service('common').list('device_gateway', state=True, search={'farm_id':self.data['setting']['farm']})
@@ -22,19 +22,19 @@ class index_path(Load):
 class mul_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		self.data['list'] = self.service('common').list('device_mul', search={'farm_id':self.data['setting']['farm']})
 		if self.data['list']:
 			for key, value in enumerate(self.data['list']):
-				info = self.service('common').one('device_mul_queue', mul_id=value['id'])
+				model = Demeter.model('device_mul_queue')
+				model.status = 1
+				info = model.select(type='fetchone')
 				if not info:
 					self.data['list'][key]['oper'] = ''
 		self.view("device/mul.html")
 
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def post(self):
 		id = self.input('id')
 		value = self.input('value')
@@ -69,7 +69,6 @@ class mul_path(Load):
 class screen_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		device = self.input('device')
 
@@ -115,7 +114,6 @@ class screen_path(Load):
 class screen_set_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		self.data['info'] = self.data['setting']['farmInfo']
 		self.data['info']['devices'] = self.data['info']['gateway']
@@ -125,7 +123,6 @@ class screen_set_path(Load):
 
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def post(self):
 		id = self.input('id')
 		update = {}
@@ -135,6 +132,13 @@ class screen_set_path(Load):
 			self.out(u'请选择设备')
 			return
 		update['gateway'] = str(update['gateway'])
+		if update['welcome']:
+			value = update['welcome']
+		else:
+			value = self.data['setting']['farmInfo']['name']
+		key = 'update/w/' + id
+		pub = Pub()
+		pub.push(key, value)
 		state = self.service('common').update('farm', id, update)
 		self.out('yes', {'id':state})
 
@@ -142,7 +146,6 @@ class screen_set_path(Load):
 class data_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		Device.data(self)
 		if 'stat' in self.data and self.data['stat']:
@@ -153,7 +156,6 @@ class data_path(Load):
 class pic_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		Device.pic(self)
 		self.view("device/pic.html")
@@ -162,7 +164,6 @@ class pic_path(Load):
 class stat_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		Device.stat(self)
 		self.view("device/stat.html")
@@ -171,7 +172,6 @@ class stat_path(Load):
 class log_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		Device.log(self)
 		self.view("device/logs.html")
@@ -180,7 +180,6 @@ class log_path(Load):
 class group_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		# 获取页面
 		self.data['page'] = self.service('common').list('device_page', order='inorder asc,cdate desc', search={'farm_id':self.data['setting']['farm']})
@@ -197,7 +196,6 @@ class group_path(Load):
 class update_device_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		id = self.input('device_id')
 		if id:
@@ -213,7 +211,6 @@ class update_device_path(Load):
 
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def post(self):
 		id = self.input('id')
 		update = {}
@@ -234,7 +231,6 @@ class update_device_path(Load):
 class update_page_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		id = self.input('id')
 		#self.data['ico'] = ('cj', 'kz', 'syt', 'wg', 'pl', 'dpm', 'fz', 'zn')
@@ -248,7 +244,6 @@ class update_page_path(Load):
 
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def post(self):
 		id = self.input('id')
 		update = {}
@@ -276,7 +271,6 @@ class update_page_path(Load):
 class update_group_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		page = self.input('page')
 		self.data['page'] = self.service('common').one('device_page', id=page)
@@ -292,7 +286,6 @@ class update_group_path(Load):
 
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def post(self):
 		id = self.input('id')
 		update = {}
@@ -315,7 +308,6 @@ class update_group_path(Load):
 
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def delete(self):
 		id = self.input('id')
 		if not id:
@@ -328,7 +320,6 @@ class update_group_path(Load):
 class set_mul_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		self.data['name'] = '批量控制'
 		Device.set(self)
@@ -342,7 +333,6 @@ class set_mul_path(Load):
 class update_set_mul_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		id = self.input('id')
 		self.data['info'] = {}
@@ -356,7 +346,6 @@ class update_set_mul_path(Load):
 
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def post(self):
 		id = self.input('id')
 		update = {}
@@ -378,7 +367,6 @@ class update_set_mul_path(Load):
 
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def delete(self):
 		id = self.input('id')
 		if not id:
@@ -391,7 +379,6 @@ class update_set_mul_path(Load):
 class set_timing_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		self.data['name'] = '定时设置'
 		Device.set(self)
@@ -421,7 +408,6 @@ class set_timing_path(Load):
 class update_set_timing_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		id = self.input('id')
 		Device.setCronOper(self)
@@ -437,7 +423,6 @@ class update_set_timing_path(Load):
 
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def post(self):
 		id = self.input('id')
 		update = {}
@@ -460,7 +445,6 @@ class update_set_timing_path(Load):
 
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def delete(self):
 		id = self.input('id')
 		if not id:
@@ -473,7 +457,6 @@ class update_set_timing_path(Load):
 class set_loop_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		self.data['name'] = '周期设置'
 		Device.set(self)
@@ -511,7 +494,6 @@ class set_loop_path(Load):
 class update_set_loop_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		id = self.input('id')
 		Device.setCronOper(self)
@@ -525,7 +507,6 @@ class update_set_loop_path(Load):
 
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def post(self):
 		id = self.input('id')
 		update = {}
@@ -556,7 +537,6 @@ class update_set_loop_path(Load):
 
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def delete(self):
 		id = self.input('id')
 		if not id:
@@ -572,7 +552,6 @@ class update_set_loop_path(Load):
 class set_condition_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		self.data['name'] = '条件控制'
 		Device.set(self)
@@ -603,7 +582,6 @@ class set_condition_path(Load):
 class update_set_condition_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		id = self.input('id')
 		Device.setCronOper(self)
@@ -618,7 +596,6 @@ class update_set_condition_path(Load):
 
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def post(self):
 		id = self.input('id')
 		update = {}
@@ -658,7 +635,6 @@ class update_set_condition_path(Load):
 
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def delete(self):
 		id = self.input('id')
 		if not id:
@@ -674,7 +650,6 @@ class update_set_condition_path(Load):
 class update_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def post(self):
 		id = self.input('id')
 		value = self.input('value')
@@ -707,7 +682,6 @@ class update_path(Load):
 class get_path(Load):
 	@Web.auth
 	@Web.setting
-	@Web.setting
 	def get(self):
 		# 根据网关id获取设备
 		id = self.input('id')

File diff suppressed because it is too large
+ 0 - 0
front/static/mobile/css/global.css


File diff suppressed because it is too large
+ 0 - 0
front/static/pc/css/global.css


+ 11 - 1
front/static/pc/js/main.js

@@ -60,15 +60,22 @@ var Farm =
 	{
 		var self = this;
 		var e = $(obj);
+		var c = e.attr('class');
+		if ($('.loading').length) {
+			return;
+		}
 		if (e.attr('class').indexOf('loading') > -1) {
 			return;
 		}
+		if (c.indexOf('disabled') != -1) {
+			return;
+		}
 		var value = e.attr('data-status');
 		data = {};
 		data.id = id;
 		data.value = value;
 		if (value == 1) {
-			e.attr('data-status', 0);
+			e.attr('data-status', 2);
 		} else {
 			e.attr('data-status', 1);
 		}
@@ -104,6 +111,9 @@ var Farm =
 		var e = $(obj);
 		var c = e.attr('class');
 		var p = e.parent();
+		if ($('.loading').length) {
+			return;
+		}
 		if (p.find('.loading').length) {
 			return;
 		}

+ 8 - 4
front/templates/mobile/device/inc/data.html

@@ -38,12 +38,14 @@
         {%set layer = value['exp'] %}
         {% end %}
         <label><span>{{value['name']}}</span>
+        {% if value['status'] == False %}<span class="disable">离线</span>{% end %}
         <p>
-        <button {% if layer %}data-hint="{{layer}}"{% end %} onclick="Farm.Button(this, '/device/update', '{{value['id']}}', 1, '#button_down_{{value['id']}}')" id="button_up_{{value['id']}}" class="btn btn-switch {% if layer and value['cxnum'] in (1,4) %}hint--top hint--error hint--always {% end %} {% if value['exp'] == '-1' and value['cxnum'] in (1,4) %}loading{% end %} {% if value['value'] in ('2','3') %}disabled{% end %} {% if value['value'] in ('1','4') %}open{% end %}"></button>
 
-        <button {% if layer %}data-hint="{{layer}}"{% end %} onclick="Farm.Button(this, '/device/update', '{{value['id']}}', 5)" id="button_stop_{{value['id']}}" class="btn btn-switch {% if layer and value['cxnum'] == 5 %}hint--top hint--error hint--always {% end %} {% if value['exp'] == '-1' and value['cxnum'] == 5 %}loading{% end %} {% if value['value'] == '5' %}open{% end %}"></button>
+        <button {% if layer %}data-hint="{{layer}}"{% end %} onclick="Farm.Button(this, '/device/update', '{{value['id']}}', 1, '#button_down_{{value['id']}}')" id="button_up_{{value['id']}}" class="btn btn-switch {% if layer and value['cxnum'] in (1,4) %}hint--top hint--error hint--always {% end %} {% if value['exp'] == '-1' and value['cxnum'] in (1,4) %}loading{% end %} {% if value['value'] in ('2','3') %}disabled{% end %} {% if value['value'] in ('1','4') %}open{% end %} {% if value['status'] == False %}disabled{% end %}"></button>
 
-        <button {% if layer %}data-hint="{{layer}}"{% end %} onclick="Farm.Button(this, '/device/update', '{{value['id']}}', 2, '#button_up_{{value['id']}}')" id="button_down_{{value['id']}}" class="btn btn-switch {% if layer and value['cxnum'] in (2,3) %}hint--top hint--error hint--always {% end %} {% if value['exp'] == '-1' and value['cxnum'] in (2,3) %}loading{% end %} {% if value['value'] in ('1','4') %}disabled{% end %} {% if value['value'] in ('2','3') %}open{% end %}"></button>
+        <button {% if layer %}data-hint="{{layer}}"{% end %} onclick="Farm.Button(this, '/device/update', '{{value['id']}}', 5)" id="button_stop_{{value['id']}}" class="btn btn-switch {% if layer and value['cxnum'] == 5 %}hint--top hint--error hint--always {% end %} {% if value['exp'] == '-1' and value['cxnum'] == 5 %}loading{% end %} {% if value['value'] == '5' %}open{% end %} {% if value['status'] == False %}disabled{% end %}"></button>
+
+        <button {% if layer %}data-hint="{{layer}}"{% end %} onclick="Farm.Button(this, '/device/update', '{{value['id']}}', 2, '#button_up_{{value['id']}}')" id="button_down_{{value['id']}}" class="btn btn-switch {% if layer and value['cxnum'] in (2,3) %}hint--top hint--error hint--always {% end %} {% if value['exp'] == '-1' and value['cxnum'] in (2,3) %}loading{% end %} {% if value['value'] in ('1','4') %}disabled{% end %} {% if value['value'] in ('2','3') %}open{% end %} {% if value['status'] == False %}disabled{% end %}"></button>
         </p>
         </label>
             
@@ -55,7 +57,9 @@
         {% if value['exp'] != '-1' and  value['exp'] != '1' and value['exp'] != 'None' and value['exp'] %}
         {%set layer = value['exp'] %}
         {% end %}
-        <label><span>{{value['name']}}</span><p><a href="javascript:;" {% if layer %}data-hint="{{layer}}"{% end %} data-status="{% if value['value'] == '1' %}0{% else %}1{% end %}"  onclick="Farm.Switch(this, '/device/update', '{{value['id']}}')" class="{% if layer %}hint--left hint--error hint--always {% end %} {% if value['exp'] != '-1' and  value['exp'] != '1' %}data-layer{% end %} btn btn-switch {% if value['exp'] == '-1' %}loading{% end %} {% if value['value'] == '1' %}open{% end %}"><i></i></a></p></label>
+        <label><span>{{value['name']}}</span>
+        {% if value['status'] == False %}<span class="disable">离线</span>{% end %}
+        <p><a href="javascript:;" {% if layer %}data-hint="{{layer}}"{% end %} data-status="{% if value['value'] == '1' %}2{% else %}1{% end %}"  onclick="Farm.Switch(this, '/device/update', '{{value['id']}}')" class="{% if layer %}hint--left hint--error hint--always {% end %} {% if value['exp'] != '-1' and  value['exp'] != '1' %}data-layer{% end %} btn btn-switch {% if value['exp'] == '-1' %}loading{% end %} {% if value['value'] == '1' %}open{% end %} {% if value['status'] == False %}disabled{% end %}"><i></i></a></p></label>
     </li>
 
     {% end %}

+ 1 - 1
front/templates/mobile/device/mul.html

@@ -55,7 +55,7 @@
 
         {% if value['device_type'] == 1 %}
         <li class="form-input">
-	        <label><span>{{value['name']}}</span><p><a {% if layer %}data-hint="{{layer}}"{% end %} href="javascript:;" data-status="{% if value['value'] == '1' %}0{% else %}1{% end %}"  onclick="Farm.Switch(this, '/device/mul', '{{value['id']}}')" class="{% if layer %}hint--left hint--info hint--always loading{% end %} btn btn-switch {% if value['value'] == '1' %}open{% end %}"><i></i></a></p></label>
+	        <label><span>{{value['name']}}</span><p><a {% if layer %}data-hint="{{layer}}"{% end %} href="javascript:;" data-status="{% if value['value'] == '1' %}2{% else %}1{% end %}"  onclick="Farm.Switch(this, '/device/mul', '{{value['id']}}')" class="{% if layer %}hint--left hint--info hint--always loading{% end %} btn btn-switch {% if value['value'] == '1' %}open{% end %}"><i></i></a></p></label>
 	    </li>
         {% else %}
         <li class="form-input buttons">

+ 6 - 6
front/templates/pc/device/inc/data.html

@@ -37,32 +37,32 @@
         {% elif value['hardware_type'] == 3 and value['unit'] == 'button' %}
         <dl class="button">
             {% if 'noset' not in data %}
-            <dd class="controller"></dd>
+            <dd class="controller">{% if value['status'] == False %}<em class="error">离线</em>{% end %}</dd>
             {% end %}
             {%set layer = '' %}
             {% if value['exp'] != '-1' and  value['exp'] != '1' and value['exp'] != 'None' and value['exp'] %}
             {%set layer = value['exp'] %}
             {% end %}
             <dt>
-                <button {% if layer %}data-hint="{{layer}}"{% end %} onclick="Farm.Button(this, '/device/update', '{{value['id']}}', 1, '#button_down_{{value['id']}}')" id="button_up_{{value['id']}}" class="btn-switch {% if layer and value['cxnum'] in (1,4) %}hint--top hint--error hint--always {% end %} {% if value['exp'] == '-1' and value['cxnum'] in (1,4) %}loading{% end %} {% if value['value'] in ('2','3') %}disabled{% end %} {% if value['value'] in ('1','4') %}open{% end %}"></button>
+                <button {% if layer %}data-hint="{{layer}}"{% end %} onclick="Farm.Button(this, '/device/update', '{{value['id']}}', 1, '#button_down_{{value['id']}}')" id="button_up_{{value['id']}}" class="btn-switch {% if layer and value['cxnum'] in (1,4) %}hint--top hint--error hint--always {% end %} {% if value['exp'] == '-1' and value['cxnum'] in (1,4) %}loading{% end %} {% if value['value'] in ('2','3') %}disabled{% end %} {% if value['value'] in ('1','4') %}open{% end %} {% if value['status'] == False %}disabled{% end %}"></button>
 
-                <button {% if layer %}data-hint="{{layer}}"{% end %} onclick="Farm.Button(this, '/device/update', '{{value['id']}}', 5)" id="button_stop_{{value['id']}}" class="btn-switch {% if layer and value['cxnum'] == 5 %}hint--top hint--error hint--always {% end %} {% if value['exp'] == '-1' and value['cxnum'] == 5 %}loading{% end %} {% if value['value'] == '5' %}open{% end %}"></button>
+                <button {% if layer %}data-hint="{{layer}}"{% end %} onclick="Farm.Button(this, '/device/update', '{{value['id']}}', 5)" id="button_stop_{{value['id']}}" class="btn-switch {% if layer and value['cxnum'] == 5 %}hint--top hint--error hint--always {% end %} {% if value['exp'] == '-1' and value['cxnum'] == 5 %}loading{% end %} {% if value['value'] == '5' %}open{% end %} {% if value['status'] == False %}disabled{% end %}"></button>
 
-                <button {% if layer %}data-hint="{{layer}}"{% end %} onclick="Farm.Button(this, '/device/update', '{{value['id']}}', 2, '#button_up_{{value['id']}}')" id="button_down_{{value['id']}}" class="btn-switch {% if layer and value['cxnum'] in (2,3) %}hint--top hint--error hint--always {% end %} {% if value['exp'] == '-1' and value['cxnum'] in (2,3) %}loading{% end %} {% if value['value'] in ('1','4') %}disabled{% end %} {% if value['value'] in ('2','3') %}open{% end %}"></button>
+                <button {% if layer %}data-hint="{{layer}}"{% end %} onclick="Farm.Button(this, '/device/update', '{{value['id']}}', 2, '#button_up_{{value['id']}}')" id="button_down_{{value['id']}}" class="btn-switch {% if layer and value['cxnum'] in (2,3) %}hint--top hint--error hint--always {% end %} {% if value['exp'] == '-1' and value['cxnum'] in (2,3) %}loading{% end %} {% if value['value'] in ('1','4') %}disabled{% end %} {% if value['value'] in ('2','3') %}open{% end %} {% if value['status'] == False %}disabled{% end %}"></button>
             </dt>
             <dd class="tit">{{value['name']}}</dd>          
         </dl>
         {% elif value['hardware_type'] == 3 %}
         <dl>
             {% if 'noset' not in data %}
-            <dd class="controller"></dd>
+            <dd class="controller">{% if value['status'] == False %}<em class="error">离线</em>{% end %}</dd>
             {% end %}
             {%set layer = '' %}
             {% if value['exp'] != '-1' and  value['exp'] != '1' and value['exp'] != 'None' and value['exp'] %}
             {%set layer = value['exp'] %}
             {% end %}
             <dt>
-                <p href="javascript:;" {% if layer %}data-hint="{{layer}}"{% end %} data-status="{% if value['value'] == '1' %}0{% else %}1{% end %}"  onclick="Farm.Switch(this, '/device/update', '{{value['id']}}')" class="{% if layer %}hint--top hint--error hint--always {% end %} {% if value['exp'] != '-1' and  value['exp'] != '1' %}data-layer{% end %} btn-switch {% if value['exp'] == '-1' %}loading{% end %} {% if value['value'] == '1' %}open{% end %}"><i></i></p>
+                <p href="javascript:;" {% if layer %}data-hint="{{layer}}"{% end %} data-status="{% if value['value'] == '1' %}2{% else %}1{% end %}"  onclick="Farm.Switch(this, '/device/update', '{{value['id']}}')" class="{% if layer %}hint--top hint--error hint--always {% end %} {% if value['exp'] != '-1' and  value['exp'] != '1' %}data-layer{% end %} btn-switch {% if value['exp'] == '-1' %}loading{% end %} {% if value['value'] == '1' %}open{% end %} {% if value['status'] == False %}disabled{% end %}"><i></i></p>
             </dt>
             <dd class="tit">{{value['name']}}</dd>          
         </dl>

+ 1 - 1
front/templates/pc/device/mul.html

@@ -49,7 +49,7 @@
                 <dd class="controller"></dd>
                 {% if value['device_type'] == 1 %}
                 <dt>
-                    <p href="javascript:;" {% if layer %}data-hint="{{layer}}"{% end %} data-status="{% if value['value'] == '1' %}0{% else %}1{% end %}"  onclick="Farm.Switch(this, '/device/mul', '{{value['id']}}')" class="{% if layer %}hint--top {{hint}} hint--always loading{% end %} btn-switch {% if value['value'] == '1' %}open{% end %}"><i></i></p>
+                    <p href="javascript:;" {% if layer %}data-hint="{{layer}}"{% end %} data-status="{% if value['value'] == '1' %}2{% else %}1{% end %}"  onclick="Farm.Switch(this, '/device/mul', '{{value['id']}}')" class="{% if layer %}hint--top {{hint}} hint--always loading{% end %} btn-switch {% if value['value'] == '1' %}open{% end %}"><i></i></p>
                 </dt>
                 {% else %}
                 <dt class="button">

+ 1 - 1
front/templates/pc/farm/edit.html

@@ -25,7 +25,7 @@
         </div>
         <div class="form-group"><span>联系电话</span><div class="formbox"><input type="text" name="update_tel" id="update_tel" placeholder="联系电话" value="{{data['setting']['farmInfo']['tel']}}"/></div></div>
         <div class="form-group"><span>联系地址</span><div class="formbox"><input type="text" name="update_address" id="update_address" placeholder="联系地址" value="{{data['setting']['farmInfo']['address']}}"/></div></div>
-        <div class="form-group"><span>欢迎语</span><div class="formbox"><input type="text" name="update_welcome" id="update_welcome" placeholder="欢迎语" value="{{data['setting']['farmInfo']['welcome']}}"/></div></div>
+        <div class="form-group" style="display:none;"><span>欢迎语</span><div class="formbox"><input type="text" name="update_welcome" id="update_welcome" placeholder="欢迎语" value="{{data['setting']['farmInfo']['welcome']}}"/></div></div>
         <div class="form-group">
             <input type="submit" name="" class="button big primary" value="修改确认">
         </div>

+ 3 - 2
model/device_info.py

@@ -29,7 +29,8 @@ class Device_info(Model):
 	cdate = Fields(type='int', default='time', comment='创建时间')
 	udate = Fields(type='int', default='time', comment='接入时间')
 	inorder = Fields(type='int', default='0', comment='排序', match='number|排序必须是数字')
-
-	#ALTER TABLE demeter_device_info ADD exp varchar(500); 
+	oper = Fields(type='boolean', default='False', comment='操作类型')
+	##ALTER TABLE demeter_device_info ADD exp varchar(500); 
 	#ALTER TABLE demeter_device_info ADD inorder int default 100; 
+	#ALTER TABLE demeter_device_info ADD oper boolean; 
 	#ALTER TABLE demeter_device_info DROP inorder;   

+ 1 - 0
model/device_mul.py

@@ -16,6 +16,7 @@ class Device_mul(Model):
 	devices = Fields(type='text', comment='设备id,逗号隔开')
 	oper = Fields(type='varchar(500)', comment='操作状态')
 	value = Fields(type='varchar(10)', comment='开关状态')
+	old = Fields(type='varchar(10)', comment='上次开关状态')
 	device_type = Fields(type='int', comment='设备类型,1为开关2为卷帘')
 	state = Fields(type='boolean', default='True', comment='数据存在状态')
 	cdate = Fields(type='int', default='time', comment='创建时间')

+ 3 - 0
model/device_mul_queue.py

@@ -14,5 +14,8 @@ class Device_mul_queue(Model):
 	farm_id = Fields(type='int', default='setting.farm', comment='园区ID', match='not')
 	mul_id = Fields(type='uuid', comment='批量控制id')
 	device_id = Fields(type='uuid', comment='设备id')
+	value = Fields(type='int', comment='当前的值')
+	status = Fields(type='int', default='1', comment='数据执行状态,1为队列中,2为执行成功,3执行失败')
+	oper = Fields(type='boolean', default='False', comment='数据执行状态,True为已执行,False为未执行')
 	state = Fields(type='boolean', default='True', comment='数据存在状态')
 	cdate = Fields(type='int', default='time', comment='创建时间')

+ 19 - 0
model/log.py

@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+    demeter database
+    name:log.py
+    author:rabin
+
+"""
+from __load__ import *
+
+class Log(Model):
+	__table__ = 'log'
+	__comment__ = '网关日志表'
+	id = Fields(type='uuid', primaryKey=True, comment='日志ID', uuid='farm_id')
+	farm_id = Fields(type='int', default='setting.farm', comment='园区ID')
+	gateway_id = Fields(type='uuid', comment='网关ID')
+	content = Fields(type='text', comment='内容')
+	state = Fields(type='boolean', default='True', comment='数据存在状态')
+	cdate = Fields(type='int', default='time', comment='创建时间')

+ 17 - 0
model/package.py

@@ -0,0 +1,17 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+    demeter database
+    name:package.py
+    author:rabin
+"""
+from __load__ import *
+
+class Package(Model):
+	__table__ = 'package'
+	__comment__ = '上传的包'
+	id = Fields(type='int', primaryKey=True, autoIncrement=True, comment='包ID')
+	name = Fields(type='varchar(200)', comment='包名')
+	url = Fields(type='varchar(300)', comment='包地址')
+	state = Fields(type='boolean', default='True', comment='数据存在状态')
+	cdate = Fields(type='int', default='time', comment='创建时间')

+ 18 - 0
model/package_version.py

@@ -0,0 +1,18 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+    demeter database
+    name:package_version.py
+    author:rabin
+"""
+from __load__ import *
+
+class Package_version(Model):
+	__table__ = 'package_version'
+	__comment__ = '版本号'
+	id = Fields(type='int', primaryKey=True, autoIncrement=True, comment='版本ID')
+	package_id = Fields(type='int', comment='PackageID')
+	name = Fields(type='varchar(200)', comment='版本名')
+	version = Fields(type='varchar(200)', comment='版本号')
+	state = Fields(type='boolean', default='True', comment='数据存在状态')
+	cdate = Fields(type='int', default='time', comment='创建时间')

+ 7 - 1
pub.py

@@ -14,9 +14,15 @@ import base64
 
 
 pub = Pub()
-key = 'status/valve/10086/100109'
+key = 'status/valve/10086/100107'
 value = 'ok'
 state = pub.push(key, value)
+
+pub = Pub()
+key = 'status/valve/10086/100108'
+value = 'error'
+state = pub.push(key, value)
+
 print state
 """
 def callback(param, client, userdata, mid):

+ 52 - 27
service/device.py

@@ -21,7 +21,7 @@ class Device(object):
 				insert['hardware_id'] = hardware_id
 				insert['gateway_id'] = gateway_id
 				insert['hardware_type'] = 5
-				insert['value'] = '0'
+				insert['value'] = '2'
 				insert['type_id'] = 0
 				insert['status'] = False
 				Demeter.service('common').update('device_info', None, insert)
@@ -33,7 +33,7 @@ class Device(object):
 				insert['hardware_id'] = hardware_id
 				insert['gateway_id'] = gateway_id
 				insert['hardware_type'] = 4
-				insert['value'] = '0'
+				insert['value'] = '2'
 				insert['type_id'] = 8
 				insert['status'] = False
 				Demeter.service('common').update('device_info', None, insert)
@@ -46,7 +46,7 @@ class Device(object):
 			if value['oper'] == 1:
 				switch = 1
 			else:
-				switch = 0
+				switch = 2
 			for v in value['devices']:
 				self.switch(v, switch)
 
@@ -60,11 +60,14 @@ class Device(object):
 			queue_model = Demeter.model('device_mul_queue')
 			queue_model.mul_id = mul
 			queue_model.device_id = info['id']
+			queue_model.status = 1
+			queue_model.value = switch
 			queue_model.insert()
+			return
 		if info and info['status'] == True:
 			# 设置为loading状态,cxnum保存当前的值
 			model.id = device_id
-			model.update(exp='-1', cxnum=switch)
+			model.update(exp='-1', cxnum=switch, oper=True)
 
 			model = Demeter.model('device_gateway')
 			model.id = info['gateway_id']
@@ -107,7 +110,7 @@ class Device(object):
 			if msg == 'ok':
 				model = Demeter.model('device_info')
 				model.id = info['id']
-				model.update(value=param['switch'], exp='1')
+				model.update(value=param['switch'], exp='1', oper=False)
 
 				# 如果有批量控制
 				self.mul(info['id'], info['type_id'], info['name'], param['switch'], '成功', True)
@@ -115,10 +118,10 @@ class Device(object):
 				msg = self.notice(msg)
 				model = Demeter.model('device_info')
 				model.id = info['id']
-				model.update(exp=msg)
+				model.update(exp=msg, oper=False)
 
 				# 如果有批量控制
-				self.mul(info['id'], info['type_id'], info['name'], param['switch'], '失败:' + msg, False)
+				oper = self.mul(info['id'], info['type_id'], info['name'], param['switch'], '失败:' + msg, False)
 
 				content = oper + gateway['name'] + '下的'+ info['name'] + '失败,错误提示:' + msg
 				Demeter.service('record').msg(info['id'], content, info['farm_id'], 3)
@@ -136,29 +139,51 @@ class Device(object):
 	def mul(self, id, type_id, name, switch, msg, state):
 		model = Demeter.model('device_mul_queue')
 		model.device_id = id
+		model.status = 1
 		queue = model.select()
 		if queue:
+			model.device_id = id
 			if state:
-				model.device_id = id
-				model.delete()
-			model = Demeter.model('device_mul')
+				model.update(status=2)
+				#model.device_id = id
+				#model.delete()
+			else:
+				model.update(status=3)
+			mul_model = Demeter.model('device_mul')
+			type_model = Demeter.model('device_type')
+			type_model.id = type_id
+			type_info = type_model.select(type='fetchone')
+			if type_info['unit'] == 'button':
+				if switch == '1':
+					oper = '升起'
+				elif switch == '2':
+					oper = '降下'
+				elif switch == '5':
+					oper = '停止'
+			else:
+				if switch == '1':
+					oper = '开启'
+				else:
+					oper = '关闭'
 			if msg:
 				for v in queue:
-					model.id = v['mul_id']
-					type_model = Demeter.model('device_type')
-					type_model.id = type_id
-					type_info = type_model.select(type='fetchone')
-					if type_info['unit'] == 'button':
-						if switch == '1':
-							oper = '升起'
-						elif switch == '2':
-							oper = '降下'
-						elif switch == '5':
-							oper = '停止'
-					else:
-						if switch == '1':
-							oper = '开启'
-						else:
-							oper = '关闭'
+					# 判断是否全部失败,全部失败,则将回执状态值
+					old = False
+					if state == False:
+						mul_model.id = v['mul_id']
+						info = mul_model.select(type='fetchone')
+						model.mul_id = v['mul_id']
+						model.status = 3
+						queueMulNum = len(model.select())
+						devicesNum = len(tuple(eval(info['devices'])))
+						if queueMulNum == devicesNum:
+							old = info['old']
+
+					mul_model.id = v['mul_id']
+					
 					oper = oper + name + msg
-					model.update(oper=oper)
+					if old:
+						mul_model.update(oper=oper, value=old)
+					else:
+						mul_model.update(oper=oper)
+			return oper

+ 16 - 15
service/record.py

@@ -18,26 +18,27 @@ class Record(object):
 			return {'method':array[0], 'type':array[1], 'parent':array[2], 'child':array[2]}
 
 	def push(self, key, value):
-		config = self.topic(key)
-		method = 'record_' + config['method']
-		cls = Demeter.getClass(method, 'service.')
-		state = False
-		if config['method'] != 'pic':
-			if '{' in value:
-				value = Demeter.isJson(value)
-				if value:
-					state = True
-					for k,v in value.items():
-						config['child'] = k
-						cls().handle(self, config, v)
-		if state == False:
-			cls().handle(self, config, value)
+		if value and value != '0' and value != 0:
+			config = self.topic(key)
+			method = 'record_' + config['method']
+			cls = Demeter.getClass(method, 'service.')
+			state = False
+			if config['method'] != 'pic':
+				if '{' in value:
+					value = Demeter.isJson(value)
+					if value:
+						state = True
+						for k,v in value.items():
+							config['child'] = k
+							cls().handle(self, config, v)
+			if state == False:
+				cls().handle(self, config, value)
 
 	def save(self, config, value, name='', device_type=None):
 		model = Demeter.model('device_gateway')
 		model.hardware_id = config['parent']
 		gateway = model.select(type='fetchone')
-		if gateway:
+		if gateway and value:
 			#更新网关状态
 			self.gateway(config['parent'], gateway['farm_id'], gateway['id'])
 			model_type = Demeter.model('hardware_type')

+ 21 - 0
service/record_log.py

@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+    demeter service
+    name:record_log.py 记录网关日志
+    author:rabin
+    key:log/hw/gateway/gateway
+"""
+from demeter.core import *
+class Record_log(object):
+
+	def handle(self, record, config, value):
+		model = Demeter.model('device_gateway')
+		model.hardware_id = config['parent']
+		data = model.select(type='fetchone')
+		if data:
+			logModel = Demeter.model('log')
+			logModel.farm_id = data['farm_id']
+			logModel.gateway_id = data['id']
+			logModel.content = value
+			logModel.insert()

Some files were not shown because too many files changed in this diff