|
@@ -1,7 +1,7 @@
|
|
|
import json
|
|
|
|
|
|
from django.contrib.auth.models import User
|
|
|
-from django.db.models import Q
|
|
|
+from django.db.models import Q, Sum
|
|
|
from django.forms.models import model_to_dict
|
|
|
from rest_framework import status
|
|
|
from rest_framework.response import Response
|
|
@@ -12,6 +12,8 @@ from even_table.models import Dept, Jobs, Dept2Jobs
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
class deptView(APIView):
|
|
|
"""
|
|
|
request {name名字},parent_id{父级id,可空}
|
|
@@ -125,7 +127,8 @@ class jobsView(APIView):
|
|
|
|
|
|
def get(self, request):
|
|
|
|
|
|
- names = Dept2Jobs.objects.filter(dept=request.GET['dept_id']).values("job", "job__name")
|
|
|
+ names = Dept2Jobs.objects.filter(dept=request.GET['dept_id']).values("job", "job__name").annotate(
|
|
|
+ jog_sum=Sum('job'))
|
|
|
|
|
|
return Response(data={'result': names, 'message': '查询成功'}, status=status.HTTP_200_OK)
|
|
|
|
|
@@ -145,18 +148,18 @@ class jobsView(APIView):
|
|
|
|
|
|
|
|
|
class userView(APIView):
|
|
|
- def post(self, request):
|
|
|
- pass
|
|
|
|
|
|
|
|
|
def get(self, request):
|
|
|
data = request.GET
|
|
|
+ res = []
|
|
|
if 'job_id' in data:
|
|
|
- job_ids = Dept2Jobs.objects.filter(job_id=data['job_id'], user_id__isnull=False).values()
|
|
|
+ job_ids = Dept2Jobs.objects.filter(job_id=data['job_id'], user_id__isnull=False).values('user_id')
|
|
|
ids = []
|
|
|
for id in job_ids:
|
|
|
- ids.append(id)
|
|
|
- res = User.objects.filter(id__in=ids).values()
|
|
|
+ ids.append(id['user_id'])
|
|
|
+ if len(ids) != 0:
|
|
|
+ res = User.objects.filter(id__in=ids).values()
|
|
|
else:
|
|
|
res = User.objects.values()
|
|
|
|
|
@@ -179,3 +182,15 @@ class userView(APIView):
|
|
|
|
|
|
def delete(self, request):
|
|
|
pass
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+class Dept2JobsView(APIView):
|
|
|
+
|
|
|
+ def post(self, request):
|
|
|
+
|
|
|
+ Dept2Jobs.objects.filter(~Q(user_id=None), dept_id=request.data['dept_id'],
|
|
|
+ job_id=request.data['job_id']).delete()
|
|
|
+ for user_id in request.data['user_id']:
|
|
|
+ Dept2Jobs(dept_id=request.data['dept_id'], job_id=request.data['job_id'], user_id=user_id).save()
|
|
|
+ return Response(data=None, status=status.HTTP_200_OK)
|