Beispiel #1
0
def findOne_money(request, id):
    money = get_object_or_404(Money, id=id)
    money.__dict__.pop('_state')
    money.transaction_time = time.mktime(
        money.transaction_time.timetuple()) * 1000
    response = ResponseBean().get_success_instance()
    response.message = '查询成功。'
    response.data = money.__dict__
    return JsonResponse(response.__dict__)
Beispiel #2
0
def findOne_appointment(request, id):
    appointment = get_object_or_404(Appointment, id=id)
    appointment.start_time = time.mktime(appointment.start_time.timetuple())*1000
    appointment.end_time = time.mktime(appointment.end_time.timetuple())*1000
    appointment.__dict__.pop('_state')
    response = ResponseBean().get_success_instance()
    response.message = '查询成功。'
    response.data = appointment.__dict__
    return JsonResponse(response.__dict__)
Beispiel #3
0
def cancel_repairment(request, id):
    repairment = get_object_or_404(Repairment, id=id)
    washmachine = get_object_or_404(WashMachine, machine_id=repairment.machine_id)
    repairment.state = 'C'
    washmachine.state = 'F'
    repairment.save()
    washmachine.save()
    response = ResponseBean().get_success_instance()
    response.message = '撤销成功。'
    return JsonResponse(response.__dict__)
Beispiel #4
0
def cancel_appointment(request, id):
    appointment = get_object_or_404(Appointment, id=id)
    washmachine = get_object_or_404(WashMachine, machine_id=appointment.machine_id)
    appointment.end_time=datetime.datetime.now()
    appointment.state = 'C'
    washmachine.state = 'F'
    appointment.save()
    washmachine.save()
    response = ResponseBean().get_success_instance()
    response.message = '撤销成功。'
    return JsonResponse(response.__dict__)
Beispiel #5
0
def findOne_repairment(request, id):
    repairment = get_object_or_404(Repairment, id=id)
    repairment.__dict__.pop('_state')
    if repairment.repair_time:
        repairment.repair_time = time.mktime(repairment.repair_time.timetuple()) * 1000
    if repairment.complete_time:
        repairment.complete_time = time.mktime(repairment.complete_time.timetuple()) * 1000
    response = ResponseBean().get_success_instance()
    response.message = '查询成功。'
    response.data = repairment.__dict__
    return JsonResponse(response.__dict__)
Beispiel #6
0
def complete_repairment(request, id):
    user = User.objects.get(id=request.user.id)
    repairment = get_object_or_404(Repairment, id=id)
    washmachine = get_object_or_404(WashMachine, machine_id=repairment.machine_id)
    complete_account = user.username
    repairment.complete_account = complete_account
    repairment.complete_time = datetime.datetime.now()
    repairment.state = 'E'
    washmachine.state = 'F'
    repairment.save()
    washmachine.save()
    response = ResponseBean().get_success_instance()
    response.message = '处理成功。'
    return JsonResponse(response.__dict__)
Beispiel #7
0
def add_money(request):
    if request.method == 'POST':
        user = User.objects.get(id=request.user.id)
        student = get_object_or_404(StudentInformation, user=user)
        d = json.loads(str(request.body, encoding="utf-8"))
        trading_account = user.username
        trading_amount = d['trading_amount']
        balance = student.balance
        transaction_type = d['transaction_type']
        new_money = Money.objects.create(trading_account=trading_account,
                                         trading_amount=trading_amount,
                                         balance=balance,
                                         transaction_type=transaction_type)
        new_money.save()
        response = ResponseBean().get_success_instance()
        response.message = '新建现金交易记录成功。'
        return JsonResponse(response.__dict__)
Beispiel #8
0
def modify_appointment(request):
    if request.method == 'POST':
        d = json.loads(str(request.body, encoding="utf-8"))
        appointment = get_object_or_404(Appointment, id=d['id'])
        if 'machine_id' in d.keys():
            appointment.machine_id = d['machine_id']
        if 'account' in d.keys():
            appointment.account = d['account']
        if 'start_time' in d.keys():
            appointment.start_time = d['start_time']
        if 'end_time' in d.keys():
            appointment.end_time = d['end_time']
        if 'state' in d.keys():
            appointment.state = d['state']
        appointment.save()
        response = ResponseBean().get_success_instance()
        response.message = '修改预约成功。'
        return JsonResponse(response.__dict__)
