Преглед изворни кода

新增算法绑定UID增加时间字段

zhangdongming пре 3 година
родитељ
комит
b5a46b8a07
2 измењених фајлова са 7 додато и 2 уклоњено
  1. 5 2
      Controller/AlgorithmShop/AlgorithmShopController.py
  2. 2 0
      Model/models.py

+ 5 - 2
Controller/AlgorithmShop/AlgorithmShopController.py

@@ -7,6 +7,7 @@
 @Software: PyCharm
 @Software: PyCharm
 """
 """
 import logging
 import logging
+import time
 
 
 from django.views.generic.base import View
 from django.views.generic.base import View
 
 
@@ -170,12 +171,14 @@ class AlgorithmShopView(View):
                 return response.json(444)
                 return response.json(444)
             status = int(status)
             status = int(status)
             type_id = int(type_id)
             type_id = int(type_id)
+            now_time = int(time.time())
             uid_algorithm_qs = DeviceUidAlgorithmType.objects.filter(algorithm_type_id=type_id, device_uid=uid)
             uid_algorithm_qs = DeviceUidAlgorithmType.objects.filter(algorithm_type_id=type_id, device_uid=uid)
             if not uid_algorithm_qs.exists():
             if not uid_algorithm_qs.exists():
-                param = {'algorithm_type_id': int(type_id), 'uid': uid, 'function': setting_json, 'status': status}
+                param = {'algorithm_type_id': int(type_id), 'uid': uid, 'function': setting_json,
+                         'status': status, 'updated_time': now_time, 'created_time': now_time}
                 DeviceUidAlgorithmType.objects.create(**param)
                 DeviceUidAlgorithmType.objects.create(**param)
                 return response.json(0)
                 return response.json(0)
-            uid_algorithm_qs.update(status=status, function=setting_json)
+            uid_algorithm_qs.update(status=status, function=setting_json, updated_time=now_time)
             return response.json(0)
             return response.json(0)
         except Exception as e:
         except Exception as e:
             print('保存算法设置异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
             print('保存算法设置异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))

+ 2 - 0
Model/models.py

@@ -2880,6 +2880,8 @@ class DeviceUidAlgorithmType(models.Model):
     device_uid = models.CharField(max_length=32, db_index=True, default='', verbose_name='设备uid')
     device_uid = models.CharField(max_length=32, db_index=True, default='', verbose_name='设备uid')
     algorithm_type = models.ForeignKey(DeviceAlgorithmType, to_field='id', default='', on_delete=models.CASCADE,
     algorithm_type = models.ForeignKey(DeviceAlgorithmType, to_field='id', default='', on_delete=models.CASCADE,
                                        verbose_name=u'关联算法类型')
                                        verbose_name=u'关联算法类型')
+    updated_time = models.IntegerField(default=0, verbose_name='更新时间')
+    created_time = models.IntegerField(default=0, verbose_name='创建时间')
 
 
     class Meta:
     class Meta:
         db_table = 'device_uid_algorithm_type'
         db_table = 'device_uid_algorithm_type'