fix: 调整system app去除无用的
This commit is contained in:
parent
b25dfcac0c
commit
28e6bf0fc5
|
@ -2,9 +2,7 @@
|
||||||
from django_celery_beat.models import PeriodicTask, CrontabSchedule, IntervalSchedule
|
from django_celery_beat.models import PeriodicTask, CrontabSchedule, IntervalSchedule
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from django_celery_results.models import TaskResult
|
from django_celery_results.models import TaskResult
|
||||||
from apps.hrm.errors import PHONE_EXIST
|
|
||||||
from apps.system.errors import USERNAME_EXIST
|
from apps.system.errors import USERNAME_EXIST
|
||||||
from apps.system.services import sync_dahua_dept
|
|
||||||
from apps.utils.fields import MyFilePathField
|
from apps.utils.fields import MyFilePathField
|
||||||
from apps.utils.serializers import CustomModelSerializer
|
from apps.utils.serializers import CustomModelSerializer
|
||||||
from apps.utils.constants import EXCLUDE_FIELDS, EXCLUDE_FIELDS_BASE
|
from apps.utils.constants import EXCLUDE_FIELDS, EXCLUDE_FIELDS_BASE
|
||||||
|
@ -13,7 +11,6 @@ from .models import (Dictionary, DictType, File, Dept, MySchedule, Permission, P
|
||||||
Role, User, UserPost)
|
Role, User, UserPost)
|
||||||
from rest_framework.exceptions import ParseError, ValidationError
|
from rest_framework.exceptions import ParseError, ValidationError
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from apps.third.tapis import dhapis
|
|
||||||
from rest_framework.validators import UniqueValidator
|
from rest_framework.validators import UniqueValidator
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
@ -255,7 +252,8 @@ class DeptCreateUpdateSerializer(CustomModelSerializer):
|
||||||
"""
|
"""
|
||||||
部门序列化
|
部门序列化
|
||||||
"""
|
"""
|
||||||
parent = serializers.PrimaryKeyRelatedField(queryset=Dept.objects.all(), required=True)
|
parent = serializers.PrimaryKeyRelatedField(
|
||||||
|
queryset=Dept.objects.all(), required=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Dept
|
model = Dept
|
||||||
|
@ -281,7 +279,9 @@ class UserSimpleSerializer(CustomModelSerializer):
|
||||||
|
|
||||||
|
|
||||||
class UserSignatureSerializer(CustomModelSerializer):
|
class UserSignatureSerializer(CustomModelSerializer):
|
||||||
signature = serializers.CharField(source='employee.signature', read_only=True)
|
signature = serializers.CharField(
|
||||||
|
source='employee.signature', read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
fields = ['id', 'username', 'name', 'phone', 'signature']
|
fields = ['id', 'username', 'name', 'phone', 'signature']
|
||||||
|
@ -291,7 +291,8 @@ class UserListSerializer(CustomModelSerializer):
|
||||||
"""
|
"""
|
||||||
用户列表序列化
|
用户列表序列化
|
||||||
"""
|
"""
|
||||||
belong_dept_name = serializers.CharField(source='belong_dept.name', read_only=True)
|
belong_dept_name = serializers.CharField(
|
||||||
|
source='belong_dept.name', read_only=True)
|
||||||
post_name = serializers.CharField(source='post.name', read_only=True)
|
post_name = serializers.CharField(source='post.name', read_only=True)
|
||||||
# posts_ = PostSimpleSerializer(source='posts', many=True)
|
# posts_ = PostSimpleSerializer(source='posts', many=True)
|
||||||
avatar_f = MyFilePathField(source='avatar', read_only=True)
|
avatar_f = MyFilePathField(source='avatar', read_only=True)
|
||||||
|
@ -394,7 +395,8 @@ class UserInfoSerializer(CustomModelSerializer):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
fields = ['id', 'username', 'name', 'post', 'avatar', 'belong_dept', 'type']
|
fields = ['id', 'username', 'name', 'post',
|
||||||
|
'avatar', 'belong_dept', 'type']
|
||||||
|
|
||||||
|
|
||||||
class ApkSerializer(serializers.Serializer):
|
class ApkSerializer(serializers.Serializer):
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
from apps.system.models import Dept
|
|
||||||
from django.conf import settings
|
|
||||||
from apps.third.tapis import dhapis
|
|
||||||
from apps.third.dahua import dhClient
|
|
||||||
|
|
||||||
|
|
||||||
def sync_dahua_dept(dept: Dept):
|
|
||||||
# 同步大华部门信息
|
|
||||||
third_info = dept.third_info
|
|
||||||
if settings.DAHUA_ENABLED:
|
|
||||||
if third_info.get('dh_id', False):
|
|
||||||
data = {
|
|
||||||
"id": dept.third_info['dh_id'],
|
|
||||||
"parentId": 1,
|
|
||||||
"name": dept.name
|
|
||||||
}
|
|
||||||
dhClient.request(**dhapis['dept_update'], json=data)
|
|
||||||
else:
|
|
||||||
# 如果dh_id 不存在
|
|
||||||
data = {
|
|
||||||
"parentId": 1,
|
|
||||||
"name": dept.name,
|
|
||||||
"service": "ehs"
|
|
||||||
}
|
|
||||||
_, res = dhClient.request(**dhapis['dept_create'], json=data)
|
|
||||||
third_info['dh_id'] = res['id']
|
|
||||||
dept.third_info = third_info
|
|
||||||
dept.save()
|
|
||||||
dhClient.face_bind()
|
|
|
@ -17,7 +17,6 @@ from rest_framework.serializers import Serializer
|
||||||
from rest_framework.permissions import IsAuthenticated, AllowAny
|
from rest_framework.permissions import IsAuthenticated, AllowAny
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
from apps.hrm.models import Employee
|
|
||||||
from apps.system.errors import OLD_PASSWORD_WRONG, PASSWORD_NOT_SAME, SCHEDULE_WRONG
|
from apps.system.errors import OLD_PASSWORD_WRONG, PASSWORD_NOT_SAME, SCHEDULE_WRONG
|
||||||
from apps.system.filters import DeptFilterSet, UserFilterSet
|
from apps.system.filters import DeptFilterSet, UserFilterSet
|
||||||
# from django_q.models import Task as QTask, Schedule as QSchedule
|
# from django_q.models import Task as QTask, Schedule as QSchedule
|
||||||
|
@ -383,14 +382,16 @@ class UserPostViewSet(CreateModelMixin, DestroyModelMixin, ListModelMixin, Custo
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
instance = serializer.save()
|
instance = serializer.save()
|
||||||
user = instance.user
|
user = instance.user
|
||||||
up = UserPost.objects.filter(user=user).order_by('sort', 'create_time').first()
|
up = UserPost.objects.filter(user=user).order_by(
|
||||||
|
'sort', 'create_time').first()
|
||||||
if up:
|
if up:
|
||||||
user.belong_dept = up.dept
|
user.belong_dept = up.dept
|
||||||
user.post = up.post
|
user.post = up.post
|
||||||
user.update_by = self.request.user
|
user.update_by = self.request.user
|
||||||
user.save()
|
user.save()
|
||||||
# 更新人员表
|
# 更新人员表
|
||||||
ep = Employee.objects.get_queryset(all=True).filter(user=user).first()
|
ep = Employee.objects.get_queryset(
|
||||||
|
all=True).filter(user=user).first()
|
||||||
if ep:
|
if ep:
|
||||||
ep.belong_dept = user.belong_dept
|
ep.belong_dept = user.belong_dept
|
||||||
ep.post = user.post
|
ep.post = user.post
|
||||||
|
@ -401,7 +402,8 @@ class UserPostViewSet(CreateModelMixin, DestroyModelMixin, ListModelMixin, Custo
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
user = instance.user
|
user = instance.user
|
||||||
instance.delete()
|
instance.delete()
|
||||||
up = UserPost.objects.filter(user=user).order_by('sort', 'create_time').first()
|
up = UserPost.objects.filter(user=user).order_by(
|
||||||
|
'sort', 'create_time').first()
|
||||||
if up:
|
if up:
|
||||||
user.belong_dept = up.dept
|
user.belong_dept = up.dept
|
||||||
user.post = up.post
|
user.post = up.post
|
||||||
|
@ -411,7 +413,8 @@ class UserPostViewSet(CreateModelMixin, DestroyModelMixin, ListModelMixin, Custo
|
||||||
user.update_by = self.request.user
|
user.update_by = self.request.user
|
||||||
user.save()
|
user.save()
|
||||||
# 更新人员表
|
# 更新人员表
|
||||||
ep = Employee.objects.get_queryset(all=True).filter(user=user).first()
|
ep = Employee.objects.get_queryset(
|
||||||
|
all=True).filter(user=user).first()
|
||||||
if ep:
|
if ep:
|
||||||
ep.belong_dept = user.belong_dept
|
ep.belong_dept = user.belong_dept
|
||||||
ep.post = user.post
|
ep.post = user.post
|
||||||
|
@ -437,8 +440,10 @@ class UserViewSet(CustomModelViewSet):
|
||||||
|
|
||||||
def perform_update(self, serializer):
|
def perform_update(self, serializer):
|
||||||
instance = serializer.save()
|
instance = serializer.save()
|
||||||
ep = Employee.objects.get_queryset(all=True).filter(user=instance).first()
|
ep = Employee.objects.get_queryset(
|
||||||
ep2 = Employee.objects.get_queryset(all=True).filter(phone=instance.phone).first()
|
all=True).filter(user=instance).first()
|
||||||
|
ep2 = Employee.objects.get_queryset(
|
||||||
|
all=True).filter(phone=instance.phone).first()
|
||||||
if ep:
|
if ep:
|
||||||
pass
|
pass
|
||||||
elif ep2:
|
elif ep2:
|
||||||
|
@ -461,8 +466,10 @@ class UserViewSet(CustomModelViewSet):
|
||||||
serializer = self.get_serializer(data=request.data)
|
serializer = self.get_serializer(data=request.data)
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
instance = serializer.save(password=password, belong_dept=None)
|
instance = serializer.save(password=password, belong_dept=None)
|
||||||
ep = Employee.objects.get_queryset(all=True).filter(user=instance).first()
|
ep = Employee.objects.get_queryset(
|
||||||
ep2 = Employee.objects.get_queryset(all=True).filter(phone=instance.phone).first()
|
all=True).filter(user=instance).first()
|
||||||
|
ep2 = Employee.objects.get_queryset(
|
||||||
|
all=True).filter(phone=instance.phone).first()
|
||||||
if ep:
|
if ep:
|
||||||
pass
|
pass
|
||||||
elif ep2:
|
elif ep2:
|
||||||
|
@ -548,7 +555,8 @@ class UserViewSet(CustomModelViewSet):
|
||||||
if openid:
|
if openid:
|
||||||
user = request.user
|
user = request.user
|
||||||
if user.wxmp_openid != openid:
|
if user.wxmp_openid != openid:
|
||||||
User.objects.filter(wxmp_openid=openid).update(wxmp_openid=None)
|
User.objects.filter(wxmp_openid=openid).update(
|
||||||
|
wxmp_openid=None)
|
||||||
user.wxmp_openid = openid
|
user.wxmp_openid = openid
|
||||||
user.save()
|
user.save()
|
||||||
return Response({'wxmp_openid': openid})
|
return Response({'wxmp_openid': openid})
|
||||||
|
@ -668,7 +676,7 @@ class ApkViewSet(MyLoggingMixin, ListModelMixin, CreateModelMixin, GenericViewSe
|
||||||
sr.is_valid(raise_exception=True)
|
sr.is_valid(raise_exception=True)
|
||||||
vdata = sr.validated_data
|
vdata = sr.validated_data
|
||||||
update_sysconfig({
|
update_sysconfig({
|
||||||
"apk":{
|
"apk": {
|
||||||
"apk_version": vdata['version'],
|
"apk_version": vdata['version'],
|
||||||
"apk_file": vdata['file']
|
"apk_file": vdata['file']
|
||||||
}
|
}
|
||||||
|
@ -677,7 +685,8 @@ class ApkViewSet(MyLoggingMixin, ListModelMixin, CreateModelMixin, GenericViewSe
|
||||||
|
|
||||||
|
|
||||||
class MyScheduleViewSet(ListModelMixin, CreateModelMixin, DestroyModelMixin, CustomGenericViewSet):
|
class MyScheduleViewSet(ListModelMixin, CreateModelMixin, DestroyModelMixin, CustomGenericViewSet):
|
||||||
perms_map = {'get': '*', 'post': 'myschedule.create', 'delete': 'myschedule.delete'}
|
perms_map = {'get': '*', 'post': 'myschedule.create',
|
||||||
|
'delete': 'myschedule.delete'}
|
||||||
serializer_class = MyScheduleSerializer
|
serializer_class = MyScheduleSerializer
|
||||||
create_serializer_class = MyScheduleCreateSerializer
|
create_serializer_class = MyScheduleCreateSerializer
|
||||||
queryset = MySchedule.objects.all()
|
queryset = MySchedule.objects.all()
|
||||||
|
@ -689,7 +698,8 @@ class MyScheduleViewSet(ListModelMixin, CreateModelMixin, DestroyModelMixin, Cus
|
||||||
"seconds": "秒",
|
"seconds": "秒",
|
||||||
"microseconds": "毫秒"
|
"microseconds": "毫秒"
|
||||||
}
|
}
|
||||||
def get_chinese_description(self, type:str = 'interval', data: dict = {}):
|
|
||||||
|
def get_chinese_description(self, type: str = 'interval', data: dict = {}):
|
||||||
"""转换为汉语描述
|
"""转换为汉语描述
|
||||||
"""
|
"""
|
||||||
if type == 'interval':
|
if type == 'interval':
|
||||||
|
@ -702,18 +712,20 @@ class MyScheduleViewSet(ListModelMixin, CreateModelMixin, DestroyModelMixin, Cus
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def perform_create(self, serializer):
|
def perform_create(self, serializer):
|
||||||
vdata = serializer.validated_data
|
vdata = serializer.validated_data
|
||||||
vdata['create_by'] = self.request.user #不可少
|
vdata['create_by'] = self.request.user # 不可少
|
||||||
interval_data = vdata.pop('interval_', None)
|
interval_data = vdata.pop('interval_', None)
|
||||||
crontab_data = vdata.pop('crontab_', None)
|
crontab_data = vdata.pop('crontab_', None)
|
||||||
if vdata['type'] == 10:
|
if vdata['type'] == 10:
|
||||||
interval, _ = IntervalSchedule.objects.get_or_create(**interval_data, defaults=interval_data)
|
interval, _ = IntervalSchedule.objects.get_or_create(
|
||||||
|
**interval_data, defaults=interval_data)
|
||||||
obj = MySchedule(**vdata)
|
obj = MySchedule(**vdata)
|
||||||
obj.name = self.get_chinese_description('interval', vdata)
|
obj.name = self.get_chinese_description('interval', vdata)
|
||||||
obj.interval = interval
|
obj.interval = interval
|
||||||
obj.save()
|
obj.save()
|
||||||
elif vdata['type'] == 20:
|
elif vdata['type'] == 20:
|
||||||
crontab_data['timezone'] = 'Asia/Shanghai'
|
crontab_data['timezone'] = 'Asia/Shanghai'
|
||||||
crontab, _ = CrontabSchedule.objects.get_or_create(**crontab_data, defaults=crontab_data)
|
crontab, _ = CrontabSchedule.objects.get_or_create(
|
||||||
|
**crontab_data, defaults=crontab_data)
|
||||||
obj = MySchedule(**vdata)
|
obj = MySchedule(**vdata)
|
||||||
obj.name = self.get_chinese_description('crontab', vdata)
|
obj.name = self.get_chinese_description('crontab', vdata)
|
||||||
obj.crontab = crontab
|
obj.crontab = crontab
|
||||||
|
@ -732,9 +744,11 @@ class SysBaseConfigView(APIView):
|
||||||
获取系统基本信息
|
获取系统基本信息
|
||||||
"""
|
"""
|
||||||
config = get_sysconfig()
|
config = get_sysconfig()
|
||||||
base_dict = {key: config[key] for key in self.read_keys if key in config}
|
base_dict = {key: config[key]
|
||||||
|
for key in self.read_keys if key in config}
|
||||||
return Response(base_dict)
|
return Response(base_dict)
|
||||||
|
|
||||||
|
|
||||||
class SysConfigView(MyLoggingMixin, APIView):
|
class SysConfigView(MyLoggingMixin, APIView):
|
||||||
perms_map = {'get': 'sysconfig.view', 'put': 'sysconfig.update'}
|
perms_map = {'get': 'sysconfig.view', 'put': 'sysconfig.update'}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,6 @@ urlpatterns = [
|
||||||
# api
|
# api
|
||||||
path('', include('apps.auth1.urls')),
|
path('', include('apps.auth1.urls')),
|
||||||
path('', include('apps.system.urls')),
|
path('', include('apps.system.urls')),
|
||||||
path('', include('apps.monitor.urls')),
|
|
||||||
path('', include('apps.wf.urls')),
|
path('', include('apps.wf.urls')),
|
||||||
path('', include('apps.utils.urls')),
|
path('', include('apps.utils.urls')),
|
||||||
path('', include('apps.ops.urls')),
|
path('', include('apps.ops.urls')),
|
||||||
|
@ -51,9 +50,12 @@ urlpatterns = [
|
||||||
|
|
||||||
|
|
||||||
# api文档
|
# api文档
|
||||||
path('api/docs/', include_docs_urls(title="接口文档", authentication_classes=[], permission_classes=[])),
|
path('api/docs/', include_docs_urls(title="接口文档",
|
||||||
path('api/swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
|
authentication_classes=[], permission_classes=[])),
|
||||||
path('api/redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
|
path('api/swagger/', schema_view.with_ui('swagger',
|
||||||
|
cache_timeout=0), name='schema-swagger-ui'),
|
||||||
|
path('api/redoc/', schema_view.with_ui('redoc',
|
||||||
|
cache_timeout=0), name='schema-redoc'),
|
||||||
# 前端页面入口
|
# 前端页面入口
|
||||||
path('', TemplateView.as_view(template_name="index.html")),
|
path('', TemplateView.as_view(template_name="index.html")),
|
||||||
] + \
|
] + \
|
||||||
|
|
Loading…
Reference in New Issue