from django.http import JsonResponse
import json
from common.models import Customer,Clocktime,Staff,User,Num,Leave
from django.utils import timezone
import os
from datetime import datetime
import time
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage, InvalidPage
from django.http import HttpResponse
from django.shortcuts import render
from django.core.files.storage import default_storage
from django.core.files.base import ContentFile
from django.conf import settings
import string
def fun(username):
os.system("python mgr/人脸识别.py %s" % (username))
def dispatcher(request):
# 浏览器关闭时清除cookie
request.session.set_expiry(0)
if 'usertype' not in request.session:
return JsonResponse({
'ret': 302,
'msg': '管理员',
'redirect': '/mgr/login.html'
},
)
# 将请求参数统一放入request 的 params 属性中,方便后续处理
# GET请求 参数在url中,同过request 对象的 GET属性获取
if request.method == 'GET':
request.params = request.GET
# POST/PUT/DELETE 请求 参数 从 request 对象的 body 属性中获取
elif request.method in ['POST','PUT','DELETE']:
# 根据接口,POST/PUT/DELETE 请求的消息体都是 json格式
request.params = json.loads(request.body)
# 根据不同的action分派给不同的函数进行处理
action = request.params['action']
if action == 'validatelogon':
return validatelogon(request)
elif action == 'add_customer':
return addcustomer(request)
elif action == 'modify_customer':
return modifycustomer(request)
elif action == 'del_customer':
return deletecustomer(request)
elif action == 'face_customer':
return facecustomer(request)
elif action == 'signin_customer':
return signincustomer(request)
elif action == 'logout_customer':
return logoutcustomer(request)
elif action == 'list_staff':
return liststaff(request)
elif action == 'export':
return export(request)
elif action == 'vip':
return vip(request)
elif action == 'Remarks':
return Remarks(request)
elif action == 'Clocktime_list':
return Clocktime_list(request)
elif action == 'num':
return num(request)
elif action == 'export_clocktimelist':
return export_clocktimelist(request)
elif action == 'Retype':
return Retype(request)
elif action == 'update':
return update(request)
elif action == 'export_num':
return export_num(request)
elif action == 'leave':
return leave(request)
elif action == 'leave_list':
return leave_list(request)
elif action == 'export_leave':
return export_leave(request)
elif action == 'Agree':
return Agree(request)
elif action == 'myleave_list':
return myleave_list(request)
elif action == 'Absence':
return Absence(request)
else:
return JsonResponse({'ret': 1, 'msg': '不支持该类型http请求'})
def Agree(request):
refusal = request.params['refusal']
name = request.params['name']
times = request.params['times']
s1 = request.params['s1']
s2= request.params['s2']
s3= request.params['s3']
s4 = request.params['s4']
day_num = request.params['day_num']
type = request.params['type']
leave = Leave.objects.get(name=name,times=times)
username=User.objects.filter(username=name).values_list('id')
namelist=list(username)
a=times.replace('年', '-').replace('月', '-').replace('日','')
if type=='1':
leave.code =1
if day_num=='1':
record = Clocktime.objects.create(name=name,code='1',signin=a,signout=a,nowtime=times,year_month=times, worktimes='0',staff_id=namelist[0][0])
elif day_num=='2':
record1 = Clocktime.objects.create(name=name,code='1',signin=a,signout=a,nowtime=times,year_month=times, worktimes='0',staff_id=namelist[0][0])
record2 = Clocktime.objects.create(name=name,code='1',signin=a,signout=a,nowtime=s1,year_month=s1, worktimes='0',staff_id=namelist[0][0])
elif day_num=='3':
record1= Clocktime.objects.create(name=name,code='1',signin=a,signout=a,nowtime=times,year_month=times, worktimes='0',staff_id=namelist[0][0])
record2 = Clocktime.objects.create(name=name,code='1',signin=a,signout=a,nowtime=s1,year_month=s1, worktimes='0',staff_id=namelist[0][0])
record3 = Clocktime.objects.create(name=name,code='1',signin=a,signout=a,nowtime=s2,year_month=s2, worktimes='0',staff_id=namelist[0][0])
elif day_num=='4':
record1 = Clocktime.objects.create(name=name,code='1',signin=a,signout=a,nowtime=times,year_month=times, worktimes='0',staff_id=namelist[0][0])
record2 = Clocktime.objects.create(name=name,code='1',signin=a,signout=a,nowtime=s1,year_month=s1, worktimes='0',staff_id=namelist[0][0])
record3 = Clocktime.objects.create(name=name,code='1',signin=a,signout=a,nowtime=s2,year_month=s2, worktimes='0',staff_id=namelist[0][0])
record4 = Clocktime.objects.create(name=name,code='1',signin=a,signout=a,nowtime=s3,year_month=s3, worktimes='0',staff_id=namelist[0][0])
elif day_num=='5':
record1 = Clocktime.objects.create(name=name,code='1',signin=a,signout=a,nowtime=times,year_month=times, worktimes='0',staff_id=namelist[0][0])
record2 = Clocktime.objects.create(name=name,code='1',signin=a,signout=a,nowtime=s1,year_month=s1, worktimes='0',staff_id=namelist[0][0])
record3 = Clocktime.objects.create(name=name,code='1',signin=a,signout=a,nowtime=s2,year_month=s2, worktimes='0',staff_id=namelist[0][0])
record4 = Clocktime.objects.create(name=name,code='1',signin=a,signout=a,nowtime=s3,year_month=s3, worktimes='0',staff_id=namelist[0][0])
record5 = Clocktime.objects.create(name=name,code='1',signin=a,signout=a,nowtime=s4,year_month=s4, worktimes='0',staff_id=namelist[0][0])
else:
leave.code =2
leave.refusal=refusal
leave.save()
return JsonResponse({'msg': 'tingguo'})
def update(request):
name = Staff.objects.values_list('name')
retlist = list(name)
year=datetime.now().year
month=datetime.now().month
year_month=str(year)+'年'+str(month)+'月'
for i in retlist:
havename= Num.objects.filter(name=i[0],time=year_month)
# 时间问题,默认显示本年本月,查询可以显示其他时间
# 如果查询结果为空,则创建
if len(havename)<1:
num= Clocktime.objects.filter(name=i[0],year_month=year_month,code='0').values()
ret = list(num)
a = len(ret)
num1= Clocktime.objects.filter(name=i[0],year_month=year_month,code='1').values()
ret1 = list(num1)
a1 = len(ret1)
num2= Clocktime.objects.filter(name=i[0],year_month=year_month,code='2').values()
ret2 = list(num2)
a2= len(ret2)
num3= Clocktime.objects.filter(name=i[0],year_month=year_month,code='3').values()
ret3 = list(num3)
a3= len(ret3)
Num.objects.create(name=i[0],time=year_month,code='0',nums=a)
Num.objects.create(name=i[0],time=year_month,code='1',nums=a1)
Num.objects.create(name=i[0],time=year_month,code='2',nums=a2)
Num.objects.create(name=i[0],time=year_month,code='3',nums=a3)
# # 不为空,就更新nums的值
else: