Merge branch 'master' of https://e.coding.net/ctcdevteam/safesite
This commit is contained in:
commit
3e7033cb25
|
@ -131,7 +131,7 @@ class TroubleListView(APIView):
|
|||
|
||||
|
||||
def post(self, request):
|
||||
# 查询某一天的隐患, 默认是当天
|
||||
# 查询某一时间段的隐患, 默认是当天
|
||||
data = request.data
|
||||
if 'token' not in data:
|
||||
return Response({'code': 400, 'msg': '请提供token', 'data': None})
|
||||
|
@ -139,13 +139,24 @@ class TroubleListView(APIView):
|
|||
if user_data is None:
|
||||
return Response({'code': 400, 'msg': '无效token', 'data': None})
|
||||
company_id = user_data['company_id']
|
||||
day = datetime.now().date()
|
||||
if 'date' in data:
|
||||
day = datetime.strptime(data['date'],'%Y-%m-%d').date()
|
||||
objs = Trouble.objects.filter(usecomp__partid=company_id).exclude(deletemark=0)
|
||||
if data.get('type', 1) == 2: # 当时整改的
|
||||
objs = objs.filter(zgsj__year=day.year, zgsj__month=day.month, zgsj__day=day.day)
|
||||
if data.get('time_start', None):
|
||||
objs = objs.filter(zgsj__gte=data['time_start'])
|
||||
if data.get('time_end', None):
|
||||
objs = objs.filter(zgsj__lte=data['time_end'])
|
||||
if data.get('date', None):
|
||||
day = datetime.strptime(data['date'],'%Y-%m-%d').date()
|
||||
objs = objs.filter(zgsj__year=day.year, zgsj__month=day.month, zgsj__day=day.day)
|
||||
else:
|
||||
objs = objs.filter(fxsj__year=day.year, fxsj__month=day.month, fxsj__day=day.day)
|
||||
if data.get('time_start', None):
|
||||
objs = objs.filter(fxsj__gte=data['time_start'])
|
||||
if data.get('time_end', None):
|
||||
objs = objs.filter(fxsj__lte=data['time_end'])
|
||||
if data.get('date', None):
|
||||
day = datetime.strptime(data['date'],'%Y-%m-%d').date()
|
||||
objs = objs.filter(fxsj__year=day.year, fxsj__month=day.month, fxsj__day=day.day)
|
||||
if objs.count() >= 1000:
|
||||
return Response({'code': 400, 'msg': '列表过长,请重新规划时间范围', 'data': None})
|
||||
serializer = TroubleListSerializer(instance=objs, many=True)
|
||||
return Response({'code': 200, 'data': serializer.data, 'msg': None})
|
||||
|
|
Loading…
Reference in New Issue