Beispiel #9
0
def findAllOfCondition_repairment(request):
    if request.method == 'POST':
        user = User.objects.get(id=request.user.id)
        data = Repairment.objects.order_by('-repair_time')
        d = json.loads(str(request.body, encoding="utf-8"))
        repair_account = user.username
        if 'machine_id' in d.keys():
            data = data.filter(machine_id=d['machine_id'])
        if repair_account is not None and Group.objects.get(user=user) == Group.objects.get(name='U'):
            data = data.filter(repair_account=repair_account)
        if 'state' in d.keys():
            data = data.filter(state=d['state'])
        if 'page_index' in d.keys():
            page_index = d['page_index']
        else:
            page_index = 1
        if 'page_size' in d.keys():
            page_size = d['page_size']
        else:
            page_size = 10

        totol = data.__len__()
        paginator = Paginator(data, page_size)
        try:
            data = paginator.page(page_index)
        except PageNotAnInteger:
            data = paginator.page(1)
        except EmptyPage:
            data = paginator.page(paginator.num_pages)
        response = ResponseBean().get_success_instance()
        response.message = "查询成功。"
        response.total = totol
        data_list = []
        for element in data:
            element.__dict__.pop('_state')
            if element.repair_time:
                element.repair_time = time.mktime(element.repair_time.timetuple()) * 1000
            if element.complete_time:
                element.complete_time = time.mktime(element.complete_time.timetuple()) * 1000
            data_list.append(element.__dict__)
        response.data = data_list
        return JsonResponse(response.__dict__)
Beispiel #10
0
def add_appointment(request, id):
    scheduler = BackgroundScheduler()
    washmachine = get_object_or_404(WashMachine, id=id)
    user = User.objects.get(id=request.user.id)
    machine_id = washmachine.machine_id
    account = user.username
    start_time = datetime.datetime.now()
    end_time = start_time + datetime.timedelta(minutes=+1)
    washmachine.state = 'A'
    state = 'A'
    new_appointment = Appointment.objects.create(machine_id=machine_id,
                                                 account=account,
                                                 start_time=start_time,
                                                 end_time=end_time,
                                                 state=state)
    washmachine.save()
    new_appointment.save()
    scheduler.add_job(appointment_task, 'date', run_date=end_time)
    scheduler.start()
    response = ResponseBean().get_success_instance()
    response.message = '预约成功,请在10分钟之内尽快使用。'
    return JsonResponse(response.__dict__)
Beispiel #11
0
def add_repairment(request):
    if request.method == 'POST':
        user = User.objects.get(id=request.user.id)
        d = json.loads(str(request.body, encoding="utf-8"))
        washmachine = get_object_or_404(WashMachine, id=d['id'])
        machine_id = washmachine.machine_id
        repair_account = user.username
        washmachine_state = d['state']
        remarks = d['remarks']
        if washmachine_state == 'B':
            washmachine.state = 'B'
            state = 'R'
        else:
            washmachine.state = 'D'
            state = 'W'
        new_repairment = Repairment.objects.create(machine_id=machine_id,
                                                   repair_account=repair_account,
                                                   remarks=remarks,
                                                   state=state)
        washmachine.save()
        new_repairment.save()
        response = ResponseBean().get_success_instance()
        response.message = '提交异常成功。'
        return JsonResponse(response.__dict__)
Beispiel #12
0
def remove_appointment(request, id):
    appointment = get_object_or_404(Appointment, id=id)
    appointment.delete()
    response = ResponseBean().get_success_instance()
    response.message = '删除预约记录成功。'
    return JsonResponse(response.__dict__)
Beispiel #13
0
def remove_money(request, id):
    money = get_object_or_404(Money, id=id)
    money.delete()
    response = ResponseBean().get_success_instance()
    response.message = '删除现金交易记录成功。'
    return JsonResponse(response.__dict__)