|
@@ -1,3 +1,4 @@
|
|
|
+import datetime
|
|
|
import time
|
|
|
import traceback
|
|
|
|
|
@@ -170,16 +171,28 @@ class EquipmentInfo(View):
|
|
|
count = 0
|
|
|
for ei_id in id_list:
|
|
|
try:
|
|
|
- event_date = '20{}'.format(ei_id[0:6])
|
|
|
- ei_id = ei_id[6:]
|
|
|
- val = LocalDateTimeUtil.format_date_to_week(event_date, '%Y%m%d')
|
|
|
+ dt = int(ei_id[0:10])
|
|
|
+ event_date = datetime.datetime.utcfromtimestamp(dt).date()
|
|
|
+ ei_id = int(ei_id[10:])
|
|
|
+ val = LocalDateTimeUtil.format_date_to_week(str(event_date), '%Y-%m-%d')
|
|
|
eq = EquipmentInfoService.get_equipment_info_model('', val)
|
|
|
- eq = eq.filter(id=int(ei_id))
|
|
|
+ eq = eq.filter(id=ei_id, event_time=dt)
|
|
|
if eq.exists():
|
|
|
own_dev = ModelService.check_own_device(userID, eq[0].device_uid)
|
|
|
if own_dev is True:
|
|
|
count += 1
|
|
|
eq.update(status=1)
|
|
|
+ if count == 0:
|
|
|
+ for i in range(2):
|
|
|
+ week = (7 if val == 1 else val - 1) if i == 0 else (1 if val == 7 else val + 1)
|
|
|
+ result = EquipmentInfoService.get_equipment_info_model('', week)
|
|
|
+ result = result.filter(id=ei_id, event_time=dt)
|
|
|
+ if result.exists():
|
|
|
+ own_dev = ModelService.check_own_device(userID, result[0].device_uid)
|
|
|
+ if own_dev is True:
|
|
|
+ count += 1
|
|
|
+ result.update(status=1)
|
|
|
+
|
|
|
except Exception as e:
|
|
|
print(repr(e))
|
|
|
return response.json(0, {'update_success': count})
|
|
@@ -194,15 +207,28 @@ class EquipmentInfo(View):
|
|
|
if param_flag is True:
|
|
|
try:
|
|
|
for ei_id in id_list:
|
|
|
- event_date = '20{}'.format(ei_id[0:6])
|
|
|
- ei_id = ei_id[6:]
|
|
|
- val = LocalDateTimeUtil.format_date_to_week(event_date, '%Y%m%d')
|
|
|
+ dt = int(ei_id[0:10])
|
|
|
+ event_date = datetime.datetime.utcfromtimestamp(dt).date()
|
|
|
+ res = 0
|
|
|
+ ei_id = int(ei_id[10:])
|
|
|
+ val = LocalDateTimeUtil.format_date_to_week(str(event_date), '%Y-%m-%d')
|
|
|
eq = EquipmentInfoService.get_equipment_info_model('', val)
|
|
|
- eq = eq.filter(id=ei_id)
|
|
|
+ eq = eq.filter(id=ei_id, event_time=dt)
|
|
|
if eq.exists():
|
|
|
own_dev = ModelService.check_own_device(userID, eq[0].device_uid)
|
|
|
if own_dev is True:
|
|
|
+ res += 1
|
|
|
eq.delete()
|
|
|
+ if res == 0:
|
|
|
+ for i in range(2):
|
|
|
+ week = (7 if val == 1 else val - 1) if i == 0 else (1 if val == 7 else val + 1)
|
|
|
+ result = EquipmentInfoService.get_equipment_info_model('', week)
|
|
|
+ result = result.filter(id=ei_id, event_time=dt)
|
|
|
+ if result.exists():
|
|
|
+ own_dev = ModelService.check_own_device(userID, result[0].device_uid)
|
|
|
+ if own_dev is True:
|
|
|
+ result.delete()
|
|
|
+
|
|
|
except Exception as e:
|
|
|
errorInfo = traceback.format_exc()
|
|
|
print(errorInfo)
|