|
@@ -66,17 +66,22 @@ class deptView(APIView):
|
|
|
|
|
|
"""
|
|
"""
|
|
删除节点
|
|
删除节点
|
|
- {id:节点id}
|
|
|
|
|
|
+ {id:部门id}
|
|
"""
|
|
"""
|
|
|
|
|
|
def delete(self, request):
|
|
def delete(self, request):
|
|
data = request.data
|
|
data = request.data
|
|
- # 部门 删除这个部门
|
|
|
|
- res = Dept.objects.filter(id=data['id']).delete()
|
|
|
|
|
|
|
|
# 岗位 删除这个部门下面的所有岗位
|
|
# 岗位 删除这个部门下面的所有岗位
|
|
- # Jobs.objects.filter()
|
|
|
|
- # Dept2Jobs.objects.filter(dept_id=data['id'])
|
|
|
|
|
|
+ # 这个部门下面的所有岗位
|
|
|
|
+ jobs = Dept2Jobs.objects.filter(dept_id=data['id']).values('job_id').all()
|
|
|
|
+ job_ids = []
|
|
|
|
+ for job in jobs:
|
|
|
|
+ job_ids.append(job['job_id'])
|
|
|
|
+ Jobs.objects.filter(id__in=job_ids).delete()
|
|
|
|
+
|
|
|
|
+ # 部门 删除这个部门
|
|
|
|
+ res = Dept.objects.filter(id=data['id']).delete()
|
|
|
|
|
|
# 关联表 删除跟这个部门关联的
|
|
# 关联表 删除跟这个部门关联的
|
|
Dept2Jobs.objects.filter(dept_id=data['id']).delete()
|
|
Dept2Jobs.objects.filter(dept_id=data['id']).delete()
|
|
@@ -143,14 +148,34 @@ class userView(APIView):
|
|
def post(self, request):
|
|
def post(self, request):
|
|
pass
|
|
pass
|
|
|
|
|
|
- # 用户查询
|
|
|
|
|
|
+ # 用户查询 {job_id:岗位id(可空,有则选这个岗位下的用户)}
|
|
def get(self, request):
|
|
def get(self, request):
|
|
data = request.GET
|
|
data = request.GET
|
|
- res = User.objects.values('id', 'username', 'email')
|
|
|
|
- return Response(data={'result': res, 'message': '查询所有用户基础数据'}, status=status.HTTP_200_OK)
|
|
|
|
|
|
+ if 'job_id' in data:
|
|
|
|
+ job_ids = Dept2Jobs.objects.filter(job_id=data['job_id'], user_id__isnull=False).values()
|
|
|
|
+ ids = []
|
|
|
|
+ for id in job_ids:
|
|
|
|
+ ids.append(id)
|
|
|
|
+ res = User.objects.filter(id__in=ids).values()
|
|
|
|
+ else:
|
|
|
|
+ res = User.objects.values()
|
|
|
|
+
|
|
|
|
+ return Response(data={'result': res, 'message': '查询用户基础数据'}, status=status.HTTP_200_OK)
|
|
|
|
|
|
|
|
+ # 用户替换部门 {job_id:岗位id,user_ids:用户id数组,type:移除用户还是新增用户(0移除,1新增)}
|
|
def put(self, request):
|
|
def put(self, request):
|
|
- pass
|
|
|
|
|
|
+ data = request.data
|
|
|
|
+ res = {}
|
|
|
|
+ if data['type'] == 0:
|
|
|
|
+ # 岗位下删除这个用户
|
|
|
|
+ Dept2Jobs.objects.filter(job_id=data['job_id'], user_id__in=data['user_ids']).delete()
|
|
|
|
+ res = {'message': '删除用户'}
|
|
|
|
+ elif data['type'] == 1:
|
|
|
|
+ # 岗位下新增用户
|
|
|
|
+ for user_id in data['user_ids']:
|
|
|
|
+ Dept2Jobs.objects.create(job_id=data['job_id'], user_id=user_id)
|
|
|
|
+ res = {'message': '新增用户'}
|
|
|
|
+ return Response(data=res, status=status.HTTP_200_OK)
|
|
|
|
|
|
def delete(self, request):
|
|
def delete(self, request):
|
|
pass
|
|
pass
|