rabin 6 years ago
parent
commit
f4840fbace

+ 9 - 0
admin/page/admin.py

@@ -9,6 +9,7 @@ from __load__ import *
 
 class admin_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			name = u'管理员' #中文名
@@ -25,6 +26,7 @@ class admin_path(Load):
 
 class admin_update_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			path = '/admin/admin'
@@ -35,12 +37,14 @@ class admin_update_path(Load):
 		self.commonOne('manage_admin')
 		self.commonView('update')
 	@Web.auth
+	@Web.setting
 	def post(self):
 		self.commonUpdate('manage_admin', '手机号已经被注册', mobile=self.data['update']['mobile'])
 
 
 class role_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			name = u'角色'
@@ -60,6 +64,7 @@ class role_path(Load):
 
 class role_update_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		auth = self.data['setting']['menuList']
 		self.common(
@@ -75,14 +80,17 @@ class role_update_path(Load):
 		self.commonOne('manage_role')
 		self.commonView('update')
 	@Web.auth
+	@Web.setting
 	def post(self):
 		self.commonUpdate('manage_role')
 	@Web.auth
+	@Web.setting
 	def delete(self):
 		self.commonDelete('manage_role')
 
 class log_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			name = u'日志' #中文名
@@ -101,6 +109,7 @@ class log_path(Load):
 
 class setCookie_path(Load):
 	@Web.auth
+	@Web.setting
 	def post(self):
 		value = self.input('farm', Demeter.config['setting']['farm'])
 		self.set_secure_cookie('farm', value)

+ 125 - 19
admin/page/device.py

@@ -9,6 +9,7 @@ from __load__ import *
 
 class gateway_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			name = u'网关'
@@ -45,10 +46,12 @@ class gateway_path(Load):
 
 class gateway_update_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		id = self.input('id')
 		if id:
-			hardware_id = 'hardware_id-show-required'
+			#hardware_id = 'hardware_id-show-required'
+			hardware_id = 'hardware_id-input-required'
 		else:
 			hardware_id = 'hardware_id-input-required'
 		self.common(
@@ -60,15 +63,18 @@ class gateway_update_path(Load):
 		self.commonOne('device_gateway')
 		self.commonView('update')
 	@Web.auth
+	@Web.setting
 	def post(self):
 		id = self.commonUpdate('device_gateway')
 		self.device(id)
 
 	@Web.auth
+	@Web.setting
 	def delete(self):
 		self.commonDelete('device_gateway')
 
 	@Web.auth
+	@Web.setting
 	def device(self, id):
 		info = self.service('common').one('device_gateway', id=id)
 		hardware_id = info['hardware_id']
@@ -76,20 +82,20 @@ class gateway_update_path(Load):
 		
 class info_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			name = u'设备'
 			,path = 'info'
 			,width = '600'
 			,height = '400'
-			#,button = ({'name':'添加摄像机','link':'/device/camera_update'},{'name':'添加摄像头','link':'/device/camera_pic_update'})
-			,button = ({'name':'添加摄像头','link':'/device/camera_pic_update'},)
+			,button = ({'name':'添加摄像机','link':'/device/camera_update'},{'name':'添加摄像头','link':'/device/camera_pic_update'})
 			,add = False
 			#,edit = False
-			,search = (('farm_id-select--gateway_id', 'hardware_type-select-','type_id-select-', 'status-hidden-'), (u'选择农场',u'硬件类型',u'设备类型', '设备状态'))
+			,search = (('farm_id-select--gateway_id', 'hardware_type-select-','type_id-select-','name-input-mlike', 'status-hidden-'), (u'选择农场',u'硬件类型',u'设备类型',u'设备名称', '设备状态'))
 			,thead = (u'所属农场', u'设备名称', u'设备id', u'当前值', u'设备类型', u'网关',u'硬件类型')
 			,tbody = ('farm','name', 'hardware_id', 'value', 'type', 'gateway', 'hardware_type')
-			,state = False
+			,state = True
 		)
 		self.data['common']['search_farm_id-select--gateway_id'] = Demeter.config['setting']['farmList']
 		self.data['common']['search_type_id-select-'] = self.service('common').list('device_type')
@@ -101,9 +107,9 @@ class info_path(Load):
 		"""
 		status = self.input('search_status-hidden-', False)
 		if status:
-			self.data['search']['status-hidden-'] = False
+			self.data['search']['status'] = False
 
-		self.commonList('device_info', order='id desc')
+		self.commonList('device_info', order='inorder asc, type_id asc,udate asc,hardware_id asc')
 		if self.data['list']:
 			for key, value in enumerate(self.data['list']):
 				farm = self.service('common').one('farm', id=value['farm_id'])
@@ -139,6 +145,7 @@ class info_path(Load):
 						self.data['list'][key]['value'] = '<input type="checkbox" name="switch" lay-filter="switch" lay-skin="switch" checked '+status+' value="1" data-value="0" data-id="'+value['id']+'" data-url="'+url+'">'
 					else:
 						self.data['list'][key]['value'] = '<input type="checkbox" lay-filter="switch" name="switch" lay-skin="switch" '+status+' value="0" data-value="1" data-id="'+value['id']+'" data-url="'+url+'">'
+					self.data['list'][key]['value'] = ''
 				elif value['hardware_type'] == 5:
 					if value['value'] == '1':
 						self.data['list'][key]['value'] = '已连接'
@@ -152,6 +159,7 @@ class info_path(Load):
 		self.commonView('list')
 
 	@Web.auth
+	@Web.setting
 	def post(self):
 		id = self.input('id')
 		value = self.input('value')
@@ -163,6 +171,7 @@ class info_path(Load):
 
 class info_update_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.commonOne('device_info')
 		if self.data['info']['hardware_type'] == 7:
@@ -170,8 +179,8 @@ class info_update_path(Load):
 				path = 'camera'
 				#,label = (u'摄像机名称', u'摄像机id', u'所属农场', u'选择网关', u'选择硬件类型', u'摄像机地址')
 				#,update = ('name-input-required','hardware_id-show-','farm_id-select-required','gateway_id-select-required','hardware_type-select-required','value-text-required')
-				,label = (u'摄像机名称', u'摄像机id', u'所属农场', u'选择网关', u'摄像机地址')
-				,update = ('name-input-required','hardware_id-show-','farm_id-select-required-gateway_id','gateway_id-select-required--farm_id','value-text-required')
+				,label = (u'摄像机名称', u'摄像机id', u'所属农场', u'选择网关', u'摄像机地址', u'排序')
+				,update = ('name-input-required','hardware_id-show-','farm_id-select-required-gateway_id','gateway_id-select-required--farm_id','value-text-required','inorder-text-')
 				,update_farm_id = Demeter.config['setting']['farmList']
 				,update_gateway_id = self.service('common').list('device_gateway')
 				#,update_hardware_type = self.service('common').list('hardware_type')
@@ -179,84 +188,106 @@ class info_update_path(Load):
 		elif self.data['info']['hardware_type'] == 6:
 			self.common(
 				path = 'camera_pic'
-				,label = (u'摄像头名称', u'摄像头id', u'所属农场', u'选择网关', u'摄像头地址')
-				,update = ('name-input-required','hardware_id-show-','farm_id-select-required-gateway_id','gateway_id-select-required--farm_id','value-text-required')
+				,label = (u'摄像头名称', u'摄像头id', u'所属农场', u'选择网关', u'摄像头地址', u'排序')
+				,update = ('name-input-required','hardware_id-show-','farm_id-select-required-gateway_id','gateway_id-select-required--farm_id','value-text-required','inorder-text-')
 				,update_farm_id = Demeter.config['setting']['farmList']
 				,update_gateway_id = self.service('common').list('device_gateway')
 			)
+		elif self.data['info']['hardware_type'] in (2,4):
+			self.common(
+				path = 'info'
+				#,label = (u'设备名称', u'设备id', u'计算公式', u'实时计算公式')
+				#,update = ('name-input-required','hardware_id-show-',u'exp-text--{n}为当前数据,只处理最新数据',u'out_exp-text--处理所有数据,比较消耗服务器资源')
+				,label = (u'设备名称', u'设备id', u'计算公式', u'排序')
+				,update = ('name-input-required','hardware_id-show-',u'exp-text--{n}为当前数据,只处理最新数据','inorder-text-')
+			)
 		else:
 			self.common(
 				path = 'info'
-				,label = (u'设备名称', u'设备id')
-				,update = ('name-input-required','hardware_id-show-')
+				,label = (u'设备名称', u'设备id', u'排序')
+				,update = ('name-input-required','hardware_id-show-','inorder-text-')
 			)
 		self.commonView('update')
 	@Web.auth
+	@Web.setting
 	def post(self):
 		self.commonUpdate('device_info')
 	@Web.auth
+	@Web.setting
 	def delete(self):
+		self.commonDelete('device_info')
+		"""
 		self.commonOne('device_info')
 		if self.input('state') == 'True' or (self.data['info'] and 'hardware_type' in self.data['info'] and self.data['info']['hardware_type'] == 7):
 			self.commonDelete('device_info')
 		else:
 			#除摄像机之外,其余设备不允许删除
 			self.out('no')
+		"""
 
 class camera_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.redirect('/device/info?search_hardware_type=7')
 
 class camera_update_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			path = 'camera'
-			,label = (u'摄像机名称', u'摄像机id', u'所属农场', u'选择网关', u'摄像机地址')
-			,update = ('name-input-required','hardware_id-input-required','farm_id-select-required-gateway_id','gateway_id-select-required--farm_id','value-text-required')
+			,label = (u'摄像机名称', u'摄像机id', u'所属农场', u'选择网关', u'摄像机地址',u'排序')
+			,update = ('name-input-required','hardware_id-input-required','farm_id-select-required-gateway_id','gateway_id-select-required--farm_id','value-text-required','inorder-text-')
 			,update_farm_id = Demeter.config['setting']['farmList']
 			,update_gateway_id = self.service('common').list('device_gateway')
 		)
 		self.commonOne('device_info')
 		self.commonView('update')
 	@Web.auth
+	@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
 	def delete(self):
 		self.commonDelete('device_info')
 
 class camera_pic_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.redirect('/device/info?search_hardware_type=6')
 
 class camera_pic_update_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			path = 'camera_pic'
-			,label = (u'摄像头名称', u'摄像头id', u'所属农场', u'选择网关', u'摄像头地址')
-			,update = ('name-input-required','hardware_id-input-required','farm_id-select-required-gateway_id','gateway_id-select-required--farm_id','value-text-required')
+			,label = (u'摄像头名称', u'摄像头id', u'所属农场', u'选择网关', u'摄像头地址',u'排序')
+			,update = ('name-input-required','hardware_id-input-required','farm_id-select-required-gateway_id','gateway_id-select-required--farm_id','value-text-required','inorder-text-')
 			,update_farm_id = Demeter.config['setting']['farmList']
 			,update_gateway_id = self.service('common').list('device_gateway')
 		)
 		self.commonOne('device_info')
 		self.commonView('update')
 	@Web.auth
+	@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
 	def delete(self):
 		self.commonDelete('device_info')
 
 class pic_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			name = u'摄像头图片'
@@ -279,6 +310,7 @@ class pic_path(Load):
 
 class stat_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		method = self.input('method', 'avg')
 		id = self.input('id')
@@ -311,6 +343,7 @@ class stat_path(Load):
 
 class type_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			name = u'类型'
@@ -327,24 +360,30 @@ class type_path(Load):
 
 class type_update_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			path = 'type'
-			,label = (u'类型名称', u'类型标识',u'类型单位',u'表达式')
-			,update = ('name-input-required','key-input-required','unit-input-',u'exp-text--请输入表达式,{n}代表当前数据')
+			#,label = (u'类型名称', u'类型标识',u'类型单位',u'表达式')
+			#,update = ('name-input-required','key-input-required','unit-input-',u'exp-text--请输入表达式,{n}代表当前数据')
+			,label = (u'类型名称', u'类型标识',u'类型单位')
+			,update = ('name-input-required','key-input-required','unit-input-')
 		)
 		self.commonOne('device_type')
 		self.commonView('update')
 	@Web.auth
+	@Web.setting
 	def post(self):
 		self.commonUpdate('device_type')
 	@Web.auth
+	@Web.setting
 	def delete(self):
 		self.commonDelete('device_type')
 
 
 class printer_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			name = u'打印机'
@@ -366,6 +405,7 @@ class printer_path(Load):
 
 class printer_update_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			path = 'printer'
@@ -376,8 +416,74 @@ class printer_update_path(Load):
 		self.commonOne('device_printer')
 		self.commonView('update')
 	@Web.auth
+	@Web.setting
 	def post(self):
 		self.commonUpdate('device_printer')
 	@Web.auth
+	@Web.setting
 	def delete(self):
 		self.commonDelete('device_printer')
+
+
+class notice_type_path(Load):
+	@Web.auth
+	@Web.setting
+	def get(self):
+		self.common(
+			name = u'错误码设置'
+			,path = '/device/notice_type'
+			,width = '600'
+			,height = '300'
+			,search = (('name-input-mlike','key-input-mlike'), (u'错误码描述',u'错误码key'))
+			,thead = (u'ID', u'错误码描述',u'错误码key', u'更新时间')
+			,tbody = ('id', 'name', 'key', 'cdate')
+			,state = False
+		)
+		self.commonList('notice_type')
+		self.commonView('list')
+
+class notice_type_update_path(Load):
+	@Web.auth
+	@Web.setting
+	def get(self):
+		self.common(
+			path = '/device/notice_type'
+			,label = (u'错误码描述', u'错误码key')
+			,update = ('name-input-required', 'key-input-required')
+		)
+		self.commonOne('notice_type')
+		self.commonView('update')
+	@Web.auth
+	@Web.setting
+	def post(self):
+		self.commonUpdate('notice_type')
+	@Web.auth
+	@Web.setting
+	def delete(self):
+		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')

+ 9 - 0
admin/page/farm.py

@@ -9,6 +9,7 @@ from __load__ import *
 
 class farm_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			name = u'农场' #中文名
@@ -44,6 +45,7 @@ class farm_path(Load):
 
 class farm_update_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			path = '/farm/farm'
@@ -53,12 +55,14 @@ class farm_update_path(Load):
 		self.commonOne('farm')
 		self.commonView('update')
 	@Web.auth
+	@Web.setting
 	def post(self):
 		id = self.commonUpdate('farm')
 		Demeter.config['setting']['farmList'] = self.service('common').list('farm')
 
 class info_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		id = str(Demeter.config['setting']['farm'])
 		param = '?farm=' + id + '&search_farm_id-select-=' + id
@@ -70,11 +74,13 @@ class info_path(Load):
 		self.commonOne('farm', id=Demeter.config['setting']['farm'])
 		self.commonView('set')
 	@Web.auth
+	@Web.setting
 	def post(self):
 		self.commonUpdate('farm', id=Demeter.config['setting']['farm'])
 
 class user_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			name = u'用户'
@@ -98,6 +104,7 @@ class user_path(Load):
 
 class user_update_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			path = '/farm/user'
@@ -108,8 +115,10 @@ class user_update_path(Load):
 		self.commonOne('farm_user')
 		self.commonView('update')
 	@Web.auth
+	@Web.setting
 	def post(self):
 		self.commonUpdate('farm_user', '手机号已经被注册', mobile=self.data['update']['mobile'])
 	@Web.auth
+	@Web.setting
 	def delete(self):
 		self.commonDelete('farm_user')

+ 8 - 0
admin/page/hardware.py

@@ -9,6 +9,7 @@ from __load__ import *
 
 class hardware_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			name = u'硬件设备'
@@ -44,6 +45,7 @@ class hardware_path(Load):
 
 class hardware_update_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			path = '/hardware/hardware'
@@ -54,14 +56,17 @@ class hardware_update_path(Load):
 		self.commonOne('hardware')
 		self.commonView('update')
 	@Web.auth
+	@Web.setting
 	def post(self):
 		self.commonUpdate('hardware')
 	@Web.auth
+	@Web.setting
 	def delete(self):
 		self.commonDelete('hardware')
 
 class type_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			name = u'硬件类型'
@@ -78,6 +83,7 @@ class type_path(Load):
 
 class type_update_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			path = '/hardware/type'
@@ -87,8 +93,10 @@ class type_update_path(Load):
 		self.commonOne('hardware_type')
 		self.commonView('update')
 	@Web.auth
+	@Web.setting
 	def post(self):
 		self.commonUpdate('hardware_type')
 	@Web.auth
+	@Web.setting
 	def delete(self):
 		self.commonDelete('hardware_type')

+ 2 - 0
admin/page/main.py

@@ -9,10 +9,12 @@ from __load__ import *
 
 class index_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.view("index.html")
 
 class main_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.view("main.html")

+ 8 - 0
admin/page/msg.py

@@ -11,6 +11,7 @@ push = ({'id':'sms', 'name':'短信'}, {'id':'weixin', 'name':'微信'})
 
 class msg_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			name = u'消息'
@@ -46,6 +47,7 @@ class msg_path(Load):
 
 class msg_update_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			path = '/msg/msg'
@@ -59,15 +61,18 @@ class msg_update_path(Load):
 		self.commonOne('msg')
 		self.commonView('update')
 	@Web.auth
+	@Web.setting
 	def post(self):
 		# 发消息
 		self.commonUpdate('msg')
 	@Web.auth
+	@Web.setting
 	def delete(self):
 		self.commonDelete('msg')
 
 class type_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			name = u'消息类型'
@@ -84,6 +89,7 @@ class type_path(Load):
 
 class type_update_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			path = '/msg/type'
@@ -94,8 +100,10 @@ class type_update_path(Load):
 		self.commonOne('msg_type')
 		self.commonView('update')
 	@Web.auth
+	@Web.setting
 	def post(self):
 		self.commonUpdate('msg_type')
 	@Web.auth
+	@Web.setting
 	def delete(self):
 		self.commonDelete('msg_type')

+ 4 - 0
admin/page/origin.py

@@ -9,6 +9,7 @@ from __load__ import *
 
 class batch_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			name = u'溯源批次'
@@ -35,6 +36,7 @@ class batch_path(Load):
 
 class batch_update_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			path = '/origin/batch'
@@ -47,8 +49,10 @@ class batch_update_path(Load):
 		self.commonOne('origin_batch')
 		self.commonView('update')
 	@Web.auth
+	@Web.setting
 	def post(self):
 		self.commonUpdate('origin_batch')
 	@Web.auth
+	@Web.setting
 	def delete(self):
 		self.commonDelete('origin_batch')

+ 1 - 0
admin/page/upload.py

@@ -12,6 +12,7 @@ import uuid
 
 class upload_path(Load):
  	@Web.auth
+	@Web.setting
 	def post(self, *args, **kwargs):
 		url = self.request.protocol + "://" + self.request.host
 		file_metas = self.request.files["file"]

+ 3 - 0
admin/page/user.py

@@ -8,8 +8,10 @@
 from __load__ import *
 
 class login_path(Load):
+	@Web.setting
 	def get(self):
 		self.view("login.html")
+	@Web.setting
 	def post(self):
 		mobile = self.input('username')
 		password = self.input('password')
@@ -28,6 +30,7 @@ class login_path(Load):
 
 
 class loginout_path(Load):
+	@Web.setting
 	def get(self):
 		self.set_secure_cookie('admin', '')
 		self.redirect('/user/login')

+ 22 - 0
admin/page/web.py

@@ -9,6 +9,7 @@ from __load__ import *
 
 class set_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			path = '/web/set'
@@ -18,11 +19,13 @@ class set_path(Load):
 		self.commonOne('web_set', id=1)
 		self.commonView('set')
 	@Web.auth
+	@Web.setting
 	def post(self):
 		self.commonUpdate('web_set',id=1)
 
 class article_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			name = u'文章'
@@ -44,6 +47,7 @@ class article_path(Load):
 
 class article_update_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			path = '/web/article'
@@ -54,15 +58,18 @@ class article_update_path(Load):
 		self.commonOne('web_article')
 		self.commonView('update')
 	@Web.auth
+	@Web.setting
 	def post(self):
 		self.commonUpdate('web_article')
 	@Web.auth
+	@Web.setting
 	def delete(self):
 		self.commonDelete('web_article')
 
 
 class category_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			name = u'分类'
@@ -79,6 +86,7 @@ class category_path(Load):
 
 class category_update_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			path = '/web/category'
@@ -88,14 +96,17 @@ class category_update_path(Load):
 		self.commonOne('web_article_category')
 		self.commonView('update')
 	@Web.auth
+	@Web.setting
 	def post(self):
 		self.commonUpdate('web_article_category')
 	@Web.auth
+	@Web.setting
 	def delete(self):
 		self.commonDelete('web_article_category')
 
 class help_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			name = u'帮助'
@@ -117,6 +128,7 @@ class help_path(Load):
 
 class help_update_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			path = '/web/help'
@@ -127,14 +139,17 @@ class help_update_path(Load):
 		self.commonOne('web_help')
 		self.commonView('update')
 	@Web.auth
+	@Web.setting
 	def post(self):
 		self.commonUpdate('web_help')
 	@Web.auth
+	@Web.setting
 	def delete(self):
 		self.commonDelete('web_help')
 
 class help_category_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			name = u'分类'
@@ -151,6 +166,7 @@ class help_category_path(Load):
 
 class help_category_update_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			path = '/web/help_category'
@@ -160,14 +176,17 @@ class help_category_update_path(Load):
 		self.commonOne('web_help_category')
 		self.commonView('update')
 	@Web.auth
+	@Web.setting
 	def post(self):
 		self.commonUpdate('web_help_category')
 	@Web.auth
+	@Web.setting
 	def delete(self):
 		self.commonDelete('web_help_category')
 
 class menu_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			name = u'菜单'
@@ -184,6 +203,7 @@ class menu_path(Load):
 
 class menu_update_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			path = '/web/menu'
@@ -193,8 +213,10 @@ class menu_update_path(Load):
 		self.commonOne('web_menu')
 		self.commonView('update')
 	@Web.auth
+	@Web.setting
 	def post(self):
 		self.commonUpdate('web_menu')
 	@Web.auth
+	@Web.setting
 	def delete(self):
 		self.commonDelete('web_menu')

+ 12 - 0
admin/page/work.py

@@ -9,6 +9,7 @@ from __load__ import *
 
 class work_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			name = u'农事'
@@ -35,6 +36,7 @@ class work_path(Load):
 
 class work_update_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			path = '/work/work'
@@ -47,14 +49,17 @@ class work_update_path(Load):
 		self.commonOne('farm_work')
 		self.commonView('update')
 	@Web.auth
+	@Web.setting
 	def post(self):
 		self.commonUpdate('farm_work')
 	@Web.auth
+	@Web.setting
 	def delete(self):
 		self.commonDelete('farm_work')
 
 class category_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			name = u'劳作方式'
@@ -76,6 +81,7 @@ class category_path(Load):
 
 class category_update_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			path = '/work/category'
@@ -86,15 +92,18 @@ class category_update_path(Load):
 		self.commonOne('farm_work_category')
 		self.commonView('update')
 	@Web.auth
+	@Web.setting
 	def post(self):
 		self.commonUpdate('farm_work_category')
 	@Web.auth
+	@Web.setting
 	def delete(self):
 		self.commonDelete('farm_work_category')
 
 
 class land_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			name = u'地块'
@@ -116,6 +125,7 @@ class land_path(Load):
 
 class land_update_path(Load):
 	@Web.auth
+	@Web.setting
 	def get(self):
 		self.common(
 			path = '/work/land'
@@ -126,8 +136,10 @@ class land_update_path(Load):
 		self.commonOne('farm_work_land')
 		self.commonView('update')
 	@Web.auth
+	@Web.setting
 	def post(self):
 		self.commonUpdate('farm_work_land')
 	@Web.auth
+	@Web.setting
 	def delete(self):
 		self.commonDelete('farm_work_land')

+ 7 - 1
conf/dev.conf

@@ -71,4 +71,10 @@ port				= 8089
 debug				= True
 max_buffer_size		= 210763776
 process				= 0
-url					= http://192.168.15.10:8089/
+url					= http://192.168.15.10:8089/
+
+;微信小程序配置
+[weixinApp]
+appid				= 1
+secret				= 1
+login				= https://api.weixin.qq.com/sns/jscode2session

File diff suppressed because it is too large
+ 10 - 1
front/api/device.py


+ 3 - 0
front/api/farm.py

@@ -30,6 +30,7 @@ class index_path(Load):
 	{"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
 	"""
 	@auth
+	@Web.setting
 	def get(self):
 		# 获取农场信息
 		self.data['farm'] = self.service('common').one('farm', id=Demeter.config['setting']['farm'])
@@ -58,6 +59,7 @@ class index_path(Load):
 	{"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
 	"""
 	@auth
+	@Web.setting
 	def post(self):
 		id = self.input('id', None)
 		update = {}
@@ -112,6 +114,7 @@ class msg_path(Load):
 	{"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
 	"""
 	@auth
+	@Web.setting
 	def get(self):
 		self.data['list'] = self.service('common').list('msg', state=True, page=True)
 		for key, value in enumerate(self.data['list']):

+ 30 - 2
front/api/login.py

@@ -8,6 +8,34 @@
 from __load__ import *
 
 class login_path(Load):
-
+	@Web.setting
 	def get(self):
-		self.out('test')
+		mobile = self.input('mobile')
+		password = self.input('password')
+		if mobile and password:
+			user = self.service('common').one('user', mobile=mobile)
+			if user:
+				temp = user['password'].split('_')
+				if Demeter.md5(password, temp[1]) == user['password']:
+					self.bind(user['id'])
+					#self.set_secure_cookie('user', str(user['id']))
+					#self.redirect('/')
+					self.out('yes', {'uid':user['id']})
+					return
+		else:
+			self.out('手机号或密码错误,登录失败')
+			return
+	@Web.setting
+	def bind(self, uid):
+		code = self.input('code')
+		if not code:
+			self.out('no')
+			return
+		url = Demeter.config['weixinApp']['login']
+		url = url + '?appid=' + Demeter.config['weixinApp']['appid']
+		url = url + '&secret=' + Demeter.config['weixinApp']['secret']
+		url = url + '&js_code=' + code
+		url = url + '&grant_type=authorization_code'
+		data = Demeter.curl(url)
+		
+		return data

+ 3 - 2
front/api/main.py

@@ -25,11 +25,12 @@ class index_path(Load):
 	@apiSuccess {String}   gateway.name  网关名称
 	@apiSuccess {String}   gateway.id    网关ID
 	@apiErrorExample 操作成功
-	{"status": 1, "msg": "yes", "code": 0, "data": {"farm": {"info": "", "master_name": "", "tel": "", "name": "\u9ed8\u8ba4\u56ed\u533a", "pic": "", "cdate": 1503915445, "state": true, "address": "", "id": 1}, "setting": {"farm": 1, "user": 0, "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "msg": 0, "gateway": [{"status": false, "hardware_id": 3213, "name": "323", "farm_id": 2, "cdate": 1504075691, "state": true, "power_num": null, "power_status": false, "id": "d53db924-2043-500f-8140-b24780bb4691"}, {"status": false, "hardware_id": 10086, "name": "\u9ed8\u8ba4\u7f51\u5173", "farm_id": 1, "cdate": 1503915445, "state": true, "power_num": null, "power_status": false, "id": "5828ba1d-10de-5ebc-988d-345bc5ad40a8"}]}}
+	{"status": 1, "msg": "yes", "code": 0, "data": {"farm": {"info": "3123fdf", "master_name": "31232", "tel": "323", "name": "\u9ed8\u8ba4\u56ed\u533a", "pic": "http://192.168.15.10:8087/upload/2017/09/27/5c3d27b95a0375cd5c0eab03c61a494a.jpg", "cdate": 1506496822, "gateway": "", "master_pic": "", "state": true, "location": "", "address": "312", "id": 1}, "gateway": [{"stat": false, "pic": null, "hardware_id": 10086, "farm_id": 1, "cdate": 1506496123, "state": true, "camera": null, "id": "542535db-6c0b-51fc-9f73-cafb3872ce76", "name": "\u9ed8\u8ba4\u7f51\u5173"}], "setting": {"farm": 1, "user": "229cfd36-9399-5599-b2b5-c53174c3de19", "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "base": {}, "msg": 0}}
 	@apiErrorExample 操作失败
 	{"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
 	"""
 	@auth
+	@Web.setting
 	def get(self):
 		# 获取网关
 		self.data['gateway'] = self.service('common').list('device_gateway', search={'farm_id': Demeter.config['setting']['farm']})
@@ -38,5 +39,5 @@ class index_path(Load):
 		self.data['farm'] = self.service('common').one('farm', id=Demeter.config['setting']['farm'])
 
 		# 获取消息数量
-		self.data['msg'] = len(self.service('common').list('msg', search={'farm_id': Demeter.config['setting']['farm']})
+		self.data['msg'] = len(self.service('common').list('msg', search={'farm_id': Demeter.config['setting']['farm']}))
 		self.out('yes', self.data)

+ 3 - 0
front/api/origin.py

@@ -36,6 +36,7 @@ class index_path(Load):
 	{"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
 	"""
 	@auth
+	@Web.setting
 	def get(self):
 		self.data['list'] = self.service('common').list('origin_batch', state=True, page=True)
 		if self.data['list']:
@@ -72,6 +73,7 @@ class index_path(Load):
 	{"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
 	"""
 	@auth
+	@Web.setting
 	def post(self):
 		id = self.input('id', None)
 		if not id:
@@ -124,6 +126,7 @@ class info_path(Load):
 	{"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
 	"""
 	@auth
+	@Web.setting
 	def get(self):
 		id = self.input('id', None)
 		if id:

+ 1 - 0
front/api/upload.py

@@ -31,6 +31,7 @@ class index_path(Load):
 	{"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
 	"""
  	@auth
+	@Web.setting
 	def post(self, *args, **kwargs):
 		url = self.request.protocol + "://" + self.request.host
 		file_metas = self.request.files["file"]

+ 6 - 0
front/api/work.py

@@ -36,6 +36,7 @@ class index_path(Load):
 	{"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
 	"""
 	@auth
+	@Web.setting
 	def get(self):
 		self.data['list'] = self.service('common').list('farm_work', state=True, page=True)
 		if self.data['list']:
@@ -72,6 +73,7 @@ class index_path(Load):
 	{"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
 	"""
 	@auth
+	@Web.setting
 	def post(self):
 		id = self.input('id', None)
 		if not id:
@@ -123,6 +125,7 @@ class info_path(Load):
 	{"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
 	"""
 	@auth
+	@Web.setting
 	def get(self):
 		id = self.input('id', None)
 		if id:
@@ -154,6 +157,7 @@ class land_path(Load):
 	{"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
 	"""
 	@auth
+	@Web.setting
 	def get(self):
 		self.data['list'] = self.service('common').list('farm_work_land', state=True)
 		self.out('yes', self.data)
@@ -177,6 +181,7 @@ class land_path(Load):
 	{"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
 	"""
 	@auth
+	@Web.setting
 	def post(self):
 		id = self.input('id', None)
 		update = {}
@@ -207,6 +212,7 @@ class category_path(Load):
 	{"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
 	"""
 	@auth
+	@Web.setting
 	def get(self):
 		self.data['list'] = self.service('common').list('farm_work_category', state=True)
 		self.out('yes', self.data)

+ 10 - 1
model/device_info.py

@@ -18,6 +18,7 @@ class Device_info(Model):
 	gateway_id = Fields(type='uuid', comment='网关id')
 	type_id = Fields(type='int', comment='设备类型')
 	value = Fields(type='varchar(1000)', comment='设备传过来的值')
+	exp = Fields(type='varchar(500)', comment='表达式')
 	max = Fields(type='float', comment='最大上限', match='number|最大上限必须是数字')
 	min = Fields(type='float', comment='最小下限', match='number|最小下限必须是数字')
 	cxnum = Fields(type='int', comment='超限次数')
@@ -26,4 +27,12 @@ class Device_info(Model):
 	status = Fields(type='boolean', default='False', comment='设备连接状态')
 	state = Fields(type='boolean', default='True', comment='数据存在状态')
 	cdate = Fields(type='int', default='time', comment='创建时间')
-	udate = Fields(type='int', default='time', comment='接入时间')
+	udate = Fields(type='int', default='time', comment='接入时间')
+	inorder = Fields(type='int', default='0', comment='排序', match='number|排序必须是数字')
+	oper = Fields(type='boolean', default='False', comment='操作类型')
+	operdate = Fields(type='int', 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 ADD operdate int; 
+	#ALTER TABLE demeter_device_info DROP inorder;   

+ 1 - 1
pub.py

@@ -11,7 +11,7 @@ import ConfigParser
 import random
 import time
 import base64
-import oss2
+#import oss2
 
 def push():
 	# 模拟传感器设备数据

+ 120 - 11
service/device.py

@@ -8,7 +8,7 @@
 from demeter.core import *
 from demeter.mqtt import *
 class Device(object):
-
+	type_info = []
 	# 新增网关时,增加状态和电源
 	def upGatewayStatus(self, farm_id, gateway_id, hardware_id):
 		if hardware_id and gateway_id > 0:
@@ -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)
@@ -46,17 +46,43 @@ class Device(object):
 			if value['oper'] == 1:
 				switch = 1
 			else:
-				switch = 0
+				switch = 2
 			for v in value['devices']:
 				self.switch(v, switch)
-	# 处理开关
-	def switch(self, device_id, switch=1):
+
+	# 处理开关-向设备发送请求
+	def switch(self, device_id, switch=1, mul=False, queue=False):
 		model = Demeter.model('device_info')
 		model.id = device_id
 		info = model.select(type='fetchone')
-		if info:
+		# 如果有批量控制,还要保存mul的id
+		if mul:
+			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
+			if info['inorder']:
+				queue_model.inorder = info['inorder']
+			else:
+				queue_model.inorder = 100
+			queue_model.udate = info['udate']
+			queue_model.hardware_id = info['hardware_id']
+			queue_model.insert()
+			return
+		
+		if info and info['status'] == True:
+			"""
+			if queue:
+				oper = self.msg(info['type_id'], switch)
+				queue_model = Demeter.model('device_mul_queue')
+				queue_model.id = queue
+				queue_model.update(oper='正在' + oper + info['name'])
+			"""
+			# 设置为loading状态,cxnum保存当前的值
 			model.id = device_id
-			model.update(value=switch)
+			model.update(exp='-1', cxnum=switch, oper=True, operdate=Demeter.time())
+
 			model = Demeter.model('device_gateway')
 			model.id = info['gateway_id']
 			gateway_info = model.select(type='fetchone')
@@ -70,9 +96,92 @@ class Device(object):
 					switch = str(switch)
 					gateway_info['hardware_id'] = str(gateway_info['hardware_id'])
 					# 这里要向服务器发送pub请求了,暂时使用临时文件代替
-					Demeter.temp(key=type_info['key'], name=info['hardware_id'], value=switch)
+					#Demeter.temp(key=type_info['key'], name=info['hardware_id'], value=switch)
 					#pub
-					#pub = Pub()
-					key = 'update/' + type_info['key'] + '/' + gateway_info['hardware_id']  + '/' + info['hardware_id']
+					pub = Pub()
+					key = type_info['key'] + '/' + gateway_info['hardware_id']  + '/' + info['hardware_id']
+					update = 'update/' + key
+					feedback = 'status/' + key
 					value = switch
-					#pub.push(key, value, 2)
+					#pub.push(update, value, qos=0, callback=self.switchAction, param={'info':info, 'key':feedback, 'switch':switch}, feedback=True)
+					pub.push(update, value)
+		else:
+			msg = self.notice('offline')
+			model.id = device_id
+			model.update(exp=msg, cxnum=switch, oper=True, operdate=Demeter.time())
+			self.mul(info, info['name'] + '失败:' + msg, False)
+			#Demeter.error('offline')
+
+	# 处理开关-响应
+	def switchAction(self, param, client, userdata, mid, msg='ok'):
+		info = param['info']
+		if info and info['status'] == True:
+			param['switch'] = info['cxnum']
+			model = Demeter.model('device_gateway')
+			model.id = info['gateway_id']
+			gateway = model.select(type='fetchone')
+
+			if msg == 'ok':
+				model = Demeter.model('device_info')
+				model.id = info['id']
+				model.update(value=param['switch'], exp='1', oper=False, operdate=Demeter.time())
+
+				# 如果有批量控制
+				self.mul(info, info['name'] + '成功', True)
+			else:
+				msg = self.notice(msg)
+				model = Demeter.model('device_info')
+				model.id = info['id']
+				model.update(exp=msg, oper=True, operdate=Demeter.time())
+
+				# 如果有批量控制
+				self.mul(info, info['name'] + '失败:' + msg, False)
+				oper = self.msg(info['type_id'], param['switch'])
+				content = oper + gateway['name'] + '下的'+ info['name'] + '失败,错误提示:' + msg
+				Demeter.service('record').msg(info['id'], content, info['farm_id'], 3)
+
+				#Demeter.error(msg)
+
+	def notice(self, msg):
+		model = Demeter.model('notice_type')
+		model.key = msg
+		info = model.select(type='fetchone')
+		if info:
+			msg = info['name']
+		return msg
+
+	def msg(self, type_id, switch):
+		oper = ''
+		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 = '关闭'
+		return oper
+
+	def mul(self, info, msg, state):
+		model = Demeter.model('device_mul_queue')
+		mul_model = Demeter.model('device_mul')
+		model.device_id = info['id']
+		model.status = 1
+		queue = model.select()
+
+		if queue:
+			for v in queue:
+				model.status = 1
+				model.device_id = info['id']
+				oper = self.msg(info['type_id'], v['value']) + msg
+			if state:
+				model.update(status=2, oper=oper, operdate=Demeter.time())
+			else:
+				model.update(status=3, oper=oper, operdate=Demeter.time())

+ 7 - 2
service/record.py

@@ -48,10 +48,15 @@ class Record(object):
 			model.hardware_type = hard['id']
 			device = model.select(type='fetchone')
 			if device:
-				#update
 				model.id = device['id']
+				if config['method'] == 'control' and (value == '0' or value == 0):
+					model.update(status=True, cdate='time')
+					return
+				#update
 				id = device['id']
-				model.update(farm_id=gateway['farm_id'], value=value,status=True,cdate='time')
+				if config['method'] == 'sensor' or config['method'] == 'power':
+					value = Demeter.exp(device['exp'], value)
+				model.update(value=value,status=True,cdate='time')
 				# 上下限判断
 				# 条件判断
 				if device['type_id'] > 0 and (hard['id'] == 2 or hard['id'] == 4):

+ 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()

+ 20 - 0
service/record_status.py

@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+    demeter service
+    name:record_status.py 处理update控制器的实时错误码
+    author:rabin
+    key:status/type/gateway/device
+"""
+from demeter.core import *
+class Record_status(object):
+
+	def handle(self, record, config, value):
+		model = Demeter.model('device_info')
+		model.hardware_id = config['child']
+		model.hardware_type = 3
+		device = model.select(type='fetchone')
+		if device:
+			param = {}
+			param['info'] = device
+			Demeter.service('device').switchAction(param, False, False, False, msg=value)

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