fix: 调整system app去除无用的

This commit is contained in:
caoqianming 2023-10-10 14:08:02 +08:00
parent b25dfcac0c
commit 28e6bf0fc5
4 changed files with 54 additions and 65 deletions

View File

@ -2,9 +2,7 @@
from django_celery_beat.models import PeriodicTask, CrontabSchedule, IntervalSchedule
from rest_framework import serializers
from django_celery_results.models import TaskResult
from apps.hrm.errors import PHONE_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.serializers import CustomModelSerializer
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)
from rest_framework.exceptions import ParseError, ValidationError
from django.db import transaction
from apps.third.tapis import dhapis
from rest_framework.validators import UniqueValidator
from django.conf import settings
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:
model = Dept
@ -281,7 +279,9 @@ class UserSimpleSerializer(CustomModelSerializer):
class UserSignatureSerializer(CustomModelSerializer):
signature = serializers.CharField(source='employee.signature', read_only=True)
signature = serializers.CharField(
source='employee.signature', read_only=True)
class Meta:
model = User
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)
# posts_ = PostSimpleSerializer(source='posts', many=True)
avatar_f = MyFilePathField(source='avatar', read_only=True)
@ -394,7 +395,8 @@ class UserInfoSerializer(CustomModelSerializer):
class Meta:
model = User
fields = ['id', 'username', 'name', 'post', 'avatar', 'belong_dept', 'type']
fields = ['id', 'username', 'name', 'post',
'avatar', 'belong_dept', 'type']
class ApkSerializer(serializers.Serializer):

View File

@ -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()

View File

