dever 6 years ago
parent
commit
334d780c88
6 changed files with 39 additions and 13 deletions
  1. 1 1
      admin/page/work.py
  2. 3 2
      cron.py
  3. 4 2
      front/api/device.py
  4. 9 1
      front/api/origin.py
  5. 3 1
      model/origin_batch.py
  6. 19 6
      service/record.py

+ 1 - 1
admin/page/work.py

@@ -31,7 +31,7 @@ class work_path(Load):
 				category = self.service('common').one('farm_work_category', id=value['category_id'])
 				self.data['list'][key]['category'] = category['name']
 				land = self.service('common').one('farm_work_land', id=value['land_id'])
-                if land:
+				if land:
 					self.data['list'][key]['land'] = land['name']
 		self.commonView('list')
 

+ 3 - 2
cron.py

@@ -61,13 +61,14 @@ def userNotice():
 
 # 用户提醒
 def notice(t, data):
+	pass
 
 def handle():
 	gevent.joinall([
 		gevent.spawn(device),
-		#gevent.spawn(savePic),
+		gevent.spawn(savePic),
 		gevent.spawn(timeSync),
-		gevent.spawn(userNotice),
+		#gevent.spawn(userNotice),
 	])
 
 handle()

+ 4 - 2
front/api/device.py

@@ -78,7 +78,7 @@ class index_path(Load):
 			if pic:
 				for key, value in enumerate(pic):
 					pic[key]['cdates'] = Demeter.date(value['cdate'])
-				self.data['pic'] = pic[0]
+				self.data['pic'] = pic
 
 			self.out('yes', self.data)
 		else:
@@ -252,6 +252,7 @@ class pic_path(Load):
 	@Web.setting
 	def get(self):
 		id = self.input('id', None)
+		device = self.input('device', None)
 		if id:
 			self.data['info'] = self.service('common').one('device_gateway', id=id)
 			if not self.data['info']:
@@ -263,6 +264,7 @@ class pic_path(Load):
 
 			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'
@@ -270,7 +272,7 @@ class pic_path(Load):
 			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'] = 'http://api.nongxiaohe.com' + value['pic']
+					self.data['pic'][key]['pic'] = 'https://api.nongxiaohe.com' + value['pic']
 
 			self.out('yes', self.data)
 		else:

+ 9 - 1
front/api/origin.py

@@ -111,6 +111,7 @@ class index_path(Load):
 		update = {}
 		update['pic'] = self.input('update_pic')
 		update['gateway_id'] = self.input('update_device_id')
+		update['pic_id'] = self.input('update_pic_id')
 		update['land_id'] = self.input('update_land')
 		update['zzdate'] = self.input('update_zzdate')
 		update['csdate'] = self.input('update_csdate')
@@ -164,7 +165,14 @@ class info_path(Load):
 			self.data['info'] = self.service('common').one('origin_batch', id=id)
 			if self.data['info']:
 				self.data['info'] = Origin.get(self, self.data['info'])
-				
+			
+			self.data['pic'] = {}
+			pic = self.service('common').list('device_info', state=True, search={'hardware_type':6, 'gateway_id':self.data['gateway_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')

+ 3 - 1
model/origin_batch.py

@@ -20,4 +20,6 @@ class Origin_batch(Model):
 	number = Fields(type='varchar(32)', comment='批号')
 	pic = Fields(type='text', comment='图像记录')
 	state = Fields(type='boolean', default='True', comment='数据存在状态')
-	cdate = Fields(type='int', default='time', comment='创建时间')
+	cdate = Fields(type='int', default='time', comment='创建时间')
+	pic_id = Fields(type='uuid', comment='摄像头设备id')
+	#ALTER TABLE demeter_origin_batch ADD pic_id uuid; 

+ 19 - 6
service/record.py

@@ -171,20 +171,33 @@ class Record(object):
 
 	def msg(self, device_id, content, farm_id, type_id):
 		model = Demeter.model('msg')
+
+		# 2018-05-23更新 增加三个小时之内只能报一次错误
 		model.farm_id = farm_id
-		model.content = content
+		#model.content = content
 		model.device_id = device_id
 		model.type_id = type_id
 		info = model.select(type='fetchone')
-		if not info:
+		state = False
+		if info:
+			if Demeter.time() - info['cdate'] > 3600*3:
+				state = True
+
+		if state == True:
 			model.farm_id = farm_id
 			model.content = content
 			model.device_id = device_id
 			model.type_id = type_id
-			model.insert()
-		else:
-			model.id = info['id']
-			model.update(content=content, cdate='time')
+			info = model.select(type='fetchone')
+			if not info:
+				model.farm_id = farm_id
+				model.content = content
+				model.device_id = device_id
+				model.type_id = type_id
+				model.insert()
+			else:
+				model.id = info['id']
+				model.update(content=content, cdate='time')
 
 	def gateway(self, gateway, farm, id):
 		# 更新网关状态