@ -17,7 +17,6 @@ from rest_framework.serializers import Serializer
from rest_framework.permissions import IsAuthenticated, AllowAny
from rest_framework.response import Response
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.filters import DeptFilterSet, UserFilterSet
# from django_q.models import Task as QTask, Schedule as QSchedule
@ -383,14 +382,16 @@ class UserPostViewSet(CreateModelMixin, DestroyModelMixin, ListModelMixin, Custo
with transaction.atomic():
instance = serializer.save()
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:
user.belong_dept = up.dept
user.post = up.post
user.update_by = self.request.user
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:
ep.belong_dept = user.belong_dept
ep.post = user.post
@ -401,7 +402,8 @@ class UserPostViewSet(CreateModelMixin, DestroyModelMixin, ListModelMixin, Custo
with transaction.atomic():
user = instance.user
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:
user.belong_dept = up.dept
user.post = up.post
@ -411,7 +413,8 @@ class UserPostViewSet(CreateModelMixin, DestroyModelMixin, ListModelMixin, Custo
user.update_by = self.request.user
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:
ep.belong_dept = user.belong_dept
ep.post = user.post
@ -431,14 +434,16 @@ class UserViewSet(CustomModelViewSet):
ordering = ['create_time', 'type']
def get_queryset(self):
if self.request.method == 'GET' and (not self.request.query_params.get('is_deleted', None)):
if self.request.method == 'GET' and (not self.request.query_params.get('is_deleted', None)):
self.queryset = User.objects.all()
return super().get_queryset()
def perform_update(self, serializer):
instance = serializer.save()
ep = Employee.objects.get_queryset(all=True).filter(user=instance).first()
ep2 = Employee.objects.get_queryset(all=True).filter(phone=instance.phone).first()
ep = Employee.objects.get_queryset(
all=True).filter(user=instance).first()
ep2 = Employee.objects.get_queryset(
all=True).filter(phone=instance.phone).first()
if ep:
pass
elif ep2:
@ -461,8 +466,10 @@ class UserViewSet(CustomModelViewSet):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
instance = serializer.save(password=password, belong_dept=None)
ep = Employee.objects.get_queryset(all=True).filter(user=instance).first()
ep2 = Employee.objects.get_queryset(all=True).filter(phone=instance.phone).first()
ep = Employee.objects.get_queryset(
all=True).filter(user=instance).first()
ep2 = Employee.objects.get_queryset(
all=True).filter(phone=instance.phone).first()
if ep:
pass
elif ep2:
@ -500,7 +507,7 @@ class UserViewSet(CustomModelViewSet):
raise ParseError(**PASSWORD_NOT_SAME)
else:
raise ValidationError(**OLD_PASSWORD_WRONG)
@action(methods=['post'], detail=True, perms_map={'post': '*'}, serializer_class=Serializer)
def reset_password(self, request, pk=None):
user = self.get_object()
@ -548,7 +555,8 @@ class UserViewSet(CustomModelViewSet):
if openid:
user = request.user
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.save()
return Response({'wxmp_openid': openid})
@ -668,16 +676,17 @@ class ApkViewSet(MyLoggingMixin, ListModelMixin, CreateModelMixin, GenericViewSe
sr.is_valid(raise_exception=True)
vdata = sr.validated_data
update_sysconfig({
"apk":{
"apk": {
"apk_version": vdata['version'],
"apk_file": vdata['file']
}
})
return Response()
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
create_serializer_class = MyScheduleCreateSerializer
queryset = MySchedule.objects.all()
@ -689,7 +698,8 @@ class MyScheduleViewSet(ListModelMixin, CreateModelMixin, DestroyModelMixin, Cus
"seconds": "",
"microseconds": "毫秒"
}
def get_chinese_description(self, type:str = 'interval', data: dict = {}):
def get_chinese_description(self, type: str = 'interval', data: dict = {}):
"""转换为汉语描述
"""
if type == 'interval':
@ -698,22 +708,24 @@ class MyScheduleViewSet(ListModelMixin, CreateModelMixin, DestroyModelMixin, Cus
locale.setlocale(locale.LC_ALL, 'zh_CN.UTF-8')
return get_description(f"{data['minute']} {data['hour']} {data['day_of_month']} {data['month_of_year']} {data['day_of_week']}")
return ''
@transaction.atomic
def perform_create(self, serializer):
vdata = serializer.validated_data
vdata['create_by'] = self.request.user #不可少
vdata['create_by'] = self.request.user # 不可少
interval_data = vdata.pop('interval_', None)
crontab_data = vdata.pop('crontab_', None)
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.name = self.get_chinese_description('interval', vdata)
obj.interval = interval
obj.save()
elif vdata['type'] == 20:
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.name = self.get_chinese_description('crontab', vdata)
obj.crontab = crontab
@ -732,12 +744,14 @@ class SysBaseConfigView(APIView):
获取系统基本信息
"""
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)
class SysConfigView(MyLoggingMixin, APIView):
perms_map = {'get': 'sysconfig.view', 'put': 'sysconfig.update'}
def get(self, request, format=None):
"""
获取config json
@ -748,7 +762,7 @@ class SysConfigView(MyLoggingMixin, APIView):
if request.query_params.get('reload', None):
reload = True
return Response(get_sysconfig(reload=reload))
@swagger_auto_schema(request_body=Serializer)
def put(self, request, format=None):
"""
@ -758,4 +772,4 @@ class SysConfigView(MyLoggingMixin, APIView):
"""
data = request.data
update_sysconfig(data)
return Response()
return Response()

View File

@ -43,7 +43,6 @@ urlpatterns = [
# api
path('', include('apps.auth1.urls')),
path('', include('apps.system.urls')),
path('', include('apps.monitor.urls')),
path('', include('apps.wf.urls')),
path('', include('apps.utils.urls')),
path('', include('apps.ops.urls')),
@ -51,9 +50,12 @@ urlpatterns = [
# api文档
path('api/docs/', include_docs_urls(title="接口文档", authentication_classes=[], permission_classes=[])),
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('api/docs/', include_docs_urls(title="接口文档",
authentication_classes=[], permission_classes=[])),
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")),
] + \